[vlc-devel] [PATCH 13/21] Add IOMX wrapping for the omxil module

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


The separate .cpp files is an ugly hack, but IIRC the reason
was that I had problems getting a special define set for these
source files when built as iomx.

Building with IOMX requires private Android headers from the
Android source tree, namely the frameworks/base and
system/core repositories. This API is not public, has no
ABI guarantees and isn't supported.

Since there are no ABI guarantees, linking to this API might
make the .so fail to load on some devices, so for proper use
it should be in a dynamically loaded module, separate from the
rest of the VLC core and modules.

Since this can lead to crashes on unsupported devices, it should
only be enabled in production on whitelisted device/firmware
combinations that are known to work.
---
 configure.ac                       |   12 +++
 modules/codec/omxil/Modules.am     |    4 +
 modules/codec/omxil/iomx.cpp       |    2 +
 modules/codec/omxil/iomx_utils.cpp |    2 +
 modules/codec/omxil/omxil.cpp      |  148 +++++++++++++++++++++++++++++++++++-
 modules/codec/omxil/omxil.h        |   97 +++++++++++++++++++++++
 modules/codec/omxil/omxil_utils.h  |    4 +-
 modules/codec/omxil/utils.cpp      |   11 ++-
 8 files changed, 272 insertions(+), 8 deletions(-)
 create mode 100644 modules/codec/omxil/iomx.cpp
 create mode 100644 modules/codec/omxil/iomx_utils.cpp

diff --git a/configure.ac b/configure.ac
index a0c29c7..71bc9e7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2382,6 +2382,18 @@ then
 fi
 
 dnl
