khronosfws/openmax_al/src/outputmix/xaoutputmixitf.c
changeset 42 1fa3fb47b1e3
parent 32 94fc26b6e006
child 47 c2e43643db4c
equal deleted inserted replaced
32:94fc26b6e006 42:1fa3fb47b1e3
     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 "xaoutputmixitf.h"
       
    19 
       
    20 #include "xaoutputmixitfadaptation.h"
       
    21 
       
    22 #include <assert.h>
       
    23 #include "xathreadsafety.h"
       
    24 #include "e32def.h"
       
    25 /**
       
    26  * XAOutputMixtfImpl* GetImpl(XAOutputMixtfImpl self)
       
    27  * Description: Validated interface pointer and cast it to implementations pointer.
       
    28  **/
       
    29 static XAOutputMixItfImpl* GetImpl(XAOutputMixItf self)
       
    30 {
       
    31     if(self)
       
    32     {
       
    33         XAOutputMixItfImpl* impl = (XAOutputMixItfImpl*)(*self);
       
    34         if(impl && impl == impl->self)
       
    35         {
       
    36             return impl;
       
    37         }
       
    38     }
       
    39     return NULL;
       
    40 }
       
    41 
       
    42 /**
       
    43  * Base interface XAOutputMixtf implementation
       
    44  */
       
    45 
       
    46 /*
       
    47  * XAresult XAOutputMixItfImpl_GetDestinationOutputDeviceIDs( XAOutputMixItf self,
       
    48  *                                                          XAint32 * pNumDevices,
       
    49  *                                                          XAuint32 * pDeviceIDs )
       
    50  * Description: Retrieves the device IDs of the destination output devices currently
       
    51  * associated with the output mix.
       
    52  */
       
    53 XAresult XAOutputMixItfImpl_GetDestinationOutputDeviceIDs( XAOutputMixItf self, XAint32 * pNumDevices, XAuint32 * pDeviceIDs )
       
    54 {
       
    55     XAresult ret = XA_RESULT_SUCCESS;
       
    56     XAOutputMixItfImpl* impl = GetImpl(self);
       
    57     DEBUG_API_A1("->XAOutputMixItfImpl_GetDestinationOutputDeviceIDs - pNumDevices %ld",*pNumDevices);
       
    58     XA_IMPL_THREAD_SAFETY_ENTRY(XATSOutputMix);
       
    59     if(!impl || !pNumDevices  )
       
    60     {
       
    61         /* invalid parameter */
       
    62         XA_IMPL_THREAD_SAFETY_EXIT(XATSOutputMix);
       
    63         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
       
    64         DEBUG_API("<-XAOutputMixItfImpl_GetDestinationOutputDeviceIDs");
       
    65         return XA_RESULT_PARAMETER_INVALID;
       
    66     }
       
    67 
       
    68 
       
    69     ret = XAOutputMixItfAdapt_GetDestinationOutputDeviceIDs((XAAdaptationGstCtx*)impl->adapCtx, pNumDevices, pDeviceIDs );
       
    70 
       
    71     XA_IMPL_THREAD_SAFETY_EXIT(XATSOutputMix);
       
    72     DEBUG_API_A1("<-XAOutputMixItfImpl_GetDestinationOutputDeviceIDs - pNumDevices %ld",*pNumDevices);
       
    73     return ret;
       
    74 }
       
    75 
       
    76 /*
       
    77  * XAresult XAOutputMixItfImpl_RegisterDeviceChangeCallback( XAOutputMixItf self,
       
    78  *                                                          xaMixDeviceChangeCallback callback,
       
    79  *                                                          void * pContext)
       
    80  * Description: Registers a callback to notify client when there are changes to the
       
    81  * device IDs associated with the output mix.
       
    82  */
       
    83 XAresult XAOutputMixItfImpl_RegisterDeviceChangeCallback( XAOutputMixItf self, xaMixDeviceChangeCallback callback, void * pContext)
       
    84 {
       
    85    XAresult ret = XA_RESULT_SUCCESS;
       
    86    XAOutputMixItfImpl* impl = GetImpl(self);
       
    87    DEBUG_API("->XAOutputMixItfImpl_RegisterDeviceChangeCallback");
       
    88    if(!impl)
       
    89    {
       
    90        /* invalid parameter */
       
    91        DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
       
    92        DEBUG_API("<-XAOutputMixItfImpl_RegisterDeviceChangeCallback");
       
    93        return XA_RESULT_PARAMETER_INVALID;
       
    94    }
       
    95 
       
    96    /* callback may be NULL (to remove callback) */
       
    97    impl->callback = callback;
       
    98    impl->cbContext = pContext;
       
    99    impl->cbPtrToSelf = self;
       
   100 
       
   101    if(callback)
       
   102    {   /* start listening */
       
   103        XAAdaptationBase_AddEventHandler( impl->adapCtx, &XAOutputMixItfImpl_AdaptCb, XA_OUTPUTMIXITFEVENTS, (void*)self );
       
   104    }
       
   105    else
       
   106    {   /* stop listening */
       
   107        XAAdaptationBase_RemoveEventHandler( impl->adapCtx, &XAOutputMixItfImpl_AdaptCb );
       
   108    }
       
   109 
       
   110 
       
   111    DEBUG_API("<-XAOutputMixItfImpl_RegisterDeviceChangeCallback");
       
   112    return ret;
       
   113 }
       
   114 
       
   115 /*
       
   116  * XAresult XAOutputMixItfImpl_ReRoute( XAOutputMixItf self,
       
   117  *                                      XAint32 numOutputDevices,
       
   118  *                                      XAuint32 * pOutputDeviceIDs)
       
   119  * Description: Requests a change to the specified set of output devices on an output mix.
       
   120  */
       
   121 XAresult XAOutputMixItfImpl_ReRoute( XAOutputMixItf self, XAint32 numOutputDevices, XAuint32 * pOutputDeviceIDs)
       
   122 {
       
   123    XAresult ret = XA_RESULT_SUCCESS;
       
   124    XAOutputMixItfImpl* impl = GetImpl(self);
       
   125 
       
   126    DEBUG_API("->XAOutputMixItfImpl_ReRoute");
       
   127    XA_IMPL_THREAD_SAFETY_ENTRY(XATSOutputMix);
       
   128 
       
   129    if(!impl || ( numOutputDevices > 0 && !pOutputDeviceIDs) )
       
   130    {
       
   131        /* invalid parameter */
       
   132        XA_IMPL_THREAD_SAFETY_EXIT(XATSOutputMix);
       
   133        DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
       
   134        DEBUG_API("<-XAOutputMixItfImpl_ReRoute");
       
   135        return XA_RESULT_PARAMETER_INVALID;
       
   136    }
       
   137 
       
   138 
       
   139    ret = XAOutputMixItfAdapt_ReRoute((XAAdaptationGstCtx*)impl->adapCtx, numOutputDevices, pOutputDeviceIDs );
       
   140 
       
   141 
       
   142    XA_IMPL_THREAD_SAFETY_EXIT(XATSOutputMix);
       
   143    DEBUG_API("<-XAOutputMixItfImpl_ReRoute");
       
   144    return ret;
       
   145 
       
   146 }
       
   147 
       
   148 /**
       
   149  * XAVolumeItfImpl -specific methods
       
   150  **/
       
   151 
       
   152 
       
   153 /*
       
   154  * XAOutputMixItfImpl* XAOutputMixItfImpl_Create(XAAdaptationBaseCtx *adapCtx)
       
   155  * Description: Creates new Output mix itf implmementation
       
   156  */
       
   157 XAOutputMixItfImpl* XAOutputMixItfImpl_Create(XAAdaptationBaseCtx *adapCtx)
       
   158 {
       
   159    XAOutputMixItfImpl *self = (XAOutputMixItfImpl*)
       
   160         calloc(1,sizeof(XAOutputMixItfImpl));
       
   161    DEBUG_API("->XAVolumeItfImpl_Create");
       
   162 
       
   163     if(self)
       
   164     {
       
   165         /* init itf default implementation */
       
   166         self->itf.GetDestinationOutputDeviceIDs = XAOutputMixItfImpl_GetDestinationOutputDeviceIDs;
       
   167         self->itf.RegisterDeviceChangeCallback = XAOutputMixItfImpl_RegisterDeviceChangeCallback;
       
   168         self->itf.ReRoute = XAOutputMixItfImpl_ReRoute;
       
   169 
       
   170         /* init variables */
       
   171         self->adapCtx = adapCtx;
       
   172         self->callback = NULL;
       
   173         self->cbContext = NULL;
       
   174         self->cbPtrToSelf = NULL;
       
   175 
       
   176         self->self = self;
       
   177     }
       
   178 
       
   179     DEBUG_API("<-XAVolumeItfImpl_Create");
       
   180     return self;
       
   181 }
       
   182 
       
   183 /*
       
   184  * void XAOutputMixItfImpl_Free(XAOutputMixItfImpl* self)
       
   185  * Description: Frees XAOutputMixItfImpl
       
   186  */
       
   187 void XAOutputMixItfImpl_Free(XAOutputMixItfImpl* self)
       
   188 {
       
   189     DEBUG_API("->XAOutputMixItfImpl_Free");
       
   190     assert(self==self->self);
       
   191     if( self->callback )
       
   192     {
       
   193         XAAdaptationBase_RemoveEventHandler( self->adapCtx, &XAOutputMixItfImpl_AdaptCb );
       
   194     }
       
   195     free(self);
       
   196     DEBUG_API("<-XAOutputMixItfImpl_Free");
       
   197 }
       
   198 
       
   199 
       
   200 
       
   201 /* void XAOutputMixItfImpl_AdaptCb( void *pHandlerCtx,
       
   202  *                                  XAAdaptEvent *event )
       
   203  * Description: Listen changes in adaptation
       
   204  */
       
   205 void XAOutputMixItfImpl_AdaptCb( void *pHandlerCtx, XAAdaptEvent *event )
       
   206 {
       
   207      XAOutputMixItfImpl* impl = (XAOutputMixItfImpl*)pHandlerCtx;
       
   208      DEBUG_API("->XAOutputMixItfImpl_AdaptCb");
       
   209 
       
   210      if(!impl)
       
   211      {
       
   212         DEBUG_ERR("XAOutputMixItfImpl_AdaptCb, invalid context pointer!");
       
   213         return;
       
   214      }
       
   215      assert(event);
       
   216 
       
   217      /* send callback if needed.
       
   218       * Check event-id to avoid sending incorrect events. */
       
   219      if( (event->eventid==XA_ADAPT_OMIX_DEVICESET_CHANGED) && impl->callback )
       
   220      {
       
   221         impl->callback(impl->cbPtrToSelf, impl->cbContext);
       
   222      }
       
   223 
       
   224      DEBUG_API("<-XAOutputMixItfImpl_AdaptCb");
       
   225 }
       
   226