[vlc-devel] [PATCH 3/4] omxil: Wait for the right event when deinitializing

Martin Storsjö martin at martin.st
Tue Jan 29 16:55:09 CET 2013


Previously, we checked that the event queue had an OMX_EventCmdComplete
item, but we didn't make sure that it was for the previously issued
OMX_CommandStateSet. In many cases, it was from a OMX_CommandFlush,
which made the code proceed with other deinitialization. If the decoder
hadn't actually transitioned to idle state yet, the buffers weren't
actually ever freed (in the state == OMX_StateIdle block), which lead
to crashes when the handle was freed at the end.

This fixes crashes when finishing playback of wmv3 videos on Galaxy S3.
---
 modules/codec/omxil/omxil.c |   11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/modules/codec/omxil/omxil.c b/modules/codec/omxil/omxil.c
index b36d768..d7eb043 100644
--- a/modules/codec/omxil/omxil.c
+++ b/modules/codec/omxil/omxil.c
@@ -626,8 +626,15 @@ static OMX_ERRORTYPE DeinitialiseComponent(decoder_t *p_dec,
         omx_error = OMX_SendCommand( omx_handle, OMX_CommandStateSet,
                                      OMX_StateIdle, 0 );
         CHECK_ERROR(omx_error, "OMX_CommandStateSet Idle failed (%x)", omx_error );
-        omx_error = WaitForSpecificOmxEvent(p_dec, OMX_EventCmdComplete, 0, 0, 0);
-        CHECK_ERROR(omx_error, "Wait for Idle failed (%x)", omx_error );
+        while (1) {
+            OMX_U32 cmd, state;
+            omx_error = WaitForSpecificOmxEvent(p_dec, OMX_EventCmdComplete, &cmd, &state, 0);
+            CHECK_ERROR(omx_error, "Wait for Idle failed (%x)", omx_error );
+            // The event queue can contain other OMX_EventCmdComplete items,
+            // such as for OMX_CommandFlush
+            if (cmd == OMX_CommandStateSet && state == OMX_StateIdle)
+                break;
+        }
     }
 
     omx_error = OMX_GetState(omx_handle, &state);
-- 
1.7.10.4




More information about the vlc-devel mailing list