khronosfws/openmax_al/src/common/xavolumeitf.c
changeset 25 6f7ceef7b1d1
parent 19 4a629bc82c5e
child 33 5e8b14bae8c3
--- a/khronosfws/openmax_al/src/common/xavolumeitf.c	Fri May 28 19:26:28 2010 -0500
+++ b/khronosfws/openmax_al/src/common/xavolumeitf.c	Fri Jun 11 19:59:23 2010 -0500
@@ -1,26 +1,26 @@
 /*
-* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
-* All rights reserved.
-* This component and the accompanying materials are made available
-* under the terms of "Eclipse Public License v1.0"
-* which accompanies this distribution, and is available
-* at the URL "http://www.eclipse.org/legal/epl-v10.html".
-*
-* Initial Contributors:
-* Nokia Corporation - initial contribution.
-*
-* Contributors:
-*
-* Description: 
-*
-*/
+ * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+ * All rights reserved.
+ * This component and the accompanying materials are made available
+ * under the terms of "Eclipse Public License v1.0"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ *
+ * Initial Contributors:
+ * Nokia Corporation - initial contribution.
+ *
+ * Contributors:
+ *
+ * Description: Volume Interface Implementation
+ *
+ */
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <assert.h>
 
 #include "xavolumeitf.h"
- 
+
 #include "xavolumeitfadaptation.h"
 #include "xanokiavolumeextitfadaptationmmf.h"
 /**
@@ -28,17 +28,17 @@
  * Description: Validated interface pointer and cast it to implementations pointer.
  **/
 static XAVolumeItfImpl* GetImpl(XAVolumeItf self)
-{
-    if(self)
     {
-        XAVolumeItfImpl* impl = (XAVolumeItfImpl*)(*self);
-        if(impl && impl == impl->self)
+    if (self)
         {
+        XAVolumeItfImpl* impl = (XAVolumeItfImpl*) (*self);
+        if (impl && impl == impl->self)
+            {
             return impl;
+            }
         }
+    return NULL;
     }
-    return NULL;
-}
 
 /**
  * Base interface XAVolumeItf implementation
@@ -49,7 +49,7 @@
  * Description: Sets the object's volume level.
  **/
 XAresult XAVolumeItfImpl_SetVolumeLevel(XAVolumeItf self, XAmillibel level)
-{
+    {
     XAVolumeItfImpl *impl = GetImpl(self);
     XAresult ret = XA_RESULT_SUCCESS;
 
@@ -57,102 +57,105 @@
     DEBUG_API("->XAVolumeItfImpl_SetVolumeLevel");
 
     /* check maximum volume level */
-    if(XAVolumeItfImpl_GetMaxVolumeLevel(self, &maximumLevel) != XA_RESULT_SUCCESS)
-    {
+    if (XAVolumeItfImpl_GetMaxVolumeLevel(self, &maximumLevel)
+            != XA_RESULT_SUCCESS)
+        {
         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
         DEBUG_API("<-XAVolumeItfImpl_SetVolumeLevel");
         /* cannot solve maximum volume level */
         return XA_RESULT_PARAMETER_INVALID;
-    }
+        }
 
-    if(!impl || level > maximumLevel)
-    {
+    if (!impl || level > maximumLevel || !impl->adapCtx)
+        {
         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
         DEBUG_API("<-XAVolumeItfImpl_SetVolumeLevel");
         /* invalid parameter */
         return XA_RESULT_PARAMETER_INVALID;
-    }
+        }
 
- 
     ret = XAAdaptationBase_ThreadEntry(impl->adapCtx);
-    if( ret == XA_RESULT_PARAMETER_INVALID || ret == XA_RESULT_PRECONDITIONS_VIOLATED )
-    {
+    if (ret == XA_RESULT_PARAMETER_INVALID || ret
+            == XA_RESULT_PRECONDITIONS_VIOLATED)
+        {
         DEBUG_API("<-XAVolumeItfImpl_SetVolumeLevel");
         return ret;
-    }
-    if(impl->adapCtx->fwtype == FWMgrFWGST)
+        }
+    if (impl->adapCtx->fwtype == FWMgrFWGST)
         {
-        ret = XAVolumeItfAdapt_SetVolumeLevel((XAAdaptationGstCtx*)impl->adapCtx,  level);
+        ret = XAVolumeItfAdapt_SetVolumeLevel(
+                (XAAdaptationGstCtx*) impl->adapCtx, level);
         }
     else
         {
         impl->volumeLevel = level;
         }
-    
-    if(ret == XA_RESULT_SUCCESS)
-    {
+
+    if (ret == XA_RESULT_SUCCESS)
+        {
         impl->volumeLevel = level;
-    }
+        }
 
     XAAdaptationBase_ThreadExit(impl->adapCtx);
 
     DEBUG_API("<-XAVolumeItfImpl_SetVolumeLevel");
-    return ret ;
-}
+    return ret;
+    }
 
 /**
  * XAresult XAVolumeItfImpl_GetVolumeLevel(XAVolumeItf self, XAmillibel *pLevel)
  * Description: Gets the object’s volume level.
  **/
 XAresult XAVolumeItfImpl_GetVolumeLevel(XAVolumeItf self, XAmillibel *pLevel)
