[vlc-devel] [PATCH 11/21] Convert omxil.c to C++

Martin Storsjö martin at martin.st
Mon Sep 5 14:31:15 CEST 2011


This is necessary for using IOMX, which is a C++ API.
---
 modules/codec/omxil/Modules.am             |    2 +-
 modules/codec/omxil/{omxil.c => omxil.cpp} |   66 ++++++++++++++--------------
 modules/codec/omxil/omxil_utils.h          |    8 +++
 3 files changed, 42 insertions(+), 34 deletions(-)
 rename modules/codec/omxil/{omxil.c => omxil.cpp} (96%)

diff --git a/modules/codec/omxil/Modules.am b/modules/codec/omxil/Modules.am
index b2d447d..5941515 100644
--- a/modules/codec/omxil/Modules.am
+++ b/modules/codec/omxil/Modules.am
@@ -1,3 +1,3 @@
-SOURCES_omxil = omxil.c utils.c omxil.h omxil_utils.h \
+SOURCES_omxil = omxil.cpp utils.c omxil.h omxil_utils.h \
 	OMX_Component.h OMX_Core.h OMX_Image.h OMX_IVCommon.h OMX_Types.h \
         OMX_Audio.h OMX_Index.h OMX_Other.h OMX_Video.h
diff --git a/modules/codec/omxil/omxil.c b/modules/codec/omxil/omxil.cpp
similarity index 96%
rename from modules/codec/omxil/omxil.c
rename to modules/codec/omxil/omxil.cpp
index 5ab0638..3d9655c 100644
--- a/modules/codec/omxil/omxil.c
+++ b/modules/codec/omxil/omxil.cpp
@@ -133,7 +133,7 @@ static int CreateComponentsList(decoder_t *p_dec, const char *psz_role)
         omx_error = p_sys->pf_get_roles_of_component(psz_name, &roles, 0);
         if(omx_error != OMX_ErrorNone || !roles) continue;
 
-        ppsz_roles = malloc(roles * (sizeof(OMX_U8*) + OMX_MAX_STRINGNAME_SIZE));
+        ppsz_roles = (OMX_U8**) malloc(roles * (sizeof(OMX_U8*) + OMX_MAX_STRINGNAME_SIZE));
         if(!ppsz_roles) continue;
 
         for( j = 0; j < roles; j++ )
