khronosfws/openmax_al/src/common/xacommon.c
changeset 25 6f7ceef7b1d1
parent 21 2ed61feeead6
child 53 eabc8c503852
--- a/khronosfws/openmax_al/src/common/xacommon.c	Fri May 28 19:26:28 2010 -0500
+++ b/khronosfws/openmax_al/src/common/xacommon.c	Fri Jun 11 19:59:23 2010 -0500
@@ -1,19 +1,19 @@
 /*
-* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
-* All rights reserved.
-* This component and the accompanying materials are made available
-* under the terms of "Eclipse Public License v1.0"
-* which accompanies this distribution, and is available
-* at the URL "http://www.eclipse.org/legal/epl-v10.html".
-*
-* Initial Contributors:
-* Nokia Corporation - initial contribution.
-*
-* Contributors:
-*
-* Description: 
-*
-*/
+ * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+ * All rights reserved.
+ * This component and the accompanying materials are made available
+ * under the terms of "Eclipse Public License v1.0"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ *
+ * Initial Contributors:
+ * Nokia Corporation - initial contribution.
+ *
+ * Contributors:
+ *
+ * Description: Common Openmax AL utility functions
+ *
+ */
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -27,32 +27,33 @@
  *  compare two XAInterfaceIDs, return true if same
  */
 XAboolean XACommon_EqualIIds(XAInterfaceID idA, XAInterfaceID idB)
-{
+    {
     XAboolean nodeOk;
     XAuint16 nodeIdx;
-    if(idA==idB) return XA_BOOLEAN_TRUE;
-    if(!idA||!idB) return XA_BOOLEAN_FALSE;
-    if( idA->time_low == idB->time_low &&
-        idA->time_mid == idB->time_mid &&
-        idA->time_hi_and_version == idB->time_hi_and_version &&
-        idA->clock_seq == idB->clock_seq)
+    if (idA == idB)
+        return XA_BOOLEAN_TRUE;
+    if (!idA || !idB)
+        return XA_BOOLEAN_FALSE;
+    if (idA->time_low == idB->time_low && idA->time_mid == idB->time_mid
+            && idA->time_hi_and_version == idB->time_hi_and_version
+            && idA->clock_seq == idB->clock_seq)
         {
-            nodeOk = XA_BOOLEAN_TRUE;
-            for(nodeIdx = 0; nodeIdx < sizeof(idA->node); nodeIdx++ )
+        nodeOk = XA_BOOLEAN_TRUE;
+        for (nodeIdx = 0; nodeIdx < sizeof(idA->node); nodeIdx++)
             {
-                if(idA->node[nodeIdx] != idB->node[nodeIdx])
+            if (idA->node[nodeIdx] != idB->node[nodeIdx])
                 {
-                    nodeOk = XA_BOOLEAN_FALSE;
-                    break;
+                nodeOk = XA_BOOLEAN_FALSE;
+                break;
                 }
             }
-            if(nodeOk)
+        if (nodeOk)
             {
-                return XA_BOOLEAN_TRUE;
+            return XA_BOOLEAN_TRUE;
             }
         }
     return XA_BOOLEAN_FALSE;
-}
+    }
 
 /* Check source availability and content type. Return error only if we are sure
  * content is not valid, otherwise let adaptation try to identify and use content.
@@ -60,83 +61,82 @@
  * @return Success code
  */
 XAresult XACommon_CheckDataSource(XADataSource* source, XAMediaType* type)
