<div dir="ltr"><div><div><div><div>OK, that should do it. "i_input_used" is passed recursively.<br><br></div>But I think I just spotted a bug (not introduced by my patch, I hope ?).<br>What happens if OMX_FIFO_GET_TIMEOUT does timeout the next time when i_input_used is != 0 ?<br>
</div>I think DecodeVideo will return and will be called again but with the same p_block and with i_input_used = 0.<br></div>I think we should use something like i_last_input_used in OmxPort struct, in order to save the p_block offset across several calls of DecodeVideo.<br>
<br></div>I you agree, I'll propose an other patch.<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Jul 10, 2014 at 11:53 PM, Thomas Guillem <span dir="ltr"><<a href="mailto:thomas.guillem@gmail.com" target="_blank">thomas.guillem@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">From: Thomas Guillem <<a href="mailto:guillem@archos.com">guillem@archos.com</a>><br>
<br>
---<br>
modules/codec/omxil/omxil.c | 137 ++++++++++++++++++++++++--------------------<br>
1 file changed, 75 insertions(+), 62 deletions(-)<br>
<br>
diff --git a/modules/codec/omxil/omxil.c b/modules/codec/omxil/omxil.c<br>
index 99e6d2a..f67b526 100644<br>
--- a/modules/codec/omxil/omxil.c<br>
+++ b/modules/codec/omxil/omxil.c<br>
@@ -1268,72 +1268,23 @@ error:<br>
<div class=""> return -1;<br>
}<br>
<br>
-/*****************************************************************************<br>
- * DecodeVideo: Called to decode one frame<br>
- *****************************************************************************/<br>
-static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block )<br>
+static int DecodeVideoInput( decoder_t *p_dec, OmxPort *p_port, block_t **pp_block,<br>
</div>+ unsigned int i_input_used, bool *p_reconfig )<br>
<div class=""> {<br>
decoder_sys_t *p_sys = p_dec->p_sys;<br>
- picture_t *p_pic = NULL;<br>
- OMX_ERRORTYPE omx_error;<br>
- unsigned int i;<br>
-<br>
OMX_BUFFERHEADERTYPE *p_header;<br>
- block_t *p_block;<br>
</div>- unsigned int i_input_used = 0;<br>
<div><div class="h5"> struct H264ConvertState convert_state = { 0, 0 };<br>
+ block_t *p_block = *pp_block;<br>
<br>
- if( !pp_block || !*pp_block )<br>
- return NULL;<br>
-<br>
- p_block = *pp_block;<br>
-<br>
- /* Check for errors from codec */<br>
- if(p_sys->b_error)<br>
- {<br>
- msg_Dbg(p_dec, "error during decoding");<br>
- block_Release( p_block );<br>
- return 0;<br>
- }<br>
-<br>
- if( p_block->i_flags & (BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) )<br>
- {<br>
- block_Release( p_block );<br>
- if(!p_sys->in.b_flushed)<br>
- {<br>
- msg_Dbg(p_dec, "flushing");<br>
- OMX_SendCommand( p_sys->omx_handle, OMX_CommandFlush,<br>
- p_sys->in.definition.nPortIndex, 0 );<br>
- }<br>
- p_sys->in.b_flushed = true;<br>
- return NULL;<br>
- }<br>
-<br>
- /* Use the aspect ratio provided by the input (ie read from packetizer).<br>
- * In case the we get aspect ratio info from the decoder (as in the<br>
- * broadcom OMX implementation on RPi), don't let the packetizer values<br>
- * override what the decoder says, if anything - otherwise always update<br>
- * even if it already is set (since it can change within a stream). */<br>
- if((p_dec->fmt_in.video.i_sar_num != 0 && p_dec->fmt_in.video.i_sar_den != 0) &&<br>
- (p_dec->fmt_out.video.i_sar_num == 0 || p_dec->fmt_out.video.i_sar_den == 0 ||<br>
- !p_sys->b_aspect_ratio_handled))<br>
- {<br>
- p_dec->fmt_out.video.i_sar_num = p_dec->fmt_in.video.i_sar_num;<br>
- p_dec->fmt_out.video.i_sar_den = p_dec->fmt_in.video.i_sar_den;<br>
- }<br>
-<br>
- /* Take care of decoded frames first */<br>
- if( DecodeVideoOutput( p_dec, &p_sys->out, &p_pic ) != 0 )<br>
- goto error;<br>
-<br>
-more_input:<br>
/* Send the input buffer to the component */<br>
- OMX_FIFO_GET_TIMEOUT(&p_sys->in.fifo, p_header, 200000);<br>
+ OMX_FIFO_GET_TIMEOUT(&p_port->fifo, p_header, 200000);<br>
<br>
if (p_header && p_header->nFlags & SENTINEL_FLAG) {<br>
free(p_header);<br>
- goto reconfig;<br>
+ *p_reconfig = true;<br>
+ return 0;<br>
}<br>
+ *p_reconfig = false;<br>
<br>
if(p_header)<br>
{<br>
</div></div>@@ -1348,7 +1299,7 @@ more_input:<br>
<div class=""><br>
/* In direct mode we pass the input pointer as is.<br>
* Otherwise we memcopy the data */<br>
- if(p_sys->in.b_direct)<br>
+ if(p_port->b_direct)<br>
{<br>
p_header->pOutputPortPrivate = p_header->pBuffer;<br>
p_header->pBuffer = p_block->p_buffer;<br>
</div>@@ -1383,19 +1334,81 @@ more_input:<br>
<div class=""> msg_Dbg( p_dec, "EmptyThisBuffer %p, %p, %i, %"PRId64, p_header, p_header->pBuffer,<br>
(int)p_header->nFilledLen, FromOmxTicks(p_header->nTimeStamp) );<br>
#endif<br>
- OMX_EmptyThisBuffer(p_sys->omx_handle, p_header);<br>
- p_sys->in.b_flushed = false;<br>
+ OMX_EmptyThisBuffer(p_port->omx_handle, p_header);<br>
+ p_port->b_flushed = false;<br>
if (decode_more)<br>
- goto more_input;<br>
</div>+ return DecodeVideoInput( p_dec, p_port, pp_block, i_input_used,<br>
<div class="">+ p_reconfig );<br>
else<br>
*pp_block = NULL; /* Avoid being fed the same packet again */<br>
}<br>
<br>
+ return 0;<br>
+}<br>
+<br>
+/*****************************************************************************<br>
</div><div class="">+ * DecodeVideo: Called to decode one frame<br>
+ *****************************************************************************/<br>
+static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block )<br>
</div><div class="">+{<br>
+ decoder_sys_t *p_sys = p_dec->p_sys;<br>
+ picture_t *p_pic = NULL;<br>
+ OMX_ERRORTYPE omx_error;<br>
+ unsigned int i;<br>
+ bool b_reconfig;<br>
+ block_t *p_block;<br>
+<br>
+ if( !pp_block || !*pp_block )<br>
+ return NULL;<br>
+<br>
+ p_block = *pp_block;<br>
+<br>
</div><div class="">+ /* Check for errors from codec */<br>
</div>+ if(p_sys->b_error)<br>
+ {<br>
<div class="">+ msg_Dbg(p_dec, "error during decoding");<br>
</div><div class="">+ block_Release( p_block );<br>
+ return 0;<br>
+ }<br>
+<br>
</div><div class="">+ if( p_block->i_flags & (BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) )<br>
</div><div class="">+ {<br>
+ block_Release( p_block );<br>
+ if(!p_sys->in.b_flushed)<br>
+ {<br>
+ msg_Dbg(p_dec, "flushing");<br>
+ OMX_SendCommand( p_sys->omx_handle, OMX_CommandFlush,<br>
+ p_sys->in.definition.nPortIndex, 0 );<br>
+ }<br>
+ p_sys->in.b_flushed = true;<br>
+ return NULL;<br>
+ }<br>
+<br>
</div><div class="">+ /* Use the aspect ratio provided by the input (ie read from packetizer).<br>
+ * In case the we get aspect ratio info from the decoder (as in the<br>
+ * broadcom OMX implementation on RPi), don't let the packetizer values<br>
+ * override what the decoder says, if anything - otherwise always update<br>
+ * even if it already is set (since it can change within a stream). */<br>
+ if((p_dec->fmt_in.video.i_sar_num != 0 && p_dec->fmt_in.video.i_sar_den != 0) &&<br>
+ (p_dec->fmt_out.video.i_sar_num == 0 || p_dec->fmt_out.video.i_sar_den == 0 ||<br>
</div>+ !p_sys->b_aspect_ratio_handled))<br>
+ {<br>
<div class="">+ p_dec->fmt_out.video.i_sar_num = p_dec->fmt_in.video.i_sar_num;<br>
+ p_dec->fmt_out.video.i_sar_den = p_dec->fmt_in.video.i_sar_den;<br>
+ }<br>
+<br>
+ /* Take care of decoded frames first */<br>
+ if( DecodeVideoOutput( p_dec, &p_sys->out, &p_pic ) != 0 )<br>
</div>+ goto error;<br>
+<br>
+ if( DecodeVideoInput( p_dec, &p_sys->in, pp_block, 0, &b_reconfig ) != 0 )<br>
<div class="">+ goto error;<br>
+<br>
/* If we don't have a p_pic from the first try. Try again */<br>
- if( !p_pic && DecodeVideoOutput( p_dec, &p_sys->out, &p_pic ) != 0 )<br>
+ if( !b_reconfig && !p_pic &&<br>
</div><div class="">+ DecodeVideoOutput( p_dec, &p_sys->out, &p_pic ) != 0 )<br>
</div><div class=""> goto error;<br>
<br>
-reconfig:<br>
/* Handle the PortSettingsChanged events */<br>
for(i = 0; i < p_sys->ports; i++)<br>
{<br>
--<br>
</div>2.0.0.rc2<br>
<br>
</blockquote></div><br></div>