khronosfws/openmax_al/src/ledarray/xaledarraydevice.c
changeset 12 5a06f39ad45b
child 16 43d09473c595
equal deleted inserted replaced
0:71ca22bcf22a 12:5a06f39ad45b
       
     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: 
       
    15 *
       
    16 */
       
    17 
       
    18 #include <stdio.h>
       
    19 #include <stdlib.h>
       
    20 #include <assert.h>
       
    21 #include "xaledarraydevice.h"
       
    22 #include "xaledarrayitf.h"
       
    23 #include "xaconfigextensionsitf.h"
       
    24 #include "xadynintmgmtitf.h"
       
    25 #include "xathreadsafety.h"
       
    26 
       
    27 
       
    28 /* Static mapping of enumeration XALEDArrayDeviceInterfaces to interface iids */
       
    29 static const XAInterfaceID* XALEDArrayDeviceItfIIDs[LEDARRAY_ITFCOUNT]=
       
    30 {
       
    31     &XA_IID_OBJECT,
       
    32     &XA_IID_LED,
       
    33     &XA_IID_CONFIGEXTENSION,
       
    34     &XA_IID_DYNAMICINTERFACEMANAGEMENT,
       
    35 };
       
    36 
       
    37 
       
    38 /*****************************************************************************
       
    39  * Global methods
       
    40  *****************************************************************************/
       
    41 
       
    42 /* XAResult XALEDArrayDeviceImpl_Create
       
    43  * Description: Create object
       
    44  */
       
    45 XAresult XALEDArrayDeviceImpl_CreateLEDArrayDevice(XAObjectItf* pDevice,
       
    46                                                    XAuint32 deviceID,
       
    47                                                    XAuint32 numInterfaces,
       
    48                                                    const XAInterfaceID * pInterfaceIds,
       
    49                                                    const XAboolean * pInterfaceRequired)
       
    50 {
       
    51 
       
    52     
       
    53     XAuint8 itfIndex = 0;
       
    54 
       
    55     XALEDArrayDeviceImpl* pImpl = NULL;
       
    56     XAObjectItfImpl* pBaseObj = NULL;
       
    57     
       
    58 
       
    59     DEBUG_API("->XALEDArrayDeviceImpl_Create");
       
    60     XA_IMPL_THREAD_SAFETY_ENTRY(XATSLEDArray);
       
    61 
       
    62     if( !pDevice )
       
    63     {
       
    64         /* invalid parameter */
       
    65         XA_IMPL_THREAD_SAFETY_EXIT(XATSLEDArray);
       
    66         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
       
    67         DEBUG_API("<-XALEDArrayDeviceImpl_Create");
       
    68         return XA_RESULT_PARAMETER_INVALID;
       
    69     }
       
    70 
       
    71     /* instantiate object implementation */
       
    72     pImpl = (XALEDArrayDeviceImpl*)calloc(1,sizeof(XALEDArrayDeviceImpl));
       
    73     if( !pImpl )
       
    74     {
       
    75         /* memory allocation failed */
       
    76         XA_IMPL_THREAD_SAFETY_EXIT(XATSLEDArray);
       
    77         DEBUG_ERR("XA_RESULT_MEMORY_FAILURE");
       
    78         DEBUG_API("<-XALEDArrayDeviceImpl_Create");
       
    79         return XA_RESULT_MEMORY_FAILURE;
       
    80     }
       
    81     pBaseObj = &pImpl->baseObj;
       
    82 
       
    83 
       
    84 
       
    85     /* Initialize base object default implementation */
       
    86     XAObjectItfImpl_Init(pBaseObj,
       
    87                          LEDARRAY_ITFCOUNT,
       
    88                          XALEDArrayDeviceItfIIDs,
       
    89                          XALEDArrayDeviceImpl_DoRealize,
       
    90                          XALEDArrayDeviceImpl_DoResume,
       
    91                          XALEDArrayDeviceImpl_FreeResources);
       
    92 
       
    93     /* Mark interfaces that need to be exposed */
       
    94     /* Implicit and mandated interfaces */
       
    95     pBaseObj->interfaceMap[LEDARRAY_LEDARRAYITF].required = XA_BOOLEAN_TRUE;
       
    96     pBaseObj->interfaceMap[LEDARRAY_DIMITF].required = XA_BOOLEAN_TRUE;
       
    97 
       
    98     /* Explicit interfaces */
       
    99     if( (numInterfaces != 0) && pInterfaceIds && pInterfaceRequired )
       
   100     {
       
   101         /* Check required interfaces */
       
   102         for( itfIndex = 0; itfIndex < numInterfaces; itfIndex++ )
       
   103         {
       
   104             /* If mapEntry is null then required interface is not supported.*/
       
   105             XAObjItfMapEntry *entry =
       
   106                 XAObjectItfImpl_GetItfEntry((XAObjectItf)&(pBaseObj), pInterfaceIds[itfIndex]);
       
   107            if( !entry  )
       
   108             {
       
   109                 if( pInterfaceRequired[itfIndex] )
       
   110                 {
       
   111                     /* required interface cannot be accommodated - fail creation */
       
   112                     XAObjectItfImpl_Destroy((XAObjectItf)&(pBaseObj));
       
   113                     XA_IMPL_THREAD_SAFETY_EXIT(XATSLEDArray);
       
   114                     DEBUG_ERR("Required interface not found - abort creation!");
       
   115                     DEBUG_API("<-XALEDArrayDeviceImpl_Create");
       
   116                     return XA_RESULT_FEATURE_UNSUPPORTED;
       
   117                 }
       
   118                 else
       
   119                 {
       
   120                     DEBUG_INFO("Requested (not required) interface not found - continue creation");
       
   121                 }
       
   122             }
       
   123             else
       
   124             {
       
   125                 entry->required = XA_BOOLEAN_TRUE;
       
   126             }
       
   127         }
       
   128     }
       
   129 
       
   130     /* Initialize XALEDArrayDeviceImpl variables */
       
   131     pImpl->deviceID = deviceID;
       
   132 #ifdef _GSTREAMER_BACKEND_  
       
   133     pImpl->adaptationCtx = XALEDArrayAdapt_Create(pImpl->deviceID);
       
   134 #endif
       
   135     
       
   136     /* This code is put here to return Feature Not Supported since adaptation is not present*/
       
   137     /*************************************************/
       
   138     XAObjectItfImpl_Destroy((XAObjectItf)&(pBaseObj));
       
   139     XA_IMPL_THREAD_SAFETY_EXIT(XATSLEDArray);
       
   140     DEBUG_ERR("Required interface not found - abort creation!");
       
   141     DEBUG_API("<-XALEDArrayDeviceImpl_Create");
       
   142     return XA_RESULT_FEATURE_UNSUPPORTED;
       
   143     /*************************************************/
       
   144     
       
   145     /* Set ObjectItf to point to newly created object */
       
   146 /*
       
   147     *pDevice = (XAObjectItf)&(pBaseObj->self);
       
   148     XA_IMPL_THREAD_SAFETY_EXIT(XATSLEDArray);
       
   149     DEBUG_API("<-XALEDArrayDeviceImpl_Create");
       
   150     return XA_RESULT_SUCCESS;
       
   151 */
       
   152 }
       
   153 
       
   154 /* XAResult XALEDArrayDeviceImpl_QueryNumSupportedInterfaces
       
   155  * Description: Statically query number of supported interfaces
       
   156  */
       
   157 XAresult XALEDArrayDeviceImpl_QueryNumSupportedInterfaces( XAuint32 *pNumSupportedInterfaces )
       
   158 {
       
   159     DEBUG_API("->XALEDArrayDeviceImpl_QueryNumSupportedInterfaces");
       
   160     if( pNumSupportedInterfaces )
       
   161     {
       
   162 #ifdef _GSTREAMER_BACKEND_  
       
   163         *pNumSupportedInterfaces = LEDARRAY_ITFCOUNT;
       
   164 #endif
       
   165         DEBUG_API_A1("<-XALEDArrayDeviceImpl_QueryNumSupportedInterfaces - %ld", *pNumSupportedInterfaces );
       
   166         return XA_RESULT_SUCCESS;
       
   167     }
       
   168     else
       
   169     {
       
   170         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
       
   171         DEBUG_API("<-XALEDArrayDeviceImpl_QueryNumSupportedInterfaces");
       
   172         return XA_RESULT_PARAMETER_INVALID;
       
   173     }
       
   174 }
       
   175 /* XAResult XALEDArrayDeviceImpl_QuerySupportedInterfaces
       
   176  * Description: Statically query supported interfaces
       
   177  */
       
   178 XAresult XALEDArrayDeviceImpl_QuerySupportedInterfaces( XAuint32 index,
       
   179                                                       XAInterfaceID * pInterfaceId )
       
   180 {
       
   181     DEBUG_API("->XALEDArrayDeviceImpl_QuerySupportedInterfaces");
       
   182 
       
   183 #ifdef _GSTREAMER_BACKEND_  
       
   184     if( index >= LEDARRAY_ITFCOUNT || !pInterfaceId )
       
   185     {
       
   186         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
       
   187         DEBUG_API("<-XALEDArrayDeviceImpl_QuerySupportedInterfaces");
       
   188         return XA_RESULT_PARAMETER_INVALID;
       
   189     }
       
   190     else
       
   191     {
       
   192         *pInterfaceId = *(XALEDArrayDeviceItfIIDs[index]);
       
   193 #endif
       
   194         DEBUG_API("<-XALEDArrayDeviceImpl_QuerySupportedInterfaces");
       
   195         return XA_RESULT_SUCCESS;
       
   196 #ifdef _GSTREAMER_BACKEND_  
       
   197     }
       
   198 #endif    
       
   199 }
       
   200 
       
   201 
       
   202 /*****************************************************************************
       
   203  * base object XAObjectItfImpl methods
       
   204  *****************************************************************************/
       
   205 
       
   206 /* XAresult XALEDArrayDeviceImpl_DoRealize( XAObjectItf self )
       
   207  * Description: Realize all implicit and explicitly wanted interfaces.
       
   208  * Create and initialize implementation-specific variables.
       
   209  * Called from base object XAObjectItfImpl
       
   210  */
       
   211 XAresult XALEDArrayDeviceImpl_DoRealize( XAObjectItf self )
       
   212 {
       
   213 #ifdef _GSTREAMER_BACKEND_
       
   214     XAObjectItfImpl* pObj = (XAObjectItfImpl*)(*self);
       
   215     XAuint8 itfIdx = 0;
       
   216     XALEDArrayDeviceImpl* pObjImpl = (XALEDArrayDeviceImpl*)(pObj);
       
   217     XAresult ret = XA_RESULT_SUCCESS;
       
   218 
       
   219     DEBUG_API("->XALEDArrayDeviceImpl_DoRealize");
       
   220     XA_IMPL_THREAD_SAFETY_ENTRY(XATSLEDArray);
       
   221 
       
   222     /* check casting from correct pointer type */
       
   223     if( !pObjImpl || pObj != pObjImpl->baseObj.self )
       
   224     {
       
   225         /* invalid parameter */
       
   226         XA_IMPL_THREAD_SAFETY_EXIT(XATSLEDArray);
       
   227         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
       
   228         DEBUG_API("<-XALEDArrayDeviceImpl_DoRealize");
       
   229         return XA_RESULT_PARAMETER_INVALID;
       
   230     }
       
   231 
       
   232     ret = XALEDArrayAdapt_PostInit( pObjImpl->adaptationCtx );
       
   233     if( ret != XA_RESULT_SUCCESS )
       
   234     {
       
   235         XA_IMPL_THREAD_SAFETY_EXIT(XATSLEDArray);
       
   236         DEBUG_ERR_A1("Error: %d",ret);
       
   237         DEBUG_API("<-XALEDArrayDeviceImpl_DoRealize");
       
   238         return ret;
       
   239     }
       
   240 
       
   241     /* Realize all implicit and explicitly wanted interfaces */
       
   242     for( itfIdx = 0; itfIdx < LEDARRAY_ITFCOUNT; itfIdx++)
       
   243     {
       
   244         if( !(pObj->interfaceMap[itfIdx].pItf) &&
       
   245             pObj->interfaceMap[itfIdx].required )
       
   246         {
       
   247             void *pItf = NULL;
       
   248             switch( itfIdx )
       
   249             {
       
   250                 case LEDARRAY_LEDARRAYITF:
       
   251                     pItf = XALEDArrayItfImpl_Create( pObjImpl->adaptationCtx );
       
   252                     break;
       
   253                 case LEDARRAY_CONFIGEXTENSIONITF:
       
   254                     pItf = XAConfigExtensionsItfImpl_Create();
       
   255                     break;
       
   256                 case LEDARRAY_DIMITF:
       
   257                     pItf = XADIMItfImpl_Create();
       
   258                     break;
       
   259                 default:
       
   260                     break;
       
   261             }
       
   262             if( !pItf )
       
   263             {
       
   264                 /* memory allocation failed */
       
   265                 XA_IMPL_THREAD_SAFETY_EXIT(XATSLEDArray);
       
   266                 DEBUG_ERR("XA_RESULT_MEMORY_FAILURE");
       
   267                 DEBUG_API("<-XALEDArrayDeviceImpl_DoRealize");
       
   268                 return XA_RESULT_MEMORY_FAILURE;
       
   269             }
       
   270             else
       
   271             {
       
   272                 pObj->interfaceMap[itfIdx].pItf = pItf;
       
   273             }
       
   274         }
       
   275     }
       
   276 
       
   277     pObj->state = XA_OBJECT_STATE_REALIZED;
       
   278     XA_IMPL_THREAD_SAFETY_EXIT(XATSLEDArray);
       
   279 #endif    
       
   280     DEBUG_API("<-XALEDArrayDeviceImpl_DoRealize");
       
   281     return XA_RESULT_SUCCESS;
       
   282 }
       
   283 
       
   284 /* XAresult XALEDArrayDeviceImpl_DoResume
       
   285  * Description: Resume object from suspended state
       
   286  */
       
   287 XAresult XALEDArrayDeviceImpl_DoResume(XAObjectItf self)
       
   288 {
       
   289     DEBUG_API("->XALEDArrayDeviceImpl_DoResume");
       
   290     DEBUG_API("<-XALEDArrayDeviceImpl_DoResume");
       
   291     /* This implementation does not support suspended state */
       
   292     return XA_RESULT_PRECONDITIONS_VIOLATED;
       
   293 }
       
   294 
       
   295 /* void XALEDArrayDeviceImpl_FreeResources
       
   296  * Description: Free all resources reserved at XALEDArrayDeviceImpl_DoRealize()
       
   297  */
       
   298 void XALEDArrayDeviceImpl_FreeResources(XAObjectItf self)
       
   299 {
       
   300 #ifdef _GSTREAMER_BACKEND_  
       
   301     XAObjectItfImpl* pObj = (XAObjectItfImpl*)(*self);
       
   302     XALEDArrayDeviceImpl* pImpl = (XALEDArrayDeviceImpl*)(*self);
       
   303     XAuint8 itfIdx = 0;
       
   304     DEBUG_API("->XALEDArrayDeviceImpl_FreeResources");
       
   305     XA_IMPL_THREAD_SAFETY_ENTRY_FOR_VOID_FUNCTIONS(XATSLEDArray);
       
   306     assert( pObj && pImpl && pObj == pObj->self );
       
   307 
       
   308     if ( pImpl->adaptationCtx != NULL )
       
   309     {
       
   310         XALEDArrayAdapt_Destroy( pImpl->adaptationCtx );
       
   311         pImpl->adaptationCtx = NULL;
       
   312     }
       
   313 
       
   314     /* free all allocated interfaces */
       
   315     for(itfIdx = 0; itfIdx < LEDARRAY_ITFCOUNT; itfIdx++)
       
   316     {
       
   317         void *pItf = pObj->interfaceMap[itfIdx].pItf;
       
   318         if(pItf)
       
   319         {
       
   320             switch(itfIdx)
       
   321             {
       
   322                 case LEDARRAY_LEDARRAYITF:
       
   323                     XALEDArrayItfImpl_Free( pItf );
       
   324                     break;
       
   325                 case LEDARRAY_CONFIGEXTENSIONITF:
       
   326                     XAConfigExtensionsItfImpl_Free( pItf );
       
   327                     break;
       
   328                 case LEDARRAY_DIMITF:
       
   329                     XADIMItfImpl_Free( pItf );
       
   330                     break;
       
   331 
       
   332                 default:
       
   333                     break;
       
   334             }
       
   335             pObj->interfaceMap[itfIdx].pItf = NULL;
       
   336         }
       
   337     }
       
   338 
       
   339     if ( pImpl->adaptationCtx != NULL )
       
   340     {
       
   341         XALEDArrayAdapt_Destroy( pImpl->adaptationCtx );
       
   342         pImpl->adaptationCtx = NULL;
       
   343     }
       
   344 
       
   345     XA_IMPL_THREAD_SAFETY_EXIT_FOR_VOID_FUNCTIONS(XATSLEDArray);
       
   346     DEBUG_API("<-XALEDArrayDeviceImpl_FreeResources");
       
   347 #endif    
       
   348     return;
       
   349 }
       
   350 /* END OF FILE */