@@ -650,7 +650,7 @@ static OMX_ERRORTYPE InitialiseComponent(decoder_t *p_dec,
     {
         OmxPort *p_port = &p_sys->p_ports[i];
 
-        p_port->pp_buffers =
+        p_port->pp_buffers = (OMX_BUFFERHEADERTYPE**)
             malloc(p_port->definition.nBufferCountActual *
                    sizeof(OMX_BUFFERHEADERTYPE*));
         if(!p_port->pp_buffers)
@@ -767,7 +767,7 @@ static int OpenGeneric( vlc_object_t *p_this, bool b_encode )
     }
 
     /* Allocate the memory needed to store the decoder's structure */
-    if( ( p_dec->p_sys = p_sys = calloc( 1, sizeof(*p_sys)) ) == NULL )
+    if( ( p_dec->p_sys = p_sys = (decoder_sys_t*) calloc( 1, sizeof(*p_sys)) ) == NULL )
     {
         dll_close(dll_handle);
         return VLC_ENOMEM;
@@ -783,12 +783,12 @@ static int OpenGeneric( vlc_object_t *p_this, bool b_encode )
     }
     p_sys->b_enc = b_encode;
     p_sys->dll_handle = dll_handle;
-    p_sys->pf_init = pf_init;
-    p_sys->pf_deinit = pf_deinit;
-    p_sys->pf_get_handle = pf_get_handle;
-    p_sys->pf_free_handle = pf_free_handle;
-    p_sys->pf_component_enum = pf_component_enum;
-    p_sys->pf_get_roles_of_component = pf_get_roles_of_component;
+    p_sys->pf_init = (OMX_ERRORTYPE(*)()) pf_init;
+    p_sys->pf_deinit = (OMX_ERRORTYPE(*)()) pf_deinit;
+    p_sys->pf_get_handle = (OMX_ERRORTYPE(*)(void**, char*, void*, OMX_CALLBACKTYPE*)) pf_get_handle;
+    p_sys->pf_free_handle = (OMX_ERRORTYPE(*)(void*)) pf_free_handle;
+    p_sys->pf_component_enum = (OMX_ERRORTYPE(*)(char*, OMX_U32, OMX_U32)) pf_component_enum;
+    p_sys->pf_get_roles_of_component = (OMX_ERRORTYPE(*)(char*, OMX_U32*, OMX_U8**)) pf_get_roles_of_component;
     p_sys->pp_last_event = &p_sys->p_events;
     vlc_mutex_init (&p_sys->mutex);
     vlc_cond_init (&p_sys->cond);
@@ -797,15 +797,15 @@ static int OpenGeneric( vlc_object_t *p_this, bool b_encode )
     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;
-    p_sys->in.b_direct = false;
-    p_sys->in.b_flushed = true;
+    p_sys->in.b_direct = OMX_FALSE;
+    p_sys->in.b_flushed = OMX_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;
-    p_sys->out.b_direct = true;
-    p_sys->out.b_flushed = true;
+    p_sys->out.b_direct = OMX_TRUE;
+    p_sys->out.b_flushed = OMX_TRUE;
     p_sys->out.p_fmt = &p_dec->fmt_out;
     p_sys->ports = 2;
     p_sys->p_ports = &p_sys->in;
@@ -867,7 +867,7 @@ static int OpenGeneric( vlc_object_t *p_this, bool b_encode )
                 omx_error =
                     OMX_UseBuffer( p_sys->omx_handle, &p_port->pp_buffers[j],
                                    p_port->i_port_index, 0,
-                                   p_port->definition.nBufferSize, (void*)1);
+                                   p_port->definition.nBufferSize, (OMX_U8*)1);
             else
                 omx_error =
                     OMX_AllocateBuffer( p_sys->omx_handle, &p_port->pp_buffers[j],
@@ -928,7 +928,7 @@ static int OpenGeneric( vlc_object_t *p_this, bool b_encode )
         else if(p_sys->in.b_direct)
         {
             p_header->pOutputPortPrivate = p_header->pBuffer;
-            p_header->pBuffer = p_dec->fmt_in.p_extra;
+            p_header->pBuffer = (OMX_U8*) p_dec->fmt_in.p_extra;
         }
         else
         {
@@ -1020,7 +1020,7 @@ static OMX_ERRORTYPE PortReconfigure(decoder_t *p_dec, OmxPort *p_port)
 
     if (p_port->definition.nBufferCountActual > p_port->i_buffers) {
         free(p_port->pp_buffers);
-        p_port->pp_buffers = malloc(p_port->definition.nBufferCountActual * sizeof(OMX_BUFFERHEADERTYPE*));
+        p_port->pp_buffers = (OMX_BUFFERHEADERTYPE**) malloc(p_port->definition.nBufferCountActual * sizeof(OMX_BUFFERHEADERTYPE*));
         if(!p_port->pp_buffers)
         {
           omx_error = OMX_ErrorInsufficientResources;
@@ -1034,7 +1034,7 @@ static OMX_ERRORTYPE PortReconfigure(decoder_t *p_dec, OmxPort *p_port)
             omx_error =
                 OMX_UseBuffer( p_sys->omx_handle, &p_port->pp_buffers[i],
                                p_port->i_port_index, 0,
-                               p_port->definition.nBufferSize, (void*)1);
+                               p_port->definition.nBufferSize, (OMX_U8*)1);
         else
             omx_error =
                 OMX_AllocateBuffer( p_sys->omx_handle, &p_port->pp_buffers[i],
@@ -1093,7 +1093,7 @@ static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block )
             OMX_SendCommand( p_sys->omx_handle, OMX_CommandFlush,
                              p_sys->in.definition.nPortIndex, 0 );
         }
-        p_sys->in.b_flushed = true;
+        p_sys->in.b_flushed = OMX_TRUE;
         return NULL;
     }
 
@@ -1105,7 +1105,7 @@ static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block )
 
         if(p_header->nFilledLen)
         {
-            p_pic = p_header->pAppPrivate;
+            p_pic = (picture_t*) p_header->pAppPrivate;
             if(!p_pic)
             {
                 /* We're not in direct rendering mode.
@@ -1194,7 +1194,7 @@ static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block )
                  (int)p_header->nFilledLen );
 #endif
         OMX_EmptyThisBuffer(p_sys->omx_handle, p_header);
-        p_sys->in.b_flushed = false;
+        p_sys->in.b_flushed = OMX_FALSE;
         *pp_block = NULL; /* Avoid being fed the same packet again */
     }
 
@@ -1203,7 +1203,7 @@ static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block )
     {
         OmxPort *p_port = &p_sys->p_ports[i];
         if(!p_port->b_reconfigure) continue;
-        p_port->b_reconfigure = 0;
+        p_port->b_reconfigure = OMX_FALSE;
         omx_error = PortReconfigure(p_dec, p_port);
     }
 
@@ -1244,7 +1244,7 @@ aout_buffer_t *DecodeAudio ( decoder_t *p_dec, block_t **pp_block )
             OMX_SendCommand( p_sys->omx_handle, OMX_CommandFlush,
                              p_sys->in.definition.nPortIndex, 0 );
         }
-        p_sys->in.b_flushed = true;
+        p_sys->in.b_flushed = OMX_TRUE;
         return NULL;
     }
 
@@ -1327,7 +1327,7 @@ aout_buffer_t *DecodeAudio ( decoder_t *p_dec, block_t **pp_block )
                  (int)p_header->nFilledLen );
 #endif
         OMX_EmptyThisBuffer(p_sys->omx_handle, p_header);
-        p_sys->in.b_flushed = false;
+        p_sys->in.b_flushed = OMX_FALSE;
         *pp_block = NULL; /* Avoid being fed the same packet again */
     }
 
