[x265] [PATCH] api: add param.bRepeatHeaders - insert stream headers in each keyframe NAL

Steve Borho steve at borho.org
Tue Mar 25 17:43:15 CET 2014


# HG changeset patch
# User Steve Borho <steve at borho.org>
# Date 1395765782 18000
#      Tue Mar 25 11:43:02 2014 -0500
# Node ID e739e579609a0bc11ef72368ab39c824411d1d7b
# Parent  4318d47d934857a5d0a5e2a8dc0eaed48f086197
api: add param.bRepeatHeaders - insert stream headers in each keyframe NAL

This is apparently useful for raw stream formats

diff -r 4318d47d9348 -r e739e579609a source/CMakeLists.txt
--- a/source/CMakeLists.txt	Mon Mar 24 12:00:06 2014 -0700
+++ b/source/CMakeLists.txt	Tue Mar 25 11:43:02 2014 -0500
@@ -18,7 +18,7 @@
 include(CheckCXXCompilerFlag)
 
 # X265_BUILD must be incremented each time the public API is changed
-set(X265_BUILD 10)
+set(X265_BUILD 11)
 configure_file("${PROJECT_SOURCE_DIR}/x265.def.in"
                "${PROJECT_BINARY_DIR}/x265.def")
 configure_file("${PROJECT_SOURCE_DIR}/x265_config.h.in"
diff -r 4318d47d9348 -r e739e579609a source/common/common.h
--- a/source/common/common.h	Mon Mar 24 12:00:06 2014 -0700
+++ b/source/common/common.h	Tue Mar 25 11:43:02 2014 -0500
@@ -104,7 +104,7 @@
 #define X265_LOWRES_CU_SIZE   8
 #define X265_LOWRES_CU_BITS   3
 
-#define MAX_NAL_UNITS 6
+#define MAX_NAL_UNITS 12
 #define MIN_FIFO_SIZE 1000
 
 #define X265_MALLOC(type, count)    (type*)x265_malloc(sizeof(type) * (count))
diff -r 4318d47d9348 -r e739e579609a source/common/param.cpp
--- a/source/common/param.cpp	Mon Mar 24 12:00:06 2014 -0700
+++ b/source/common/param.cpp	Tue Mar 25 11:43:02 2014 -0500
@@ -529,6 +529,7 @@
             p->logLevel = parseName(value, logLevelNames, bError) - 1;
         }
     }
+    OPT("repeat-headers") p->bRepeatHeaders = atobool(value);
     OPT("wpp") p->bEnableWavefront = atobool(value);
     OPT("ctu") p->maxCUSize = (uint32_t)atoi(value);
     OPT("tu-intra-depth") p->tuQTMaxIntraDepth = (uint32_t)atoi(value);
diff -r 4318d47d9348 -r e739e579609a source/encoder/api.cpp
--- a/source/encoder/api.cpp	Mon Mar 24 12:00:06 2014 -0700
+++ b/source/encoder/api.cpp	Tue Mar 25 11:43:02 2014 -0500
@@ -75,7 +75,7 @@
 
     int ret = 0;
     NALUnitEBSP *nalunits[MAX_NAL_UNITS] = { 0, 0, 0, 0, 0 };
-    if (!encoder->getStreamHeaders(nalunits))
+    if (encoder->getStreamHeaders(nalunits) > 0)
     {
         int nalcount = encoder->extractNalData(nalunits);
         *pp_nal = &encoder->m_nals[0];
diff -r 4318d47d9348 -r e739e579609a source/encoder/frameencoder.cpp
--- a/source/encoder/frameencoder.cpp	Mon Mar 24 12:00:06 2014 -0700
+++ b/source/encoder/frameencoder.cpp	Tue Mar 25 11:43:02 2014 -0500
@@ -244,7 +244,7 @@
         CHECKED_MALLOC(nalunits[count], NALUnitEBSP, 1);
         nalunits[count]->init(nalu);
     }
-    return 0;
+    return count;
 
 fail:
     return -1;
@@ -357,7 +357,10 @@
     TComSlice*   slice             = m_pic->getSlice();
     int          chFmt             = slice->getSPS()->getChromaFormatIdc();
 
-    m_nalCount = 0;
+    if (m_cfg->param->bRepeatHeaders && m_pic->m_lowres.bKeyframe)
+        m_nalCount = getStreamHeaders(m_nalList);
+    else
+        m_nalCount = 0;
 
     int qp = slice->getSliceQp();
     double lambda = 0;
diff -r 4318d47d9348 -r e739e579609a source/x265.cpp
--- a/source/x265.cpp	Mon Mar 24 12:00:06 2014 -0700
+++ b/source/x265.cpp	Tue Mar 25 11:43:02 2014 -0500
@@ -688,9 +688,10 @@
     x265_stats stats;
     uint32_t nal;
 
-    if (!x265_encoder_headers(encoder, &p_nal, &nal))
+    if (!param->bRepeatHeaders)
     {
-        cliopt.writeNALs(p_nal, nal);
+        if (!x265_encoder_headers(encoder, &p_nal, &nal))
+            cliopt.writeNALs(p_nal, nal);
     }
 
     x265_picture_init(param, pic_in);
diff -r 4318d47d9348 -r e739e579609a source/x265.h
--- a/source/x265.h	Mon Mar 24 12:00:06 2014 -0700
+++ b/source/x265.h	Tue Mar 25 11:43:02 2014 -0500
@@ -389,6 +389,10 @@
      * temporal order. EXPERIMENTAL */
     int       interlaceMode;
 
+    /* Flag indicating whether VPS, SPS and PPS headers should be output with
+     * each keyframe. Default false */
+    int       bRepeatHeaders;
+
     /*== Coding Unit (CU) definitions ==*/
 
     /* Maxiumum CU width and height in pixels.  The size must be 64, 32, or 16.


More information about the x265-devel mailing list