khronosfws/openmax_al/src/engine/xaengine.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: Engine Implementation
       
    15  *
       
    16  */
       
    17 
       
    18 #include <stdio.h>
       
    19 #include <stdlib.h>
       
    20 #include <assert.h>
       
    21 
       
    22 #include "xaengine.h"
       
    23 #include "xaobjectitf.h"
       
    24 #include "xaengineitf.h"
       
    25 #include "xathreadsyncitf.h"
       
    26 #include "xadynintmgmtitf.h"
       
    27 #include "xaaudioiodevicecapabilitiesitf.h"
       
    28 #include "xaaudioencodercapabilitiesitf.h"
       
    29 #include "xaconfigextensionsitf.h"
       
    30 #include "xathreadsafety.h"
       
    31 #include "xaframeworkmgr.h"  
       
    32 
       
    33 /* Static mapping of enumeration XAEngineInterfaces to interface iids */
       
    34 static const XAInterfaceID* xaEngineItfIIDs[ENGINE_ITFCOUNT] =
       
    35     {
       
    36     &XA_IID_OBJECT,
       
    37     &XA_IID_ENGINE,
       
    38     &XA_IID_DYNAMICINTERFACEMANAGEMENT,
       
    39     &XA_IID_THREADSYNC,
       
    40     /*    &XA_IID_CONFIGEXTENSION,*/
       
    41     /*    &XA_IID_DEVICEVOLUME,*/
       
    42     &XA_IID_AUDIOIODEVICECAPABILITIES,
       
    43     /*    &XA_IID_AUDIODECODERCAPABILITIES,*/
       
    44     &XA_IID_AUDIOENCODERCAPABILITIES
       
    45     /*
       
    46     &XA_IID_CAMERACAPABILITIES,
       
    47     &XA_IID_IMAGEDECODERCAPABILITIES,
       
    48     &XA_IID_IMAGEENCODERCAPABILITIES,
       
    49     &XA_IID_VIDEODECODERCAPABILITIES,
       
    50     &XA_IID_VIDEOENCODERCAPABILITIES
       
    51      */
       
    52     };
       
    53 
       
    54 /*****************************************************************************
       
    55  * Global methods
       
    56  *****************************************************************************/
       
    57 
       
    58 /* XAResult XAEngineImpl_Create
       
    59  * Description: Create object
       
    60  */
       
    61 XAresult XAEngineImpl_Create(XAObjectItf *pEngine, XAuint32 numOptions,
       
    62         const XAEngineOption *pEngineOptions, XAuint32 numInterfaces,
       
    63         const XAInterfaceID *pInterfaceIds,
       
    64         const XAboolean *pInterfaceRequired)
       
    65     {
       
    66     XAEngineImpl* pImpl = NULL;
       
    67     XAObjectItfImpl* pBaseObj = NULL;
       
    68     XAuint32 itfIndex = 0;
       
    69     //XAboolean optEnabled = XA_BOOLEAN_FALSE;
       
    70     XAboolean threadSafeEnabled = XA_BOOLEAN_TRUE;
       
    71     DEBUG_API("->XAEngineImpl_Create");
       
    72 
       
    73     if (!pEngine)
       
    74         {
       
    75         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
       
    76         DEBUG_API("<-XAEngineImpl_Create");
       
    77         /* invalid parameter */
       
    78         return XA_RESULT_PARAMETER_INVALID;
       
    79         }
       
    80 
       
    81     /* check engine options */
       
    82     if (pEngineOptions && (numOptions != 0))
       
    83         {
       
    84         int i;
       
    85         for (i = 0; i < numOptions; i++)
       
    86             {
       
    87             if (pEngineOptions[i].feature == XA_ENGINEOPTION_LOSSOFCONTROL)
       
    88                 {
       
    89                 //XAboolean optEnabled = pEngineOptions[i].data;
       
    90                 // TODO: do something with the above value or else remove the code
       
    91                 }
       
    92             if (pEngineOptions[i].feature == XA_ENGINEOPTION_THREADSAFE)
       
    93                 {
       
    94                 threadSafeEnabled = pEngineOptions[i].data;
       
    95                 }
       
    96             }
       
    97         }
       
    98 
       
    99     /* instantiate object implementation */
       
   100     pImpl = (XAEngineImpl*) calloc(1, sizeof(XAEngineImpl));
       
   101     if (!pImpl)
       
   102         {
       
   103         DEBUG_ERR("XA_RESULT_MEMORY_FAILURE");
       
   104         DEBUG_API("<-XAEngineImpl_Create");
       
   105         /* memory allocation failed */
       
   106         return XA_RESULT_MEMORY_FAILURE;
       
   107         }
       
   108     pBaseObj = &pImpl->baseObj;
       
   109 
       
   110     /* Initialize base object default implementation */
       
   111     XAObjectItfImpl_Init(pBaseObj, ENGINE_ITFCOUNT, xaEngineItfIIDs,
       
   112             XAEngineImpl_DoRealize, XAEngineImpl_DoResume,
       
   113             XAEngineImpl_FreeResources);
       
   114 
       
   115     /* Mark interfaces that need to be exposed */
       
   116     /* Implicit and mandated interfaces */
       
   117     pBaseObj->interfaceMap[ENGINE_ENGINEITF].required = XA_BOOLEAN_TRUE;
       
   118     pBaseObj->interfaceMap[ENGINE_DIMITF].required = XA_BOOLEAN_TRUE;
       
   119     pBaseObj->interfaceMap[ENGINE_THREADSYNCITF].required = XA_BOOLEAN_TRUE;
       
   120     pBaseObj->interfaceMap[ENGINE_AUDIOIODEVICECAPAITF].required
       
   121             = XA_BOOLEAN_TRUE;
       
   122     pBaseObj->interfaceMap[ENGINE_AUDIOENCODERCAPAITF].required
       
   123             = XA_BOOLEAN_TRUE;
       
   124     /* Explicit interfaces */
       
   125     if ((numInterfaces != 0) && pInterfaceIds && pInterfaceRequired)
       
   126         {
       
   127         /* Check required interfaces */
       
   128         for (itfIndex = 0; itfIndex < numInterfaces; itfIndex++)
       
   129             {
       
   130             /* If mapEntry is null then required interface is not supported.*/
       
   131             XAObjItfMapEntry *entry = XAObjectItfImpl_GetItfEntry(
       
   132                     (XAObjectItf) &(pBaseObj), pInterfaceIds[itfIndex]);
       
   133             if (!entry)
       
   134                 {
       
   135                 if (pInterfaceRequired[itfIndex])
       
   136                     {
       
   137                     /* required interface cannot be accommodated - fail creation */
       
   138                     XAObjectItfImpl_Destroy((XAObjectItf) &(pBaseObj));
       
   139                     DEBUG_ERR("Required interface not found - abort creation!");
       
   140                     DEBUG_API("<-XAEngineImpl_Create");
       
   141                     return XA_RESULT_FEATURE_UNSUPPORTED;
       
   142                     }
       
   143                 else
       
   144                     {
       
   145                     DEBUG_INFO("Requested (not required) interface not found - continue creation");
       
   146                     }
       
   147                 }
       
   148             else
       
   149                 {
       
   150                 entry->required = XA_BOOLEAN_TRUE;
       
   151                 }
       
   152             }
       
   153         }
       
   154 
       
   155     /* Initialize XAEngineImpl variables */
       
   156     if (threadSafeEnabled)
       
   157         {
       
   158         XAresult ret = XA_RESULT_SUCCESS;
       
   159         pImpl->isThreadSafe = threadSafeEnabled;
       
   160         ret = XAThreadSafety_Init(threadSafeEnabled);
       
   161         if (ret != XA_RESULT_SUCCESS)
       
   162             {
       
   163             DEBUG_INFO_A1("Unable to initialize thread safety - ret:%x", ret );
       
   164             }
       
   165         }
       
   166 
       
   167     /* Set ObjectItf to point to newly created object */
       
   168     *pEngine = ((XAObjectItf) &(pBaseObj->self));
       
   169 
       
   170     DEBUG_API("<-XAEngineImpl_Create");
       
   171     return XA_RESULT_SUCCESS;
       
   172     }
       
   173 
       
   174 /* XAResult XAEngineImpl_QueryNumSupportedInterfaces
       
   175  * Description: Statically query number of supported interfaces
       
   176  */
       
   177 XAresult XAEngineImpl_QueryNumSupportedInterfaces(
       
   178         XAuint32 *pNumSupportedInterfaces)
       
   179     {
       
   180     DEBUG_API("->XAEngineImpl_QueryNumSupportedInterfaces");
       
   181     if (pNumSupportedInterfaces)
       
   182         {
       
   183         *pNumSupportedInterfaces = ENGINE_ITFCOUNT;
       
   184         DEBUG_API("<-XAEngineImpl_QueryNumSupportedInterfaces");
       
   185         return XA_RESULT_SUCCESS;
       
   186         }
       
   187     else
       
   188         {
       
   189         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
       
   190         DEBUG_API("<-XAEngineImpl_QueryNumSupportedInterfaces");
       
   191         return XA_RESULT_PARAMETER_INVALID;
       
   192         }
       
   193     }
       
   194 
       
   195 /* XAResult XAEngineImpl_QuerySupportedInterfaces
       
   196  * Description: Statically query supported interfaces
       
   197  */
       
   198 XAresult XAEngineImpl_QuerySupportedInterfaces(XAuint32 index,
       
   199         XAInterfaceID *pInterfaceId)
       
   200     {
       
   201     DEBUG_API("->XAEngineImpl_QuerySupportedInterfaces");
       
   202     if (index >= ENGINE_ITFCOUNT || !pInterfaceId)
       
   203         {
       
   204         if (pInterfaceId)
       
   205             {
       
   206             *pInterfaceId = XA_IID_NULL;
       
   207             }
       
   208         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
       
   209         DEBUG_API("<-XAEngineImpl_QuerySupportedInterfaces");
       
   210         return XA_RESULT_PARAMETER_INVALID;
       
   211         }
       
   212     else
       
   213         {
       
   214         *pInterfaceId = *(xaEngineItfIIDs[index]);
       
   215         DEBUG_API("<-XAEngineImpl_QuerySupportedInterfaces");
       
   216         return XA_RESULT_SUCCESS;
       
   217         }
       
   218     }
       
   219 
       
   220 /*****************************************************************************
       
   221  * base object XAObjectItfImpl methods
       
   222  *****************************************************************************/
       
   223 
       
   224 /* XAresult XAEngineImpl_DoRealize
       
   225  * Description: Realize all implicit and explicitly wanted interfaces.
       
   226  * Create and initialize implementation-specific variables.
       
   227  * Called from base object XAObjectItfImpl
       
   228  */
       
   229 XAresult XAEngineImpl_DoRealize(XAObjectItf self)
       
   230     {
       
   231     XAuint8 itfIdx = 0;
       
   232     XAObjectItfImpl* pObj = (XAObjectItfImpl*) (*self);
       
   233     XAEngineImpl* pObjImpl = (XAEngineImpl*) (pObj);
       
   234     XAresult ret = XA_RESULT_SUCCESS;
       
   235 
       
   236     DEBUG_API("->XAEngineImpl_DoRealize");
       
   237 
       
   238     /* check casting from correct pointer type */
       
   239     if (!pObjImpl || pObj != pObjImpl->baseObj.self)
       
   240         {
       
   241         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
       
   242         DEBUG_API("<-XAEngineImpl_DoRealize");
       
   243         /* invalid parameter */
       
   244         return XA_RESULT_PARAMETER_INVALID;
       
   245         }
       
   246 
       
   247     /* Table containing use-case framework map */
       
   248     pObjImpl->frameworkMap = XAFrameworkMgr_CreateFrameworkMap();
       
   249     if (pObjImpl->frameworkMap == NULL)
       
   250         {
       
   251         DEBUG_ERR("XA_RESULT_MEMORY_FAILURE");
       
   252         DEBUG_API("<-XAEngineImpl_DoRealize");
       
   253         /* memory allocation failed */
       
   254         return XA_RESULT_MEMORY_FAILURE;
       
   255         }
       
   256 
       
   257     /* Create capabilities list */
       
   258     ret = XACapabilitiesMgr_CreateCapabilitieList(pObjImpl->frameworkMap,
       
   259             &(pObjImpl->capabilities));
       
   260     if (ret != XA_RESULT_SUCCESS)
       
   261         {
       
   262         return ret;
       
   263         }
       
   264 
       
   265     /* Realize all implicit and explicitly wanted interfaces */
       
   266     for (itfIdx = 0; itfIdx < ENGINE_ITFCOUNT; itfIdx++)
       
   267         {
       
   268         if (!(pObj->interfaceMap[itfIdx].pItf)
       
   269                 && pObj->interfaceMap[itfIdx].required)
       
   270             {
       
   271             void *pItf = NULL;
       
   272             switch (itfIdx)
       
   273                 {
       
   274                 case ENGINE_ENGINEITF:
       
   275                     pItf = XAEngineItfImpl_Create(pObjImpl->frameworkMap,
       
   276                             pObjImpl->capabilities);
       
   277                     break;
       
   278                 case ENGINE_THREADSYNCITF:
       
   279                     pItf = XAThreadSyncItfImpl_Create();
       
   280                     break;
       
   281                 case ENGINE_DIMITF:
       
   282                     pItf = XADIMItfImpl_Create();
       
   283                     break;
       
   284                 case ENGINE_AUDIOIODEVICECAPAITF:
       
   285                     pItf = XAAudIODevCapaItfImpl_Create(
       
   286                             pObjImpl->capabilities);
       
   287                     break;
       
   288                 case ENGINE_AUDIOENCODERCAPAITF:
       
   289                     pItf = XAAudioEncoderCapabilitiesItfImpl_Create(
       
   290                             pObjImpl->capabilities);
       
   291                     break;
       
   292                 default:
       
   293                     break;
       
   294                 }
       
   295             if (!pItf)
       
   296                 {
       
   297                 DEBUG_ERR("XA_RESULT_MEMORY_FAILURE");
       
   298                 DEBUG_API("<-XAEngineImpl_DoRealize");
       
   299                 /* memory allocation failed */
       
   300                 return XA_RESULT_MEMORY_FAILURE;
       
   301                 }
       
   302             else
       
   303                 {
       
   304                 pObj->interfaceMap[itfIdx].pItf = pItf;
       
   305                 }
       
   306             }
       
   307         }
       
   308 
       
   309     pObj->state = XA_OBJECT_STATE_REALIZED;
       
   310     DEBUG_API("<-XAEngineImpl_DoRealize");
       
   311     return XA_RESULT_SUCCESS;
       
   312     }
       
   313 
       
   314 /* XAresult XAEngineImpl_DoResume
       
   315  * Description: Resume object from suspended state
       
   316  */
       
   317 XAresult XAEngineImpl_DoResume(XAObjectItf self)
       
   318     {
       
   319     DEBUG_API("->XAEngineImpl_DoResume");
       
   320     DEBUG_API("<-XAEngineImpl_DoResume");
       
   321 
       
   322     return XA_RESULT_PRECONDITIONS_VIOLATED;
       
   323     }
       
   324 
       
   325 /* void XAEngineImpl_FreeResources
       
   326  * Description: Free all resources reserved at XA%ExampleObject%Impl_DoRealize()
       
   327  */
       
   328 void XAEngineImpl_FreeResources(XAObjectItf self)
       
   329     {
       
   330     XAObjectItfImpl* pObj = (XAObjectItfImpl*) (*self);
       
   331     XAEngineImpl* pImpl = (XAEngineImpl*) (*self);
       
   332     XAuint8 itfIdx = 0;
       
   333     DEBUG_API("->XAEngineImpl_FreeResources");
       
   334     assert( pObj && pImpl && pObj == pObj->self );
       
   335 
       
   336     /* free all allocated interfaces */
       
   337     for (itfIdx = 0; itfIdx < ENGINE_ITFCOUNT; itfIdx++)
       
   338         {
       
   339         void *pItf = pObj->interfaceMap[itfIdx].pItf;
       
   340         if (pItf)
       
   341             {
       
   342             switch (itfIdx)
       
   343                 {
       
   344                 case ENGINE_ENGINEITF:
       
   345                     XAEngineItfImpl_Free(pItf);
       
   346                     break;
       
   347                 case ENGINE_THREADSYNCITF:
       
   348                     XAThreadSyncItfImpl_Free(pItf);
       
   349                     break;
       
   350                 case ENGINE_DIMITF:
       
   351                     XADIMItfImpl_Free(pItf);
       
   352                     break;
       
   353                 case ENGINE_AUDIOIODEVICECAPAITF:
       
   354                     XAAudIODevCapaItfImpl_Free(pItf);
       
   355                     break;
       
   356                 case ENGINE_AUDIOENCODERCAPAITF:
       
   357                     XAAudioEncoderCapabilitiesItfImpl_Free(pItf);
       
   358                     break;
       
   359                 default:
       
   360                     break;
       
   361                 }
       
   362             pObj->interfaceMap[itfIdx].pItf = NULL;
       
   363             }
       
   364         }
       
   365 
       
   366     /* free all other allocated resources*/
       
   367 
       
   368     /* free framework map */
       
   369     XAFrameworkMgr_DeleteFrameworkMap(&pImpl->frameworkMap);
       
   370 
       
   371     /* free capabilities list */
       
   372     XACapabilitiesMgr_DeleteCapabilitieList(&pImpl->capabilities);
       
   373 
       
   374     XAThreadSafety_Destroy();
       
   375 
       
   376     DEBUG_API("<-XAEngineImpl_FreeResources");
       
   377     return;
       
   378     }
       
   379 
       
   380 /* END OF FILE */