[vlc-commits] omxil: Factorize event queue handling to a separate struct

Martin Storsjö git at videolan.org
Mon Mar 18 17:41:14 CET 2013


vlc | branch: master | Martin Storsjö <martin at martin.st> | Mon Mar 11 16:52:18 2013 +0200| [0859ce7fdeca66688f611cd38a95f8d9014fc279] | committer: Martin Storsjö

omxil: Factorize event queue handling to a separate struct

Signed-off-by: Martin Storsjö <martin at martin.st>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=0859ce7fdeca66688f611cd38a95f8d9014fc279
---

 modules/codec/omxil/omxil.c       |   23 ++++++++----------
 modules/codec/omxil/omxil.h       |    6 +----
 modules/codec/omxil/omxil_utils.h |   17 +++++++++++---
 modules/codec/omxil/utils.c       |   47 +++++++++++++++++++++++--------------
 4 files changed, 54 insertions(+), 39 deletions(-)

diff --git a/modules/codec/omxil/omxil.c b/modules/codec/omxil/omxil.c
index 0536cee..e0348a9 100644
--- a/modules/codec/omxil/omxil.c
+++ b/modules/codec/omxil/omxil.c
@@ -501,7 +501,7 @@ static OMX_ERRORTYPE DeinitialiseComponent(decoder_t *p_dec,
         CHECK_ERROR(omx_error, "OMX_CommandStateSet Idle failed (%x)", omx_error );
         while (1) {
             OMX_U32 cmd, state;
-            omx_error = WaitForSpecificOmxEvent(p_dec, OMX_EventCmdComplete, &cmd, &state, 0);
+            omx_error = WaitForSpecificOmxEvent(&p_sys->event_queue, 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
@@ -552,7 +552,7 @@ static OMX_ERRORTYPE DeinitialiseComponent(decoder_t *p_dec,
             }
         }
 
-        omx_error = WaitForSpecificOmxEvent(p_dec, OMX_EventCmdComplete, 0, 0, 0);
+        omx_error = WaitForSpecificOmxEvent(&p_sys->event_queue, OMX_EventCmdComplete, 0, 0, 0);
         CHECK_ERROR(omx_error, "Wait for Loaded failed (%x)", omx_error );
     }
 
@@ -704,7 +704,7 @@ static OMX_ERRORTYPE InitialiseComponent(decoder_t *p_dec,
                                          p_port->i_port_index, NULL);
             CHECK_ERROR(omx_error, "OMX_CommandPortEnable on %i failed (%x)",
                         (int)p_port->i_port_index, omx_error );
-            omx_error = WaitForSpecificOmxEvent(p_dec, OMX_EventCmdComplete, 0, 0, 0);
+            omx_error = WaitForSpecificOmxEvent(&p_sys->event_queue, OMX_EventCmdComplete, 0, 0, 0);
             CHECK_ERROR(omx_error, "Wait for PortEnable on %i failed (%x)",
                         (int)p_port->i_port_index, omx_error );
         }
@@ -789,9 +789,7 @@ static int OpenGeneric( vlc_object_t *p_this, bool b_encode )
         p_dec->fmt_out.i_codec = 0;
     }
     p_sys->b_enc = b_encode;
-    p_sys->pp_last_event = &p_sys->p_events;
-    vlc_mutex_init (&p_sys->mutex);
-    vlc_cond_init (&p_sys->cond);
+    InitOmxEventQueue(&p_sys->event_queue);
     vlc_mutex_init (&p_sys->in.fifo.lock);
     vlc_cond_init (&p_sys->in.fifo.wait);
     p_sys->in.fifo.offset = offsetof(OMX_BUFFERHEADERTYPE, pOutputPortPrivate) / sizeof(void *);
@@ -908,13 +906,13 @@ static int OpenGeneric( vlc_object_t *p_this, bool b_encode )
                     omx_error, (int)p_port->i_port_index, j );
     }
 
-    omx_error = WaitForSpecificOmxEvent(p_dec, OMX_EventCmdComplete, 0, 0, 0);
+    omx_error = WaitForSpecificOmxEvent(&p_sys->event_queue, OMX_EventCmdComplete, 0, 0, 0);
     CHECK_ERROR(omx_error, "Wait for Idle failed (%x)", omx_error );
 
     omx_error = OMX_SendCommand( p_sys->omx_handle, OMX_CommandStateSet,
                                  OMX_StateExecuting, 0);
     CHECK_ERROR(omx_error, "OMX_CommandStateSet Executing failed (%x)", omx_error );
-    omx_error = WaitForSpecificOmxEvent(p_dec, OMX_EventCmdComplete, 0, 0, 0);
+    omx_error = WaitForSpecificOmxEvent(&p_sys->event_queue, OMX_EventCmdComplete, 0, 0, 0);
     CHECK_ERROR(omx_error, "Wait for Executing failed (%x)", omx_error );
 
     /* Send codec configuration data */
