<div dir="ltr"><div>Shall we copy quant offsets into inFrame within Encoder, so we dont need to worry about the user-handled x265_picture instances? Of course, inFrame will need to alloc/delete its own memory. <br><br></div>x264 uses callback free function pointers for all its structures (param, mb_info, quant_offsets) but we've not gone down this route yet (is there a good reason to?). Handling this the above way will keep it consistent with the way x265_picture::planes, analysis data etc are handled currently. <br><div><br><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Aug 5, 2015 at 8:48 PM, Steve Borho <span dir="ltr"><<a href="mailto:steve@borho.org" target="_blank">steve@borho.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On 08/05, <a href="mailto:santhoshini@multicorewareinc.com">santhoshini@multicorewareinc.com</a> wrote:<br>
> # HG changeset patch<br>
> # User Santhoshini Sekar<<a href="mailto:santhoshini@multicorewareinc.com">santhoshini@multicorewareinc.com</a>><br>
> # Date 1438679012 -19800<br>
> # Tue Aug 04 14:33:32 2015 +0530<br>
> # Node ID 14abf498e49b0963fb1c0db19e39aa5de18560a5<br>
> # Parent 3fa7f6838098854de79d3800b2d775dabaf45705<br>
> add API and implementation for Region of Interest(ROI)<br>
><br>
> diff -r 3fa7f6838098 -r 14abf498e49b source/CMakeLists.txt<br>
> --- a/source/CMakeLists.txt Mon Aug 03 14:56:21 2015 -0500<br>
> +++ b/source/CMakeLists.txt Tue Aug 04 14:33:32 2015 +0530<br>
> @@ -30,7 +30,7 @@<br>
> mark_as_advanced(FPROFILE_USE FPROFILE_GENERATE NATIVE_BUILD)<br>
><br>
> # X265_BUILD must be incremented each time the public API is changed<br>
> -set(X265_BUILD 68)<br>
> +set(X265_BUILD 69)<br>
> configure_file("${PROJECT_SOURCE_DIR}/<a href="http://x265.def.in" rel="noreferrer" target="_blank">x265.def.in</a>"<br>
> "${PROJECT_BINARY_DIR}/x265.def")<br>
> configure_file("${PROJECT_SOURCE_DIR}/<a href="http://x265_config.h.in" rel="noreferrer" target="_blank">x265_config.h.in</a>"<br>
> diff -r 3fa7f6838098 -r 14abf498e49b source/common/frame.h<br>
> --- a/source/common/frame.h Mon Aug 03 14:56:21 2015 -0500<br>
> +++ b/source/common/frame.h Tue Aug 04 14:33:32 2015 +0530<br>
> @@ -59,6 +59,8 @@<br>
> bool m_lowresInit; // lowres init complete (pre-analysis)<br>
> bool m_bChromaExtended; // orig chroma planes motion extended for weight analysis<br>
><br>
> + float* m_quantOffsets; // points to quantOffsets in x265_picture<br>
> +<br>
> /* Frame Parallelism - notification between FrameEncoders of available motion reference rows */<br>
> ThreadSafeInteger m_reconRowCount; // count of CTU rows completely reconstructed and extended for motion reference<br>
> volatile uint32_t m_countRefEncoders; // count of FrameEncoder threads monitoring m_reconRowCount<br>
> diff -r 3fa7f6838098 -r 14abf498e49b source/encoder/api.cpp<br>
> --- a/source/encoder/api.cpp Mon Aug 03 14:56:21 2015 -0500<br>
> +++ b/source/encoder/api.cpp Tue Aug 04 14:33:32 2015 +0530<br>
> @@ -281,6 +281,8 @@<br>
><br>
> void x265_picture_free(x265_picture *p)<br>
> {<br>
> + if (p->quantOffsets)<br>
> + X265_FREE(p->quantOffsets);<br>
<br>
</div></div>I'm not sure this is any better. For us to use X265_FREE the user would<br>
need to use X265_ALLOC and we do not make this function public. Plus, a<br>
user might re-use an x265_picture instance, so this would leak buffers.<br>
<br>
I think we still need the user-supplied free function pointer, but we<br>
need to defer calling it until after we're certain the offset buffer is<br>
no longer needed. If it is only read by pre-lookahead, then we can call<br>
the free function as we take the picture off of the lookahead output<br>
queue and pass it to a frame encoder.<br>
<div><div class="h5"><br>
> return x265_free(p);<br>
> }<br>
><br>
> diff -r 3fa7f6838098 -r 14abf498e49b source/encoder/encoder.cpp<br>
> --- a/source/encoder/encoder.cpp Mon Aug 03 14:56:21 2015 -0500<br>
> +++ b/source/encoder/encoder.cpp Tue Aug 04 14:33:32 2015 +0530<br>
> @@ -465,6 +465,7 @@<br>
> inFrame->m_pts = pic_in->pts;<br>
> inFrame->m_forceqp = pic_in->forceqp;<br>
> inFrame->m_param = m_reconfigured ? m_latestParam : m_param;<br>
> + inFrame->m_quantOffsets = pic_in->quantOffsets;<br>
><br>
> if (m_pocLast == 0)<br>
> m_firstPts = inFrame->m_pts;<br>
> diff -r 3fa7f6838098 -r 14abf498e49b source/encoder/slicetype.cpp<br>
> --- a/source/encoder/slicetype.cpp Mon Aug 03 14:56:21 2015 -0500<br>
> +++ b/source/encoder/slicetype.cpp Tue Aug 04 14:33:32 2015 +0530<br>
> @@ -96,6 +96,7 @@<br>
> int maxRow = curFrame->m_fencPic->m_picHeight;<br>
> int blockCount = curFrame->m_lowres.maxBlocksInRow * curFrame->m_lowres.maxBlocksInCol;<br>
><br>
> + float* quantOffsets = curFrame->m_quantOffsets;<br>
> for (int y = 0; y < 3; y++)<br>
> {<br>
> curFrame->m_lowres.wp_ssd[y] = 0;<br>
> @@ -113,10 +114,21 @@<br>
><br>
> if (param->rc.aqMode && param->rc.aqStrength == 0)<br>
> {<br>
> - memset(curFrame->m_lowres.qpCuTreeOffset, 0, cuCount * sizeof(double));<br>
> - memset(curFrame->m_lowres.qpAqOffset, 0, cuCount * sizeof(double));<br>
> - for (int cuxy = 0; cuxy < cuCount; cuxy++)<br>
> - curFrame->m_lowres.invQscaleFactor[cuxy] = 256;<br>
> + if (quantOffsets)<br>
> + {<br>
> + for (int cuxy = 0; cuxy < cuCount; cuxy++)<br>
> + {<br>
> + curFrame->m_lowres.qpCuTreeOffset[cuxy] = curFrame->m_lowres.qpAqOffset[cuxy] = quantOffsets[cuxy];<br>
> + curFrame->m_lowres.invQscaleFactor[cuxy] = x265_exp2fix8(curFrame->m_lowres.qpCuTreeOffset[cuxy]);<br>
> + }<br>
> + }<br>
> + else<br>
> + {<br>
> + memset(curFrame->m_lowres.qpCuTreeOffset, 0, cuCount * sizeof(double));<br>
> + memset(curFrame->m_lowres.qpAqOffset, 0, cuCount * sizeof(double));<br>
> + for (int cuxy = 0; cuxy < cuCount; cuxy++)<br>
> + curFrame->m_lowres.invQscaleFactor[cuxy] = 256;<br>
> + }<br>
> }<br>
><br>
> /* Need variance data for weighted prediction */<br>
> @@ -177,6 +189,8 @@<br>
> uint32_t energy = acEnergyCu(curFrame, blockX, blockY, param->internalCsp);<br>
> qp_adj = strength * (X265_LOG2(X265_MAX(energy, 1)) - (14.427f + 2 * (X265_DEPTH - 8)));<br>
> }<br>
> + if (quantOffsets)<br>
> + qp_adj += quantOffsets[blockXY];<br>
> curFrame->m_lowres.qpAqOffset[blockXY] = qp_adj;<br>
> curFrame->m_lowres.qpCuTreeOffset[blockXY] = qp_adj;<br>
> curFrame->m_lowres.invQscaleFactor[blockXY] = x265_exp2fix8(qp_adj);<br>
> diff -r 3fa7f6838098 -r 14abf498e49b source/x265.h<br>
> --- a/source/x265.h Mon Aug 03 14:56:21 2015 -0500<br>
> +++ b/source/x265.h Tue Aug 04 14:33:32 2015 +0530<br>
> @@ -205,6 +205,13 @@<br>
> * this data structure */<br>
> x265_analysis_data analysisData;<br>
><br>
> + /* An array of quantizer offsets to be applied to this image during encoding.<br>
> + * These are added on top of the decisions made by rateControl.<br>
> + * Adaptive quantization must be enabled to use this feature. These quantizer<br>
> + * offsets should be given for each 16x16 block. Behavior if quant<br>
> + * offsets differ between encoding passes is undefined. */<br>
> + float *quantOffsets;<br>
> +<br>
> /* Frame level statistics */<br>
> x265_frame_stats frameData;<br>
<br>
</div></div>the rest looks ok<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
Steve Borho<br>
</font></span><div class="HOEnZb"><div class="h5">_______________________________________________<br>
x265-devel mailing list<br>
<a href="mailto:x265-devel@videolan.org">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>
</div></div></blockquote></div><br></div>