shithub: openh264

Download patch

ref: 49f4dad1b7cadb7da941945c70592d6b1a0808ce
parent: 622694935b38495af1a5249220debf2a97c3789c
author: Martin Storsjö <[email protected]>
date: Tue Feb 18 07:29:43 EST 2014

Split the encoder Initialize method into two

This avoids the struct type casting and having to pass a parameter
that says which kind of struct it actually is.

--- a/codec/api/svc/codec_api.h
+++ b/codec/api/svc/codec_api.h
@@ -56,7 +56,8 @@
   /*
    * return: CM_RETURN: 0 - success; otherwise - failed;
    */
-  virtual int EXTAPI Initialize (const void* pParam, const INIT_TYPE kiInitType = INIT_TYPE_PARAMETER_BASED) = 0;
+  virtual int EXTAPI Initialize (const SEncParamBase* pParam) = 0;
+  virtual int EXTAPI InitializeExt (const SEncParamExt* pParam) = 0;
 
   virtual int EXTAPI Uninitialize() = 0;
 
@@ -140,7 +141,8 @@
 typedef const ISVCEncoderVtbl* ISVCEncoder;
 struct ISVCEncoderVtbl {
 
-  int (*Initialize) (ISVCEncoder*, const void* pParam, const INIT_TYPE kiInitType);
+  int (*Initialize) (ISVCEncoder*, const SEncParamBase* pParam);
+  int (*InitializeExt) (ISVCEncoder*, const SEncParamExt* pParam);
 
   int (*Uninitialize) (ISVCEncoder*);
 
--- a/codec/console/enc/src/welsenc.cpp
+++ b/codec/console/enc/src/welsenc.cpp
@@ -763,7 +763,7 @@
     goto ERROR_RET;
   }
 
