shithub: openh264

Download patch

ref: b1fc94e31448c40f750f1e0026da34afc51ef961
parent: 9230b497282ada7649b2ac4cfd51a7b5d9e2f75d
parent: 27662155457b0e48dd84b79261fce6c93471341a
author: Ethan Hugg <[email protected]>
date: Tue Jan 14 10:31:18 EST 2014

Merge pull request #134 from mstorsjo/encode-sps-pps

Add an encoder method for encoding the SPS/PPS without encoding a frame

--- a/codec/api/svc/codec_api.h
+++ b/codec/api/svc/codec_api.h
@@ -55,6 +55,11 @@
   /*
    * return: 0 - success; otherwise - failed;
    */
+  virtual int EncodeParameterSets (SFrameBSInfo* pBsInfo) = 0;
+
+  /*
+   * return: 0 - success; otherwise - failed;
+   */
   virtual int PauseFrame (const unsigned char* kpSrc, SFrameBSInfo* pBsInfo) = 0;
 
   /*
--- a/codec/encoder/core/inc/extern.h
+++ b/codec/encoder/core/inc/extern.h
@@ -98,6 +98,8 @@
 int32_t WelsEncoderEncodeExt (sWelsEncCtx*, void* pDst, const SSourcePicture** kppSrcList,
                               const int32_t kiConfiguredLayerNum);
 
+int32_t WelsEncoderEncodeParameterSets (sWelsEncCtx* pCtx, void* pDst);
+
 /*
  * Force coding IDR as follows
  */
--- a/codec/encoder/core/src/encoder_ext.cpp
+++ b/codec/encoder/core/src/encoder_ext.cpp
@@ -3093,6 +3093,37 @@
   return 0;
 }
 
+int32_t WelsEncoderEncodeParameterSets (sWelsEncCtx* pCtx, void* pDst) {
+  SFrameBSInfo* pFbi          = (SFrameBSInfo*)pDst;
+  SLayerBSInfo* pLayerBsInfo  = &pFbi->sLayerInfo[0];
+  int32_t iNalLen[128]        = {0};
+  int32_t iCountNal           = 0;
+
+  pLayerBsInfo->pBsBuf = pCtx->pFrameBs;
+  InitBits (&pCtx->pOut->sBsWrite, pCtx->pOut->pBsBuffer, pCtx->pOut->uiSize);
+
+  WelsWriteParameterSets (pCtx, &iNalLen[0], &iCountNal);
+
+  pLayerBsInfo->uiPriorityId  = 0;
+  pLayerBsInfo->uiSpatialId   = 0;
+  pLayerBsInfo->uiTemporalId  = 0;
+  pLayerBsInfo->uiQualityId   = 0;
+  pLayerBsInfo->uiLayerType   = NON_VIDEO_CODING_LAYER;
+  pLayerBsInfo->iNalCount     = iCountNal;
+  for (int32_t iNalIndex      = 0; iNalIndex < iCountNal; ++ iNalIndex) {
+    pLayerBsInfo->iNalLengthInByte[iNalIndex] = iNalLen[iNalIndex];
+  }
+
+  pCtx->eLastNalPriority      = NRI_PRI_HIGHEST;
+  pFbi->iLayerNum             = 1;
+
+#if defined(X86_ASM)
+  WelsEmms();
+#endif //X86_ASM
+
+  return 0;
+}
+
 /*!
  * \brief	core svc encoding process
  *
--- a/codec/encoder/plus/inc/welsEncoderExt.h
+++ b/codec/encoder/plus/inc/welsEncoderExt.h
@@ -79,6 +79,11 @@
   /*
    * return: 0 - success; otherwise - failed;
    */
+  virtual int EncodeParameterSets (SFrameBSInfo* pBsInfo);
+
+  /*
+   * return: 0 - success; otherwise - failed;
+   */
   virtual int PauseFrame (const unsigned char* pSrc, SFrameBSInfo* pBsInfo);
 
   /*
--- a/codec/encoder/plus/src/welsEncoderExt.cpp
+++ b/codec/encoder/plus/src/welsEncoderExt.cpp
@@ -730,6 +730,10 @@
 
 }
 
+int CWelsH264SVCEncoder::EncodeParameterSets (SFrameBSInfo* pBsInfo) {
+    return WelsEncoderEncodeParameterSets (m_pEncContext, pBsInfo);
+}
+
 /*
  * return: 0 - success; otherwise - failed;
  */