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