khronosfws/openmax_al/src/camera/xacameradevice.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 "xacameradevice.h"
       
    22 #include "xacameraitf.h"
       
    23 #include "xaconfigextensionsitf.h"
       
    24 #include "xadynintmgmtitf.h"
       
    25 #include "xaimagecontrolsitf.h"
       
    26 #include "xaimageeffectsitf.h"
       
    27 #include "xavideopostprocessingitf.h"
       
    28 #include "xathreadsafety.h"
       
    29 
       
    30 /* Static mapping of enumeration XACameraDeviceInterfaces to interface iids */
       
    31 static const XAInterfaceID* XACameraDeviceItfIIDs[CAMERA_ITFCOUNT]=
       
    32 {
       
    33     &XA_IID_OBJECT,
       
    34     &XA_IID_CAMERA,
       
    35     &XA_IID_CONFIGEXTENSION,
       
    36     &XA_IID_DYNAMICINTERFACEMANAGEMENT,
       
    37     &XA_IID_IMAGECONTROLS,
       
    38     &XA_IID_IMAGEEFFECTS,
       
    39     &XA_IID_VIDEOPOSTPROCESSING
       
    40 };
       
    41 
       
    42 
       
    43 /*****************************************************************************
       
    44  * Global methods
       
    45  *****************************************************************************/
       
    46 
       
    47 /* XAResult XACameraDeviceImpl_Create
       
    48  * Description: Create object
       
    49  */
       
    50 XAresult XACameraDeviceImpl_CreateCameraDevice(XAObjectItf* pDevice,
       
    51                                                XAuint32 deviceID,
       
    52                                                XAuint32 numInterfaces,
       
    53                                                const XAInterfaceID * pInterfaceIds,
       
    54                                                const XAboolean * pInterfaceRequired)
       
    55 {
       
    56     XACameraDeviceImpl* pImpl = NULL;
       
    57     XAObjectItfImpl* pBaseObj = NULL;
       
    58     XAuint8 itfIndex = 0;
       
    59 
       
    60     DEBUG_API("->XACameraDeviceImpl_Create");
       
    61     XA_IMPL_THREAD_SAFETY_ENTRY(XATSCamera);
       
    62 
       
    63     if( !pDevice )
       
    64     {
       
    65         XA_IMPL_THREAD_SAFETY_EXIT(XATSCamera);
       
    66         /* invalid parameter */
       
    67         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
       
    68         DEBUG_API("<-XACameraDeviceImpl_Create");
       
    69         return XA_RESULT_PARAMETER_INVALID;
       
    70     }
       
    71 
       
    72     /* instantiate object implementation */
       
    73     pImpl = (XACameraDeviceImpl*)calloc(1,sizeof(XACameraDeviceImpl));
       
    74     if( !pImpl )
       
    75     {
       
    76         /* memory allocation failed */
       
    77         XA_IMPL_THREAD_SAFETY_EXIT(XATSCamera);
       
    78         DEBUG_ERR("XA_RESULT_MEMORY_FAILURE");
       
    79         DEBUG_API("<-XACameraDeviceImpl_Create");
       
    80         return XA_RESULT_MEMORY_FAILURE;
       
    81     }
       
    82     pBaseObj = &pImpl->baseObj;
       
    83 
       
    84     /* Initialize base object default implementation */
       
    85     XAObjectItfImpl_Init(pBaseObj,
       
    86                          CAMERA_ITFCOUNT,
       
    87                          XACameraDeviceItfIIDs,
       
    88                          XACameraDeviceImpl_DoRealize,
       
    89                          XACameraDeviceImpl_DoResume,
       
    90                          XACameraDeviceImpl_FreeResources);
       
    91 
       
    92     /* Mark interfaces that need to be exposed */
       
    93     /* Implicit and mandated interfaces */
       
    94     pBaseObj->interfaceMap[CAMERA_CAMERAITF].required = XA_BOOLEAN_TRUE;
       
    95     pBaseObj->interfaceMap[CAMERA_DIMITF].required = XA_BOOLEAN_TRUE;
       
    96 
       
    97     /* Explicit interfaces */
       
    98     if( (numInterfaces != 0) && pInterfaceIds && pInterfaceRequired )
       
    99     {
       
   100         /* Check required interfaces */
       
   101         for( itfIndex = 0; itfIndex < numInterfaces; itfIndex++ )
       
   102         {
       
   103             /* If mapEntry is null then required interface is not supported.*/
       
   104             XAObjItfMapEntry *entry =
       
   105                 XAObjectItfImpl_GetItfEntry((XAObjectItf)&(pBaseObj), pInterfaceIds[itfIndex]);
       
   106             if( !entry  )
       
   107             {
       
   108                 if( pInterfaceRequired[itfIndex] )
       
   109                 {
       
   110                     /* required interface cannot be accommodated - fail creation */
       
   111                     XAObjectItfImpl_Destroy((XAObjectItf)&(pBaseObj));
       
   112                     XA_IMPL_THREAD_SAFETY_EXIT(XATSCamera);
       
   113                     DEBUG_ERR("Required interface not found - abort creation!");
       
   114                     DEBUG_API("<-XACameraDeviceImpl_Create");
       
   115                     return XA_RESULT_FEATURE_UNSUPPORTED;
       
   116                 }
       
   117                 else
       
   118                 {
       
   119                     DEBUG_INFO("Requested (not required) interface not found - continue creation");
       
   120                 }
       
   121             }
       
   122             else
       
   123             {
       
   124                 entry->required = XA_BOOLEAN_TRUE;
       
   125             }
       
   126         }
       
   127     }
       
   128 
       
   129     /* Mark interfaces that can be handled dynamically */
       
   130     /* Mandated dynamic itfs */
       
   131     pBaseObj->interfaceMap[CAMERA_IMAGEEFFECTSITF].isDynamic = XA_BOOLEAN_TRUE;
       
   132 
       
   133 
       
   134     /* Initialize XACameraDeviceImpl variables */
       
   135     pImpl->deviceID = deviceID;
       
   136 #ifdef _GSTREAMER_BACKEND_   
       
   137     pImpl->adaptationCtx = XACameraAdapt_Create(pImpl->deviceID);
       
   138 #endif
       
   139     
       
   140     
       
   141     /* This code is put here to return Feature Not Supported since adaptation is not present*/
       
   142     /*************************************************/
       
   143     XAObjectItfImpl_Destroy((XAObjectItf)&(pBaseObj));
       
   144     XA_IMPL_THREAD_SAFETY_EXIT(XATSCamera);
       
   145     DEBUG_ERR("Required interface not found - abort creation!");
       
   146     DEBUG_API("<-XACameraDeviceImpl_Create");
       
   147     return XA_RESULT_FEATURE_UNSUPPORTED;    
       
   148     /*************************************************/
       
   149 
       
   150     
       
   151     
       
   152     
       
   153     /* Set ObjectItf to point to newly created object */
       
   154 /*
       
   155     *pDevice = (XAObjectItf)&(pBaseObj->self);
       
   156 
       
   157     XA_IMPL_THREAD_SAFETY_EXIT(XATSCamera);
       
   158     DEBUG_API("<-XACameraDeviceImpl_Create");
       
   159     return XA_RESULT_SUCCESS;
       
   160 */
       
   161 }
       
   162 
       
   163 /* XAResult XACameraDeviceImpl_QueryNumSupportedInterfaces
       
   164  * Description: Statically query number of supported interfaces
       
   165  */
       
   166 XAresult XACameraDeviceImpl_QueryNumSupportedInterfaces( XAuint32 *pNumSupportedInterfaces )
       
   167 {
       
   168     DEBUG_API("->XACameraDeviceImpl_QueryNumSupportedInterfaces");
       
   169     if( pNumSupportedInterfaces )
       
   170     {
       
   171         *pNumSupportedInterfaces = CAMERA_ITFCOUNT;
       
   172 
       
   173         DEBUG_API_A1("<-XACameraDeviceImpl_QueryNumSupportedInterfaces - %i", (int)(*pNumSupportedInterfaces) );
       
   174         return XA_RESULT_SUCCESS;
       
   175     }
       
   176     else
       
   177     {
       
   178         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
       
   179         DEBUG_API("<-XACameraDeviceImpl_QueryNumSupportedInterfaces");
       
   180         return XA_RESULT_PARAMETER_INVALID;
       
   181     }
       
   182 }
       
   183 /* XAResult XACameraDeviceImpl_QuerySupportedInterfaces
       
   184  * Description: Statically query supported interfaces
       
   185  */
       
   186 XAresult XACameraDeviceImpl_QuerySupportedInterfaces( XAuint32 index,
       
   187                                                       XAInterfaceID * pInterfaceId )
       
   188 {
       
   189     DEBUG_API("->XACameraDeviceImpl_QuerySupportedInterfaces");
       
   190 
       
   191     if( index >= CAMERA_ITFCOUNT || !pInterfaceId )
       
   192     {
       
   193         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
       
   194         DEBUG_API("<-XACameraDeviceImpl_QuerySupportedInterfaces");
       
   195         return XA_RESULT_PARAMETER_INVALID;
       
   196     }
       
   197     else
       
   198     {
       
   199         *pInterfaceId = *(XACameraDeviceItfIIDs[index]);
       
   200 
       
   201         DEBUG_API("<-XACameraDeviceImpl_QuerySupportedInterfaces");
       
   202         return XA_RESULT_SUCCESS;
       
   203     }
       
   204 }
       
   205 
       
   206 
       
   207 /*****************************************************************************
       
   208  * base object XAObjectItfImpl methods
       
   209  *****************************************************************************/
       
   210 
       
   211 /* XAresult XACameraDeviceImpl_DoRealize( XAObjectItf self )
       
   212  * Description: Realize all implicit and explicitly wanted interfaces.
       
   213  * Create and initialize implementation-specific variables.
       
   214  * Called from base object XAObjectItfImpl
       
   215  */
       
   216 XAresult XACameraDeviceImpl_DoRealize( XAObjectItf self )
       
   217 {
       
   218     XAuint8 itfIdx = 0;
       
   219     XAObjectItfImpl* pObj = (XAObjectItfImpl*)(*self);
       
   220     XACameraDeviceImpl* pObjImpl = (XACameraDeviceImpl*)(pObj);
       
   221     XAresult ret = XA_RESULT_SUCCESS;
       
   222 
       
   223 
       
   224     DEBUG_API("->XACameraDeviceImpl_DoRealize");
       
   225     XA_IMPL_THREAD_SAFETY_ENTRY(XATSCamera);
       
   226 
       
   227     /* check casting from correct pointer type */
       
   228     if( !pObjImpl || pObj != pObjImpl->baseObj.self )
       
   229     {
       
   230         /* invalid parameter */
       
   231         XA_IMPL_THREAD_SAFETY_EXIT(XATSCamera);
       
   232         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
       
   233         DEBUG_API("<-XACameraDeviceImpl_DoRealize");
       
   234         return XA_RESULT_PARAMETER_INVALID;
       
   235     }
       
   236 
       
   237 #ifdef _GSTREAMER_BACKEND_   
       
   238     ret = XACameraAdapt_PostInit( pObjImpl->adaptationCtx );
       
   239 #endif
       
   240     if( ret != XA_RESULT_SUCCESS )
       
   241     {
       
   242         XA_IMPL_THREAD_SAFETY_EXIT(XATSCamera);
       
   243         DEBUG_ERR_A1("Camera adapt postinit - %d", ret);
       
   244         DEBUG_API("<-XACameraDeviceImpl_DoRealize");
       
   245         return ret;
       
   246     }
       
   247 
       
   248     /* Realize all implicit and explicitly wanted interfaces */
       
   249     for( itfIdx = 0; itfIdx < CAMERA_ITFCOUNT; itfIdx++)
       
   250     {
       
   251         if( !(pObj->interfaceMap[itfIdx].pItf) &&
       
   252             pObj->interfaceMap[itfIdx].required )
       
   253         {
       
   254             void *pItf = NULL;
       
   255             switch( itfIdx )
       
   256             {
       
   257                 case CAMERA_DIMITF:
       
   258                     pItf = XADIMItfImpl_Create();
       
   259                     if(pItf)
       
   260                     {
       
   261                         XADIMItfImpl_Init(pItf, self,
       
   262                                 XACameraDeviceImpl_DoAddItf,
       
   263                                 XACameraDeviceImpl_DoResumeItf,
       
   264                                 XACameraDeviceImpl_DoRemoveItf);
       
   265                     }
       
   266                     break;
       
   267 #ifdef _GSTREAMER_BACKEND_   
       
   268                 case CAMERA_CAMERAITF:
       
   269                     pItf = XACameraItfImpl_Create( pObjImpl->adaptationCtx );
       
   270                     break;
       
   271                 case CAMERA_CONFIGEXTENSIONITF:
       
   272                     pItf = XAConfigExtensionsItfImpl_Create();
       
   273                     break;
       
   274                 case CAMERA_IMAGECONTROLSITF:
       
   275                    pItf = XAImageControlsItfImpl_Create( pObjImpl->adaptationCtx );
       
   276                    break;
       
   277                 case CAMERA_IMAGEEFFECTSITF:
       
   278                    pItf = XAImageEffectsItfImpl_Create( pObjImpl->adaptationCtx );
       
   279                    break;
       
   280                 case CAMERA_VIDEOPOSTPROCESSINGITF:
       
   281                      pItf = XAVideoPostProcessingItfImpl_Create( pObjImpl->adaptationCtx );
       
   282                      break;
       
   283 #endif                     
       
   284                 default:
       
   285                     break;
       
   286             }
       
   287             if( !pItf )
       
   288             {
       
   289                 /* memory allocation failed */
       
   290                 XA_IMPL_THREAD_SAFETY_EXIT(XATSCamera);
       
   291                 DEBUG_ERR("XA_RESULT_MEMORY_FAILURE");
       
   292                 DEBUG_API("<-XACameraDeviceImpl_DoRealize");
       
   293                 return XA_RESULT_MEMORY_FAILURE;
       
   294             }
       
   295             else
       
   296             {
       
   297                 pObj->interfaceMap[itfIdx].pItf = pItf;
       
   298             }
       
   299         }
       
   300     }
       
   301 
       
   302     pObj->state = XA_OBJECT_STATE_REALIZED;
       
   303     XA_IMPL_THREAD_SAFETY_EXIT(XATSCamera);
       
   304     DEBUG_API("<-XACameraDeviceImpl_DoRealize");
       
   305     return XA_RESULT_SUCCESS;
       
   306 }
       
   307 
       
   308 /* XAresult XACameraDeviceImpl_DoResume
       
   309  * Description: Resume object from suspended state
       
   310  */
       
   311 XAresult XACameraDeviceImpl_DoResume(XAObjectItf self)
       
   312 {
       
   313     DEBUG_API("->XACameraDeviceImpl_DoResume");
       
   314     DEBUG_API("<-XACameraDeviceImpl_DoResume");
       
   315     /* This implementation does not support suspended state */
       
   316     return XA_RESULT_PRECONDITIONS_VIOLATED;
       
   317 }
       
   318 
       
   319 /* void XACameraDeviceImpl_FreeResources
       
   320  * Description: Free all resources reserved at XACameraDeviceImpl_DoRealize()
       
   321  */
       
   322 void XACameraDeviceImpl_FreeResources(XAObjectItf self)
       
   323 {
       
   324     XAObjectItfImpl* pObj = (XAObjectItfImpl*)(*self);
       
   325     XAuint8 itfIdx = 0;
       
   326     DEBUG_API("->XACameraDeviceImpl_FreeResources");
       
   327     XA_IMPL_THREAD_SAFETY_ENTRY_FOR_VOID_FUNCTIONS(XATSCamera);
       
   328 #ifdef _GSTREAMER_BACKEND_ 
       
   329     XACameraDeviceImpl* pImpl = (XACameraDeviceImpl*)(*self);
       
   330     assert( pObj && pImpl && pObj == pObj->self );
       
   331 #endif
       
   332     
       
   333 
       
   334     /* free all allocated interfaces */
       
   335     for(itfIdx = 0; itfIdx < CAMERA_ITFCOUNT; itfIdx++)
       
   336     {
       
   337         void *pItf = pObj->interfaceMap[itfIdx].pItf;
       
   338         if(pItf)
       
   339         {
       
   340             switch(itfIdx)
       
   341             {
       
   342                 case CAMERA_CAMERAITF:
       
   343                     XACameraItfImpl_Free( pItf );
       
   344                     break;
       
   345                 case CAMERA_CONFIGEXTENSIONITF:
       
   346                     XAConfigExtensionsItfImpl_Free( pItf );
       
   347                     break;
       
   348                 case CAMERA_DIMITF:
       
   349                     XADIMItfImpl_Free( pItf );
       
   350                     break;
       
   351                 case CAMERA_IMAGECONTROLSITF:
       
   352                     XAImageControlsItfImpl_Free( pItf );
       
   353                     break;
       
   354                 case CAMERA_IMAGEEFFECTSITF:
       
   355                     XAImageEffectsItfImpl_Free( pItf );
       
   356                     break;
       
   357                 case CAMERA_VIDEOPOSTPROCESSINGITF:
       
   358                     XAVideoPostProcessingItfImpl_Free( pItf );
       
   359                     break;
       
   360                 default:
       
   361                     break;
       
   362             }
       
   363             pObj->interfaceMap[itfIdx].pItf = NULL;
       
   364         }
       
   365     }
       
   366 #ifdef _GSTREAMER_BACKEND_   
       
   367     if ( pImpl->adaptationCtx != NULL )
       
   368     {
       
   369         XACameraAdapt_Destroy( pImpl->adaptationCtx );
       
   370         pImpl->adaptationCtx = NULL;
       
   371     }
       
   372 #endif
       
   373     XA_IMPL_THREAD_SAFETY_EXIT_FOR_VOID_FUNCTIONS(XATSCamera);
       
   374     DEBUG_API("<-XACameraDeviceImpl_FreeResources");
       
   375     return;
       
   376 }
       
   377 
       
   378 /*****************************************************************************
       
   379  * CameraDeviceImpl -specific methods
       
   380  *****************************************************************************/
       
   381 
       
   382 /* XACameraDeviceImpl_DoAddItf
       
   383  * Dynamically add an interface, object specific parts
       
   384  */
       
   385 XAresult XACameraDeviceImpl_DoAddItf(XAObjectItf self, XAObjItfMapEntry *mapEntry  )
       
   386 {
       
   387 #ifdef _GSTREAMER_BACKEND_
       
   388     XAObjectItfImpl* pObj = (XAObjectItfImpl*)(*self);
       
   389     XACameraDeviceImpl* pImpl = (XACameraDeviceImpl*)(pObj);
       
   390 #endif
       
   391     XAresult ret = XA_RESULT_SUCCESS;
       
   392     DEBUG_API("->XACameraDeviceImpl_DoAddItf");
       
   393     if(mapEntry)
       
   394     {
       
   395         switch( mapEntry->mapIdx )
       
   396         {
       
   397         case CAMERA_IMAGEEFFECTSITF:
       
   398 #ifdef _GSTREAMER_BACKEND_   
       
   399             mapEntry->pItf = XAImageEffectsItfImpl_Create( pImpl->adaptationCtx );
       
   400 #endif
       
   401             break;
       
   402         default:
       
   403             DEBUG_ERR("XACameraDeviceImpl_DoAddItf unknown id");
       
   404             ret = XA_RESULT_FEATURE_UNSUPPORTED;
       
   405             break;
       
   406         }
       
   407 
       
   408         if( !mapEntry->pItf && ret == XA_RESULT_SUCCESS)
       
   409             {
       
   410                 DEBUG_ERR("XACameraDeviceImpl_DoAddItf itf creation failed");
       
   411                 ret = XA_RESULT_MEMORY_FAILURE;
       
   412             }
       
   413     }
       
   414     else
       
   415     {
       
   416         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
       
   417         ret = XA_RESULT_PARAMETER_INVALID;
       
   418     }
       
   419 
       
   420     DEBUG_API("<-XACameraDeviceImpl_DoAddItf");
       
   421     return ret;
       
   422 }
       
   423 
       
   424 /* XACameraDeviceImpl_DoResumeItf
       
   425  * Try to resume lost interface, object specific parts
       
   426  */
       
   427 XAresult XACameraDeviceImpl_DoResumeItf(XAObjectItf self, XAObjItfMapEntry *mapEntry  )
       
   428 {
       
   429     XAresult ret = XA_RESULT_SUCCESS;
       
   430     DEBUG_API("->XACameraDeviceImpl_DoResumeItf");
       
   431     /* For now, no difference between suspended and unrealised itfs */
       
   432     ret = XACameraDeviceImpl_DoAddItf(self,mapEntry);
       
   433     DEBUG_API("<-XACameraDeviceImpl_DoResumeItf");
       
   434     return ret;
       
   435 }
       
   436 
       
   437 /* XACameraDeviceImpl_DoRemoveItf
       
   438  * Dynamically remove an interface, object specific parts
       
   439  */
       
   440 XAresult XACameraDeviceImpl_DoRemoveItf(XAObjectItf self, XAObjItfMapEntry *mapEntry )
       
   441 {
       
   442     XAresult ret = XA_RESULT_SUCCESS;
       
   443     DEBUG_API("->XACameraDeviceImpl_DoRemoveItf");
       
   444     if(mapEntry)
       
   445     {
       
   446         switch( mapEntry->mapIdx )
       
   447         {
       
   448         case CAMERA_IMAGEEFFECTSITF:
       
   449             XAImageEffectsItfImpl_Free( mapEntry->pItf );
       
   450             break;
       
   451         default:
       
   452             DEBUG_ERR("XACameraDeviceImpl_DoRemoveItf unknown id");
       
   453             ret = XA_RESULT_FEATURE_UNSUPPORTED;
       
   454             break;
       
   455         }
       
   456         mapEntry->pItf = NULL;
       
   457     }
       
   458     else
       
   459     {
       
   460         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
       
   461         ret = XA_RESULT_PARAMETER_INVALID;
       
   462     }
       
   463 
       
   464     DEBUG_API("<-XACameraDeviceImpl_DoRemoveItf");
       
   465     return ret;
       
   466 }
       
   467 /* END OF FILE */