Merge pull request #5101 from FernetMenta/ffmpeg-threads
[vuplus_xbmc] / xbmc / cores / dvdplayer / DVDCodecs / Video / DVDVideoCodecFFmpeg.h
1 #pragma once
2
3 /*
4  *      Copyright (C) 2005-2013 Team XBMC
5  *      http://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 "DVDVideoCodec.h"
24 #include "DVDResource.h"
25 #include "DllAvCodec.h"
26 #include "DllAvFormat.h"
27 #include "DllAvUtil.h"
28 #include "DllSwScale.h"
29 #include "DllAvFilter.h"
30 #include "DllPostProc.h"
31
32 class CCriticalSection;
33
34 class CDVDVideoCodecFFmpeg : public CDVDVideoCodec
35 {
36 public:
37   class IHardwareDecoder : public IDVDResourceCounted<IHardwareDecoder>
38   {
39     public:
40              IHardwareDecoder() {}
41     virtual ~IHardwareDecoder() {};
42     virtual bool Open      (AVCodecContext* avctx, const enum PixelFormat, unsigned int surfaces) = 0;
43     virtual int  Decode    (AVCodecContext* avctx, AVFrame* frame) = 0;
44     virtual bool GetPicture(AVCodecContext* avctx, AVFrame* frame, DVDVideoPicture* picture) = 0;
45     virtual int  Check     (AVCodecContext* avctx) = 0;
46     virtual void Reset     () {}
47     virtual unsigned GetAllowedReferences() { return 0; }
48     virtual const std::string Name() = 0;
49     virtual CCriticalSection* Section() { return NULL; }
50   };
51
52   CDVDVideoCodecFFmpeg();
53   virtual ~CDVDVideoCodecFFmpeg();
54   virtual bool Open(CDVDStreamInfo &hints, CDVDCodecOptions &options);
55   virtual void Dispose();
56   virtual int Decode(uint8_t* pData, int iSize, double dts, double pts);
57   virtual void Reset();
58   bool GetPictureCommon(DVDVideoPicture* pDvdVideoPicture);
59   virtual bool GetPicture(DVDVideoPicture* pDvdVideoPicture);
60   virtual void SetDropState(bool bDrop);
61   virtual unsigned int SetFilters(unsigned int filters);
62   virtual const char* GetName() { return m_name.c_str(); }; // m_name is never changed after open
63   virtual unsigned GetConvergeCount();
64   virtual unsigned GetAllowedReferences();
65
66   bool               IsHardwareAllowed()                     { return !m_bSoftware; }
67   IHardwareDecoder * GetHardware()                           { return m_pHardware; };
68   void               SetHardware(IHardwareDecoder* hardware) 
69   {
70     SAFE_RELEASE(m_pHardware);
71     m_pHardware = hardware;
72     UpdateName();
73   }
74
75 protected:
76   static enum PixelFormat GetFormat(struct AVCodecContext * avctx, const PixelFormat * fmt);
77
78   int  FilterOpen(const CStdString& filters, bool scale);
79   void FilterClose();
80   int  FilterProcess(AVFrame* frame);
81
82   void UpdateName()
83   {
84     if(m_pCodecContext->codec->name)
85       m_name = CStdString("ff-") + m_pCodecContext->codec->name;
86     else
87       m_name = "ffmpeg";
88
89     if(m_pHardware)
90       m_name += "-" + m_pHardware->Name();
91   }
92
93   AVFrame* m_pFrame;
94   AVCodecContext* m_pCodecContext;
95
96   CStdString       m_filters;
97   CStdString       m_filters_next;
98   AVFilterGraph*   m_pFilterGraph;
99   AVFilterContext* m_pFilterIn;
100   AVFilterContext* m_pFilterOut;
101 #if defined(LIBAVFILTER_AVFRAME_BASED)
102   AVFrame*         m_pFilterFrame;
103 #else
104   AVFilterBufferRef* m_pBufferRef;
105 #endif
106
107   int m_iPictureWidth;
108   int m_iPictureHeight;
109
110   int m_iScreenWidth;
111   int m_iScreenHeight;
112   int m_iOrientation;// orientation of the video in degress counter clockwise
113
114   unsigned int m_uSurfacesCount;
115
116   DllAvCodec m_dllAvCodec;
117   DllAvUtil  m_dllAvUtil;
118   DllSwScale m_dllSwScale;
119   DllAvFilter m_dllAvFilter;
120   DllPostProc m_dllPostProc;
121
122   std::string m_name;
123   bool              m_bSoftware;
124   bool  m_isHi10p;
125   IHardwareDecoder *m_pHardware;
126   int m_iLastKeyframe;
127   double m_dts;
128   bool   m_started;
129   std::vector<PixelFormat> m_formats;
130 };