-{
+    {
     XAresult ret = XA_RESULT_SUCCESS;
     XAVolumeItfImpl *impl = GetImpl(self);
     DEBUG_API("->XAVolumeItfImpl_GetVolumeLevel");
 
-    if(!impl || !pLevel)
-    {
+    if (!impl || !pLevel)
+        {
         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
         DEBUG_API("<-XAVolumeItfImpl_GetVolumeLevel");
         /* invalid parameter */
         return XA_RESULT_PARAMETER_INVALID;
-    }
+        }
 
     *pLevel = impl->volumeLevel;
 
     DEBUG_API("<-XAVolumeItfImpl_GetVolumeLevel");
     return ret;
-}
+    }
 
 /**
  * XAresult XAVolumeItfImpl_GetMaxVolumeLevel(XAVolumeItf  self, XAmillibel *pMaxLevel)
  * Description: Gets the maximum supported level.
  **/
-XAresult XAVolumeItfImpl_GetMaxVolumeLevel(XAVolumeItf  self, XAmillibel *pMaxLevel)
-{
+XAresult XAVolumeItfImpl_GetMaxVolumeLevel(XAVolumeItf self,
+        XAmillibel *pMaxLevel)
+    {
     XAresult ret = XA_RESULT_SUCCESS;
     XAVolumeItfImpl *impl = GetImpl(self);
     DEBUG_API("->XAVolumeItfImpl_GetVolumeLevel");
 
-    if(!impl || !pMaxLevel)
-    {
+    if (!impl || !pMaxLevel || !impl->adapCtx)
+        {
         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
         DEBUG_API("<-XAVolumeItfImpl_GetMaxVolumeLevel");
         /* invalid parameter */
         return XA_RESULT_PARAMETER_INVALID;
-    }
+        }
 
- 
     ret = XAAdaptationBase_ThreadEntry(impl->adapCtx);
-    if( ret == XA_RESULT_PARAMETER_INVALID || ret == XA_RESULT_PRECONDITIONS_VIOLATED )
-    {
+    if (ret == XA_RESULT_PARAMETER_INVALID || ret
+            == XA_RESULT_PRECONDITIONS_VIOLATED)
+        {
         DEBUG_API("<-XAVolumeItfImpl_GetMaxVolumeLevel");
         return ret;
-    }
-    if(impl->adapCtx->fwtype == FWMgrFWGST)
+        }
+    if (impl->adapCtx->fwtype == FWMgrFWGST)
         {
-        ret = XAVolumeItfAdapt_GetMaxVolumeLevel((XAAdaptationGstCtx*)impl->adapCtx,
-                                                 pMaxLevel);
+        ret = XAVolumeItfAdapt_GetMaxVolumeLevel(
+                (XAAdaptationGstCtx*) impl->adapCtx, pMaxLevel);
         }
     else
         {
@@ -163,130 +166,133 @@
 
     DEBUG_API("<-XAVolumeItfImpl_GetMaxVolumeLevel");
     return ret;
-}
+    }
 
 /**
  * XAresult XAVolumeItfImpl_SetMute(XAVolumeItf self, XAboolean mute)
  * Description: Mutes or unmutes the object.
  **/
 XAresult XAVolumeItfImpl_SetMute(XAVolumeItf self, XAboolean mute)
-{
+    {
     XAresult ret = XA_RESULT_SUCCESS;
     XAVolumeItfImpl *impl = GetImpl(self);
     DEBUG_API("->XAVolumeItfImpl_SetMute");
 
-    if(!impl)
-    {
+    if (!impl || !impl->adapCtx)
+        {
         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
         DEBUG_API("<-XAVolumeItfImpl_SetMute");
         /* invalid parameter */
         return XA_RESULT_PARAMETER_INVALID;
-    }
+        }
 
- 
     ret = XAAdaptationBase_ThreadEntry(impl->adapCtx);
-    if( ret == XA_RESULT_PARAMETER_INVALID || ret == XA_RESULT_PRECONDITIONS_VIOLATED )
-    {
+    if (ret == XA_RESULT_PARAMETER_INVALID || ret
+            == XA_RESULT_PRECONDITIONS_VIOLATED)
+        {
         DEBUG_API("<-XAVolumeItfImpl_SetMute");
         return ret;
-    }
+        }
     /* check is mute state changed */
-    if(mute != impl->mute)
-    {
-        if(impl->adapCtx->fwtype == FWMgrFWMMF)
+    if (mute != impl->mute)
+        {
+        if (impl->adapCtx->fwtype == FWMgrFWMMF)
             {
-            ret = XANokiaVolumeExtItfAdapt_SetMute((XAAdaptationMMFCtx*)impl->adapCtx,  mute);
+            ret = XANokiaVolumeExtItfAdapt_SetMute(
+                    (XAAdaptationMMFCtx*) impl->adapCtx, mute);
             }
         else
             {
-            ret = XAVolumeItfAdapt_SetMute((XAAdaptationGstCtx*)impl->adapCtx,  mute);
+            ret = XAVolumeItfAdapt_SetMute(
+                    (XAAdaptationGstCtx*) impl->adapCtx, mute);
             }
 
-        if(ret == XA_RESULT_SUCCESS)
-        {
+        if (ret == XA_RESULT_SUCCESS)
+            {
             impl->mute = mute;
+            }
         }
-    }
 
     XAAdaptationBase_ThreadExit(impl->adapCtx);
 
     DEBUG_API("<-XAVolumeItfImpl_SetMute");
     return ret;
-}
+    }
 
 /**
  * XAresult XAVolumeItfImpl_GetMute(XAVolumeItf self, XAboolean *pMute)
  * Description: Retrieves the object's state.
  **/
 XAresult XAVolumeItfImpl_GetMute(XAVolumeItf self, XAboolean *pMute)
-{
+    {
     XAresult ret = XA_RESULT_SUCCESS;
     XAVolumeItfImpl *impl = GetImpl(self);
     DEBUG_API("->XAVolumeItfImpl_GetMute");
 
-    if(!impl || !pMute)
-    {
+    if (!impl || !pMute)
+        {
         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
         DEBUG_API("<-XAVolumeItfImpl_GetMute");
         /* invalid parameter */
         return XA_RESULT_PARAMETER_INVALID;
-    }
+        }
 
     *pMute = impl->mute;
 
     DEBUG_API("<-XAVolumeItfImpl_GetMute");
     return ret;
-}
+    }
 
 /**
  * XAresult XAVolumeItfImpl_EnableStereoPosition(XAVolumeItf self, XAboolean enable)
  * Description: Enables or disables the stereo positioning effect.
  **/
-XAresult XAVolumeItfImpl_EnableStereoPosition(XAVolumeItf self, XAboolean enable)
-{
+XAresult XAVolumeItfImpl_EnableStereoPosition(XAVolumeItf self,
+        XAboolean enable)
+    {
     XAresult ret = XA_RESULT_SUCCESS;
     XAVolumeItfImpl *impl = GetImpl(self);
     DEBUG_API("->XAVolumeItfImpl_EnableStereoPosition");
 
-    if(!impl)
-    {
+    if (!impl || !impl->adapCtx)
+        {
         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
         DEBUG_API("<-XAVolumeItfImpl_EnableStereoPosition");
         /* invalid parameter */
         return XA_RESULT_PARAMETER_INVALID;
-    }
+        }
 
- 
     ret = XAAdaptationBase_ThreadEntry(impl->adapCtx);
-    if( ret == XA_RESULT_PARAMETER_INVALID || ret == XA_RESULT_PRECONDITIONS_VIOLATED )
-    {
+    if (ret == XA_RESULT_PARAMETER_INVALID || ret
+            == XA_RESULT_PRECONDITIONS_VIOLATED)
+        {
         DEBUG_API("<-XAVolumeItfImpl_EnableStereoPosition");
         return ret;
-    }
-    /* Check is stereo position state changed */
-    if(enable != impl->enableStereoPos)
-    {
-    if(impl->adapCtx->fwtype == FWMgrFWGST)
-        {
-        ret = XAVolumeItfAdapt_EnableStereoPosition((XAAdaptationGstCtx*)impl->adapCtx,
-                                                    enable);
         }
-    else
+    /* Check is stereo position state changed */
+    if (enable != impl->enableStereoPos)
         {
-        ret = XANokiaVolumeExtItfAdapt_EnableStereoPosition((XAAdaptationMMFCtx*)impl->adapCtx,
-                                                    enable);    
+        if (impl->adapCtx->fwtype == FWMgrFWGST)
+            {
+            ret = XAVolumeItfAdapt_EnableStereoPosition(
+                    (XAAdaptationGstCtx*) impl->adapCtx, enable);
+            }
+        else
+            {
+            ret = XANokiaVolumeExtItfAdapt_EnableStereoPosition(
+                    (XAAdaptationMMFCtx*) impl->adapCtx, enable);
+            }
+        if (ret == XA_RESULT_SUCCESS)
+            {
+            impl->enableStereoPos = enable;
+            }
         }
-        if(ret == XA_RESULT_SUCCESS)
-        {
-            impl->enableStereoPos = enable;
-        }
-    }
 
     XAAdaptationBase_ThreadExit(impl->adapCtx);
 
     DEBUG_API("<-XAVolumeItfImpl_EnableStereoPosition");
     return ret;
-}
+    }
 
 /**
  * XAresult XAVolumeItfImpl_IsEnabledStereoPosition(XAVolumeItf self,
@@ -294,25 +300,25 @@
  * Description: Returns the enabled state of the stereo positioning effect.
  **/
 XAresult XAVolumeItfImpl_IsEnabledStereoPosition(XAVolumeItf self,
-                                                 XAboolean *pEnable)
-{
+        XAboolean *pEnable)
+    {
     XAresult ret = XA_RESULT_SUCCESS;
     XAVolumeItfImpl *impl = GetImpl(self);
     DEBUG_API("->XAVolumeItfImpl_IsEnabledStereoPosition");
 
-    if(!impl || !pEnable)
-    {
+    if (!impl || !pEnable)
+        {
         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
         DEBUG_API("<-XAVolumeItfImpl_IsEnabledStereoPosition");
         /* invalid parameter */
         return XA_RESULT_PARAMETER_INVALID;
-    }
+        }
 
     *pEnable = impl->enableStereoPos;
 
     DEBUG_API("<-XAVolumeItfImpl_IsEnabledStereoPosition");
     return ret;
-}
+    }
 
 /**
  * XAresult XAVolumeItfImpl_SetStereoPosition(XAVolumeItf self,
@@ -320,50 +326,50 @@
  * Description: Sets the stereo position of the object.
  **/
 XAresult XAVolumeItfImpl_SetStereoPosition(XAVolumeItf self,
-                                           XApermille stereoPosition)
-{
+        XApermille stereoPosition)
+    {
     XAresult ret = XA_RESULT_SUCCESS;
     XAVolumeItfImpl *impl = GetImpl(self);
     DEBUG_API("->XAVolumeItfImpl_SetStereoPosition");
 
-    if(!impl || (stereoPosition < STEREO_POSITION_LEFT) ||
-        (stereoPosition > STEREO_POSITION_RIGHT))
-    {
+    if (!impl || (stereoPosition < STEREO_POSITION_LEFT) || (stereoPosition
+            > STEREO_POSITION_RIGHT) || !impl->adapCtx)
+        {
         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
         DEBUG_API("<-XAVolumeItfImpl_SetStereoPosition");
         /* invalid parameter */
         return XA_RESULT_PARAMETER_INVALID;
-    }
+        }
 
     impl->stereoPosition = stereoPosition;
 
- 
     ret = XAAdaptationBase_ThreadEntry(impl->adapCtx);
-    if( ret == XA_RESULT_PARAMETER_INVALID || ret == XA_RESULT_PRECONDITIONS_VIOLATED )
-    {
+    if (ret == XA_RESULT_PARAMETER_INVALID || ret
+            == XA_RESULT_PRECONDITIONS_VIOLATED)
+        {
         DEBUG_API("<-XAVolumeItfImpl_SetStereoPosition");
         return ret;
-    }
+        }
     /* check is stereo position effect enabled if is then handle effect */
-    if(impl->enableStereoPos)
-    {
-    if(impl->adapCtx->fwtype == FWMgrFWGST)
+    if (impl->enableStereoPos)
         {
-        ret = XAVolumeItfAdapt_SetStereoPosition((XAAdaptationGstCtx*)impl->adapCtx,
-                                                 stereoPosition);
+        if (impl->adapCtx->fwtype == FWMgrFWGST)
+            {
+            ret = XAVolumeItfAdapt_SetStereoPosition(
+                    (XAAdaptationGstCtx*) impl->adapCtx, stereoPosition);
+            }
+        else
+            {
+            ret = XANokiaVolumeExtItfAdapt_SetStereoPosition(
+                    (XAAdaptationMMFCtx*) impl->adapCtx, stereoPosition);
+            }
         }
-    else
-        {
-        ret = XANokiaVolumeExtItfAdapt_SetStereoPosition((XAAdaptationMMFCtx*)impl->adapCtx,
-                                                 stereoPosition);    
-        }
-    }
 
     XAAdaptationBase_ThreadExit(impl->adapCtx);
 
     DEBUG_API("<-XAVolumeItfImpl_SetStereoPosition");
     return ret;
-}
+    }
 
 /**
  * XAresult XAVolumeItfImpl_GetStereoPosition(XAVolumeItf self,
@@ -371,50 +377,50 @@
  * Description: Gets the object’s stereo position setting.
  **/
 XAresult XAVolumeItfImpl_GetStereoPosition(XAVolumeItf self,
-                                           XApermille *pStereoPosition)
-{
+        XApermille *pStereoPosition)
+    {
     XAresult ret = XA_RESULT_SUCCESS;
     XAVolumeItfImpl *impl = GetImpl(self);
     DEBUG_API("->XAVolumeItfImpl_GetStereoPosition");
 
-    if(!impl || !pStereoPosition)
-    {
+    if (!impl || !pStereoPosition)
+        {
         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
         DEBUG_API("<-XAVolumeItfImpl_GetStereoPosition");
         /* invalid parameter */
         return XA_RESULT_PARAMETER_INVALID;
-    }
+        }
 
     *pStereoPosition = impl->stereoPosition;
 
     DEBUG_API("<-XAVolumeItfImpl_GetStereoPosition");
     return ret;
-}
+    }
 
 /**
  * XAVolumeItfImpl -specific methods
  **/
 
