[x265-commits] [x265] y4m: prevent infinite loop on malformed y4m frame headers

Steve Borho steve at borho.org
Mon Jan 27 07:06:22 CET 2014


details:   http://hg.videolan.org/x265/rev/9867ebc4b164
branches:  stable
changeset: 5898:9867ebc4b164
user:      Steve Borho <steve at borho.org>
date:      Fri Jan 24 13:31:13 2014 -0600
description:
y4m: prevent infinite loop on malformed y4m frame headers
Subject: [x265] input: use ifstream::good() instead of !ifstream::fail()

details:   http://hg.videolan.org/x265/rev/dba087c3613b
branches:  stable
changeset: 5899:dba087c3613b
user:      Steve Borho <steve at borho.org>
date:      Fri Jan 24 13:37:38 2014 -0600
description:
input: use ifstream::good() instead of !ifstream::fail()

good() implies bad, fail, and eof flags are all false. The fail() flag does
not include eof status or the bad bit for I/O errors.
Subject: [x265] yuv: support colorspaces in YUV input files (closes #13)

details:   http://hg.videolan.org/x265/rev/13dac38f54ac
branches:  stable
changeset: 5900:13dac38f54ac
user:      Steve Borho <steve at borho.org>
date:      Fri Jan 24 12:57:16 2014 -0600
description:
yuv: support colorspaces in YUV input files (closes #13)
Subject: [x265] asm : Fix for luma_vss test bench failure

details:   http://hg.videolan.org/x265/rev/7f09cfcf176c
branches:  
changeset: 5901:7f09cfcf176c
user:      Nabajit Deka
date:      Fri Jan 24 15:42:52 2014 +0530
description:
asm : Fix for luma_vss test bench failure
Subject: [x265] Merge with stable

details:   http://hg.videolan.org/x265/rev/237bf6667405
branches:  
changeset: 5902:237bf6667405
user:      Steve Borho <steve at borho.org>
date:      Fri Jan 24 14:43:31 2014 -0600
description:
Merge with stable
Subject: [x265] input: add build flag to disable read thread for debug purposes

details:   http://hg.videolan.org/x265/rev/1ac9148a3661
branches:  stable
changeset: 5903:1ac9148a3661
user:      Steve Borho <steve at borho.org>
date:      Fri Jan 24 09:02:15 2014 -0600
description:
input: add build flag to disable read thread for debug purposes
Subject: [x265] me: add a two pixel pad to the max ME range when calculating reference lag

details:   http://hg.videolan.org/x265/rev/b173809575c6
branches:  stable
changeset: 5904:b173809575c6
user:      Steve Borho <steve at borho.org>
date:      Mon Jan 27 00:04:22 2014 -0600
description:
me: add a two pixel pad to the max ME range when calculating reference lag

We must account for subpel refine search range when calculating how many rows
of reference frames must be encoded ahead of the current frame.  Without this
we saw non-deterministic decoder hash mismatches with some videos.

diffstat:

 source/common/common.cpp        |   4 ++--
 source/encoder/frameencoder.cpp |   5 ++++-
 source/input/y4m.cpp            |  12 ++++++++++--
 source/input/yuv.cpp            |  39 ++++++++++++++++++++++++++++-----------
 source/input/yuv.h              |   4 +++-
 5 files changed, 47 insertions(+), 17 deletions(-)

diffs (215 lines):

diff -r 2a2e5711f63b -r b173809575c6 source/common/common.cpp
--- a/source/common/common.cpp	Fri Jan 24 12:57:46 2014 -0600
+++ b/source/common/common.cpp	Mon Jan 27 00:04:22 2014 -0600
@@ -174,7 +174,7 @@ void x265_param_default(x265_param *para
     /* Inter Coding tools */
     param->searchMethod = X265_HEX_SEARCH;
     param->subpelRefine = 2;
-    param->searchRange = 60;
+    param->searchRange = 58;
     param->maxNumMergeCand = 2;
     param->bEnableWeightedPred = 1;
     param->bEnableWeightedBiPred = 0;
@@ -277,7 +277,7 @@ int x265_param_default_preset(x265_param
         {
             param->lookaheadDepth = 10;
             param->maxCUSize = 32;
-            param->searchRange = 28;
+            param->searchRange = 26;
             param->bFrameAdaptive = 0;
             param->subpelRefine = 0;
             param->maxNumMergeCand = 2;
diff -r 2a2e5711f63b -r b173809575c6 source/encoder/frameencoder.cpp
--- a/source/encoder/frameencoder.cpp	Fri Jan 24 12:57:46 2014 -0600
+++ b/source/encoder/frameencoder.cpp	Mon Jan 27 00:04:22 2014 -0600
@@ -944,7 +944,10 @@ void FrameEncoder::compressCTURows()
         m_rows[i].m_rdGoOnBinCodersCABAC.m_fracBits = 0;
     }
 
-    uint32_t refLagRows = ((m_cfg->param.searchRange + NTAPS_LUMA / 2 + g_maxCUHeight - 1) / g_maxCUHeight) + 1;
+    int range = m_cfg->param.searchRange + /* fpel search */
+                2 +                        /* subpel refine */
+                NTAPS_LUMA / 2;            /* subpel filter half-length */
+    uint32_t refLagRows = 1 + ((range + g_maxCUHeight - 1) / g_maxCUHeight);
     int numPredDir = slice->isInterP() ? 1 : slice->isInterB() ? 2 : 0;
 
     m_pic->m_SSDY = 0;
diff -r 2a2e5711f63b -r b173809575c6 source/input/y4m.cpp
--- a/source/input/y4m.cpp	Fri Jan 24 12:57:46 2014 -0600
+++ b/source/input/y4m.cpp	Mon Jan 27 00:04:22 2014 -0600
@@ -28,6 +28,8 @@
 #include <string.h>
 #include <iostream>
 
+#define ENABLE_THREADING 1
+
 #if _WIN32
 #include <io.h>
 #include <fcntl.h>
@@ -61,7 +63,7 @@ Y4MInput::Y4MInput(const char *filename,
         ifs = new ifstream(filename, ios::binary | ios::in);
 
     threadActive = false;
-    if (ifs && !ifs->fail())
+    if (ifs && ifs->good())
     {
         if (parseHeader())
         {
@@ -307,12 +309,16 @@ void Y4MInput::skipFrames(uint32_t numFr
 bool Y4MInput::readPicture(x265_picture& pic)
 {
     PPAStartCpuEventFunc(read_yuv);
+#if ENABLE_THREADING
     while (head == tail)
     {
         notEmpty.wait();
         if (!threadActive)
             return false;
     }
+#else
+    populateFrameQueue();
+#endif
 
     if (!frameStat[head])
         return false;
@@ -332,8 +338,10 @@ bool Y4MInput::readPicture(x265_picture&
 
 void Y4MInput::startReader()
 {
+#if ENABLE_THREADING
     if (threadActive)
         start();
+#endif
 }
 
 void Y4MInput::threadMain()
@@ -366,7 +374,7 @@ bool Y4MInput::populateFrameQueue()
     }
     /* consume bytes up to line feed */
     int c = ifs->get();
-    while (c != '\n' && !ifs)
+    while (c != '\n' && ifs->good())
     {
         c = ifs->get();
     }
diff -r 2a2e5711f63b -r b173809575c6 source/input/yuv.cpp
--- a/source/input/yuv.cpp	Fri Jan 24 12:57:46 2014 -0600
+++ b/source/input/yuv.cpp	Mon Jan 27 00:04:22 2014 -0600
@@ -29,6 +29,8 @@
 #include <assert.h>
 #include <iostream>
 
+#define ENABLE_THREADING 1
+
 #if _WIN32
 #include <io.h>
 #include <fcntl.h>
@@ -63,7 +65,7 @@ YUVInput::YUVInput(const char *filename,
     else
         ifs = new ifstream(filename, ios::binary | ios::in);
 
-    if (ifs && !ifs->fail())
+    if (ifs && ifs->good())
         threadActive = true;
     else if (ifs && ifs != &cin)
     {
@@ -90,25 +92,32 @@ void YUVInput::release()
     delete this;
 }
 
-void YUVInput::setDimensions(int w, int h)
+void YUVInput::init()
 {
-    width = w;
-    height = h;
-    framesize = (width * height * 3 / 2) * pixelbytes;
+    if (!framesize)
+    {
+        for (int i = 0; i < x265_cli_csps[colorSpace].planes; i++)
+        {
+            uint32_t w = width >> x265_cli_csps[colorSpace].width[i];
+            uint32_t h = height >> x265_cli_csps[colorSpace].height[i];
+            framesize += w * h * pixelbytes;
+        }
 
-    for (uint32_t i = 0; i < QUEUE_SIZE; i++)
-    {
-        buf[i] = new char[framesize];
-        if (buf[i] == NULL)
+        for (uint32_t i = 0; i < QUEUE_SIZE; i++)
         {
-            x265_log(NULL, X265_LOG_ERROR, "yuv: buffer allocation failure, aborting\n");
-            threadActive = false;
+            buf[i] = new char[framesize];
+            if (buf[i] == NULL)
+            {
+                x265_log(NULL, X265_LOG_ERROR, "yuv: buffer allocation failure, aborting\n");
+                threadActive = false;
+            }
         }
     }
 }
 
 int YUVInput::guessFrameCount()
 {
+    init();
     if (!ifs || ifs == &cin) return -1;
 
     ifstream::pos_type cur = ifs->tellg();
@@ -127,6 +136,7 @@ int YUVInput::guessFrameCount()
 
 void YUVInput::skipFrames(uint32_t numFrames)
 {
+    init();
     if (ifs)
     {
         for (uint32_t i = 0; i < numFrames; i++)
@@ -136,8 +146,11 @@ void YUVInput::skipFrames(uint32_t numFr
 
 void YUVInput::startReader()
 {
+    init();
+#if ENABLE_THREADING
     if (ifs && threadActive)
         start();
+#endif
 }
 
 void YUVInput::threadMain()
@@ -173,12 +186,16 @@ bool YUVInput::populateFrameQueue()
 
 bool YUVInput::readPicture(x265_picture& pic)
 {
+#if ENABLE_THREADING
     while (head == tail)
     {
         notEmpty.wait();
         if (!threadActive)
             return false;
     }
+#else
+    populateFrameQueue();
+#endif
 
     if (!frameStat[head])
         return false;
diff -r 2a2e5711f63b -r b173809575c6 source/input/yuv.h
--- a/source/input/yuv.h	Fri Jan 24 12:57:46 2014 -0600
+++ b/source/input/yuv.h	Mon Jan 27 00:04:22 2014 -0600
@@ -65,13 +65,15 @@ protected:
 
     std::istream *ifs;
 
+    void init();
+
 public:
 
     YUVInput(const char *filename, uint32_t inputBitDepth);
 
     virtual ~YUVInput();
 
-    void setDimensions(int w, int h);
+    void setDimensions(int w, int h)              { width = w; height = h; }
 
     void setColorSpace(int csp)                   { colorSpace = csp; }
 


More information about the x265-commits mailing list