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: Play Itf Adapt MMF |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "unistd.h" |
|
19 #include "xamediaplayeradaptctxmmf.h" |
|
20 #include "xaplayitfadaptationmmf.h" |
|
21 #include "xaadaptationmmf.h" |
|
22 #include "cmmfbackendengine.h" |
|
23 #include "cmmfradiobackendengine.h" |
|
24 #include <glib.h> |
|
25 |
|
26 /*forward declaration of position updater callback*/ |
|
27 gboolean XAPlayItfAdapt_PositionUpdate(gpointer ctx); |
|
28 |
|
29 /* |
|
30 * XAresult XAPlayItfAdaptMMF_SetPlayState(XAAdaptationBaseCtx *bCtx, XAuint32 state) |
|
31 * Sets play state to GStreamer. |
|
32 * @param XAAdaptationBaseCtx *bCtx - Adaptation context, this will be casted to correct type regarding to contextID |
|
33 * XAuint32 state - Play state to be set |
|
34 * @return XAresult ret - Success value |
|
35 */ |
|
36 XAresult XAPlayItfAdaptMMF_SetPlayState(XAAdaptationBaseCtx *bCtx, |
|
37 XAuint32 state) |
|
38 { |
|
39 XAresult ret = XA_RESULT_SUCCESS; |
|
40 XAMediaPlayerAdaptationMMFCtx* mCtx; |
|
41 if (!bCtx) |
|
42 { |
|
43 ret = XA_RESULT_PARAMETER_INVALID; |
|
44 return ret; |
|
45 } |
|
46 |
|
47 mCtx = (XAMediaPlayerAdaptationMMFCtx*) bCtx; |
|
48 |
|
49 |
|
50 DEBUG_API_A1("->XAPlayItfAdaptMMF_SetPlayState %s",PLAYSTATENAME(state)); |
|
51 |
|
52 /* bCtx and parameter pointer validation happens in the calling function. |
|
53 * We don't need to repeat it here*/ |
|
54 switch (state) |
|
55 { |
|
56 case XA_PLAYSTATE_STOPPED: |
|
57 { |
|
58 if (bCtx->ctxId == XARadioAdaptation) |
|
59 { |
|
60 mmf_set_player_adapt_context(cmmfradiobackendengine_init(), |
|
61 bCtx); |
|
62 stop_radio(cmmfradiobackendengine_init()); |
|
63 } |
|
64 else |
|
65 { |
|
66 ret = mmf_playitf_stop_playback(mCtx->mmfContext); |
|
67 } |
|
68 break; |
|
69 } |
|
70 case XA_PLAYSTATE_PAUSED: |
|
71 ret = mmf_playitf_pause_playback(mCtx->mmfContext); |
|
72 break; |
|
73 case XA_PLAYSTATE_PLAYING: |
|
74 { |
|
75 if (bCtx->ctxId == XARadioAdaptation) |
|
76 { |
|
77 mmf_set_player_adapt_context(cmmfradiobackendengine_init(), |
|
78 bCtx); |
|
79 play_radio(cmmfradiobackendengine_init()); |
|
80 } |
|
81 else |
|
82 { |
|
83 ret = mmf_playitf_resume_playback(mCtx->mmfContext); |
|
84 } |
|
85 break; |
|
86 } |
|
87 default: |
|
88 ret = XA_RESULT_PARAMETER_INVALID; |
|
89 break; |
|
90 } |
|
91 |
|
92 DEBUG_API("<-XAPlayItfAdaptMMF_SetPlayState"); |
|
93 return ret; |
|
94 } |
|
95 |
|
96 /* |
|
97 * XAresult XAPlayItfAdaptMMF_GetPlayState(XAAdaptationBaseCtx *bCtx, XAuint32 *pState) |
|
98 * @param XAAdaptationBaseCtx *bCtx - Adaptation context, this will be casted to correct type regarding to contextID |
|
99 * XAuint32 *state - XAmillisecond *pMsec - Pointer where to store play state |
|
100 * @return XAresult ret - Success value |
|
101 */ |
|
102 XAresult XAPlayItfAdaptMMF_GetPlayState(XAAdaptationBaseCtx *bCtx, |
|
103 XAuint32 *pState) |
|
104 { |
|
105 XAresult ret = XA_RESULT_SUCCESS; |
|
106 XAMediaPlayerAdaptationMMFCtx* pSelf; |
|
107 if (!bCtx || !pState) |
|
108 { |
|
109 ret = XA_RESULT_PARAMETER_INVALID; |
|
110 return ret; |
|
111 } |
|
112 |
|
113 pSelf = (XAMediaPlayerAdaptationMMFCtx*) bCtx; |
|
114 |
|
115 DEBUG_API("->XAPlayItfAdaptMMF_GetPlayState"); |
|
116 |
|
117 /* If playhead reaches eof, state will transition to paused. |
|
118 * This object does not have visibility to callback*/ |
|
119 ret = mmf_playitf_get_play_state(pSelf->mmfContext, pState); |
|
120 |
|
121 DEBUG_API("<-XAPlayItfAdaptMMF_GetPlayState"); |
|
122 return ret; |
|
123 |
|
124 } |
|
125 |
|
126 /* |
|
127 * XAresult XAPlayItfAdaptMMF_GetDuration(XAAdaptationBaseCtx *bCtx, XAmillisecond *pMsec) |
|
128 * @param XAAdaptationBaseCtx *bCtx - Adaptation context, this will be casted to correct type regarding to contextID |
|
129 * XAmillisecond *pMsec - Pointer where to store duration of stream. |
|
130 * @return XAresult ret - Success value |
|
131 */ |
|
132 XAresult XAPlayItfAdaptMMF_GetDuration(XAAdaptationBaseCtx *bCtx, |
|
133 XAmillisecond *pMsec) |
|
134 { |
|
135 XAresult ret = XA_RESULT_SUCCESS; |
|
136 XAMediaPlayerAdaptationMMFCtx* pSelf; |
|
137 if (!bCtx || !pMsec) |
|
138 { |
|
139 ret = XA_RESULT_PARAMETER_INVALID; |
|
140 return ret; |
|
141 } |
|
142 |
|
143 pSelf = (XAMediaPlayerAdaptationMMFCtx*) bCtx; |
|
144 |
|
145 DEBUG_API("->XAPlayItfAdaptMMF_GetDuration"); |
|
146 |
|
147 ret = mmf_playitf_get_duration(pSelf->mmfContext, pMsec); |
|
148 |
|
149 DEBUG_API("<-XAPlayItfAdaptMMF_GetDuration"); |
|
150 return ret; |
|
151 } |
|
152 |
|
153 /* |
|
154 * XAresult XAPlayItfAdaptMMF_GetPosition(XAAdaptationBaseCtx *bCtx, XAmillisecond *pMsec) |
|
155 * @param XAAdaptationBaseCtx *bCtx - Adaptation context, this will be casted to correct type regarding to contextID value |
|
156 * XAmillisecond *pMsec - Pointer where to store current position in stream. |
|
157 * @return XAresult ret - Success value |
|
158 */ |
|
159 XAresult XAPlayItfAdaptMMF_GetPosition(XAAdaptationBaseCtx *bCtx, |
|
160 XAmillisecond *pMsec) |
|
161 { |
|
162 XAresult ret = XA_RESULT_SUCCESS; |
|
163 XAMediaPlayerAdaptationMMFCtx* pSelf; |
|
164 if (!bCtx || !pMsec) |
|
165 { |
|
166 ret = XA_RESULT_PARAMETER_INVALID; |
|
167 return ret; |
|
168 } |
|
169 |
|
170 pSelf = (XAMediaPlayerAdaptationMMFCtx*) bCtx; |
|
171 |
|
172 DEBUG_API("->XAPlayItfAdaptMMF_GetPosition"); |
|
173 |
|
174 ret = mmf_playitf_get_position(pSelf->mmfContext, pMsec); |
|
175 |
|
176 DEBUG_API("<-XAPlayItfAdaptMMF_GetPosition"); |
|
177 return ret; |
|
178 } |
|
179 |
|
180 /* |
|
181 * XAresult XAPlayItfAdaptMMF_RegisterCallback(XAAdaptationBaseCtx *bCtx, xaPlayCallback callback) |
|
182 * Description: Sets the playback callback function. |
|
183 */ |
|
184 XAresult XAPlayItfAdaptMMF_RegisterCallback(XAAdaptationBaseCtx *bCtx, |
|
185 xaPlayCallback callback) |
|
186 { |
|
187 XAresult ret = XA_RESULT_SUCCESS; |
|
188 XAMediaPlayerAdaptationMMFCtx* pSelf; |
|
189 if (!bCtx) |
|
190 { |
|
191 ret = XA_RESULT_PARAMETER_INVALID; |
|
192 return ret; |
|
193 } |
|
194 |
|
195 pSelf = (XAMediaPlayerAdaptationMMFCtx*) bCtx; |
|
196 |
|
197 DEBUG_API("->XAPlayItfAdaptMMF_RegisterCallback"); |
|
198 |
|
199 ret = mmf_playitf_register_callback(pSelf->mmfContext, callback); |
|
200 |
|
201 DEBUG_API("<-XAPlayItfAdaptMMF_RegisterCallback"); |
|
202 return ret; |
|
203 } |
|
204 |
|
205 /** |
|
206 * XAresult XAPlayItfAdaptMMF_SetCallbackEventsMask(XAAdaptationBaseCtx *bCtx, XAuint32 eventFlags) |
|
207 * Description: Enables/disables notification of playback events. |
|
208 **/ |
|
209 XAresult XAPlayItfAdaptMMF_SetCallbackEventsMask(XAAdaptationBaseCtx *bCtx, |
|
210 XAuint32 eventFlags) |
|
211 { |
|
212 XAresult ret = XA_RESULT_SUCCESS; |
|
213 XAMediaPlayerAdaptationMMFCtx* pSelf; |
|
214 if (!bCtx) |
|
215 { |
|
216 ret = XA_RESULT_PARAMETER_INVALID; |
|
217 return ret; |
|
218 } |
|
219 |
|
220 pSelf = (XAMediaPlayerAdaptationMMFCtx*) bCtx; |
|
221 |
|
222 DEBUG_API("->XAPlayItfAdaptMMF_SetCallbackEventsMask"); |
|
223 |
|
224 ret = mmf_playitf_set_callback_events_mask(pSelf->mmfContext, eventFlags); |
|
225 |
|
226 DEBUG_API("<-XAPlayItfAdaptMMF_SetCallbackEventsMask"); |
|
227 return ret; |
|
228 } |
|
229 |
|
230 /** |
|
231 * XAresult XAPlayItfAdaptMMF_SetMarkerPosition(XAAdaptationBaseCtx *bCtx, XAmillisecond mSec) |
|
232 * Description: Sets marker position. |
|
233 **/ |
|
234 XAresult XAPlayItfAdaptMMF_SetMarkerPosition(XAAdaptationBaseCtx *bCtx, |
|
235 XAmillisecond mSec) |
|
236 { |
|
237 XAresult ret = XA_RESULT_SUCCESS; |
|
238 XAMediaPlayerAdaptationMMFCtx* pSelf; |
|
239 if (!bCtx) |
|
240 { |
|
241 ret = XA_RESULT_PARAMETER_INVALID; |
|
242 return ret; |
|
243 } |
|
244 |
|
245 pSelf = (XAMediaPlayerAdaptationMMFCtx*) bCtx; |
|
246 |
|
247 DEBUG_API("->XAPlayItfAdaptMMF_SetMarkerPosition"); |
|
248 |
|
249 ret = mmf_playitf_set_marker_position(pSelf->mmfContext, mSec); |
|
250 |
|
251 DEBUG_API("<-XAPlayItfAdaptMMF_SetMarkerPosition"); |
|
252 return ret; |
|
253 } |
|
254 |
|
255 /** |
|
256 * XAresult XAPlayItfAdaptMMF_SetCallbackEventsMask(XAAdaptationBaseCtx *bCtx, XAuint32 eventFlags) |
|
257 * Description: Clears marker position. |
|
258 **/ |
|
259 XAresult XAPlayItfAdaptMMF_ClearMarkerPosition(XAAdaptationBaseCtx *bCtx) |
|
260 { |
|
261 XAresult ret = XA_RESULT_SUCCESS; |
|
262 XAMediaPlayerAdaptationMMFCtx* pSelf; |
|
263 if (!bCtx) |
|
264 { |
|
265 ret = XA_RESULT_PARAMETER_INVALID; |
|
266 return ret; |
|
267 } |
|
268 |
|
269 pSelf = (XAMediaPlayerAdaptationMMFCtx*) bCtx; |
|
270 |
|
271 DEBUG_API("->XAPlayItfAdaptMMF_ClearMarkerPosition"); |
|
272 |
|
273 ret = mmf_playitf_clear_marker_position(pSelf->mmfContext); |
|
274 |
|
275 DEBUG_API("<-XAPlayItfAdaptMMF_ClearMarkerPosition"); |
|
276 return ret; |
|
277 } |
|
278 |
|
279 /** |
|
280 * XAPlayItfAdaptMMF_SetPositionUpdatePeriod(XAAdaptationBaseCtx *bCtx, XAmillisecond mSec) |
|
281 * Description: Sets position update period. |
|
282 **/ |
|
283 XAresult XAPlayItfAdaptMMF_SetPositionUpdatePeriod(XAAdaptationBaseCtx *bCtx, |
|
284 XAmillisecond mSec) |
|
285 { |
|
286 XAresult ret = XA_RESULT_SUCCESS; |
|
287 XAMediaPlayerAdaptationMMFCtx* pSelf; |
|
288 if (!bCtx) |
|
289 { |
|
290 ret = XA_RESULT_PARAMETER_INVALID; |
|
291 return ret; |
|
292 } |
|
293 |
|
294 pSelf = (XAMediaPlayerAdaptationMMFCtx*) bCtx; |
|
295 |
|
296 DEBUG_API("->XAPlayItfAdaptMMF_SetPositionUpdatePeriod"); |
|
297 |
|
298 ret = mmf_playitf_set_position_update_period(pSelf->mmfContext, mSec); |
|
299 |
|
300 DEBUG_API("<-XAPlayItfAdaptMMF_SetPositionUpdatePeriod"); |
|
301 return ret; |
|
302 } |
|
303 /* |
|
304 * XAresult XAPlayItfAdapt_StateChange |
|
305 * Handle callback from Radio utility |
|
306 */ |
|
307 void XAPlayItfAdaptMMF_StateChange(XAAdaptationBaseCtx *bCtx, |
|
308 XAboolean playing) |
|
309 { |
|
310 if (playing) |
|
311 { |
|
312 XAAdaptEvent event = |
|
313 { |
|
314 XA_PLAYITFEVENTS, XA_PLAYEVENT_HEADMOVING, 1, 0 |
|
315 }; |
|
316 XAAdaptationBase_SendAdaptEvents(bCtx, &event); |
|
317 } |
|
318 else |
|
319 { |
|
320 XAAdaptEvent event = |
|
321 { |
|
322 XA_PLAYITFEVENTS, XA_PLAYEVENT_HEADSTALLED, 1, 0 |
|
323 }; |
|
324 XAAdaptationBase_SendAdaptEvents(bCtx, &event); |
|
325 } |
|
326 |
|
327 } |
|