@@ -1053,7 +1051,7 @@ static OMX_ERRORTYPE PortReconfigure(decoder_t *p_dec, OmxPort *p_port)
     CHECK_ERROR(omx_error, "OMX_FreeBuffer failed (%x, %i, %i)",
                 omx_error, (int)p_port->i_port_index, i );
 
-    omx_error = WaitForSpecificOmxEvent(p_dec, OMX_EventCmdComplete, 0, 0, 0);
+    omx_error = WaitForSpecificOmxEvent(&p_sys->event_queue, OMX_EventCmdComplete, 0, 0, 0);
     CHECK_ERROR(omx_error, "Wait for PortDisable failed (%x)", omx_error );
 
     /* Get the new port definition */
@@ -1114,7 +1112,7 @@ static OMX_ERRORTYPE PortReconfigure(decoder_t *p_dec, OmxPort *p_port)
     CHECK_ERROR(omx_error, "OMX_UseBuffer failed (%x, %i, %i)",
                 omx_error, (int)p_port->i_port_index, i );
 
-    omx_error = WaitForSpecificOmxEvent(p_dec, OMX_EventCmdComplete, 0, 0, 0);
+    omx_error = WaitForSpecificOmxEvent(&p_sys->event_queue, OMX_EventCmdComplete, 0, 0, 0);
     CHECK_ERROR(omx_error, "Wait for PortEnable failed (%x)", omx_error );
 
     PrintOmx(p_dec, p_sys->omx_handle, p_dec->p_sys->in.i_port_index);
@@ -1543,8 +1541,7 @@ static void CloseGeneric( vlc_object_t *p_this )
 
     DeinitOmxCore();
 
-    vlc_mutex_destroy (&p_sys->mutex);
-    vlc_cond_destroy (&p_sys->cond);
+    DeinitOmxEventQueue(&p_sys->event_queue);
     vlc_mutex_destroy (&p_sys->in.fifo.lock);
     vlc_cond_destroy (&p_sys->in.fifo.wait);
     vlc_mutex_destroy (&p_sys->out.fifo.lock);
@@ -1601,7 +1598,7 @@ static OMX_ERRORTYPE OmxEventHandler( OMX_HANDLETYPE omx_handle,
         break;
     }
 
-    PostOmxEvent(p_dec, event, data_1, data_2, event_data);
+    PostOmxEvent(&p_sys->event_queue, event, data_1, data_2, event_data);
     return OMX_ErrorNone;
 }
 
diff --git a/modules/codec/omxil/omxil.h b/modules/codec/omxil/omxil.h
index aaa1551..999895b 100644
--- a/modules/codec/omxil/omxil.h
+++ b/modules/codec/omxil/omxil.h
@@ -81,11 +81,7 @@ struct decoder_sys_t
     char ppsz_components[MAX_COMPONENTS_LIST_SIZE][OMX_MAX_STRINGNAME_SIZE];
     unsigned int components;
 
-    struct OmxEvent *p_events;
-    struct OmxEvent **pp_last_event;
-
-    vlc_mutex_t mutex;
-    vlc_cond_t cond;
+    OmxEventQueue event_queue;
 
     OmxPort *p_ports;
     unsigned int ports;
diff --git a/modules/codec/omxil/omxil_utils.h b/modules/codec/omxil/omxil_utils.h
index 91be2f0..afe0978 100644
--- a/modules/codec/omxil/omxil_utils.h
+++ b/modules/codec/omxil/omxil_utils.h
@@ -151,11 +151,22 @@ typedef struct OmxEvent
     struct OmxEvent *next;
 } OmxEvent;
 
