1 // Copyright (c) 2017 Intel Corporation
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to deal
5 // in the Software without restriction, including without limitation the rights
6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 // copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in all
11 // copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 // SOFTWARE.
20 
21 /* ****************************************************************************** */
22 
23 #include "mfx_common.h"
24 
25 #if defined (MFX_ENABLE_VPP)
26 
27 #ifndef __MFX_VPP_SW_H
28 #define __MFX_VPP_SW_H
29 
30 #include <memory>
31 
32 #include "mfxvideo++int.h"
33 
34 #include "mfx_vpp_defs.h"
35 #include "mfx_vpp_base.h"
36 #include "mfx_task.h"
37 
38 
39 /* ******************************************************************** */
40 /*                 Core Class of MSDK VPP                               */
41 /* ******************************************************************** */
42 
43 #include "mfx_vpp_hw.h"
44 
45 class VideoVPPBase
46 {
47 public:
48 
49   static mfxStatus Query( VideoCORE *core, mfxVideoParam *in, mfxVideoParam *out);
50   static mfxStatus QueryIOSurf(VideoCORE *core, mfxVideoParam *par, mfxFrameAllocRequest *request);
51 
52   VideoVPPBase(VideoCORE *core, mfxStatus* sts);
53   virtual ~VideoVPPBase();
54 
55   // VideoBase methods
56   virtual mfxStatus Reset(mfxVideoParam *par);
57   virtual mfxStatus Close(void);
58   virtual mfxStatus Init(mfxVideoParam *par);
59 
60   virtual mfxStatus GetVideoParam(mfxVideoParam *par);
61   virtual mfxStatus GetVPPStat(mfxVPPStat *stat);
62   virtual mfxStatus VppFrameCheck(mfxFrameSurface1 *in, mfxFrameSurface1 *out, mfxExtVppAuxData *aux,
63                                   MFX_ENTRY_POINT pEntryPoint[], mfxU32 &numEntryPoints);
64 
VppFrameCheck(mfxFrameSurface1 *,mfxFrameSurface1 *)65   virtual mfxStatus VppFrameCheck(mfxFrameSurface1 *, mfxFrameSurface1 *)
66   {
67       return MFX_ERR_UNSUPPORTED;
68   }
69 
70   virtual mfxStatus RunFrameVPP(mfxFrameSurface1* in, mfxFrameSurface1* out, mfxExtVppAuxData *aux) = 0;
71 
72   virtual mfxTaskThreadingPolicy GetThreadingPolicy(void);
73 
74 protected:
75 
76   typedef struct
77   {
78     mfxFrameInfo    In;
79     mfxFrameInfo    Out;
80     mfxFrameInfo    Deffered;
81 
82     mfxU16          IOPattern;
83     mfxU16          AsyncDepth;
84 
85     bool            isInited;
86     bool            isFirstFrameProcessed;
87     bool            isCompositionModeEnabled;
88 
89   } sErrPrtctState;
90 
91   virtual mfxStatus InternalInit(mfxVideoParam *par) = 0;
92 
93   // methods of sync part of VPP for check info/params
94   mfxStatus CheckIOPattern( mfxVideoParam* par );
95 
96   static mfxStatus QueryCaps(VideoCORE * core, MfxHwVideoProcessing::mfxVppCaps& caps);
97   static mfxStatus CheckPlatformLimitations( VideoCORE* core, mfxVideoParam & param, bool bCorrectionEnable );
98   mfxU32    GetNumUsedFilters();
99 
100   std::vector<mfxU32> m_pipelineList; // list like DO_USE but contains some internal filter names (ex RESIZE, DEINTERLACE etc)
101 
102   //
103   bool               m_bDynamicDeinterlace;
104 
105   VideoCORE*  m_core;
106   mfxVPPStat  m_stat;
107 
108   // protection state. Keeps Init/Reset params that allows checking that RunFrame params
109   // do not violate Init/Reset params
110   sErrPrtctState m_errPrtctState;
111 
112   // State that keeps Init params. They are changed on Init only
113   sErrPrtctState m_InitState;
114 
115   // opaque processing
116   bool                  m_bOpaqMode[2];
117   mfxFrameAllocRequest  m_requestOpaq[2];
118 
119   //
120   // HW VPP Support
121   //
122   std::unique_ptr<MfxHwVideoProcessing::VideoVPPHW>     m_pHWVPP;
123 };
124 
125 class VideoVPP_HW : public VideoVPPBase
126 {
127 public:
128     VideoVPP_HW(VideoCORE *core, mfxStatus* sts);
129 
130     virtual mfxStatus InternalInit(mfxVideoParam *par);
131     virtual mfxStatus Close(void);
132     virtual mfxStatus Reset(mfxVideoParam *par);
133 
134     virtual mfxStatus GetVideoParam(mfxVideoParam *par);
135 
136     virtual mfxStatus VppFrameCheck(mfxFrameSurface1 *in, mfxFrameSurface1 *out, mfxExtVppAuxData *aux,
137                                     MFX_ENTRY_POINT pEntryPoints[], mfxU32 &numEntryPoints);
138 
139     virtual mfxStatus RunFrameVPP(mfxFrameSurface1* in, mfxFrameSurface1* out, mfxExtVppAuxData *aux);
140 
141     mfxStatus PassThrough(mfxFrameInfo* In, mfxFrameInfo* Out, mfxU32 taskIndex);
142 };
143 
144 
145 mfxStatus RunFrameVPPRoutine(void *pState, void *pParam, mfxU32 threadNumber, mfxU32 callNumber);
146 mfxStatus CompleteFrameVPPRoutine(void *pState, void *pParam, mfxStatus taskRes);
147 
148 VideoVPPBase* CreateAndInitVPPImpl(mfxVideoParam *par, VideoCORE *core, mfxStatus *mfxSts);
149 
150 #endif // __MFX_VPP_SW_H
151 
152 #endif // MFX_ENABLE_VPP
153 /* EOF */
154