-
 /**
  * XAVolumeItfImpl* XAVolumeItfImpl_Create()
  * Description: Allocate and initialize VolumeItfImpl
  **/
-XAVolumeItfImpl* XAVolumeItfImpl_Create(XAAdaptationBaseCtx *adapCtx )
-{
-    XAVolumeItfImpl *self = (XAVolumeItfImpl*)
-        calloc(1,sizeof(XAVolumeItfImpl));
+XAVolumeItfImpl* XAVolumeItfImpl_Create(XAAdaptationBaseCtx *adapCtx)
+    {
+    XAVolumeItfImpl *self = (XAVolumeItfImpl*) calloc(1,
+            sizeof(XAVolumeItfImpl));
     DEBUG_API("->XAVolumeItfImpl_Create");
 
-    if(self)
-    {
+    if (self)
+        {
         /* init itf default implementation */
         self->itf.EnableStereoPosition = XAVolumeItfImpl_EnableStereoPosition;
         self->itf.GetMaxVolumeLevel = XAVolumeItfImpl_GetMaxVolumeLevel;
         self->itf.GetMute = XAVolumeItfImpl_GetMute;
         self->itf.GetStereoPosition = XAVolumeItfImpl_GetStereoPosition;
         self->itf.GetVolumeLevel = XAVolumeItfImpl_GetVolumeLevel;
-        self->itf.IsEnabledStereoPosition = XAVolumeItfImpl_IsEnabledStereoPosition;
+        self->itf.IsEnabledStereoPosition
+                = XAVolumeItfImpl_IsEnabledStereoPosition;
         self->itf.SetMute = XAVolumeItfImpl_SetMute;
         self->itf.SetStereoPosition = XAVolumeItfImpl_SetStereoPosition;
         self->itf.SetVolumeLevel = XAVolumeItfImpl_SetVolumeLevel;
@@ -428,20 +434,20 @@
         self->adapCtx = adapCtx;
 
         self->self = self;
-    }
+        }
 
     DEBUG_API("<-XAVolumeItfImpl_Create");
     return self;
-}
+    }
 
 /**
  * void XAVolumeItfImpl_Free(XAVolumeItfImpl* self)
  * Description: Free all resources reserved at XAVolumeItfImpl_Create
  **/
 void XAVolumeItfImpl_Free(XAVolumeItfImpl* self)
-{
+    {
     DEBUG_API("->XAVolumeItfImpl_Free");
     assert(self==self->self);
     free(self);
     DEBUG_API("<-XAVolumeItfImpl_Free");
-}
+    }