@@ -1336,7 +1336,7 @@ aout_buffer_t *DecodeAudio ( decoder_t *p_dec, block_t **pp_block )
     {
         OmxPort *p_port = &p_sys->p_ports[i];
         if(!p_port->b_reconfigure) continue;
-        p_port->b_reconfigure = 0;
+        p_port->b_reconfigure = OMX_FALSE;
         omx_error = PortReconfigure(p_dec, p_port);
     }
 
@@ -1390,7 +1390,7 @@ static block_t *EncodeVideo( encoder_t *p_enc, picture_t *p_pic )
                  (int)p_header->nFilledLen );
 #endif
         OMX_EmptyThisBuffer(p_sys->omx_handle, p_header);
-        p_sys->in.b_flushed = false;
+        p_sys->in.b_flushed = OMX_FALSE;
     }
 
     /* Handle the PortSettingsChanged events */
@@ -1398,7 +1398,7 @@ static block_t *EncodeVideo( encoder_t *p_enc, picture_t *p_pic )
     {
         OmxPort *p_port = &p_sys->p_ports[i];
         if(!p_port->b_reconfigure) continue;
-        p_port->b_reconfigure = 0;
+        p_port->b_reconfigure = OMX_FALSE;
         omx_error = PortReconfigure(p_dec, p_port);
     }
 
@@ -1415,7 +1415,7 @@ static block_t *EncodeVideo( encoder_t *p_enc, picture_t *p_pic )
                 msg_Dbg(p_dec, "received codec config %i", (int)p_header->nFilledLen);
             }
 
-            p_block = p_header->pAppPrivate;
+            p_block = (block_t*) p_header->pAppPrivate;
             if(!p_block)
             {
                 /* We're not in direct rendering mode.
@@ -1477,16 +1477,16 @@ static OMX_ERRORTYPE OmxEventHandler( OMX_HANDLETYPE omx_handle,
     switch (event)
     {
     case OMX_EventCmdComplete:
-        switch ((OMX_STATETYPE)data_1)
+        switch (data_1)
         {
         case OMX_CommandStateSet:
             msg_Dbg( p_dec, "OmxEventHandler (%s, %s, %s)", EventToString(event),
-                     CommandToString(data_1), StateToString(data_2) );
+                     CommandToString((OMX_COMMANDTYPE) data_1), StateToString((OMX_STATETYPE) data_2) );
             break;
 
         default:
             msg_Dbg( p_dec, "OmxEventHandler (%s, %s, %u)", EventToString(event),
-                     CommandToString(data_1), (unsigned int)data_2 );
+                     CommandToString((OMX_COMMANDTYPE) data_1), (unsigned int)data_2 );
             break;
         }
         break;
@@ -1503,7 +1503,7 @@ static OMX_ERRORTYPE OmxEventHandler( OMX_HANDLETYPE omx_handle,
                  (unsigned int)data_1, (unsigned int)data_2 );
         for(i = 0; i < p_sys->ports; i++)
             if(p_sys->p_ports[i].definition.eDir == OMX_DirOutput)
-                p_sys->p_ports[i].b_reconfigure = true;
+                p_sys->p_ports[i].b_reconfigure = OMX_TRUE;
         break;
 
     default:
@@ -1530,7 +1530,7 @@ static OMX_ERRORTYPE OmxEmptyBufferDone( OMX_HANDLETYPE omx_handle,
     if(omx_header->pAppPrivate || omx_header->pOutputPortPrivate)
     {
         block_t *p_block = (block_t *)omx_header->pAppPrivate;
-        omx_header->pBuffer = omx_header->pOutputPortPrivate;
+        omx_header->pBuffer = (OMX_U8*) omx_header->pOutputPortPrivate;
         if(p_block) block_Release(p_block);
         omx_header->pAppPrivate = 0;
     }
@@ -1553,7 +1553,7 @@ static OMX_ERRORTYPE OmxFillBufferDone( OMX_HANDLETYPE omx_handle,
 
     if(omx_header->pInputPortPrivate)
     {
-        omx_header->pBuffer = omx_header->pInputPortPrivate;
+        omx_header->pBuffer = (OMX_U8*) omx_header->pInputPortPrivate;
     }
     OMX_FIFO_PUT(&p_sys->out.fifo, omx_header);
 
diff --git a/modules/codec/omxil/omxil_utils.h b/modules/codec/omxil/omxil_utils.h
index 63c23c3..61e5200 100644
--- a/modules/codec/omxil/omxil_utils.h
+++ b/modules/codec/omxil/omxil_utils.h
@@ -21,6 +21,10 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /*****************************************************************************
  * OMX macros
  *****************************************************************************/
@@ -167,3 +171,7 @@ OMX_ERRORTYPE GetAudioParameters(OMX_HANDLETYPE handle,
     OmxFormatParam *param, OMX_U32 i_port, OMX_AUDIO_CODINGTYPE encoding,
     uint8_t *pi_channels, unsigned int *pi_samplerate,
     unsigned int *pi_bitrate, unsigned int *pi_bps, unsigned int *pi_blocksize);
+
+#ifdef __cplusplus
+}
+#endif
-- 
1.7.2.5




More information about the vlc-devel mailing list