khronosfws/openmax_al/src/common/xacommon.c
branchRCL_3
changeset 45 095bea5f582e
equal deleted inserted replaced
41:a36789189b53 45:095bea5f582e
       
     1 /*
       
     2  * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description: Common Openmax AL utility functions
       
    15  *
       
    16  */
       
    17 
       
    18 #include <stdio.h>
       
    19 #include <stdlib.h>
       
    20 #include <string.h>
       
    21 
       
    22 #include <stdarg.h>
       
    23 #include "openmaxalwrapper.h"
       
    24 #include "xaglobals.h"
       
    25 #include "xaengine.h"
       
    26 /*
       
    27  *  compare two XAInterfaceIDs, return true if same
       
    28  */
       
    29 XAboolean XACommon_EqualIIds(XAInterfaceID idA, XAInterfaceID idB)
       
    30     {
       
    31     XAboolean nodeOk;
       
    32     XAuint16 nodeIdx;
       
    33     if (idA == idB)
       
    34         return XA_BOOLEAN_TRUE;
       
    35     if (!idA || !idB)
       
    36         return XA_BOOLEAN_FALSE;
       
    37     if (idA->time_low == idB->time_low && idA->time_mid == idB->time_mid
       
    38             && idA->time_hi_and_version == idB->time_hi_and_version
       
    39             && idA->clock_seq == idB->clock_seq)
       
    40         {
       
    41         nodeOk = XA_BOOLEAN_TRUE;
       
    42         for (nodeIdx = 0; nodeIdx < sizeof(idA->node); nodeIdx++)
       
    43             {
       
    44             if (idA->node[nodeIdx] != idB->node[nodeIdx])
       
    45                 {
       
    46                 nodeOk = XA_BOOLEAN_FALSE;
       
    47                 break;
       
    48                 }
       
    49             }
       
    50         if (nodeOk)
       
    51             {
       
    52             return XA_BOOLEAN_TRUE;
       
    53             }
       
    54         }
       
    55     return XA_BOOLEAN_FALSE;
       
    56     }
       
    57 
       
    58 /* Check source availability and content type. Return error only if we are sure
       
    59  * content is not valid, otherwise let adaptation try to identify and use content.
       
    60  * @param type: on return, contains content type, if known.
       
    61  * @return Success code
       
    62  */
       
    63 XAresult XACommon_CheckDataSource(XADataSource* source, XAMediaType* type)
       
    64     {
       
    65     XAresult ret = XA_RESULT_SUCCESS;
       
    66     XAchar* fname = NULL;
       
    67     XAchar* mime = NULL;
       
    68     XAboolean isLocal = XA_BOOLEAN_FALSE;
       
    69 
       
    70     if (!source || !source->pLocator)
       
    71         {
       
    72         DEBUG_ERR("Invalid XADataSource structure!!");
       
    73         return XA_RESULT_PARAMETER_INVALID;
       
    74         }
       
    75 
       
    76     /* check URI availability */
       
    77     if (*(XAuint32*) (source->pLocator) == XA_DATALOCATOR_URI)
       
    78         {
       
    79         fname = (XAchar*) ((XADataLocator_URI*) (source->pLocator))->URI;
       
    80         /* check protocol prefix */
       
    81         if (strstr((char*) fname, "://"))
       
    82             {
       
    83             if (strncmp((char*) fname, "file:///", 8) == 0)
       
    84                 {
       
    85                 isLocal = XA_BOOLEAN_TRUE;
       
    86                 fname += 8;
       
    87                 }
       
    88             else
       
    89                 { /* add support for other protocols if needed */
       
    90                 isLocal = XA_BOOLEAN_FALSE;
       
    91                 }
       
    92             }
       
    93         else
       
    94             {
       
    95             isLocal = XA_BOOLEAN_TRUE;
       
    96             }
       
    97         if (isLocal)
       
    98             {
       
    99             FILE* file = fopen((char*) fname, "r");
       
   100             if (!file)
       
   101                 {
       
   102                 DEBUG_INFO_A1("%s not found from filesystem", fname);
       
   103                 ret = XA_RESULT_CONTENT_NOT_FOUND;
       
   104                 }
       
   105             else
       
   106                 {
       
   107                 fclose(file);
       
   108                 }
       
   109             }
       
   110         }
       
   111 
       
   112     /* check content type */
       
   113     if (type)
       
   114         {
       
   115         if (source->pFormat)
       
   116             {
       
   117             switch (*(XAuint32*) source->pFormat)
       
   118                 {
       
   119                 case XA_DATAFORMAT_MIME:
       
   120                     {
       
   121                     /* try to parse mimetype first */
       
   122                     mime = ((XADataFormat_MIME*) (source->pFormat))->mimeType;
       
   123                     if (mime && (strncmp((char*) mime, "audio", 5) == 0))
       
   124                         {
       
   125                         *type = XA_MEDIATYPE_AUDIO;
       
   126                         }
       
   127                     else if (mime && (strncmp((char*) mime, "video", 5) == 0))
       
   128                         {
       
   129                         *type = XA_MEDIATYPE_VIDEO;
       
   130                         }
       
   131                     else if (mime && (strncmp((char*) mime, "image", 5) == 0))
       
   132                         {
       
   133                         *type = XA_MEDIATYPE_IMAGE;
       
   134                         }
       
   135                     else
       
   136                         {
       
   137                         /* try to parse containertype next */
       
   138                         switch (((XADataFormat_MIME*) (source->pFormat))->containerType)
       
   139                             {
       
   140                             case XA_CONTAINERTYPE_M4A:
       
   141                             case XA_CONTAINERTYPE_MP3:
       
   142                             case XA_CONTAINERTYPE_WAV:
       
   143                             case XA_CONTAINERTYPE_XMF_0:
       
   144                             case XA_CONTAINERTYPE_XMF_1:
       
   145                             case XA_CONTAINERTYPE_XMF_2:
       
   146                             case XA_CONTAINERTYPE_XMF_3:
       
   147                             case XA_CONTAINERTYPE_XMF_GENERIC:
       
   148                             case XA_CONTAINERTYPE_AMR:
       
   149                             case XA_CONTAINERTYPE_AAC:
       
   150                             case XA_CONTAINERTYPE_3GA:
       
   151                             case XA_CONTAINERTYPE_DMF:
       
   152                             case XA_CONTAINERTYPE_SMF:
       
   153                             case XA_CONTAINERTYPE_MOBILE_DLS:
       
   154                                 *type = XA_MEDIATYPE_AUDIO;
       
   155                                 break;
       
   156 
       
   157                             case XA_CONTAINERTYPE_ASF:
       
   158                             case XA_CONTAINERTYPE_AVI:
       
   159                             case XA_CONTAINERTYPE_MP4:
       
   160                             case XA_CONTAINERTYPE_MPEG_ES:
       
   161                             case XA_CONTAINERTYPE_MPEG_PS:
       
   162                             case XA_CONTAINERTYPE_MPEG_TS:
       
   163                             case XA_CONTAINERTYPE_QT:
       
   164                             case XA_CONTAINERTYPE_3GPP:
       
   165                             case XA_CONTAINERTYPE_RM:
       
   166                                 *type = XA_MEDIATYPE_VIDEO;
       
   167                                 break;
       
   168 
       
   169                             case XA_CONTAINERTYPE_BMP:
       
   170                             case XA_CONTAINERTYPE_JPG:
       
   171                             case XA_CONTAINERTYPE_JPG2000:
       
   172                                 *type = XA_MEDIATYPE_IMAGE;
       
   173                                 break;
       
   174 
       
   175                             case XA_CONTAINERTYPE_RAW:
       
   176                             case XA_CONTAINERTYPE_UNSPECIFIED:
       
   177                             default:
       
   178                                 *type = XA_MEDIATYPE_UNKNOWN;
       
   179                                 break;
       
   180                             }
       
   181                         }
       
   182                     }
       
   183                     break;
       
   184 
       
   185                 case XA_DATAFORMAT_PCM:
       
   186                     *type = XA_MEDIATYPE_AUDIO;
       
   187                     break;
       
   188 
       
   189                 case XA_DATAFORMAT_RAWIMAGE:
       
   190                     *type = XA_MEDIATYPE_IMAGE;
       
   191                     break;
       
   192 
       
   193                 default:
       
   194                     *type = XA_MEDIATYPE_UNKNOWN;
       
   195                     DEBUG_INFO("Warning: unknown dataformat")
       
   196                     ;
       
   197                     break;
       
   198                 }
       
   199             }
       
   200         else
       
   201             {
       
   202             DEBUG_ERR("Warning: no data format set");
       
   203             *type = XA_MEDIATYPE_UNKNOWN;
       
   204             }
       
   205 
       
   206         /* Expand this list if add new supported media type */
       
   207         /* If media type unknow check it from file extension */
       
   208         if (*type == XA_MEDIATYPE_UNKNOWN && fname)
       
   209             {
       
   210             if ((strstr((char*) fname, ".wav")) || (strstr((char*) fname,
       
   211                     ".mid")) || (strstr((char*) fname, ".amr")))
       
   212                 {
       
   213                 *type = XA_MEDIATYPE_AUDIO;
       
   214                 }
       
   215             if ((strstr((char*) fname, ".avi")) || (strstr((char*) fname,
       
   216                     ".ogg")))
       
   217                 {
       
   218 
       
   219                 }
       
   220             if (strstr((char*) fname, ".jpg"))
       
   221                 {
       
   222                 *type = XA_MEDIATYPE_IMAGE;
       
   223                 }
       
   224             }
       
   225         }
       
   226     return ret;
       
   227     }
       
   228 
       
   229 /* Validate XADataSink and XADataSrc object creation parameters.
       
   230  * @return Success code
       
   231  */
       
   232 XAresult XACommon_ValidateDataLocator(XAuint32 pCounter, void* pSnk, ...)
       
   233     {
       
   234     va_list argptr;
       
   235     XAuint32 counter = 0;
       
   236     XADataLocator_URI* uri = NULL;
       
   237     XADataLocator_NativeDisplay* display = NULL;
       
   238     XADataLocator_OutputMix* omix = NULL;
       
   239     XADataLocator_Address* address = NULL;
       
   240     XADataLocator_IODevice* iodevice = NULL;
       
   241     XAresult ret = XA_RESULT_SUCCESS;
       
   242     XADataSink* xaSnk = NULL;
       
   243     DEBUG_API("->XACommon_ValidateDataLocator");
       
   244 
       
   245     xaSnk = (XADataSink*) pSnk;
       
   246 
       
   247     /* Initialize variable arguments. */
       
   248     va_start (argptr, pSnk);
       
   249     while (counter < pCounter)
       
   250         {
       
   251         if (counter > 0)
       
   252             {
       
   253             /*XADataSink and XADataSrc are equivalent, use XADataSink for both*/
       
   254 xaSnk            = va_arg(argptr, XADataSink*);
       
   255             }
       
   256         if( !xaSnk )
       
   257             { /*NULL sinks/sources are possible, not checked here*/
       
   258             counter++;
       
   259             continue;
       
   260             }
       
   261         else if( !xaSnk->pLocator )
       
   262             {
       
   263             DEBUG_ERR_A1("NULL XADataLocator in parameter %d",(int)counter);
       
   264             ret = XA_RESULT_PARAMETER_INVALID;
       
   265             va_end(argptr);
       
   266             DEBUG_API("<-XACommon_ValidateDataLocator");
       
   267             return ret;
       
   268             }
       
   269         switch ( *(XAuint32*)(xaSnk->pLocator) )
       
   270             {
       
   271             case XA_DEFAULTDEVICEID_AUDIOOUTPUT:
       
   272             DEBUG_INFO("XA_DEFAULTDEVICEID_AUDIOOUTPUT");
       
   273             uri = (XADataLocator_URI*)xaSnk->pLocator;
       
   274             break;
       
   275             case XA_DATALOCATOR_URI:
       
   276             DEBUG_INFO("XA_DATALOCATOR_URI");
       
   277             uri = (XADataLocator_URI*)xaSnk->pLocator;
       
   278             if( !uri->URI && !xaSnk->pFormat )
       
   279                 {
       
   280                 DEBUG_ERR("Invalid parameter set for uri ");
       
   281                 ret = XA_RESULT_PARAMETER_INVALID;
       
   282                 }
       
   283             break;
       
   284             case XA_DATALOCATOR_NATIVEDISPLAY:
       
   285             DEBUG_INFO("Sink locator type - XA_DATALOCATOR_NATIVEDISPLAY");
       
   286             display = (XADataLocator_NativeDisplay*)(xaSnk->pLocator);
       
   287             if( !display->hDisplay || !display->hWindow )
       
   288                 {
       
   289                 /*No action at this time*/
       
   290                 DEBUG_INFO("Warning - no display or window handle set");
       
   291                 }
       
   292             break;
       
   293             case XA_DATALOCATOR_OUTPUTMIX:
       
   294             DEBUG_INFO("Sink locator type - XA_DATALOCATOR_OUTPUTMIX");
       
   295                 {
       
   296                 omix = (XADataLocator_OutputMix*)(xaSnk->pLocator);
       
   297                 if ( !omix->outputMix )
       
   298                     {
       
   299                     DEBUG_ERR("Invalid parameter set for outputmix");
       
   300                     ret = XA_RESULT_PARAMETER_INVALID;
       
   301                     }
       
   302                 }
       
   303             break;
       
   304             case XA_DATALOCATOR_ADDRESS:
       
   305             DEBUG_INFO("XA_DATALOCATOR_ADDRESS");
       
   306             address = (XADataLocator_Address*)(xaSnk->pLocator);
       
   307             if( !address->pAddress && !xaSnk->pFormat )
       
   308                 {
       
   309                 DEBUG_ERR("Invalid parameter set for address");
       
   310                 ret = XA_RESULT_PARAMETER_INVALID;
       
   311                 }
       
   312             break;
       
   313             case XA_DATALOCATOR_IODEVICE:
       
   314             DEBUG_INFO("XA_DATALOCATOR_IODEVICE");
       
   315             iodevice = (XADataLocator_IODevice*)(xaSnk->pLocator);
       
   316             if( iodevice->device )
       
   317                 {
       
   318                 DEBUG_INFO("Media object as IODevice");
       
   319                 }
       
   320             else
       
   321                 {
       
   322                 DEBUG_INFO("Iodevice id used");
       
   323                 }
       
   324             break;
       
   325             default:
       
   326             DEBUG_ERR("Incorrect data locator for sink.")
       
   327             ret = XA_RESULT_PARAMETER_INVALID;
       
   328             break;
       
   329             }
       
   330         counter ++;
       
   331         }
       
   332     va_end(argptr);
       
   333     DEBUG_API("<-XACommon_ValidateDataLocator");
       
   334     return ret;
       
   335     }