Skip to content

Commit

Permalink
[HEVCe][Linux][Windows][Android]Move h265 encoder to libmfxhw (Part 2)
Browse files Browse the repository at this point in the history
- Enable HEVCe HW through libmfxhw: add inmplementation to encode_hw

- Disable using HEVCe HW as plugin, call with guid possible
  • Loading branch information
Kokoshnikov authored and Oleg Nabiullin committed May 31, 2018
1 parent 6939e3d commit 8536960
Show file tree
Hide file tree
Showing 11 changed files with 255 additions and 173 deletions.
6 changes: 4 additions & 2 deletions _studio/hevce_hw/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ LOCAL_C_INCLUDES := \

LOCAL_CFLAGS := \
$(MFX_CFLAGS_INTERNAL) \
-DMFX_ENABLE_H265_VIDEO_ENCODE
-DMFX_ENABLE_H265_VIDEO_ENCODE \
-DAS_HEVCE_PLUGIN
LOCAL_CFLAGS_32 := $(MFX_CFLAGS_INTERNAL_32)

LOCAL_STATIC_LIBRARIES := $(MFX_LOCAL_STATIC_LIBRARIES)
Expand Down Expand Up @@ -67,7 +68,8 @@ LOCAL_C_INCLUDES := \

LOCAL_CFLAGS := \
$(MFX_CFLAGS_INTERNAL) \
-DMFX_ENABLE_H265_VIDEO_ENCODE
-DMFX_ENABLE_H265_VIDEO_ENCODE \
-DAS_HEVCE_PLUGIN
LOCAL_CFLAGS_64 := $(MFX_CFLAGS_INTERNAL_64)

LOCAL_STATIC_LIBRARIES := $(MFX_LOCAL_STATIC_LIBRARIES)
Expand Down
166 changes: 0 additions & 166 deletions _studio/hevce_hw/h265/include/mfx_h265_encode_hw.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,13 @@
#include "mfx_h265_encode_hw_ddi.h"
#include "mfx_h265_encode_hw_utils.h"
#include "umc_mutex.h"
#include "mfxplugin++.h"
#include "mfx_h265_encode_hw_brc.h"
#include "mfxvideo++int.h"
#include <mfx_task.h>

