Merge pull request #2819 from Fice/dnd_assign_fix
[vuplus_xbmc] / xbmc / cores / dvdplayer / DVDCodecs / Video / DVDVideoCodec.h
1 #pragma once
2
3 /*
4  *      Copyright (C) 2005-2013 Team XBMC
5  *      http://www.xbmc.org
6  *
7  *  This Program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 2, or (at your option)
10  *  any later version.
11  *
12  *  This Program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with XBMC; see the file COPYING.  If not, see
19  *  <http://www.gnu.org/licenses/>.
20  *
21  */
22
23 #include "system.h"
24
25 #include <vector>
26 #include "cores/VideoRenderers/RenderFormats.h"
27
28 // when modifying these structures, make sure you update all codecs accordingly
29 #define FRAME_TYPE_UNDEF 0
30 #define FRAME_TYPE_I 1
31 #define FRAME_TYPE_P 2
32 #define FRAME_TYPE_B 3
33 #define FRAME_TYPE_D 4
34
35 namespace DXVA { class CSurfaceContext; }
36 namespace VAAPI { struct CHolder; }
37 class CVDPAU;
38 class COpenMax;
39 class COpenMaxVideo;
40 struct OpenMaxVideoBuffer;
41
42 // should be entirely filled by all codecs
43 struct DVDVideoPicture
44 {
45   double pts; // timestamp in seconds, used in the CDVDPlayer class to keep track of pts
46   double dts;
47
48   union
49   {
50     struct {
51       uint8_t* data[4];      // [4] = alpha channel, currently not used
52       int iLineSize[4];   // [4] = alpha channel, currently not used
53     };
54     struct {
55       DXVA::CSurfaceContext* context;
56     };
57     struct {
58       CVDPAU* vdpau;
59     };
60     struct {
61       VAAPI::CHolder* vaapi;
62     };
63
64     struct {
65       COpenMax *openMax;
66       OpenMaxVideoBuffer *openMaxBuffer;
67     };
68
69     struct {
70       struct __CVBuffer *cvBufferRef;
71     };
72   };
73
74   unsigned int iFlags;
75
76   double       iRepeatPicture;
77   double       iDuration;
78   unsigned int iFrameType         : 4; // see defines above // 1->I, 2->P, 3->B, 0->Undef
79   unsigned int color_matrix       : 4;
80   unsigned int color_range        : 1; // 1 indicate if we have a full range of color
81   unsigned int chroma_position;
82   unsigned int color_primaries;
83   unsigned int color_transfer;
84   unsigned int extended_format;
85
86   int8_t* qscale_table; // Quantization parameters, primarily used by filters
87   int qscale_stride;
88   int qscale_type;
89
90   unsigned int iWidth;
91   unsigned int iHeight;
92   unsigned int iDisplayWidth;  // width of the picture without black bars
93   unsigned int iDisplayHeight; // height of the picture without black bars
94
95   ERenderFormat format;
96 };
97
98 struct DVDVideoUserData
99 {
100   uint8_t* data;
101   int size;
102 };
103
104 #define DVP_FLAG_TOP_FIELD_FIRST    0x00000001
105 #define DVP_FLAG_REPEAT_TOP_FIELD   0x00000002 //Set to indicate that the top field should be repeated
106 #define DVP_FLAG_ALLOCATED          0x00000004 //Set to indicate that this has allocated data
107 #define DVP_FLAG_INTERLACED         0x00000008 //Set to indicate that this frame is interlaced
108
109 #define DVP_FLAG_NOSKIP             0x00000010 // indicate this picture should never be dropped
110 #define DVP_FLAG_DROPPED            0x00000020 // indicate that this picture has been dropped in decoder stage, will have no data
111
112 // DVP_FLAG 0x00000100 - 0x00000f00 is in use by libmpeg2!
113
114 #define DVP_QSCALE_UNKNOWN          0
115 #define DVP_QSCALE_MPEG1            1
116 #define DVP_QSCALE_MPEG2            2
117 #define DVP_QSCALE_H264             3
118
119 class CDVDStreamInfo;
120 class CDVDCodecOption;
121 class CDVDCodecOptions;
122
123 // VC_ messages, messages can be combined
124 #define VC_ERROR    0x00000001  // an error occured, no other messages will be returned
125 #define VC_BUFFER   0x00000002  // the decoder needs more data
126 #define VC_PICTURE  0x00000004  // the decoder got a picture, call Decode(NULL, 0) again to parse the rest of the data
127 #define VC_USERDATA 0x00000008  // the decoder found some userdata,  call Decode(NULL, 0) again to parse the rest of the data
128 #define VC_FLUSHED  0x00000010  // the decoder lost it's state, we need to restart decoding again
129 class CDVDVideoCodec
130 {
131 public:
132
133   CDVDVideoCodec() {}
134   virtual ~CDVDVideoCodec() {}
135
136   /*
137    * Open the decoder, returns true on success
138    */
139   virtual bool Open(CDVDStreamInfo &hints, CDVDCodecOptions &options) = 0;
140
141   /*
142    * Dispose, Free all resources
143    */
144   virtual void Dispose() = 0;
145
146   /*
147    * returns one or a combination of VC_ messages
148    * pData and iSize can be NULL, this means we should flush the rest of the data.
149    */
150   virtual int Decode(uint8_t* pData, int iSize, double dts, double pts) = 0;
151
152  /*
153    * Reset the decoder.
154    * Should be the same as calling Dispose and Open after each other
155    */
156   virtual void Reset() = 0;
157
158   /*
159    * returns true if successfull
160    * the data is valid until the next Decode call
161    */
162   virtual bool GetPicture(DVDVideoPicture* pDvdVideoPicture) = 0;
163
164
165   /*
166    * returns true if successfull
167    * the data is cleared to zero
168    */ 
169   virtual bool ClearPicture(DVDVideoPicture* pDvdVideoPicture)
170   {
171     memset(pDvdVideoPicture, 0, sizeof(DVDVideoPicture));
172     return true;
173   }
174
175   /*
176    * returns true if successfull
177    * the data is valid until the next Decode call
178    * userdata can be anything, for now we use it for closed captioning
179    */
180   virtual bool GetUserData(DVDVideoUserData* pDvdVideoUserData)
181   {
182     pDvdVideoUserData->data = NULL;
183     pDvdVideoUserData->size = 0;
184     return false;
185   }
186
187   /*
188    * will be called by video player indicating if a frame will eventually be dropped
189    * codec can then skip actually decoding the data, just consume the data set picture headers
190    */
191   virtual void SetDropState(bool bDrop) = 0;
192
193   /*
194    * will be called by video player indicating the playback speed. see DVD_PLAYSPEED_NORMAL,
195    * DVD_PLAYSPEED_PAUSE and friends.
196    */
197   virtual void SetSpeed(int iSpeed) {};
198
199   /*
200    * returns the number of demuxer bytes in any internal buffers
201    */
202   virtual int GetDataSize(void)
203   {
204     return 0;
205   }
206
207   /*
208    * returns the time in seconds for demuxer bytes in any internal buffers
209    */
210   virtual double GetTimeSize(void)
211   {
212     return 0;
213   }
214
215   enum EFilterFlags {
216     FILTER_NONE                =  0x0,
217     FILTER_DEINTERLACE_YADIF   =  0x1,  /* use first deinterlace mode */
218     FILTER_DEINTERLACE_ANY     =  0xf,  /* use any deinterlace mode */
219     FILTER_DEINTERLACE_FLAGGED = 0x10,  /* only deinterlace flagged frames */
220     FILTER_DEINTERLACE_HALFED  = 0x20,  /* do half rate deinterlacing */
221     FILTER_ROTATE              = 0x40,  /* rotate image according to the codec hints */
222   };
223
224   /*
225    * set the type of filters that should be applied at decoding stage if possible
226    */
227   virtual unsigned int SetFilters(unsigned int filters) { return 0u; }
228
229   /*
230    *
231    * should return codecs name
232    */
233   virtual const char* GetName() = 0;
234
235   /*
236    *
237    * How many packets should player remember, so codec
238    * can recover should something cause it to flush
239    * outside of players control
240    */
241   virtual unsigned GetConvergeCount()
242   {
243     return 0;
244   }
245
246
247   /**
248    * Number of references to old pictures that are allowed to
249    * be retained when calling decode on the next demux packet
250    */
251   virtual unsigned GetAllowedReferences() { return 0; }
252 };