-  if (cmResultSuccess != pPtrEnc->Initialize (&sSvcParam, INIT_TYPE_PARAMETER_EXT)) {
+  if (cmResultSuccess != pPtrEnc->InitializeExt (&sSvcParam)) {
     fprintf (stderr, "Encoder Initialization failed!\n");
 	ret = 1;
     goto ERROR_RET;
@@ -932,7 +932,7 @@
   sSvcParam.iPicHeight = sSvcParam.sSpatialLayers[sSvcParam.iSpatialLayerNum - 1].iVideoHeight;
 
 
-  if (cmResultSuccess != pPtrEnc->Initialize (&sSvcParam, INIT_TYPE_PARAMETER_EXT)) {	// SVC encoder initialization
+  if (cmResultSuccess != pPtrEnc->InitializeExt (&sSvcParam)) {	// SVC encoder initialization
     fprintf (stderr, "SVC encoder Initialize failed\n");
     iRet = 1;
     goto INSIDE_MEM_FREE;
--- a/codec/encoder/plus/inc/welsEncoderExt.h
+++ b/codec/encoder/plus/inc/welsEncoderExt.h
@@ -66,7 +66,8 @@
   /*
    * return: CM_RETURN: 0 - success; otherwise - failed;
    */
-  virtual int EXTAPI Initialize (const void* argv, const INIT_TYPE init_type);
+  virtual int EXTAPI Initialize (const SEncParamBase* argv);
+  virtual int EXTAPI InitializeExt (const SEncParamExt* argv);
 
   virtual int EXTAPI Uninitialize();
 
--- a/codec/encoder/plus/src/welsEncoderExt.cpp
+++ b/codec/encoder/plus/src/welsEncoderExt.cpp
@@ -200,33 +200,39 @@
 /*
  *	SVC Encoder Initialization
  */
-int CWelsH264SVCEncoder::Initialize (const void* argv, const INIT_TYPE iInitType) {
+int CWelsH264SVCEncoder::Initialize (const SEncParamBase* argv) {
 
-
-  if ((INIT_TYPE_PARAMETER_BASED != iInitType && INIT_TYPE_PARAMETER_EXT != iInitType)|| NULL == argv) {
-    WelsLog (m_pEncContext, WELS_LOG_ERROR, "CWelsH264SVCEncoder::Initialize(), invalid iInitType= %d, argv= 0x%p\n",
-             iInitType, (void*)argv);
+  if (NULL == argv) {
+    WelsLog (m_pEncContext, WELS_LOG_ERROR, "CWelsH264SVCEncoder::Initialize(), invalid argv= 0x%p\n",
+             argv);
     return cmInitParaError;
   }
 
   SWelsSvcCodingParam	sConfig (true);
-  if(iInitType ==  INIT_TYPE_PARAMETER_BASED)
-  {
-	 // Convert SEncParamBase into WelsSVCParamConfig here..
-	 if (sConfig.ParamBaseTranscode (*(const SEncParamBase*)argv, true)) {
-		 WelsLog (m_pEncContext, WELS_LOG_ERROR, "CWelsH264SVCEncoder::Initialize(), parameter_translation failed.\n");
-		 Uninitialize();
-		 return cmInitParaError;
-	 }
+  // Convert SEncParamBase into WelsSVCParamConfig here..
+  if (sConfig.ParamBaseTranscode (*argv, true)) {
+    WelsLog (m_pEncContext, WELS_LOG_ERROR, "CWelsH264SVCEncoder::Initialize(), parameter_translation failed.\n");
+    Uninitialize();
+    return cmInitParaError;
   }
-  else if(iInitType ==  INIT_TYPE_PARAMETER_EXT)
-  {
-	// Convert SEncParamExt into WelsSVCParamConfig here..
-	if (sConfig.ParamTranscode (*(const SEncParamExt*)argv)) {
-		WelsLog (m_pEncContext, WELS_LOG_ERROR, "CWelsH264SVCEncoder::Initialize(), parameter_translation failed.\n");
-		Uninitialize();
-		return cmInitParaError;
-	}
+
+  return Initialize2 (&sConfig);
+}
+
+int CWelsH264SVCEncoder::InitializeExt (const SEncParamExt* argv) {
+
+  if (NULL == argv) {
+    WelsLog (m_pEncContext, WELS_LOG_ERROR, "CWelsH264SVCEncoder::Initialize(), invalid argv= 0x%p\n",
+             argv);
+    return cmInitParaError;
+  }
+
+  SWelsSvcCodingParam	sConfig (true);
+  // Convert SEncParamExt into WelsSVCParamConfig here..
+  if (sConfig.ParamTranscode (*argv)) {
+    WelsLog (m_pEncContext, WELS_LOG_ERROR, "CWelsH264SVCEncoder::Initialize(), parameter_translation failed.\n");
+    Uninitialize();
+    return cmInitParaError;
   }
 
   return Initialize2 (&sConfig);
--- a/test/BaseEncoderTest.cpp
+++ b/test/BaseEncoderTest.cpp
@@ -15,7 +15,7 @@
   param.iPicHeight = height;
   param.iTargetBitrate = 5000000;
   param.iInputCsp = videoFormatI420;
-  return encoder->Initialize(&param, INIT_TYPE_PARAMETER_BASED);
+  return encoder->Initialize(&param);
 }
 
 BaseEncoderTest::BaseEncoderTest() : encoder_(NULL) {}
--- a/test/c_interface_test.c
+++ b/test/c_interface_test.c
@@ -11,6 +11,7 @@
 
 void CheckEncoderInterface(ISVCEncoder* p, CheckFunc check) {
   CHECK(1, p, Initialize);
+  CHECK(2, p, InitializeExt);
   CHECK(3, p, Uninitialize);
   CHECK(4, p, EncodeFrame);
   CHECK(5, p, EncodeFrame2);
--- a/test/cpp_interface_test.cpp
+++ b/test/cpp_interface_test.cpp
@@ -22,10 +22,13 @@
  */
 struct SVCEncoderImpl : public ISVCEncoder {
   virtual ~SVCEncoderImpl() {}
-  virtual int EXTAPI Initialize(const void* pParam,
-      const INIT_TYPE kiInitType) {
+  virtual int EXTAPI Initialize(const SEncParamBase* pParam) {
     EXPECT_TRUE(gThis == this);
     return 1;
+  }
+  virtual int EXTAPI InitializeExt(const SEncParamExt* pParam) {
+    EXPECT_TRUE(gThis == this);
+    return 2;
   }
   virtual int EXTAPI Uninitialize() {
     EXPECT_TRUE(gThis == this);