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  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  AVDOVIDecoderConfigurationRecord dovi{};
154 };
155 
157 {
158 public:
160  : CDemuxStream()
161  {
162  iChannels = 0;
163  iSampleRate = 0;
164  iBlockAlign = 0;
165  iBitRate = 0;
166  iBitsPerSample = 0;
167  iChannelLayout = 0;
168  type = STREAM_AUDIO;
169  }
170 
171  ~CDemuxStreamAudio() override = default;
172 
173  std::string GetStreamType();
174 
175  int iChannels;
176  int iSampleRate;
177  int iBlockAlign;
178  int iBitRate;
179  int iBitsPerSample;
180  uint64_t iChannelLayout;
181  std::string m_channelLayoutName;
182 };
183 
185 {
186 public:
188  : CDemuxStream()
189  {
190  type = STREAM_SUBTITLE;
191  }
192 };
193 
195 {
196 public:
198  : CDemuxStream()
199  {
200  type = STREAM_TELETEXT;
201  }
202 };
203 
205 {
206 public:
207  CDemuxStreamAudioID3() : CDemuxStream() { type = STREAM_AUDIO_ID3; }
208 };
209 
211 {
212 public:
214  : CDemuxStream()
215  {
216  type = STREAM_RADIO_RDS;
217  }
218 };
219 
221 {
222 public:
223  CDVDDemux()
224  : m_demuxerId(NewGuid())
225  {
226  }
227  virtual ~CDVDDemux() = default;
228 
229 
230  /*
231  * Reset the entire demuxer (same result as closing and opening it)
232  */
233  virtual bool Reset() = 0;
234 
235  /*
236  * Aborts any internal reading that might be stalling main thread
237  * NOTICE - this can be called from another thread
238  */
239  virtual void Abort() {}
240 
241  /*
242  * Flush the demuxer, if any data is kept in buffers, this should be freed now
243  */
244  virtual void Flush() = 0;
245 
246  /*
247  * Read a packet, returns NULL on error
248  *
249  */
250  virtual DemuxPacket* Read() = 0;
251 
252  /*
253  * Seek, time in msec calculated from stream start
254  */
255  virtual bool SeekTime(double time, bool backwards = false, double* startpts = NULL) = 0;
256 
257  /*
258  * Seek to a specified chapter.
259  * startpts can be updated to the point where display should start
260  */
261  virtual bool SeekChapter(int chapter, double* startpts = NULL) { return false; }
262 
263  /*
264  * Get the number of chapters available
265  */
266  virtual int GetChapterCount() { return 0; }
267 
268  /*
269  * Get current chapter
270  */
271  virtual int GetChapter() { return 0; }
272 
273  /*
274  * Get the name of a chapter
275  * \param strChapterName[out] Name of chapter
276  * \param chapterIdx -1 for current chapter, else a chapter index
277  */
278  virtual void GetChapterName(std::string& strChapterName, int chapterIdx = -1) {}
279 
280  /*
281  * Get the position of a chapter
282  * \param chapterIdx -1 for current chapter, else a chapter index
283  */
284  virtual int64_t GetChapterPos(int chapterIdx = -1) { return 0; }
285 
286  /*
287  * Set the playspeed, if demuxer can handle different
288  * speeds of playback
289  */
290  virtual void SetSpeed(int iSpeed) {}
291 
292  /*
293  * Let demuxer know if we want to fill demux queue
294  */
295  virtual void FillBuffer(bool mode) {}
296 
297  /*
298  * returns the total time in msec
299  */
300  virtual int GetStreamLength() { return 0; }
301 
302  /*
303  * returns the stream or NULL on error
304  */
305  virtual CDemuxStream* GetStream(int64_t demuxerId, int iStreamId) const
306  {
307  return GetStream(iStreamId);
308  };
309 
310  virtual std::vector<CDemuxStream*> GetStreams() const = 0;
311 
312  /*
313  * return nr of streams, 0 if none
314  */
315  virtual int GetNrOfStreams() const = 0;
316 
317  /*
318  * get a list of available programs
319  */
320  virtual int GetPrograms(std::vector<ProgramInfo>& programs) { return 0; }
321 
322  /*
323  * select programs
324  */
325  virtual void SetProgram(int progId) {}
326 
327  /*
328  * returns opened filename
329  */
330  virtual std::string GetFileName() { return ""; }
331 
332  /*
333  * return nr of subtitle streams, 0 if none
334  */
335  int GetNrOfSubtitleStreams();
336 
337  /*
338  * return a user-presentable codec name of the given stream
339  */
340  virtual std::string GetStreamCodecName(int64_t demuxerId, int iStreamId)
341  {
342  return GetStreamCodecName(iStreamId);
343  };
344 
345  /*
346  * enable / disable demux stream
347  */
348  virtual void EnableStream(int64_t demuxerId, int id, bool enable) { EnableStream(id, enable); }
349 
350  /*
351  * implicitly enable and open a demux stream for playback
352  */
353  virtual void OpenStream(int64_t demuxerId, int id) { OpenStream(id); }
354 
355  /*
356  * sets desired width / height for video stream
357  * adaptive demuxers like DASH can use this to choose best fitting video stream
358  */
359  virtual void SetVideoResolution(unsigned int width, unsigned int height) {}
360 
361  /*
362  * return the id of the demuxer
363  */
364  int64_t GetDemuxerId() { return m_demuxerId; }
365 
366 protected:
367  virtual void EnableStream(int id, bool enable) {}
368  virtual void OpenStream(int id) {}
369  virtual CDemuxStream* GetStream(int iStreamId) const = 0;
370  virtual std::string GetStreamCodecName(int iStreamId) { return ""; }
371 
372  int GetNrOfStreams(StreamType streamType);
373 
374  int64_t m_demuxerId;
375 
376 private:
377  int64_t NewGuid()
378  {
379  static int64_t guid = 0;
380  return guid++;
381  }
382 };
Definition: FFmpeg.h:75
Definition: DVDDemux.h:220
Definition: DVDDemux.h:204
Definition: DVDInputStream.h:50
Definition: DVDDemux.h:194
Definition: DVDDemux.h:156
Definition: DVDDemux.h:210
Definition: DVDDemux.h:124
Definition: DemuxCrypto.h:26
Definition: DVDDemux.h:184
Definition: DVDDemux.h:72
Definition: DemuxPacket.h:22
Definition: Addon.cpp:39