kodi
DVDVideoCodec.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 "DVDResource.h"
12 #include "cores/VideoPlayer/Buffers/VideoBuffer.h"
13 #include "cores/VideoPlayer/Interface/DemuxPacket.h"
14 #include "cores/VideoPlayer/Process/ProcessInfo.h"
15 
16 extern "C" {
17 #include <libavcodec/avcodec.h>
18 #include <libavutil/mastering_display_metadata.h>
19 }
20 
21 #include <vector>
22 #include <string>
23 #include <map>
24 
25 class CSetting;
26 
27 // when modifying these structures, make sure you update all codecs accordingly
28 #define FRAME_TYPE_UNDEF 0
29 #define FRAME_TYPE_I 1
30 #define FRAME_TYPE_P 2
31 #define FRAME_TYPE_B 3
32 #define FRAME_TYPE_D 4
33 
34 
35 // should be entirely filled by all codecs
37 {
38 public:
39  VideoPicture();
40  ~VideoPicture();
41  VideoPicture& CopyRef(const VideoPicture &pic);
42  VideoPicture& SetParams(const VideoPicture &pic);
43  void Reset(); // reinitialize members, videoBuffer will be released if set!
44 
45  CVideoBuffer *videoBuffer = nullptr;
46 
47  double pts; // timestamp in seconds, used in the CVideoPlayer class to keep track of pts
48  double dts;
49  unsigned int iFlags;
50  double iRepeatPicture;
51  double iDuration;
52  unsigned int iFrameType : 4; //< see defines above // 1->I, 2->P, 3->B, 0->Undef
53  AVColorSpace color_space;
54  unsigned int color_range : 1; //< 1 indicate if we have a full range of color
55  AVChromaLocation chroma_position;
56  AVColorPrimaries color_primaries; // heuristics applied when original is AVCOL_PRI_UNSPECIFIED
57  AVColorPrimaries m_originalColorPrimaries;
58  AVColorTransferCharacteristic color_transfer;
59  unsigned int colorBits = 8;
60  std::string stereoMode;
61 
62  int8_t* qp_table; //< Quantization parameters, primarily used by filters
63  int qstride;
64  int qscale_type;
65  int pict_type;
66 
67  StreamHdrType hdrType;
68 
69  bool hasDisplayMetadata = false;
70  AVMasteringDisplayMetadata displayMetadata;
71  bool hasLightMetadata = false;
72  AVContentLightMetadata lightMetadata;
73 
74  AVPixelFormat pixelFormat; //< source pixel format
75 
76  unsigned int iWidth;
77  unsigned int iHeight;
78  unsigned int iDisplayWidth; //< width of the picture without black bars
79  unsigned int iDisplayHeight; //< height of the picture without black bars
80 
81 private:
82  VideoPicture(VideoPicture const&);
83  VideoPicture& operator=(VideoPicture const&);
84 };
85 
86 #define DVP_FLAG_TOP_FIELD_FIRST 0x00000001
87 #define DVP_FLAG_REPEAT_TOP_FIELD 0x00000002 //< Set to indicate that the top field should be repeated
88 #define DVP_FLAG_INTERLACED 0x00000008 //< Set to indicate that this frame is interlaced
89 #define DVP_FLAG_DROPPED 0x00000010 //< indicate that this picture has been dropped in decoder stage, will have no data
90 
91 #define DVD_CODEC_CTRL_SKIPDEINT 0x01000000 //< request to skip a deinterlacing cycle, if possible
92 #define DVD_CODEC_CTRL_NO_POSTPROC 0x02000000 //< see GetCodecStats
93 #define DVD_CODEC_CTRL_HURRY 0x04000000 //< see GetCodecStats
94 #define DVD_CODEC_CTRL_DROP 0x08000000 //< drop in decoder or set DVP_FLAG_DROPPED, no render of frame
95 #define DVD_CODEC_CTRL_DROP_ANY 0x10000000 //< drop some non-reference frame
96 #define DVD_CODEC_CTRL_DRAIN 0x20000000 //< squeeze out pictured without feeding new packets
97 #define DVD_CODEC_CTRL_ROTATE 0x40000000 //< rotate if renderer does not support it
98 
99 // DVP_FLAG 0x00000100 - 0x00000f00 is in use by libmpeg2!
100 
101 #define DVP_QSCALE_UNKNOWN 0
102 #define DVP_QSCALE_MPEG1 1
103 #define DVP_QSCALE_MPEG2 2
104 #define DVP_QSCALE_H264 3
105 
106 class CDVDStreamInfo;
107 class CDVDCodecOption;
108 class CDVDCodecOptions;
109 
111 {
112 public:
113 
114  enum VCReturn
115  {
116  VC_NONE = 0,
117  VC_ERROR, //< an error occurred, no other messages will be returned
118  VC_FATAL, //< non recoverable error
119  VC_BUFFER, //< the decoder needs more data
120  VC_PICTURE, //< the decoder got a picture, call Decode(NULL, 0) again to parse the rest of the data
121  VC_FLUSHED, //< the decoder lost it's state, we need to restart decoding again
122  VC_NOBUFFER, //< last FFmpeg GetBuffer failed
123  VC_REOPEN, //< decoder request to re-open
124  VC_EOF //< EOF
125  };
126 
127  explicit CDVDVideoCodec(CProcessInfo &processInfo) : m_processInfo(processInfo) {}
128  virtual ~CDVDVideoCodec() = default;
129 
135  virtual bool Open(CDVDStreamInfo &hints, CDVDCodecOptions &options) = 0;
136 
143  virtual bool Reconfigure(CDVDStreamInfo &hints)
144  {
145  return false;
146  }
147 
152  virtual bool AddData(const DemuxPacket &packet) = 0;
153 
158  virtual void Reset() = 0;
159 
165  virtual VCReturn GetPicture(VideoPicture* pVideoPicture) = 0;
166 
171  virtual void SetSpeed(int iSpeed) {}
172 
176  virtual const char* GetName() = 0;
177 
182  virtual unsigned GetConvergeCount()
183  {
184  return 0;
185  }
186 
191  virtual unsigned GetAllowedReferences() { return 0; }
192 
205  virtual bool GetCodecStats(double &pts, int &droppedFrames, int &skippedPics)
206  {
207  droppedFrames = -1;
208  skippedPics = -1;
209  return false;
210  }
211 
235  virtual void SetCodecControl(int flags) {}
236 
241  virtual void Reopen() {}
242 
243 protected:
244  CProcessInfo &m_processInfo;
245 };
246 
247 // callback interface for ffmpeg hw accelerators
248 class IHardwareDecoder : public IDVDResourceCounted<IHardwareDecoder>
249 {
250 public:
251  IHardwareDecoder() = default;
252  ~IHardwareDecoder() override = default;
253  virtual bool Open(AVCodecContext* avctx, AVCodecContext* mainctx, const enum AVPixelFormat) = 0;
254  virtual CDVDVideoCodec::VCReturn Decode(AVCodecContext* avctx, AVFrame* frame) = 0;
255  virtual bool GetPicture(AVCodecContext* avctx, VideoPicture* picture) = 0;
256  virtual CDVDVideoCodec::VCReturn Check(AVCodecContext* avctx) = 0;
257  virtual void Reset() {}
258  virtual unsigned GetAllowedReferences() { return 0; }
259  virtual bool CanSkipDeint() {return false; }
260  virtual const std::string Name() = 0;
261  virtual void SetCodecControl(int flags) {}
262 };
263 
265 {
266 public:
267  virtual ~ICallbackHWAccel() = default;
268  virtual IHardwareDecoder* GetHWAccel() = 0;
269  virtual bool GetPictureCommon(VideoPicture* pVideoPicture) = 0;
270 };
virtual void SetSpeed(int iSpeed)
will be called by video player indicating the playback speed.
Definition: DVDVideoCodec.h:171
Definition: DVDStreamInfo.h:25
Definition: VideoBuffer.h:85
virtual void SetCodecControl(int flags)
Codec can be informed by player with the following flags:
Definition: DVDVideoCodec.h:235
Definition: DVDCodecs.h:23
Setting base class containing all the properties which are common to all settings independent of the ...
Definition: Setting.h:46
Definition: DVDVideoCodec.h:248
Definition: DVDResource.h:14
Definition: DVDVideoCodec.h:264
Definition: ProcessInfo.h:26
virtual unsigned GetConvergeCount()
How many packets should player remember, so codec can recover should something cause it to flush outs...
Definition: DVDVideoCodec.h:182
virtual bool Reconfigure(CDVDStreamInfo &hints)
Reconfigure the decoder, returns true on success Decoders not capable of running multiple instances m...
Definition: DVDVideoCodec.h:143
Definition: DVDVideoCodec.h:36
virtual bool GetCodecStats(double &pts, int &droppedFrames, int &skippedPics)
For calculation of dropping requirements player asks for some information.
Definition: DVDVideoCodec.h:205
virtual unsigned GetAllowedReferences()
Number of references to old pictures that are allowed to be retained when calling decode on the next ...
Definition: DVDVideoCodec.h:191
Definition: DemuxPacket.h:22
Definition: DVDCodecs.h:15
Definition: DVDVideoCodec.h:110
virtual void Reopen()
Re-open the decoder.
Definition: DVDVideoCodec.h:241