[x265-commits] [x265] encoder: nits

Steve Borho steve at borho.org
Mon Dec 2 00:07:54 CET 2013


details:   http://hg.videolan.org/x265/rev/d17843e942b5
branches:  
changeset: 5400:d17843e942b5
user:      Steve Borho <steve at borho.org>
date:      Sun Dec 01 14:40:49 2013 -0600
description:
encoder: nits
Subject: [x265] test: intrapred harness fixup

details:   http://hg.videolan.org/x265/rev/0547f1672f13
branches:  
changeset: 5401:0547f1672f13
user:      Steve Borho <steve at borho.org>
date:      Sun Dec 01 15:45:59 2013 -0600
description:
test: intrapred harness fixup
Subject: [x265] csv: improve CSV headers to use title caps

details:   http://hg.videolan.org/x265/rev/418e55eefbb8
branches:  stable
changeset: 5402:418e55eefbb8
user:      Steve Borho <steve at borho.org>
date:      Sun Dec 01 15:53:12 2013 -0600
description:
csv: improve CSV headers to use title caps
Subject: [x265] api: change x265_param.bpyramid to bBPyramid (bool)

details:   http://hg.videolan.org/x265/rev/53b1eeb6333b
branches:  stable
changeset: 5403:53b1eeb6333b
user:      Steve Borho <steve at borho.org>
date:      Sun Dec 01 16:06:44 2013 -0600
description:
api: change x265_param.bpyramid to bBPyramid (bool)

x264's strict bpyramid mode seems to be H.264/blue-ray specific and thus we are
left with only on or off.
Subject: [x265] api: add alloc/free methods for x265_param

details:   http://hg.videolan.org/x265/rev/aabaf5382ac5
branches:  stable
changeset: 5404:aabaf5382ac5
user:      Steve Borho <steve at borho.org>
date:      Sun Dec 01 16:37:54 2013 -0600
description:
api: add alloc/free methods for x265_param

This allows apps to use x265_param as pure abstract structures, just like
x265_encoder, in order to make their app future-safe against changes to
x265_param (without requiring recompiles or code changes).
Subject: [x265] api: add alloc/free methods for x265_picture for future safety

details:   http://hg.videolan.org/x265/rev/32942ebd5793
branches:  stable
changeset: 5405:32942ebd5793
user:      Steve Borho <steve at borho.org>
date:      Sun Dec 01 16:48:57 2013 -0600
description:
api: add alloc/free methods for x265_picture for future safety
Subject: [x265] Merge with stable

details:   http://hg.videolan.org/x265/rev/7f2bc20e9ff1
branches:  
changeset: 5406:7f2bc20e9ff1
user:      Steve Borho <steve at borho.org>
date:      Sun Dec 01 16:50:08 2013 -0600
description:
Merge with stable

diffstat:

 source/common/common.cpp         |   8 +++---
 source/encoder/encoder.cpp       |  36 ++++++++++++++++++++++++----
 source/encoder/slicetype.cpp     |  23 ++++++++---------
 source/test/intrapredharness.cpp |   2 +-
 source/x265.cpp                  |  31 +++++++++++++-----------
 source/x265.def.in               |   4 +++
 source/x265.h                    |  49 +++++++++++++++++++++++++++++++--------
 7 files changed, 106 insertions(+), 47 deletions(-)

diffs (truncated from 433 to 300 lines):

