xbmc
DVDDemux.h
1 /*
2  * Copyright (C) 2005-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include "Interface/StreamInfo.h"
12 
13 #include <memory>
14 #include <string>
15 #include <vector>
16 
17 struct DemuxPacket;
18 struct DemuxCryptoSession;
19 
20 class CDVDInputStream;
21 
22 namespace ADDON
23 {
24 class IAddonProvider;
25 }
26 
27 #ifndef __GNUC__
28 #pragma warning(push)
29 #pragma warning(disable : 4244)
30 #endif
31 
32 extern "C"
33 {
34 #include <libavcodec/avcodec.h>
35 #include <libavutil/mastering_display_metadata.h>
36 }
37 
38 #ifndef __GNUC__
39 #pragma warning(pop)
40 #endif
41 
42 enum StreamType
43 {
44  STREAM_NONE = 0, // if unknown
45  STREAM_AUDIO, // audio stream
46  STREAM_VIDEO, // video stream
47  STREAM_DATA, // data stream
48  STREAM_SUBTITLE, // subtitle stream
49  STREAM_TELETEXT, // Teletext data stream
50  STREAM_RADIO_RDS, // Radio RDS data stream
51  STREAM_AUDIO_ID3 // Audio ID3 data stream
52 };
53 
54 enum StreamSource
55 {
56  STREAM_SOURCE_NONE = 0x000,
57  STREAM_SOURCE_DEMUX = 0x100,
58  STREAM_SOURCE_NAV = 0x200,
59  STREAM_SOURCE_DEMUX_SUB = 0x300,
60  STREAM_SOURCE_TEXT = 0x400,
61  STREAM_SOURCE_VIDEOMUX = 0x500
62 };
63 
64 #define STREAM_SOURCE_MASK(a) ((a)&0xf00)
65 
66 /*
67  * CDemuxStream
68  * Base class for all demuxer streams
69  */
71 {
72 public:
73  CDemuxStream()
74  {
75  uniqueId = 0;
76  dvdNavId = 0;
77  demuxerId = -1;
78  codec_fourcc = 0;
79  profile = FF_PROFILE_UNKNOWN;
80  level = FF_LEVEL_UNKNOWN;
81  type = STREAM_NONE;
82  source = STREAM_SOURCE_NONE;
83  iDuration = 0;
84  pPrivate = NULL;
85  ExtraSize = 0;
86  disabled = false;
87  changes = 0;
88  flags = StreamFlags::FLAG_NONE;
89  }
90 
91  virtual ~CDemuxStream() = default;
92  CDemuxStream(CDemuxStream&&) = default;
93 
94  virtual std::string GetStreamName();
95 
96  int uniqueId; // unique stream id
97  int dvdNavId;
98  int64_t demuxerId; // id of the associated demuxer
99  AVCodecID codec = AV_CODEC_ID_NONE;
100  unsigned int codec_fourcc; // if available
101  int profile; // encoder profile of the stream reported by the decoder. used to qualify hw decoders.
102  int level; // encoder level of the stream reported by the decoder. used to qualify hw decoders.
103  StreamType type;
104  int source;
105 
106  int iDuration; // in mseconds
107  void* pPrivate; // private pointer for the demuxer
108  std::unique_ptr<uint8_t[]> ExtraData; // extra data for codec to use
109  unsigned int ExtraSize; // size of extra data
110 
111  StreamFlags flags;
112  std::string language; // RFC 5646 language code (empty string if undefined)
113  bool disabled; // set when stream is disabled. (when no decoder exists)
114 
115  std::string name;
116  std::string codecName;
117 
118  int changes; // increment on change which player may need to know about
119 
120  std::shared_ptr<DemuxCryptoSession> cryptoSession;
121  std::shared_ptr<ADDON::IAddonProvider> externalInterfaces;
122 };
123 
125 {
126 public:
127  CDemuxStreamVideo() { type = STREAM_VIDEO; }
128 
129  ~CDemuxStreamVideo() override = default;
130  int iFpsScale = 0; // scale of 1000 and a rate of 29970 will result in 29.97 fps
131  int iFpsRate = 0;
132  int iHeight = 0; // height of the stream reported by the demuxer
133  int iWidth = 0; // width of the stream reported by the demuxer
134  double fAspect = 0; // display aspect of stream
135  bool bVFR = false; // variable framerate
136  bool bPTSInvalid = false; // pts cannot be trusted (avi's).
137  bool bForcedAspect = false; // aspect is forced from container
138  int iOrientation = 0; // orientation of the video in degrees counter clockwise
139  int iBitsPerPixel = 0;
140  int iBitRate = 0;
141  int bitDepth = 0;
142 
143  AVColorSpace colorSpace = AVCOL_SPC_UNSPECIFIED;
144  AVColorRange colorRange = AVCOL_RANGE_UNSPECIFIED;
145  AVColorPrimaries colorPrimaries = AVCOL_PRI_UNSPECIFIED;
146  AVColorTransferCharacteristic colorTransferCharacteristic = AVCOL_TRC_UNSPECIFIED;
147 
148  std::shared_ptr<AVMasteringDisplayMetadata> masteringMetaData;
149  std::shared_ptr<AVContentLightMetadata> contentLightMetaData;
150 
151  std::string stereo_mode; // expected stereo mode
152  StreamHdrType hdr_type = StreamHdrType::HDR_TYPE_NONE; // type of HDR for this stream (hdr10, etc)
153 };
154 
156 {
157 public:
159  : CDemuxStream()
160  {
161  iChannels = 0;
162  iSampleRate = 0;
163  iBlockAlign = 0;
164  iBitRate = 0;
165  iBitsPerSample = 0;
166  iChannelLayout = 0;
167  type = STREAM_AUDIO;
168  }
169 
170  ~CDemuxStreamAudio() override = default;
171 
172  std::string GetStreamType();
173 
174  int iChannels;
175  int iSampleRate;
176  int iBlockAlign;
177  int iBitRate;
178  int iBitsPerSample;
179  uint64_t iChannelLayout;
180  std::string m_channelLayoutName;
181 };
182 
184 {
185 public:
187  : CDemuxStream()
188  {
189  type = STREAM_SUBTITLE;
190  }
191 };
192 
194 {
195 public:
197  : CDemuxStream()
198  {
199  type = STREAM_TELETEXT;
200  }
201 };
202 
204 {
205 public:
206  CDemuxStreamAudioID3() : CDemuxStream() { type = STREAM_AUDIO_ID3; }
207 };
208 
210 {
211 public:
213  : CDemuxStream()
214  {
215  type = STREAM_RADIO_RDS;
216  }
217 };
218 
220 {
221 public:
222  CDVDDemux()
223  : m_demuxerId(NewGuid())
224  {
225  }
226  virtual ~CDVDDemux() = default;
227 
228 
229  /*
230  * Reset the entire demuxer (same result as closing and opening it)
231  */
232  virtual bool Reset() = 0;
233 
234  /*
235  * Aborts any internal reading that might be stalling main thread
236  * NOTICE - this can be called from another thread
237  */
238  virtual void Abort() {}
239 
240  /*
241  * Flush the demuxer, if any data is kept in buffers, this should be freed now
242  */
243  virtual void Flush() = 0;
244 
245  /*
246  * Read a packet, returns NULL on error
247  *
248  */
249  virtual DemuxPacket* Read() = 0;
250 
251  /*
252  * Seek, time in msec calculated from stream start
253  */
254  virtual bool SeekTime(double time, bool backwards = false, double* startpts = NULL) = 0;
255 
256  /*
257  * Seek to a specified chapter.
258  * startpts can be updated to the point where display should start
259  */
260  virtual bool SeekChapter(int chapter, double* startpts = NULL) { return false; }
261 
262  /*
263  * Get the number of chapters available
264  */
265  virtual int GetChapterCount() { return 0; }
266 
267  /*
268  * Get current chapter
269  */
270  virtual int GetChapter() { return 0; }
271 
272  /*
273  * Get the name of a chapter
274  * \param strChapterName[out] Name of chapter
275  * \param chapterIdx -1 for current chapter, else a chapter index
276  */
277  virtual void GetChapterName(std::string& strChapterName, int chapterIdx = -1) {}
278 
279  /*
280  * Get the position of a chapter
281  * \param chapterIdx -1 for current chapter, else a chapter index
282  */
283  virtual int64_t GetChapterPos(int chapterIdx = -1) { return 0; }
284 
285  /*
286  * Set the playspeed, if demuxer can handle different
287  * speeds of playback
288  */
289  virtual void SetSpeed(int iSpeed) {}
290 
291  /*
292  * Let demuxer know if we want to fill demux queue
293  */
294  virtual void FillBuffer(bool mode) {}
295 
296  /*
297  * returns the total time in msec
298  */
299  virtual int GetStreamLength() { return 0; }
300 
301  /*
302  * returns the stream or NULL on error
303  */
304  virtual CDemuxStream* GetStream(int64_t demuxerId, int iStreamId) const
305  {
306  return GetStream(iStreamId);
307  };
308 
309  virtual std::vector<CDemuxStream*> GetStreams() const = 0;
310 
311  /*
312  * return nr of streams, 0 if none
313  */
314  virtual int GetNrOfStreams() const = 0;
315 
316  /*
317  * get a list of available programs
318  */
319  virtual int GetPrograms(std::vector<ProgramInfo>& programs) { return 0; }
320 
321  /*
322  * select programs
323  */
324  virtual void SetProgram(int progId) {}
325 
326  /*
327  * returns opened filename
328  */
329  virtual std::string GetFileName() { return ""; }
330 
331  /*
332  * return nr of subtitle streams, 0 if none
333  */
334  int GetNrOfSubtitleStreams();
335 
336  /*
337  * return a user-presentable codec name of the given stream
338  */
339  virtual std::string GetStreamCodecName(int64_t demuxerId, int iStreamId)
340  {
341  return GetStreamCodecName(iStreamId);
342  };
343 
344  /*
345  * enable / disable demux stream
346  */
347  virtual void EnableStream(int64_t demuxerId, int id, bool enable) { EnableStream(id, enable); }
348 
349  /*
350  * implicitly enable and open a demux stream for playback
351  */
352  virtual void OpenStream(int64_t demuxerId, int id) { OpenStream(id); }
353 
354  /*
355  * sets desired width / height for video stream
356  * adaptive demuxers like DASH can use this to choose best fitting video stream
357  */
358  virtual void SetVideoResolution(unsigned int width, unsigned int height) {}
359 
360  /*
361  * return the id of the demuxer
362  */
363  int64_t GetDemuxerId() { return m_demuxerId; }
364 
365 protected:
366  virtual void EnableStream(int id, bool enable) {}
367  virtual void OpenStream(int id) {}
368  virtual CDemuxStream* GetStream(int iStreamId) const = 0;
369  virtual std::string GetStreamCodecName(int iStreamId) { return ""; }
370 
371  int GetNrOfStreams(StreamType streamType);
372 
373  int64_t m_demuxerId;
374 
375 private:
376  int64_t NewGuid()
377  {
378  static int64_t guid = 0;
379  return guid++;
380  }
381 };
Definition: DVDDemux.h:219
Definition: DVDDemux.h:203
Definition: DVDInputStream.h:50
Definition: DVDDemux.h:193
Definition: DVDDemux.h:155
Definition: DVDDemux.h:209
Definition: DVDDemux.h:124
Definition: DemuxCrypto.h:25
Definition: DVDDemux.h:183
Definition: DVDDemux.h:70
Definition: DemuxPacket.h:22
Definition: Addon.cpp:39