khronosfws/openmax_al/src/gst_adaptation/xadevicevolumeitfadaptation.c
changeset 16 43d09473c595
child 20 b67dd1fc57c5
equal deleted inserted replaced
14:80975da52420 16:43d09473c595
       
     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 <gst.h>
       
    19 #include <mixer.h>
       
    20 #include "xadevicevolumeitfadaptation.h"
       
    21 #include "xaengineadaptctx.h"
       
    22 #include "xaadaptationgst.h"
       
    23 //#include "XAStaticCapsAdaptation.h"
       
    24 
       
    25 
       
    26 /* XAresult XADeviceVolumeItfAdapt_SetVolume
       
    27  * Description: Sets the device's volume.
       
    28  */
       
    29 XAresult XADeviceVolumeItfAdapt_SetVolume(XAAdaptationGstCtx *bCtx, XAuint32 deviceID, XAint32 volume)
       
    30 {
       
    31     XAEngineAdaptationCtx* ctx = NULL;
       
    32     GstElement* amixer = NULL;
       
    33     GstMixerTrack *mixerTrack = NULL;
       
    34     const GList *gList = NULL;
       
    35     gint volumeIdx = 0;
       
    36 
       
    37     DEBUG_API("->XADeviceVolumeItfAdapt_SetVolume");
       
    38 
       
    39     if(!bCtx )
       
    40     {
       
    41         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
       
    42         DEBUG_API("<-XADeviceVolumeItfAdapt_SetVolume");
       
    43         return XA_RESULT_PARAMETER_INVALID;
       
    44     }
       
    45 
       
    46     ctx = (XAEngineAdaptationCtx*) bCtx;
       
    47 
       
    48     amixer = gst_bin_get_by_name( GST_BIN(ctx->baseObj.bin), "alsamixer");
       
    49     if( !amixer )
       
    50     {
       
    51         DEBUG_ERR("XA_RESULT_INTERNAL_ERROR");
       
    52         DEBUG_API("<-XADeviceVolumeItfAdapt_SetVolume");
       
    53         return XA_RESULT_INTERNAL_ERROR;
       
    54     }
       
    55 
       
    56     gList = gst_mixer_list_tracks( GST_MIXER(amixer) );
       
    57     if( !gList )
       
    58     {
       
    59         DEBUG_ERR("XA_RESULT_INTERNAL_ERROR");
       
    60         DEBUG_API("<-XADeviceVolumeItfAdapt_SetVolume");
       
    61         return XA_RESULT_INTERNAL_ERROR;
       
    62     }
       
    63 
       
    64     while( gList )
       
    65     {
       
    66         mixerTrack = (GstMixerTrack*)gList->data;
       
    67         if( !mixerTrack )
       
    68         {
       
    69             DEBUG_ERR("XA_RESULT_INTERNAL_ERROR");
       
    70             DEBUG_API("<-XADeviceVolumeItfAdapt_SetVolume");
       
    71             return XA_RESULT_INTERNAL_ERROR;
       
    72         }
       
    73 
       
    74         if( ((mixerTrack->flags & GST_MIXER_TRACK_INPUT ) && deviceID == XA_DEFAULTDEVICEID_AUDIOINPUT) ||
       
    75 //            ((mixerTrack->flags & GST_MIXER_TRACK_INPUT ) && deviceID == XA_ADAPTID_ALSASRC) || //krishna
       
    76                 ((mixerTrack->flags & GST_MIXER_TRACK_INPUT ) && deviceID == XA_ADAPTID_DEVSOUNDSRC) ||
       
    77             ((mixerTrack->flags & GST_MIXER_TRACK_INPUT ) && deviceID == XA_ADAPTID_AUDIOTESTSRC) ||
       
    78             ((mixerTrack->flags & GST_MIXER_TRACK_OUTPUT ) && deviceID == XA_DEFAULTDEVICEID_AUDIOOUTPUT) ||
       
    79             ((mixerTrack->flags & GST_MIXER_TRACK_OUTPUT ) && deviceID == XA_ADAPTID_JACKSINK) ||
       
    80 //            ((mixerTrack->flags & GST_MIXER_TRACK_OUTPUT ) && deviceID == XA_ADAPTID_ALSASINK) )
       
    81             ((mixerTrack->flags & GST_MIXER_TRACK_OUTPUT ) && deviceID == XA_ADAPTID_DEVSOUNDSINK) )
       
    82         {
       
    83             gint *gVolume = (gint*) calloc(mixerTrack->num_channels, sizeof(gint) );
       
    84             if( !gVolume )
       
    85             {
       
    86                 DEBUG_ERR("XA_RESULT_MEMORY_FAILURE");
       
    87                 DEBUG_API("<-XADeviceVolumeItfAdapt_SetVolume");
       
    88                 return XA_RESULT_MEMORY_FAILURE;
       
    89             }
       
    90 
       
    91             for( volumeIdx = 0; volumeIdx < mixerTrack->num_channels; volumeIdx++ )
       
    92             {
       
    93                 /* Set same volume level for all channels */
       
    94                 gVolume[volumeIdx] = (gint)volume;
       
    95             }
       
    96 
       
    97             /* found master track */
       
    98             gst_mixer_set_volume( GST_MIXER(amixer), mixerTrack, gVolume );
       
    99             free( gVolume );
       
   100             gVolume = NULL;
       
   101             break;
       
   102         }
       
   103         gList = g_list_next(gList);
       
   104     }
       
   105     if ( amixer )
       
   106     {
       
   107         gst_object_unref( GST_OBJECT(amixer));
       
   108     }
       
   109 
       
   110     DEBUG_API("<-XADeviceVolumeItfAdapt_SetVolume");
       
   111     return XA_RESULT_SUCCESS;
       
   112 }
       
   113 
       
   114 /* XAresult XADeviceVolumeItfAdapt_IsDeviceIDSupported
       
   115  * Description: Check is request device ID supported.
       
   116  */
       
   117 XAresult XADeviceVolumeItfAdapt_IsDeviceIDSupported(XAAdaptationGstCtx *bCtx, XAuint32 deviceID, XAboolean *isSupported)
       
   118 {
       
   119     DEBUG_API("->XADeviceVolumeItfAdapt_IsDeviceIDSupported");
       
   120 
       
   121     if(!bCtx || !isSupported )
       
   122     {
       
   123         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
       
   124         DEBUG_API("<-XADeviceVolumeItfAdapt_IsDeviceIDSupported");
       
   125         return XA_RESULT_PARAMETER_INVALID;
       
   126     }
       
   127 
       
   128     /* check is device ID supported or not supported */
       
   129 //    if( deviceID == XA_DEFAULTDEVICEID_AUDIOINPUT || deviceID == XA_ADAPTID_ALSASRC ||
       
   130     if( deviceID == XA_DEFAULTDEVICEID_AUDIOINPUT || deviceID == XA_ADAPTID_DEVSOUNDSRC ||
       
   131         deviceID == XA_ADAPTID_AUDIOTESTSRC || deviceID == XA_DEFAULTDEVICEID_AUDIOOUTPUT ||
       
   132 //        deviceID == XA_ADAPTID_JACKSINK || deviceID == XA_ADAPTID_ALSASINK )
       
   133         deviceID == XA_ADAPTID_JACKSINK || deviceID == XA_ADAPTID_DEVSOUNDSINK )
       
   134     {
       
   135         *isSupported = XA_BOOLEAN_TRUE;
       
   136     }
       
   137     else
       
   138     {
       
   139         *isSupported = XA_BOOLEAN_FALSE;
       
   140     }
       
   141 
       
   142     DEBUG_API("<-XADeviceVolumeItfAdapt_IsDeviceIDSupported");
       
   143     return XA_RESULT_SUCCESS;
       
   144 }