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 "XACameraAdaptCtx.h" |
|
23 #include "XAImageControlsItfAdaptation.h" |
|
24 |
|
25 /* |
|
26 * XAresult XAImageControlsItfAdapt_SetBrightness(XAAdaptationBaseCtx *bCtx, |
|
27 * XAuint32 brightness) |
|
28 */ |
|
29 XAresult XAImageControlsItfAdapt_SetBrightness(XAAdaptationBaseCtx *bCtx, |
|
30 XAuint32 brightness) |
|
31 { |
|
32 XAresult ret = XA_RESULT_SUCCESS; |
|
33 |
|
34 gdouble gstBrightness = 0; |
|
35 XAint32 tempBrightness = 0; |
|
36 GstElement *balanceElement = NULL; |
|
37 DEBUG_API("->XAImageControlsItfAdapt_SetBrightness") |
|
38 |
|
39 if(!bCtx || (bCtx->ctxId != XAMediaPlayerAdaptation && bCtx->ctxId != XAMediaRecorderAdaptation |
|
40 && bCtx->ctxId != XACameraAdaptation)) |
|
41 { |
|
42 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
43 DEBUG_API("<-XAImageControlsItfAdapt_SetBrightness") |
|
44 return XA_RESULT_PARAMETER_INVALID; |
|
45 } |
|
46 |
|
47 if( bCtx->ctxId == XAMediaRecorderAdaptation ) |
|
48 { |
|
49 XAMediaRecorderAdaptationCtx* ctx = (XAMediaRecorderAdaptationCtx*) bCtx; |
|
50 |
|
51 balanceElement = gst_bin_get_by_name( GST_BIN(ctx->baseObj.bin), "pp_balance"); |
|
52 } |
|
53 if( bCtx->ctxId == XAMediaPlayerAdaptation ) |
|
54 { |
|
55 XAMediaPlayerAdaptationCtx* ctx = (XAMediaPlayerAdaptationCtx*) bCtx; |
|
56 |
|
57 balanceElement = gst_bin_get_by_name( GST_BIN(ctx->baseObj.bin), "pp_balance"); |
|
58 } |
|
59 if( bCtx->ctxId == XACameraAdaptation ) |
|
60 { |
|
61 XACameraAdaptationCtx* ctx = (XACameraAdaptationCtx*) bCtx; |
|
62 |
|
63 GstElement *videoPP = gst_bin_get_by_name( GST_BIN(ctx->baseObj.bin), "videopp_camera"); |
|
64 if ( !videoPP ) |
|
65 { |
|
66 DEBUG_ERR("Could not receive videopp from camerabin!"); |
|
67 } |
|
68 else |
|
69 { |
|
70 /* Get camera balance element */ |
|
71 balanceElement = gst_bin_get_by_name( GST_BIN(videoPP), "pp_balance"); |
|
72 } |
|
73 } |
|
74 |
|
75 /* count gstBrightness from XA contrast. Allowed values for gst is -1 to 1 |
|
76 * and allowed value for XA is 0 to 100 */ |
|
77 tempBrightness = brightness; |
|
78 |
|
79 gstBrightness = ( ((gdouble)tempBrightness - SCALE_VALUE_BRIGHTNESS) / SCALE_VALUE_BRIGHTNESS ); |
|
80 |
|
81 if(balanceElement) |
|
82 { |
|
83 g_object_set(G_OBJECT(balanceElement), "brightness", gstBrightness, NULL); |
|
84 |
|
85 if(bCtx->ctxId == XAMediaPlayerAdaptation) |
|
86 { |
|
87 ret = XAImageControlsItfAdapt_HandleImageType(bCtx); |
|
88 } |
|
89 } |
|
90 |
|
91 if ( balanceElement ) |
|
92 { |
|
93 gst_object_unref(balanceElement); |
|
94 } |
|
95 |
|
96 DEBUG_API("<-XAImageControlsItfAdapt_SetBrightness") |
|
97 return ret; |
|
98 } |
|
99 |
|
100 /* |
|
101 * XAresult XAImageControlsItfAdapt_SetContrast(XAAdaptationBaseCtx *bCtx, |
|
102 * XAuint32 contrast) |
|
103 */ |
|
104 XAresult XAImageControlsItfAdapt_SetContrast(XAAdaptationBaseCtx *bCtx, |
|
105 XAint32 contrast) |
|
106 { |
|
107 XAresult ret = XA_RESULT_SUCCESS; |
|
108 |
|
109 gdouble gstContrast = 1; |
|
110 GstElement *balanceElement = NULL; |
|
111 DEBUG_API("->XAImageControlsItfAdapt_SetContrast") |
|
112 |
|
113 if(!bCtx || (bCtx->ctxId != XAMediaPlayerAdaptation && bCtx->ctxId != XAMediaRecorderAdaptation |
|
114 && bCtx->ctxId != XACameraAdaptation)) |
|
115 { |
|
116 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
117 DEBUG_API("<-XAImageControlsItfAdapt_SetContrast") |
|
118 return XA_RESULT_PARAMETER_INVALID; |
|
119 } |
|
120 |
|
121 if( bCtx->ctxId == XAMediaPlayerAdaptation ) |
|
122 { |
|
123 XAMediaPlayerAdaptationCtx* ctx = (XAMediaPlayerAdaptationCtx*) bCtx; |
|
124 |
|
125 balanceElement = gst_bin_get_by_name( GST_BIN(ctx->baseObj.bin), "pp_balance"); |
|
126 } |
|
127 if( bCtx->ctxId == XAMediaRecorderAdaptation ) |
|
128 { |
|
129 XAMediaRecorderAdaptationCtx* ctx = (XAMediaRecorderAdaptationCtx*) bCtx; |
|
130 |
|
131 balanceElement = gst_bin_get_by_name( GST_BIN(ctx->baseObj.bin), "pp_balance"); |
|
132 } |
|
133 if( bCtx->ctxId == XACameraAdaptation ) |
|
134 { |
|
135 XACameraAdaptationCtx* ctx = (XACameraAdaptationCtx*) bCtx; |
|
136 |
|
137 GstElement *videoPP = gst_bin_get_by_name( GST_BIN(ctx->baseObj.bin), "videopp_camera"); |
|
138 if( !videoPP ) |
|
139 { |
|
140 DEBUG_ERR("Could not receive videopp from camerabin!"); |
|
141 } |
|
142 else |
|
143 { |
|
144 /* Get camera balance element */ |
|
145 balanceElement = gst_bin_get_by_name( GST_BIN(videoPP), "pp_balance"); |
|
146 } |
|
147 } |
|
148 |
|
149 /* count gstContrast from XA contrast. Allowed values for gst is 0 to 2 |
|
150 * and allowed value for XA is -100 to 100 */ |
|
151 gstContrast = (( (gdouble)contrast + SCALE_VALUE_CONTRAST ) / SCALE_VALUE_CONTRAST ); |
|
152 |
|
153 if(balanceElement) |
|
154 { |
|
155 g_object_set(G_OBJECT(balanceElement), "contrast", gstContrast, NULL); |
|
156 |
|
157 if(bCtx->ctxId == XAMediaPlayerAdaptation) |
|
158 { |
|
159 ret = XAImageControlsItfAdapt_HandleImageType(bCtx); |
|
160 } |
|
161 } |
|
162 |
|
163 if ( balanceElement ) |
|
164 { |
|
165 gst_object_unref(balanceElement); |
|
166 } |
|
167 |
|
168 DEBUG_API("<-XAImageControlsItfAdapt_SetContrast") |
|
169 return ret; |
|
170 } |
|
171 |
|
172 /* |
|
173 * XAresult XAImageControlsItfAdapt_SetGamma(XAAdaptationBaseCtx *bCtx, |
|
174 * XApermille gamma) |
|
175 */ |
|
176 XAresult XAImageControlsItfAdapt_SetGamma(XAAdaptationBaseCtx *bCtx, |
|
177 XApermille gamma) |
|
178 { |
|
179 XAresult ret = XA_RESULT_SUCCESS; |
|
180 |
|
181 gdouble gstGamma=0; |
|
182 GstElement *gammaElement = NULL; |
|
183 DEBUG_API("->XAImageControlsItfAdapt_SetGamma") |
|
184 |
|
185 if(!bCtx || (bCtx->ctxId != XAMediaPlayerAdaptation && bCtx->ctxId != XAMediaRecorderAdaptation |
|
186 && bCtx->ctxId != XACameraAdaptation)) |
|
187 { |
|
188 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
189 DEBUG_API("<-XAImageControlsItfAdapt_SetGamma") |
|
190 return XA_RESULT_PARAMETER_INVALID; |
|
191 } |
|
192 |
|
193 if( bCtx->ctxId == XAMediaPlayerAdaptation ) |
|
194 { |
|
195 XAMediaPlayerAdaptationCtx* ctx = (XAMediaPlayerAdaptationCtx*) bCtx; |
|
196 |
|
197 gammaElement = gst_bin_get_by_name( GST_BIN(ctx->baseObj.bin), "pp_gamma"); |
|
198 } |
|
199 |
|
200 if( bCtx->ctxId == XAMediaRecorderAdaptation ) |
|
201 { |
|
202 XAMediaRecorderAdaptationCtx* ctx = (XAMediaRecorderAdaptationCtx*) bCtx; |
|
203 |
|
204 gammaElement = gst_bin_get_by_name( GST_BIN(ctx->baseObj.bin), "pp_gamma"); |
|
205 } |
|
206 |
|
207 if( bCtx->ctxId == XACameraAdaptation ) |
|
208 { |
|
209 XACameraAdaptationCtx* ctx = (XACameraAdaptationCtx*) bCtx; |
|
210 |
|
211 GstElement *videoPP = gst_bin_get_by_name( GST_BIN(ctx->baseObj.bin), "videopp_camera"); |
|
212 if( !videoPP ) |
|
213 { |
|
214 DEBUG_ERR("Could not receive videopp from camerabin!"); |
|
215 } |
|
216 else |
|
217 { |
|
218 /* Get camera gamma element */ |
|
219 gammaElement = gst_bin_get_by_name( GST_BIN(videoPP), "pp_gamma"); |
|
220 } |
|
221 } |
|
222 |
|
223 /* count gstGamma from XA gamma */ |
|
224 gstGamma = ( (gdouble)gamma / SCALE_VALUE_GAMMA ); |
|
225 |
|
226 if(gammaElement) |
|
227 { |
|
228 g_object_set(G_OBJECT(gammaElement), "gamma", gstGamma, NULL); |
|
229 |
|
230 if(bCtx->ctxId == XAMediaPlayerAdaptation) |
|
231 { |
|
232 ret = XAImageControlsItfAdapt_HandleImageType(bCtx); |
|
233 } |
|
234 } |
|
235 |
|
236 if ( gammaElement ) |
|
237 { |
|
238 gst_object_unref(gammaElement); |
|
239 } |
|
240 |
|
241 DEBUG_API("<-XAImageControlsItfAdapt_SetGamma") |
|
242 return ret; |
|
243 } |
|
244 |
|
245 /* |
|
246 * XAresult XAImageControlsItfAdapt_GetSupportedGammaSettings(XAAdaptationBaseCtx *bCtx, |
|
247 * XApermille *pMinValue, |
|
248 * XApermille *pMaxValue, |
|
249 * XAuint32 *pNumSettings, |
|
250 * XApermille **ppSettings) |
|
251 */ |
|
252 XAresult XAImageControlsItfAdapt_GetSupportedGammaSettings(XAAdaptationBaseCtx *bCtx, |
|
253 XApermille *pMinValue, |
|
254 XApermille *pMaxValue, |
|
255 XAuint32 *pNumSettings, |
|
256 XApermille **ppSettings) |
|
257 { |
|
258 XAresult ret = XA_RESULT_SUCCESS; |
|
259 DEBUG_API("->XAImageControlsItfAdapt_GetSupportedGammaSettings") |
|
260 |
|
261 if(!bCtx || (bCtx->ctxId != XAMediaPlayerAdaptation && bCtx->ctxId != XAMediaRecorderAdaptation |
|
262 && bCtx->ctxId != XACameraAdaptation) || !pMinValue || !pMaxValue || !pNumSettings) |
|
263 { |
|
264 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
265 /* invalid parameter */ |
|
266 DEBUG_API("<-XAImageControlsItfAdapt_GetSupportedGammaSettings") |
|
267 return XA_RESULT_PARAMETER_INVALID; |
|
268 } |
|
269 |
|
270 *pMinValue = MIN_GAMMA_VALUE; |
|
271 *pMaxValue = MAX_GAMMA_VALUE; |
|
272 |
|
273 /* manual settings is continuous from min to max then pNumSetting return 0. */ |
|
274 *pNumSettings = 0; |
|
275 |
|
276 DEBUG_API("<-XAImageControlsItfAdapt_GetSupportedGammaSettings") |
|
277 return ret; |
|
278 } |
|
279 /* |
|
280 * XAresult XAImageControlsItfAdapt_ThreadEntry(XAAdaptationBaseCtx *adapCtx) |
|
281 * Description: Safety thread entry |
|
282 */ |
|
283 XAresult XAImageControlsItfAdapt_ThreadEntry(XAAdaptationBaseCtx *adaptCtx) |
|
284 { |
|
285 DEBUG_API("->XAImageControlsItfAdapt_ThreadEntry"); |
|
286 if((!adaptCtx ) ||( adaptCtx->ctxId != XAMediaPlayerAdaptation && |
|
287 adaptCtx->ctxId != XAMediaRecorderAdaptation && |
|
288 adaptCtx->ctxId != XACameraAdaptation )) |
|
289 { |
|
290 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
291 DEBUG_API("<-XAImageControlsItfAdapt_ThreadEntry"); |
|
292 /* invalid parameter */ |
|
293 return XA_RESULT_PARAMETER_INVALID; |
|
294 |
|
295 } |
|
296 |
|
297 if ( adaptCtx->ctxId == XAMediaPlayerAdaptation ) |
|
298 { |
|
299 XA_IMPL_THREAD_SAFETY_ENTRY(XATSMediaPlayer); |
|
300 } |
|
301 else if( adaptCtx->ctxId == XAMediaRecorderAdaptation ) |
|
302 { |
|
303 XA_IMPL_THREAD_SAFETY_ENTRY(XATSMediaRecorder); |
|
304 } |
|
305 else if (adaptCtx->ctxId == XACameraAdaptation ) |
|
306 { |
|
307 XA_IMPL_THREAD_SAFETY_ENTRY(XATSCamera); |
|
308 } |
|
309 |
|
310 DEBUG_API("<-XAImageControlsItfAdapt_ThreadEntry"); |
|
311 return XA_RESULT_SUCCESS; |
|
312 } |
|
313 /* |
|
314 * XAresult XAImageControlsItfAdapt_ThreadExit(XAAdaptationBaseCtx *adaptCtx) |
|
315 * Description: Safety thread exit |
|
316 */ |
|
317 XAresult XAImageControlsItfAdapt_ThreadExit(XAAdaptationBaseCtx *adaptCtx) |
|
318 { |
|
319 DEBUG_API("->XAImageControlsItfAdapt_ThreadExit"); |
|
320 if((!adaptCtx ) ||( adaptCtx->ctxId != XAMediaPlayerAdaptation && |
|
321 adaptCtx->ctxId != XAMediaRecorderAdaptation && |
|
322 adaptCtx->ctxId != XACameraAdaptation )) |
|
323 { |
|
324 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
325 DEBUG_API("<-XAImageControlsItfAdapt_ThreadExit"); |
|
326 /* invalid parameter */ |
|
327 return XA_RESULT_PARAMETER_INVALID; |
|
328 |
|
329 } |
|
330 |
|
331 if ( adaptCtx->ctxId == XAMediaPlayerAdaptation ) |
|
332 { |
|
333 XA_IMPL_THREAD_SAFETY_EXIT(XATSMediaPlayer); |
|
334 } |
|
335 else if( adaptCtx->ctxId == XAMediaRecorderAdaptation ) |
|
336 { |
|
337 XA_IMPL_THREAD_SAFETY_EXIT(XATSMediaRecorder); |
|
338 } |
|
339 else if (adaptCtx->ctxId == XACameraAdaptation ) |
|
340 { |
|
341 XA_IMPL_THREAD_SAFETY_EXIT(XATSCamera); |
|
342 } |
|
343 |
|
344 |
|
345 DEBUG_API("<-XAImageControlsItfAdapt_ThreadExit"); |
|
346 return XA_RESULT_SUCCESS; |
|
347 } |
|
348 |
|
349 /* |
|
350 * XAresult XAImageControlsItfAdapt_HandleImageType(XAAdaptationBaseCtx *bCtx) |
|
351 * Description: this run gstreamer for image type |
|
352 * |
|
353 */ |
|
354 XAresult XAImageControlsItfAdapt_HandleImageType(XAAdaptationBaseCtx *bCtx) |
|
355 { |
|
356 XAresult ret = XA_RESULT_SUCCESS; |
|
357 XADataSource *dataSrc = NULL; |
|
358 GstStateChangeReturn gstRet = GST_STATE_CHANGE_SUCCESS; |
|
359 GstState gstOrigState = GST_STATE_PLAYING; |
|
360 GstState gstTmpState = GST_STATE_PLAYING; |
|
361 XAMediaPlayerAdaptationCtx* mCtx = NULL; |
|
362 DEBUG_API("->XAImageControlsItfAdapt_HandleImageType"); |
|
363 |
|
364 if( !bCtx || (bCtx->ctxId != XAMediaPlayerAdaptation) ) |
|
365 { |
|
366 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
367 DEBUG_API("<-XAImageControlsItfAdapt_HandleImageType") |
|
368 return XA_RESULT_PARAMETER_INVALID; |
|
369 } |
|
370 |
|
371 mCtx = (XAMediaPlayerAdaptationCtx*) bCtx; |
|
372 |
|
373 dataSrc = mCtx->xaSource; |
|
374 |
|
375 if( dataSrc ) |
|
376 { |
|
377 XAMediaType mediaType; |
|
378 ret = XACommon_CheckDataSource(dataSrc, &mediaType); |
|
379 if( ret == XA_RESULT_SUCCESS && mediaType == XA_MEDIATYPE_IMAGE ) |
|
380 { |
|
381 gstOrigState = GST_STATE(bCtx->bin); |
|
382 |
|
383 DEBUG_INFO_A1("Sending change state request to state %d", GST_STATE_READY); |
|
384 gstRet = gst_element_set_state( GST_ELEMENT(bCtx->bin), GST_STATE_READY); |
|
385 gstTmpState = GST_STATE(bCtx->bin); |
|
386 |
|
387 DEBUG_INFO_A1("Sending change state request to state %d", gstOrigState); |
|
388 gstRet = gst_element_set_state( GST_ELEMENT(bCtx->bin), gstOrigState); |
|
389 } |
|
390 } |
|
391 DEBUG_API("<-XAImageControlsItfAdapt_HandleImageType"); |
|
392 return ret; |
|
393 } |
|