[x265] [PATCH] api: add support for access unit delimiters (--aud)

Steve Borho steve at borho.org
Fri Apr 4 03:33:14 CEST 2014


# HG changeset patch
# User Steve Borho <steve at borho.org>
# Date 1396572381 18000
#      Thu Apr 03 19:46:21 2014 -0500
# Node ID 6327400944eefe4847770bf450889997ad52b737
# Parent  8273932bc5b7bab6f3c3fb50c2ae771a5bea4085
api: add support for access unit delimiters (--aud)

diff -r 8273932bc5b7 -r 6327400944ee doc/reST/cli.rst
--- a/doc/reST/cli.rst	Thu Apr 03 20:32:49 2014 -0500
+++ b/doc/reST/cli.rst	Thu Apr 03 19:46:21 2014 -0500
@@ -746,6 +746,17 @@
 	info reported in the PPS header but is sometimes required.  Default
 	disabled
 
+Bitstream options
+=================
+
+.. option:: --aud, --no-aud
+
+	Emit an access unit delimiter NAL at the start of each slice access
+	unit. If option:`--repeat-headers` is not enabled (indicating the
+	user will be writing headers manually at the start of the stream)
+	the very first AUD will be skipped since it cannot be placed at the
+	start of the access unit, where it belongs. Default disabled
+
 Debugging options
 =================
 
diff -r 8273932bc5b7 -r 6327400944ee source/CMakeLists.txt
--- a/source/CMakeLists.txt	Thu Apr 03 20:32:49 2014 -0500
+++ b/source/CMakeLists.txt	Thu Apr 03 19:46:21 2014 -0500
@@ -19,7 +19,7 @@
 include(CheckCXXCompilerFlag)
 
 # X265_BUILD must be incremented each time the public API is changed
-set(X265_BUILD 13)
+set(X265_BUILD 14)
 configure_file("${PROJECT_SOURCE_DIR}/x265.def.in"
                "${PROJECT_BINARY_DIR}/x265.def")
 configure_file("${PROJECT_SOURCE_DIR}/x265_config.h.in"
diff -r 8273932bc5b7 -r 6327400944ee source/Lib/TLibEncoder/TEncEntropy.cpp
--- a/source/Lib/TLibEncoder/TEncEntropy.cpp	Thu Apr 03 20:32:49 2014 -0500
+++ b/source/Lib/TLibEncoder/TEncEntropy.cpp	Thu Apr 03 19:46:21 2014 -0500
@@ -89,6 +89,11 @@
     m_entropyCoderIf->codeSPS(sps);
 }
 
+void TEncEntropy::encodeAUD(TComSlice* slice)
+{
+    m_entropyCoderIf->codeAUD(slice);
+}
+
 void TEncEntropy::encodeCUTransquantBypassFlag(TComDataCU* cu, uint32_t absPartIdx, bool bRD)
 {
     if (bRD)
diff -r 8273932bc5b7 -r 6327400944ee source/Lib/TLibEncoder/TEncEntropy.h
--- a/source/Lib/TLibEncoder/TEncEntropy.h	Thu Apr 03 20:32:49 2014 -0500
+++ b/source/Lib/TLibEncoder/TEncEntropy.h	Thu Apr 03 19:46:21 2014 -0500
@@ -71,6 +71,7 @@
     virtual void codeVPS(TComVPS* vps) = 0;
     virtual void codeSPS(TComSPS* sps) = 0;
     virtual void codePPS(TComPPS* pps) = 0;
+    virtual void codeAUD(TComSlice* slice) = 0;
     virtual void codeSliceHeader(TComSlice* slice) = 0;
 
     virtual void codeTilesWPPEntryPoint(TComSlice* slice) = 0;
@@ -149,6 +150,7 @@
     // SPS
     void encodeSPS(TComSPS* sps);
     void encodePPS(TComPPS* pps);
+    void encodeAUD(TComSlice* pps);
     void encodeSplitFlag(TComDataCU* cu, uint32_t absPartIdx, uint32_t depth, bool bRD = false);
     void encodeCUTransquantBypassFlag(TComDataCU* cu, uint32_t absPartIdx, bool bRD = false);
     void encodeSkipFlag(TComDataCU* cu, uint32_t absPartIdx, bool bRD = false);
diff -r 8273932bc5b7 -r 6327400944ee source/Lib/TLibEncoder/TEncSbac.cpp
--- a/source/Lib/TLibEncoder/TEncSbac.cpp	Thu Apr 03 20:32:49 2014 -0500
+++ b/source/Lib/TLibEncoder/TEncSbac.cpp	Thu Apr 03 19:46:21 2014 -0500
@@ -649,6 +649,28 @@
     }
 }
 
