<div dir="ltr">pushed <div> <br clear="all"><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div>Thanks,</div><div dir="ltr"><span></span><span></span>Kalyan Goswami, PhD</div><div dir="ltr"><span style="font-size:12.8px">Video Architect @ MulticoreWare</span></div><div dir="ltr"><div><a href="http://www.multicorewareinc.com/" target="_blank">http:</a><a href="http://www.multicorewareinc.com/" style="font-size:12.8px" target="_blank">//www.multicorewareinc.com</a></div><div><span style="font-size:12.8px">+91 9884989331</span><br></div><div></div></div></div></div></div></div></div></div></div></div></div></div></div><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Mon, Dec 10, 2018 at 3:29 PM Aruna Matheswaran <<a href="mailto:aruna@multicorewareinc.com">aruna@multicorewareinc.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div># HG changeset patch</div><div># User Aruna Matheswaran <<a href="mailto:aruna@multicorewareinc.com" target="_blank">aruna@multicorewareinc.com</a>></div><div># Date 1538037975 -19800</div><div># Thu Sep 27 14:16:15 2018 +0530</div><div># Node ID e50f803e26fb3926dc695e0aeea39681fe1eacbd</div><div># Parent b748ee9f44657a9468b9d62c85d02dfafcbc4039</div><div>Add support for Dolby Vision RPU muxing</div><div><br></div><div>diff -r b748ee9f4465 -r e50f803e26fb doc/reST/cli.rst</div><div>--- a/doc/reST/cli.rst<span style="white-space:pre-wrap"> </span>Fri Sep 28 10:45:23 2018 +0530</div><div>+++ b/doc/reST/cli.rst<span style="white-space:pre-wrap"> </span>Thu Sep 27 14:16:15 2018 +0530</div><div>@@ -2208,6 +2208,15 @@</div><div> </div><div> Currently only profile 5 enabled, Default 0 (disabled)</div><div> </div><div>+.. option:: --dolby-vision-rpu</div><div>+</div><div>+ File containing Dolby Vision RPU metadata. If given, x265's Dolby Vision </div><div>+ metadata parser will fill the RPU field of input pictures with the metadata</div><div>+ read from the file. The library will interleave access units with RPUs in the </div><div>+ bitstream. Default NULL (disabled).</div><div>+ </div><div>+ **CLI ONLY**</div><div>+</div><div> .. option:: --info, --no-info</div><div> </div><div> <span style="white-space:pre-wrap"> </span>Emit an informational SEI with the stream headers which describes</div><div>diff -r b748ee9f4465 -r e50f803e26fb source/CMakeLists.txt</div><div>--- a/source/CMakeLists.txt<span style="white-space:pre-wrap"> </span>Fri Sep 28 10:45:23 2018 +0530</div><div>+++ b/source/CMakeLists.txt<span style="white-space:pre-wrap"> </span>Thu Sep 27 14:16:15 2018 +0530</div><div>@@ -29,7 +29,7 @@</div><div> option(STATIC_LINK_CRT "Statically link C runtime for release builds" OFF)</div><div> mark_as_advanced(FPROFILE_USE FPROFILE_GENERATE NATIVE_BUILD)</div><div> # X265_BUILD must be incremented each time the public API is changed</div><div>-set(X265_BUILD 166)</div><div>+set(X265_BUILD 167)</div><div> configure_file("${PROJECT_SOURCE_DIR}/<a href="http://x265.def.in" target="_blank">x265.def.in</a>"</div><div> "${PROJECT_BINARY_DIR}/x265.def")</div><div> configure_file("${PROJECT_SOURCE_DIR}/<a href="http://x265_config.h.in" target="_blank">x265_config.h.in</a>"</div><div>diff -r b748ee9f4465 -r e50f803e26fb source/common/frame.cpp</div><div>--- a/source/common/frame.cpp<span style="white-space:pre-wrap"> </span>Fri Sep 28 10:45:23 2018 +0530</div><div>+++ b/source/common/frame.cpp<span style="white-space:pre-wrap"> </span>Thu Sep 27 14:16:15 2018 +0530</div><div>@@ -44,6 +44,8 @@</div><div> m_param = NULL;</div><div> m_userSEI.numPayloads = 0;</div><div> m_userSEI.payloads = NULL;</div><div>+ m_rpu.payloadSize = 0;</div><div>+ m_rpu.payload = NULL;</div><div> memset(&m_lowres, 0, sizeof(m_lowres));</div><div> m_rcData = NULL;</div><div> m_encodeStartTime = 0;</div><div>diff -r b748ee9f4465 -r e50f803e26fb source/common/frame.h</div><div>--- a/source/common/frame.h<span style="white-space:pre-wrap"> </span>Fri Sep 28 10:45:23 2018 +0530</div><div>+++ b/source/common/frame.h<span style="white-space:pre-wrap"> </span>Thu Sep 27 14:16:15 2018 +0530</div><div>@@ -98,6 +98,7 @@</div><div> </div><div> float* m_quantOffsets; // points to quantOffsets in x265_picture</div><div> x265_sei m_userSEI;</div><div>+ x265_dolby_vision_rpu m_rpu;</div><div> </div><div> /* Frame Parallelism - notification between FrameEncoders of available motion reference rows */</div><div> ThreadSafeInteger* m_reconRowFlag; // flag of CTU rows completely reconstructed and extended for motion reference</div><div>diff -r b748ee9f4465 -r e50f803e26fb source/encoder/api.cpp</div><div>--- a/source/encoder/api.cpp<span style="white-space:pre-wrap"> </span>Fri Sep 28 10:45:23 2018 +0530</div><div>+++ b/source/encoder/api.cpp<span style="white-space:pre-wrap"> </span>Thu Sep 27 14:16:15 2018 +0530</div><div>@@ -598,6 +598,8 @@</div><div> pic->quantOffsets = NULL;</div><div> pic->userSEI.payloads = NULL;</div><div> pic->userSEI.numPayloads = 0;</div><div>+ pic->rpu.payloadSize = 0;</div><div>+ pic->rpu.payload = NULL;</div><div> </div><div> if ((param->analysisSave || param->analysisLoad) || (param->bMVType == AVC_INFO))</div><div> {</div><div>@@ -612,6 +614,8 @@</div><div> </div><div> void x265_picture_free(x265_picture *p)</div><div> {</div><div>+ if (p->rpu.payload)</div><div>+ X265_FREE(p->rpu.payload);</div><div> return x265_free(p);</div><div> }</div><div> </div><div>diff -r b748ee9f4465 -r e50f803e26fb source/encoder/encoder.cpp</div><div>--- a/source/encoder/encoder.cpp<span style="white-space:pre-wrap"> </span>Fri Sep 28 10:45:23 2018 +0530</div><div>+++ b/source/encoder/encoder.cpp<span style="white-space:pre-wrap"> </span>Thu Sep 27 14:16:15 2018 +0530</div><div>@@ -1075,6 +1075,14 @@</div><div> </div><div> copyUserSEIMessages(inFrame, pic_in);</div><div> </div><div>+ /*Copy Dolby Vision RPU from pic_in to frame*/</div><div>+ if (pic_in->rpu.payloadSize)</div><div>+ {</div><div>+ inFrame->m_rpu.payloadSize = pic_in->rpu.payloadSize;</div><div>+ inFrame->m_rpu.payload = new uint8_t[pic_in->rpu.payloadSize];</div><div>+ memcpy(inFrame->m_rpu.payload, pic_in->rpu.payload, pic_in->rpu.payloadSize);</div><div>+ }</div><div>+</div><div> if (pic_in->quantOffsets != NULL)</div><div> {</div><div> int cuCount;</div><div>@@ -2362,6 +2370,13 @@</div><div> {</div><div> sbacCoder.setBitstream(&bs);</div><div> </div><div>+ if (m_param->dolbyProfile && !m_param->bRepeatHeaders)</div><div>+ {</div><div>+ bs.resetBits();</div><div>+ bs.write(0x10, 8);</div><div>+ list.serialize(NAL_UNIT_ACCESS_UNIT_DELIMITER, bs);</div><div>+ }</div><div>+ </div><div> /* headers for start of bitstream */</div><div> bs.resetBits();</div><div> sbacCoder.codeVPS(m_vps);</div><div>diff -r b748ee9f4465 -r e50f803e26fb source/encoder/frameencoder.cpp</div><div>--- a/source/encoder/frameencoder.cpp<span style="white-space:pre-wrap"> </span>Fri Sep 28 10:45:23 2018 +0530</div><div>+++ b/source/encoder/frameencoder.cpp<span style="white-space:pre-wrap"> </span>Thu Sep 27 14:16:15 2018 +0530</div><div>@@ -1063,6 +1063,14 @@</div><div> m_accessUnitBits = bytes << 3;</div><div> }</div><div> </div><div>+ if (m_frame->m_rpu.payloadSize)</div><div>+ {</div><div>+ m_bs.resetBits();</div><div>+ for (int i = 0; i < m_frame->m_rpu.payloadSize; i++)</div><div>+ m_bs.write(m_frame->m_rpu.payload[i], 8);</div><div>+ m_nalList.serialize(NAL_UNIT_UNSPECIFIED, m_bs);</div><div>+ }</div><div>+</div><div> m_endCompressTime = x265_mdate();</div><div> </div><div> /* Decrement referenced frame reference counts, allow them to be recycled */</div><div>diff -r b748ee9f4465 -r e50f803e26fb source/encoder/nal.cpp</div><div>--- a/source/encoder/nal.cpp<span style="white-space:pre-wrap"> </span>Fri Sep 28 10:45:23 2018 +0530</div><div>+++ b/source/encoder/nal.cpp<span style="white-space:pre-wrap"> </span>Thu Sep 27 14:16:15 2018 +0530</div><div>@@ -97,7 +97,7 @@</div><div> /* Will write size later */</div><div> bytes += 4;</div><div> }</div><div>- else if (!m_numNal || nalUnitType == NAL_UNIT_VPS || nalUnitType == NAL_UNIT_SPS || nalUnitType == NAL_UNIT_PPS)</div><div>+ else if (!m_numNal || nalUnitType == NAL_UNIT_VPS || nalUnitType == NAL_UNIT_SPS || nalUnitType == NAL_UNIT_PPS || nalUnitType == NAL_UNIT_UNSPECIFIED)</div><div> {</div><div> memcpy(out, startCodePrefix, 4);</div><div> bytes += 4;</div><div>@@ -124,7 +124,7 @@</div><div> * - 0x000002 */</div><div> for (uint32_t i = 0; i < payloadSize; i++)</div><div> {</div><div>- if (i > 2 && !out[bytes - 2] && !out[bytes - 3] && out[bytes - 1] <= 0x03)</div><div>+ if (i > 2 && !out[bytes - 2] && !out[bytes - 3] && out[bytes - 1] <= 0x03 && nalUnitType != NAL_UNIT_UNSPECIFIED)</div><div> {</div><div> /* inject 0x03 to prevent emulating a start code */</div><div> out[bytes] = out[bytes - 1];</div><div>diff -r b748ee9f4465 -r e50f803e26fb source/encoder/sei.cpp</div><div>--- a/source/encoder/sei.cpp<span style="white-space:pre-wrap"> </span>Fri Sep 28 10:45:23 2018 +0530</div><div>+++ b/source/encoder/sei.cpp<span style="white-space:pre-wrap"> </span>Thu Sep 27 14:16:15 2018 +0530</div><div>@@ -66,7 +66,8 @@</div><div> </div><div> if (!isNested)</div><div> {</div><div>- bs.writeByteAlignment();</div><div>+ if (nalUnitType != NAL_UNIT_UNSPECIFIED)</div><div>+ bs.writeByteAlignment();</div><div> list.serialize(nalUnitType, bs);</div><div> }</div><div> }</div><div>diff -r b748ee9f4465 -r e50f803e26fb source/x265.cpp</div><div>--- a/source/x265.cpp<span style="white-space:pre-wrap"> </span>Fri Sep 28 10:45:23 2018 +0530</div><div>+++ b/source/x265.cpp<span style="white-space:pre-wrap"> </span>Thu Sep 27 14:16:15 2018 +0530</div><div>@@ -65,6 +65,8 @@</div><div> {</div><div> b_ctrl_c = 1;</div><div> }</div><div>+#define START_CODE 0x00000001</div><div>+#define START_CODE_BYTES 4</div><div> </div><div> struct CLIOptions</div><div> {</div><div>@@ -72,6 +74,7 @@</div><div> ReconFile* recon;</div><div> OutputFile* output;</div><div> FILE* qpfile;</div><div>+ FILE* dolbyVisionRpu; /* File containing Dolby Vision BL RPU metadata */</div><div> const char* reconPlayCmd;</div><div> const x265_api* api;</div><div> x265_param* param;</div><div>@@ -94,6 +97,7 @@</div><div> recon = NULL;</div><div> output = NULL;</div><div> qpfile = NULL;</div><div>+ dolbyVisionRpu = NULL;</div><div> reconPlayCmd = NULL;</div><div> api = NULL;</div><div> param = NULL;</div><div>@@ -124,6 +128,9 @@</div><div> if (qpfile)</div><div> fclose(qpfile);</div><div> qpfile = NULL;</div><div>+ if (dolbyVisionRpu)</div><div>+ fclose(dolbyVisionRpu);</div><div>+ dolbyVisionRpu = NULL;</div><div> if (output)</div><div> output->release();</div><div> output = NULL;</div><div>@@ -311,6 +318,15 @@</div><div> if (!this->qpfile)</div><div> x265_log_file(param, X265_LOG_ERROR, "%s qpfile not found or error in opening qp file\n", optarg);</div><div> }</div><div>+ OPT("dolby-vision-rpu")</div><div>+ {</div><div>+ this->dolbyVisionRpu = x265_fopen(optarg, "rb");</div><div>+ if (!this->dolbyVisionRpu)</div><div>+ {</div><div>+ x265_log_file(param, X265_LOG_ERROR, "Dolby Vision RPU metadata file %s not found or error in opening file\n", optarg);</div><div>+ return true;</div><div>+ }</div><div>+ }</div><div> OPT("fullhelp")</div><div> {</div><div> param->logLevel = X265_LOG_FULL;</div><div>@@ -552,6 +568,59 @@</div><div> }</div><div> #endif</div><div> </div><div>+/* Parse the RPU file and extract the RPU corresponding to the current picture </div><div>+ * and fill the rpu field of the input picture */</div><div>+static int rpuParser(x265_picture * pic, FILE * ptr)</div><div>+{</div><div>+ uint8_t byte;</div><div>+ uint32_t code = 0;</div><div>+ int bytesRead = 0;</div><div>+ pic->rpu.payloadSize = 0;</div><div>+</div><div>+ if (!pic->pts)</div><div>+ {</div><div>+ while (bytesRead++ < 4 && fread(&byte, sizeof(uint8_t), 1, ptr))</div><div>+ code = (code << 8) | byte;</div><div>+ </div><div>+ if (code != START_CODE)</div><div>+ {</div><div>+ x265_log(NULL, X265_LOG_ERROR, "Invalid Dolby Vision RPU startcode in POC %d\n", pic->pts);</div><div>+ return 1;</div><div>+ }</div><div>+ } </div><div>+</div><div>+ bytesRead = 0;</div><div>+ while (fread(&byte, sizeof(uint8_t), 1, ptr))</div><div>+ {</div><div>+ code = (code << 8) | byte;</div><div>+ if (bytesRead++ < 3)</div><div>+ continue;</div><div>+ if (bytesRead >= 1024)</div><div>+ {</div><div>+ x265_log(NULL, X265_LOG_ERROR, "Invalid Dolby Vision RPU size in POC %d\n", pic->pts);</div><div>+ return 1;</div><div>+ }</div><div>+ </div><div>+ if (code != START_CODE)</div><div>+ pic->rpu.payload[pic->rpu.payloadSize++] = (code >> (3 * 8)) & 0xFF;</div><div>+ else</div><div>+ return 0; </div><div>+ }</div><div>+</div><div>+ int ShiftBytes = START_CODE_BYTES - (bytesRead - pic->rpu.payloadSize);</div><div>+ int bytesLeft = bytesRead - pic->rpu.payloadSize;</div><div>+ code = (code << ShiftBytes * 8);</div><div>+ for (int i = 0; i < bytesLeft; i++)</div><div>+ {</div><div>+ pic->rpu.payload[pic->rpu.payloadSize++] = (code >> (3 * 8)) & 0xFF;</div><div>+ code = (code << 8);</div><div>+ }</div><div>+ if (!pic->rpu.payloadSize)</div><div>+ x265_log(NULL, X265_LOG_WARNING, "Dolby Vision RPU not found for POC %d\n", pic->pts);</div><div>+ return 0;</div><div>+}</div><div>+</div><div>+</div><div> /* CLI return codes:</div><div> *</div><div> * 0 - encode successful</div><div>@@ -630,8 +699,10 @@</div><div> x265_stats stats;</div><div> uint32_t nal;</div><div> int16_t *errorBuf = NULL;</div><div>+ bool bDolbyVisionRPU = false;</div><div> int ret = 0;</div><div> </div><div>+</div><div> if (!param->bRepeatHeaders)</div><div> {</div><div> if (api->encoder_headers(encoder, &p_nal, &nal) < 0)</div><div>@@ -646,6 +717,13 @@</div><div> </div><div> api->picture_init(param, pic_in);</div><div> </div><div>+ if (param->dolbyProfile && cliopt.dolbyVisionRpu)</div><div>+ {</div><div>+ pic_in->rpu.payload = X265_MALLOC(uint8_t, 1024);</div><div>+ if (pic_in->rpu.payload)</div><div>+ bDolbyVisionRPU = true;</div><div>+ }</div><div>+ </div><div> if (cliopt.bDither)</div><div> {</div><div> errorBuf = X265_MALLOC(int16_t, param->sourceWidth + 1);</div><div>@@ -685,8 +763,13 @@</div><div> }</div><div> /* Overwrite PTS */</div><div> pic_in->pts = pic_in->poc;</div><div>+</div><div>+ if (bDolbyVisionRPU)</div><div>+ {</div><div>+ if (rpuParser(pic_in, cliopt.dolbyVisionRpu) > 0)</div><div>+ goto fail;</div><div>+ }</div><div> }</div><div>-</div><div> int numEncoded = api->encoder_encode(encoder, &p_nal, &nal, pic_in, pic_recon);</div><div> if (numEncoded < 0)</div><div> {</div><div>@@ -749,6 +832,13 @@</div><div> break;</div><div> }</div><div> </div><div>+ if (bDolbyVisionRPU)</div><div>+ {</div><div>+ if(fgetc(cliopt.dolbyVisionRpu) != EOF)</div><div>+ x265_log(NULL, X265_LOG_WARNING, "Dolby Vision RPU count is greater than frame count\n");</div><div>+ x265_log(NULL, X265_LOG_INFO, "VES muxing with Dolby Vision RPU file successful\n");</div><div>+ }</div><div>+</div><div> /* clear progress report */</div><div> if (cliopt.bProgress)</div><div> fprintf(stderr, "%*s\r", 80, " ");</div><div>diff -r b748ee9f4465 -r e50f803e26fb source/x265.h</div><div>--- a/source/x265.h<span style="white-space:pre-wrap"> </span>Fri Sep 28 10:45:23 2018 +0530</div><div>+++ b/source/x265.h<span style="white-space:pre-wrap"> </span>Thu Sep 27 14:16:15 2018 +0530</div><div>@@ -81,6 +81,7 @@</div><div> NAL_UNIT_FILLER_DATA,</div><div> NAL_UNIT_PREFIX_SEI,</div><div> NAL_UNIT_SUFFIX_SEI,</div><div>+ NAL_UNIT_UNSPECIFIED = 62,</div><div> NAL_UNIT_INVALID = 64,</div><div> } NalUnitType;</div><div> </div><div>@@ -360,6 +361,12 @@</div><div> x265_sei_payload *payloads;</div><div> } x265_sei;</div><div> </div><div>+typedef struct x265_dolby_vision_rpu</div><div>+{</div><div>+ int payloadSize;</div><div>+ uint8_t* payload;</div><div>+}x265_dolby_vision_rpu;</div><div>+</div><div> /* Used to pass pictures into the encoder, and to get picture data back out of</div><div> * the encoder. The input and output semantics are different */</div><div> typedef struct x265_picture</div><div>@@ -445,6 +452,9 @@</div><div> </div><div> // pts is reordered in the order of encoding.</div><div> int64_t reorderedPts;</div><div>+</div><div>+ //Dolby Vision RPU metadata</div><div>+ x265_dolby_vision_rpu rpu;</div><div> } x265_picture;</div><div> </div><div> typedef enum</div><div>diff -r b748ee9f4465 -r e50f803e26fb source/x265cli.h</div><div>--- a/source/x265cli.h<span style="white-space:pre-wrap"> </span>Fri Sep 28 10:45:23 2018 +0530</div><div>+++ b/source/x265cli.h<span style="white-space:pre-wrap"> </span>Thu Sep 27 14:16:15 2018 +0530</div><div>@@ -306,6 +306,7 @@</div><div> { "atc-sei", required_argument, NULL, 0 },</div><div> { "pic-struct", required_argument, NULL, 0 },</div><div> { "nalu-file", required_argument, NULL, 0 },</div><div>+ { "dolby-vision-rpu", required_argument, NULL, 0 },</div><div> { 0, 0, 0, 0 },</div><div> { 0, 0, 0, 0 },</div><div> { 0, 0, 0, 0 },</div><div>@@ -357,6 +358,8 @@</div><div> H0(" --[no-]dhdr10-opt Insert tone mapping SEI only for IDR frames and when the tone mapping information changes. Default disabled\n");</div><div> #endif</div><div> H0(" --dolby-vision-profile <float|integer> Specifies Dolby Vision profile ID. Currently only profile 5 enabled. Specified as '5' or '50'. Default 0 (disabled).\n");</div><div>+ H0(" --dolby-vision-rpu <filename> File containing Dolby Vision RPU metadata.\n"</div><div>+ " If given, x265's Dolby Vision metadata parser will fill the RPU field of input pictures with the metadata read from the file. Default NULL(disabled).\n");</div><div> H0(" --nalu-file <filename> Text file containing SEI messages in the following format : <POC><space><PREFIX><space><NAL UNIT TYPE>/<SEI TYPE><space><SEI Payload>\n");</div><div> H0("-f/--frames <integer> Maximum number of frames to encode. Default all\n");</div><div> H0(" --seek <integer> First frame to encode\n");</div><div><br></div></div></div>
_______________________________________________<br>
x265-devel mailing list<br>
<a href="mailto:x265-devel@videolan.org" target="_blank">x265-devel@videolan.org</a><br>
<a href="https://mailman.videolan.org/listinfo/x265-devel" rel="noreferrer" target="_blank">https://mailman.videolan.org/listinfo/x265-devel</a><br>
</blockquote></div>