khronosfws/openmax_al/src/engine/xadevicevolumeitf.c
changeset 33 5e8b14bae8c3
parent 28 ebf79c79991a
child 36 73253677b50a
equal deleted inserted replaced
28:ebf79c79991a 33:5e8b14bae8c3
     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 "xaglobals.h"
       
    22 #include "xadevicevolumeitf.h"
       
    23   
       
    24 #include "xadevicevolumeitfadaptation.h"
       
    25 
       
    26 
       
    27 static XADeviceVolumeItfImpl* GetImpl(XADeviceVolumeItf self)
       
    28 {
       
    29     if( self )
       
    30     {
       
    31         XADeviceVolumeItfImpl* impl = (XADeviceVolumeItfImpl*)(*self);
       
    32         if( impl && (impl == impl->self) )
       
    33         {
       
    34             return impl;
       
    35         }
       
    36     }
       
    37     return NULL;
       
    38 }
       
    39 
       
    40 /**
       
    41  * Base interface XADeviceVolumeItf implementation
       
    42  */
       
    43 
       
    44 /* XAresult XADeviceVolumeItfImpl_GetVolumeScale( XADeviceVolumeItf self,
       
    45  *                                                XAuint32 deviceID,
       
    46  *                                                XAint32* pMinValue,
       
    47  *                                                XAint32* pMaxValue,
       
    48  *                                                XAboolean* pIsMillibelScale)
       
    49  * Description: Gets the properties of the volume scale supported by the given device.
       
    50  */
       
    51 XAresult XADeviceVolumeItfImpl_GetVolumeScale( XADeviceVolumeItf self,
       
    52                                                XAuint32 deviceID,
       
    53                                                XAint32* pMinValue,
       
    54                                                XAint32* pMaxValue,
       
    55                                                XAboolean* pIsMillibelScale)
       
    56 {
       
    57     XADeviceVolumeItfImpl* impl = GetImpl(self);
       
    58     XAresult ret = XA_RESULT_SUCCESS;
       
    59     XAboolean supported = XA_BOOLEAN_FALSE;
       
    60     DEBUG_API("->XADeviceVolumeItfImpl_GetVolumeScale");
       
    61     if( !impl || !pMinValue || !pMaxValue || !pIsMillibelScale )
       
    62     {
       
    63         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
       
    64         DEBUG_API("<-XADeviceVolumeItfImpl_GetVolumeScale");
       
    65         return XA_RESULT_PARAMETER_INVALID;
       
    66     }
       
    67 
       
    68   
       
    69     ret = XADeviceVolumeItfAdapt_IsDeviceIDSupported((XAAdaptationGstCtx*)impl->adapCtx, deviceID, &supported);
       
    70 
       
    71     if( ret != XA_RESULT_SUCCESS || supported != XA_BOOLEAN_TRUE )
       
    72     {
       
    73         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
       
    74         DEBUG_API("<-XADeviceVolumeItfImpl_GetVolumeScale");
       
    75         return XA_RESULT_PARAMETER_INVALID;
       
    76     }
       
    77 
       
    78     *pMinValue = impl->minVolume;
       
    79     *pMaxValue = impl->maxVolume;
       
    80     *pIsMillibelScale = impl->ismBscale;
       
    81 
       
    82     DEBUG_API("<-XADeviceVolumeItfImpl_GetVolumeScale");
       
    83     return ret;
       
    84 }
       
    85 
       
    86 /* XAresult XADeviceVolumeItfImpl_SetVolume( XADeviceVolumeItf self,
       
    87  *                                           XAuint32 deviceID,
       
    88  *                                           XAint32 volume)
       
    89  * Description: Sets the device's volume.
       
    90  */
       
    91 XAresult XADeviceVolumeItfImpl_SetVolume( XADeviceVolumeItf self,
       
    92                                           XAuint32 deviceID,
       
    93                                           XAint32 volume)
       
    94 {
       
    95     XADeviceVolumeItfImpl* impl = GetImpl(self);
       
    96     XAresult ret = XA_RESULT_SUCCESS;
       
    97   
       
    98     XAboolean supported = XA_BOOLEAN_FALSE;
       
    99 
       
   100     DEBUG_API("->XADeviceVolumeItfImpl_SetVolume");
       
   101 
       
   102     if( !impl || volume < impl->minVolume || volume > impl->maxVolume )
       
   103     {
       
   104         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
       
   105         DEBUG_API("<-XADeviceVolumeItfImpl_SetVolume");
       
   106         return XA_RESULT_PARAMETER_INVALID;
       
   107     }
       
   108 
       
   109   
       
   110     ret = XADeviceVolumeItfAdapt_IsDeviceIDSupported((XAAdaptationGstCtx*)impl->adapCtx, deviceID, &supported);
       
   111     if( ret != XA_RESULT_SUCCESS || supported != XA_BOOLEAN_TRUE )
       
   112     {
       
   113         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
       
   114         DEBUG_API("<-XADeviceVolumeItfImpl_SetVolume");
       
   115         return XA_RESULT_PARAMETER_INVALID;
       
   116     }
       
   117 
       
   118     ret = XADeviceVolumeItfAdapt_SetVolume((XAAdaptationGstCtx*)impl->adapCtx, deviceID, volume);
       
   119 
       
   120     if( ret == XA_RESULT_SUCCESS )
       
   121     {
       
   122         impl->curVolume = volume;
       
   123     }
       
   124 
       
   125     DEBUG_API("<-XADeviceVolumeItfImpl_SetVolume");
       
   126     return ret;
       
   127 }
       
   128 
       
   129 /* XAresult XADeviceVolumeItfImpl_GetVolume( XADeviceVolumeItf self,
       
   130  *                                           XAuint32 deviceID,
       
   131  *                                           XAint32 * pVolume)
       
   132  * Description: Gets the device's volume.
       
   133  */
       
   134 XAresult XADeviceVolumeItfImpl_GetVolume( XADeviceVolumeItf self,
       
   135                                           XAuint32 deviceID,
       
   136                                           XAint32 * pVolume)
       
   137 {
       
   138     XADeviceVolumeItfImpl* impl = GetImpl(self);
       
   139     XAresult ret = XA_RESULT_SUCCESS;
       
   140     XAboolean supported = XA_BOOLEAN_FALSE;
       
   141     DEBUG_API("->XADeviceVolumeItfImpl_GetVolume");
       
   142 
       
   143     if( !impl || !pVolume )
       
   144     {
       
   145         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
       
   146         DEBUG_API("<-XADeviceVolumeItfImpl_GetVolume");
       
   147         return XA_RESULT_PARAMETER_INVALID;
       
   148     }
       
   149 
       
   150   
       
   151     ret = XADeviceVolumeItfAdapt_IsDeviceIDSupported((XAAdaptationGstCtx*)impl->adapCtx, deviceID, &supported);
       
   152 
       
   153     if( ret != XA_RESULT_SUCCESS || supported != XA_BOOLEAN_TRUE )
       
   154     {
       
   155         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
       
   156         DEBUG_API("<-XADeviceVolumeItfImpl_GetVolume");
       
   157         return XA_RESULT_PARAMETER_INVALID;
       
   158     }
       
   159     *pVolume = impl->curVolume;
       
   160     DEBUG_API("<-XADeviceVolumeItfImpl_GetVolume");
       
   161     return XA_RESULT_SUCCESS;
       
   162 }
       
   163 
       
   164 /**
       
   165  * XADeviceVolumeItfImpl -specific methods
       
   166  **/
       
   167   
       
   168 /**
       
   169  * XADeviceVolumeItfImpl* XADeviceVolumeItfImpl_Create(XAAdaptationBaseCtx *adapCtx)
       
   170  * Description: Allocate and initialize DeviceVolumeImpl
       
   171  **/
       
   172 XADeviceVolumeItfImpl* XADeviceVolumeItfImpl_Create(XAAdaptationBaseCtx *adapCtx)
       
   173 {
       
   174     XADeviceVolumeItfImpl* self = (XADeviceVolumeItfImpl*)
       
   175         calloc(1,sizeof(XADeviceVolumeItfImpl));
       
   176     DEBUG_API("->XADeviceVolumeItfImpl_Create");
       
   177 
       
   178     if(self)
       
   179     {
       
   180         /* init itf default implementation */
       
   181         self->itf.GetVolumeScale =
       
   182             XADeviceVolumeItfImpl_GetVolumeScale;
       
   183         self->itf.GetVolume =
       
   184             XADeviceVolumeItfImpl_GetVolume;
       
   185         self->itf.SetVolume =
       
   186             XADeviceVolumeItfImpl_SetVolume;
       
   187 
       
   188         /* init variables */
       
   189         /* these values are replaced by adaptation in init phase */
       
   190         self->curVolume = DEFAULTDEVICEVOLUME;
       
   191         self->minVolume = DEFAULTDEVICEMINVOLUME;
       
   192         self->maxVolume = DEFAULTDEVICEMAXVOLUME;
       
   193         self->ismBscale = DEFAULTSCALEISMILLIBEL;
       
   194 
       
   195         self->adapCtx = adapCtx;
       
   196         self->self = self;
       
   197     }
       
   198     DEBUG_API("<-XADeviceVolumeItfImpl_Create");
       
   199     return self;
       
   200 }
       
   201 
       
   202 /* void XADeviceVolumeItfImpl_Free(XADeviceVolumeItfImpl* self)
       
   203  * Description: Free all resources reserved at XADeviceVolumeItfImpl_Create
       
   204  */
       
   205 void XADeviceVolumeItfImpl_Free(XADeviceVolumeItfImpl* self)
       
   206 {
       
   207     DEBUG_API("->XADeviceVolumeItfImpl_Free");
       
   208     assert(self==self->self);
       
   209     free(self);
       
   210     DEBUG_API("<-XADeviceVolumeItfImpl_Free");
       
   211 }