+void TEncSbac::codeAUD(TComSlice* slice)
+{
+    int picType;
+
+    switch (slice->getSliceType())
+    {
+    case I_SLICE:
+        picType = 0;
+        break;
+    case P_SLICE:
+        picType = 1;
+        break;
+    case B_SLICE:
+        picType = 2;
+        break;
+    default:
+        picType = 7;
+        break;
+    }
+    WRITE_CODE(picType, 3, "pic_type");
+}
+
 void TEncSbac::codeHrdParameters(TComHRD *hrd, bool commonInfPresentFlag, uint32_t maxNumSubLayersMinus1)
 {
     if (commonInfPresentFlag)
diff -r 8273932bc5b7 -r 6327400944ee source/Lib/TLibEncoder/TEncSbac.h
--- a/source/Lib/TLibEncoder/TEncSbac.h	Thu Apr 03 20:32:49 2014 -0500
+++ b/source/Lib/TLibEncoder/TEncSbac.h	Thu Apr 03 19:46:21 2014 -0500
@@ -88,6 +88,7 @@
     void codeSPS(TComSPS* sps);
     void codePPS(TComPPS* pps);
     void codeVUI(TComVUI* vui, TComSPS* sps);
+    void codeAUD(TComSlice *slice);
     void codeSliceHeader(TComSlice* slice);
     void codePTL(TComPTL* ptl, bool profilePresentFlag, int maxNumSubLayersMinus1);
     void codeProfileTier(ProfileTierLevel* ptl);
diff -r 8273932bc5b7 -r 6327400944ee source/common/param.cpp
--- a/source/common/param.cpp	Thu Apr 03 20:32:49 2014 -0500
+++ b/source/common/param.cpp	Thu Apr 03 19:46:21 2014 -0500
@@ -595,6 +595,7 @@
     OPT("ssim") p->bEnableSsim = atobool(value);
     OPT("psnr") p->bEnablePsnr = atobool(value);
     OPT("hash") p->decodedPictureHashSEI = atoi(value);
+    OPT("aud") p->bEnableAccessUnitDelimiters = atobool(value);
     OPT("b-pyramid") p->bBPyramid = atobool(value);
     OPT("aq-mode") p->rc.aqMode = atoi(value);
     OPT("aq-strength") p->rc.aqStrength = atof(value);
diff -r 8273932bc5b7 -r 6327400944ee source/encoder/frameencoder.cpp
--- a/source/encoder/frameencoder.cpp	Thu Apr 03 20:32:49 2014 -0500
+++ b/source/encoder/frameencoder.cpp	Thu Apr 03 19:46:21 2014 -0500
@@ -369,10 +369,27 @@
     TComSlice*   slice             = m_pic->getSlice();
     int          chFmt             = slice->getSPS()->getChromaFormatIdc();
 
+    m_nalCount = 0;
+    entropyCoder->setEntropyCoder(&m_sbacCoder, NULL);
+
+    /* Emit access unit delimiter unless this is the first frame and the user is
+     * not repeating headers (since AUD is supposed to be the first NAL in the access
+     * unit) */
+    if (m_cfg->param->bEnableAccessUnitDelimiters && (m_pic->getPOC() || m_cfg->param->bRepeatHeaders))
+    {
+        OutputNALUnit nalu(NAL_UNIT_ACCESS_UNIT_DELIMITER);
+        entropyCoder->setBitstream(&nalu.m_bitstream);
+        entropyCoder->encodeAUD(slice);
+        writeRBSPTrailingBits(nalu.m_bitstream);
+        m_nalList[m_nalCount] = X265_MALLOC(NALUnitEBSP, 1);
+        if (m_nalList[m_nalCount])
+        {
+            m_nalList[m_nalCount]->init(nalu);
+            m_nalCount++;
+        }
+    }
     if (m_cfg->param->bRepeatHeaders && m_pic->m_lowres.bKeyframe)
-        m_nalCount = getStreamHeaders(m_nalList);
-    else
-        m_nalCount = 0;
+        m_nalCount += getStreamHeaders(m_nalList + m_nalCount);
 
     int qp = slice->getSliceQp();
     double lambda = 0;
diff -r 8273932bc5b7 -r 6327400944ee source/x265.cpp
--- a/source/x265.cpp	Thu Apr 03 20:32:49 2014 -0500
+++ b/source/x265.cpp	Thu Apr 03 19:46:21 2014 -0500
@@ -171,6 +171,8 @@
     { "no-timinginfo",        no_argument, NULL, 0 },
     { "no-dither",            no_argument, NULL, 0 },
     { "dither",               no_argument, NULL, 0 },
+    { "aud",                  no_argument, NULL, 0 },
+    { "no-aud",               no_argument, NULL, 0 },
     { 0, 0, 0, 0 }
 };
 
@@ -391,6 +393,8 @@
     H0("                                 smpte240m, GBR, YCgCo, bt2020nc, bt2020c. Default undef\n");
     H0("   --chromaloc <integer>         Specify chroma sample location (0 to 5). Default of %d\n", param->vui.chromaSampleLocTypeTopField);
     H0("   --[no-]timinginfo             Add timing information to the VUI. Defaut %s\n", OPT(param->vui.bEnableVuiTimingInfoPresentFlag));
+    H0("\nBitstream options:\n");
+    H0("   --[no-]aud                    Emit access unit delimiters at the start of each access unit. Default %s\n", OPT(param->bEnableAccessUnitDelimiters));
     H0("\nReconstructed video options (debugging):\n");
     H0("-r/--recon <filename>            Reconstructed raw image YUV or Y4M output file name\n");
     H0("   --recon-depth <integer>       Bit-depth of reconstructed raw image file. Defaults to input bit depth, or 8 if Y4M\n");
diff -r 8273932bc5b7 -r 6327400944ee source/x265.h
--- a/source/x265.h	Thu Apr 03 20:32:49 2014 -0500
+++ b/source/x265.h	Thu Apr 03 19:46:21 2014 -0500
@@ -392,6 +392,10 @@
      * each keyframe. Default false */
     int       bRepeatHeaders;
 
+    /* Flag indicating whether the encoder should emit an Access Unit Delimiter
+     * NAL at the start of every access unit. Default false */
+    int       bEnableAccessUnitDelimiters;
+
     /*== 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