diff -r 8a90153de720 -r 7f2bc20e9ff1 source/common/common.cpp
--- a/source/common/common.cpp	Fri Nov 08 18:41:21 2013 +0800
+++ b/source/common/common.cpp	Sun Dec 01 16:50:08 2013 -0600
@@ -164,7 +164,7 @@ void x265_param_default(x265_param *para
     param->bframes = 4;
     param->lookaheadDepth = 20;
     param->bFrameAdaptive = X265_B_ADAPT_TRELLIS;
-    param->bpyramid = 1;
+    param->bBPyramid = 1;
     param->scenecutThreshold = 40; /* Magic number pulled in from x264 */
 
     /* Intra Coding Tools */
@@ -610,7 +610,7 @@ void x265_print_params(x265_param *param
         x265_log(param, X265_LOG_INFO, "RDpenalty                    : %d\n", param->rdPenalty);
     }
     x265_log(param, X265_LOG_INFO, "Lookahead / bframes / badapt : %d / %d / %d\n", param->lookaheadDepth, param->bframes, param->bFrameAdaptive);
-    x265_log(param, X265_LOG_INFO, "b-pyramid / weightp / ref    : %d / %d / %d\n", param->bpyramid, param->bEnableWeightedPred, param->maxNumReferences);
+    x265_log(param, X265_LOG_INFO, "b-pyramid / weightp / refs   : %d / %d / %d\n", param->bBPyramid, param->bEnableWeightedPred, param->maxNumReferences);
     x265_log(param, X265_LOG_INFO, "tools: ");
 #define TOOLOPT(FLAG, STR) if (FLAG) fprintf(stderr, "%s ", STR)
     TOOLOPT(param->bEnableRectInter, "rect");
@@ -719,6 +719,7 @@ int x265_param_parse(x265_param *p, cons
     OPT("ssim") p->bEnableSsim = bvalue;
     OPT("psnr") p->bEnablePsnr = bvalue;
     OPT("hash") p->decodedPictureHashSEI = atoi(value);
+    OPT("b-pyramid") p->bBPyramid = bvalue;
     OPT("aq-mode") p->rc.aqMode = atoi(value);
     OPT("aq-strength") p->rc.aqStrength = atof(value);
     OPT("vbv-maxrate") p->rc.vbvMaxBitrate = atoi(value);
@@ -742,7 +743,6 @@ int x265_param_parse(x265_param *p, cons
     }
     OPT("input-csp") p->internalCsp = parseName(value, x265_source_csp_names, berror);
     OPT("me")        p->searchMethod = parseName(value, x265_motion_est_names, berror);
-    OPT("b-pyramid") p->bpyramid = parseName(value, x265_b_pyramid_names, berror);
     else
         return X265_PARAM_BAD_NAME;
 #undef OPT
@@ -800,7 +800,7 @@ char *x265_param2string(x265_param *p)
     BOOL(p->bEnableSAO, "sao");
     s += sprintf(s, " sao-lcu-bounds=%d", p->saoLcuBoundary);
     s += sprintf(s, " sao-lcu-opt=%d", p->saoLcuBasedOptimization);
-    s += sprintf(s, " b-pyramid=%d", p->bpyramid);
+    s += sprintf(s, " b-pyramid=%d", p->bBPyramid);
 #undef BOOL
 
     return buf;
diff -r 8a90153de720 -r 7f2bc20e9ff1 source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp	Fri Nov 08 18:41:21 2013 +0800
+++ b/source/encoder/encoder.cpp	Sun Dec 01 16:50:08 2013 -0600
@@ -123,9 +123,9 @@ void Encoder::create()
             if (m_csvfpt)
             {
                 if (param.logLevel >= X265_LOG_DEBUG)
-                    fprintf(m_csvfpt, "Encode Order, Type, POC, nQP, QP, Bits, PSNR Y, PSNR U, PSNR V, PSNR, SSIM, Encoding time, Elapsed time, List 0, List 1\n");
+                    fprintf(m_csvfpt, "Encode Order, Type, POC, nQP, QP, Bits, Y PSNR, U PSNR, V PSNR, YUV PSNR, SSIM, Encoding time, Elapsed time, List 0, List 1\n");
                 else
-                    fprintf(m_csvfpt, "CLI arguments, date/time, elapsed time, fps, bitrate, global PSNR Y, global PSNR U, global PSNR V, global PSNR, global SSIM, version\n");
+                    fprintf(m_csvfpt, "Command, Date/Time, Elapsed Time, FPS, Bitrate, Y PSNR, U PSNR, V PSNR, Global PSNR, Global SSIM, Version\n");
             }
         }
     }