-{
-    XAresult ret=XA_RESULT_SUCCESS;
-    XAchar* fname=NULL;
-    XAchar* mime=NULL;
-    XAboolean isLocal=XA_BOOLEAN_FALSE;
+    {
+    XAresult ret = XA_RESULT_SUCCESS;
+    XAchar* fname = NULL;
+    XAchar* mime = NULL;
+    XAboolean isLocal = XA_BOOLEAN_FALSE;
 
-
-    if(!source || !source->pLocator)
-    {
+    if (!source || !source->pLocator)
+        {
         DEBUG_ERR("Invalid XADataSource structure!!");
         return XA_RESULT_PARAMETER_INVALID;
-    }
+        }
 
     /* check URI availability */
-    if( *(XAuint32*)(source->pLocator) == XA_DATALOCATOR_URI )
-    {
-        fname = (XAchar*)((XADataLocator_URI*)(source->pLocator))->URI;
-        /* check protocol prefix */
-        if(strstr((char*)fname,"://"))
+    if (*(XAuint32*) (source->pLocator) == XA_DATALOCATOR_URI)
         {
-            if(strncmp((char*)fname, "file:///", 8) == 0)
+        fname = (XAchar*) ((XADataLocator_URI*) (source->pLocator))->URI;
+        /* check protocol prefix */
+        if (strstr((char*) fname, "://"))
             {
-                isLocal=XA_BOOLEAN_TRUE;
+            if (strncmp((char*) fname, "file:///", 8) == 0)
+                {
+                isLocal = XA_BOOLEAN_TRUE;
                 fname += 8;
-            }
+                }
             else
-            {   /* add support for other protocols if needed */
-                isLocal=XA_BOOLEAN_FALSE;
+                { /* add support for other protocols if needed */
+                isLocal = XA_BOOLEAN_FALSE;
+                }
+            }
+        else
+            {
+            isLocal = XA_BOOLEAN_TRUE;
+            }
+        if (isLocal)
+            {
+            FILE* file = fopen((char*) fname, "r");
+            if (!file)
+                {
+                DEBUG_INFO_A1("%s not found from filesystem", fname);
+                ret = XA_RESULT_CONTENT_NOT_FOUND;
+                }
+            else
+                {
+                fclose(file);
+                }
             }
         }
-        else
-        {
-            isLocal=XA_BOOLEAN_TRUE;
-        }
-        if(isLocal)
-        {
-            FILE* file=fopen((char*)fname, "r");
-            if(!file)
-            {
-                DEBUG_INFO_A1("%s not found from filesystem", fname);
-                ret = XA_RESULT_CONTENT_NOT_FOUND;
-            }
-            else
-            {
-                fclose(file);
-            }
-        }
-    }
 
     /* check content type */
-    if( type )
-    {
-        if(source->pFormat)
+    if (type)
         {
-            switch( *(XAuint32*)source->pFormat )
+        if (source->pFormat)
             {
+            switch (*(XAuint32*) source->pFormat)
+                {
                 case XA_DATAFORMAT_MIME:
-                {
+                    {
                     /* try to parse mimetype first */
-                    mime = ((XADataFormat_MIME*)(source->pFormat))->mimeType;
-                    if(mime && (strncmp((char*)mime,"audio",5)==0))
-                    {
+                    mime = ((XADataFormat_MIME*) (source->pFormat))->mimeType;
+                    if (mime && (strncmp((char*) mime, "audio", 5) == 0))
+                        {
                         *type = XA_MEDIATYPE_AUDIO;
-                    }
-                    else if(mime && (strncmp((char*)mime,"video",5)==0))
-                    {
+                        }
+                    else if (mime && (strncmp((char*) mime, "video", 5) == 0))
+                        {
                         *type = XA_MEDIATYPE_VIDEO;
-                    }
-                    else if(mime && (strncmp((char*)mime,"image",5)==0))
-                    {
+                        }
+                    else if (mime && (strncmp((char*) mime, "image", 5) == 0))
+                        {
                         *type = XA_MEDIATYPE_IMAGE;
-                    }
+                        }
                     else
-                    {
+                        {
                         /* try to parse containertype next */
-                        switch( ((XADataFormat_MIME*)(source->pFormat))->containerType )
-                        {
+                        switch (((XADataFormat_MIME*) (source->pFormat))->containerType)
+                            {
                             case XA_CONTAINERTYPE_M4A:
                             case XA_CONTAINERTYPE_MP3:
                             case XA_CONTAINERTYPE_WAV:
@@ -177,58 +177,60 @@
                             default:
                                 *type = XA_MEDIATYPE_UNKNOWN;
                                 break;
+                            }
                         }
                     }
-                }
-                break;
+                    break;
 
                 case XA_DATAFORMAT_PCM:
                     *type = XA_MEDIATYPE_AUDIO;
-                break;
+                    break;
 
                 case XA_DATAFORMAT_RAWIMAGE:
                     *type = XA_MEDIATYPE_IMAGE;
-                break;
+                    break;
 
                 default:
                     *type = XA_MEDIATYPE_UNKNOWN;
-                    DEBUG_INFO("Warning: unknown dataformat");
-                break;
+                    DEBUG_INFO("Warning: unknown dataformat")
+                    ;
+                    break;
+                }
             }
-        }
         else
-        {
+            {
             DEBUG_ERR("Warning: no data format set");
             *type = XA_MEDIATYPE_UNKNOWN;
-        }
+            }
 
         /* Expand this list if add new supported media type */
         /* If media type unknow check it from file extension */
-        if(*type == XA_MEDIATYPE_UNKNOWN && fname)
-        {
-            if( (strstr((char*)fname,".wav")) || (strstr((char*)fname,".mid"))
-                || (strstr((char*)fname,".amr")))
+        if (*type == XA_MEDIATYPE_UNKNOWN && fname)
             {
+            if ((strstr((char*) fname, ".wav")) || (strstr((char*) fname,
+                    ".mid")) || (strstr((char*) fname, ".amr")))
+                {
                 *type = XA_MEDIATYPE_AUDIO;
-            }
-            if( (strstr((char*)fname,".avi")) || (strstr((char*)fname,".ogg")) )
-            {
+                }
+            if ((strstr((char*) fname, ".avi")) || (strstr((char*) fname,
+                    ".ogg")))
+                {
 
-            }
-            if(strstr((char*)fname,".jpg"))
-            {
+                }
+            if (strstr((char*) fname, ".jpg"))
+                {
                 *type = XA_MEDIATYPE_IMAGE;
+                }
             }
         }
+    return ret;
     }
-    return ret;
-}
 
 /* Validate XADataSink and XADataSrc object creation parameters.
  * @return Success code
  */
-XAresult XACommon_ValidateDataLocator(XAuint32 pCounter, void* pSnk, ... )
-{
+XAresult XACommon_ValidateDataLocator(XAuint32 pCounter, void* pSnk, ...)
+    {
     va_list argptr;
     XAuint32 counter = 0;
     XADataLocator_URI* uri = NULL;
@@ -240,91 +242,94 @@
     XADataSink* xaSnk = NULL;
     DEBUG_API("->XACommon_ValidateDataLocator");
 
-    xaSnk = (XADataSink*)pSnk;
+    xaSnk = (XADataSink*) pSnk;
 
     /* Initialize variable arguments. */
-    //va_start (argptr, xaSnk); TL: Replaced with:
-  	va_start (argptr, pSnk);    
-    while( counter < pCounter )
-    {
-        if( counter > 0)
+    va_start (argptr, pSnk);
+    while (counter < pCounter)
         {
+        if (counter > 0)
+            {
             /*XADataSink and XADataSrc are equivalent, use XADataSink for both*/
-            xaSnk = va_arg(argptr, XADataSink*);
-        }
+xaSnk            = va_arg(argptr, XADataSink*);
+            }
         if( !xaSnk )
-        {   /*NULL sinks/sources are possible, not checked here*/
+            { /*NULL sinks/sources are possible, not checked here*/
             counter++;
             continue;
-        }
+            }
         else if( !xaSnk->pLocator )
-        {
+            {
             DEBUG_ERR_A1("NULL XADataLocator in parameter %d",(int)counter);
             ret = XA_RESULT_PARAMETER_INVALID;
             va_end(argptr);
-    				DEBUG_API("<-XACommon_ValidateDataLocator");
-    				return ret;
-        }
+            DEBUG_API("<-XACommon_ValidateDataLocator");
+            return ret;
+            }
         switch ( *(XAuint32*)(xaSnk->pLocator) )
-        {
+            {
+            case XA_DEFAULTDEVICEID_AUDIOOUTPUT:
+            DEBUG_INFO("XA_DEFAULTDEVICEID_AUDIOOUTPUT");
+            uri = (XADataLocator_URI*)xaSnk->pLocator;
+            break;
             case XA_DATALOCATOR_URI:
-                DEBUG_INFO("XA_DATALOCATOR_URI");
-                uri = (XADataLocator_URI*)xaSnk->pLocator;
-                if( !uri->URI && !xaSnk->pFormat )
+            DEBUG_INFO("XA_DATALOCATOR_URI");
+            uri = (XADataLocator_URI*)xaSnk->pLocator;
+            if( !uri->URI && !xaSnk->pFormat )
                 {
-                    DEBUG_ERR("Invalid parameter set for uri ");
-                    ret = XA_RESULT_PARAMETER_INVALID;
+                DEBUG_ERR("Invalid parameter set for uri ");
+                ret = XA_RESULT_PARAMETER_INVALID;
                 }
-                break;
+            break;
             case XA_DATALOCATOR_NATIVEDISPLAY:
-                DEBUG_INFO("Sink locator type - XA_DATALOCATOR_NATIVEDISPLAY");
-                display = (XADataLocator_NativeDisplay*)(xaSnk->pLocator);
-                if( !display->hDisplay || !display->hWindow )
+            DEBUG_INFO("Sink locator type - XA_DATALOCATOR_NATIVEDISPLAY");
+            display = (XADataLocator_NativeDisplay*)(xaSnk->pLocator);
+            if( !display->hDisplay || !display->hWindow )
                 {
-                    /*No action at this time*/
-                    DEBUG_INFO("Warning - no display or window handle set");
+                /*No action at this time*/
+                DEBUG_INFO("Warning - no display or window handle set");
                 }
-                break;
+            break;
             case XA_DATALOCATOR_OUTPUTMIX:
-                DEBUG_INFO("Sink locator type - XA_DATALOCATOR_OUTPUTMIX");
+            DEBUG_INFO("Sink locator type - XA_DATALOCATOR_OUTPUTMIX");
                 {
-                    omix = (XADataLocator_OutputMix*)(xaSnk->pLocator);
-                    if ( !omix->outputMix )
+                omix = (XADataLocator_OutputMix*)(xaSnk->pLocator);
+                if ( !omix->outputMix )
                     {
-                        DEBUG_ERR("Invalid parameter set for outputmix");
-                        ret = XA_RESULT_PARAMETER_INVALID;
+                    DEBUG_ERR("Invalid parameter set for outputmix");
+                    ret = XA_RESULT_PARAMETER_INVALID;
                     }
                 }
-                break;
+            break;
             case XA_DATALOCATOR_ADDRESS:
-                DEBUG_INFO("XA_DATALOCATOR_ADDRESS");
-                address = (XADataLocator_Address*)(xaSnk->pLocator);
-                if( !address->pAddress && !xaSnk->pFormat )
+            DEBUG_INFO("XA_DATALOCATOR_ADDRESS");
+            address = (XADataLocator_Address*)(xaSnk->pLocator);
+            if( !address->pAddress && !xaSnk->pFormat )
                 {
-                    DEBUG_ERR("Invalid parameter set for address");
-                    ret = XA_RESULT_PARAMETER_INVALID;
+                DEBUG_ERR("Invalid parameter set for address");
+                ret = XA_RESULT_PARAMETER_INVALID;
                 }
-                break;
+            break;
             case XA_DATALOCATOR_IODEVICE:
-                DEBUG_INFO("XA_DATALOCATOR_IODEVICE");
-                iodevice = (XADataLocator_IODevice*)(xaSnk->pLocator);
-                if( iodevice->device )
+            DEBUG_INFO("XA_DATALOCATOR_IODEVICE");
+            iodevice = (XADataLocator_IODevice*)(xaSnk->pLocator);
+            if( iodevice->device )
                 {
-                    DEBUG_INFO("Media object as IODevice");
+                DEBUG_INFO("Media object as IODevice");
                 }
-                else
+            else
                 {
-                    DEBUG_INFO("Iodevice id used");
+                DEBUG_INFO("Iodevice id used");
                 }
-                break;
+            break;
             default:
-                DEBUG_ERR("Incorrect data locator for sink.")
-                ret = XA_RESULT_PARAMETER_INVALID;
-                break;
+            DEBUG_ERR("Incorrect data locator for sink.")
+            ret = XA_RESULT_PARAMETER_INVALID;
+            break;
+            }
+        counter ++;
         }
-        counter ++;
-    }
     va_end(argptr);
     DEBUG_API("<-XACommon_ValidateDataLocator");
     return ret;
-}
+    }