[x265] [PATCH] api: change x265_encoder_headers() to return byte count on success
Steve Borho
steve at borho.org
Thu Mar 27 01:48:41 CET 2014
# HG changeset patch
# User Steve Borho <steve at borho.org>
# Date 1395881165 18000
# Wed Mar 26 19:46:05 2014 -0500
# Node ID f6e68cc47e6764017e41bf8273bab688a127a0b1
# Parent d38335a9375adc028e5e027e824bb993476e6263
api: change x265_encoder_headers() to return byte count on success
diff -r d38335a9375a -r f6e68cc47e67 source/CMakeLists.txt
--- a/source/CMakeLists.txt Mon Mar 24 23:42:38 2014 +0900
+++ b/source/CMakeLists.txt Wed Mar 26 19:46:05 2014 -0500
@@ -18,7 +18,7 @@
include(CheckCXXCompilerFlag)
# X265_BUILD must be incremented each time the public API is changed
-set(X265_BUILD 12)
+set(X265_BUILD 13)
configure_file("${PROJECT_SOURCE_DIR}/x265.def.in"
"${PROJECT_BINARY_DIR}/x265.def")
configure_file("${PROJECT_SOURCE_DIR}/x265_config.h.in"
diff -r d38335a9375a -r f6e68cc47e67 source/encoder/api.cpp
--- a/source/encoder/api.cpp Mon Mar 24 23:42:38 2014 +0900
+++ b/source/encoder/api.cpp Wed Mar 26 19:46:05 2014 -0500
@@ -69,7 +69,7 @@
int x265_encoder_headers(x265_encoder *enc, x265_nal **pp_nal, uint32_t *pi_nal)
{
if (!pp_nal || !enc)
- return 0;
+ return -1;
Encoder *encoder = static_cast<Encoder*>(enc);
@@ -77,7 +77,7 @@
NALUnitEBSP *nalunits[MAX_NAL_UNITS] = { 0, 0, 0, 0, 0 };
if (encoder->getStreamHeaders(nalunits) > 0)
{
- int nalcount = encoder->extractNalData(nalunits);
+ int nalcount = encoder->extractNalData(nalunits, ret);
*pp_nal = &encoder->m_nals[0];
if (pi_nal) *pi_nal = nalcount;
}
@@ -111,7 +111,8 @@
if (pp_nal && numEncoded > 0)
{
- int nalcount = encoder->extractNalData(nalunits);
+ int memsize;
+ int nalcount = encoder->extractNalData(nalunits, memsize);
*pp_nal = &encoder->m_nals[0];
if (pi_nal) *pi_nal = nalcount;
}
diff -r d38335a9375a -r f6e68cc47e67 source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp Mon Mar 24 23:42:38 2014 +0900
+++ b/source/encoder/encoder.cpp Wed Mar 26 19:46:05 2014 -0500
@@ -1523,14 +1523,13 @@
m_CUTransquantBypassFlagValue = false;
}
-int Encoder::extractNalData(NALUnitEBSP **nalunits)
+int Encoder::extractNalData(NALUnitEBSP **nalunits, int& memsize)
{
- uint32_t memsize = 0;
- uint32_t offset = 0;
+ int offset = 0;
int nalcount = 0;
-
int num = 0;
+ memsize = 0;
for (; num < MAX_NAL_UNITS && nalunits[num] != NULL; num++)
{
const NALUnitEBSP& temp = *nalunits[num];
@@ -1548,7 +1547,7 @@
for (; nalcount < num; nalcount++)
{
const NALUnitEBSP& nalu = *nalunits[nalcount];
- uint32_t size; /* size of annexB unit in bytes */
+ int size; /* size of annexB unit in bytes */
static const char start_code_prefix[] = { 0, 0, 0, 1 };
if (nalcount == 0 || nalu.m_nalUnitType == NAL_UNIT_SPS || nalu.m_nalUnitType == NAL_UNIT_PPS)
diff -r d38335a9375a -r f6e68cc47e67 source/encoder/encoder.h
--- a/source/encoder/encoder.h Mon Mar 24 23:42:38 2014 +0900
+++ b/source/encoder/encoder.h Wed Mar 26 19:46:05 2014 -0500
@@ -224,7 +224,7 @@
void determineLevelAndProfile(x265_param *param);
- int extractNalData(NALUnitEBSP **nalunits);
+ int extractNalData(NALUnitEBSP **nalunits, int& memsize);
void updateVbvPlan(RateControl* rc);
diff -r d38335a9375a -r f6e68cc47e67 source/x265.cpp
--- a/source/x265.cpp Mon Mar 24 23:42:38 2014 +0900
+++ b/source/x265.cpp Wed Mar 26 19:46:05 2014 -0500
@@ -669,21 +669,26 @@
x265_picture pic_orig, pic_out;
x265_picture *pic_in = &pic_orig;
x265_picture *pic_recon = cliopt.recon ? &pic_out : NULL;
+ uint32_t inFrameCount = 0;
+ uint32_t outFrameCount = 0;
x265_nal *p_nal;
x265_stats stats;
uint32_t nal;
if (!param->bRepeatHeaders)
{
- if (!x265_encoder_headers(encoder, &p_nal, &nal))
+ if (x265_encoder_headers(encoder, &p_nal, &nal) < 0)
+ {
+ x265_log(param, X265_LOG_ERROR, "Failure generating stream headers\n");
+ goto fail;
+ }
+ else
cliopt.writeNALs(p_nal, nal);
}
x265_picture_init(param, pic_in);
// main encoder loop
- uint32_t inFrameCount = 0;
- uint32_t outFrameCount = 0;
while (pic_in && !b_ctrl_c)
{
pic_orig.poc = inFrameCount;
@@ -737,6 +742,7 @@
if (cliopt.bProgress)
fprintf(stderr, "%*s\r", 80, " ");
+fail:
x265_encoder_get_stats(encoder, &stats, sizeof(stats));
if (param->csvfn && !b_ctrl_c)
x265_encoder_log(encoder, argc, argv);
diff -r d38335a9375a -r f6e68cc47e67 source/x265.h
--- a/source/x265.h Mon Mar 24 23:42:38 2014 +0900
+++ b/source/x265.h Wed Mar 26 19:46:05 2014 -0500
@@ -925,7 +925,7 @@
/* x265_encoder_headers:
* return the SPS and PPS that will be used for the whole stream.
* *pi_nal is the number of NAL units outputted in pp_nal.
- * returns negative on error.
+ * returns negative on error, total byte size of payload data on success
* the payloads of all output NALs are guaranteed to be sequential in memory. */
int x265_encoder_headers(x265_encoder *, x265_nal **pp_nal, uint32_t *pi_nal);
More information about the x265-devel
mailing list