@@ -331,7 +331,7 @@ int Encoder::encode(bool flush, const x2
         m_dpb->prepareEncode(fenc);
 
         // set slice QP
-        m_rateControl->rateControlStart(fenc, m_lookahead, &(curEncoder->m_rce),this); 
+        m_rateControl->rateControlStart(fenc, m_lookahead, &curEncoder->m_rce, this); 
 
         // Allow FrameEncoder::compressFrame() to start in a worker thread
         curEncoder->m_enable.trigger();
@@ -1232,9 +1232,9 @@ void Encoder::configure(x265_param *_par
     {
         _param->bEnableRDOQTS = 0;
     }
-    if (_param->bpyramid && !_param->bframes)
+    if (_param->bBPyramid && !_param->bframes)
     {
-        _param->bpyramid = 0;
+        _param->bBPyramid = 0;
     }
     /* Set flags according to RDLevel specified - check_params has verified that RDLevel is within range */
     switch (_param->rdLevel)
@@ -1273,7 +1273,7 @@ void Encoder::configure(x265_param *_par
     for (int i = 0; i < MAX_TLAYER; i++)
     {
         /* Increase the DPB size and reorderpicture if enabled the bpyramid */
-        m_numReorderPics[i] = (_param->bpyramid && _param->bframes > 1) ? 2 : 1;
+        m_numReorderPics[i] = (_param->bBPyramid && _param->bframes > 1) ? 2 : 1;
         m_maxDecPicBuffering[i] = X265_MIN(MAX_NUM_REF, X265_MAX(m_numReorderPics[i] + 1, _param->maxNumReferences) + m_numReorderPics[i]);
 
         vps.setNumReorderPics(m_numReorderPics[i], i);
@@ -1440,6 +1440,30 @@ fail:
 }
 
 extern "C"
+x265_param *x265_param_alloc()
+{
+    return (x265_param*)x265_malloc(sizeof(x265_param));
+}
+
+extern "C"
+void x265_param_free(x265_param *p)
+{
+    return x265_free(p);
+}
+
+extern "C"
+x265_picture *x265_picture_alloc()
+{
+    return (x265_picture*)x265_malloc(sizeof(x265_picture));
+}
+
+extern "C"
+void x265_picture_free(x265_picture *p)
+{
+    return x265_free(p);
+}
+
+extern "C"
 x265_encoder *x265_encoder_open(x265_param *param)
 {
     x265_setup_primitives(param, -1);  // -1 means auto-detect if uninitialized
diff -r 8a90153de720 -r 7f2bc20e9ff1 source/encoder/slicetype.cpp
--- a/source/encoder/slicetype.cpp	Fri Nov 08 18:41:21 2013 +0800
+++ b/source/encoder/slicetype.cpp	Sun Dec 01 16:50:08 2013 -0600
@@ -642,22 +642,21 @@ void Lookahead::slicetypeDecide()
         {
             Lowres& frm = list[bframes]->m_lowres;
 
-            if (frm.sliceType == X265_TYPE_BREF
-                && cfg->param.bpyramid < X265_B_PYRAMID_NORMAL && brefs == cfg->param.bpyramid)
+            if (frm.sliceType == X265_TYPE_BREF && !cfg->param.bBPyramid && brefs == cfg->param.bBPyramid)
             {
                 frm.sliceType = X265_TYPE_B;
-                x265_log(&cfg->param, X265_LOG_WARNING, "B-ref at frame %d incompatible with B-pyramid %s \n",
-                        frm.frameNum, x265_b_pyramid_names[cfg->param.bpyramid] );
+                x265_log(&cfg->param, X265_LOG_WARNING, "B-ref at frame %d incompatible with B-pyramid\n",
+                        frm.frameNum);
             }
 
             /* pyramid with multiple B-refs needs a big enough dpb that the preceding P-frame stays available.
                smaller dpb could be supported by smart enough use of mmco, but it's easier just to forbid it.*/
-            else if (frm.sliceType == X265_TYPE_BREF && cfg->param.bpyramid == X265_B_PYRAMID_NORMAL &&
-                     brefs && cfg->param.maxNumReferences <= (brefs+3))
+            else if (frm.sliceType == X265_TYPE_BREF && cfg->param.bBPyramid && brefs &&
+                     cfg->param.maxNumReferences <= (brefs+3))
             {
                 frm.sliceType = X265_TYPE_B;
-                x265_log(&cfg->param, X265_LOG_WARNING, "B-ref at frame %d incompatible with B-pyramid %s and %d reference frames\n",
-                        frm.sliceType, x265_b_pyramid_names[cfg->param.bpyramid], cfg->param.maxNumReferences);
+                x265_log(&cfg->param, X265_LOG_WARNING, "B-ref at frame %d incompatible with B-pyramid and %d reference frames\n",
+                        frm.sliceType, cfg->param.maxNumReferences);
             }
 
             if (frm.sliceType == X265_TYPE_KEYFRAME)
@@ -718,7 +717,7 @@ void Lookahead::slicetypeDecide()
         lastNonB = &list[bframes]->m_lowres;
 
         /* insert a bref into the sequence */
-        if (cfg->param.bpyramid && bframes > 1 && !brefs)
+        if (cfg->param.bBPyramid && bframes > 1 && !brefs)
         {
             list[bframes/2]->m_lowres.sliceType = X265_TYPE_BREF;
             brefs++;
@@ -776,7 +775,7 @@ void Lookahead::slicetypeDecide()
         outputQueue.pushBack(*list[bframes]);
 
         /* Add B-ref frame next to P frame in output queue, the B-ref encode before non B-ref frame */
-        if (bframes > 1 && cfg->param.bpyramid)
+        if (bframes > 1 && cfg->param.bBPyramid)
         {
             for (int i = 0; i < bframes; i++)
             {
@@ -860,7 +859,7 @@ void Lookahead::slicetypeDecide()
         outputQueue.pushBack(*pic);
         numDecided++;
 
-        if (cfg->param.bpyramid && bframes > 1)
+        if (cfg->param.bBPyramid && bframes > 1)
         {
             int bref = bframes / 2;
             if (list[bref - 1]->m_lowres.sliceType == X265_TYPE_AUTO)
@@ -1184,7 +1183,7 @@ int Lookahead::slicetypePathCost(char *p
         if (cost > threshold)
             break;
 
-        if (cfg->param.bpyramid && next_p - cur_p > 2)
+        if (cfg->param.bBPyramid && next_p - cur_p > 2)
         {
             int middle = cur_p + (next_p - cur_p) / 2;
             cost += estimateFrameCost(cur_p, next_p, middle, 0);
diff -r 8a90153de720 -r 7f2bc20e9ff1 source/test/intrapredharness.cpp
--- a/source/test/intrapredharness.cpp	Fri Nov 08 18:41:21 2013 +0800
+++ b/source/test/intrapredharness.cpp	Sun Dec 01 16:50:08 2013 -0600
@@ -313,7 +313,7 @@ void IntraPredHarness::measureSpeed(cons
             REPORT_SPEEDUP(opt.intra_pred_planar[i], ref.intra_pred_planar[i],
                         pixel_buff + srcStride, pixel_buff, pixel_out_vec, FENC_STRIDE);
         }
-        if (opt.intra_pred_allangs[size])
+        if (opt.intra_pred_allangs[i])
         {
             bool bFilter = (size <= 16);
             pixel * refAbove = pixel_buff + srcStride;
diff -r 8a90153de720 -r 7f2bc20e9ff1 source/x265.cpp
--- a/source/x265.cpp	Fri Nov 08 18:41:21 2013 +0800
+++ b/source/x265.cpp	Sun Dec 01 16:50:08 2013 -0600
@@ -116,7 +116,8 @@ static const struct option long_options[
     { "bframes",        required_argument, NULL, 'b' },
     { "bframe-bias",    required_argument, NULL, 0 },
     { "b-adapt",        required_argument, NULL, 0 },
-    { "b-pyramid",      required_argument, NULL, 0 },
+    { "no-b-pyramid",         no_argument, NULL, 0 },
+    { "b-pyramid",            no_argument, NULL, 0 },
     { "ref",            required_argument, NULL, 0 },
     { "no-weightp",           no_argument, NULL, 0 },
     { "weightp",              no_argument, NULL, 'w' },
@@ -308,7 +309,7 @@ void CLIOptions::showHelp(x265_param *pa
     H0("   --bframes                     Maximum number of consecutive b-frames (now it only enables B GOP structure) Default %d\n", param->bframes);
     H0("   --bframe-bias                 Bias towards B frame decisions. Default %d\n", param->bFrameBias);
     H0("   --b-adapt                     0 - none, 1 - fast, 2 - full (trellis) adaptive B frame scheduling. Default %d\n", param->bFrameAdaptive);
-    H0("   --b-pyramid                   Use B-frames as references 0: Disabled, 1: Enabled Default %s\n", OPT(param->bpyramid));
+    H0("   --[no-]b-pyramid              Use B-frames as references. Default %s\n", OPT(param->bBPyramid));
     H0("   --ref                         max number of L0 references to be allowed (1 .. 16) Default %d\n", param->maxNumReferences);
     H0("-w/--[no-]weightp                Enable weighted prediction in P slices. Default %s\n", OPT(param->bEnableWeightedPred));
     H0("\nQP, rate control and rate distortion options:\n");
@@ -574,19 +575,19 @@ int main(int argc, char **argv)
 #endif
     PPA_INIT();
 
-    x265_param param;
-    CLIOptions   cliopt;
+    x265_param *param = x265_param_alloc();
+    CLIOptions cliopt;
 
-    if (cliopt.parse(argc, argv, &param))
+    if (cliopt.parse(argc, argv, param))
     {
         cliopt.destroy();
         exit(1);
     }
 
-    x265_encoder *encoder = x265_encoder_open(&param);
+    x265_encoder *encoder = x265_encoder_open(param);
     if (!encoder)
     {
-        x265_log(&param, X265_LOG_ERROR, "failed to open encoder\n");
+        x265_log(param, X265_LOG_ERROR, "failed to open encoder\n");
         cliopt.destroy();
         x265_cleanup();
         exit(1);
@@ -594,7 +595,7 @@ int main(int argc, char **argv)
 
     /* Control-C handler */
     if (signal(SIGINT, sigint_handler) == SIG_ERR)
-        x265_log(&param, X265_LOG_ERROR, "Unable to register CTRL+C handler: %s\n", strerror(errno));
+        x265_log(param, X265_LOG_ERROR, "Unable to register CTRL+C handler: %s\n", strerror(errno));
 
     x265_picture pic_orig, pic_out;
     x265_picture *pic_in = &pic_orig;
@@ -608,7 +609,7 @@ int main(int argc, char **argv)
         cliopt.writeNALs(p_nal, nal);
     }
 
-    x265_picture_init(&param, pic_in);
+    x265_picture_init(param, pic_in);
 
     // main encoder loop
     uint32_t inFrameCount = 0;
@@ -635,7 +636,7 @@ int main(int argc, char **argv)
             cliopt.writeNALs(p_nal, nal);
 
         // Because x265_encoder_encode() lazily encodes entire GOPs, updates are per-GOP
-        cliopt.printStatus(outFrameCount, &param);
+        cliopt.printStatus(outFrameCount, param);
     }
 
     /* Flush the encoder */
@@ -651,7 +652,7 @@ int main(int argc, char **argv)
         if (nal)
             cliopt.writeNALs(p_nal, nal);
 
-        cliopt.printStatus(outFrameCount, &param);
+        cliopt.printStatus(outFrameCount, param);
 
         if (!numEncoded)
             break;
@@ -662,7 +663,7 @@ int main(int argc, char **argv)
         fprintf(stderr, "                                                                               \r");
 
     x265_encoder_get_stats(encoder, &stats, sizeof(stats));
-    if (param.csvfn && !b_ctrl_c)
+    if (param->csvfn && !b_ctrl_c)
         x265_encoder_log(encoder, argc, argv);
     x265_encoder_close(encoder);
     cliopt.bitstreamFile.close();
@@ -676,10 +677,10 @@ int main(int argc, char **argv)
         printf("\nencoded %d frames in %.2fs (%.2f fps), %.2f kb/s, ", stats.encodedPictureCount,
                stats.elapsedEncodeTime, stats.encodedPictureCount / stats.elapsedEncodeTime, stats.bitrate);
 
-        if (param.bEnablePsnr)


More information about the x265-commits mailing list