diff -r 80975da52420 -r 43d09473c595 khronosfws/openmax_al/src/gst_adaptation/xaequalizeritfadaptation.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/khronosfws/openmax_al/src/gst_adaptation/xaequalizeritfadaptation.c Fri May 14 16:22:35 2010 +0300 @@ -0,0 +1,268 @@ +/* +* 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: +* +*/ + +#include +#include "xaadaptationgst.h" +#include "xamediaplayeradaptctx.h" +#include "xamediarecorderadaptctx.h" +#include "xaoutputmixadaptctx.h" +#include "xaequalizeritfadaptation.h" +//#include "XAStaticCapsAdaptation.h" + +static const XAmilliHertz centerFrequencies[EQUALIZER_NUM_OF_BANDS] = { + 29000, 59000, 119000, 227000, 474000, + 947000, 1889000, 3770000, 7523000, 15011000 }; + +static const char* band_names[EQUALIZER_NUM_OF_BANDS] = { + "band0", "band1", "band2", "band3", "band4", + "band5", "band6", "band7", "band8", "band9" }; + +/*static const XAmilliHertz bandFreqRangeMin = 0; +static const XAmilliHertz bandFreqRangeMax = 0;*/ +static const XAmillibel bandLevelRangeMin = -2400; +static const XAmillibel bandLevelRangeMax = 1200; + + +/* + * XAresult XAEqualizerItfAdapt_GetBandLevelRange(XAAdaptationGstCtx *bCtx, + * XAmillibel *pMin, + * XAmillibel *pMax) + */ +XAresult XAEqualizerItfAdapt_GetBandLevelRange(XAAdaptationGstCtx *bCtx, + XAmillibel *pMin, + XAmillibel *pMax) +{ + XAresult ret = XA_RESULT_SUCCESS; + DEBUG_API("->XAEqualizerItfAdapt_GetBandLevelRange"); + + if( (!pMin && !pMax) ) /* other may be NULL */ + { + DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); + return XA_RESULT_PARAMETER_INVALID; + } + + if (pMin) + { + *pMin = bandLevelRangeMin; + } + if (pMax) + { + *pMax = bandLevelRangeMax; + } + + DEBUG_API("<-XAEqualizerItfAdapt_GetBandLevelRange"); + return ret; +} + +/* + * XAresult XAEqualizerItfAdapt_SetBandLevel(XAAdaptationGstCtx *bCtx, + * XAuint16 band, + * XAmillibel level) + */ +XAresult XAEqualizerItfAdapt_SetBandLevel(XAAdaptationGstCtx *bCtx, + XAuint16 band, + XAmillibel level) +{ + XAresult ret = XA_RESULT_SUCCESS; + GstElement *equ=NULL, *audiopp=NULL; + DEBUG_API("->XAEqualizerItfAdapt_SetBandLevel"); + + if(!bCtx || + band >= EQUALIZER_NUM_OF_BANDS || + level < bandLevelRangeMin || + level > bandLevelRangeMax) + { + DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); + return XA_RESULT_PARAMETER_INVALID; + } + else + { + if( bCtx->baseObj.ctxId == XAMediaPlayerAdaptation || bCtx->baseObj.ctxId == XAMediaRecorderAdaptation ) + { + audiopp = gst_bin_get_by_name( GST_BIN(bCtx->bin), "audiopp" ); + equ = gst_bin_get_by_name( GST_BIN(audiopp), "pp_equ" ); + if(equ) + { + g_object_set( G_OBJECT(equ), band_names[band], (gdouble)(level/1000), NULL ); + } + else + { + DEBUG_ERR("Media object equalizer element not found!!"); + } + } + else if( bCtx->baseObj.ctxId == XAOutputMixAdaptation ) + { + XAOutputMixAdaptationCtx* context = (XAOutputMixAdaptationCtx*) bCtx; + guint iterator; + for ( iterator = 0; iterator < context->connectedObjects->len; iterator++ ) + { + GstBin* basebin = GST_BIN(g_array_index(context->connectedObjects,XAOMixAdaptConnObj,iterator).ctx->bin); + equ=NULL; + audiopp=NULL; + audiopp = gst_bin_get_by_name( basebin, "audiopp" ); + if(audiopp) + { + equ = gst_bin_get_by_name( GST_BIN(audiopp), "pp_equ" ); + } + if(equ) + { + g_object_set( G_OBJECT(equ), band_names[band], (gdouble)(level/1000), NULL ); + } + else + { + DEBUG_ERR_A1("Could not find equalizer for player %u!!", iterator); + } + } + } + else + { + DEBUG_ERR_A1("Not supported adaptation element: %d", bCtx->baseObj.ctxId); + return XA_RESULT_PARAMETER_INVALID; + } + } + if(equ) + { + gst_object_unref(equ); + } + if(audiopp) + { + gst_object_unref(audiopp); + } + + DEBUG_API("<-XAEqualizerItfAdapt_SetBandLevel"); + return ret; +} + +/* + * XAresult XAEqualizerItfAdapt_GetCenterFreq(XAAdaptationGstCtx *bCtx, + * XAuint16 band, + * XAmilliHertz *pCenter) + */ + +XAresult XAEqualizerItfAdapt_GetCenterFreq(XAAdaptationGstCtx *bCtx, + XAuint16 band, + XAmilliHertz *pCenter) +{ + XAresult ret = XA_RESULT_SUCCESS; + DEBUG_API("->XAEqualizerItfAdapt_GetCenterFreq"); + + if(!pCenter || band >= EQUALIZER_NUM_OF_BANDS) + { + DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); + return XA_RESULT_PARAMETER_INVALID; + } + + *pCenter = centerFrequencies[band]; + + DEBUG_API("<-XAEqualizerItfAdapt_GetCenterFreq"); + return ret; +} + +/* + * XAresult XAEqualizerItfAdapt_GetBandFreqRange(XAAdaptationGstCtx *bCtx, + * XAuint16 band, + * XAmilliHertz *pMin, + * XAmilliHerts *pMax) + */ +XAresult XAEqualizerItfAdapt_GetBandFreqRange(XAAdaptationGstCtx *bCtx, + XAuint16 band, + XAmilliHertz *pMin, + XAmilliHertz *pMax) +{ + XAresult ret = XA_RESULT_SUCCESS; + DEBUG_API("->XAEqualizerItfAdapt_GetBandFreqRange"); + + /* pMin or pMax may be NULL */ + if((!pMin && !pMax) || band >= EQUALIZER_NUM_OF_BANDS) + { + DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); + return XA_RESULT_PARAMETER_INVALID; + } + + /* in this implementation there are no ranges */ + if (pMin) + { + *pMin = centerFrequencies[band]; + } + if (pMax) + { + *pMax = centerFrequencies[band]; + } + + DEBUG_API("<-XAEqualizerItfAdapt_GetBandFreqRange"); + return ret; +} + +/* + * XAresult XAEqualizerItfAdapt_GetBand(XAAdaptationGstCtx *bCtx, + * XAmilliHertz frequency, + * XAuint16 *pBand) + */ +XAresult XAEqualizerItfAdapt_GetBand(XAAdaptationGstCtx *bCtx, + XAmilliHertz frequency, + XAuint16 *pBand) +{ + XAuint16 index=0; + XAresult ret = XA_RESULT_SUCCESS; + DEBUG_API("->XAEqualizerItfAdapt_GetBand"); + + if(!pBand) + { + DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); + return XA_RESULT_PARAMETER_INVALID; + } + + *pBand = XA_EQUALIZER_UNDEFINED; + + /* as there are no ranges, it must match exactly */ + for (index = 0; index < EQUALIZER_NUM_OF_BANDS; index++) + { + if (frequency == centerFrequencies[index]) + { + *pBand = index; + break; + } + } + + DEBUG_API("<-XAEqualizerItfAdapt_GetBand"); + return ret; +} + +/* + * XAresult XAEqualizerItfAdapt_GetDefaultBandLevel(XAAdaptationGstCtx *bCtx, + * XAuint16 band, + * XAmillibel *pLevel) + */ +XAresult XAEqualizerItfAdapt_GetDefaultBandLevel(XAAdaptationGstCtx *bCtx, + XAuint16 band, + XAmillibel *pLevel) +{ + XAresult ret = XA_RESULT_SUCCESS; + DEBUG_API("->XAEqualizerItfAdapt_GetDefaultBandLevel"); + + if(!pLevel) + { + DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); + return XA_RESULT_PARAMETER_INVALID; + } + + pLevel = EQUALIZER_DEFAULT_BAND_LEVEL; + + DEBUG_API("<-XAEqualizerItfAdapt_GetDefaultBandLevel"); + return ret; +} +