namespace MfxHwH265Encode
{

static const mfxPluginUID MFX_PLUGINID_HEVCE_HW = {{0x6f, 0xad, 0xc7, 0x91, 0xa0, 0xc2, 0xeb, 0x47, 0x9a, 0xb6, 0xdc, 0xd5, 0xea, 0x9d, 0xa3, 0x47}};

class MFXVideoENCODEH265_HW : public VideoENCODE
{
Expand Down Expand Up @@ -204,170 +202,6 @@ class MFXVideoENCODEH265_HW : public VideoENCODE

};

class Plugin : public MFXEncoderPlugin
{
public:
static MFXEncoderPlugin* Create()
{
return new Plugin(false);
}

static mfxStatus CreateByDispatcher(mfxPluginUID guid, mfxPlugin* mfxPlg)
{
if (memcmp(& guid , &MFX_PLUGINID_HEVCE_HW, sizeof(mfxPluginUID)))
{
return MFX_ERR_NOT_FOUND;
}

Plugin* tmp_pplg = 0;

try
{
tmp_pplg = new Plugin(false);
}
catch(std::bad_alloc&)
{
return MFX_ERR_MEMORY_ALLOC;
}
catch(...)
{
delete tmp_pplg;
return MFX_ERR_UNKNOWN;
}

*mfxPlg = tmp_pplg->m_adapter;
tmp_pplg->m_createdByDispatcher = true;

return MFX_ERR_NONE;
}

virtual mfxStatus PluginInit(mfxCoreInterface *core)
{
MFX_TRACE_INIT();
MFX_AUTO_LTRACE(MFX_TRACE_LEVEL_API, "Plugin::PluginInit");

MFX_CHECK_NULL_PTR1(core);

m_core = *core;

return MFX_ERR_NONE;
}
virtual mfxStatus PluginClose()
{
{
MFX_AUTO_LTRACE(MFX_TRACE_LEVEL_API, "Plugin::PluginClose");
if (m_createdByDispatcher)
Release();
}

MFX_TRACE_CLOSE();

return MFX_ERR_NONE;
}
virtual mfxStatus GetPluginParam(mfxPluginParam *par)
{
MFX_CHECK_NULL_PTR1(par);

par->PluginUID = MFX_PLUGINID_HEVCE_HW;
par->PluginVersion = 1;
par->ThreadPolicy = MFX_THREADPOLICY_SERIAL;
par->MaxThreadNum = 1;
par->APIVersion.Major = MFX_VERSION_MAJOR;
par->APIVersion.Minor = MFX_VERSION_MINOR;
par->Type = MFX_PLUGINTYPE_VIDEO_ENCODE;
par->CodecId = MFX_CODEC_HEVC;

return MFX_ERR_NONE;
}
virtual mfxStatus Execute(mfxThreadTask task, mfxU32 uid_p, mfxU32 uid_a)
{
if (m_pImpl.get())
return MFXVideoENCODEH265_HW::Execute((reinterpret_cast<void*>(m_pImpl.get())), task, uid_p, uid_a);
else
return MFX_ERR_NOT_INITIALIZED;
}
virtual mfxStatus FreeResources(mfxThreadTask /*task*/, mfxStatus /*sts*/)
{
return MFX_ERR_NONE;
}

virtual mfxStatus Init(mfxVideoParam *par)
{
mfxStatus sts;
m_pImpl.reset(new MFXVideoENCODEH265_HW(&m_core, &sts));
MFX_CHECK_STS(sts);
return m_pImpl->Init(par);
}
virtual mfxStatus QueryIOSurf(mfxVideoParam *par, mfxFrameAllocRequest *in, mfxFrameAllocRequest * /*out*/)
{
return MFXVideoENCODEH265_HW::QueryIOSurf(&m_core, par, in);
}
virtual mfxStatus Query(mfxVideoParam *in, mfxVideoParam *out)
{
return MFXVideoENCODEH265_HW::Query(&m_core, in, out);
}
virtual mfxStatus Reset(mfxVideoParam *par)
{
if (m_pImpl.get())
return m_pImpl->Reset(par);
else
return MFX_ERR_NOT_INITIALIZED;
}
virtual mfxStatus GetVideoParam(mfxVideoParam *par)
{
if (m_pImpl.get())
return m_pImpl->GetVideoParam(par);
else
return MFX_ERR_NOT_INITIALIZED;
}

virtual mfxStatus EncodeFrameSubmit(mfxEncodeCtrl *ctrl, mfxFrameSurface1 *surface, mfxBitstream *bs, mfxThreadTask *task)
{
if (m_pImpl.get())
return m_pImpl->EncodeFrameSubmit(ctrl, surface, bs, task);
else
return MFX_ERR_NOT_INITIALIZED;
}

virtual mfxU32 GetPluginType()
{
return MFX_PLUGINTYPE_VIDEO_ENCODE;
}

virtual void Release()
{
delete this;
}

virtual mfxStatus Close()
{
if (m_pImpl.get())
return m_pImpl->Close();
else
return MFX_ERR_NOT_INITIALIZED;
}

virtual mfxStatus SetAuxParams(void*, int)
{
return MFX_ERR_UNSUPPORTED;
}

protected:
explicit Plugin(bool CreateByDispatcher)
: m_createdByDispatcher(CreateByDispatcher)
, m_adapter(this)
, m_pImpl(nullptr)
{}
virtual ~Plugin()
{}

bool m_createdByDispatcher;
MFXPluginAdapter<MFXEncoderPlugin> m_adapter;
mfxCoreInterface m_core;
std::unique_ptr<MFXVideoENCODEH265_HW> m_pImpl;

};

} //MfxHwH265Encode

#endif
171 changes: 171 additions & 0 deletions _studio/hevce_hw/h265/include/mfx_h265_encode_plugin_hw.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
// Copyright (c) 2018 Intel Corporation
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#pragma once

#include "mfx_common.h"
#if defined(AS_HEVCE_PLUGIN)

#include "mfxplugin++.h"

