omxil: factorize OMX_FIFO init/destroy
authorThomas Guillem <guillem@archos.com>
Thu, 26 Jun 2014 12:05:58 +0000 (14:05 +0200)
committerMartin Storsjö <martin@martin.st>
Sun, 29 Jun 2014 20:34:56 +0000 (23:34 +0300)
Signed-off-by: Martin Storsjö <martin@martin.st>
modules/codec/omxil/omxil.c
modules/codec/omxil/omxil.h
modules/codec/omxil/omxil_utils.h

index ea3d7e2..f7c52f8 100644 (file)
@@ -854,17 +854,11 @@ static int OpenGeneric( vlc_object_t *p_this, bool b_encode )
     }
     p_sys->b_enc = b_encode;
     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 *);
-    p_sys->in.fifo.pp_last = &p_sys->in.fifo.p_first;
+    OMX_FIFO_INIT (&p_sys->in.fifo, pOutputPortPrivate );
     p_sys->in.b_direct = false;
     p_sys->in.b_flushed = true;
     p_sys->in.p_fmt = &p_dec->fmt_in;
-    vlc_mutex_init (&p_sys->out.fifo.lock);
-    vlc_cond_init (&p_sys->out.fifo.wait);
-    p_sys->out.fifo.offset = offsetof(OMX_BUFFERHEADERTYPE, pInputPortPrivate) / sizeof(void *);
-    p_sys->out.fifo.pp_last = &p_sys->out.fifo.p_first;
+    OMX_FIFO_INIT (&p_sys->out.fifo, pInputPortPrivate );
     p_sys->out.b_direct = false;
     p_sys->out.b_flushed = true;
     p_sys->out.p_fmt = &p_dec->fmt_out;
@@ -1645,10 +1639,9 @@ static void CloseGeneric( vlc_object_t *p_this )
     DeinitOmxCore();
 
     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);
-    vlc_cond_destroy (&p_sys->out.fifo.wait);
+
+    OMX_FIFO_DESTROY( &p_sys->in.fifo );
+    OMX_FIFO_DESTROY( &p_sys->out.fifo );
 
     free( p_sys );
 }
index 1d6ea76..6cb7abf 100644 (file)
 /*****************************************************************************
  * decoder_sys_t : omxil decoder descriptor
  *****************************************************************************/
+typedef struct OmxFifo
+{
+    vlc_mutex_t lock;
+    vlc_cond_t  wait;
+
+    OMX_BUFFERHEADERTYPE *p_first;
+    OMX_BUFFERHEADERTYPE **pp_last;
+
+    int offset;
+
+} OmxFifo;
+
 typedef struct OmxPort
 {
     bool b_valid;
@@ -54,17 +66,7 @@ typedef struct OmxPort
     unsigned int i_buffers;
     OMX_BUFFERHEADERTYPE **pp_buffers;
 
-    struct fifo_t
-    {
-      vlc_mutex_t         lock;
-      vlc_cond_t          wait;
-
-      OMX_BUFFERHEADERTYPE *p_first;
-      OMX_BUFFERHEADERTYPE **pp_last;
-
-      int offset;
-
-    } fifo;
+    OmxFifo fifo;
 
     OmxFormatParam format_param;
 
index 943e836..a1d564b 100644 (file)
@@ -80,6 +80,16 @@ static inline OMX_TICKS ToOmxTicks(int64_t value)
 /*****************************************************************************
  * OMX buffer FIFO macros
  *****************************************************************************/
+#define OMX_FIFO_INIT(p_fifo, next) \
+    do { vlc_mutex_init( &(p_fifo)->lock ); \
+         vlc_cond_init( &(p_fifo)->wait ); \
+         (p_fifo)->offset = offsetof(OMX_BUFFERHEADERTYPE, next) / sizeof(void *); \
+         (p_fifo)->pp_last = &(p_fifo)->p_first; } while(0)
+
+#define OMX_FIFO_DESTROY(p_fifo) \
+    do { vlc_mutex_destroy( &(p_fifo)->lock ); \
+         vlc_cond_destroy (&(p_fifo)->wait); } while(0)
+
 #define OMX_FIFO_PEEK(p_fifo, p_buffer) \
          p_buffer = (p_fifo)->p_first;