+dnl iomx codec plugin
+dnl
+AC_ARG_ENABLE(iomx,
+  [  --enable-iomx           iomx codec module (default disabled)])
+if test "${enable_iomx}" = "yes"
+then
+  VLC_ADD_PLUGIN([iomx])
+  VLC_ADD_CXXFLAGS([iomx],[-fno-exceptions -fno-rtti])
+  VLC_ADD_LIBS([iomx], [-lstagefright -lmedia -lutils -lbinder])
+fi
+
+dnl
 dnl CrystalHD codec plugin
 dnl
 AC_ARG_ENABLE(crystalhd,
diff --git a/modules/codec/omxil/Modules.am b/modules/codec/omxil/Modules.am
index a14edd8..4d1e7e1 100644
--- a/modules/codec/omxil/Modules.am
+++ b/modules/codec/omxil/Modules.am
@@ -1,3 +1,7 @@
 SOURCES_omxil = omxil.cpp utils.cpp 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
+
+SOURCES_iomx = iomx.cpp iomx_utils.cpp 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/iomx.cpp b/modules/codec/omxil/iomx.cpp
new file mode 100644
index 0000000..31ff798
--- /dev/null
+++ b/modules/codec/omxil/iomx.cpp
@@ -0,0 +1,2 @@
+#define USE_IOMX
+#include "omxil.cpp"
diff --git a/modules/codec/omxil/iomx_utils.cpp b/modules/codec/omxil/iomx_utils.cpp
new file mode 100644
index 0000000..b660920
--- /dev/null
+++ b/modules/codec/omxil/iomx_utils.cpp
@@ -0,0 +1,2 @@
+#define USE_IOMX
+#include "utils.cpp"
diff --git a/modules/codec/omxil/omxil.cpp b/modules/codec/omxil/omxil.cpp
index 3d9655c..b37b53f 100644
--- a/modules/codec/omxil/omxil.cpp
+++ b/modules/codec/omxil/omxil.cpp
@@ -41,6 +41,10 @@
 
 #include "omxil.h"
 
+#ifdef USE_IOMX
+#include <media/stagefright/OMXClient.h>
+#endif
+
 //#define OMXIL_EXTRA_DEBUG
 
 /*****************************************************************************
@@ -84,6 +88,52 @@ static OMX_ERRORTYPE OmxEmptyBufferDone( OMX_HANDLETYPE, OMX_PTR,
 static OMX_ERRORTYPE OmxFillBufferDone( OMX_HANDLETYPE, OMX_PTR,
                                         OMX_BUFFERHEADERTYPE * );
 
+#ifdef USE_IOMX
+class OMXCodecObserver : public BnOMXObserver {
+public:
+    OMXCodecObserver() {
+        p_dec = NULL;
+    }
+    void set_ptr(decoder_t *p) {
+        p_dec = p;
+    }
+    void onMessage(const omx_message &msg) {
+        if (!p_dec)
+            return;
+        decoder_sys_t *p_sys = p_dec->p_sys;
+        int i;
+        switch (msg.type) {
+        case omx_message::EVENT:
+            OmxEventHandler(p_sys->omx_handle, p_dec, msg.u.event_data.event, msg.u.event_data.data1, msg.u.event_data.data2, NULL);
+            break;
+        case omx_message::EMPTY_BUFFER_DONE:
+            for (i = 0; i < p_sys->in.i_buffers; i++) {
+                if (msg.u.buffer_data.buffer == p_sys->in.pp_buffers[i]->pPlatformPrivate) {
+                    OmxEmptyBufferDone(p_sys->omx_handle, p_dec, p_sys->in.pp_buffers[i]);
+                    break;
+                }
+            }
+            break;
+        case omx_message::FILL_BUFFER_DONE:
+            for (i = 0; i < p_sys->out.i_buffers; i++) {
+                if (msg.u.extended_buffer_data.buffer == p_sys->out.pp_buffers[i]->pPlatformPrivate) {
+                    OMX_BUFFERHEADERTYPE *buffer = p_sys->out.pp_buffers[i];
+                    buffer->nOffset = msg.u.extended_buffer_data.range_offset;
+                    buffer->nFilledLen = msg.u.extended_buffer_data.range_length;
+                    buffer->nFlags = msg.u.extended_buffer_data.flags;
+                    buffer->nTimeStamp = msg.u.extended_buffer_data.timestamp;
+                    OmxFillBufferDone(p_sys->omx_handle, p_dec, buffer);
+                    break;
+                }
+            }
+            break;
+        }
+    }
+private:
+    decoder_t *p_dec;
+};
+#endif
+
 /*****************************************************************************
  * Module descriptor
  *****************************************************************************/
@@ -117,10 +167,42 @@ static int CreateComponentsList(decoder_t *p_dec, const char *psz_role)
     OMX_U32 roles = 0;
     OMX_U8 **ppsz_roles = 0;
     unsigned int i, j, len;
+#ifdef USE_IOMX
+    List<IOMX::ComponentInfo> components;
+#endif
 
     if(!psz_role) goto end;
     len = strlen(psz_role);
 
+#ifdef USE_IOMX
+    IOMX_ptr->listNodes( &components );
+    for( List<IOMX::ComponentInfo>::iterator it = components.begin(); it != components.end(); it++ )
+    {
+        bool b_found = false;
+
+        msg_Dbg(p_dec, "component %s", it->mName.string());
+        for( List<String8>::iterator it2 = it->mRoles.begin(); it2 != it->mRoles.end(); it2++ )
+        {
+            msg_Dbg(p_dec, "  - role: %s", it2->string());
+            if(!strncmp(it2->string(), psz_role, len)) b_found = true;
+        }
+        if( !b_found )
+            continue;
+        if( !strncmp(it->mName.string(), "OMX.PV.", 7) )
+            continue;
+
+        if(p_sys->components >= MAX_COMPONENTS_LIST_SIZE)
+        {
+            msg_Dbg(p_dec, "too many matching components");
+            continue;
+        }
+
+        strncpy(p_sys->ppsz_components[p_sys->components], it->mName.string(),
+                OMX_MAX_STRINGNAME_SIZE-1);
+        p_sys->components++;
+    }
+
+#else
     for( i = 0; ; i++ )
     {
         bool b_found = false;
@@ -163,6 +245,7 @@ static int CreateComponentsList(decoder_t *p_dec, const char *psz_role)
                 OMX_MAX_STRINGNAME_SIZE-1);
         p_sys->components++;
     }
