Add a public C API to the library
Add a struct that matches the C++ interface vtable. This requires that the C++ interface methods are declared to use the same calling convention as normal C functions, and that the C struct exactly matches the layout and ordering of the C++ virtual table - MSVC seemed to reorder methods if there were overloaded methods.
This commit is contained in:
parent
dd0db820fc
commit
043575ffb0
@ -36,36 +36,43 @@
|
|||||||
#include "codec_app_def.h"
|
#include "codec_app_def.h"
|
||||||
#include "codec_def.h"
|
#include "codec_def.h"
|
||||||
|
|
||||||
|
#if defined(_WIN32) || defined(__cdecl)
|
||||||
|
#define EXTAPI __cdecl
|
||||||
|
#else
|
||||||
|
#define EXTAPI
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
class ISVCEncoder {
|
class ISVCEncoder {
|
||||||
public:
|
public:
|
||||||
/*
|
/*
|
||||||
* return: CM_RETURN: 0 - success; otherwise - failed;
|
* return: CM_RETURN: 0 - success; otherwise - failed;
|
||||||
*/
|
*/
|
||||||
virtual int Initialize (SVCEncodingParam* pParam, const INIT_TYPE kiInitType = INIT_TYPE_PARAMETER_BASED) = 0;
|
virtual int EXTAPI Initialize (SVCEncodingParam* pParam, const INIT_TYPE kiInitType = INIT_TYPE_PARAMETER_BASED) = 0;
|
||||||
virtual int Initialize2 (void* pParam, const INIT_TYPE kiInitType = INIT_TYPE_CONFIG_BASED) = 0;
|
virtual int EXTAPI Initialize2 (void* pParam, const INIT_TYPE kiInitType = INIT_TYPE_CONFIG_BASED) = 0;
|
||||||
|
|
||||||
virtual int Uninitialize() = 0;
|
virtual int EXTAPI Uninitialize() = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* return: EVideoFrameType [IDR: videoFrameTypeIDR; P: videoFrameTypeP; ERROR: videoFrameTypeInvalid]
|
* return: EVideoFrameType [IDR: videoFrameTypeIDR; P: videoFrameTypeP; ERROR: videoFrameTypeInvalid]
|
||||||
*/
|
*/
|
||||||
virtual int EncodeFrame (const unsigned char* kpSrc, SFrameBSInfo* pBsInfo) = 0;
|
virtual int EXTAPI EncodeFrame (const unsigned char* kpSrc, SFrameBSInfo* pBsInfo) = 0;
|
||||||
virtual int EncodeFrame2 (const SSourcePicture** kppSrcPicList, int nSrcPicNum, SFrameBSInfo* pBsInfo) = 0;
|
virtual int EXTAPI EncodeFrame2 (const SSourcePicture** kppSrcPicList, int nSrcPicNum, SFrameBSInfo* pBsInfo) = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* return: 0 - success; otherwise - failed;
|
* return: 0 - success; otherwise - failed;
|
||||||
*/
|
*/
|
||||||
virtual int EncodeParameterSets (SFrameBSInfo* pBsInfo) = 0;
|
virtual int EXTAPI EncodeParameterSets (SFrameBSInfo* pBsInfo) = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* return: 0 - success; otherwise - failed;
|
* return: 0 - success; otherwise - failed;
|
||||||
*/
|
*/
|
||||||
virtual int PauseFrame (const unsigned char* kpSrc, SFrameBSInfo* pBsInfo) = 0;
|
virtual int EXTAPI PauseFrame (const unsigned char* kpSrc, SFrameBSInfo* pBsInfo) = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* return: 0 - success; otherwise - failed;
|
* return: 0 - success; otherwise - failed;
|
||||||
*/
|
*/
|
||||||
virtual int ForceIntraFrame (bool bIDR) = 0;
|
virtual int EXTAPI ForceIntraFrame (bool bIDR) = 0;
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* InDataFormat, IDRInterval, SVC Encode Param, Frame Rate, Bitrate,..
|
* InDataFormat, IDRInterval, SVC Encode Param, Frame Rate, Bitrate,..
|
||||||
@ -73,58 +80,118 @@ class ISVCEncoder {
|
|||||||
/*
|
/*
|
||||||
* return: CM_RETURN: 0 - success; otherwise - failed;
|
* return: CM_RETURN: 0 - success; otherwise - failed;
|
||||||
*/
|
*/
|
||||||
virtual int SetOption (ENCODER_OPTION eOptionId, void* pOption) = 0;
|
virtual int EXTAPI SetOption (ENCODER_OPTION eOptionId, void* pOption) = 0;
|
||||||
virtual int GetOption (ENCODER_OPTION eOptionId, void* pOption) = 0;
|
virtual int EXTAPI GetOption (ENCODER_OPTION eOptionId, void* pOption) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ISVCDecoder {
|
class ISVCDecoder {
|
||||||
public:
|
public:
|
||||||
virtual long Initialize (void* pParam, const INIT_TYPE iInitType) = 0;
|
virtual long EXTAPI Initialize (void* pParam, const INIT_TYPE iInitType) = 0;
|
||||||
virtual long Uninitialize() = 0;
|
virtual long EXTAPI Uninitialize() = 0;
|
||||||
|
|
||||||
virtual DECODING_STATE DecodeFrame (const unsigned char* pSrc,
|
virtual DECODING_STATE EXTAPI DecodeFrame (const unsigned char* pSrc,
|
||||||
const int iSrcLen,
|
const int iSrcLen,
|
||||||
unsigned char** ppDst,
|
unsigned char** ppDst,
|
||||||
int* pStride,
|
int* pStride,
|
||||||
int& iWidth,
|
int& iWidth,
|
||||||
int& iHeight) = 0;
|
int& iHeight) = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* src must be 4 byte aligned, recommend 16 byte aligned. the available src size must be multiple of 4.
|
* src must be 4 byte aligned, recommend 16 byte aligned. the available src size must be multiple of 4.
|
||||||
*/
|
*/
|
||||||
virtual DECODING_STATE DecodeFrame2 (const unsigned char* pSrc,
|
virtual DECODING_STATE EXTAPI DecodeFrame2 (const unsigned char* pSrc,
|
||||||
const int iSrcLen,
|
const int iSrcLen,
|
||||||
void** ppDst,
|
void** ppDst,
|
||||||
SBufferInfo* pDstInfo) = 0;
|
SBufferInfo* pDstInfo) = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* src must be 4 byte aligned, recommend 16 byte aligned. the available src size must be multiple of 4.
|
* src must be 4 byte aligned, recommend 16 byte aligned. the available src size must be multiple of 4.
|
||||||
* this API does not work for now!! This is for future use to support non-I420 color format output.
|
* this API does not work for now!! This is for future use to support non-I420 color format output.
|
||||||
*/
|
*/
|
||||||
virtual DECODING_STATE DecodeFrameEx (const unsigned char* pSrc,
|
virtual DECODING_STATE EXTAPI DecodeFrameEx (const unsigned char* pSrc,
|
||||||
const int iSrcLen,
|
const int iSrcLen,
|
||||||
unsigned char* pDst,
|
unsigned char* pDst,
|
||||||
int iDstStride,
|
int iDstStride,
|
||||||
int& iDstLen,
|
int& iDstLen,
|
||||||
int& iWidth,
|
int& iWidth,
|
||||||
int& iHeight,
|
int& iHeight,
|
||||||
int& iColorFormat) = 0;
|
int& iColorFormat) = 0;
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
* OutDataFormat
|
* OutDataFormat
|
||||||
*************************************************************************/
|
*************************************************************************/
|
||||||
virtual long SetOption (DECODER_OPTION eOptionId, void* pOption) = 0;
|
virtual long EXTAPI SetOption (DECODER_OPTION eOptionId, void* pOption) = 0;
|
||||||
virtual long GetOption (DECODER_OPTION eOptionId, void* pOption) = 0;
|
virtual long EXTAPI GetOption (DECODER_OPTION eOptionId, void* pOption) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
|
#else
|
||||||
|
|
||||||
|
typedef struct ISVCEncoderVtbl ISVCEncoderVtbl;
|
||||||
|
typedef const ISVCEncoderVtbl* ISVCEncoder;
|
||||||
|
struct ISVCEncoderVtbl {
|
||||||
|
|
||||||
|
int (*Initialize) (ISVCEncoder*, SVCEncodingParam* pParam, const INIT_TYPE kiInitType);
|
||||||
|
int (*Initialize2) (ISVCEncoder*, void* pParam, const INIT_TYPE kiInitType);
|
||||||
|
|
||||||
|
int (*Uninitialize) (ISVCEncoder*);
|
||||||
|
|
||||||
|
int (*EncodeFrame) (ISVCEncoder*, const unsigned char* kpSrc, SFrameBSInfo* pBsInfo);
|
||||||
|
int (*EncodeFrame2) (ISVCEncoder*, const SSourcePicture** kppSrcPicList, int nSrcPicNum, SFrameBSInfo* pBsInfo);
|
||||||
|
|
||||||
|
int (*EncodeParameterSets) (ISVCEncoder*, SFrameBSInfo* pBsInfo);
|
||||||
|
|
||||||
|
int (*PauseFrame) (ISVCEncoder*, const unsigned char* kpSrc, SFrameBSInfo* pBsInfo);
|
||||||
|
|
||||||
|
int (*ForceIntraFrame) (ISVCEncoder*, bool bIDR);
|
||||||
|
|
||||||
|
int (*SetOption) (ISVCEncoder*, ENCODER_OPTION eOptionId, void* pOption);
|
||||||
|
int (*GetOption) (ISVCEncoder*, ENCODER_OPTION eOptionId, void* pOption);
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct ISVCDecoderVtbl ISVCDecoderVtbl;
|
||||||
|
typedef const ISVCDecoderVtbl* ISVCDecoder;
|
||||||
|
struct ISVCDecoderVtbl {
|
||||||
|
long (*Initialize) (ISVCDecoder*, void* pParam, const INIT_TYPE iInitType);
|
||||||
|
long (*Uninitialize) (ISVCDecoder*);
|
||||||
|
|
||||||
|
DECODING_STATE (*DecodeFrame) (ISVCDecoder*, const unsigned char* pSrc,
|
||||||
|
const int iSrcLen,
|
||||||
|
unsigned char** ppDst,
|
||||||
|
int* pStride,
|
||||||
|
int* iWidth,
|
||||||
|
int* iHeight);
|
||||||
|
|
||||||
|
DECODING_STATE (*DecodeFrame2) (ISVCDecoder*, const unsigned char* pSrc,
|
||||||
|
const int iSrcLen,
|
||||||
|
void** ppDst,
|
||||||
|
SBufferInfo* pDstInfo);
|
||||||
|
|
||||||
|
DECODING_STATE (*DecodeFrameEx) (ISVCDecoder*, const unsigned char* pSrc,
|
||||||
|
const int iSrcLen,
|
||||||
|
unsigned char* pDst,
|
||||||
|
int iDstStride,
|
||||||
|
int* iDstLen,
|
||||||
|
int* iWidth,
|
||||||
|
int* iHeight,
|
||||||
|
int* iColorFormat);
|
||||||
|
|
||||||
|
long (*SetOption) (ISVCDecoder*, DECODER_OPTION eOptionId, void* pOption);
|
||||||
|
long (*GetOption) (ISVCDecoder*, DECODER_OPTION eOptionId, void* pOption);
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
int CreateSVCEncoder (ISVCEncoder** ppEncoder);
|
int CreateSVCEncoder (ISVCEncoder** ppEncoder);
|
||||||
void DestroySVCEncoder (ISVCEncoder* pEncoder);
|
void DestroySVCEncoder (ISVCEncoder* pEncoder);
|
||||||
|
|
||||||
long CreateDecoder (ISVCDecoder** ppDecoder);
|
long CreateDecoder (ISVCDecoder** ppDecoder);
|
||||||
void DestroyDecoder (ISVCDecoder* pDecoder);
|
void DestroyDecoder (ISVCDecoder* pDecoder);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif//WELS_VIDEO_CODEC_SVC_API_H__
|
#endif//WELS_VIDEO_CODEC_SVC_API_H__
|
||||||
|
@ -59,8 +59,8 @@ class CWelsDecoder : public ISVCDecoder {
|
|||||||
CWelsDecoder (void_t);
|
CWelsDecoder (void_t);
|
||||||
virtual ~CWelsDecoder();
|
virtual ~CWelsDecoder();
|
||||||
|
|
||||||
virtual long Initialize (void_t* pParam, const INIT_TYPE keInitType);
|
virtual long EXTAPI Initialize (void_t* pParam, const INIT_TYPE keInitType);
|
||||||
virtual long Uninitialize();
|
virtual long EXTAPI Uninitialize();
|
||||||
|
|
||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Description:
|
* Description:
|
||||||
@ -74,28 +74,28 @@ virtual long Uninitialize();
|
|||||||
*
|
*
|
||||||
* return: if decode frame success return 0, otherwise corresponding error returned.
|
* return: if decode frame success return 0, otherwise corresponding error returned.
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
virtual DECODING_STATE DecodeFrame (const unsigned char* kpSrc,
|
virtual DECODING_STATE EXTAPI DecodeFrame (const unsigned char* kpSrc,
|
||||||
const int kiSrcLen,
|
const int kiSrcLen,
|
||||||
unsigned char** ppDst,
|
unsigned char** ppDst,
|
||||||
int* pStride,
|
int* pStride,
|
||||||
int& iWidth,
|
int& iWidth,
|
||||||
int& iHeight);
|
int& iHeight);
|
||||||
|
|
||||||
virtual DECODING_STATE DecodeFrame2 (const unsigned char* kpSrc,
|
virtual DECODING_STATE EXTAPI DecodeFrame2 (const unsigned char* kpSrc,
|
||||||
const int kiSrcLen,
|
const int kiSrcLen,
|
||||||
void_t** ppDst,
|
void_t** ppDst,
|
||||||
SBufferInfo* pDstInfo);
|
SBufferInfo* pDstInfo);
|
||||||
virtual DECODING_STATE DecodeFrameEx (const unsigned char* kpSrc,
|
virtual DECODING_STATE EXTAPI DecodeFrameEx (const unsigned char* kpSrc,
|
||||||
const int kiSrcLen,
|
const int kiSrcLen,
|
||||||
unsigned char* pDst,
|
unsigned char* pDst,
|
||||||
int iDstStride,
|
int iDstStride,
|
||||||
int& iDstLen,
|
int& iDstLen,
|
||||||
int& iWidth,
|
int& iWidth,
|
||||||
int& iHeight,
|
int& iHeight,
|
||||||
int& color_format);
|
int& color_format);
|
||||||
|
|
||||||
virtual long SetOption (DECODER_OPTION eOptID, void_t* pOption);
|
virtual long EXTAPI SetOption (DECODER_OPTION eOptID, void_t* pOption);
|
||||||
virtual long GetOption (DECODER_OPTION eOptID, void_t* pOption);
|
virtual long EXTAPI GetOption (DECODER_OPTION eOptID, void_t* pOption);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PWelsDecoderContext m_pDecContext;
|
PWelsDecoderContext m_pDecContext;
|
||||||
|
@ -65,31 +65,31 @@ class CWelsH264SVCEncoder : public ISVCEncoder {
|
|||||||
/*
|
/*
|
||||||
* return: CM_RETURN: 0 - success; otherwise - failed;
|
* return: CM_RETURN: 0 - success; otherwise - failed;
|
||||||
*/
|
*/
|
||||||
virtual int Initialize (SVCEncodingParam* argv, const INIT_TYPE init_type);
|
virtual int EXTAPI Initialize (SVCEncodingParam* argv, const INIT_TYPE init_type);
|
||||||
virtual int Initialize2 (void* argv, const INIT_TYPE init_type);
|
virtual int EXTAPI Initialize2 (void* argv, const INIT_TYPE init_type);
|
||||||
|
|
||||||
virtual int Uninitialize();
|
virtual int EXTAPI Uninitialize();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* return: EVideoFrameType [IDR: videoFrameTypeIDR; P: videoFrameTypeP; ERROR: videoFrameTypeInvalid]
|
* return: EVideoFrameType [IDR: videoFrameTypeIDR; P: videoFrameTypeP; ERROR: videoFrameTypeInvalid]
|
||||||
*/
|
*/
|
||||||
virtual int EncodeFrame (const unsigned char* kpSrc, SFrameBSInfo* pBsInfo);
|
virtual int EXTAPI EncodeFrame (const unsigned char* kpSrc, SFrameBSInfo* pBsInfo);
|
||||||
virtual int EncodeFrame2 (const SSourcePicture** kppSrcPicList, int nSrcPicNum, SFrameBSInfo* pBsInfo);
|
virtual int EXTAPI EncodeFrame2 (const SSourcePicture** kppSrcPicList, int nSrcPicNum, SFrameBSInfo* pBsInfo);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* return: 0 - success; otherwise - failed;
|
* return: 0 - success; otherwise - failed;
|
||||||
*/
|
*/
|
||||||
virtual int EncodeParameterSets (SFrameBSInfo* pBsInfo);
|
virtual int EXTAPI EncodeParameterSets (SFrameBSInfo* pBsInfo);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* return: 0 - success; otherwise - failed;
|
* return: 0 - success; otherwise - failed;
|
||||||
*/
|
*/
|
||||||
virtual int PauseFrame (const unsigned char* pSrc, SFrameBSInfo* pBsInfo);
|
virtual int EXTAPI PauseFrame (const unsigned char* pSrc, SFrameBSInfo* pBsInfo);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* return: 0 - success; otherwise - failed;
|
* return: 0 - success; otherwise - failed;
|
||||||
*/
|
*/
|
||||||
virtual int ForceIntraFrame (bool bIDR);
|
virtual int EXTAPI ForceIntraFrame (bool bIDR);
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* InDataFormat, IDRInterval, SVC Encode Param, Frame Rate, Bitrate,..
|
* InDataFormat, IDRInterval, SVC Encode Param, Frame Rate, Bitrate,..
|
||||||
@ -97,8 +97,8 @@ class CWelsH264SVCEncoder : public ISVCEncoder {
|
|||||||
/*
|
/*
|
||||||
* return: CM_RETURN: 0 - success; otherwise - failed;
|
* return: CM_RETURN: 0 - success; otherwise - failed;
|
||||||
*/
|
*/
|
||||||
virtual int SetOption (ENCODER_OPTION opt_id, void* option);
|
virtual int EXTAPI SetOption (ENCODER_OPTION opt_id, void* option);
|
||||||
virtual int GetOption (ENCODER_OPTION opt_id, void* option);
|
virtual int EXTAPI GetOption (ENCODER_OPTION opt_id, void* option);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
sWelsEncCtx* m_pEncContext;
|
sWelsEncCtx* m_pEncContext;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user