1 // Copyright (c) 2018-2019 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 #pragma once 21 22 #include "mfx_common.h" 23 #include "mfxplugin++.h" 24 25 namespace MfxHwH265Encode 26 { 27 28 static const mfxPluginUID MFX_PLUGINID_HEVCE_HW = { { 0x6f, 0xad, 0xc7, 0x91, 0xa0, 0xc2, 0xeb, 0x47, 0x9a, 0xb6, 0xdc, 0xd5, 0xea, 0x9d, 0xa3, 0x47 } }; 29 30 class Plugin : public MFXEncoderPlugin 31 { 32 public: Create()33 static MFXEncoderPlugin* Create() 34 { 35 return GetInstance(); 36 } CreateByDispatcher(mfxPluginUID guid,mfxPlugin * mfxPlg)37 static mfxStatus CreateByDispatcher(mfxPluginUID guid, mfxPlugin* mfxPlg) 38 { 39 if (!mfxPlg) 40 { 41 return MFX_ERR_NULL_PTR; 42 } 43 if (guid != MFX_PLUGINID_HEVCE_HW) 44 { 45 return MFX_ERR_NOT_FOUND; 46 } 47 48 Plugin* tmp_pplg = nullptr; 49 50 try 51 { 52 tmp_pplg = GetInstance(); 53 } 54 catch (std::bad_alloc&) 55 { 56 return MFX_ERR_MEMORY_ALLOC; 57 } 58 catch (...) 59 { 60 return MFX_ERR_UNKNOWN; 61 } 62 63 *mfxPlg = tmp_pplg->m_adapter; 64 tmp_pplg->m_createdByDispatcher = true; 65 66 return MFX_ERR_NONE; 67 } PluginInit(mfxCoreInterface *)68 virtual mfxStatus PluginInit(mfxCoreInterface * /*core*/) 69 { 70 return MFX_ERR_NONE; 71 } PluginClose()72 virtual mfxStatus PluginClose() 73 { 74 if (m_createdByDispatcher) 75 Release(); 76 77 return MFX_ERR_NONE; 78 } GetPluginParam(mfxPluginParam * par)79 virtual mfxStatus GetPluginParam(mfxPluginParam *par) 80 { 81 MFX_CHECK_NULL_PTR1(par); 82 83 par->PluginUID = MFX_PLUGINID_HEVCE_HW; 84 par->PluginVersion = 1; 85 par->ThreadPolicy = MFX_THREADPOLICY_SERIAL; 86 par->MaxThreadNum = 1; 87 par->APIVersion.Major = MFX_VERSION_MAJOR; 88 par->APIVersion.Minor = MFX_VERSION_MINOR; 89 par->Type = MFX_PLUGINTYPE_VIDEO_ENCODE; 90 par->CodecId = MFX_CODEC_HEVC; 91 92 return MFX_ERR_NONE; 93 } Execute(mfxThreadTask,mfxU32,mfxU32)94 virtual mfxStatus Execute(mfxThreadTask /*task*/, mfxU32 /*uid_p*/, mfxU32 /*uid_a*/) 95 { 96 return MFX_ERR_UNDEFINED_BEHAVIOR; 97 } FreeResources(mfxThreadTask,mfxStatus)98 virtual mfxStatus FreeResources(mfxThreadTask /*task*/, mfxStatus /*sts*/) 99 { 100 return MFX_ERR_UNDEFINED_BEHAVIOR; 101 } 102 Init(mfxVideoParam *)103 virtual mfxStatus Init(mfxVideoParam * /*par*/) 104 { 105 return MFX_ERR_UNDEFINED_BEHAVIOR; 106 } QueryIOSurf(mfxVideoParam *,mfxFrameAllocRequest *,mfxFrameAllocRequest *)107 virtual mfxStatus QueryIOSurf(mfxVideoParam * /*par*/, mfxFrameAllocRequest * /*in*/, mfxFrameAllocRequest * /*out*/) 108 { 109 return MFX_ERR_UNDEFINED_BEHAVIOR; 110 } Query(mfxVideoParam *,mfxVideoParam *)111 virtual mfxStatus Query(mfxVideoParam * /*in*/, mfxVideoParam * /*out*/) 112 { 113 return MFX_ERR_UNDEFINED_BEHAVIOR; 114 } Reset(mfxVideoParam *)115 virtual mfxStatus Reset(mfxVideoParam * /*par*/) 116 { 117 return MFX_ERR_UNDEFINED_BEHAVIOR; 118 } GetVideoParam(mfxVideoParam *)119 virtual mfxStatus GetVideoParam(mfxVideoParam * /*par*/) 120 { 121 return MFX_ERR_UNDEFINED_BEHAVIOR; 122 } 123 EncodeFrameSubmit(mfxEncodeCtrl *,mfxFrameSurface1 *,mfxBitstream *,mfxThreadTask *)124 virtual mfxStatus EncodeFrameSubmit(mfxEncodeCtrl * /*ctrl*/, mfxFrameSurface1 * /*surface*/, mfxBitstream * /*bs*/, mfxThreadTask * /*task*/) 125 { 126 return MFX_ERR_UNDEFINED_BEHAVIOR; 127 } 128 Release()129 virtual void Release() 130 { 131 return; 132 } 133 Close()134 virtual mfxStatus Close() 135 { 136 return MFX_ERR_UNDEFINED_BEHAVIOR; 137 } 138 SetAuxParams(void *,int)139 virtual mfxStatus SetAuxParams(void*, int) 140 { 141 return MFX_ERR_UNSUPPORTED; 142 } 143 protected: Plugin(bool CreateByDispatcher)144 explicit Plugin(bool CreateByDispatcher) 145 : m_createdByDispatcher(CreateByDispatcher) 146 , m_adapter(this) 147 {} 148 ~Plugin()149 virtual ~Plugin() 150 {} 151 GetInstance()152 static Plugin* GetInstance() 153 { 154 static Plugin instance(false); 155 return &instance; 156 } 157 158 bool m_createdByDispatcher; 159 MFXPluginAdapter<MFXEncoderPlugin> m_adapter; 160 }; 161 } //MfxHwH265Encode 162