提交 3e4bcf06 编写于 作者: S Seung-Woo Kim 提交者: jp9000

obs-qsv11: Add native obs-studio QSV encoder

上级 d56dc479
......@@ -9,6 +9,7 @@ if(WIN32)
add_subdirectory(win-capture)
add_subdirectory(decklink/win)
add_subdirectory(win-mf)
add_subdirectory(obs-qsv11)
elseif(APPLE)
add_subdirectory(coreaudio-encoder)
add_subdirectory(mac-avcapture)
......
project(obs-qsv11)
include_directories(libmfx/include/msdk/include)
include_directories(libmfx/include)
set(obs-qsv11_libmfx_SOURCES
libmfx/src/main.cpp
libmfx/src/mfx_critical_section.cpp
libmfx/src/mfx_dispatcher.cpp
libmfx/src/mfx_dispatcher_log.cpp
libmfx/src/mfx_dxva2_device.cpp
libmfx/src/mfx_function_table.cpp
libmfx/src/mfx_library_iterator.cpp
libmfx/src/mfx_load_dll.cpp
libmfx/src/mfx_load_plugin.cpp
libmfx/src/mfx_plugin_hive.cpp
libmfx/src/mfx_win_reg_key.cpp
)
set(obs-qsv11_libmfx_HEADERS
libmfx/include/msdk/include/mfxastructures.h
libmfx/include/msdk/include/mfxaudio.h
libmfx/include/msdk/include/mfxaudio++.h
libmfx/include/msdk/include/mfxcommon.h
libmfx/include/msdk/include/mfxdefs.h
libmfx/include/msdk/include/mfxjpeg.h
libmfx/include/msdk/include/mfxmvc.h
libmfx/include/msdk/include/mfxplugin.h
libmfx/include/msdk/include/mfxplugin++.h
libmfx/include/msdk/include/mfxsession.h
libmfx/include/msdk/include/mfxstructures.h
libmfx/include/msdk/include/mfxvideo.h
libmfx/include/msdk/include/mfxvideo++.h
libmfx/include/msdk/include/mfxvstructures.h
libmfx/include/mfx_critical_section.h
libmfx/include/mfx_dispatcher.h
libmfx/include/mfx_dispatcher_defs.h
libmfx/include/mfx_dispatcher_log.h
libmfx/include/mfx_dxva2_device.h
libmfx/include/mfx_exposed_functions_list.h
libmfx/include/mfx_library_iterator.h
libmfx/include/mfx_load_dll.h
libmfx/include/mfx_load_plugin.h
libmfx/include/mfx_plugin_hive.h
libmfx/include/mfx_vector.h
libmfx/include/mfx_win_reg_key.h
libmfx/include/mfxaudio_exposed_functions_list.h
)
set(obs-qsv11_SOURCES
common_directx11.cpp
common_utils.cpp
common_utils_windows.cpp
QSV_Encoder.cpp
QSV_Encoder_Internal.cpp
obs-qsv11.c
obs-qsv11-plugin-main.c)
set(obs-qsv11_HEADERS
bits/linux_defs.h
bits/windows_defs.h
common_directx11.h
common_utils.h
QSV_Encoder.h
QSV_Encoder_Internal.h)
add_library(obs-qsv11 MODULE
${obs-qsv11_SOURCES}
${obs-qsv11_HEADERS}
${obs-qsv11_libmfx_SOURCES}
${obs-qsv11_libmfx_HEADERS}
)
target_link_libraries(obs-qsv11
libobs
d3d11
dxgi
)
target_compile_definitions(obs-qsv11 PRIVATE DX11_D3D)
source_group("obs-qsv11\\Source Files" FILES ${obs-qsv11_SOURCES})
source_group("obs-qsv11\\Header Files" FILES ${obs-qsv11_HEADERS})
source_group("libmfx\\Source Files" FILES ${obs-qsv11_libmfx_SOURCES})
source_group("libmfx\\Header Files" FILES ${obs-qsv11_libmfx_HEADERS})
install_obs_plugin_with_data(obs-qsv11 data)
/*
This file is provided under a dual BSD/GPLv2 license. When using or
redistributing this file, you may do so under either license.
GPL LICENSE SUMMARY
Copyright(c) Oct. 2015 Intel Corporation.
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
Contact Information:
Seung-Woo Kim, seung-woo.kim@intel.com
705 5th Ave S #500, Seattle, WA 98104
BSD LICENSE
Copyright(c) <date> Intel Corporation.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
* Neither the name of Intel Corporation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// QSV_Encoder.cpp : Defines the exported functions for the DLL application.
//
#include "QSV_Encoder.h"
#include "QSV_Encoder_Internal.h"
#include <string>
QSV_Encoder_Internal *g_pEncoder = NULL;
mfxIMPL impl = MFX_IMPL_HARDWARE_ANY;
mfxVersion ver = {{0, 1}}; // for backward compatibility
void qsv_encoder_version(unsigned short *major, unsigned short *minor)
{
*major = ver.Major;
*minor = ver.Minor;
}
qsv_t *qsv_encoder_open(qsv_param_t *pParams)
{
QSV_Encoder_Internal *pEncoder = new QSV_Encoder_Internal(impl, ver);
mfxStatus sts = pEncoder->Open(pParams);
if (sts != MFX_ERR_NONE) {
delete pEncoder;
return NULL;
}
return (qsv_t *) pEncoder;
}
int qsv_encoder_headers(qsv_t *pContext, uint8_t **pSPS, uint8_t **pPPS,
uint16_t *pnSPS, uint16_t *pnPPS)
{
QSV_Encoder_Internal *pEncoder = (QSV_Encoder_Internal *)pContext;
pEncoder->GetSPSPPS(pSPS, pPPS, pnSPS, pnPPS);
return 0;
}
int qsv_encoder_encode(qsv_t * pContext, uint64_t ts, uint8_t *pDataY,
uint8_t *pDataUV, uint32_t strideY, uint32_t strideUV,
mfxBitstream **pBS)
{
QSV_Encoder_Internal *pEncoder = (QSV_Encoder_Internal *)pContext;
mfxStatus sts = MFX_ERR_NONE;
if (pDataY != NULL && pDataUV != NULL)
sts = pEncoder->Encode(ts, pDataY, pDataUV, strideY, strideUV,
pBS);
if (sts == MFX_ERR_NONE)
return 0;
else if (sts == MFX_ERR_MORE_DATA)
return 1;
else
return -1;
}
int qsv_encoder_close(qsv_t *pContext)
{
QSV_Encoder_Internal *pEncoder = (QSV_Encoder_Internal *)pContext;
delete pEncoder;
return 0;
}
/*
int qsv_param_default_preset(qsv_param_t *pParams, const char *preset,
const char *tune)
{
return 0;
}
int qsv_param_parse(qsv_param_t *, const char *name, const char *value)
{
return 0;
}
int qsv_param_apply_profile(qsv_param_t *, const char *profile)
{
return 0;
}
*/
int qsv_encoder_reconfig(qsv_t *pContext, qsv_param_t *pParams)
{
QSV_Encoder_Internal *pEncoder = (QSV_Encoder_Internal *)pContext;
mfxStatus sts = pEncoder->Reset(pParams);
if (sts == MFX_ERR_NONE)
return 0;
else
return -1;
}
enum qsv_cpu_platform qsv_get_cpu_platform()
{
using std::string;
int cpuInfo[4];
__cpuid(cpuInfo, 0);
string vendor;
vendor += string((char*)&cpuInfo[1], 4);
vendor += string((char*)&cpuInfo[3], 4);
vendor += string((char*)&cpuInfo[2], 4);
if (vendor != "GenuineIntel")
return QSV_CPU_PLATFORM_UNKNOWN;
__cpuid(cpuInfo, 1);
BYTE model = ((cpuInfo[0] >> 4) & 0xF) + ((cpuInfo[0] >> 12) & 0xF0);
BYTE family = ((cpuInfo[0] >> 8) & 0xF) + ((cpuInfo[0] >> 20) & 0xFF);
// See Intel 64 and IA-32 Architectures Software Developer's Manual,
// Vol 3C Table 35-1
if (family != 6)
return QSV_CPU_PLATFORM_UNKNOWN;
switch (model)
{
case 0x1C:
case 0x26:
case 0x27:
case 0x35:
case 0x36:
return QSV_CPU_PLATFORM_BNL;
case 0x2a:
case 0x2d:
return QSV_CPU_PLATFORM_SNB;
case 0x3a:
case 0x3e:
return QSV_CPU_PLATFORM_IVB;
case 0x37:
case 0x4A:
case 0x4D:
case 0x5A:
case 0x5D:
return QSV_CPU_PLATFORM_SLM;
case 0x4C:
return QSV_CPU_PLATFORM_CHT;
case 0x3c:
case 0x3f:
case 0x45:
case 0x46:
return QSV_CPU_PLATFORM_HSW;
}
//assume newer revisions are at least as capable as haswell
return QSV_CPU_PLATFORM_INTEL;
}
/*
This file is provided under a dual BSD/GPLv2 license. When using or
redistributing this file, you may do so under either license.
GPL LICENSE SUMMARY
Copyright(c) Oct. 2015 Intel Corporation.
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
Contact Information:
Seung-Woo Kim, seung-woo.kim@intel.com
705 5th Ave S #500, Seattle, WA 98104
BSD LICENSE
Copyright(c) <date> Intel Corporation.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
* Neither the name of Intel Corporation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include <Windows.h>
#include "mfxstructures.h"
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
struct qsv_rate_control_info {
const char *name;
bool haswell_or_greater;
};
static const struct qsv_rate_control_info qsv_ratecontrols[] = {
{"CBR", false},
{"VBR", false},
{"VCM", true},
{"CQP", false},
{"AVBR", false},
{"ICQ", true},
{"LA_ICQ", true},
{"LA", true},
{0, false}
};
static const char * const qsv_profile_names[] = {
"high",
"main",
"baseline",
0
};
static const char * const qsv_usage_names[] = {
"quality",
"balanced",
"speed",
0
};
typedef struct qsv_t qsv_t;
typedef struct
{
mfxU16 nTargetUsage; /* 1 through 7, 1 being best quality and 7
being the best speed */
mfxU16 nWidth; /* source picture width */
mfxU16 nHeight; /* source picture height */
mfxU16 nAsyncDepth;
mfxU16 nFpsNum;
mfxU16 nFpsDen;
mfxU16 nTargetBitRate;
mfxU16 nMaxBitRate;
mfxU16 nCodecProfile;
mfxU16 nRateControl;
mfxU16 nAccuracy;
mfxU16 nConvergence;
mfxU16 nQPI;
mfxU16 nQPP;
mfxU16 nQPB;
mfxU16 nLADEPTH;
mfxU16 nKeyIntSec;
mfxU16 nbFrames;
mfxU16 nICQQuality;
} qsv_param_t;
enum qsv_cpu_platform {
QSV_CPU_PLATFORM_UNKNOWN,
QSV_CPU_PLATFORM_BNL,
QSV_CPU_PLATFORM_SNB,
QSV_CPU_PLATFORM_IVB,
QSV_CPU_PLATFORM_SLM,
QSV_CPU_PLATFORM_CHT,
QSV_CPU_PLATFORM_HSW,
QSV_CPU_PLATFORM_INTEL
};
int qsv_encoder_close(qsv_t *);
int qsv_param_parse(qsv_param_t *, const char *name, const char *value);
int qsv_param_apply_profile(qsv_param_t *, const char *profile);
int qsv_param_default_preset(qsv_param_t *, const char *preset,
const char *tune);
int qsv_encoder_reconfig(qsv_t *, qsv_param_t *);
void qsv_encoder_version(unsigned short *major, unsigned short *minor);
qsv_t *qsv_encoder_open( qsv_param_t * );
int qsv_encoder_encode(qsv_t *, uint64_t, uint8_t *, uint8_t *, uint32_t,
uint32_t, mfxBitstream **pBS);
int qsv_encoder_headers(qsv_t *, uint8_t **pSPS, uint8_t **pPPS,
uint16_t *pnSPS, uint16_t *pnPPS);
enum qsv_cpu_platform qsv_get_cpu_platform();
#ifdef __cplusplus
}
#endif
/*
This file is provided under a dual BSD/GPLv2 license. When using or
redistributing this file, you may do so under either license.
GPL LICENSE SUMMARY
Copyright(c) Oct. 2015 Intel Corporation.
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
Contact Information:
Seung-Woo Kim, seung-woo.kim@intel.com
705 5th Ave S #500, Seattle, WA 98104
BSD LICENSE
Copyright(c) <date> Intel Corporation.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
* Neither the name of Intel Corporation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "QSV_Encoder_Internal.h"
#include "QSV_Encoder.h"
#include "mfxastructures.h"
#include "mfxvideo++.h"
#include <VersionHelpers.h>
#include <obs-module.h>
#define do_log(level, format, ...) \
blog(level, "[qsv encoder: '%s'] " format, \
"msdk_impl", ##__VA_ARGS__)
#define warn(format, ...) do_log(LOG_WARNING, format, ##__VA_ARGS__)
#define info(format, ...) do_log(LOG_INFO, format, ##__VA_ARGS__)
#define debug(format, ...) do_log(LOG_DEBUG, format, ##__VA_ARGS__)
QSV_Encoder_Internal::QSV_Encoder_Internal(mfxIMPL& impl, mfxVersion& version) :
m_pmfxENC(NULL),
m_nSPSBufferSize(100),
m_nPPSBufferSize(100),
m_nTaskPool(0),
m_pTaskPool(NULL),
m_nTaskIdx(0),
m_nFirstSyncTask(0)
{
mfxIMPL tempImpl;
mfxStatus sts;
m_bIsWindows8OrGreater = IsWindows8OrGreater();
m_bUseD3D11 = false;
if (m_bIsWindows8OrGreater) {
tempImpl = impl | MFX_IMPL_VIA_D3D11;
sts = m_session.Init(tempImpl, &version);
if (sts == MFX_ERR_NONE) {
m_session.QueryVersion(&version);
m_session.Close();
// Use D3D11 surface
// m_bUseD3D11 = ((version.Major > 1) ||
// (version.Major == 1 && version.Minor >= 8));
m_bUseD3D11 = true;
if (m_bUseD3D11)
blog(LOG_INFO, "\timpl: D3D11\n"
"\tsurf: D3D11");
else
blog(LOG_INFO, "\timpl: D3D11\n"
"\tsurf: SysMem");
m_impl = tempImpl;
m_ver = version;
return;
}
}
// Either windows 7 or D3D11 failed at this point.
tempImpl = impl | MFX_IMPL_VIA_D3D9;
sts = m_session.Init(tempImpl, &version);
if (sts == MFX_ERR_NONE) {
m_session.QueryVersion(&version);
m_session.Close();
blog(LOG_INFO, "\timpl: D3D09\n"
"\tsurf: SysMem");
m_impl = tempImpl;
m_ver = version;
}
}
QSV_Encoder_Internal::~QSV_Encoder_Internal()
{
ClearData();
}
mfxStatus QSV_Encoder_Internal::Open(qsv_param_t * pParams)
{
mfxStatus sts = MFX_ERR_NONE;
if (m_bUseD3D11)
// Use D3D11 surface
sts = Initialize(m_impl, m_ver, &m_session, &m_mfxAllocator);
else
// Use system memory
sts = Initialize(m_impl, m_ver, &m_session, NULL);
if (sts == MFX_ERR_NONE)
m_pmfxENC = new MFXVideoENCODE(m_session);
InitParams(pParams);
sts = m_pmfxENC->Query(&m_mfxEncParams, &m_mfxEncParams);
MSDK_IGNORE_MFX_STS(sts, MFX_WRN_INCOMPATIBLE_VIDEO_PARAM);
MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);
sts = AllocateSurfaces();
MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);
sts = m_pmfxENC->Init(&m_mfxEncParams);
MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);
sts = GetVideoParam();
MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);
sts = InitBitstream();
MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);
return sts;
}
bool QSV_Encoder_Internal::InitParams(qsv_param_t * pParams)
{
memset(&m_mfxEncParams, 0, sizeof(m_mfxEncParams));
m_mfxEncParams.mfx.CodecId = MFX_CODEC_AVC;
m_mfxEncParams.mfx.GopOptFlag = MFX_GOP_STRICT;
m_mfxEncParams.mfx.NumSlice = 1;
m_mfxEncParams.mfx.TargetUsage = pParams->nTargetUsage;
m_mfxEncParams.mfx.CodecProfile = pParams->nCodecProfile;
m_mfxEncParams.mfx.FrameInfo.FrameRateExtN = pParams->nFpsNum;
m_mfxEncParams.mfx.FrameInfo.FrameRateExtD = pParams->nFpsDen;
m_mfxEncParams.mfx.FrameInfo.FourCC = MFX_FOURCC_NV12;
m_mfxEncParams.mfx.FrameInfo.ChromaFormat = MFX_CHROMAFORMAT_YUV420;
m_mfxEncParams.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_PROGRESSIVE;
m_mfxEncParams.mfx.FrameInfo.CropX = 0;
m_mfxEncParams.mfx.FrameInfo.CropY = 0;
m_mfxEncParams.mfx.FrameInfo.CropW = pParams->nWidth;
m_mfxEncParams.mfx.FrameInfo.CropH = pParams->nHeight;
m_mfxEncParams.mfx.RateControlMethod = pParams->nRateControl;
switch (pParams->nRateControl) {
case MFX_RATECONTROL_CBR:
m_mfxEncParams.mfx.TargetKbps = pParams->nTargetBitRate;
break;
case MFX_RATECONTROL_VBR:
case MFX_RATECONTROL_VCM:
m_mfxEncParams.mfx.TargetKbps = pParams->nTargetBitRate;
m_mfxEncParams.mfx.MaxKbps = pParams->nMaxBitRate;
break;
case MFX_RATECONTROL_CQP:
m_mfxEncParams.mfx.QPI = pParams->nQPI;
m_mfxEncParams.mfx.QPB = pParams->nQPB;
m_mfxEncParams.mfx.QPP = pParams->nQPP;
break;
case MFX_RATECONTROL_AVBR:
m_mfxEncParams.mfx.TargetKbps = pParams->nTargetBitRate;
m_mfxEncParams.mfx.Accuracy = pParams->nAccuracy;
m_mfxEncParams.mfx.Convergence = pParams->nConvergence;
break;
case MFX_RATECONTROL_ICQ:
m_mfxEncParams.mfx.ICQQuality = pParams->nICQQuality;
break;
case MFX_RATECONTROL_LA:
m_mfxEncParams.mfx.TargetKbps = pParams->nTargetBitRate;
break;
case MFX_RATECONTROL_LA_ICQ:
m_mfxEncParams.mfx.ICQQuality = pParams->nICQQuality;
break;
default:
break;
}
m_mfxEncParams.AsyncDepth = pParams->nAsyncDepth;
m_mfxEncParams.mfx.GopPicSize = (mfxU16)(pParams->nKeyIntSec *
pParams->nFpsNum / (float)pParams->nFpsDen);
static mfxExtBuffer* extendedBuffers[2];
int iBuffers = 0;
if (pParams->nAsyncDepth == 1) {
m_mfxEncParams.mfx.NumRefFrame = 1;
// low latency, I and P frames only
m_mfxEncParams.mfx.GopRefDist = 1;
memset(&m_co, 0, sizeof(mfxExtCodingOption));
m_co.Header.BufferId = MFX_EXTBUFF_CODING_OPTION;
m_co.Header.BufferSz = sizeof(mfxExtCodingOption);
m_co.MaxDecFrameBuffering = 1;
extendedBuffers[iBuffers++] = (mfxExtBuffer*)&m_co;
}
else
m_mfxEncParams.mfx.GopRefDist = pParams->nbFrames + 1;
if (pParams->nRateControl == MFX_RATECONTROL_LA_ICQ ||
pParams->nRateControl == MFX_RATECONTROL_LA) {
memset(&m_co2, 0, sizeof(mfxExtCodingOption2));
m_co2.Header.BufferId = MFX_EXTBUFF_CODING_OPTION;
m_co2.Header.BufferSz = sizeof(m_co2);
m_co2.LookAheadDepth = pParams->nLADEPTH;
extendedBuffers[iBuffers++] = (mfxExtBuffer*)& m_co2;
}
if (iBuffers > 0) {
m_mfxEncParams.ExtParam = extendedBuffers;
m_mfxEncParams.NumExtParam = (mfxU16)iBuffers;
}
// Width must be a multiple of 16
// Height must be a multiple of 16 in case of frame picture and a
// multiple of 32 in case of field picture
m_mfxEncParams.mfx.FrameInfo.Width = MSDK_ALIGN16(pParams->nWidth);
m_mfxEncParams.mfx.FrameInfo.Height = MSDK_ALIGN16(pParams->nHeight);
if (m_bUseD3D11)
m_mfxEncParams.IOPattern = MFX_IOPATTERN_IN_VIDEO_MEMORY;
else
m_mfxEncParams.IOPattern = MFX_IOPATTERN_IN_SYSTEM_MEMORY;
return true;
}
mfxStatus QSV_Encoder_Internal::AllocateSurfaces()
{
// Query number of required surfaces for encoder
mfxFrameAllocRequest EncRequest;
memset(&EncRequest, 0, sizeof(EncRequest));
mfxStatus sts = m_pmfxENC->QueryIOSurf(&m_mfxEncParams, &EncRequest);
MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);
EncRequest.Type |= WILL_WRITE;
// SNB hack. On some SNB, it seems to require more surfaces
EncRequest.NumFrameSuggested += m_mfxEncParams.AsyncDepth;
// Allocate required surfaces
if (m_bUseD3D11) {
sts = m_mfxAllocator.Alloc(m_mfxAllocator.pthis, &EncRequest,
&m_mfxResponse);
MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);
m_nSurfNum = m_mfxResponse.NumFrameActual;
m_pmfxSurfaces = new mfxFrameSurface1 *[m_nSurfNum];
MSDK_CHECK_POINTER(m_pmfxSurfaces, MFX_ERR_MEMORY_ALLOC);
for (int i = 0; i < m_nSurfNum; i++) {
m_pmfxSurfaces[i] = new mfxFrameSurface1;
memset(m_pmfxSurfaces[i], 0, sizeof(mfxFrameSurface1));
memcpy(&(m_pmfxSurfaces[i]->Info),
&(m_mfxEncParams.mfx.FrameInfo),
sizeof(mfxFrameInfo));
m_pmfxSurfaces[i]->Data.MemId = m_mfxResponse.mids[i];
}
}
else {
mfxU16 width = (mfxU16)MSDK_ALIGN32(EncRequest.Info.Width);
mfxU16 height = (mfxU16)MSDK_ALIGN32(EncRequest.Info.Height);
mfxU8 bitsPerPixel = 12;
mfxU32 surfaceSize = width * height * bitsPerPixel / 8;
m_nSurfNum = EncRequest.NumFrameSuggested;
m_pmfxSurfaces = new mfxFrameSurface1 *[m_nSurfNum];
for (int i = 0; i < m_nSurfNum; i++) {
m_pmfxSurfaces[i] = new mfxFrameSurface1;
memset(m_pmfxSurfaces[i], 0, sizeof(mfxFrameSurface1));
memcpy(&(m_pmfxSurfaces[i]->Info),
&(m_mfxEncParams.mfx.FrameInfo),
sizeof(mfxFrameInfo));
mfxU8* pSurface = (mfxU8*) new mfxU8[surfaceSize];
m_pmfxSurfaces[i]->Data.Y = pSurface;
m_pmfxSurfaces[i]->Data.U = pSurface + width * height;
m_pmfxSurfaces[i]->Data.V = pSurface + width * height + 1;
m_pmfxSurfaces[i]->Data.Pitch = width;
}
}
blog(LOG_INFO, "\tm_nSurfNum: %d", m_nSurfNum);
return sts;
}
mfxStatus QSV_Encoder_Internal::GetVideoParam()
{
memset(&m_parameter, 0, sizeof(m_parameter));
mfxExtCodingOptionSPSPPS opt;
memset(&m_parameter, 0, sizeof(m_parameter));
opt.Header.BufferId = MFX_EXTBUFF_CODING_OPTION_SPSPPS;
opt.Header.BufferSz = sizeof(mfxExtCodingOptionSPSPPS);
static mfxExtBuffer* extendedBuffers[1];
extendedBuffers[0] = (mfxExtBuffer*)& opt;
m_parameter.ExtParam = extendedBuffers;
m_parameter.NumExtParam = 1;
opt.SPSBuffer = m_SPSBuffer;
opt.PPSBuffer = m_PPSBuffer;
opt.SPSBufSize = 100; // m_nSPSBufferSize;
opt.PPSBufSize = 100; // m_nPPSBufferSize;
mfxStatus sts = m_pmfxENC->GetVideoParam(&m_parameter);
MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);
m_nSPSBufferSize = opt.SPSBufSize;
m_nPPSBufferSize = opt.PPSBufSize;
return sts;
}
void QSV_Encoder_Internal::GetSPSPPS(mfxU8 **pSPSBuf, mfxU8 **pPPSBuf,
mfxU16 *pnSPSBuf, mfxU16 *pnPPSBuf)
{
*pSPSBuf = m_SPSBuffer;
*pPPSBuf = m_PPSBuffer;
*pnSPSBuf = m_nSPSBufferSize;
*pnPPSBuf = m_nPPSBufferSize;
}
mfxStatus QSV_Encoder_Internal::InitBitstream()
{
m_nTaskPool = m_parameter.AsyncDepth;
m_nFirstSyncTask = 0;
m_pTaskPool = new Task[m_nTaskPool];
memset(m_pTaskPool, 0, sizeof(Task) * m_nTaskPool);
for (int i = 0; i < m_nTaskPool; i++) {
m_pTaskPool[i].mfxBS.MaxLength =
m_parameter.mfx.BufferSizeInKB * 1000;
m_pTaskPool[i].mfxBS.Data =
new mfxU8[m_pTaskPool[i].mfxBS.MaxLength];
m_pTaskPool[i].mfxBS.DataOffset = 0;
m_pTaskPool[i].mfxBS.DataLength = 0;
MSDK_CHECK_POINTER(m_pTaskPool[i].mfxBS.Data,
MFX_ERR_MEMORY_ALLOC);
}
memset(&m_outBitstream, 0, sizeof(mfxBitstream));
m_outBitstream.MaxLength = m_parameter.mfx.BufferSizeInKB * 1000;
m_outBitstream.Data = new mfxU8[m_outBitstream.MaxLength];
m_outBitstream.DataOffset = 0;
m_outBitstream.DataLength = 0;
blog(LOG_INFO, "\tm_nTaskPool: %d", m_nTaskPool);
return MFX_ERR_NONE;
}
mfxStatus QSV_Encoder_Internal::LoadNV12(mfxFrameSurface1 *pSurface,
uint8_t *pDataY, uint8_t *pDataUV, uint32_t strideY,
uint32_t strideUV)
{
mfxU16 w, h, i, pitch;
mfxU8* ptr;
mfxFrameInfo* pInfo = &pSurface->Info;
mfxFrameData* pData = &pSurface->Data;
if (pInfo->CropH > 0 && pInfo->CropW > 0)
{
w = pInfo->CropW;
h = pInfo->CropH;
}
else
{
w = pInfo->Width;
h = pInfo->Height;
}
pitch = pData->Pitch;
ptr = pData->Y + pInfo->CropX + pInfo->CropY * pData->Pitch;
// load Y plane
for (i = 0; i < h; i++)
memcpy(ptr + i * pitch, pDataY + i * strideY, w);
// load UV plane
h /= 2;
ptr = pData->UV + pInfo->CropX + (pInfo->CropY / 2) * pitch;
for (i = 0; i < h; i++)
memcpy(ptr + i * pitch, pDataUV + i * strideUV, w);
return MFX_ERR_NONE;
}
int QSV_Encoder_Internal::GetFreeTaskIndex(Task* pTaskPool, mfxU16 nPoolSize)
{
if (pTaskPool)
for (int i = 0; i < nPoolSize; i++)
if (!pTaskPool[i].syncp)
return i;
return MFX_ERR_NOT_FOUND;
}
mfxStatus QSV_Encoder_Internal::Encode(uint64_t ts, uint8_t *pDataY,
uint8_t *pDataUV, uint32_t strideY, uint32_t strideUV,
mfxBitstream **pBS)
{
mfxStatus sts = MFX_ERR_NONE;
*pBS = NULL;
int nTaskIdx = GetFreeTaskIndex(m_pTaskPool, m_nTaskPool);
#if 0
info("MSDK Encode:\n"
"\tTaskIndex: %d",
nTaskIdx);
#endif
int nSurfIdx = GetFreeSurfaceIndex(m_pmfxSurfaces, m_nSurfNum);
#if 0
info("MSDK Encode:\n"
"\tnSurfIdx: %d",
nSurfIdx);
#endif
while (MFX_ERR_NOT_FOUND == nTaskIdx || MFX_ERR_NOT_FOUND == nSurfIdx) {
// No more free tasks or surfaces, need to sync
sts = m_session.SyncOperation(m_pTaskPool[m_nFirstSyncTask].syncp,
60000);
MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);
mfxU8 *pTemp = m_outBitstream.Data;
memcpy(&m_outBitstream, &m_pTaskPool[m_nFirstSyncTask].mfxBS,
sizeof(mfxBitstream));
m_pTaskPool[m_nFirstSyncTask].mfxBS.Data = pTemp;
m_pTaskPool[m_nFirstSyncTask].mfxBS.DataLength = 0;
m_pTaskPool[m_nFirstSyncTask].mfxBS.DataOffset = 0;
m_pTaskPool[m_nFirstSyncTask].syncp = NULL;
nTaskIdx = m_nFirstSyncTask;
m_nFirstSyncTask = (m_nFirstSyncTask + 1) % m_nTaskPool;
*pBS = &m_outBitstream;
#if 0
info("MSDK Encode:\n"
"\tnew FirstSyncTask: %d\n"
"\tTaskIndex: %d",
m_nFirstSyncTask,
nTaskIdx);
#endif
nSurfIdx = GetFreeSurfaceIndex(m_pmfxSurfaces, m_nSurfNum);
#if 0
info("MSDK Encode:\n"
"\tnSurfIdx: %d",
nSurfIdx);
#endif
}
mfxFrameSurface1 *pSurface = m_pmfxSurfaces[nSurfIdx];
if (m_bUseD3D11)
sts = m_mfxAllocator.Lock(m_mfxAllocator.pthis,
pSurface->Data.MemId, &(pSurface->Data));
sts = LoadNV12(pSurface, pDataY, pDataUV, strideY, strideUV);
pSurface->Data.TimeStamp = ts;
if (m_bUseD3D11)
sts = m_mfxAllocator.Unlock(m_mfxAllocator.pthis,
pSurface->Data.MemId, &(pSurface->Data));
MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);
for (;;) {
// Encode a frame asychronously (returns immediately)
sts = m_pmfxENC->EncodeFrameAsync(NULL, pSurface,
&m_pTaskPool[nTaskIdx].mfxBS,
&m_pTaskPool[nTaskIdx].syncp);
if (MFX_ERR_NONE < sts && !m_pTaskPool[nTaskIdx].syncp) {
// Repeat the call if warning and no output
if (MFX_WRN_DEVICE_BUSY == sts)
MSDK_SLEEP(1); // Wait if device is busy, then repeat the same call
} else if (MFX_ERR_NONE < sts && m_pTaskPool[nTaskIdx].syncp) {
sts = MFX_ERR_NONE; // Ignore warnings if output is available
break;
} else if (MFX_ERR_NOT_ENOUGH_BUFFER == sts) {
// Allocate more bitstream buffer memory here if needed...
break;
} else
break;
}
return sts;
}
mfxStatus QSV_Encoder_Internal::Drain()
{
mfxStatus sts = MFX_ERR_NONE;
while (m_pTaskPool[m_nFirstSyncTask].syncp) {
sts = m_session.SyncOperation(m_pTaskPool[m_nFirstSyncTask].syncp, 60000);
MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);
m_pTaskPool[m_nFirstSyncTask].syncp = NULL;
m_nFirstSyncTask = (m_nFirstSyncTask + 1) % m_nTaskPool;
}
return sts;
}
mfxStatus QSV_Encoder_Internal::ClearData()
{
mfxStatus sts = MFX_ERR_NONE;
sts = Drain();
sts = m_pmfxENC->Close();
if (m_bUseD3D11)
m_mfxAllocator.Free(m_mfxAllocator.pthis, &m_mfxResponse);
for (int i = 0; i < m_nSurfNum; i++) {
if (!m_bUseD3D11)
delete m_pmfxSurfaces[i]->Data.Y;
delete m_pmfxSurfaces[i];
}
MSDK_SAFE_DELETE_ARRAY(m_pmfxSurfaces);
for (int i = 0; i < m_nTaskPool; i++)
delete m_pTaskPool[i].mfxBS.Data;
MSDK_SAFE_DELETE_ARRAY(m_pTaskPool);
delete m_outBitstream.Data;
if (m_pmfxENC != NULL) {
delete m_pmfxENC;
m_pmfxENC = NULL;
}
if (m_bUseD3D11)
Release();
m_session.Close();
return sts;
}
mfxStatus QSV_Encoder_Internal::Reset(qsv_param_t *pParams)
{
mfxStatus sts = ClearData();
MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);
sts = Open(pParams);
MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);
return sts;
}
/*
This file is provided under a dual BSD/GPLv2 license. When using or
redistributing this file, you may do so under either license.
GPL LICENSE SUMMARY
Copyright(c) Oct. 2015 Intel Corporation.
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
Contact Information:
Seung-Woo Kim, seung-woo.kim@intel.com
705 5th Ave S #500, Seattle, WA 98104
BSD LICENSE
Copyright(c) <date> Intel Corporation.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
* Neither the name of Intel Corporation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include "mfxastructures.h"
#include "mfxvideo++.h"
#include "QSV_Encoder.h"
#include "common_utils.h"
class QSV_Encoder_Internal
{
public:
QSV_Encoder_Internal(mfxIMPL& impl, mfxVersion& version);
~QSV_Encoder_Internal();
mfxStatus Open(qsv_param_t * pParams);
void GetSPSPPS(mfxU8 **pSPSBuf, mfxU8 **pPPSBuf,
mfxU16 *pnSPSBuf, mfxU16 *pnPPSBuf);
mfxStatus Encode(uint64_t ts, uint8_t *pDataY, uint8_t *pDataUV,
uint32_t strideY, uint32_t strideUV, mfxBitstream
**pBS);
mfxStatus ClearData();
mfxStatus Reset(qsv_param_t *pParams);
protected:
bool InitParams(qsv_param_t * pParams);
mfxStatus AllocateSurfaces();
mfxStatus GetVideoParam();
mfxStatus InitBitstream();
mfxStatus LoadNV12(mfxFrameSurface1 *pSurface, uint8_t *pDataY,
uint8_t *pDataUV, uint32_t strideY, uint32_t strideUV);
mfxStatus Drain();
int GetFreeTaskIndex(Task* pTaskPool, mfxU16 nPoolSize);
private:
mfxIMPL m_impl;
mfxVersion m_ver;
MFXVideoSession m_session;
mfxFrameAllocator m_mfxAllocator;
mfxVideoParam m_mfxEncParams;
mfxFrameAllocResponse m_mfxResponse;
mfxFrameSurface1** m_pmfxSurfaces;
mfxU16 m_nSurfNum;
MFXVideoENCODE* m_pmfxENC;
mfxU8 m_SPSBuffer[100];
mfxU8 m_PPSBuffer[100];
mfxU16 m_nSPSBufferSize;
mfxU16 m_nPPSBufferSize;
mfxVideoParam m_parameter;
mfxExtCodingOption2 m_co2;
mfxExtCodingOption m_co;
mfxU16 m_nTaskPool;
Task* m_pTaskPool;
int m_nTaskIdx;
int m_nFirstSyncTask;
mfxBitstream m_outBitstream;
bool m_bIsWindows8OrGreater;
bool m_bUseD3D11;
};
/*****************************************************************************
INTEL CORPORATION PROPRIETARY INFORMATION
This software is supplied under the terms of a license agreement or
nondisclosure agreement with Intel Corporation and may not be copied
or disclosed except in accordance with the terms of that agreement.
Copyright(c) 2005-2014 Intel Corporation. All Rights Reserved.
*****************************************************************************/
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#define MSDK_FOPEN(FH, FN, M) { FH=fopen(FN,M); }
#define MSDK_SLEEP(X) { usleep(1000*(X)); }
typedef timespec mfxTime;
/*****************************************************************************
INTEL CORPORATION PROPRIETARY INFORMATION
This software is supplied under the terms of a license agreement or
nondisclosure agreement with Intel Corporation and may not be copied
or disclosed except in accordance with the terms of that agreement.
Copyright(c) 2005-2014 Intel Corporation. All Rights Reserved.
*****************************************************************************/
#include <windows.h>
#define MSDK_FOPEN(FH, FN, M) { fopen_s(&FH, FN, M); }
#define MSDK_SLEEP(X) { Sleep(X); }
typedef LARGE_INTEGER mfxTime;
/*****************************************************************************
INTEL CORPORATION PROPRIETARY INFORMATION
This software is supplied under the terms of a license agreement or
nondisclosure agreement with Intel Corporation and may not be copied
or disclosed except in accordance with the terms of that agreement.
Copyright(c) 2005-2014 Intel Corporation. All Rights Reserved.
*****************************************************************************/
#include "common_directx11.h"
#include<map>
ID3D11Device* g_pD3D11Device;
ID3D11DeviceContext* g_pD3D11Ctx;
IDXGIFactory2* g_pDXGIFactory;
IDXGIAdapter* g_pAdapter;
std::map<mfxMemId*, mfxHDL> allocResponses;
std::map<mfxHDL, mfxFrameAllocResponse> allocDecodeResponses;
std::map<mfxHDL, int> allocDecodeRefCount;
typedef struct {
mfxMemId memId;
mfxMemId memIdStage;
mfxU16 rw;
} CustomMemId;
const struct {
mfxIMPL impl; // actual implementation
mfxU32 adapterID; // device adapter number
} implTypes[] = {
{MFX_IMPL_HARDWARE, 0},
{MFX_IMPL_HARDWARE2, 1},
{MFX_IMPL_HARDWARE3, 2},
{MFX_IMPL_HARDWARE4, 3}
};
// =================================================================
// DirectX functionality required to manage DX11 device and surfaces
//
IDXGIAdapter* GetIntelDeviceAdapterHandle(mfxSession session)
{
mfxU32 adapterNum = 0;
mfxIMPL impl;
MFXQueryIMPL(session, &impl);
mfxIMPL baseImpl = MFX_IMPL_BASETYPE(impl); // Extract Media SDK base implementation type
// get corresponding adapter number
for (mfxU8 i = 0; i < sizeof(implTypes)/sizeof(implTypes[0]); i++) {
if (implTypes[i].impl == baseImpl) {
adapterNum = implTypes[i].adapterID;
break;
}
}
HRESULT hres = CreateDXGIFactory(__uuidof(IDXGIFactory2), (void**)(&g_pDXGIFactory) );
if (FAILED(hres)) return NULL;
IDXGIAdapter* adapter;
hres = g_pDXGIFactory->EnumAdapters(adapterNum, &adapter);
if (FAILED(hres)) return NULL;
return adapter;
}
// Create HW device context
mfxStatus CreateHWDevice(mfxSession session, mfxHDL* deviceHandle, HWND hWnd, bool bCreateSharedHandles)
{
//Note: not using bCreateSharedHandles for DX11 -- for API consistency only
hWnd; // Window handle not required by DX11 since we do not showcase rendering.
bCreateSharedHandles; // For rendering, not used here. Just for consistencies sake.
HRESULT hres = S_OK;
static D3D_FEATURE_LEVEL FeatureLevels[] = {
D3D_FEATURE_LEVEL_11_1,
D3D_FEATURE_LEVEL_11_0,
D3D_FEATURE_LEVEL_10_1,
D3D_FEATURE_LEVEL_10_0
};
D3D_FEATURE_LEVEL pFeatureLevelsOut;
g_pAdapter = GetIntelDeviceAdapterHandle(session);
if (NULL == g_pAdapter)
return MFX_ERR_DEVICE_FAILED;
UINT dxFlags = 0;
//UINT dxFlags = D3D11_CREATE_DEVICE_DEBUG;
hres = D3D11CreateDevice( g_pAdapter,
D3D_DRIVER_TYPE_UNKNOWN,
NULL,
dxFlags,
FeatureLevels,
(sizeof(FeatureLevels) / sizeof(FeatureLevels[0])),
D3D11_SDK_VERSION,
&g_pD3D11Device,
&pFeatureLevelsOut,
&g_pD3D11Ctx);
if (FAILED(hres))
return MFX_ERR_DEVICE_FAILED;
// turn on multithreading for the DX11 context
CComQIPtr<ID3D10Multithread> p_mt(g_pD3D11Ctx);
if (p_mt)
p_mt->SetMultithreadProtected(true);
else
return MFX_ERR_DEVICE_FAILED;
*deviceHandle = (mfxHDL)g_pD3D11Device;
return MFX_ERR_NONE;
}
void SetHWDeviceContext(CComPtr<ID3D11DeviceContext> devCtx)
{
g_pD3D11Ctx = devCtx;
devCtx->GetDevice(&g_pD3D11Device);
}
// Free HW device context
void CleanupHWDevice()
{
if (g_pAdapter)
{
g_pAdapter->Release();
g_pAdapter = NULL;
}
if (g_pD3D11Device)
{
g_pD3D11Device->Release();
g_pD3D11Device = NULL;
}
if (g_pD3D11Ctx)
{
g_pD3D11Ctx->Release();
g_pD3D11Ctx = NULL;
}
if (g_pDXGIFactory)
{
g_pDXGIFactory->Release();
g_pDXGIFactory = NULL;
}
}
CComPtr<ID3D11DeviceContext> GetHWDeviceContext()
{
return g_pD3D11Ctx;
}
/* (Hugh) Functions currently unused */
#if 0
void ClearYUVSurfaceD3D(mfxMemId memId)
{
// TBD
}
void ClearRGBSurfaceD3D(mfxMemId memId)
{
// TBD
}
#endif
//
// Intel Media SDK memory allocator entrypoints....
//
mfxStatus _simple_alloc(mfxFrameAllocRequest* request, mfxFrameAllocResponse* response)
{
HRESULT hRes;
// Determine surface format
DXGI_FORMAT format;
if (MFX_FOURCC_NV12 == request->Info.FourCC)
format = DXGI_FORMAT_NV12;
else if (MFX_FOURCC_RGB4 == request->Info.FourCC)
format = DXGI_FORMAT_B8G8R8A8_UNORM;
else if (MFX_FOURCC_YUY2== request->Info.FourCC)
format = DXGI_FORMAT_YUY2;
else if (MFX_FOURCC_P8 == request->Info.FourCC ) //|| MFX_FOURCC_P8_TEXTURE == request->Info.FourCC
format = DXGI_FORMAT_P8;
else
format = DXGI_FORMAT_UNKNOWN;
if (DXGI_FORMAT_UNKNOWN == format)
return MFX_ERR_UNSUPPORTED;
// Allocate custom container to keep texture and stage buffers for each surface
// Container also stores the intended read and/or write operation.
CustomMemId** mids = (CustomMemId**)calloc(request->NumFrameSuggested, sizeof(CustomMemId*));
if (!mids) return MFX_ERR_MEMORY_ALLOC;
for (int i=0; i<request->NumFrameSuggested; i++) {
mids[i] = (CustomMemId*)calloc(1, sizeof(CustomMemId));
if (!mids[i]) {
return MFX_ERR_MEMORY_ALLOC;
}
mids[i]->rw = request->Type & 0xF000; // Set intended read/write operation
}
request->Type = request->Type & 0x0FFF;
// because P8 data (bitstream) for h264 encoder should be allocated by CreateBuffer()
// but P8 data (MBData) for MPEG2 encoder should be allocated by CreateTexture2D()
if (request->Info.FourCC == MFX_FOURCC_P8) {
D3D11_BUFFER_DESC desc = { 0 };
if (!request->NumFrameSuggested) return MFX_ERR_MEMORY_ALLOC;
desc.ByteWidth = request->Info.Width * request->Info.Height;
desc.Usage = D3D11_USAGE_STAGING;
desc.BindFlags = 0;
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
desc.MiscFlags = 0;
desc.StructureByteStride = 0;
ID3D11Buffer* buffer = 0;
hRes = g_pD3D11Device->CreateBuffer(&desc, 0, &buffer);
if (FAILED(hRes))
return MFX_ERR_MEMORY_ALLOC;
mids[0]->memId = reinterpret_cast<ID3D11Texture2D*>(buffer);
} else {
D3D11_TEXTURE2D_DESC desc = {0};
desc.Width = request->Info.Width;
desc.Height = request->Info.Height;
desc.MipLevels = 1;
desc.ArraySize = 1; // number of subresources is 1 in this case
desc.Format = format;
desc.SampleDesc.Count = 1;
desc.Usage = D3D11_USAGE_DEFAULT;
desc.BindFlags = D3D11_BIND_DECODER;
desc.MiscFlags = 0;
//desc.MiscFlags = D3D11_RESOURCE_MISC_SHARED;
if ( (MFX_MEMTYPE_FROM_VPPIN & request->Type) &&
(DXGI_FORMAT_B8G8R8A8_UNORM == desc.Format) ) {
desc.BindFlags = D3D11_BIND_RENDER_TARGET;
if (desc.ArraySize > 2)
return MFX_ERR_MEMORY_ALLOC;
}
if ( (MFX_MEMTYPE_FROM_VPPOUT & request->Type) ||
(MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET & request->Type)) {
desc.BindFlags = D3D11_BIND_RENDER_TARGET;
if (desc.ArraySize > 2)
return MFX_ERR_MEMORY_ALLOC;
}
if ( DXGI_FORMAT_P8 == desc.Format )
desc.BindFlags = 0;
ID3D11Texture2D* pTexture2D;
// Create surface textures
for (size_t i = 0; i < request->NumFrameSuggested / desc.ArraySize; i++) {
hRes = g_pD3D11Device->CreateTexture2D(&desc, NULL, &pTexture2D);
if (FAILED(hRes))
return MFX_ERR_MEMORY_ALLOC;
mids[i]->memId = pTexture2D;
}
desc.ArraySize = 1;
desc.Usage = D3D11_USAGE_STAGING;
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;// | D3D11_CPU_ACCESS_WRITE;
desc.BindFlags = 0;
desc.MiscFlags = 0;
//desc.MiscFlags = D3D11_RESOURCE_MISC_SHARED;
// Create surface staging textures
for (size_t i = 0; i < request->NumFrameSuggested; i++) {
hRes = g_pD3D11Device->CreateTexture2D(&desc, NULL, &pTexture2D);
if (FAILED(hRes))
return MFX_ERR_MEMORY_ALLOC;
mids[i]->memIdStage = pTexture2D;
}
}
response->mids = (mfxMemId*)mids;
response->NumFrameActual = request->NumFrameSuggested;
return MFX_ERR_NONE;
}
mfxStatus simple_alloc(mfxHDL pthis, mfxFrameAllocRequest* request, mfxFrameAllocResponse* response)
{
mfxStatus sts = MFX_ERR_NONE;
if (request->Type & MFX_MEMTYPE_SYSTEM_MEMORY)
return MFX_ERR_UNSUPPORTED;
if (allocDecodeResponses.find(pthis) != allocDecodeResponses.end() &&
MFX_MEMTYPE_EXTERNAL_FRAME & request->Type &&
MFX_MEMTYPE_FROM_DECODE & request->Type) {
// Memory for this request was already allocated during manual allocation stage. Return saved response
// When decode acceleration device (DXVA) is created it requires a list of d3d surfaces to be passed.
// Therefore Media SDK will ask for the surface info/mids again at Init() stage, thus requiring us to return the saved response
// (No such restriction applies to Encode or VPP)
*response = allocDecodeResponses[pthis];
allocDecodeRefCount[pthis]++;
} else {
sts = _simple_alloc(request, response);
if (MFX_ERR_NONE == sts) {
if ( MFX_MEMTYPE_EXTERNAL_FRAME & request->Type &&
MFX_MEMTYPE_FROM_DECODE & request->Type) {
// Decode alloc response handling
allocDecodeResponses[pthis] = *response;
allocDecodeRefCount[pthis]++;
} else {
// Encode and VPP alloc response handling
allocResponses[response->mids] = pthis;
}
}
}
return sts;
}
mfxStatus simple_lock(mfxHDL pthis, mfxMemId mid, mfxFrameData* ptr)
{
pthis; // To suppress warning for this unused parameter
HRESULT hRes = S_OK;
D3D11_TEXTURE2D_DESC desc = {0};
D3D11_MAPPED_SUBRESOURCE lockedRect = {0};
CustomMemId* memId = (CustomMemId*)mid;
ID3D11Texture2D* pSurface = (ID3D11Texture2D*)memId->memId;
ID3D11Texture2D* pStage = (ID3D11Texture2D*)memId->memIdStage;
D3D11_MAP mapType = D3D11_MAP_READ;
UINT mapFlags = D3D11_MAP_FLAG_DO_NOT_WAIT;
if (NULL == pStage) {
hRes = g_pD3D11Ctx->Map(pSurface, 0, mapType, mapFlags, &lockedRect);
desc.Format = DXGI_FORMAT_P8;
} else {
pSurface->GetDesc(&desc);
// copy data only in case of user wants o read from stored surface
if (memId->rw & WILL_READ)
g_pD3D11Ctx->CopySubresourceRegion(pStage, 0, 0, 0, 0, pSurface, 0, NULL);
do {
hRes = g_pD3D11Ctx->Map(pStage, 0, mapType, mapFlags, &lockedRect);
if (S_OK != hRes && DXGI_ERROR_WAS_STILL_DRAWING != hRes)
return MFX_ERR_LOCK_MEMORY;
} while (DXGI_ERROR_WAS_STILL_DRAWING == hRes);
}
if (FAILED(hRes))
return MFX_ERR_LOCK_MEMORY;
switch (desc.Format) {
case DXGI_FORMAT_NV12:
ptr->Pitch = (mfxU16)lockedRect.RowPitch;
ptr->Y = (mfxU8*)lockedRect.pData;
ptr->U = (mfxU8*)lockedRect.pData + desc.Height * lockedRect.RowPitch;
ptr->V = ptr->U + 1;
break;
case DXGI_FORMAT_B8G8R8A8_UNORM :
ptr->Pitch = (mfxU16)lockedRect.RowPitch;
ptr->B = (mfxU8*)lockedRect.pData;
ptr->G = ptr->B + 1;
ptr->R = ptr->B + 2;
ptr->A = ptr->B + 3;
break;
case DXGI_FORMAT_YUY2:
ptr->Pitch = (mfxU16)lockedRect.RowPitch;
ptr->Y = (mfxU8*)lockedRect.pData;
ptr->U = ptr->Y + 1;
ptr->V = ptr->Y + 3;
break;
case DXGI_FORMAT_P8 :
ptr->Pitch = (mfxU16)lockedRect.RowPitch;
ptr->Y = (mfxU8*)lockedRect.pData;
ptr->U = 0;
ptr->V = 0;
break;
default:
return MFX_ERR_LOCK_MEMORY;
}
return MFX_ERR_NONE;
}
mfxStatus simple_unlock(mfxHDL pthis, mfxMemId mid, mfxFrameData* ptr)
{
pthis; // To suppress warning for this unused parameter
CustomMemId* memId = (CustomMemId*)mid;
ID3D11Texture2D* pSurface = (ID3D11Texture2D*)memId->memId;
ID3D11Texture2D* pStage = (ID3D11Texture2D*)memId->memIdStage;
if (NULL == pStage) {
g_pD3D11Ctx->Unmap(pSurface, 0);
} else {
g_pD3D11Ctx->Unmap(pStage, 0);
// copy data only in case of user wants to write to stored surface
if (memId->rw & WILL_WRITE)
g_pD3D11Ctx->CopySubresourceRegion(pSurface, 0, 0, 0, 0, pStage, 0, NULL);
}
if (ptr) {
ptr->Pitch=0;
ptr->U=ptr->V=ptr->Y=0;
ptr->A=ptr->R=ptr->G=ptr->B=0;
}
return MFX_ERR_NONE;
}
mfxStatus simple_gethdl(mfxHDL pthis, mfxMemId mid, mfxHDL* handle)
{
pthis; // To suppress warning for this unused parameter
if (NULL == handle)
return MFX_ERR_INVALID_HANDLE;
mfxHDLPair* pPair = (mfxHDLPair*)handle;
CustomMemId* memId = (CustomMemId*)mid;
pPair->first = memId->memId; // surface texture
pPair->second = 0;
return MFX_ERR_NONE;
}
mfxStatus _simple_free(mfxFrameAllocResponse* response)
{
if (response->mids) {
for (mfxU32 i = 0; i < response->NumFrameActual; i++) {
if (response->mids[i]) {
CustomMemId* mid = (CustomMemId*)response->mids[i];
ID3D11Texture2D* pSurface = (ID3D11Texture2D*)mid->memId;
ID3D11Texture2D* pStage = (ID3D11Texture2D*)mid->memIdStage;
if (pSurface)
pSurface->Release();
if (pStage)
pStage->Release();
free(mid);
}
}
free(response->mids);
response->mids = NULL;
}
return MFX_ERR_NONE;
}
mfxStatus simple_free(mfxHDL pthis, mfxFrameAllocResponse* response)
{
if (NULL == response)
return MFX_ERR_NULL_PTR;
if (allocResponses.find(response->mids) == allocResponses.end()) {
// Decode free response handling
if (--allocDecodeRefCount[pthis] == 0) {
_simple_free(response);
allocDecodeResponses.erase(pthis);
allocDecodeRefCount.erase(pthis);
}
} else {
// Encode and VPP free response handling
allocResponses.erase(response->mids);
_simple_free(response);
}
return MFX_ERR_NONE;
}
/*****************************************************************************
INTEL CORPORATION PROPRIETARY INFORMATION
This software is supplied under the terms of a license agreement or
nondisclosure agreement with Intel Corporation and may not be copied
or disclosed except in accordance with the terms of that agreement.
Copyright(c) 2005-2014 Intel Corporation. All Rights Reserved.
*****************************************************************************/
#pragma once
#include "common_utils.h"
#include <windows.h>
#include <d3d11.h>
#include <dxgi1_2.h>
#include <atlbase.h>
#define DEVICE_MGR_TYPE MFX_HANDLE_D3D11_DEVICE
// =================================================================
// DirectX functionality required to manage D3D surfaces
//
// Create DirectX 11 device context
// - Required when using D3D surfaces.
// - D3D Device created and handed to Intel Media SDK
// - Intel graphics device adapter will be determined automatically (does not have to be primary),
// but with the following caveats:
// - Device must be active (but monitor does NOT have to be attached)
// - Device must be enabled in BIOS. Required for the case when used together with a discrete graphics card
// - For switchable graphics solutions (mobile) make sure that Intel device is the active device
mfxStatus CreateHWDevice(mfxSession session, mfxHDL* deviceHandle, HWND hWnd, bool bCreateSharedHandles);
void CleanupHWDevice();
void SetHWDeviceContext(CComPtr<ID3D11DeviceContext> devCtx);
CComPtr<ID3D11DeviceContext> GetHWDeviceContext();
void ClearYUVSurfaceD3D(mfxMemId memId);
void ClearRGBSurfaceD3D(mfxMemId memId);
\ No newline at end of file
/*****************************************************************************
INTEL CORPORATION PROPRIETARY INFORMATION
This software is supplied under the terms of a license agreement or
nondisclosure agreement with Intel Corporation and may not be copied
or disclosed except in accordance with the terms of that agreement.
Copyright(c) 2005-2014 Intel Corporation. All Rights Reserved.
*****************************************************************************/
#include "common_utils.h"
// =================================================================
// Utility functions, not directly tied to Intel Media SDK functionality
//
void PrintErrString(int err,const char* filestr,int line)
{
switch (err) {
case 0:
printf("\n No error.\n");
break;
case -1:
printf("\n Unknown error: %s %d\n",filestr,line);
break;
case -2:
printf("\n Null pointer. Check filename/path + permissions? %s %d\n",filestr,line);
break;
case -3:
printf("\n Unsupported feature/library load error. %s %d\n",filestr,line);
break;
case -4:
printf("\n Could not allocate memory. %s %d\n",filestr,line);
break;
case -5:
printf("\n Insufficient IO buffers. %s %d\n",filestr,line);
break;
case -6:
printf("\n Invalid handle. %s %d\n",filestr,line);
break;
case -7:
printf("\n Memory lock failure. %s %d\n",filestr,line);
break;
case -8:
printf("\n Function called before initialization. %s %d\n",filestr,line);
break;
case -9:
printf("\n Specified object not found. %s %d\n",filestr,line);
break;
case -10:
printf("\n More input data expected. %s %d\n",filestr,line);
break;
case -11:
printf("\n More output surfaces expected. %s %d\n",filestr,line);
break;
case -12:
printf("\n Operation aborted. %s %d\n",filestr,line);
break;
case -13:
printf("\n HW device lost. %s %d\n",filestr,line);
break;
case -14:
printf("\n Incompatible video parameters. %s %d\n",filestr,line);
break;
case -15:
printf("\n Invalid video parameters. %s %d\n",filestr,line);
break;
case -16:
printf("\n Undefined behavior. %s %d\n",filestr,line);
break;
case -17:
printf("\n Device operation failure. %s %d\n",filestr,line);
break;
case -18:
printf("\n More bitstream data expected. %s %d\n",filestr,line);
break;
case -19:
printf("\n Incompatible audio parameters. %s %d\n",filestr,line);
break;
case -20:
printf("\n Invalid audio parameters. %s %d\n",filestr,line);
break;
default:
printf("\nError code %d,\t%s\t%d\n\n", err, filestr, line);
}
}
mfxStatus ReadPlaneData(mfxU16 w, mfxU16 h, mfxU8* buf, mfxU8* ptr,
mfxU16 pitch, mfxU16 offset, FILE* fSource)
{
mfxU32 nBytesRead;
for (mfxU16 i = 0; i < h; i++) {
nBytesRead = (mfxU32) fread(buf, 1, w, fSource);
if (w != nBytesRead)
return MFX_ERR_MORE_DATA;
for (mfxU16 j = 0; j < w; j++)
ptr[i * pitch + j * 2 + offset] = buf[j];
}
return MFX_ERR_NONE;
}
mfxStatus LoadRawFrame(mfxFrameSurface1* pSurface, FILE* fSource)
{
if (!fSource) {
// Simulate instantaneous access to 1000 "empty" frames.
static int frameCount = 0;
if (1000 == frameCount++)
return MFX_ERR_MORE_DATA;
else
return MFX_ERR_NONE;
}
mfxStatus sts = MFX_ERR_NONE;
mfxU32 nBytesRead;
mfxU16 w, h, i, pitch;
mfxU8* ptr;
mfxFrameInfo* pInfo = &pSurface->Info;
mfxFrameData* pData = &pSurface->Data;
if (pInfo->CropH > 0 && pInfo->CropW > 0) {
w = pInfo->CropW;
h = pInfo->CropH;
} else {
w = pInfo->Width;
h = pInfo->Height;
}
pitch = pData->Pitch;
ptr = pData->Y + pInfo->CropX + pInfo->CropY * pData->Pitch;
// read luminance plane
for (i = 0; i < h; i++) {
nBytesRead = (mfxU32) fread(ptr + i * pitch, 1, w, fSource);
if (w != nBytesRead)
return MFX_ERR_MORE_DATA;
}
mfxU8 buf[2048]; // maximum supported chroma width for nv12
w /= 2;
h /= 2;
ptr = pData->UV + pInfo->CropX + (pInfo->CropY / 2) * pitch;
if (w > 2048)
return MFX_ERR_UNSUPPORTED;
// load U
sts = ReadPlaneData(w, h, buf, ptr, pitch, 0, fSource);
if (MFX_ERR_NONE != sts)
return sts;
// load V
ReadPlaneData(w, h, buf, ptr, pitch, 1, fSource);
if (MFX_ERR_NONE != sts)
return sts;
return MFX_ERR_NONE;
}
mfxStatus LoadRawRGBFrame(mfxFrameSurface1* pSurface, FILE* fSource)
{
if (!fSource) {
// Simulate instantaneous access to 1000 "empty" frames.
static int frameCount = 0;
if (1000 == frameCount++)
return MFX_ERR_MORE_DATA;
else
return MFX_ERR_NONE;
}
size_t nBytesRead;
mfxU16 w, h;
mfxFrameInfo* pInfo = &pSurface->Info;
if (pInfo->CropH > 0 && pInfo->CropW > 0) {
w = pInfo->CropW;
h = pInfo->CropH;
} else {
w = pInfo->Width;
h = pInfo->Height;
}
for (mfxU16 i = 0; i < h; i++) {
nBytesRead = fread(pSurface->Data.B + i * pSurface->Data.Pitch,
1, w * 4, fSource);
if ((size_t)(w * 4) != nBytesRead)
return MFX_ERR_MORE_DATA;
}
return MFX_ERR_NONE;
}
mfxStatus WriteBitStreamFrame(mfxBitstream* pMfxBitstream, FILE* fSink)
{
mfxU32 nBytesWritten =
(mfxU32) fwrite(pMfxBitstream->Data + pMfxBitstream->DataOffset, 1,
pMfxBitstream->DataLength, fSink);
if (nBytesWritten != pMfxBitstream->DataLength)
return MFX_ERR_UNDEFINED_BEHAVIOR;
pMfxBitstream->DataLength = 0;
return MFX_ERR_NONE;
}
mfxStatus ReadBitStreamData(mfxBitstream* pBS, FILE* fSource)
{
memmove(pBS->Data, pBS->Data + pBS->DataOffset, pBS->DataLength);
pBS->DataOffset = 0;
mfxU32 nBytesRead = (mfxU32) fread(pBS->Data + pBS->DataLength, 1,
pBS->MaxLength - pBS->DataLength,
fSource);
if (0 == nBytesRead)
return MFX_ERR_MORE_DATA;
pBS->DataLength += nBytesRead;
return MFX_ERR_NONE;
}
mfxStatus WriteSection(mfxU8* plane, mfxU16 factor, mfxU16 chunksize,
mfxFrameInfo* pInfo, mfxFrameData* pData, mfxU32 i,
mfxU32 j, FILE* fSink)
{
if (chunksize !=
fwrite(plane +
(pInfo->CropY * pData->Pitch / factor + pInfo->CropX) +
i * pData->Pitch + j, 1, chunksize, fSink))
return MFX_ERR_UNDEFINED_BEHAVIOR;
return MFX_ERR_NONE;
}
mfxStatus WriteRawFrame(mfxFrameSurface1* pSurface, FILE* fSink)
{
mfxFrameInfo* pInfo = &pSurface->Info;
mfxFrameData* pData = &pSurface->Data;
mfxU32 i, j, h, w;
mfxStatus sts = MFX_ERR_NONE;
for (i = 0; i < pInfo->CropH; i++)
sts =
WriteSection(pData->Y, 1, pInfo->CropW, pInfo, pData, i, 0,
fSink);
h = pInfo->CropH / 2;
w = pInfo->CropW;
for (i = 0; i < h; i++)
for (j = 0; j < w; j += 2)
sts =
WriteSection(pData->UV, 2, 1, pInfo, pData, i, j,
fSink);
for (i = 0; i < h; i++)
for (j = 1; j < w; j += 2)
sts =
WriteSection(pData->UV, 2, 1, pInfo, pData, i, j,
fSink);
return sts;
}
int GetFreeTaskIndex(Task* pTaskPool, mfxU16 nPoolSize)
{
if (pTaskPool)
for (int i = 0; i < nPoolSize; i++)
if (!pTaskPool[i].syncp)
return i;
return MFX_ERR_NOT_FOUND;
}
void ClearYUVSurfaceSysMem(mfxFrameSurface1* pSfc, mfxU16 width, mfxU16 height)
{
// In case simulating direct access to frames we initialize the allocated surfaces with default pattern
memset(pSfc->Data.Y, 100, width * height); // Y plane
memset(pSfc->Data.U, 50, (width * height)/2); // UV plane
}
// Get free raw frame surface
int GetFreeSurfaceIndex(mfxFrameSurface1** pSurfacesPool, mfxU16 nPoolSize)
{
if (pSurfacesPool)
for (mfxU16 i = 0; i < nPoolSize; i++)
if (0 == pSurfacesPool[i]->Data.Locked)
return i;
return MFX_ERR_NOT_FOUND;
}
char mfxFrameTypeString(mfxU16 FrameType)
{
mfxU8 FrameTmp = FrameType & 0xF;
char FrameTypeOut;
switch (FrameTmp) {
case MFX_FRAMETYPE_I:
FrameTypeOut = 'I';
break;
case MFX_FRAMETYPE_P:
FrameTypeOut = 'P';
break;
case MFX_FRAMETYPE_B:
FrameTypeOut = 'B';
break;
default:
FrameTypeOut = '*';
}
return FrameTypeOut;
}
/*****************************************************************************
INTEL CORPORATION PROPRIETARY INFORMATION
This software is supplied under the terms of a license agreement or
nondisclosure agreement with Intel Corporation and may not be copied
or disclosed except in accordance with the terms of that agreement.
Copyright(c) 2005-2014 Intel Corporation. All Rights Reserved.
*****************************************************************************/
#pragma once
#include <stdio.h>
#include "mfxvideo++.h"
// =================================================================
// OS-specific definitions of types, macro, etc...
// The following should be defined:
// - mfxTime
// - MSDK_FOPEN
// - MSDK_SLEEP
#if defined(_WIN32) || defined(_WIN64)
#include "bits/windows_defs.h"
#elif defined(__linux__)
#include "bits/linux_defs.h"
#endif
// =================================================================
// Helper macro definitions...
#define MSDK_PRINT_RET_MSG(ERR) {PrintErrString(ERR, __FILE__, __LINE__);}
#define MSDK_CHECK_RESULT(P, X, ERR) {if ((X) > (P)) {MSDK_PRINT_RET_MSG(ERR); return ERR;}}
#define MSDK_CHECK_POINTER(P, ERR) {if (!(P)) {MSDK_PRINT_RET_MSG(ERR); return ERR;}}
#define MSDK_CHECK_ERROR(P, X, ERR) {if ((X) == (P)) {MSDK_PRINT_RET_MSG(ERR); return ERR;}}
#define MSDK_IGNORE_MFX_STS(P, X) {if ((X) == (P)) {P = MFX_ERR_NONE;}}
#define MSDK_BREAK_ON_ERROR(P) {if (MFX_ERR_NONE != (P)) break;}
#define MSDK_SAFE_DELETE_ARRAY(P) {if (P) {delete[] P; P = NULL;}}
#define MSDK_ALIGN32(X) (((mfxU32)((X)+31)) & (~ (mfxU32)31))
#define MSDK_ALIGN16(value) (((value + 15) >> 4) << 4)
#define MSDK_SAFE_RELEASE(X) {if (X) { X->Release(); X = NULL; }}
#define MSDK_MAX(A, B) (((A) > (B)) ? (A) : (B))
// Usage of the following two macros are only required for certain Windows DirectX11 use cases
#define WILL_READ 0x1000
#define WILL_WRITE 0x2000
// =================================================================
// Intel Media SDK memory allocator entrypoints....
// Implementation of this functions is OS/Memory type specific.
mfxStatus simple_alloc(mfxHDL pthis, mfxFrameAllocRequest* request, mfxFrameAllocResponse* response);
mfxStatus simple_lock(mfxHDL pthis, mfxMemId mid, mfxFrameData* ptr);
mfxStatus simple_unlock(mfxHDL pthis, mfxMemId mid, mfxFrameData* ptr);
mfxStatus simple_gethdl(mfxHDL pthis, mfxMemId mid, mfxHDL* handle);
mfxStatus simple_free(mfxHDL pthis, mfxFrameAllocResponse* response);
// =================================================================
// Utility functions, not directly tied to Media SDK functionality
//
void PrintErrString(int err,const char* filestr,int line);
// LoadRawFrame: Reads raw frame from YUV file (YV12) into NV12 surface
// - YV12 is a more common format for for YUV files than NV12 (therefore the conversion during read and write)
// - For the simulation case (fSource = NULL), the surface is filled with default image data
// LoadRawRGBFrame: Reads raw RGB32 frames from file into RGB32 surface
// - For the simulation case (fSource = NULL), the surface is filled with default image data
mfxStatus LoadRawFrame(mfxFrameSurface1* pSurface, FILE* fSource);
mfxStatus LoadRawRGBFrame(mfxFrameSurface1* pSurface, FILE* fSource);
// Write raw YUV (NV12) surface to YUV (YV12) file
mfxStatus WriteRawFrame(mfxFrameSurface1* pSurface, FILE* fSink);
// Write bit stream data for frame to file
mfxStatus WriteBitStreamFrame(mfxBitstream* pMfxBitstream, FILE* fSink);
// Read bit stream data from file. Stream is read as large chunks (= many frames)
mfxStatus ReadBitStreamData(mfxBitstream* pBS, FILE* fSource);
void ClearYUVSurfaceSysMem(mfxFrameSurface1* pSfc, mfxU16 width, mfxU16 height);
void ClearYUVSurfaceVMem(mfxMemId memId);
void ClearRGBSurfaceVMem(mfxMemId memId);
// Get free raw frame surface
int GetFreeSurfaceIndex(mfxFrameSurface1** pSurfacesPool, mfxU16 nPoolSize);
// For use with asynchronous task management
typedef struct {
mfxBitstream mfxBS;
mfxSyncPoint syncp;
} Task;
// Get free task
int GetFreeTaskIndex(Task* pTaskPool, mfxU16 nPoolSize);
// Initialize Intel Media SDK Session, device/display and memory manager
mfxStatus Initialize(mfxIMPL impl, mfxVersion ver, MFXVideoSession* pSession, mfxFrameAllocator* pmfxAllocator, bool bCreateSharedHandles = false);
// Release resources (device/display)
void Release();
// Convert frame type to string
char mfxFrameTypeString(mfxU16 FrameType);
void mfxGetTime(mfxTime* timestamp);
//void mfxInitTime(); might need this for Windows
double TimeDiffMsec(mfxTime tfinish, mfxTime tstart);
/*****************************************************************************
INTEL CORPORATION PROPRIETARY INFORMATION
This software is supplied under the terms of a license agreement or
nondisclosure agreement with Intel Corporation and may not be copied
or disclosed except in accordance with the terms of that agreement.
Copyright(c) 2005-2014 Intel Corporation. All Rights Reserved.
*****************************************************************************/
#include "common_utils.h"
// ATTENTION: If D3D surfaces are used, DX9_D3D or DX11_D3D must be set in project settings or hardcoded here
#ifdef DX9_D3D
#include "common_directx.h"
#elif DX11_D3D
#include "common_directx11.h"
#endif
/* =======================================================
* Windows implementation of OS-specific utility functions
*/
mfxStatus Initialize(mfxIMPL impl, mfxVersion ver, MFXVideoSession* pSession, mfxFrameAllocator* pmfxAllocator, bool bCreateSharedHandles)
{
bCreateSharedHandles; // (Hugh) Currently unused
pmfxAllocator; // (Hugh) Currently unused
mfxStatus sts = MFX_ERR_NONE;
// If mfxFrameAllocator is provided it means we need to setup DirectX device and memory allocator
if (pmfxAllocator) {
// Initialize Intel Media SDK Session
sts = pSession->Init(impl, &ver);
MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);
// Create DirectX device context
mfxHDL deviceHandle;
sts = CreateHWDevice(*pSession, &deviceHandle, NULL, bCreateSharedHandles);
MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);
// Provide device manager to Media SDK
sts = pSession->SetHandle(DEVICE_MGR_TYPE, deviceHandle);
MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);
pmfxAllocator->pthis = *pSession; // We use Media SDK session ID as the allocation identifier
pmfxAllocator->Alloc = simple_alloc;
pmfxAllocator->Free = simple_free;
pmfxAllocator->Lock = simple_lock;
pmfxAllocator->Unlock = simple_unlock;
pmfxAllocator->GetHDL = simple_gethdl;
// Since we are using video memory we must provide Media SDK with an external allocator
sts = pSession->SetFrameAllocator(pmfxAllocator);
MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);
}
else
{
// Initialize Intel Media SDK Session
sts = pSession->Init(impl, &ver);
MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);
}
return sts;
}
void Release()
{
#if defined(DX9_D3D) || defined(DX11_D3D)
CleanupHWDevice();
#endif
}
void mfxGetTime(mfxTime* timestamp)
{
QueryPerformanceCounter(timestamp);
}
double TimeDiffMsec(mfxTime tfinish, mfxTime tstart)
{
static LARGE_INTEGER tFreq = { 0 };
if (!tFreq.QuadPart) QueryPerformanceFrequency(&tFreq);
double freq = (double)tFreq.QuadPart;
return 1000.0 * ((double)tfinish.QuadPart - (double)tstart.QuadPart) / freq;
}
/* (Hugh) Functions currently unused */
#if 0
void ClearYUVSurfaceVMem(mfxMemId memId)
{
#if defined(DX9_D3D) || defined(DX11_D3D)
ClearYUVSurfaceD3D(memId);
#endif
}
void ClearRGBSurfaceVMem(mfxMemId memId)
{
#if defined(DX9_D3D) || defined(DX11_D3D)
ClearRGBSurfaceD3D(memId);
#endif
}
#endif
TargetUsage="Target Usage"
Bitrate="Bitrate"
MaxBitrate="Max Bitrate"
RateControl="Rate Control"
KeyframeIntervalSec="Keyframe Interval (seconds, 0=auto)"
Profile="Profile"
AsyncDepth="Async Depth"
Accuracy="Accuracy"
Convergence="Convergence"
ICQQuality="ICQ Quality"
LookAheadDepth="Lookahead Depth"
/* ****************************************************************************** *\
Copyright (C) 2012-2013 Intel Corporation. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- Neither the name of Intel Corporation nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL INTEL CORPORATION BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
File Name: mfx_critical_section.h
\* ****************************************************************************** */
#if !defined(__MFX_CRITICAL_SECTION_H)
#define __MFX_CRITICAL_SECTION_H
#include <mfxdefs.h>
namespace MFX
{
// Just set "critical section" instance to zero for initialization.
typedef volatile mfxL32 mfxCriticalSection;
// Enter the global critical section.
void mfxEnterCriticalSection(mfxCriticalSection *pCSection);
// Leave the global critical section.
void mfxLeaveCriticalSection(mfxCriticalSection *pCSection);
class MFXAutomaticCriticalSection
{
public:
// Constructor
explicit MFXAutomaticCriticalSection(mfxCriticalSection *pCSection)
{
m_pCSection = pCSection;
mfxEnterCriticalSection(m_pCSection);
}
// Destructor
~MFXAutomaticCriticalSection()
{
mfxLeaveCriticalSection(m_pCSection);
}
protected:
// Pointer to a critical section
mfxCriticalSection *m_pCSection;
private:
// unimplemented by intent to make this class non-copyable
MFXAutomaticCriticalSection(const MFXAutomaticCriticalSection &);
void operator=(const MFXAutomaticCriticalSection &);
};
} // namespace MFX
#endif // __MFX_CRITICAL_SECTION_H
/* ****************************************************************************** *\
Copyright (C) 2012-2015 Intel Corporation. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- Neither the name of Intel Corporation nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL INTEL CORPORATION BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
File Name: mfx_dispatcher.h
\* ****************************************************************************** */
#if !defined(__MFX_DISPATCHER_H)
#define __MFX_DISPATCHER_H
#include <mfxvideo.h>
#include <mfxaudio.h>
#include <mfxplugin.h>
#include <stddef.h>
#include "mfx_dispatcher_defs.h"
#include "mfx_load_plugin.h"
#include "mfxenc.h"
#include "mfxpak.h"
mfxStatus MFXQueryVersion(mfxSession session, mfxVersion *version);
enum
{
// to avoid code changing versions are just inherited
// from the API header file.
DEFAULT_API_VERSION_MAJOR = MFX_VERSION_MAJOR,
DEFAULT_API_VERSION_MINOR = MFX_VERSION_MINOR
};
//
// declare functions' integer identifiers.
//
#undef FUNCTION
#define FUNCTION(return_value, func_name, formal_param_list, actual_param_list) \
e##func_name,
enum eFunc
{
eMFXInit,
eMFXClose,
eMFXQueryIMPL,
eMFXQueryVersion,
eMFXJoinSession,
eMFXDisjoinSession,
eMFXCloneSession,
eMFXSetPriority,
eMFXGetPriority,
eMFXInitEx,
#include "mfx_exposed_functions_list.h"
eVideoFuncTotal
};
enum eAudioFunc
{
eFakeAudioEnum = eMFXGetPriority,
#include "mfxaudio_exposed_functions_list.h"
eAudioFuncTotal
};
// declare max buffer length for regsitry key name
enum
{
MFX_MAX_REGISTRY_KEY_NAME = 256
};
// declare the maximum DLL path
enum
{
MFX_MAX_DLL_PATH = 1024
};
// declare library's implementation types
enum eMfxImplType
{
MFX_LIB_HARDWARE = 0,
MFX_LIB_SOFTWARE = 1,
MFX_LIB_PSEUDO = 2,
MFX_LIB_IMPL_TYPES
};
// declare dispatcher's version
enum
{
MFX_DISPATCHER_VERSION_MAJOR = 1,
MFX_DISPATCHER_VERSION_MINOR = 2
};
// declare a dispatcher's handle
struct MFX_DISP_HANDLE
{
// Default constructor
MFX_DISP_HANDLE(const mfxVersion requiredVersion);
// Destructor
~MFX_DISP_HANDLE(void);
// Load the library's module
mfxStatus LoadSelectedDLL(const msdk_disp_char *pPath, eMfxImplType implType, mfxIMPL impl, mfxIMPL implInterface, mfxInitParam &par);
// Unload the library's module
mfxStatus UnLoadSelectedDLL(void);
// Close the handle
mfxStatus Close(void);
// NOTE: changing order of struct's members can make different version of
// dispatchers incompatible. Think of different modules (e.g. MFT filters)
// within a single application.
// Library's implementation type (hardware or software)
eMfxImplType implType;
// Current library's implementation (exact implementation)
mfxIMPL impl;
// Current library's VIA interface
mfxIMPL implInterface;
// Dispatcher's version. If version is 1.1 or lower, then old dispatcher's
// architecture is used. Otherwise it means current dispatcher's version.
mfxVersion dispVersion;
// A real handle passed to a called function
mfxSession session;
// Required API version of session initialized
const mfxVersion apiVersion;
// Actual library API version
mfxVersion actualApiVersion;
// Status of loaded dll
mfxStatus loadStatus;
// Resgistry subkey name for windows version
msdk_disp_char subkeyName[MFX_MAX_REGISTRY_KEY_NAME];
// Storage ID for windows version
int storageID;
// Library's module handle
mfxModuleHandle hModule;
MFX::MFXPluginStorage pluginHive;
MFX::MFXPluginFactory pluginFactory;
// function call table
mfxFunctionPointer callTable[eVideoFuncTotal];
mfxFunctionPointer callAudioTable[eAudioFuncTotal];
private:
// Declare assignment operator and copy constructor to prevent occasional assignment
MFX_DISP_HANDLE(const MFX_DISP_HANDLE &);
MFX_DISP_HANDLE & operator = (const MFX_DISP_HANDLE &);
};
// declare comparison operator
inline
bool operator == (const mfxVersion &one, const mfxVersion &two)
{
return (one.Version == two.Version);
} // bool operator == (const mfxVersion &one, const mfxVersion &two)
inline
bool operator < (const mfxVersion &one, const mfxVersion &two)
{
return (one.Major == two.Major) && (one.Minor < two.Minor);
} // bool operator < (const mfxVersion &one, const mfxVersion &two)
inline
bool operator <= (const mfxVersion &one, const mfxVersion &two)
{
return (one == two) || (one < two);
} // bool operator <= (const mfxVersion &one, const mfxVersion &two)
//
// declare a table with functions descriptions
//
typedef
struct FUNCTION_DESCRIPTION
{
// Literal function's name
const char *pName;
// API version when function appeared first time
mfxVersion apiVersion;
} FUNCTION_DESCRIPTION;
extern const
FUNCTION_DESCRIPTION APIFunc[eVideoFuncTotal];
extern const
FUNCTION_DESCRIPTION APIAudioFunc[eAudioFuncTotal];
#endif // __MFX_DISPATCHER_H
/* ****************************************************************************** *\
Copyright (C) 2013-2015 Intel Corporation. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- Neither the name of Intel Corporation nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL INTEL CORPORATION BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
File Name: mfx_dispatcher_defs.h
\* ****************************************************************************** */
#pragma once
#include "mfxdefs.h"
#include <cstring>
#if defined(MFX_DISPATCHER_LOG)
#include <string>
#include <string.h>
#endif
#if defined(_WIN32) || defined(_WIN64)
typedef wchar_t msdk_disp_char;
#define MSDK2WIDE(x) x
#if _MSC_VER >= 1400
#define msdk_disp_char_cpy_s(to, to_size, from) wcscpy_s(to,to_size, from)
#else
#define msdk_disp_char_cpy_s(to, to_size, from) wcscpy(to, from)
#endif
#else
typedef char msdk_disp_char;
//#define msdk_disp_char_cpy_s(to, to_size, from) strcpy(to, from)
inline void msdk_disp_char_cpy_s(char * to, size_t to_size, const char * from)
{
size_t source_len = strlen(from);
size_t num_chars = (to_size - 1) < source_len ? (to_size - 1) : source_len;
strncpy(to, from, num_chars);
to[num_chars] = 0;
}
#if defined(MFX_DISPATCHER_LOG)
#define MSDK2WIDE(x) getWideString(x).c_str()
inline std::wstring getWideString(const char * string)
{
size_t len = strlen(string);
return std::wstring(string, string + len);
}
#else
#define MSDK2WIDE(x) x
#endif
#endif
#ifdef __GNUC__
#define sscanf_s sscanf
#define swscanf_s swscanf
#endif
// declare library module's handle
typedef void * mfxModuleHandle;
typedef void (MFX_CDECL * mfxFunctionPointer)(void);
/* ****************************************************************************** *\
Copyright (C) 2012-2014 Intel Corporation. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- Neither the name of Intel Corporation nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL INTEL CORPORATION BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
File Name: mfx_dispatcher_log.h
\* ****************************************************************************** */
#if !defined(__MFX_DISPATCHER_LOG_H)
#define __MFX_DISPATCHER_LOG_H
//////////////////////////////////////////////////////////////////////////
//dispatcher log (DL) level
#define DL_INFO 1
#define DL_WRN 2
#define DL_ERROR 4
#define DL_LOADED_LIBRARY 8
//////////////////////////////////////////////////////////////////////////
//opcodes used only in events
enum
{
DL_EVENT_START = 1,
DL_EVENT_STOP,
DL_EVENT_MSG
};
//////////////////////////////////////////////////////////////////////////
#define DL_SINK_NULL 0
#define DL_SINK_PRINTF 1
#define DL_SINK_IMsgHandler 2
#define MFXFOURCCTYPE() "%c%c%c%c"
#define ZERO_OR_SPACE(value) ((0==(value)) ? '0' : (value))
#define MFXU32TOFOURCC(mfxu32)\
ZERO_OR_SPACE((char)(mfxu32 & 0xFF)), \
ZERO_OR_SPACE((char)((mfxu32 >> 8) & 0xFF)),\
ZERO_OR_SPACE((char)((mfxu32 >> 16) & 0xFF)),\
ZERO_OR_SPACE((char)((mfxu32 >> 24) & 0xFF))
#define MFXGUIDTYPE() "%X-%X-%X-%X-%X-%X-%X-%X-%X-%X-%X-%X-%X-%X-%X-%X"
#define MFXGUIDTOHEX(guid)\
(guid)->Data[0],\
(guid)->Data[1],\
(guid)->Data[2],\
(guid)->Data[3],\
(guid)->Data[4],\
(guid)->Data[5],\
(guid)->Data[6],\
(guid)->Data[7],\
(guid)->Data[8],\
(guid)->Data[9],\
(guid)->Data[10],\
(guid)->Data[11],\
(guid)->Data[12],\
(guid)->Data[13],\
(guid)->Data[14],\
(guid)->Data[15]
#if defined(MFX_DISPATCHER_LOG)
//---------------------------setup section------------------------
//using of formating instead of variadic macro with NULL end,
//leads to more flexibility in format, however constructing string
//with vsprintf_s is a time wasting
#define DISPATCHER_LOG_USE_FORMATING 1
//creates unique object, event guid registration, factories on heap
//heap reduce stack allocation and reduce reservation time at startup
//is a vital if mediasdk wont use
#define DISPATCHER_LOG_HEAP_SINGLETONES
#if defined(_WIN32) || defined(_WIN64)
// guid for all dispatcher events
#define DISPATCHER_LOG_EVENT_GUID L"{EB0538CC-4FEE-484d-ACEE-1182E9F37A57}"
//puts a sink into listeners list
//#define DISPATCHER_LOG_REGISTER_EVENT_PROVIDER
//puts a sink into listeners list
//#define DISPATCHER_LOG_REGISTER_FILE_WRITER
#define DISPACTHER_LOG_FW_PATH "c:\\dispatcher.log"
#endif // #if defined(_WIN32) || defined(_WIN64)
#include <stdio.h>
#include <stdarg.h>
//callback interface for intercept logging messages
class IMsgHandler
{
public:
virtual ~IMsgHandler(){}
virtual void Write(int level, int opcode, const char * msg, va_list argptr) = 0;
};
#if defined(_WIN32) || defined(_WIN64)
#if DISPATCHER_LOG_USE_FORMATING
#define DISPATCHER_LOG(lvl, opcode, str)\
{\
DispatcherLogBracketsHelper wrt(lvl,opcode);\
wrt.Write str;\
}
#else
#define DISPATCHER_LOG_VA_ARGS(...) wrt.Write(__VA_ARGS__, NULL)
//WARNING: don't use types that occupy more that 4 bytes in memory
//WARNING: don't use %s in format specifier
#define DISPATCHER_LOG(lvl, opcode, str) \
{\
DispatcherLogBracketsHelper wrt(lvl, opcode);\
DISPATCHER_LOG_VA_ARGS str;\
}
#endif//DISPATCHER_LOG_USE_FORMATING
#define DISPATCHER_LOG_OPERATION(operation) operation
#else
#define DISPATCHER_LOG(lvl, opcode, str)
#define DISPATCHER_LOG_OPERATION(operation)
#endif
#define __name_from_line( name, line ) name ## line
#define _name_from_line( name , line) __name_from_line( name, line )
#define name_from_line( name ) _name_from_line( name, __LINE__)
#define DISPATCHER_LOG_AUTO(lvl, msg)\
DispatchLogBlockHelper name_from_line(__auto_log_)(lvl); name_from_line(__auto_log_).Write msg;
#include <memory>
#include <map>
#include <list>
#include <string>
template <class T>
class DSSingleTone
{
public:
template <class TParam1>
inline static T & get(TParam1 par1)
{
T * pstored;
if (NULL == (pstored = store_or_load()))
{
return *store_or_load(new T(par1));
}
return *pstored;
}
inline static T & get()
{
T * pstored;
if (NULL == (pstored = store_or_load()))
{
return *store_or_load(new T());
}
return *pstored;
}
private:
//if obj == NULL, then it load
//if obj != NULL then it store obj
inline static T * store_or_load(T * obj = NULL)
{
static std::auto_ptr<T> instance;
if (NULL != obj)
{
instance.reset(obj);
}
return instance.get();
}
};
class DispatchLog
: public DSSingleTone<DispatchLog>
{
friend class DSSingleTone<DispatchLog>;
std::list<IMsgHandler*>m_Recepients;
int m_DispatcherLogSink;
public:
//sets current sink
void SetSink(int nsink, IMsgHandler *pHandler);
void AttachSink(int nsink, IMsgHandler *pHandler);
void DetachSink(int nsink, IMsgHandler *pHandler);
void ExchangeSink(int nsink, IMsgHandler *pOld, IMsgHandler *pNew);
void DetachAllSinks();
void Write(int level, int opcode, const char * msg, va_list argptr);
protected:
DispatchLog();
};
//allows to push arguments on the stack without declaring them as function parameters
struct DispatcherLogBracketsHelper
{
int m_level;
int m_opcode;
DispatcherLogBracketsHelper(int level, int opcode)
:m_level(level)
,m_opcode(opcode)
{
}
void Write(const char * str, ...);
} ;
//auto log on ctor dtor
struct DispatchLogBlockHelper
{
int m_level;
void Write(const char * str, ...);
DispatchLogBlockHelper (int level)
: m_level(level)
{
}
~DispatchLogBlockHelper();
};
//----utility sinks-----
#if defined(_WIN32) || defined(_WIN64)
#if defined(DISPATCHER_LOG_REGISTER_EVENT_PROVIDER)
class ETWHandlerFactory
: public DSSingleTone<ETWHandlerFactory>
{
friend class DSSingleTone<ETWHandlerFactory>;
typedef std::map<std::wstring, IMsgHandler*> _storage_type;
_storage_type m_storage;
public:
~ETWHandlerFactory();
IMsgHandler *GetSink(const wchar_t* sguid = DISPATCHER_LOG_EVENT_GUID);
protected:
ETWHandlerFactory(){}
};
#endif
#endif // #if defined(_WIN32) || defined(_WIN64)
#if defined(DISPATCHER_LOG_REGISTER_FILE_WRITER)
class FileSink
: public DSSingleTone<FileSink>
, public IMsgHandler
{
friend class DSSingleTone<FileSink>;
public:
virtual void Write(int level, int opcode, const char * msg, va_list argptr);
~FileSink()
{
if (NULL != m_hdl)
fclose(m_hdl);
}
private:
FILE * m_hdl;
FileSink(const std::string & log_file)
{
#if defined(_WIN32) || defined(_WIN64)
fopen_s(&m_hdl, log_file.c_str(), "a");
#else
m_hdl = fopen(log_file.c_str(), "a");
#endif
}
};
#endif
//-----utility functions
//since they are not called outside of macro we can define them here
std::string DispatcherLog_GetMFXImplString(int impl);
const char *DispatcherLog_GetMFXStatusString(int sts);
#else // !defined(MFX_DISPATCHER_LOG)
#define DISPATCHER_LOG(level, opcode, message)
#define DISPATCHER_LOG_AUTO(level, message)
#define DISPATCHER_LOG_OPERATION(operation)
#endif// !defined(MFX_DISPATCHER_LOG)
#define DISPATCHER_LOG_INFO(msg) DISPATCHER_LOG(DL_INFO, DL_EVENT_MSG, msg)
#define DISPATCHER_LOG_WRN(msg) DISPATCHER_LOG(DL_WRN, DL_EVENT_MSG, msg)
#define DISPATCHER_LOG_ERROR(msg) DISPATCHER_LOG(DL_ERROR, DL_EVENT_MSG, msg)
#define DISPATCHER_LOG_LIBRARY(msg) DISPATCHER_LOG(DL_LOADED_LIBRARY, DL_EVENT_MSG, msg)
#define DISPATCHER_LOG_BLOCK(msg) DISPATCHER_LOG_AUTO(DL_INFO, msg)
#endif // !defined(__MFX_DISPATCHER_LOG_H)
/* ****************************************************************************** *\
Copyright (C) 2012-2013 Intel Corporation. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- Neither the name of Intel Corporation nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL INTEL CORPORATION BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
File Name: mfx_dxva2_device.h
\* ****************************************************************************** */
#if !defined(__MFX_DXVA2_DEVICE_H)
#define __MFX_DXVA2_DEVICE_H
#if defined(_WIN32) || defined(_WIN64)
#include <windows.h>
#endif // #if defined(_WIN32) || defined(_WIN64)
#include <mfxdefs.h>
#ifdef DXVA2DEVICE_LOG
#include <stdio.h>
#define DXVA2DEVICE_TRACE(expr) printf expr;
#define DXVA2DEVICE_TRACE_OPERATION(expr) expr;
#else
#define DXVA2DEVICE_TRACE(expr)
#define DXVA2DEVICE_TRACE_OPERATION(expr)
#endif
namespace MFX
{
class DXDevice
{
public:
// Default constructor
DXDevice(void);
// Destructor
virtual
~DXDevice(void) = 0;
// Initialize device using DXGI 1.1 or VAAPI interface
virtual
bool Init(const mfxU32 adapterNum) = 0;
// Obtain graphic card's parameter
mfxU32 GetVendorID(void) const;
mfxU32 GetDeviceID(void) const;
mfxU64 GetDriverVersion(void) const;
mfxU64 GetLUID(void) const;
// Provide the number of available adapters
mfxU32 GetAdapterCount(void) const;
// Close the object
virtual
void Close(void);
// Load the required DLL module
void LoadDLLModule(const wchar_t *pModuleName);
protected:
// Free DLL module
void UnloadDLLModule(void);
#if defined(_WIN32) || defined(_WIN64)
// Handle to the DLL library
HMODULE m_hModule;
#endif // #if defined(_WIN32) || defined(_WIN64)
// Number of adapters available
mfxU32 m_numAdapters;
// Vendor ID
mfxU32 m_vendorID;
// Device ID
mfxU32 m_deviceID;
// x.x.x.x each x of two bytes
mfxU64 m_driverVersion;
// LUID
mfxU64 m_luid;
private:
// unimplemented by intent to make this class and its descendants non-copyable
DXDevice(const DXDevice &);
void operator=(const DXDevice &);
};
#if defined(_WIN32) || defined(_WIN64)
class D3D9Device : public DXDevice
{
public:
// Default constructor
D3D9Device(void);
// Destructor
virtual
~D3D9Device(void);
// Initialize device using D3D v9 interface
virtual
bool Init(const mfxU32 adapterNum);
// Close the object
virtual
void Close(void);
protected:
// Pointer to the D3D v9 interface
void *m_pD3D9;
// Pointer to the D3D v9 extended interface
void *m_pD3D9Ex;
};
class DXGI1Device : public DXDevice
{
public:
// Default constructor
DXGI1Device(void);
// Destructor
virtual
~DXGI1Device(void);
// Initialize device
virtual
bool Init(const mfxU32 adapterNum);
// Close the object
virtual
void Close(void);
protected:
// Pointer to the DXGI1 factory
void *m_pDXGIFactory1;
// Pointer to the current DXGI1 adapter
void *m_pDXGIAdapter1;
};
#endif // #if defined(_WIN32) || defined(_WIN64)
class DXVA2Device
{
public:
// Default constructor
DXVA2Device(void);
// Destructor
~DXVA2Device(void);
// Initialize device using D3D v9 interface
bool InitD3D9(const mfxU32 adapterNum);
// Initialize device using DXGI 1.1 interface
bool InitDXGI1(const mfxU32 adapterNum);
// Obtain graphic card's parameter
mfxU32 GetVendorID(void) const;
mfxU32 GetDeviceID(void) const;
mfxU64 GetDriverVersion(void) const;
// Provide the number of available adapters
mfxU32 GetAdapterCount(void) const;
void Close(void);
protected:
// Get vendor & device IDs by alternative way (D3D9 in Remote Desktop sessions)
void UseAlternativeWay(const D3D9Device *pD3D9Device);
// Number of adapters available
mfxU32 m_numAdapters;
// Vendor ID
mfxU32 m_vendorID;
// Device ID
mfxU32 m_deviceID;
//x.x.x.x
mfxU64 m_driverVersion;
private:
// unimplemented by intent to make this class non-copyable
DXVA2Device(const DXVA2Device &);
void operator=(const DXVA2Device &);
};
} // namespace MFX
#endif // __MFX_DXVA2_DEVICE_H
/* ****************************************************************************** *\
Copyright (C) 2012-2014 Intel Corporation. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- Neither the name of Intel Corporation nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL INTEL CORPORATION BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
File Name: mfx_exposed_functions_list.h
\* ****************************************************************************** */
//
// WARNING:
// this file doesn't contain an include guard by intension.
// The file may be included into a source file many times.
// That is why this header doesn't contain any include directive.
// Please, do no try to fix it.
//
// Use define API_VERSION to set the API of functions listed further
// When new functions are added new section with functions declarations must be started with updated define
//
// API version 1.0 functions
//
// API version where a function is added. Minor value should precedes the major value
#define API_VERSION {{0, 1}}
// CORE interface functions
FUNCTION(mfxStatus, MFXVideoCORE_SetBufferAllocator, (mfxSession session, mfxBufferAllocator *allocator), (session, allocator))
FUNCTION(mfxStatus, MFXVideoCORE_SetFrameAllocator, (mfxSession session, mfxFrameAllocator *allocator), (session, allocator))
FUNCTION(mfxStatus, MFXVideoCORE_SetHandle, (mfxSession session, mfxHandleType type, mfxHDL hdl), (session, type, hdl))
FUNCTION(mfxStatus, MFXVideoCORE_GetHandle, (mfxSession session, mfxHandleType type, mfxHDL *hdl), (session, type, hdl))
FUNCTION(mfxStatus, MFXVideoCORE_SyncOperation, (mfxSession session, mfxSyncPoint syncp, mfxU32 wait), (session, syncp, wait))
// ENCODE interface functions
FUNCTION(mfxStatus, MFXVideoENCODE_Query, (mfxSession session, mfxVideoParam *in, mfxVideoParam *out), (session, in, out))
FUNCTION(mfxStatus, MFXVideoENCODE_QueryIOSurf, (mfxSession session, mfxVideoParam *par, mfxFrameAllocRequest *request), (session, par, request))
FUNCTION(mfxStatus, MFXVideoENCODE_Init, (mfxSession session, mfxVideoParam *par), (session, par))
FUNCTION(mfxStatus, MFXVideoENCODE_Reset, (mfxSession session, mfxVideoParam *par), (session, par))
FUNCTION(mfxStatus, MFXVideoENCODE_Close, (mfxSession session), (session))
FUNCTION(mfxStatus, MFXVideoENCODE_GetVideoParam, (mfxSession session, mfxVideoParam *par), (session, par))
FUNCTION(mfxStatus, MFXVideoENCODE_GetEncodeStat, (mfxSession session, mfxEncodeStat *stat), (session, stat))
FUNCTION(mfxStatus, MFXVideoENCODE_EncodeFrameAsync, (mfxSession session, mfxEncodeCtrl *ctrl, mfxFrameSurface1 *surface, mfxBitstream *bs, mfxSyncPoint *syncp), (session, ctrl, surface, bs, syncp))
// DECODE interface functions
FUNCTION(mfxStatus, MFXVideoDECODE_Query, (mfxSession session, mfxVideoParam *in, mfxVideoParam *out), (session, in, out))
FUNCTION(mfxStatus, MFXVideoDECODE_DecodeHeader, (mfxSession session, mfxBitstream *bs, mfxVideoParam *par), (session, bs, par))
FUNCTION(mfxStatus, MFXVideoDECODE_QueryIOSurf, (mfxSession session, mfxVideoParam *par, mfxFrameAllocRequest *request), (session, par, request))
FUNCTION(mfxStatus, MFXVideoDECODE_Init, (mfxSession session, mfxVideoParam *par), (session, par))
FUNCTION(mfxStatus, MFXVideoDECODE_Reset, (mfxSession session, mfxVideoParam *par), (session, par))
FUNCTION(mfxStatus, MFXVideoDECODE_Close, (mfxSession session), (session))
FUNCTION(mfxStatus, MFXVideoDECODE_GetVideoParam, (mfxSession session, mfxVideoParam *par), (session, par))
FUNCTION(mfxStatus, MFXVideoDECODE_GetDecodeStat, (mfxSession session, mfxDecodeStat *stat), (session, stat))
FUNCTION(mfxStatus, MFXVideoDECODE_SetSkipMode, (mfxSession session, mfxSkipMode mode), (session, mode))
FUNCTION(mfxStatus, MFXVideoDECODE_GetPayload, (mfxSession session, mfxU64 *ts, mfxPayload *payload), (session, ts, payload))
FUNCTION(mfxStatus, MFXVideoDECODE_DecodeFrameAsync, (mfxSession session, mfxBitstream *bs, mfxFrameSurface1 *surface_work, mfxFrameSurface1 **surface_out, mfxSyncPoint *syncp), (session, bs, surface_work, surface_out, syncp))
// VPP interface functions
FUNCTION(mfxStatus, MFXVideoVPP_Query, (mfxSession session, mfxVideoParam *in, mfxVideoParam *out), (session, in, out))
FUNCTION(mfxStatus, MFXVideoVPP_QueryIOSurf, (mfxSession session, mfxVideoParam *par, mfxFrameAllocRequest *request), (session, par, request))
FUNCTION(mfxStatus, MFXVideoVPP_Init, (mfxSession session, mfxVideoParam *par), (session, par))
FUNCTION(mfxStatus, MFXVideoVPP_Reset, (mfxSession session, mfxVideoParam *par), (session, par))
FUNCTION(mfxStatus, MFXVideoVPP_Close, (mfxSession session), (session))
FUNCTION(mfxStatus, MFXVideoVPP_GetVideoParam, (mfxSession session, mfxVideoParam *par), (session, par))
FUNCTION(mfxStatus, MFXVideoVPP_GetVPPStat, (mfxSession session, mfxVPPStat *stat), (session, stat))
FUNCTION(mfxStatus, MFXVideoVPP_RunFrameVPPAsync, (mfxSession session, mfxFrameSurface1 *in, mfxFrameSurface1 *out, mfxExtVppAuxData *aux, mfxSyncPoint *syncp), (session, in, out, aux, syncp))
#undef API_VERSION
//
// API version 1.1 functions
//
#define API_VERSION {{1, 1}}
FUNCTION(mfxStatus, MFXVideoUSER_Register, (mfxSession session, mfxU32 type, const mfxPlugin *par), (session, type, par))
FUNCTION(mfxStatus, MFXVideoUSER_Unregister, (mfxSession session, mfxU32 type), (session, type))
FUNCTION(mfxStatus, MFXVideoUSER_ProcessFrameAsync, (mfxSession session, const mfxHDL *in, mfxU32 in_num, const mfxHDL *out, mfxU32 out_num, mfxSyncPoint *syncp), (session, in, in_num, out, out_num, syncp))
#undef API_VERSION
//
// API version 1.10 functions
//
#define API_VERSION {{10, 1}}
FUNCTION(mfxStatus, MFXVideoENC_Query,(mfxSession session, mfxVideoParam *in, mfxVideoParam *out), (session,in,out))
FUNCTION(mfxStatus, MFXVideoENC_QueryIOSurf,(mfxSession session, mfxVideoParam *par, mfxFrameAllocRequest *request), (session,par,request))
FUNCTION(mfxStatus, MFXVideoENC_Init,(mfxSession session, mfxVideoParam *par), (session,par))
FUNCTION(mfxStatus, MFXVideoENC_Reset,(mfxSession session, mfxVideoParam *par), (session,par))
FUNCTION(mfxStatus, MFXVideoENC_Close,(mfxSession session),(session))
FUNCTION(mfxStatus, MFXVideoENC_ProcessFrameAsync,(mfxSession session, mfxENCInput *in, mfxENCOutput *out, mfxSyncPoint *syncp),(session,in,out,syncp))
FUNCTION(mfxStatus, MFXVideoVPP_RunFrameVPPAsyncEx, (mfxSession session, mfxFrameSurface1 *in, mfxFrameSurface1 *work, mfxFrameSurface1 **out, mfxSyncPoint *syncp), (session, in, work, out, syncp))
#undef API_VERSION
#define API_VERSION {{13, 1}}
FUNCTION(mfxStatus, MFXVideoPAK_Query, (mfxSession session, mfxVideoParam *in, mfxVideoParam *out), (session, in, out))
FUNCTION(mfxStatus, MFXVideoPAK_QueryIOSurf, (mfxSession session, mfxVideoParam *par, mfxFrameAllocRequest *request), (session, par, request))
FUNCTION(mfxStatus, MFXVideoPAK_Init, (mfxSession session, mfxVideoParam *par), (session, par))
FUNCTION(mfxStatus, MFXVideoPAK_Reset, (mfxSession session, mfxVideoParam *par), (session, par))
FUNCTION(mfxStatus, MFXVideoPAK_Close, (mfxSession session), (session))
FUNCTION(mfxStatus, MFXVideoPAK_ProcessFrameAsync, (mfxSession session, mfxPAKInput *in, mfxPAKOutput *out, mfxSyncPoint *syncp), (session, in, out, syncp))
#undef API_VERSION
#define API_VERSION {{14, 1}}
// FUNCTION(mfxStatus, MFXInitEx, (mfxInitParam par, mfxSession session), (par, session))
FUNCTION(mfxStatus, MFXDoWork, (mfxSession session), (session))
#undef API_VERSION
\ No newline at end of file
/* ****************************************************************************** *\
Copyright (C) 2012-2014 Intel Corporation. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- Neither the name of Intel Corporation nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL INTEL CORPORATION BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
File Name: mfx_library_iterator.h
\* ****************************************************************************** */
#if !defined(__MFX_LIBRARY_ITERATOR_H)
#define __MFX_LIBRARY_ITERATOR_H
#include <mfxvideo.h>
#include "mfx_win_reg_key.h"
#include "mfx_dispatcher.h"
#if !defined(_WIN32) && !defined(_WIN64)
struct mfx_disp_adapters
{
mfxU32 vendor_id;
mfxU32 device_id;
};
#ifndef __APPLE__
#define MFX_SO_BASE_NAME_LEN 15 // sizeof("libmfxhw32-p.so") = 15
#else
#define MFX_SO_BASE_NAME_LEN 16 // sizeof("libmfxhw64.dylib") = 16
#endif
#define MFX_MIN_REAL_LIBNAME MFX_SO_BASE_NAME_LEN + 4 // sizeof("libmfxhw32-p.so.0.0") >= 19
#define MFX_MAX_REAL_LIBNAME MFX_MIN_REAL_LIBNAME + 8 // sizeof("libmfxhw32-p.so.<mj>.<mn>") <= 27, max(sizeof(<mj>))=sizeof(0xFFFF) = sizeof(65535) = 5
struct mfx_libs
{
char name[MFX_MAX_REAL_LIBNAME+1];
mfxVersion version;
};
#endif
namespace MFX
{
// declare desired storage ID
#if defined(_WIN32) || defined(_WIN64)
enum
{
MFX_UNKNOWN_KEY = -1,
MFX_CURRENT_USER_KEY = 0,
MFX_LOCAL_MACHINE_KEY = 1,
MFX_APP_FOLDER = 2,
MFX_STORAGE_ID_FIRST = MFX_CURRENT_USER_KEY,
MFX_STORAGE_ID_LAST = MFX_LOCAL_MACHINE_KEY
};
#else
enum
{
MFX_UNKNOWN_KEY = -1,
MFX_STORAGE_ID_OPT = 0, // storage is: /opt/intel
MFX_APP_FOLDER = 1,
MFX_STORAGE_ID_FIRST = MFX_STORAGE_ID_OPT,
MFX_STORAGE_ID_LAST = MFX_STORAGE_ID_OPT
};
#endif
// Try to initialize using given implementation type. Select appropriate type automatically in case of MFX_IMPL_VIA_ANY.
// Params: adapterNum - in, pImplInterface - in/out, pVendorID - out, pDeviceID - out
mfxStatus SelectImplementationType(const mfxU32 adapterNum, mfxIMPL *pImplInterface, mfxU32 *pVendorID, mfxU32 *pDeviceID);
class MFXLibraryIterator
{
public:
// Default constructor
MFXLibraryIterator(void);
// Destructor
~MFXLibraryIterator(void);
// Initialize the iterator
mfxStatus Init(eMfxImplType implType, mfxIMPL implInterface, const mfxU32 adapterNum, int storageID);
// Get the next library path
mfxStatus SelectDLLVersion(msdk_disp_char *pPath, size_t pathSize,
eMfxImplType *pImplType, mfxVersion minVersion);
// Return interface type on which Intel adapter was found (if any): D3D9 or D3D11
mfxIMPL GetImplementationType();
// Retrun registry subkey name on which dll was selected after sucesfull call to selectDllVesion
bool GetSubKeyName(msdk_disp_char *subKeyName, size_t length) const;
int GetStorageID() const { return m_StorageID; }
protected:
// Release the iterator
void Release(void);
// Initialize the registry iterator
mfxStatus InitRegistry(eMfxImplType implType, mfxIMPL implInterface, const mfxU32 adapterNum, int storageID);
// Initialize the app folder iterator
mfxStatus InitFolder(eMfxImplType implType, mfxIMPL implInterface, const mfxU32 adapterNum, const msdk_disp_char * path);
eMfxImplType m_implType; // Required library implementation
mfxIMPL m_implInterface; // Required interface (D3D9, D3D11)
mfxU32 m_vendorID; // (mfxU32) property of used graphic card
mfxU32 m_deviceID; // (mfxU32) property of used graphic card
bool m_bIsSubKeyValid;
wchar_t m_SubKeyName[MFX_MAX_REGISTRY_KEY_NAME]; // registry subkey for selected module loaded
int m_StorageID;
#if defined(_WIN32) || defined(_WIN64)
WinRegKey m_baseRegKey; // (WinRegKey) main registry key
mfxU32 m_lastLibIndex; // (mfxU32) index of previously returned library
mfxU32 m_lastLibMerit; // (mfxU32) merit of previously returned library
#else
int m_lastLibIndex; // (mfxU32) index of previously returned library
mfxU32 m_adapters_num;
struct mfx_disp_adapters* m_adapters;
int m_selected_adapter;
mfxU32 m_libs_num;
struct mfx_libs* m_libs;
#endif // #if defined(_WIN32) || defined(_WIN64)
msdk_disp_char m_path[260];
private:
// unimplemented by intent to make this class non-copyable
MFXLibraryIterator(const MFXLibraryIterator &);
void operator=(const MFXLibraryIterator &);
};
} // namespace MFX
#endif // __MFX_LIBRARY_ITERATOR_H
/* ****************************************************************************** *\
Copyright (C) 2012-2014 Intel Corporation. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- Neither the name of Intel Corporation nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL INTEL CORPORATION BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
File Name: mfx_load_dll.h
\* ****************************************************************************** */
#if !defined(__MFX_LOAD_DLL_H)
#define __MFX_LOAD_DLL_H
#include "mfx_dispatcher.h"
namespace MFX
{
//
// declare DLL loading routines
//
mfxStatus mfx_get_rt_dll_name(msdk_disp_char *pPath, size_t pathSize);
mfxStatus mfx_get_default_dll_name(msdk_disp_char *pPath, size_t pathSize, eMfxImplType implType);
mfxStatus mfx_get_default_plugin_name(msdk_disp_char *pPath, size_t pathSize, eMfxImplType implType);
mfxStatus mfx_get_default_audio_dll_name(msdk_disp_char *pPath, size_t pathSize, eMfxImplType implType);
mfxModuleHandle mfx_dll_load(const msdk_disp_char *file_name);
//increments reference counter
mfxModuleHandle mfx_get_dll_handle(const msdk_disp_char *file_name);
mfxFunctionPointer mfx_dll_get_addr(mfxModuleHandle handle, const char *func_name);
bool mfx_dll_free(mfxModuleHandle handle);
} // namespace MFX
#endif // __MFX_LOAD_DLL_H
/* ****************************************************************************** *\
Copyright (C) 2013-2014 Intel Corporation. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- Neither the name of Intel Corporation nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL INTEL CORPORATION BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
File Name: mfx_load_plugin.h
\* ****************************************************************************** */
#pragma once
#include "mfxplugin.h"
#include "mfx_dispatcher_defs.h"
#include "mfx_plugin_hive.h"
namespace MFX
{
typedef mfxStatus (MFX_CDECL *CreatePluginPtr_t)(mfxPluginUID uid, mfxPlugin* plugin);
class PluginModule
{
mfxModuleHandle mHmodule;
CreatePluginPtr_t mCreatePluginPtr;
msdk_disp_char mPath[MAX_PLUGIN_PATH];
public:
PluginModule();
PluginModule(const msdk_disp_char * path);
PluginModule(const PluginModule & that) ;
PluginModule & operator = (const PluginModule & that);
bool Create(mfxPluginUID guid, mfxPlugin&);
~PluginModule(void);
private:
void Tidy();
};
class MFXPluginFactory {
struct FactoryRecord {
mfxPluginParam plgParams;
PluginModule module;
mfxPlugin plugin;
FactoryRecord () {}
FactoryRecord(const mfxPluginParam &plgParams,
PluginModule &module,
mfxPlugin plugin)
: plgParams(plgParams)
, module(module)
, plugin(plugin) {
}
};
MFXVector<FactoryRecord> mPlugins;
mfxU32 nPlugins;
mfxSession mSession;
public:
MFXPluginFactory(mfxSession session);
void Close();
mfxStatus Create(const PluginDescriptionRecord &);
bool Destroy(const mfxPluginUID &);
~MFXPluginFactory();
protected:
void DestroyPlugin( FactoryRecord & );
static bool RunVerification( const mfxPlugin & plg, const PluginDescriptionRecord &dsc, mfxPluginParam &pluginParams );
static bool VerifyEncoder( const mfxVideoCodecPlugin &videoCodec );
static bool VerifyAudioEncoder( const mfxAudioCodecPlugin &audioCodec );
static bool VerifyEnc( const mfxVideoCodecPlugin &videoEnc );
static bool VerifyVpp( const mfxVideoCodecPlugin &videoCodec );
static bool VerifyDecoder( const mfxVideoCodecPlugin &videoCodec );
static bool VerifyAudioDecoder( const mfxAudioCodecPlugin &audioCodec );
static bool VerifyCodecCommon( const mfxVideoCodecPlugin & Video );
};
}
/* ****************************************************************************** *\
Copyright (C) 2013-2014 Intel Corporation. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- Neither the name of Intel Corporation nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL INTEL CORPORATION BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
File Name: mfx_plugin_hive.h
\* ****************************************************************************** */
#pragma once
#include "mfx_dispatcher_defs.h"
#include "mfxplugin.h"
#include "mfx_win_reg_key.h"
#include "mfx_vector.h"
#include <string.h>
#include <memory>
#include <stdio.h>
struct MFX_DISP_HANDLE;
namespace MFX {
enum
{
MAX_PLUGIN_PATH = 4096
};
enum
{
MAX_PLUGIN_NAME = 4096
};
inline bool operator == (const mfxPluginUID &lhs, const mfxPluginUID & rhs)
{
return !memcmp(lhs.Data, rhs.Data, sizeof(mfxPluginUID));
}
inline bool operator != (const mfxPluginUID &lhs, const mfxPluginUID & rhs)
{
return !(lhs == rhs);
}
#ifdef _WIN32
//warning C4351: new behavior: elements of array 'MFX::PluginDescriptionRecord::sName' will be default initialized
#pragma warning (disable: 4351)
#endif
class PluginDescriptionRecord : public mfxPluginParam
{
public:
msdk_disp_char sPath[MAX_PLUGIN_PATH];
char sName[MAX_PLUGIN_NAME];
//used for FS plugins that has poor description
bool onlyVersionRegistered;
bool Default;
PluginDescriptionRecord()
: mfxPluginParam()
, sPath()
, sName()
, onlyVersionRegistered()
, Default()
{
}
};
typedef MFXVector<PluginDescriptionRecord> MFXPluginStorage;
class MFXPluginStorageBase : public MFXPluginStorage
{
protected:
mfxVersion mCurrentAPIVersion;
protected:
MFXPluginStorageBase(mfxVersion currentAPIVersion)
: mCurrentAPIVersion(currentAPIVersion)
{
}
void ConvertAPIVersion( mfxU32 APIVersion, PluginDescriptionRecord &descriptionRecord) const
{
descriptionRecord.APIVersion.Minor = static_cast<mfxU16> (APIVersion & 0x0ff);
descriptionRecord.APIVersion.Major = static_cast<mfxU16> (APIVersion >> 8);
}
};
//populated from registry
class MFXPluginsInHive : public MFXPluginStorageBase
{
public:
MFXPluginsInHive(int mfxStorageID, const msdk_disp_char *msdkLibSubKey, mfxVersion currentAPIVersion);
};
//plugins are loaded from FS close to executable
class MFXPluginsInFS : public MFXPluginStorageBase
{
bool mIsVersionParsed;
bool mIsAPIVersionParsed;
public:
MFXPluginsInFS(mfxVersion currentAPIVersion);
private:
bool ParseFile(FILE * f, PluginDescriptionRecord & des);
bool ParseKVPair( msdk_disp_char *key, msdk_disp_char * value, PluginDescriptionRecord & des);
};
//plugins are loaded from FS close to Runtime library
class MFXDefaultPlugins : public MFXPluginStorageBase
{
public:
MFXDefaultPlugins(mfxVersion currentAPIVersion, MFX_DISP_HANDLE * hdl, int implType);
private:
};
}
/* ****************************************************************************** *\
Copyright (C) 2013-2014 Intel Corporation. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- Neither the name of Intel Corporation nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL INTEL CORPORATION BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
File Name: mfx_vector.h
\* ****************************************************************************** */
#pragma once
#include "mfxstructures.h"
#include <exception>
namespace MFX
{
template <class T>
class iterator_tmpl
{
template <class U> friend class MFXVector;
mfxU32 mIndex;
T* mRecords;
iterator_tmpl(mfxU32 index , T * records)
: mIndex (index)
, mRecords(records)
{}
public:
iterator_tmpl()
: mIndex ()
, mRecords()
{}
bool operator ==(const iterator_tmpl<T> & that )const
{
return mIndex == that.mIndex;
}
bool operator !=(const iterator_tmpl<T> & that )const
{
return mIndex != that.mIndex;
}
mfxU32 operator - (const iterator_tmpl<T> &that) const
{
return mIndex - that.mIndex;
}
iterator_tmpl<T> & operator ++()
{
mIndex++;
return * this;
}
iterator_tmpl<T> & operator ++(int)
{
mIndex++;
return * this;
}
T & operator *()
{
return mRecords[mIndex];
}
T * operator ->()
{
return mRecords + mIndex;
}
};
class MFXVectorRangeError : public std::exception
{
};
template <class T>
class MFXVector
{
T* mRecords;
mfxU32 mNrecords;
public:
MFXVector()
: mRecords()
, mNrecords()
{}
MFXVector(const MFXVector & rhs)
: mRecords()
, mNrecords()
{
insert(end(), rhs.begin(), rhs.end());
}
MFXVector & operator = (const MFXVector & rhs)
{
if (this != &rhs)
{
clear();
insert(end(), rhs.begin(), rhs.end());
}
return *this;
}
virtual ~MFXVector ()
{
clear();
}
typedef iterator_tmpl<T> iterator;
iterator begin() const
{
return iterator(0u, mRecords);
}
iterator end() const
{
return iterator(mNrecords, mRecords);
}
void insert(iterator where, iterator beg_iter, iterator end_iter)
{
mfxU32 elementsToInsert = (end_iter - beg_iter);
if (!elementsToInsert)
{
return;
}
if (where.mIndex > mNrecords)
{
throw MFXVectorRangeError();
}
T *newRecords = new T[mNrecords + elementsToInsert]();
mfxU32 i = 0;
// save left
for (; i < where.mIndex; i++)
{
newRecords[i] = mRecords[i];
}
// insert
for (; beg_iter != end_iter; beg_iter++, i++)
{
newRecords[i] = *beg_iter;
}
//save right
for (; i < mNrecords + elementsToInsert; i++)
{
newRecords[i] = mRecords[i - elementsToInsert];
}
delete [] mRecords;
mRecords = newRecords;
mNrecords = i;
}
T& operator [] (mfxU32 idx)
{
return mRecords[idx];
}
void push_back(const T& obj)
{
T *newRecords = new T[mNrecords + 1]();
mfxU32 i = 0;
for (; i <mNrecords; i++)
{
newRecords[i] = mRecords[i];
}
newRecords[i] = obj;
delete [] mRecords;
mRecords = newRecords;
mNrecords = i + 1;
}
void erase (iterator at)
{
if (at.mIndex >= mNrecords)
{
throw MFXVectorRangeError();
}
mNrecords--;
mfxU32 i = at.mIndex;
for (; i != mNrecords; i++)
{
mRecords[i] = mRecords[i+1];
}
//destroy last element
mRecords[i] = T();
}
void resize(mfxU32 nSize)
{
T * newRecords = new T[nSize]();
for (mfxU32 i = 0; i <mNrecords; i++)
{
newRecords[i] = mRecords[i];
}
delete [] mRecords;
mRecords = newRecords;
mNrecords = nSize;
}
mfxU32 size() const
{
return mNrecords;
}
void clear()
{
delete [] mRecords;
mRecords = 0;
mNrecords = 0;
}
};
}
/* ****************************************************************************** *\
Copyright (C) 2012-2014 Intel Corporation. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- Neither the name of Intel Corporation nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL INTEL CORPORATION BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
File Name: mfx_win_reg_key.h
\* ****************************************************************************** */
#if !defined(__MFX_WIN_REG_KEY_H)
#define __MFX_WIN_REG_KEY_H
#if defined(_WIN32) || defined(_WIN64)
#include <windows.h>
#include "mfxplugin.h"
#include "mfx_dispatcher_log.h"
namespace MFX {
template<class T> struct RegKey{};
template<> struct RegKey<bool>{enum {type = REG_DWORD};};
template<> struct RegKey<mfxU32>{enum {type = REG_DWORD};};
template<> struct RegKey<mfxPluginUID>{enum {type = REG_BINARY};};
template<> struct RegKey<mfxVersion>{enum {type = REG_DWORD};};
template<> struct RegKey<char*>{enum {type = REG_SZ};};
template<> struct RegKey<wchar_t*>{enum {type = REG_SZ};};
class WinRegKey
{
public:
// Default constructor
WinRegKey(void);
// Destructor
~WinRegKey(void);
// Open a registry key
bool Open(HKEY hRootKey, const wchar_t *pSubKey, REGSAM samDesired);
bool Open(WinRegKey &rootKey, const wchar_t *pSubKey, REGSAM samDesired);
// Query value
bool QueryInfo(LPDWORD lpcSubkeys);
bool QueryValueSize(const wchar_t *pValueName, DWORD type, LPDWORD pcbData);
bool Query(const wchar_t *pValueName, DWORD type, LPBYTE pData, LPDWORD pcbData);
bool Query(const wchar_t *pValueName, wchar_t *pData, mfxU32 &nData) {
DWORD dw = (DWORD)nData;
if (!Query(pValueName, RegKey<wchar_t*>::type, (LPBYTE)pData, &dw)){
return false;
}
nData = dw;
return true;
}
// Enumerate value names
bool EnumValue(DWORD index, wchar_t *pValueName, LPDWORD pcchValueName, LPDWORD pType);
bool EnumKey(DWORD index, wchar_t *pValueName, LPDWORD pcchValueName);
protected:
// Release the object
void Release(void);
HKEY m_hKey; // (HKEY) handle to the opened key
private:
// unimplemented by intent to make this class non-copyable
WinRegKey(const WinRegKey &);
void operator=(const WinRegKey &);
};
template<class T>
inline bool QueryKey(WinRegKey & key, const wchar_t *pValueName, T &data ) {
DWORD size = sizeof(data);
return key.Query(pValueName, RegKey<T>::type, (LPBYTE) &data, &size);
}
template<>
inline bool QueryKey<bool>(WinRegKey & key, const wchar_t *pValueName, bool &data ) {
mfxU32 value = 0;
bool bRes = QueryKey(key, pValueName, value);
data = (1 == value);
return bRes;
}
} // namespace MFX
#endif // #if defined(_WIN32) || defined(_WIN64)
#endif // __MFX_WIN_REG_KEY_H
/* ****************************************************************************** *\
Copyright (C) 2013-2014 Intel Corporation. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- Neither the name of Intel Corporation nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL INTEL CORPORATION BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
File Name: mfxaudio_exposed_function_list.h
\* ****************************************************************************** */
//
// WARNING:
// this file doesn't contain an include guard by intension.
// The file may be included into a source file many times.
// That is why this header doesn't contain any include directive.
// Please, do no try to fix it.
//
//
// API version 1.8 functions
//
// Minor value should precedes the major value
#define API_VERSION {{8, 1}}
// CORE interface functions
FUNCTION(mfxStatus, MFXAudioCORE_SyncOperation, (mfxSession session, mfxSyncPoint syncp, mfxU32 wait), (session, syncp, wait))
// ENCODE interface functions
FUNCTION(mfxStatus, MFXAudioENCODE_Query, (mfxSession session, mfxAudioParam *in, mfxAudioParam *out), (session, in, out))
FUNCTION(mfxStatus, MFXAudioENCODE_QueryIOSize, (mfxSession session, mfxAudioParam *par, mfxAudioAllocRequest *request), (session, par, request))
FUNCTION(mfxStatus, MFXAudioENCODE_Init, (mfxSession session, mfxAudioParam *par), (session, par))
FUNCTION(mfxStatus, MFXAudioENCODE_Reset, (mfxSession session, mfxAudioParam *par), (session, par))
FUNCTION(mfxStatus, MFXAudioENCODE_Close, (mfxSession session), (session))
FUNCTION(mfxStatus, MFXAudioENCODE_GetAudioParam, (mfxSession session, mfxAudioParam *par), (session, par))
FUNCTION(mfxStatus, MFXAudioENCODE_EncodeFrameAsync, (mfxSession session, mfxAudioFrame *frame, mfxBitstream *buffer_out, mfxSyncPoint *syncp), (session, frame, buffer_out, syncp))
// DECODE interface functions
FUNCTION(mfxStatus, MFXAudioDECODE_Query, (mfxSession session, mfxAudioParam *in, mfxAudioParam *out), (session, in, out))
FUNCTION(mfxStatus, MFXAudioDECODE_DecodeHeader, (mfxSession session, mfxBitstream *bs, mfxAudioParam *par), (session, bs, par))
FUNCTION(mfxStatus, MFXAudioDECODE_Init, (mfxSession session, mfxAudioParam *par), (session, par))
FUNCTION(mfxStatus, MFXAudioDECODE_Reset, (mfxSession session, mfxAudioParam *par), (session, par))
FUNCTION(mfxStatus, MFXAudioDECODE_Close, (mfxSession session), (session))
FUNCTION(mfxStatus, MFXAudioDECODE_QueryIOSize, (mfxSession session, mfxAudioParam *par, mfxAudioAllocRequest *request), (session, par, request))
FUNCTION(mfxStatus, MFXAudioDECODE_GetAudioParam, (mfxSession session, mfxAudioParam *par), (session, par))
FUNCTION(mfxStatus, MFXAudioDECODE_DecodeFrameAsync, (mfxSession session, mfxBitstream *bs, mfxAudioFrame *frame_out, mfxSyncPoint *syncp), (session, bs, frame_out, syncp))
#undef API_VERSION
//
// API version 1.9 functions
//
#define API_VERSION {{9, 1}}
FUNCTION(mfxStatus, MFXAudioUSER_Register, (mfxSession session, mfxU32 type, const mfxPlugin *par), (session, type, par))
FUNCTION(mfxStatus, MFXAudioUSER_Unregister, (mfxSession session, mfxU32 type), (session, type))
FUNCTION(mfxStatus, MFXAudioUSER_ProcessFrameAsync, (mfxSession session, const mfxHDL *in, mfxU32 in_num, const mfxHDL *out, mfxU32 out_num, mfxSyncPoint *syncp), (session, in, in_num, out, out_num, syncp))
#undef API_VERSION
/*******************************************************************************
Copyright (C) 2013 Intel Corporation. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- Neither the name of Intel Corporation nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL INTEL CORPORATION BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
File Name: mfxastructures.h
*******************************************************************************/
#ifndef __MFXASTRUCTURES_H__
#define __MFXASTRUCTURES_H__
#include "mfxcommon.h"
#if !defined (__GNUC__)
#pragma warning(disable: 4201)
#endif
#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */
/* CodecId */
enum {
MFX_CODEC_AAC =MFX_MAKEFOURCC('A','A','C',' '),
MFX_CODEC_MP3 =MFX_MAKEFOURCC('M','P','3',' ')
};
enum {
/* AAC Profiles & Levels */
MFX_PROFILE_AAC_LC =2,
MFX_PROFILE_AAC_LTP =4,
MFX_PROFILE_AAC_MAIN =1,
MFX_PROFILE_AAC_SSR =3,
MFX_PROFILE_AAC_HE =5,
MFX_PROFILE_AAC_ALS =0x20,
MFX_PROFILE_AAC_BSAC =22,
MFX_PROFILE_AAC_PS =29,
/*MPEG AUDIO*/
MFX_AUDIO_MPEG1_LAYER1 =0x00000110,
MFX_AUDIO_MPEG1_LAYER2 =0x00000120,
MFX_AUDIO_MPEG1_LAYER3 =0x00000140,
MFX_AUDIO_MPEG2_LAYER1 =0x00000210,
MFX_AUDIO_MPEG2_LAYER2 =0x00000220,
MFX_AUDIO_MPEG2_LAYER3 =0x00000240
};
/*AAC HE decoder down sampling*/
enum {
MFX_AUDIO_AAC_HE_DWNSMPL_OFF=0,
MFX_AUDIO_AAC_HE_DWNSMPL_ON= 1
};
/* AAC decoder support of PS */
enum {
MFX_AUDIO_AAC_PS_DISABLE= 0,
MFX_AUDIO_AAC_PS_PARSER= 1,
MFX_AUDIO_AAC_PS_ENABLE_BL= 111,
MFX_AUDIO_AAC_PS_ENABLE_UR= 411
};
/*AAC decoder SBR support*/
enum {
MFX_AUDIO_AAC_SBR_DISABLE = 0,
MFX_AUDIO_AAC_SBR_ENABLE= 1,
MFX_AUDIO_AAC_SBR_UNDEF= 2
};
/*AAC header type*/
enum{
MFX_AUDIO_AAC_ADTS= 1,
MFX_AUDIO_AAC_ADIF= 2,
MFX_AUDIO_AAC_RAW= 3,
};
/*AAC encoder stereo mode*/
enum
{
MFX_AUDIO_AAC_MONO= 0,
MFX_AUDIO_AAC_LR_STEREO= 1,
MFX_AUDIO_AAC_MS_STEREO= 2,
MFX_AUDIO_AAC_JOINT_STEREO= 3
};
typedef struct {
mfxU32 CodecId;
mfxU16 CodecProfile;
mfxU16 CodecLevel;
mfxU32 Bitrate;
mfxU32 SampleFrequency;
mfxU16 NumChannel;
mfxU16 BitPerSample;
mfxU16 reserved1[22];
union {
struct { /* AAC Decoding Options */
mfxU16 FlagPSSupportLev;
mfxU16 Layer;
mfxU16 AACHeaderDataSize;
mfxU8 AACHeaderData[64];
};
struct { /* AAC Encoding Options */
mfxU16 OutputFormat;
mfxU16 StereoMode;
mfxU16 reserved2[61];
};
};
} mfxAudioInfoMFX;
typedef struct {
mfxU16 AsyncDepth;
mfxU16 Protected;
mfxU16 reserved[14];
mfxAudioInfoMFX mfx;
mfxExtBuffer** ExtParam;
mfxU16 NumExtParam;
} mfxAudioParam;
typedef struct {
mfxU32 SuggestedInputSize;
mfxU32 SuggestedOutputSize;
mfxU32 reserved[6];
} mfxAudioAllocRequest;
typedef struct {
mfxU64 TimeStamp; /* 1/90KHz */
mfxU16 Locked;
mfxU16 NumChannels;
mfxU32 SampleFrequency;
mfxU16 BitPerSample;
mfxU16 reserved1[7];
mfxU8* Data;
mfxU32 reserved2;
mfxU32 DataLength;
mfxU32 MaxLength;
mfxU32 NumExtParam;
mfxExtBuffer **ExtParam;
} mfxAudioFrame;
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
/*******************************************************************************
Copyright (C) 2013 Intel Corporation. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- Neither the name of Intel Corporation nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL INTEL CORPORATION BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
File Name: mfxaudio++.h
*******************************************************************************/
#ifndef __MFXAUDIOPLUSPLUS_H
#define __MFXAUDIOPLUSPLUS_H
#include "mfxaudio.h"
class MFXAudioSession
{
public:
MFXAudioSession(void) { m_session = (mfxSession) 0; }
virtual ~MFXAudioSession(void) { Close(); }
virtual mfxStatus Init(mfxIMPL impl, mfxVersion *ver) { return MFXInit(impl, ver, &m_session); }
virtual mfxStatus Close(void)
{
mfxStatus mfxRes;
mfxRes = MFXClose(m_session); m_session = (mfxSession) 0;
return mfxRes;
}
virtual mfxStatus QueryIMPL(mfxIMPL *impl) { return MFXQueryIMPL(m_session, impl); }
virtual mfxStatus QueryVersion(mfxVersion *version) { return MFXQueryVersion(m_session, version); }
virtual mfxStatus JoinSession(mfxSession child_session) { return MFXJoinSession(m_session, child_session);}
virtual mfxStatus DisjoinSession( ) { return MFXDisjoinSession(m_session);}
virtual mfxStatus CloneSession( mfxSession *clone) { return MFXCloneSession(m_session, clone);}
virtual mfxStatus SetPriority( mfxPriority priority) { return MFXSetPriority(m_session, priority);}
virtual mfxStatus GetPriority( mfxPriority *priority) { return MFXGetPriority(m_session, priority);}
virtual mfxStatus SyncOperation(mfxSyncPoint syncp, mfxU32 wait) { return MFXAudioCORE_SyncOperation(m_session, syncp, wait); }
virtual operator mfxSession (void) { return m_session; }
protected:
mfxSession m_session; // (mfxSession) handle to the owning session
};
class MFXAudioDECODE
{
public:
MFXAudioDECODE(mfxSession session) { m_session = session; }
virtual ~MFXAudioDECODE(void) { Close(); }
virtual mfxStatus Query(mfxAudioParam *in, mfxAudioParam *out) { return MFXAudioDECODE_Query(m_session, in, out); }
virtual mfxStatus DecodeHeader(mfxBitstream *bs, mfxAudioParam *par) { return MFXAudioDECODE_DecodeHeader(m_session, bs, par); }
virtual mfxStatus QueryIOSize(mfxAudioParam *par, mfxAudioAllocRequest *request) { return MFXAudioDECODE_QueryIOSize(m_session, par, request); }
virtual mfxStatus Init(mfxAudioParam *par) { return MFXAudioDECODE_Init(m_session, par); }
virtual mfxStatus Reset(mfxAudioParam *par) { return MFXAudioDECODE_Reset(m_session, par); }
virtual mfxStatus Close(void) { return MFXAudioDECODE_Close(m_session); }
virtual mfxStatus GetAudioParam(mfxAudioParam *par) { return MFXAudioDECODE_GetAudioParam(m_session, par); }
virtual mfxStatus DecodeFrameAsync(mfxBitstream *bs, mfxAudioFrame *frame, mfxSyncPoint *syncp) { return MFXAudioDECODE_DecodeFrameAsync(m_session, bs, frame, syncp); }
protected:
mfxSession m_session; // (mfxSession) handle to the owning session
};
class MFXAudioENCODE
{
public:
MFXAudioENCODE(mfxSession session) { m_session = session; }
virtual ~MFXAudioENCODE(void) { Close(); }
virtual mfxStatus Query(mfxAudioParam *in, mfxAudioParam *out) { return MFXAudioENCODE_Query(m_session, in, out); }
virtual mfxStatus QueryIOSize(mfxAudioParam *par, mfxAudioAllocRequest *request) { return MFXAudioENCODE_QueryIOSize(m_session, par, request); }
virtual mfxStatus Init(mfxAudioParam *par) { return MFXAudioENCODE_Init(m_session, par); }
virtual mfxStatus Reset(mfxAudioParam *par) { return MFXAudioENCODE_Reset(m_session, par); }
virtual mfxStatus Close(void) { return MFXAudioENCODE_Close(m_session); }
virtual mfxStatus GetAudioParam(mfxAudioParam *par) { return MFXAudioENCODE_GetAudioParam(m_session, par); }
virtual mfxStatus EncodeFrameAsync(mfxAudioFrame *frame, mfxBitstream *buffer_out, mfxSyncPoint *syncp) { return MFXAudioENCODE_EncodeFrameAsync(m_session, frame, buffer_out, syncp); }
protected:
mfxSession m_session; // (mfxSession) handle to the owning session
};
#endif
\ No newline at end of file
/*******************************************************************************
Copyright (C) 2013 Intel Corporation. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- Neither the name of Intel Corporation nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL INTEL CORPORATION BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
File Name: mfxaudio.h
*******************************************************************************/
#ifndef __MFXAUDIO_H__
#define __MFXAUDIO_H__
#include "mfxsession.h"
#include "mfxastructures.h"
#define MFX_AUDIO_VERSION_MAJOR 1
#define MFX_AUDIO_VERSION_MINOR 15
#ifdef __cplusplus
extern "C"
{
#endif
/* AudioCORE */
mfxStatus MFX_CDECL MFXAudioCORE_SyncOperation(mfxSession session, mfxSyncPoint syncp, mfxU32 wait);
/* AudioENCODE */
mfxStatus MFX_CDECL MFXAudioENCODE_Query(mfxSession session, mfxAudioParam *in, mfxAudioParam *out);
mfxStatus MFX_CDECL MFXAudioENCODE_QueryIOSize(mfxSession session, mfxAudioParam *par, mfxAudioAllocRequest *request);
mfxStatus MFX_CDECL MFXAudioENCODE_Init(mfxSession session, mfxAudioParam *par);
mfxStatus MFX_CDECL MFXAudioENCODE_Reset(mfxSession session, mfxAudioParam *par);
mfxStatus MFX_CDECL MFXAudioENCODE_Close(mfxSession session);
mfxStatus MFX_CDECL MFXAudioENCODE_GetAudioParam(mfxSession session, mfxAudioParam *par);
mfxStatus MFX_CDECL MFXAudioENCODE_EncodeFrameAsync(mfxSession session, mfxAudioFrame *frame, mfxBitstream *bs, mfxSyncPoint *syncp);
/* AudioDECODE */
mfxStatus MFX_CDECL MFXAudioDECODE_Query(mfxSession session, mfxAudioParam *in, mfxAudioParam *out);
mfxStatus MFX_CDECL MFXAudioDECODE_DecodeHeader(mfxSession session, mfxBitstream *bs, mfxAudioParam* par);
mfxStatus MFX_CDECL MFXAudioDECODE_Init(mfxSession session, mfxAudioParam *par);
mfxStatus MFX_CDECL MFXAudioDECODE_Reset(mfxSession session, mfxAudioParam *par);
mfxStatus MFX_CDECL MFXAudioDECODE_Close(mfxSession session);
mfxStatus MFX_CDECL MFXAudioDECODE_QueryIOSize(mfxSession session, mfxAudioParam *par, mfxAudioAllocRequest *request);
mfxStatus MFX_CDECL MFXAudioDECODE_GetAudioParam(mfxSession session, mfxAudioParam *par);
mfxStatus MFX_CDECL MFXAudioDECODE_DecodeFrameAsync(mfxSession session, mfxBitstream *bs, mfxAudioFrame *frame, mfxSyncPoint *syncp);
#ifdef __cplusplus
} // extern "C"
#endif
#endif
/*******************************************************************************
Copyright (C) 2013-2015 Intel Corporation. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- Neither the name of Intel Corporation nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL INTEL CORPORATION BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
File Name: mfxcommon.h
*******************************************************************************/
#ifndef __MFXCOMMON_H__
#define __MFXCOMMON_H__
#include "mfxdefs.h"
#if !defined (__GNUC__)
#pragma warning(disable: 4201)
#endif
#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */
#define MFX_MAKEFOURCC(A,B,C,D) ((((int)A))+(((int)B)<<8)+(((int)C)<<16)+(((int)D)<<24))
/* Extended Configuration Header Structure */
typedef struct {
mfxU32 BufferId;
mfxU32 BufferSz;
} mfxExtBuffer;
/* Library initialization and deinitialization */
typedef mfxI32 mfxIMPL;
#define MFX_IMPL_BASETYPE(x) (0x00ff & (x))
enum {
MFX_IMPL_AUTO = 0x0000, /* Auto Selection/In or Not Supported/Out */
MFX_IMPL_SOFTWARE = 0x0001, /* Pure Software Implementation */
MFX_IMPL_HARDWARE = 0x0002, /* Hardware Accelerated Implementation (default device) */
MFX_IMPL_AUTO_ANY = 0x0003, /* Auto selection of any hardware/software implementation */
MFX_IMPL_HARDWARE_ANY = 0x0004, /* Auto selection of any hardware implementation */
MFX_IMPL_HARDWARE2 = 0x0005, /* Hardware accelerated implementation (2nd device) */
MFX_IMPL_HARDWARE3 = 0x0006, /* Hardware accelerated implementation (3rd device) */
MFX_IMPL_HARDWARE4 = 0x0007, /* Hardware accelerated implementation (4th device) */
MFX_IMPL_RUNTIME = 0x0008,
MFX_IMPL_VIA_ANY = 0x0100,
MFX_IMPL_VIA_D3D9 = 0x0200,
MFX_IMPL_VIA_D3D11 = 0x0300,
MFX_IMPL_VIA_VAAPI = 0x0400,
MFX_IMPL_AUDIO = 0x8000,
MFX_IMPL_UNSUPPORTED = 0x0000 /* One of the MFXQueryIMPL returns */
};
/* Version Info */
typedef union {
struct {
mfxU16 Minor;
mfxU16 Major;
};
mfxU32 Version;
} mfxVersion;
/* session priority */
typedef enum
{
MFX_PRIORITY_LOW = 0,
MFX_PRIORITY_NORMAL = 1,
MFX_PRIORITY_HIGH = 2
} mfxPriority;
typedef struct _mfxEncryptedData mfxEncryptedData;
typedef struct {
union {
struct {
mfxEncryptedData* EncryptedData;
mfxExtBuffer **ExtParam;
mfxU16 NumExtParam;
};
mfxU32 reserved[6];
};
mfxI64 DecodeTimeStamp;
mfxU64 TimeStamp;
mfxU8* Data;
mfxU32 DataOffset;
mfxU32 DataLength;
mfxU32 MaxLength;
mfxU16 PicStruct;
mfxU16 FrameType;
mfxU16 DataFlag;
mfxU16 reserved2;
} mfxBitstream;
typedef struct _mfxSyncPoint *mfxSyncPoint;
/* GPUCopy */
enum {
MFX_GPUCOPY_DEFAULT = 0,
MFX_GPUCOPY_ON = 1,
MFX_GPUCOPY_OFF = 2
};
typedef struct {
mfxIMPL Implementation;
mfxVersion Version;
mfxU16 ExternalThreads;
union {
struct {
mfxExtBuffer **ExtParam;
mfxU16 NumExtParam;
};
mfxU16 reserved2[5];
};
mfxU16 GPUCopy;
mfxU16 reserved[21];
} mfxInitParam;
enum {
MFX_EXTBUFF_THREADS_PARAM = MFX_MAKEFOURCC('T','H','D','P')
};
typedef struct {
mfxExtBuffer Header;
mfxU16 NumThread;
mfxI32 SchedulingType;
mfxI32 Priority;
mfxU16 reserved[55];
} mfxExtThreadsParam;
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
/* ****************************************************************************** *\
Copyright (C) 2007-2015 Intel Corporation. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- Neither the name of Intel Corporation nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL INTEL CORPORATION BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
File Name: mfxdefs.h
\* ****************************************************************************** */
#ifndef __MFXDEFS_H__
#define __MFXDEFS_H__
#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */
#if (defined( _WIN32 ) || defined ( _WIN64 )) && !defined (__GNUC__)
#define __INT64 __int64
#define __UINT64 unsigned __int64
#else
#define __INT64 long long
#define __UINT64 unsigned long long
#endif
#ifdef _WIN32
#define MFX_CDECL __cdecl
#define MFX_STDCALL __stdcall
#else
#define MFX_CDECL
#define MFX_STDCALL
#endif /* _WIN32 */
#define MFX_INFINITE 0xFFFFFFFF
typedef unsigned char mfxU8;
typedef char mfxI8;
typedef short mfxI16;
typedef unsigned short mfxU16;
typedef unsigned int mfxU32;
typedef int mfxI32;
#if defined( _WIN32 ) || defined ( _WIN64 )
typedef unsigned long mfxUL32;
typedef long mfxL32;
#else
typedef unsigned int mfxUL32;
typedef int mfxL32;
#endif
typedef float mfxF32;
typedef double mfxF64;
typedef __UINT64 mfxU64;
typedef __INT64 mfxI64;
typedef void* mfxHDL;
typedef mfxHDL mfxMemId;
typedef void* mfxThreadTask;
typedef char mfxChar;
typedef struct {
mfxI16 x;
mfxI16 y;
} mfxI16Pair;
typedef struct {
mfxHDL first;
mfxHDL second;
} mfxHDLPair;
/*********************************************************************************\
Error message
\*********************************************************************************/
typedef enum
{
/* no error */
MFX_ERR_NONE = 0, /* no error */
/* reserved for unexpected errors */
MFX_ERR_UNKNOWN = -1, /* unknown error. */
/* error codes <0 */
MFX_ERR_NULL_PTR = -2, /* null pointer */
MFX_ERR_UNSUPPORTED = -3, /* undeveloped feature */
MFX_ERR_MEMORY_ALLOC = -4, /* failed to allocate memory */
MFX_ERR_NOT_ENOUGH_BUFFER = -5, /* insufficient buffer at input/output */
MFX_ERR_INVALID_HANDLE = -6, /* invalid handle */
MFX_ERR_LOCK_MEMORY = -7, /* failed to lock the memory block */
MFX_ERR_NOT_INITIALIZED = -8, /* member function called before initialization */
MFX_ERR_NOT_FOUND = -9, /* the specified object is not found */
MFX_ERR_MORE_DATA = -10, /* expect more data at input */
MFX_ERR_MORE_SURFACE = -11, /* expect more surface at output */
MFX_ERR_ABORTED = -12, /* operation aborted */
MFX_ERR_DEVICE_LOST = -13, /* lose the HW acceleration device */
MFX_ERR_INCOMPATIBLE_VIDEO_PARAM = -14, /* incompatible video parameters */
MFX_ERR_INVALID_VIDEO_PARAM = -15, /* invalid video parameters */
MFX_ERR_UNDEFINED_BEHAVIOR = -16, /* undefined behavior */
MFX_ERR_DEVICE_FAILED = -17, /* device operation failure */
MFX_ERR_MORE_BITSTREAM = -18, /* expect more bitstream buffers at output */
MFX_ERR_INCOMPATIBLE_AUDIO_PARAM = -19, /* incompatible audio parameters */
MFX_ERR_INVALID_AUDIO_PARAM = -20, /* invalid audio parameters */
/* warnings >0 */
MFX_WRN_IN_EXECUTION = 1, /* the previous asynchronous operation is in execution */
MFX_WRN_DEVICE_BUSY = 2, /* the HW acceleration device is busy */
MFX_WRN_VIDEO_PARAM_CHANGED = 3, /* the video parameters are changed during decoding */
MFX_WRN_PARTIAL_ACCELERATION = 4, /* SW is used */
MFX_WRN_INCOMPATIBLE_VIDEO_PARAM = 5, /* incompatible video parameters */
MFX_WRN_VALUE_NOT_CHANGED = 6, /* the value is saturated based on its valid range */
MFX_WRN_OUT_OF_RANGE = 7, /* the value is out of valid range */
MFX_WRN_FILTER_SKIPPED = 10, /* one of requested filters has been skipped */
MFX_WRN_INCOMPATIBLE_AUDIO_PARAM = 11, /* incompatible audio parameters */
/* threading statuses */
MFX_TASK_DONE = MFX_ERR_NONE, /* task has been completed */
MFX_TASK_WORKING = 8, /* there is some more work to do */
MFX_TASK_BUSY = 9 /* task is waiting for resources */
} mfxStatus;
// Application
#if defined(MFX_DISPATCHER_EXPOSED_PREFIX)
#include "mfxdispatcherprefixedfunctions.h"
#endif // MFX_DISPATCHER_EXPOSED_PREFIX
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __MFXDEFS_H__ */
/******************************************************************************* *\
Copyright (C) 2014 Intel Corporation. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- Neither the name of Intel Corporation nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL INTEL CORPORATION BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
File Name: mfxenc.h
*******************************************************************************/
#ifndef __MFXENC_H__
#define __MFXENC_H__
#include "mfxdefs.h"
#include "mfxvstructures.h"
#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */
typedef struct _mfxENCInput mfxENCInput;
struct _mfxENCInput{
mfxU32 reserved[32];
mfxFrameSurface1 *InSurface;
mfxU16 NumFrameL0;
mfxFrameSurface1 **L0Surface;
mfxU16 NumFrameL1;
mfxFrameSurface1 **L1Surface;
mfxU16 NumExtParam;
mfxExtBuffer **ExtParam;
} ;
typedef struct _mfxENCOutput mfxENCOutput;
struct _mfxENCOutput{
mfxU32 reserved[32];
mfxFrameSurface1 *OutSurface;
mfxU16 NumExtParam;
mfxExtBuffer **ExtParam;
} ;
mfxStatus MFX_CDECL MFXVideoENC_Query(mfxSession session, mfxVideoParam *in, mfxVideoParam *out);
mfxStatus MFX_CDECL MFXVideoENC_QueryIOSurf(mfxSession session, mfxVideoParam *par, mfxFrameAllocRequest *request);
mfxStatus MFX_CDECL MFXVideoENC_Init(mfxSession session, mfxVideoParam *par);
mfxStatus MFX_CDECL MFXVideoENC_Reset(mfxSession session, mfxVideoParam *par);
mfxStatus MFX_CDECL MFXVideoENC_Close(mfxSession session);
mfxStatus MFX_CDECL MFXVideoENC_ProcessFrameAsync(mfxSession session, mfxENCInput *in, mfxENCOutput *out, mfxSyncPoint *syncp);
#ifdef __cplusplus
} // extern "C"
#endif /* __cplusplus */
#endif
此差异已折叠。
此差异已折叠。
/******************************************************************************* *\
Copyright (C) 2014 Intel Corporation. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- Neither the name of Intel Corporation nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL INTEL CORPORATION BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
File Name: mfxpak.h
*******************************************************************************/
#ifndef __MFXPAK_H__
#define __MFXPAK_H__
#include "mfxdefs.h"
#include "mfxvstructures.h"
#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */
typedef struct {
mfxU32 reserved[32];
mfxFrameSurface1 *InSurface;
mfxU16 NumFrameL0;
mfxFrameSurface1 **L0Surface;
mfxU16 NumFrameL1;
mfxFrameSurface1 **L1Surface;
mfxU16 NumExtParam;
mfxExtBuffer **ExtParam;
} mfxPAKInput;
typedef struct {
mfxBitstream *Bs;
mfxFrameSurface1 *OutSurface;
mfxU16 NumExtParam;
mfxExtBuffer **ExtParam;
} mfxPAKOutput;
typedef struct _mfxSession *mfxSession;
mfxStatus MFX_CDECL MFXVideoPAK_Query(mfxSession session, mfxVideoParam *in, mfxVideoParam *out);
mfxStatus MFX_CDECL MFXVideoPAK_QueryIOSurf(mfxSession session, mfxVideoParam *par, mfxFrameAllocRequest *request);
mfxStatus MFX_CDECL MFXVideoPAK_Init(mfxSession session, mfxVideoParam *par);
mfxStatus MFX_CDECL MFXVideoPAK_Reset(mfxSession session, mfxVideoParam *par);
mfxStatus MFX_CDECL MFXVideoPAK_Close(mfxSession session);
mfxStatus MFX_CDECL MFXVideoPAK_ProcessFrameAsync(mfxSession session, mfxPAKInput *in, mfxPAKOutput *out, mfxSyncPoint *syncp);
#ifdef __cplusplus
} // extern "C"
#endif /* __cplusplus */
#endif
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册