-OMX_ERRORTYPE PostOmxEvent(decoder_t *p_dec, OMX_EVENTTYPE event,
+typedef struct OmxEventQueue
+{
+    OmxEvent *p_events;
+    OmxEvent **pp_last_event;
+
+    vlc_mutex_t mutex;
+    vlc_cond_t cond;
+} OmxEventQueue;
+
+void InitOmxEventQueue(OmxEventQueue *queue);
+void DeinitOmxEventQueue(OmxEventQueue *queue);
+OMX_ERRORTYPE PostOmxEvent(OmxEventQueue *queue, OMX_EVENTTYPE event,
     OMX_U32 data_1, OMX_U32 data_2, OMX_PTR event_data);
-OMX_ERRORTYPE WaitForOmxEvent(decoder_t *p_dec, OMX_EVENTTYPE *event,
+OMX_ERRORTYPE WaitForOmxEvent(OmxEventQueue *queue, OMX_EVENTTYPE *event,
     OMX_U32 *data_1, OMX_U32 *data_2, OMX_PTR *event_data);
-OMX_ERRORTYPE WaitForSpecificOmxEvent(decoder_t *p_dec,
+OMX_ERRORTYPE WaitForSpecificOmxEvent(OmxEventQueue *queue,
     OMX_EVENTTYPE specific_event, OMX_U32 *data_1, OMX_U32 *data_2,
     OMX_PTR *event_data);
 void PrintOmxEvent(vlc_object_t *p_this, OMX_EVENTTYPE event, OMX_U32 data_1,
diff --git a/modules/codec/omxil/utils.c b/modules/codec/omxil/utils.c
index 1521e6b..4736b7e 100644
--- a/modules/codec/omxil/utils.c
+++ b/modules/codec/omxil/utils.c
@@ -40,10 +40,22 @@
 /*****************************************************************************
  * Events utility functions
  *****************************************************************************/
-OMX_ERRORTYPE PostOmxEvent(decoder_t *p_dec, OMX_EVENTTYPE event,
+void InitOmxEventQueue(OmxEventQueue *queue)
+{
+    queue->pp_last_event = &queue->p_events;
+    vlc_mutex_init(&queue->mutex);
+    vlc_cond_init(&queue->cond);
+}
+
+void DeinitOmxEventQueue(OmxEventQueue *queue)
+{
+    vlc_mutex_destroy(&queue->mutex);
+    vlc_cond_destroy(&queue->cond);
+}
+
+OMX_ERRORTYPE PostOmxEvent(OmxEventQueue *queue, OMX_EVENTTYPE event,
     OMX_U32 data_1, OMX_U32 data_2, OMX_PTR event_data)
 {
-    decoder_sys_t *p_sys = p_dec->p_sys;
     OmxEvent *p_event;
 
     p_event = malloc(sizeof(OmxEvent));
@@ -55,33 +67,32 @@ OMX_ERRORTYPE PostOmxEvent(decoder_t *p_dec, OMX_EVENTTYPE event,
     p_event->event_data = event_data;
     p_event->next = 0;
 
-    vlc_mutex_lock(&p_sys->mutex);
-    *p_sys->pp_last_event = p_event;
-    p_sys->pp_last_event = &p_event->next;
-    vlc_cond_signal(&p_sys->cond);
-    vlc_mutex_unlock(&p_sys->mutex);
+    vlc_mutex_lock(&queue->mutex);
+    *queue->pp_last_event = p_event;
+    queue->pp_last_event = &p_event->next;
+    vlc_cond_signal(&queue->cond);
+    vlc_mutex_unlock(&queue->mutex);
     return OMX_ErrorNone;
 }
 
-OMX_ERRORTYPE WaitForOmxEvent(decoder_t *p_dec, OMX_EVENTTYPE *event,
+OMX_ERRORTYPE WaitForOmxEvent(OmxEventQueue *queue, OMX_EVENTTYPE *event,
     OMX_U32 *data_1, OMX_U32 *data_2, OMX_PTR *event_data)
 {
-    decoder_sys_t *p_sys = p_dec->p_sys;
     OmxEvent *p_event;
 
-    vlc_mutex_lock(&p_sys->mutex);
+    vlc_mutex_lock(&queue->mutex);
 
-    if(!p_sys->p_events)
-        vlc_cond_timedwait(&p_sys->cond, &p_sys->mutex, mdate()+CLOCK_FREQ);
+    if(!queue->p_events)
+        vlc_cond_timedwait(&queue->cond, &queue->mutex, mdate()+CLOCK_FREQ);
 
-    p_event = p_sys->p_events;
+    p_event = queue->p_events;
     if(p_event)
     {
-        p_sys->p_events = p_event->next;
-        if(!p_sys->p_events) p_sys->pp_last_event = &p_sys->p_events;
+        queue->p_events = p_event->next;
+        if(!queue->p_events) queue->pp_last_event = &queue->p_events;
     }
 
-    vlc_mutex_unlock(&p_sys->mutex);
+    vlc_mutex_unlock(&queue->mutex);
 
     if(p_event)
     {
@@ -96,7 +107,7 @@ OMX_ERRORTYPE WaitForOmxEvent(decoder_t *p_dec, OMX_EVENTTYPE *event,
     return OMX_ErrorTimeout;
 }
 
-OMX_ERRORTYPE WaitForSpecificOmxEvent(decoder_t *p_dec,
+OMX_ERRORTYPE WaitForSpecificOmxEvent(OmxEventQueue *queue,
     OMX_EVENTTYPE specific_event, OMX_U32 *data_1, OMX_U32 *data_2,
     OMX_PTR *event_data)
 {
@@ -106,7 +117,7 @@ OMX_ERRORTYPE WaitForSpecificOmxEvent(decoder_t *p_dec,
 
     while(1)
     {
-        status = WaitForOmxEvent(p_dec, &event, data_1, data_2, event_data);
+        status = WaitForOmxEvent(queue, &event, data_1, data_2, event_data);
         if(status != OMX_ErrorNone) return status;
 
         if(event == specific_event) break;



More information about the vlc-commits mailing list