khronosfws/openmax_al/src/mmf_adaptation/xamediaplayeradaptctxmmf.c
changeset 31 8dfd592727cb
parent 16 43d09473c595
child 32 94fc26b6e006
equal deleted inserted replaced
22:128eb6a32b84 31:8dfd592727cb
     1 /*
     1 /*
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     2  * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3  * All rights reserved.
     4 * This component and the accompanying materials are made available
     4  * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5  * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6  * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     8  *
     9 * Initial Contributors:
     9  * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    10  * Nokia Corporation - initial contribution.
    11 *
    11  *
    12 * Contributors:
    12  * Contributors:
    13 *
    13  *
    14 * Description: 
    14  * Description: Media Player Adapt Code MMF 
    15 *
    15  *
    16 */
    16  */
    17 
    17 
    18 #include <assert.h>
    18 #include <assert.h>
    19 #include <stdlib.h>
    19 #include <stdlib.h>
    20 #include "xamediaplayeradaptctxmmf.h"
    20 #include "xamediaplayeradaptctxmmf.h"
    21 #include "xaadaptationmmf.h"
    21 #include "xaadaptationmmf.h"
    22 #include "xaobjectitf.h"
    22 #include "xaobjectitf.h"
    23 #include "cmmfbackendengine.h"
    23 #include "cmmfbackendengine.h"
    24 
       
    25 #include "cmetadatautilityitf.h"
    24 #include "cmetadatautilityitf.h"
    26 
       
    27 
       
    28 
    25 
    29 /*
    26 /*
    30  * XAMediaPlayerAdaptationMMFCtx* XAMediaPlayerAdapt_Create()
    27  * XAMediaPlayerAdaptationMMFCtx* XAMediaPlayerAdapt_Create()
    31  * Allocates memory for Media Player Adaptation Context and makes 1st phase initialization
    28  * Allocates memory for Media Player Adaptation Context and makes 1st phase initialization
    32  * @param XADataSource *pDataSrc - pointer to OMX-AL data source
    29  * @param XADataSource *pDataSrc - pointer to OMX-AL data source
    33  * @param XADataSource *pBankSrc - pointer to instrument bank structure in Mobile DLS, if NULL default will be used.
    30  * @param XADataSource *pBankSrc - pointer to instrument bank structure in Mobile DLS, if NULL default will be used.
    34  * @param XADataSink *pAudioSnk - pointer to OMX-AL audio sink definition
    31  * @param XADataSink *pAudioSnk - pointer to OMX-AL audio sink definition
    35  * @param XADataSink *pImageVideoSnk - pointer to OMX-AL image and video sink definition
    32  * @param XADataSink *pImageVideoSnk - pointer to OMX-AL image and video sink definition
    36  * @returns XAMediaPlayerAdaptationMMFCtx* - Pointer to created context, NULL if error occurs.
    33  * @returns XAMediaPlayerAdaptationMMFCtx* - Pointer to created context, NULL if error occurs.
    37  */
    34  */
    38 XAAdaptationBaseCtx* XAMediaPlayerAdaptMMF_Create(XADataSource *pDataSrc, XADataSource *pBankSrc,
    35 XAAdaptationBaseCtx* XAMediaPlayerAdaptMMF_Create(XADataSource *pDataSrc,
    39                                                       XADataSink *pAudioSnk, XADataSink *pImageVideoSnk,
    36         XADataSource *pBankSrc, XADataSink *pAudioSnk,
    40                                                       XADataSink *pVibra, XADataSink *pLEDArray)
    37         XADataSink *pImageVideoSnk, XADataSink *pVibra, XADataSink *pLEDArray)
    41 {
    38     {
    42     XAMediaPlayerAdaptationMMFCtx *pSelf = NULL;
    39     XAMediaPlayerAdaptationMMFCtx *pSelf = NULL;
    43     XAuint32 locType = 0;
    40     XAuint32 locType = 0;
       
    41     XADataLocator_IODevice *ioDevice;
    44     XAresult res;
    42     XAresult res;
    45     DEBUG_API("->XAMediaPlayerAdaptMMF_Create");
    43     DEBUG_API("->XAMediaPlayerAdaptMMF_Create");
    46     
    44 
    47     pSelf = calloc(1, sizeof(XAMediaPlayerAdaptationMMFCtx));
    45     pSelf = calloc(1, sizeof(XAMediaPlayerAdaptationMMFCtx));
    48     if ( pSelf)
    46     if (pSelf)
    49     {
    47         {
    50           
    48         if (pDataSrc)
    51         if( XAAdaptationBaseMMF_Init(&(pSelf->baseObj),XAMediaPlayerAdaptation)
    49             {
    52             != XA_RESULT_SUCCESS )
    50             locType = *((XAuint32*) (pDataSrc->pLocator));
    53         {
    51             if (locType == XA_DATALOCATOR_IODEVICE)
       
    52                 {
       
    53                 ioDevice = (XADataLocator_IODevice*) (pDataSrc->pLocator);
       
    54                 if (ioDevice->deviceType == XA_IODEVICE_RADIO)
       
    55                     {
       
    56                     return XAMediaPlayerAdaptMMF_CreateRadio(pSelf, pDataSrc,
       
    57                             pBankSrc, pAudioSnk, pImageVideoSnk, pVibra,
       
    58                             pLEDArray);
       
    59                     }
       
    60                 }
       
    61             }
       
    62         if (XAAdaptationBaseMMF_Init(&(pSelf->baseObj),
       
    63                 XAMediaPlayerAdaptation) != XA_RESULT_SUCCESS)
       
    64             {
    54             DEBUG_ERR("Failed to init base context!!!");
    65             DEBUG_ERR("Failed to init base context!!!");
    55             free(pSelf);
    66             free(pSelf);
    56             pSelf = NULL;
    67             pSelf = NULL;
    57         }
    68             }
    58         else
    69         else
    59             
    70             {
    60         {
    71             pSelf->isForRadio = XA_BOOLEAN_FALSE;
    61             pSelf->baseObj.baseObj.fwtype = FWMgrFWMMF;
    72             pSelf->baseObj.baseObj.fwtype = FWMgrFWMMF;
    62             pSelf->xaSource = pDataSrc;
    73             pSelf->xaSource = pDataSrc;
    63             pSelf->xaBankSrc = pBankSrc;
    74             pSelf->xaBankSrc = pBankSrc;
    64             pSelf->xaAudioSink = pAudioSnk;
    75             pSelf->xaAudioSink = pAudioSnk;
    65             pSelf->xaVideoSink = pImageVideoSnk;
    76             pSelf->xaVideoSink = pImageVideoSnk;
    67             pSelf->xaVibra = pVibra;
    78             pSelf->xaVibra = pVibra;
    68             pSelf->curMirror = XA_VIDEOMIRROR_NONE;
    79             pSelf->curMirror = XA_VIDEOMIRROR_NONE;
    69             pSelf->curRotation = 0;
    80             pSelf->curRotation = 0;
    70             pSelf->isobjsrc = XA_BOOLEAN_FALSE;
    81             pSelf->isobjsrc = XA_BOOLEAN_FALSE;
    71             pSelf->cameraSinkSynced = XA_BOOLEAN_FALSE;
    82             pSelf->cameraSinkSynced = XA_BOOLEAN_FALSE;
    72             /*pSelf->waitData = XA_BOOLEAN_FALSE;*/
    83             }
    73         }
    84         }
    74 
       
    75   
       
    76     if ( pDataSrc )
       
    77 		{
       
    78 			locType = *((XAuint32*)(pDataSrc->pLocator));
       
    79 			if ( locType == XA_DATALOCATOR_IODEVICE  )
       
    80 			{
       
    81 			//XADataLocator_IODevice *ioDevice = (XADataLocator_IODevice*)(pDataSrc->pLocator);
       
    82 			}
       
    83 		}
       
    84     }
       
    85     
       
    86     else
    85     else
    87         {
    86         {
    88         DEBUG_ERR("Failed to create XAMediaPlayerAdaptationMMFCtx !!!");
    87         DEBUG_ERR("Failed to create XAMediaPlayerAdaptationMMFCtx !!!");
    89         return NULL;
    88         return NULL;
    90         }
    89         }
    91     if(pSelf)
    90     
    92     {
    91     if (pSelf)
    93 	    res = mmf_backend_engine_init(&(pSelf->mmfContext));
    92         {
    94         if(!(pSelf->mmfContext) || (res != XA_RESULT_SUCCESS))
    93         res = mmf_backend_engine_init(&(pSelf->mmfContext));
    95         {
    94         if (!(pSelf->mmfContext) || (res != XA_RESULT_SUCCESS))
       
    95             {
    96             /* TODO Check to make sure there is no undeleted MMF objects here*/
    96             /* TODO Check to make sure there is no undeleted MMF objects here*/
    97             DEBUG_ERR("Failed to init mmf context!!!");
    97             DEBUG_ERR("Failed to init mmf context!!!");
    98             free(pSelf);
    98             free(pSelf);
    99             pSelf = NULL;
    99             pSelf = NULL;
   100             return NULL;
   100             return NULL;
   101         }
   101             }
   102 		res = mmf_set_play_adapt_context(pSelf->mmfContext, &(pSelf->baseObj));
   102         res = mmf_set_play_adapt_context(pSelf->mmfContext,
   103 		if(pDataSrc)
   103                         &(pSelf->baseObj));
   104 		    {
   104         if (pDataSrc)
   105              pSelf->mmfMetadataContext = mmf_metadata_utility_init((char *)(( (XADataLocator_URI*)(pDataSrc->pLocator))->URI));
   105             {
   106              if(!pSelf->mmfMetadataContext)
   106             pSelf->mmfMetadataContext
   107                 {
   107                     = mmf_metadata_utility_init(
   108                     DEBUG_ERR("Failed to init mmf metadata context!!!");
   108                             (char *) (((XADataLocator_URI*) (pDataSrc->pLocator))->URI));
   109                     pSelf->mmfMetadataContext = NULL;			
   109             if (!pSelf->mmfMetadataContext)
   110                 }
   110                 {
   111 		    }
   111                 DEBUG_ERR("Failed to init mmf metadata context!!!");
   112 		else
   112                 pSelf->mmfMetadataContext = NULL;
   113         	{
   113                 }
   114         	DEBUG_ERR("Failed to create XAMediaPlayerAdaptationMMFCtx !!!");
   114             }
   115         	return NULL;
   115         else
   116         	}	
   116             {
   117     }
   117             DEBUG_ERR("Failed to create XAMediaPlayerAdaptationMMFCtx !!!");
       
   118             return NULL;
       
   119             }
       
   120         }
   118 
   121 
   119     DEBUG_API("<-XAMediaPlayerAdaptMMF_Create");
   122     DEBUG_API("<-XAMediaPlayerAdaptMMF_Create");
   120     return (XAAdaptationBaseCtx*)(&pSelf->baseObj.baseObj);
   123     return (XAAdaptationBaseCtx*) (&pSelf->baseObj.baseObj);
   121 }
   124     }
   122 
   125 
   123 
   126 /*
       
   127  * XAMediaPlayerAdaptationMMFCtx* XAMediaPlayerAdapt_CreateRadio()
       
   128 
       
   129  * @returns XAMediaPlayerAdaptationMMFCtx* - Pointer to created context, NULL if error occurs.
       
   130  */
       
   131 XAAdaptationBaseCtx* XAMediaPlayerAdaptMMF_CreateRadio(
       
   132         XAMediaPlayerAdaptationMMFCtx *pSelf, XADataSource *pDataSrc,
       
   133         XADataSource *pBankSrc, XADataSink *pAudioSnk,
       
   134         XADataSink *pImageVideoSnk, XADataSink *pVibra, XADataSink *pLEDArray)
       
   135     {
       
   136     XAresult res;
       
   137     DEBUG_API("->XAMediaPlayerAdaptMMF_CreateRadio");
       
   138 
       
   139     res = XAAdaptationBaseMMF_Init(&(pSelf->baseObj), XARadioAdaptation);
       
   140     if (res != XA_RESULT_SUCCESS)
       
   141         {
       
   142         DEBUG_ERR("Failed to init base context!!!");
       
   143         free(pSelf);
       
   144         pSelf = NULL;
       
   145         return NULL;
       
   146         }
       
   147 
       
   148     pSelf->isForRadio = XA_BOOLEAN_TRUE;
       
   149     pSelf->baseObj.baseObj.fwtype = FWMgrFWMMF;
       
   150     pSelf->xaSource = pDataSrc;
       
   151     pSelf->xaBankSrc = pBankSrc;
       
   152     pSelf->xaAudioSink = pAudioSnk;
       
   153     pSelf->xaVideoSink = pImageVideoSnk;
       
   154     pSelf->xaLEDArray = pLEDArray;
       
   155     pSelf->xaVibra = pVibra;
       
   156     pSelf->curMirror = XA_VIDEOMIRROR_NONE;
       
   157     pSelf->curRotation = 0;
       
   158     pSelf->isobjsrc = XA_BOOLEAN_FALSE;
       
   159     pSelf->cameraSinkSynced = XA_BOOLEAN_FALSE;
       
   160     /*pSelf->waitData = XA_BOOLEAN_FALSE;*/
       
   161 
       
   162     res = mmf_backend_engine_init(&(pSelf->mmfContext));
       
   163     if (!(pSelf->mmfContext) || (res != XA_RESULT_SUCCESS))
       
   164         {
       
   165         /* TODO Check to make sure there is no undeleted MMF objects here*/
       
   166         DEBUG_ERR("Failed to init mmf context!!!");
       
   167         free(pSelf);
       
   168         pSelf = NULL;
       
   169         return NULL;
       
   170         }DEBUG_API("<-XAMediaPlayerAdaptMMF_Create");
       
   171     return (XAAdaptationBaseCtx*) (&pSelf->baseObj.baseObj);
       
   172     }
   124 
   173 
   125 /*
   174 /*
   126  * XAresult XAMediaPlayerAdaptMMF_PostInit()
   175  * XAresult XAMediaPlayerAdaptMMF_PostInit()
   127  * 2nd phase initialization of Media Player Adaptation Context
   176  * 2nd phase initialization of Media Player Adaptation Context
   128  * @param XAMediaPlayerAdaptationMMFCtx* ctx - pointer to Media Player adaptation context
   177  * @param XAMediaPlayerAdaptationMMFCtx* ctx - pointer to Media Player adaptation context
   129  * @return XAresult - Success value
   178  * @return XAresult - Success value
   130  */
   179  */
   131 XAresult XAMediaPlayerAdaptMMF_PostInit( XAAdaptationMMFCtx* bCtx )
   180 XAresult XAMediaPlayerAdaptMMF_PostInit(XAAdaptationMMFCtx* bCtx)
   132 {
   181     {
   133     XAresult ret = XA_RESULT_PRECONDITIONS_VIOLATED;
   182     XAresult ret = XA_RESULT_PRECONDITIONS_VIOLATED;
   134     XAMediaPlayerAdaptationMMFCtx *pSelf = (XAMediaPlayerAdaptationMMFCtx*)bCtx;
   183     XAMediaPlayerAdaptationMMFCtx *pSelf = NULL;
       
   184     if(!bCtx)
       
   185         {
       
   186         ret = XA_RESULT_PARAMETER_INVALID;
       
   187         return ret;
       
   188         }
       
   189     
       
   190     pSelf = (XAMediaPlayerAdaptationMMFCtx*) bCtx;
   135 
   191 
   136     DEBUG_API("->XAMediaPlayerAdaptMMF_PostInit");
   192     DEBUG_API("->XAMediaPlayerAdaptMMF_PostInit");
       
   193 
       
   194     ret = XAAdaptationBaseMMF_PostInit(bCtx);
       
   195     if(ret == XA_RESULT_SUCCESS)
       
   196         {
       
   197         if (pSelf->isForRadio)
       
   198             {
       
   199             DEBUG_API("<-XAMediaPlayerAdaptMMF_PostInit");
       
   200             return XA_RESULT_SUCCESS;
       
   201             }
   137     
   202     
   138     XAAdaptationBaseMMF_PostInit(bCtx);
   203         if (pSelf->mmfContext)
   139     
   204             {
   140     if(pSelf->mmfContext)
   205             XADataLocator_URI* tempUri =
   141     {
   206                     (XADataLocator_URI*) (pSelf->xaSource->pLocator);
   142         XADataLocator_URI* tempUri = (XADataLocator_URI*)(pSelf->xaSource->pLocator);
   207             XADataFormat_MIME* tempFormat =
   143         XADataFormat_MIME* tempFormat = (XADataFormat_MIME*)(pSelf->xaSource->pFormat);
   208                     (XADataFormat_MIME*) (pSelf->xaSource->pFormat);
   144         ret = XA_RESULT_SUCCESS;
   209             ret = XA_RESULT_SUCCESS;
   145         if(pSelf->xaVideoSink)
   210             if (pSelf->xaVideoSink)
   146           {
   211                 {
   147           ret = mmf_setup_native_display(pSelf->mmfContext, pSelf->xaVideoSink);
   212                 ret = mmf_setup_native_display(pSelf->mmfContext,
   148           }
   213                         pSelf->xaVideoSink);
   149         if (ret == XA_RESULT_SUCCESS)
   214                 }
   150         {
   215             if (ret == XA_RESULT_SUCCESS)
   151             ret = mmf_set_player_uri(pSelf->mmfContext, (char *)(tempUri->URI), tempFormat->containerType);
   216                 {
   152         }
   217                 ret = mmf_set_player_uri(pSelf->mmfContext,
   153     }
   218                         (char *) (tempUri->URI), tempFormat->containerType);
       
   219                 }
       
   220             }
       
   221         }
   154     DEBUG_API("<-XAMediaPlayerAdaptMMF_PostInit");
   222     DEBUG_API("<-XAMediaPlayerAdaptMMF_PostInit");
   155     return ret;
   223     return ret;
   156 }
   224     }
   157 
   225 
   158 /*
   226 /*
   159  * void XAMediaPlayerAdaptMMF_Destroy( XAMediaPlayerAdaptationMMFCtx* ctx )
   227  * void XAMediaPlayerAdaptMMF_Destroy( XAMediaPlayerAdaptationMMFCtx* ctx )
   160  * Destroys Media Player Adaptation Context
   228  * Destroys Media Player Adaptation Context
   161  * @param ctx - Media Player Adaptation context to be destroyed
   229  * @param ctx - Media Player Adaptation context to be destroyed
   162  */
   230  */
   163 void XAMediaPlayerAdaptMMF_Destroy( XAAdaptationMMFCtx* bCtx )
   231 void XAMediaPlayerAdaptMMF_Destroy(XAAdaptationMMFCtx* bCtx)
   164 {
   232     {
   165     XAMediaPlayerAdaptationMMFCtx* ctx = NULL;
   233     XAMediaPlayerAdaptationMMFCtx* ctx = NULL;
   166 
   234 
   167     
       
   168     DEBUG_API("->XAMediaPlayerAdaptMMF_Destroy");
   235     DEBUG_API("->XAMediaPlayerAdaptMMF_Destroy");
   169     if(bCtx == NULL)
   236     if (bCtx == NULL)
   170     {
   237         {
   171         DEBUG_ERR("Invalid parameter!!");
   238         DEBUG_ERR("Invalid parameter!!");
   172         DEBUG_API("<-XAMediaPlayerAdaptMMF_Destroy");
   239         DEBUG_API("<-XAMediaPlayerAdaptMMF_Destroy");
   173         return;
   240         return;
   174     }
   241         }
   175     ctx = (XAMediaPlayerAdaptationMMFCtx*)bCtx;
   242     ctx = (XAMediaPlayerAdaptationMMFCtx*) bCtx;
   176 
   243 
   177     if(ctx->mmfContext)
   244     if (ctx->mmfContext)
   178         {
   245         {
   179         mmf_backend_engine_deinit(ctx->mmfContext);
   246         mmf_backend_engine_deinit(ctx->mmfContext);
   180         }
   247         }
   181 
   248 
   182 	if(ctx->mmfMetadataContext)
   249     if (ctx->mmfMetadataContext)
   183 	{
   250         {
   184 		mmf_metadata_utility_destroy(ctx->mmfMetadataContext);		
   251         mmf_metadata_utility_destroy(ctx->mmfMetadataContext);
   185 	}
   252         }
   186 	
   253 
   187     XAAdaptationBaseMMF_Free( bCtx );
   254     XAAdaptationBaseMMF_Free(bCtx);
   188     
   255 
   189     free(ctx);
   256     free(ctx);
   190     ctx = NULL;
   257     ctx = NULL;
   191 
   258 
   192     DEBUG_API("<-XAMediaPlayerAdaptMMF_Destroy");
   259     DEBUG_API("<-XAMediaPlayerAdaptMMF_Destroy");
   193 }
   260     }
   194 
   261 
   195