[x265] x265_encoder_encode: don't return 0 while flushing.
Satoshi Nakagawa
nakagawa424 at oki.com
Fri Jun 20 03:14:42 CEST 2014
# HG changeset patch
# User Satoshi Nakagawa <nakagawa424 at oki.com>
# Date 1403226667 -32400
# Fri Jun 20 10:11:07 2014 +0900
# Node ID 7f3a9661aa68dde361a62b971812adfce718af7d
# Parent ecccd5401d27b3aa5f2333295c933518653d73ef
x265_encoder_encode: don't return 0 while flushing.
diff -r ecccd5401d27 -r 7f3a9661aa68 source/encoder/api.cpp
--- a/source/encoder/api.cpp Thu Jun 19 22:13:36 2014 +0900
+++ b/source/encoder/api.cpp Fri Jun 20 10:11:07 2014 +0900
@@ -116,7 +116,15 @@
Encoder *encoder = static_cast<Encoder*>(enc);
NALUnit *nalunits[MAX_NAL_UNITS];
memset(nalunits, 0, sizeof(nalunits));
- int numEncoded = encoder->encode(!pic_in, pic_in, pic_out, nalunits);
+ bool flush = !pic_in;
+ int numEncoded;
+
+ // While flushing, We cannot return 0 until the entire stream is flushed
+ do
+ {
+ numEncoded = encoder->encode(flush, pic_in, pic_out, nalunits);
+ }
+ while (numEncoded == 0 && flush && encoder->m_numDelayedPic);
if (pp_nal && numEncoded > 0)
{
diff -r ecccd5401d27 -r 7f3a9661aa68 source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp Thu Jun 19 22:13:36 2014 +0900
+++ b/source/encoder/encoder.cpp Fri Jun 20 10:11:07 2014 +0900
@@ -60,6 +60,7 @@
m_rateControl = NULL;
m_dpb = NULL;
m_exportedPic = NULL;
+ m_numDelayedPic = 0;
m_nals = NULL;
m_packetData = NULL;
m_outputCount = 0;
@@ -322,6 +323,7 @@
if (m_param->rc.aqMode || bEnableWP)
m_rateControl->calcAdaptiveQuantFrame(pic);
m_lookahead->addPicture(pic, pic_in->sliceType);
+ m_numDelayedPic++;
}
if (flush)
@@ -350,22 +352,6 @@
// accomplished when the encoder is full.
TComPic *out = curEncoder->getEncodedPicture(nalunits);
- if (!out && flush)
- {
- // if the current encoder did not return an output picture and we are
- // flushing, check all the other encoders in logical order until
- // we find an output picture or have cycled around. We cannot return
- // 0 until the entire stream is flushed
- // (can only be an issue when --frames < --frame-threads)
- int flushed = m_curEncoder;
- do
- {
- curEncoder = &m_frameEncoder[m_curEncoder];
- m_curEncoder = (m_curEncoder + 1) % m_param->frameNumThreads;
- out = curEncoder->getEncodedPicture(nalunits);
- }
- while (!out && flushed != m_curEncoder);
- }
if (out)
{
if (pic_out)
@@ -456,6 +442,8 @@
else
m_exportedPic = out;
+ m_numDelayedPic--;
+
ret = 1;
}
diff -r ecccd5401d27 -r 7f3a9661aa68 source/encoder/encoder.h
--- a/source/encoder/encoder.h Thu Jun 19 22:13:36 2014 +0900
+++ b/source/encoder/encoder.h Fri Jun 20 10:11:07 2014 +0900
@@ -189,6 +189,8 @@
char* m_packetData;
int m_totalFrameThreads;
+ uint32_t m_numDelayedPic;
+
Encoder();
virtual ~Encoder();
diff -r ecccd5401d27 -r 7f3a9661aa68 source/encoder/slicetype.cpp
--- a/source/encoder/slicetype.cpp Thu Jun 19 22:13:36 2014 +0900
+++ b/source/encoder/slicetype.cpp Fri Jun 20 10:11:07 2014 +0900
@@ -141,6 +141,9 @@
/* Called by API thread */
void Lookahead::flush()
{
+ /* just in case the input queue is never allowed to fill */
+ m_bFilling = false;
+
/* flush synchronously */
m_inputQueueLock.acquire();
if (!m_inputQueue.empty())
@@ -150,9 +153,6 @@
else
m_inputQueueLock.release();
- /* just in case the input queue is never allowed to fill */
- m_bFilling = false;
-
m_inputQueueLock.acquire();
/* bFlushed indicates that an empty output queue actually means all frames
More information about the x265-devel
mailing list