namespace MfxHwH265Encode
{

static const mfxPluginUID MFX_PLUGINID_HEVCE_HW = { { 0x6f, 0xad, 0xc7, 0x91, 0xa0, 0xc2, 0xeb, 0x47, 0x9a, 0xb6, 0xdc, 0xd5, 0xea, 0x9d, 0xa3, 0x47 } };

class Plugin : public MFXEncoderPlugin
{
public:
static MFXEncoderPlugin* Create()
{
return new Plugin(false);
}
static mfxStatus CreateByDispatcher(mfxPluginUID guid, mfxPlugin* mfxPlg)
{
if (!mfxPlg)
{
return MFX_ERR_NULL_PTR;
}
if (memcmp(&guid, &MFX_PLUGINID_HEVCE_HW, sizeof(mfxPluginUID)))
{
return MFX_ERR_NOT_FOUND;
}

Plugin* tmp_pplg = nullptr;

try
{
tmp_pplg = new Plugin(false);
}
catch (std::bad_alloc&)
{
return MFX_ERR_MEMORY_ALLOC;
}
catch (...)
{
return MFX_ERR_UNKNOWN;
}

*mfxPlg = tmp_pplg->m_adapter;
tmp_pplg->m_createdByDispatcher = true;

return MFX_ERR_NONE;
}
virtual mfxStatus PluginInit(mfxCoreInterface * /*core*/)
{
MFX_TRACE_INIT();
MFX_AUTO_LTRACE(MFX_TRACE_LEVEL_API, "Plugin::PluginInit");
return MFX_ERR_NONE;
}
virtual mfxStatus PluginClose()
{
{
MFX_AUTO_LTRACE(MFX_TRACE_LEVEL_API, "Plugin::PluginClose");
if (m_createdByDispatcher)
Release();
}

MFX_TRACE_CLOSE();

return MFX_ERR_NONE;
}
virtual mfxStatus GetPluginParam(mfxPluginParam *par)
{
MFX_CHECK_NULL_PTR1(par);

par->PluginUID = MFX_PLUGINID_HEVCE_HW;
par->PluginVersion = 1;
par->ThreadPolicy = MFX_THREADPOLICY_SERIAL;
par->MaxThreadNum = 1;
par->APIVersion.Major = MFX_VERSION_MAJOR;
par->APIVersion.Minor = MFX_VERSION_MINOR;
par->Type = MFX_PLUGINTYPE_VIDEO_ENCODE;
par->CodecId = MFX_CODEC_HEVC;

return MFX_ERR_NONE;
}
virtual mfxStatus Execute(mfxThreadTask /*task*/, mfxU32 /*uid_p*/, mfxU32 /*uid_a*/)
{
return MFX_ERR_UNDEFINED_BEHAVIOR;
}
virtual mfxStatus FreeResources(mfxThreadTask /*task*/, mfxStatus /*sts*/)
{
return MFX_ERR_UNDEFINED_BEHAVIOR;
}

virtual mfxStatus Init(mfxVideoParam * /*par*/)
{
return MFX_ERR_UNDEFINED_BEHAVIOR;
}
virtual mfxStatus QueryIOSurf(mfxVideoParam * /*par*/, mfxFrameAllocRequest * /*in*/, mfxFrameAllocRequest * /*out*/)
{
return MFX_ERR_UNDEFINED_BEHAVIOR;
}
virtual mfxStatus Query(mfxVideoParam * /*in*/, mfxVideoParam * /*out*/)
{
return MFX_ERR_UNDEFINED_BEHAVIOR;
}
virtual mfxStatus Reset(mfxVideoParam * /*par*/)
{
return MFX_ERR_UNDEFINED_BEHAVIOR;
}
virtual mfxStatus GetVideoParam(mfxVideoParam * /*par*/)
{
return MFX_ERR_UNDEFINED_BEHAVIOR;
}

virtual mfxStatus EncodeFrameSubmit(mfxEncodeCtrl * /*ctrl*/, mfxFrameSurface1 * /*surface*/, mfxBitstream * /*bs*/, mfxThreadTask * /*task*/)
{
return MFX_ERR_UNDEFINED_BEHAVIOR;
}

virtual mfxU32 GetPluginType()
{
return MFX_PLUGINTYPE_VIDEO_ENCODE;
}

virtual void Release()
{
delete this;
}

virtual mfxStatus Close()
{
return MFX_ERR_UNDEFINED_BEHAVIOR;
}

virtual mfxStatus SetAuxParams(void*, int)
{
return MFX_ERR_UNSUPPORTED;
}
protected:
explicit Plugin(bool CreateByDispatcher)
: m_createdByDispatcher(CreateByDispatcher)
, m_adapter(this)
{}

virtual ~Plugin()
{}

bool m_createdByDispatcher;
MFXPluginAdapter<MFXEncoderPlugin> m_adapter;
};
} //MfxHwH265Encode

#endif//defined(AS_HEVCE_PLUGIN)
4 changes: 2 additions & 2 deletions _studio/hevce_hw/h265/src/export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
// SOFTWARE.

#include "mfx_common.h"
#if defined(MFX_ENABLE_H265_VIDEO_ENCODE)
#include "mfx_h265_encode_hw.h"
#if defined(MFX_ENABLE_H265_VIDEO_ENCODE) && defined(AS_HEVCE_PLUGIN)
#include "mfx_h265_encode_plugin_hw.h"
#include "plugin_version_linux.h"

#if defined(LINUX32)
Expand Down
Loading

0 comments on commit 8536960

Please sign in to comment.