+#endif
 
  end:
     msg_Dbg(p_dec, "found %i matching components for role %s",
@@ -261,6 +344,7 @@ static OMX_ERRORTYPE ImplementationSpecificWorkarounds(decoder_t *p_dec,
 static OMX_ERRORTYPE SetPortDefinition(decoder_t *p_dec, OmxPort *p_port,
                                        es_format_t *p_fmt)
 {
+    decoder_sys_t *p_sys = p_dec->p_sys;
     OMX_PARAM_PORTDEFINITIONTYPE *def = &p_port->definition;
     OMX_ERRORTYPE omx_error;
 
@@ -373,7 +457,7 @@ static OMX_ERRORTYPE SetPortDefinition(decoder_t *p_dec, OmxPort *p_port,
     /* Deal with audio params */
     if(p_fmt->i_cat == AUDIO_ES)
     {
-        omx_error = SetAudioParameters(p_port->omx_handle,
+        omx_error = SetAudioParameters(p_dec, p_port->omx_handle,
                                        &p_port->format_param, def->nPortIndex,
                                        def->format.audio.eEncoding,
                                        p_fmt->audio.i_channels,
@@ -395,6 +479,7 @@ static OMX_ERRORTYPE SetPortDefinition(decoder_t *p_dec, OmxPort *p_port,
 static OMX_ERRORTYPE GetPortDefinition(decoder_t *p_dec, OmxPort *p_port,
                                        es_format_t *p_fmt)
 {
+    decoder_sys_t *p_sys = p_dec->p_sys;
     OMX_PARAM_PORTDEFINITIONTYPE *def = &p_port->definition;
     OMX_ERRORTYPE omx_error;
 
@@ -448,7 +533,7 @@ static OMX_ERRORTYPE GetPortDefinition(decoder_t *p_dec, OmxPort *p_port,
                         (int)def->format.audio.eEncoding );
         }
 
-        omx_error = GetAudioParameters(p_port->omx_handle,
+        omx_error = GetAudioParameters(p_dec, p_port->omx_handle,
                                        &p_port->format_param, def->nPortIndex,
                                        def->format.audio.eEncoding,
                                        &p_fmt->audio.i_channels,
@@ -553,10 +638,19 @@ static OMX_ERRORTYPE DeinitialiseComponent(decoder_t *p_dec,
     for(i = 0; i < p_sys->ports; i++)
     {
         OmxPort *p_port = &p_sys->p_ports[i];
+#ifdef USE_IOMX
+        delete p_port->dealer;
+#endif
         free(p_port->pp_buffers);
         p_port->pp_buffers = 0;
     }
+#ifdef USE_IOMX
+    IOMX_ptr->freeNode( omx_handle );
+    (*p_sys->observer)->set_ptr(NULL);
+    delete p_sys->observer;
+#else
     omx_error = p_sys->pf_free_handle( omx_handle );
+#endif
     return omx_error;
 }
 
@@ -578,6 +672,17 @@ static OMX_ERRORTYPE InitialiseComponent(decoder_t *p_dec,
     OMX_PORT_PARAM_TYPE param;
 
     /* Load component */
+#ifdef USE_IOMX
+    p_sys->observer = new sp<OMXCodecObserver>();
+    *p_sys->observer = new OMXCodecObserver();
+    (*p_sys->observer)->set_ptr(p_dec);
+    status_t ret;
+    if ((ret = IOMX_ptr->allocateNode( psz_component, *p_sys->observer, &omx_handle )) != OK)
+    {
+        msg_Warn( p_dec, "allocateNode(%s) failed (%x)", psz_component, ret );
+        return OMX_ErrorUndefined;
+    }
+#else
     omx_error = p_sys->pf_get_handle( &omx_handle, psz_component,
                                       p_dec, &callbacks );
     if(omx_error != OMX_ErrorNone)
@@ -586,10 +691,14 @@ static OMX_ERRORTYPE InitialiseComponent(decoder_t *p_dec,
                   omx_error, ErrorToString(omx_error) );
         return omx_error;
     }
+#endif
+    p_sys->state = OMX_StateLoaded;
     strncpy(p_sys->psz_component, psz_component, OMX_MAX_STRINGNAME_SIZE-1);
 
+#ifndef USE_IOMX
     OMX_ComponentRoleEnum(omx_handle, psz_role, 0);
     msg_Dbg(p_dec, "loaded component %s of role %s", psz_component, psz_role);
+#endif
     PrintOmx(p_dec, omx_handle, OMX_ALL);
 
     /* Set component role */
@@ -738,6 +847,11 @@ static int OpenGeneric( vlc_object_t *p_this, bool b_encode )
     OMX_BUFFERHEADERTYPE *p_header;
     unsigned int i, j;
 
+#ifdef USE_IOMX
+    OMXClient client;
+    if (client.connect() != OK)
+        return VLC_EGENERIC;
+#else
     /* Load the OMX core */
     for( i = 0; ppsz_dll_list[i]; i++ )
     {
@@ -765,6 +879,7 @@ static int OpenGeneric( vlc_object_t *p_this, bool b_encode )
         dll_close(dll_handle);
         return VLC_EGENERIC;
     }
+#endif
 
     /* Allocate the memory needed to store the decoder's structure */
     if( ( p_dec->p_sys = p_sys = (decoder_sys_t*) calloc( 1, sizeof(*p_sys)) ) == NULL )
@@ -782,6 +897,10 @@ static int OpenGeneric( vlc_object_t *p_this, bool b_encode )
         p_dec->fmt_out.i_codec = 0;
     }
     p_sys->b_enc = b_encode;
+#ifdef USE_IOMX
+    p_sys->iomx = new sp<IOMX>();
+    *p_sys->iomx = client.interface();
+#else
     p_sys->dll_handle = dll_handle;
     p_sys->pf_init = (OMX_ERRORTYPE(*)()) pf_init;
     p_sys->pf_deinit = (OMX_ERRORTYPE(*)()) pf_deinit;
@@ -789,6 +908,7 @@ static int OpenGeneric( vlc_object_t *p_this, bool b_encode )
     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;
+#endif
     p_sys->pp_last_event = &p_sys->p_events;
     vlc_mutex_init (&p_sys->mutex);
     vlc_cond_init (&p_sys->cond);
@@ -813,6 +933,7 @@ static int OpenGeneric( vlc_object_t *p_this, bool b_encode )
     msg_Dbg(p_dec, "fmt in:%4.4s, out: %4.4s", (char *)&p_dec->fmt_in.i_codec,
             (char *)&p_dec->fmt_out.i_codec);
 
+#ifndef USE_IOMX
     /* Initialise the OMX core */
     omx_error = p_sys->pf_init();
     if(omx_error != OMX_ErrorNone)
@@ -822,6 +943,7 @@ static int OpenGeneric( vlc_object_t *p_this, bool b_encode )
         CloseGeneric(p_this);
         return VLC_EGENERIC;
     }
+#endif
     p_sys->b_init = true;
 
     /* Enumerate components and build a list of the one we want to try */
@@ -854,6 +976,12 @@ static int OpenGeneric( vlc_object_t *p_this, bool b_encode )
     {
         OmxPort *p_port = &p_sys->p_ports[i];
 
+#ifdef USE_IOMX
+        p_port->dealer = new sp<MemoryDealer>();
+        /* Overallocate slightly, to compensate for alignment. Overallocation by 32 should be enough with the current MemoryDealer implementation. */
+        *p_port->dealer = new MemoryDealer(p_port->i_buffers * (p_port->definition.nBufferSize + 4096));
+#endif
+
         for(j = 0; j < p_port->i_buffers; j++)
         {
 #if 0
@@ -863,6 +991,9 @@ static int OpenGeneric( vlc_object_t *p_this, bool b_encode )
             p_port->pp_buffers[i] = (void *)ALIGN((uintptr_t)p_buf, p_port->definition.nBufferAlignment);
 #endif
 
+#ifdef USE_IOMX
+            omx_error = iomx_allocate_buffer(IOMX_ptr, p_sys->omx_handle, p_port, &p_port->pp_buffers[j]);
+#else
             if(0 && p_port->b_direct)
                 omx_error =
                     OMX_UseBuffer( p_sys->omx_handle, &p_port->pp_buffers[j],
@@ -873,6 +1004,7 @@ static int OpenGeneric( vlc_object_t *p_this, bool b_encode )
                     OMX_AllocateBuffer( p_sys->omx_handle, &p_port->pp_buffers[j],
                                         p_port->i_port_index, 0,
                                         p_port->definition.nBufferSize);
+#endif
 
             if(omx_error != OMX_ErrorNone) break;
             OMX_FIFO_PUT(&p_port->fifo, p_port->pp_buffers[j]);
@@ -1028,8 +1160,14 @@ static OMX_ERRORTYPE PortReconfigure(decoder_t *p_dec, OmxPort *p_port)
         }
     }
     p_port->i_buffers = p_port->definition.nBufferCountActual;
+#ifdef USE_IOMX
+    *p_port->dealer = new MemoryDealer(p_port->i_buffers * (p_port->definition.nBufferSize + 4096));
+#endif
     for(i = 0; i < p_port->i_buffers; i++)
     {
+#ifdef USE_IOMX
+        omx_error = iomx_allocate_buffer(IOMX_ptr, p_sys->omx_handle, p_port, &p_port->pp_buffers[i]);
+#else
         if(0 && p_port->b_direct)
             omx_error =
                 OMX_UseBuffer( p_sys->omx_handle, &p_port->pp_buffers[i],
@@ -1040,6 +1178,7 @@ static OMX_ERRORTYPE PortReconfigure(decoder_t *p_dec, OmxPort *p_port)
                 OMX_AllocateBuffer( p_sys->omx_handle, &p_port->pp_buffers[i],
                                     p_port->i_port_index, 0,
                                     p_port->definition.nBufferSize);
+#endif
 
         if(omx_error != OMX_ErrorNone) break;
         OMX_FIFO_PUT(&p_port->fifo, p_port->pp_buffers[i]);
@@ -1449,8 +1588,12 @@ static void CloseGeneric( vlc_object_t *p_this )
     decoder_sys_t *p_sys = p_dec->p_sys;
 
     if(p_sys->omx_handle) DeinitialiseComponent(p_dec, p_sys->omx_handle);
+#ifdef USE_IOMX
+    delete p_sys->iomx;
+#else
     if(p_sys->b_init) p_sys->pf_deinit();
     dll_close( p_sys->dll_handle );
+#endif
 
     vlc_mutex_destroy (&p_sys->mutex);
     vlc_cond_destroy (&p_sys->cond);
@@ -1482,6 +1625,7 @@ static OMX_ERRORTYPE OmxEventHandler( OMX_HANDLETYPE omx_handle,
         case OMX_CommandStateSet:
             msg_Dbg( p_dec, "OmxEventHandler (%s, %s, %s)", EventToString(event),
                      CommandToString((OMX_COMMANDTYPE) data_1), StateToString((OMX_STATETYPE) data_2) );
+            p_sys->state = (OMX_STATETYPE) data_2;
             break;
 
         default:
diff --git a/modules/codec/omxil/omxil.h b/modules/codec/omxil/omxil.h
index e4aad8d..6486a33 100644
--- a/modules/codec/omxil/omxil.h
+++ b/modules/codec/omxil/omxil.h
@@ -29,6 +29,15 @@
 #include "OMX_Component.h"
 #include "OMX_Video.h"
 
+#ifdef USE_IOMX
+#include <media/IOMX.h>
+#include <binder/MemoryDealer.h>
+
+using namespace android;
+#define IOMX_ptr (*p_sys->iomx)
+class OMXCodecObserver;
+#endif
+
 #include "omxil_utils.h"
 
 /*****************************************************************************
@@ -72,10 +81,18 @@ typedef struct OmxPort
     OMX_BOOL b_direct;
     OMX_BOOL b_flushed;
 
+#ifdef USE_IOMX
+    sp<MemoryDealer> *dealer;
+#endif
 } OmxPort;
 
 struct decoder_sys_t
 {
+#ifdef USE_IOMX
+    sp<IOMX> *iomx;
+    IOMX::node_id omx_handle;
+    sp<OMXCodecObserver> *observer;
+#else
     void *dll_handle;
     OMX_HANDLETYPE omx_handle;
 
@@ -86,6 +103,8 @@ struct decoder_sys_t
     OMX_ERRORTYPE (*pf_free_handle) (OMX_HANDLETYPE);
     OMX_ERRORTYPE (*pf_component_enum)(OMX_STRING, OMX_U32, OMX_U32);
     OMX_ERRORTYPE (*pf_get_roles_of_component)(OMX_STRING, OMX_U32 *, OMX_U8 **);
+#endif
+    OMX_STATETYPE state;
 
     bool b_enc;
     bool b_init;
@@ -112,3 +131,81 @@ struct decoder_sys_t
 
     int i_nal_size_length; /* Length of the NAL size field for H264 */
 };
+
+#ifdef USE_IOMX
+static inline OMX_ERRORTYPE iomx_set_parameter(sp<IOMX> iomx, IOMX::node_id node, OMX_INDEXTYPE parameter, const void* ptr, int size)
+{
+    status_t ret = iomx->setParameter(node, parameter, ptr, size);
+    if (ret == OK)
+        return OMX_ErrorNone;
+    return OMX_ErrorUndefined;
+}
+static inline OMX_ERRORTYPE iomx_get_parameter(sp<IOMX> iomx, IOMX::node_id node, OMX_INDEXTYPE parameter, void* ptr, int size)
+{
+    status_t ret = iomx->getParameter(node, parameter, ptr, size);
+    if (ret == OK)
+        return OMX_ErrorNone;
+    return OMX_ErrorUndefined;
+}
+static inline OMX_ERRORTYPE iomx_send_command(sp<IOMX> iomx, IOMX::node_id node, OMX_COMMANDTYPE command, OMX_S32 param)
+{
+    status_t ret = iomx->sendCommand(node, command, param);
+    if (ret == OK)
+        return OMX_ErrorNone;
+    return OMX_ErrorUndefined;
+}
+static inline OMX_ERRORTYPE iomx_free_buffer(sp<IOMX> iomx, IOMX::node_id node, OMX_U32 port, OMX_BUFFERHEADERTYPE *buffer)
+{
+    status_t ret = iomx->freeBuffer(node, port, buffer->pPlatformPrivate);
+    free(buffer);
+    if (ret == OK)
+        return OMX_ErrorNone;
+    return OMX_ErrorUndefined;
+}
+static inline OMX_ERRORTYPE iomx_empty_buffer(sp<IOMX> iomx, IOMX::node_id node, OMX_BUFFERHEADERTYPE *buffer)
+{
+    status_t ret = iomx->emptyBuffer(node, buffer->pPlatformPrivate, buffer->nOffset, buffer->nFilledLen, buffer->nFlags, buffer->nTimeStamp);
+    if (ret == OK)
+        return OMX_ErrorNone;
+    return OMX_ErrorUndefined;
+}
+static inline OMX_ERRORTYPE iomx_fill_buffer(sp<IOMX> iomx, IOMX::node_id node, OMX_BUFFERHEADERTYPE *buffer)
+{
+    status_t ret = iomx->fillBuffer(node, buffer->pPlatformPrivate);
+    if (ret == OK)
+        return OMX_ErrorNone;
+    return OMX_ErrorUndefined;
+}
+static inline OMX_ERRORTYPE iomx_get_state(decoder_sys_t *p_sys, OMX_STATETYPE *ptr) {
+    *ptr = p_sys->state;
+    return OMX_ErrorNone;
+}
+static inline OMX_ERRORTYPE iomx_allocate_buffer(sp<IOMX> iomx, IOMX::node_id node, OmxPort *port, OMX_BUFFERHEADERTYPE **bufferptr)
+{
+    sp<IMemory> mem = (*port->dealer)->allocate(port->definition.nBufferSize);
+    IOMX::buffer_id id;
+    int ret = iomx->allocateBufferWithBackup(node, port->i_port_index, mem, &id);
+    if (ret != OK)
+        return OMX_ErrorUndefined;
+    OMX_BUFFERHEADERTYPE *buffer = (OMX_BUFFERHEADERTYPE*) calloc(1, sizeof(OMX_BUFFERHEADERTYPE));
+    *bufferptr = buffer;
+    buffer->pPlatformPrivate = id;
+    buffer->nAllocLen = port->definition.nBufferSize;
+    buffer->pBuffer = (OMX_U8*) mem->pointer();
+    return OMX_ErrorNone;
+}
+#undef OMX_SetParameter
+#define OMX_SetParameter(handle, parameter, value) iomx_set_parameter(IOMX_ptr, handle, parameter, value, sizeof(*(value)))
+#undef OMX_GetParameter
+#define OMX_GetParameter(handle, parameter, value) iomx_get_parameter(IOMX_ptr, handle, parameter, value, sizeof(*(value)))
+#undef OMX_SendCommand
+#define OMX_SendCommand(handle, command, param, pointer) iomx_send_command(IOMX_ptr, handle, command, param)
+#undef OMX_FreeBuffer
+#define OMX_FreeBuffer(handle, port, buffer) iomx_free_buffer(IOMX_ptr, handle, port, buffer)
+#undef OMX_EmptyThisBuffer
+#define OMX_EmptyThisBuffer(handle, buffer) iomx_empty_buffer(IOMX_ptr, handle, buffer)
+#undef OMX_FillThisBuffer
+#define OMX_FillThisBuffer(handle, buffer) iomx_fill_buffer(IOMX_ptr, handle, buffer)
+#undef OMX_GetState
+#define OMX_GetState(handle, ptr) iomx_get_state(p_sys, ptr)
+#endif
diff --git a/modules/codec/omxil/omxil_utils.h b/modules/codec/omxil/omxil_utils.h
index 61e5200..c913907 100644
--- a/modules/codec/omxil/omxil_utils.h
+++ b/modules/codec/omxil/omxil_utils.h
@@ -163,11 +163,11 @@ int GetVlcChromaSizes( vlc_fourcc_t i_fourcc,
 /*****************************************************************************
  * Functions to deal with audio format parameters
  *****************************************************************************/
-OMX_ERRORTYPE SetAudioParameters(OMX_HANDLETYPE handle,
+OMX_ERRORTYPE SetAudioParameters(decoder_t *p_dec, OMX_HANDLETYPE handle,
     OmxFormatParam *param, OMX_U32 i_port, OMX_AUDIO_CODINGTYPE encoding,
     uint8_t i_channels, unsigned int i_samplerate, unsigned int i_bitrate,
     unsigned int i_bps, unsigned int i_blocksize);
-OMX_ERRORTYPE GetAudioParameters(OMX_HANDLETYPE handle,
+OMX_ERRORTYPE GetAudioParameters(decoder_t *p_dec, 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);
diff --git a/modules/codec/omxil/utils.cpp b/modules/codec/omxil/utils.cpp
index 6d6b590..9c47637 100644
--- a/modules/codec/omxil/utils.cpp
+++ b/modules/codec/omxil/utils.cpp
@@ -626,11 +626,12 @@ static unsigned int GetAudioParamSize(OMX_INDEXTYPE index)
   return audio_encoding_param[i].size;
 }
 
-OMX_ERRORTYPE SetAudioParameters(OMX_HANDLETYPE handle,
+OMX_ERRORTYPE SetAudioParameters(decoder_t *p_dec, OMX_HANDLETYPE handle,
     OmxFormatParam *param, OMX_U32 i_port, OMX_AUDIO_CODINGTYPE encoding,
     uint8_t i_channels, unsigned int i_samplerate, unsigned int i_bitrate,
     unsigned int i_bps, unsigned int i_blocksize)
 {
+    decoder_sys_t *p_sys = p_dec->p_sys;
     OMX_INDEXTYPE index;
 
     switch(encoding)
@@ -752,11 +753,12 @@ OMX_ERRORTYPE SetAudioParameters(OMX_HANDLETYPE handle,
     return OMX_SetParameter(handle, index, param);
 }
 
-OMX_ERRORTYPE GetAudioParameters(OMX_HANDLETYPE handle,
+OMX_ERRORTYPE GetAudioParameters(decoder_t *p_dec, 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)
 {
+    decoder_sys_t *p_sys = p_dec->p_sys;
     int i_channels = 0, i_samplerate = 0, i_bitrate = 0;
     int i_bps = 0, i_blocksize = 0;
     OMX_ERRORTYPE omx_error;
@@ -843,6 +845,7 @@ OMX_ERRORTYPE GetAudioParameters(OMX_HANDLETYPE handle,
  *****************************************************************************/
 void PrintOmx(decoder_t *p_dec, OMX_HANDLETYPE omx_handle, OMX_U32 i_port)
 {
+    decoder_sys_t *p_sys = p_dec->p_sys;
     OMX_PARAM_PORTDEFINITIONTYPE definition;
     OMX_PORT_PARAM_TYPE param;
     OMX_ERRORTYPE omx_error;
@@ -883,7 +886,7 @@ void PrintOmx(decoder_t *p_dec, OMX_HANDLETYPE omx_handle, OMX_U32 i_port)
             OMX_INIT_STRUCTURE(u32param);
             u32param.nPortIndex = param.nStartPortNumber + j;
             omx_error = OMX_GetParameter(omx_handle, OMX_IndexParamNumAvailableStreams,
-                                         (OMX_PTR)&u32param);
+                                         &u32param);
 
             msg_Dbg( p_dec, "-> %s %i (%i streams) (%i:%i:%i buffers) (%i,%i) %s",
                      definition.eDir == OMX_DirOutput ? "output" : "input",
@@ -920,7 +923,7 @@ void PrintOmx(decoder_t *p_dec, OMX_HANDLETYPE omx_handle, OMX_U32 i_port)
                 GetVlcAudioFormat_omxil( definition.format.audio.eEncoding,
                                    &i_fourcc, &psz_name );
 
-                GetAudioParameters(omx_handle, &format_param,
+                GetAudioParameters(p_dec, omx_handle, &format_param,
                                    definition.nPortIndex,
                                    definition.format.audio.eEncoding,
                                    &i_channels, &i_samplerate, &i_bitrate,
-- 
1.7.2.5




More information about the vlc-devel mailing list