<html>
<body>
<span class="xfm_480049767"><p>Hi</p><div>I want to realise AVFrames handling with queue.</div><div>My code is</div><div><br/></div><div>int decode(<span>AVCodecContext</span><span style="color: rgb(192, 192, 192);"> </span><span>*</span><span style="color: rgb(128, 0, 0);">codec_ctx, </span><span>AVPacket *packet</span>)</div><div>{</div><div> <span style="color: rgb(128, 0, 128);">AVFrame</span><span style="color: rgb(192, 192, 192);"> </span><span>*</span><span>frame</span><span style="color: rgb(192, 192, 192);"> </span><span>=</span><span style="color: rgb(192, 192, 192);"> </span><span>av_frame_alloc</span><span>();</span></div><pre style="margin-top: 0px; margin-bottom: 0px;"><pre style="margin-top: 0px; margin-bottom: 0px;"><span style="color: rgb(192, 192, 192);"> </span><span style="color: rgb(128, 128, 0);">if</span><span style="color: rgb(192, 192, 192);"> </span>(!frame)</pre><pre style="margin-top: 0px; margin-bottom: 0px;"><span style="color: rgb(192, 192, 192);"> </span><span style="font-family: Arial, sans-serif; color: rgb(128, 128, 0);">return</span><span style="font-family: Arial, sans-serif; color: rgb(192, 192, 192);"> </span><span style="font-family: Arial, sans-serif;">-1;</span><br/></pre><div><br/></div></pre><pre style="margin-top: 0px; margin-bottom: 0px;"><span style="color: #c0c0c0;"> </span><span style="color: #808000;">int</span><span style="color: #c0c0c0;"> </span>got_frame;</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style="color: #c0c0c0;"> </span><span style="color: #808000;">int</span><span style="color: #c0c0c0;"> </span>ret<span style="color: #c0c0c0;"> </span>=<span style="color: #c0c0c0;"> </span>avcodec_decode_video2(codec_ctx,<span style="color: #c0c0c0;"> </span>frame,<span style="color: #c0c0c0;"> </span>&got_frame,<span style="color: #c0c0c0;"> </span>packet);</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><pre style="margin-top: 0px; margin-bottom: 0px;"><span style="font-family: Arial, sans-serif; color: rgb(192, 192, 192);"> </span><span style="font-family: Arial, sans-serif; color: rgb(128, 128, 0);">if</span><span style="font-family: Arial, sans-serif; color: rgb(192, 192, 192);"> </span><span style="font-family: Arial, sans-serif;">(ret >= 0 && </span><span style="font-family: Arial, sans-serif;">got_frame</span><span style="font-family: Arial, sans-serif;">)</span><span style="font-family: Arial, sans-serif; color: rgb(192, 192, 192);"> </span><span style="font-family: Arial, sans-serif;">{</span><br/></pre><pre style="margin-top: 0px; margin-bottom: 0px;"><span style="color: #c0c0c0;"> </span><span style="color: #008000;">/*</span><span style="color: #c0c0c0;"> </span><span style="color: #008000;">Allocate</span><span style="color: #c0c0c0;"> </span><span style="color: #008000;">buffer</span><span style="color: #c0c0c0;"> </span><span style="color: #008000;">references</span><span style="color: #c0c0c0;"> </span><span style="color: #008000;">*/</span></pre><pre style="margin-top: 0px; margin-bottom: 0px;"><span style="color: #c0c0c0;"> </span><span style="color: #808000;">for</span><span style="color: #c0c0c0;"> </span>(<span style="color: #808000;">int</span><span style="color: #c0c0c0;"> </span>i<span style="color: #c0c0c0;"> </span>=<span style="color: #c0c0c0;"> </span><span style="color: #000080;">0</span>;<span style="color: #c0c0c0;"> </span>i<span style="color: #c0c0c0;"> </span><<span style="color: #c0c0c0;"> </span><span style="color: #000080;">3</span>;<span style="color: #c0c0c0;"> </span>i++)<span style="color: #c0c0c0;"> </span>{</pre><pre style="margin-top: 0px; margin-bottom: 0px;"><span style="color: #c0c0c0;"> </span>uint8_t<span style="color: #c0c0c0;"> </span>*data<span style="color: #c0c0c0;"> </span>=<span style="color: #c0c0c0;"> </span>frame->data[i];</pre><pre style="margin-top: 0px; margin-bottom: 0px;"><span style="color: #c0c0c0;"> </span><span style="color: #808000;">int</span><span style="color: #c0c0c0;"> </span>size<span style="color: #c0c0c0;"> </span>=<span style="color: #c0c0c0;"> </span>frame->linesize[i]<span style="color: #c0c0c0;"> </span>*<span style="color: #c0c0c0;"> </span>frame->height;</pre><pre style="margin-top: 0px; margin-bottom: 0px;"><span style="color: #c0c0c0;"> </span>frame->buf[i]<span style="color: #c0c0c0;"> </span>=<span style="color: #c0c0c0;"> </span>av_buffer_create(data,<span style="color: #c0c0c0;"> </span>size,<span style="color: #c0c0c0;"> </span>av_buffer_default_free,<span style="color: #c0c0c0;"> </span><span style="color: #000080;">NULL</span>,<span style="color: #c0c0c0;"> </span><span style="color: #000080;">0</span>);</pre><pre style="margin-top: 0px; margin-bottom: 0px;"> }</pre><pre style="margin-top: 0px; margin-bottom: 0px;"> enqueue(frame);</pre><pre style="margin-top: 0px; margin-bottom: 0px;"><span style="font-family: Arial, sans-serif; color: rgb(192, 192, 192);"> </span><span style="font-family: Arial, sans-serif; color: rgb(128, 128, 0);">return</span><span style="font-family: Arial, sans-serif;"><font color="#c0c0c0"> </font></span><span style="font-family: Arial, sans-serif;">0</span><span style="font-family: Arial, sans-serif;">;</span></pre><pre style="margin-top: 0px; margin-bottom: 0px;"><span style="color: #c0c0c0;"> </span>}</pre><pre style="margin-top: 0px; margin-bottom: 0px;"><span style="font-family: Arial, sans-serif; color: rgb(192, 192, 192);"><br/></span></pre><pre style="margin-top: 0px; margin-bottom: 0px;"><span style="color: rgb(192, 192, 192);"> </span>av_frame_free(&frame);</pre><pre style="margin-top: 0px; margin-bottom: 0px;"><span style="font-family: Arial, sans-serif; color: rgb(192, 192, 192);"> </span><span style="font-family: Arial, sans-serif; color: rgb(128, 128, 0);">return</span><span style="font-family: Arial, sans-serif; color: rgb(192, 192, 192);"> </span><span style="font-family: Arial, sans-serif;">-1</span><span style="font-family: Arial, sans-serif;">;</span></pre><pre style="margin-top: 0px; margin-bottom: 0px;"><span style="font-family: Arial, sans-serif;">}</span><br/></pre></pre><div><br/></div><div>void someFunc()</div><div>{</div><div> <span style="color: rgb(128, 0, 128);">AVFrame</span><span style="color: rgb(192, 192, 192);"> </span><span>*</span><span>frame</span><span style="color: rgb(192, 192, 192);"> </span><span>=</span><span style="color: rgb(192, 192, 192);"> </span><span>dequeue</span><span>();</span></div><div><span><br/></span></div><div><span> ....</span></div><pre style="margin-top: 0px; margin-bottom: 0px;"><span style="color: #c0c0c0;"> </span><span style="color: #808000;">if</span><span style="color: #c0c0c0;"> </span>(frame)</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style="color: #c0c0c0;"> </span>av_frame_free(&frame);</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style="font-family: Arial, sans-serif;">}</span><br/></pre><div><br/></div><div>Is it right?</div><div><br/></div><div>Regards,</div><div>Yuriy</div><div><br/></div></span>
<img src="https://mail.ukr.net/api/public/message_read?a=gqm-sNtPHWe1z_ukdZtGWyfkDNIyFsnqU1RLfrTHIxatfCgkhZGM7PUqg7uFZVv2zH14TqHQ_qnPmQJ_JraOMDxtlSPvZinI1A==" alt="" width="1" height="1"/> </body>
</html>