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 "XAAdaptation.h" |
|
20 #include "XAMediaPlayerAdaptCtx.h" |
|
21 #include "XAMediaRecorderAdaptCtx.h" |
|
22 #include "XAOutputMixAdaptCtx.h" |
|
23 #include "XAEqualizerItfAdaptation.h" |
|
24 #include "XAStaticCapsAdaptation.h" |
|
25 |
|
26 static const XAmilliHertz centerFrequencies[EQUALIZER_NUM_OF_BANDS] = { |
|
27 29000, 59000, 119000, 227000, 474000, |
|
28 947000, 1889000, 3770000, 7523000, 15011000 }; |
|
29 |
|
30 static const char* band_names[EQUALIZER_NUM_OF_BANDS] = { |
|
31 "band0", "band1", "band2", "band3", "band4", |
|
32 "band5", "band6", "band7", "band8", "band9" }; |
|
33 |
|
34 static const XAmilliHertz bandFreqRangeMin = 0; |
|
35 static const XAmilliHertz bandFreqRangeMax = 0; |
|
36 static const XAmillibel bandLevelRangeMin = -2400; |
|
37 static const XAmillibel bandLevelRangeMax = 1200; |
|
38 |
|
39 |
|
40 /* |
|
41 * XAresult XAEqualizerItfAdapt_GetBandLevelRange(XAAdaptationBaseCtx *bCtx, |
|
42 * XAmillibel *pMin, |
|
43 * XAmillibel *pMax) |
|
44 */ |
|
45 XAresult XAEqualizerItfAdapt_GetBandLevelRange(XAAdaptationBaseCtx *bCtx, |
|
46 XAmillibel *pMin, |
|
47 XAmillibel *pMax) |
|
48 { |
|
49 XAresult ret = XA_RESULT_SUCCESS; |
|
50 DEBUG_API("->XAEqualizerItfAdapt_GetBandLevelRange"); |
|
51 |
|
52 if( (!pMin && !pMax) ) /* other may be NULL */ |
|
53 { |
|
54 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
55 return XA_RESULT_PARAMETER_INVALID; |
|
56 } |
|
57 |
|
58 if (pMin) |
|
59 { |
|
60 *pMin = bandLevelRangeMin; |
|
61 } |
|
62 if (pMax) |
|
63 { |
|
64 *pMax = bandLevelRangeMax; |
|
65 } |
|
66 |
|
67 DEBUG_API("<-XAEqualizerItfAdapt_GetBandLevelRange"); |
|
68 return ret; |
|
69 } |
|
70 |
|
71 /* |
|
72 * XAresult XAEqualizerItfAdapt_SetBandLevel(XAAdaptationBaseCtx *bCtx, |
|
73 * XAuint16 band, |
|
74 * XAmillibel level) |
|
75 */ |
|
76 XAresult XAEqualizerItfAdapt_SetBandLevel(XAAdaptationBaseCtx *bCtx, |
|
77 XAuint16 band, |
|
78 XAmillibel level) |
|
79 { |
|
80 XAresult ret = XA_RESULT_SUCCESS; |
|
81 GstElement *equ=NULL, *audiopp=NULL; |
|
82 DEBUG_API("->XAEqualizerItfAdapt_SetBandLevel"); |
|
83 |
|
84 if(!bCtx || |
|
85 band >= EQUALIZER_NUM_OF_BANDS || |
|
86 level < bandLevelRangeMin || |
|
87 level > bandLevelRangeMax) |
|
88 { |
|
89 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
90 return XA_RESULT_PARAMETER_INVALID; |
|
91 } |
|
92 else |
|
93 { |
|
94 if( bCtx->ctxId == XAMediaPlayerAdaptation || bCtx->ctxId == XAMediaRecorderAdaptation ) |
|
95 { |
|
96 audiopp = gst_bin_get_by_name( GST_BIN(bCtx->bin), "audiopp" ); |
|
97 equ = gst_bin_get_by_name( GST_BIN(audiopp), "pp_equ" ); |
|
98 if(equ) |
|
99 { |
|
100 g_object_set( G_OBJECT(equ), band_names[band], (gdouble)(level/1000), NULL ); |
|
101 } |
|
102 else |
|
103 { |
|
104 DEBUG_ERR("Media object equalizer element not found!!"); |
|
105 } |
|
106 } |
|
107 else if( bCtx->ctxId == XAOutputMixAdaptation ) |
|
108 { |
|
109 XAOutputMixAdaptationCtx* context = (XAOutputMixAdaptationCtx*) bCtx; |
|
110 guint iterator; |
|
111 for ( iterator = 0; iterator < context->connectedObjects->len; iterator++ ) |
|
112 { |
|
113 GstBin* basebin = GST_BIN(g_array_index(context->connectedObjects,XAOMixAdaptConnObj,iterator).ctx->bin); |
|
114 equ=NULL; |
|
115 audiopp=NULL; |
|
116 audiopp = gst_bin_get_by_name( basebin, "audiopp" ); |
|
117 if(audiopp) |
|
118 { |
|
119 equ = gst_bin_get_by_name( GST_BIN(audiopp), "pp_equ" ); |
|
120 } |
|
121 if(equ) |
|
122 { |
|
123 g_object_set( G_OBJECT(equ), band_names[band], (gdouble)(level/1000), NULL ); |
|
124 } |
|
125 else |
|
126 { |
|
127 DEBUG_ERR_A1("Could not find equalizer for player %u!!", iterator); |
|
128 } |
|
129 } |
|
130 } |
|
131 else |
|
132 { |
|
133 DEBUG_ERR_A1("Not supported adaptation element: %d", bCtx->ctxId); |
|
134 return XA_RESULT_PARAMETER_INVALID; |
|
135 } |
|
136 } |
|
137 if(equ) |
|
138 { |
|
139 gst_object_unref(equ); |
|
140 } |
|
141 if(audiopp) |
|
142 { |
|
143 gst_object_unref(audiopp); |
|
144 } |
|
145 |
|
146 DEBUG_API("<-XAEqualizerItfAdapt_SetBandLevel"); |
|
147 return ret; |
|
148 } |
|
149 |
|
150 /* |
|
151 * XAresult XAEqualizerItfAdapt_GetCenterFreq(XAAdaptationBaseCtx *bCtx, |
|
152 * XAuint16 band, |
|
153 * XAmilliHertz *pCenter) |
|
154 */ |
|
155 |
|
156 XAresult XAEqualizerItfAdapt_GetCenterFreq(XAAdaptationBaseCtx *bCtx, |
|
157 XAuint16 band, |
|
158 XAmilliHertz *pCenter) |
|
159 { |
|
160 XAresult ret = XA_RESULT_SUCCESS; |
|
161 DEBUG_API("->XAEqualizerItfAdapt_GetCenterFreq"); |
|
162 |
|
163 if(!pCenter || band >= EQUALIZER_NUM_OF_BANDS) |
|
164 { |
|
165 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
166 return XA_RESULT_PARAMETER_INVALID; |
|
167 } |
|
168 |
|
169 *pCenter = centerFrequencies[band]; |
|
170 |
|
171 DEBUG_API("<-XAEqualizerItfAdapt_GetCenterFreq"); |
|
172 return ret; |
|
173 } |
|
174 |
|
175 /* |
|
176 * XAresult XAEqualizerItfAdapt_GetBandFreqRange(XAAdaptationBaseCtx *bCtx, |
|
177 * XAuint16 band, |
|
178 * XAmilliHertz *pMin, |
|
179 * XAmilliHerts *pMax) |
|
180 */ |
|
181 XAresult XAEqualizerItfAdapt_GetBandFreqRange(XAAdaptationBaseCtx *bCtx, |
|
182 XAuint16 band, |
|
183 XAmilliHertz *pMin, |
|
184 XAmilliHertz *pMax) |
|
185 { |
|
186 XAresult ret = XA_RESULT_SUCCESS; |
|
187 DEBUG_API("->XAEqualizerItfAdapt_GetBandFreqRange"); |
|
188 |
|
189 /* pMin or pMax may be NULL */ |
|
190 if((!pMin && !pMax) || band >= EQUALIZER_NUM_OF_BANDS) |
|
191 { |
|
192 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
193 return XA_RESULT_PARAMETER_INVALID; |
|
194 } |
|
195 |
|
196 /* in this implementation there are no ranges */ |
|
197 if (pMin) |
|
198 { |
|
199 *pMin = centerFrequencies[band]; |
|
200 } |
|
201 if (pMax) |
|
202 { |
|
203 *pMax = centerFrequencies[band]; |
|
204 } |
|
205 |
|
206 DEBUG_API("<-XAEqualizerItfAdapt_GetBandFreqRange"); |
|
207 return ret; |
|
208 } |
|
209 |
|
210 /* |
|
211 * XAresult XAEqualizerItfAdapt_GetBand(XAAdaptationBaseCtx *bCtx, |
|
212 * XAmilliHertz frequency, |
|
213 * XAuint16 *pBand) |
|
214 */ |
|
215 XAresult XAEqualizerItfAdapt_GetBand(XAAdaptationBaseCtx *bCtx, |
|
216 XAmilliHertz frequency, |
|
217 XAuint16 *pBand) |
|
218 { |
|
219 XAuint16 index=0; |
|
220 XAresult ret = XA_RESULT_SUCCESS; |
|
221 DEBUG_API("->XAEqualizerItfAdapt_GetBand"); |
|
222 |
|
223 if(!pBand) |
|
224 { |
|
225 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
226 return XA_RESULT_PARAMETER_INVALID; |
|
227 } |
|
228 |
|
229 *pBand = XA_EQUALIZER_UNDEFINED; |
|
230 |
|
231 /* as there are no ranges, it must match exactly */ |
|
232 for (index = 0; index < EQUALIZER_NUM_OF_BANDS; index++) |
|
233 { |
|
234 if (frequency == centerFrequencies[index]) |
|
235 { |
|
236 *pBand = index; |
|
237 break; |
|
238 } |
|
239 } |
|
240 |
|
241 DEBUG_API("<-XAEqualizerItfAdapt_GetBand"); |
|
242 return ret; |
|
243 } |
|
244 |
|
245 /* |
|
246 * XAresult XAEqualizerItfAdapt_GetDefaultBandLevel(XAAdaptationBaseCtx *bCtx, |
|
247 * XAuint16 band, |
|
248 * XAmillibel *pLevel) |
|
249 */ |
|
250 XAresult XAEqualizerItfAdapt_GetDefaultBandLevel(XAAdaptationBaseCtx *bCtx, |
|
251 XAuint16 band, |
|
252 XAmillibel *pLevel) |
|
253 { |
|
254 XAresult ret = XA_RESULT_SUCCESS; |
|
255 DEBUG_API("->XAEqualizerItfAdapt_GetDefaultBandLevel"); |
|
256 |
|
257 if(!pLevel) |
|
258 { |
|
259 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
260 return XA_RESULT_PARAMETER_INVALID; |
|
261 } |
|
262 |
|
263 pLevel = EQUALIZER_DEFAULT_BAND_LEVEL; |
|
264 |
|
265 DEBUG_API("<-XAEqualizerItfAdapt_GetDefaultBandLevel"); |
|
266 return ret; |
|
267 } |
|
268 /* |
|
269 * XAresult XAEqualizerItfAdapt_ThreadEntry(XAAdaptationBaseCtx *adapCtx) |
|
270 * Description: Safety thread entry |
|
271 */ |
|
272 XAresult XAEqualizerItfAdapt_ThreadEntry(XAAdaptationBaseCtx *adaptCtx) |
|
273 { |
|
274 DEBUG_API("->XAEqualizerItfAdapt_ThreadEntry"); |
|
275 if((!adaptCtx ) ||( adaptCtx->ctxId != XAMediaPlayerAdaptation && |
|
276 adaptCtx->ctxId != XAMediaRecorderAdaptation && |
|
277 adaptCtx->ctxId != XAOutputMixAdaptation )) |
|
278 { |
|
279 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
280 DEBUG_API("<-XAEqualizerItfAdapt_ThreadEntry"); |
|
281 /* invalid parameter */ |
|
282 return XA_RESULT_PARAMETER_INVALID; |
|
283 |
|
284 } |
|
285 |
|
286 if ( adaptCtx->ctxId == XAMediaPlayerAdaptation ) |
|
287 { |
|
288 XA_IMPL_THREAD_SAFETY_ENTRY(XATSMediaPlayer); |
|
289 } |
|
290 else if( adaptCtx->ctxId == XAMediaRecorderAdaptation ) |
|
291 { |
|
292 XA_IMPL_THREAD_SAFETY_ENTRY(XATSMediaRecorder); |
|
293 } |
|
294 else if (adaptCtx->ctxId == XAOutputMixAdaptation ) |
|
295 { |
|
296 XA_IMPL_THREAD_SAFETY_ENTRY(XATSOutputMix); |
|
297 } |
|
298 |
|
299 DEBUG_API("<-XAEqualizerItfAdapt_ThreadEntry"); |
|
300 return XA_RESULT_SUCCESS; |
|
301 } |
|
302 /* |
|
303 * XAresult XAEqualizerItfAdapt_ThreadExit(XAAdaptationBaseCtx *adaptCtx) |
|
304 * Description: Safety thread exit |
|
305 */ |
|
306 XAresult XAEqualizerItfAdapt_ThreadExit(XAAdaptationBaseCtx *adaptCtx) |
|
307 { |
|
308 DEBUG_API("->XAEqualizerItfAdapt_ThreadExit"); |
|
309 if((!adaptCtx ) ||( adaptCtx->ctxId != XAMediaPlayerAdaptation && |
|
310 adaptCtx->ctxId != XAMediaRecorderAdaptation && |
|
311 adaptCtx->ctxId != XAOutputMixAdaptation )) |
|
312 { |
|
313 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
314 DEBUG_API("<-XAEqualizerItfAdapt_ThreadExit"); |
|
315 /* invalid parameter */ |
|
316 return XA_RESULT_PARAMETER_INVALID; |
|
317 |
|
318 } |
|
319 |
|
320 if ( adaptCtx->ctxId == XAMediaPlayerAdaptation ) |
|
321 { |
|
322 XA_IMPL_THREAD_SAFETY_EXIT(XATSMediaPlayer); |
|
323 } |
|
324 else if( adaptCtx->ctxId == XAMediaRecorderAdaptation ) |
|
325 { |
|
326 XA_IMPL_THREAD_SAFETY_EXIT(XATSMediaRecorder); |
|
327 } |
|
328 else if (adaptCtx->ctxId == XAOutputMixAdaptation ) |
|
329 { |
|
330 XA_IMPL_THREAD_SAFETY_EXIT(XATSOutputMix); |
|
331 } |
|
332 |
|
333 |
|
334 DEBUG_API("<-XAEqualizerItfAdapt_ThreadExit"); |
|
335 return XA_RESULT_SUCCESS; |
|
336 } |
|