[x265] [PATCH 4 of 4] Do not wait until all the frames in a stream are flushed, return to API as soon as one frame is flushed

santhoshini at multicorewareinc.com santhoshini at multicorewareinc.com
Mon Nov 6 09:35:10 CET 2017


# HG changeset patch
# User Santhoshini Sekar <santhoshini at multicorewareinc.com>
# Date 1502275399 -19800
#      Wed Aug 09 16:13:19 2017 +0530
# Node ID baba97b098912a798c4674bff9abc487054f3020
# Parent  7af25e9b6dd505a3da18abae7b7fd000468302fb
Do not wait until all the frames in a stream are flushed, return to API as soon as one frame is flushed.


In few cases it is better to flush only one frame in x265-lib and return to API. The
application should flush the remaining frames in the stream in these situations. This is
especially useful when the application wants to retrieve information from the lib.

diff --git a/source/encoder/api.cpp b/source/encoder/api.cpp
--- a/source/encoder/api.cpp
+++ b/source/encoder/api.cpp
@@ -257,7 +257,9 @@
     {
         numEncoded = encoder->encode(pic_in, pic_out);
     }
-    while (numEncoded == 0 && !pic_in && encoder->m_numDelayedPic && !encoder->m_latestParam->forceFlush);
+    while ((numEncoded == 0 && !pic_in && encoder->m_numDelayedPic && !encoder->m_latestParam->forceFlush) && !encoder->m_externalFlush);
+    if (numEncoded)
+        encoder->m_externalFlush = false;
 
     // do not allow reuse of these buffers for more than one picture. The
     // encoder now owns these analysisData buffers.
diff --git a/source/encoder/encoder.cpp b/source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp
+++ b/source/encoder/encoder.cpp
@@ -2342,6 +2342,8 @@
 void Encoder::configure(x265_param *p)
 {
     this->m_param = p;
+    if (p->bMVType == AVC_INFO)
+        this->m_externalFlush = true;
     if (p->keyframeMax < 0)
     {
         /* A negative max GOP size indicates the user wants only one I frame at
diff --git a/source/encoder/encoder.h b/source/encoder/encoder.h
--- a/source/encoder/encoder.h
+++ b/source/encoder/encoder.h
@@ -138,6 +138,7 @@
     RateControl*       m_rateControl;
     Lookahead*         m_lookahead;
 
+    bool               m_externalFlush;
     /* Collect statistics globally */
     EncStats           m_analyzeAll;
     EncStats           m_analyzeI;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: x265-4.patch
Type: text/x-patch
Size: 2053 bytes
Desc: not available
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20171106/6eea6aff/attachment.bin>


More information about the x265-devel mailing list