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: Seek Itf Implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <stdio.h> |
|
19 #include <stdlib.h> |
|
20 #include <assert.h> |
|
21 |
|
22 #include "xaseekitf.h" |
|
23 #include "xathreadsafety.h" |
|
24 #include "xaplayitfadaptationmmf.h" |
|
25 #include "xaseekitfadaptationmmf.h" |
|
26 /** |
|
27 * XASeekItfImpl* GetImpl(XASeekItf self) |
|
28 * Description: Validate interface pointer and cast it to implementation pointer. |
|
29 */ |
|
30 static XASeekItfImpl* GetImpl(XASeekItf self) |
|
31 { |
|
32 if (self) |
|
33 { |
|
34 XASeekItfImpl* impl = (XASeekItfImpl*) (*self); |
|
35 if (impl && impl == impl->self) |
|
36 { |
|
37 return impl; |
|
38 } |
|
39 } |
|
40 return NULL; |
|
41 } |
|
42 |
|
43 /** |
|
44 * Base interface XASeekItf implementation |
|
45 */ |
|
46 |
|
47 /** |
|
48 * XAresult XASeekItfImpl_SetPosition(XASeekItf self, XAmillisecond pos, |
|
49 * XAuint32 seekMode) |
|
50 * Description: Sets the position of the playback head. |
|
51 **/ |
|
52 XAresult XASeekItfImpl_SetPosition(XASeekItf self, XAmillisecond pos, |
|
53 XAuint32 seekMode) |
|
54 { |
|
55 XAresult ret = XA_RESULT_SUCCESS; |
|
56 XAmillisecond duration = 0; |
|
57 XASeekItfImpl* impl = GetImpl(self); |
|
58 DEBUG_API("->XASeekItfImpl_SetPosition"); |
|
59 XA_IMPL_THREAD_SAFETY_ENTRY( XATSMediaPlayer ); |
|
60 |
|
61 if (!impl) |
|
62 { |
|
63 /* invalid parameter */ |
|
64 XA_IMPL_THREAD_SAFETY_EXIT( XATSMediaPlayer ); |
|
65 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
66 DEBUG_API("<-XASeekItfImpl_SetPosition"); |
|
67 return XA_RESULT_PARAMETER_INVALID; |
|
68 } |
|
69 |
|
70 if (impl->adapCtx->fwtype == FWMgrFWMMF) |
|
71 { |
|
72 /* Get duration of the content */ |
|
73 if (XAPlayItfAdaptMMF_GetDuration( |
|
74 (XAAdaptationBaseCtx*) impl->adapCtx, &duration) |
|
75 != XA_RESULT_SUCCESS) |
|
76 { |
|
77 /* invalid parameter */ |
|
78 XA_IMPL_THREAD_SAFETY_EXIT( XATSMediaPlayer ); |
|
79 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
80 DEBUG_API("<-XASeekItfImpl_SetPosition"); |
|
81 return XA_RESULT_PARAMETER_INVALID; |
|
82 } |
|
83 if (pos > duration) |
|
84 { |
|
85 /* invalid parameter */ |
|
86 XA_IMPL_THREAD_SAFETY_EXIT( XATSMediaPlayer ); |
|
87 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
88 DEBUG_API("<-XASeekItfImpl_SetPosition"); |
|
89 return XA_RESULT_PARAMETER_INVALID; |
|
90 } |
|
91 |
|
92 if (seekMode != XA_SEEKMODE_FAST && seekMode != XA_SEEKMODE_ACCURATE) |
|
93 { |
|
94 /* seek mode unsupported */ |
|
95 XA_IMPL_THREAD_SAFETY_EXIT( XATSMediaPlayer ); |
|
96 DEBUG_ERR("XA_RESULT_FEATURE_UNSUPPORTED"); |
|
97 DEBUG_API("<-XASeekItfImpl_SetPosition"); |
|
98 return XA_RESULT_FEATURE_UNSUPPORTED; |
|
99 } |
|
100 |
|
101 ret = XASeekItfAdaptMMF_SetPosition(impl->adapCtx, pos, seekMode); |
|
102 if (ret == XA_RESULT_SUCCESS) |
|
103 { |
|
104 impl->playbackPosition = pos; |
|
105 impl->seekMode = seekMode; |
|
106 } |
|
107 } |
|
108 |
|
109 XA_IMPL_THREAD_SAFETY_EXIT( XATSMediaPlayer ); |
|
110 DEBUG_API("<-XASeekItfImpl_SetPosition"); |
|
111 return ret; |
|
112 } |
|
113 |
|
114 /** |
|
115 * XAresult XASeekItfImpl_SetLoop(XASeekItf self, XAboolean loopEnable, |
|
116 * XAmillisecond startPos, XAmillisecond endPos) |
|
117 * Description: Enables or disables looping and sets the start and end points of looping. |
|
118 **/ |
|
119 XAresult XASeekItfImpl_SetLoop(XASeekItf self, XAboolean loopEnable, |
|
120 XAmillisecond startPos, XAmillisecond endPos) |
|
121 { |
|
122 XAresult ret = XA_RESULT_SUCCESS; |
|
123 XAmillisecond duration = 0; |
|
124 XASeekItfImpl* impl = GetImpl(self); |
|
125 DEBUG_API_A2("->XASeekItfImpl_SetLoop, startPos:%lu, endPos:%lu", startPos, endPos); |
|
126 XA_IMPL_THREAD_SAFETY_ENTRY( XATSMediaPlayer ); |
|
127 |
|
128 if (!impl || (startPos > endPos)) |
|
129 { |
|
130 /* invalid parameter */ |
|
131 XA_IMPL_THREAD_SAFETY_EXIT( XATSMediaPlayer ); |
|
132 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
133 DEBUG_API("<-XASeekItfImpl_SetLoop"); |
|
134 return XA_RESULT_PARAMETER_INVALID; |
|
135 } |
|
136 |
|
137 if (impl->adapCtx->fwtype == FWMgrFWMMF) |
|
138 { |
|
139 /* Get duration of the content */ |
|
140 if (XAPlayItfAdaptMMF_GetDuration( |
|
141 (XAAdaptationBaseCtx*) impl->adapCtx, &duration) |
|
142 != XA_RESULT_SUCCESS) |
|
143 { |
|
144 /* invalid parameter */ |
|
145 XA_IMPL_THREAD_SAFETY_EXIT( XATSMediaPlayer ); |
|
146 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
147 DEBUG_API("<-XASeekItfImpl_SetLoop"); |
|
148 return XA_RESULT_PARAMETER_INVALID; |
|
149 } |
|
150 if (endPos > duration && endPos != XA_TIME_UNKNOWN) |
|
151 { |
|
152 /* invalid parameter */ |
|
153 XA_IMPL_THREAD_SAFETY_EXIT( XATSMediaPlayer ); |
|
154 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
155 DEBUG_API("<-XASeekItfImpl_SetLoop"); |
|
156 return XA_RESULT_PARAMETER_INVALID; |
|
157 } |
|
158 |
|
159 ret = XASeekItfAdaptMMF_SetLoop(impl->adapCtx, loopEnable, startPos, |
|
160 endPos); |
|
161 if (ret == XA_RESULT_SUCCESS) |
|
162 { |
|
163 impl->loopEnable = loopEnable; |
|
164 impl->startPos = startPos; |
|
165 impl->endPos = endPos; |
|
166 } |
|
167 } |
|
168 |
|
169 XA_IMPL_THREAD_SAFETY_EXIT( XATSMediaPlayer ); |
|
170 DEBUG_API("<-XASeekItfImpl_SetLoop"); |
|
171 return ret; |
|
172 } |
|
173 |
|
174 /** |
|
175 * XAresult XASeekItfImpl_GetLoop(XASeekItf self, XAboolean *pLoopEnabled, |
|
176 * XAmillisecond *pStartPos, |
|
177 * XAmillisecond *pEndPos) |
|
178 * Description: Queries whether looping is enabled or disabled, and retrieves loop points. |
|
179 **/ |
|
180 XAresult XASeekItfImpl_GetLoop(XASeekItf self, XAboolean *pLoopEnabled, |
|
181 XAmillisecond *pStartPos, XAmillisecond *pEndPos) |
|
182 { |
|
183 XAresult ret = XA_RESULT_SUCCESS; |
|
184 |
|
185 XASeekItfImpl* impl = GetImpl(self); |
|
186 DEBUG_API("->XASeekItfImpl_GetLoop"); |
|
187 |
|
188 if (!impl || !pLoopEnabled || !pStartPos || !pEndPos) |
|
189 { |
|
190 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
191 DEBUG_API("<-XASeekItfImpl_GetLoop"); |
|
192 /* invalid parameter */ |
|
193 return XA_RESULT_PARAMETER_INVALID; |
|
194 } |
|
195 |
|
196 *pLoopEnabled = impl->loopEnable; |
|
197 *pStartPos = impl->startPos; |
|
198 *pEndPos = impl->endPos; |
|
199 |
|
200 DEBUG_API("<-XASeekItfImpl_GetLoop"); |
|
201 return ret; |
|
202 } |
|
203 |
|
204 /** |
|
205 * XASeekItfImpl -specific methods |
|
206 **/ |
|
207 |
|
208 /** |
|
209 * XASeekItfImpl* XASeekItfImpl_Create() |
|
210 * Description: Allocate and initialize SeekItfImpl. |
|
211 **/ |
|
212 XASeekItfImpl* XASeekItfImpl_Create(XAMediaPlayerImpl* impl) |
|
213 { |
|
214 XASeekItfImpl *self = (XASeekItfImpl*) calloc(1, sizeof(XASeekItfImpl)); |
|
215 DEBUG_API("->XASeekItfImpl_Create"); |
|
216 if (self) |
|
217 { |
|
218 /* init itf default implementation */ |
|
219 self->itf.GetLoop = XASeekItfImpl_GetLoop; |
|
220 self->itf.SetLoop = XASeekItfImpl_SetLoop; |
|
221 self->itf.SetPosition = XASeekItfImpl_SetPosition; |
|
222 |
|
223 /* init variables */ |
|
224 self->playbackPosition = 0; |
|
225 self->seekMode = 0; |
|
226 self->loopEnable = XA_BOOLEAN_FALSE; |
|
227 self->startPos = 0; |
|
228 self->endPos = 0; |
|
229 |
|
230 self->adapCtx = impl->curAdaptCtx; |
|
231 |
|
232 self->self = self; |
|
233 } |
|
234 DEBUG_API("<-XASeekItfImpl_Create"); |
|
235 return self; |
|
236 } |
|
237 |
|
238 /** |
|
239 * void XASeekItfImpl_Free(XASeekItfImpl* self) |
|
240 * Description: Free all resources reserved at XASeekItfImpl_Create. |
|
241 **/ |
|
242 void XASeekItfImpl_Free(XASeekItfImpl* self) |
|
243 { |
|
244 DEBUG_API("->XASeekItfImpl_Free"); |
|
245 if(self) |
|
246 { |
|
247 assert(self==self->self); |
|
248 free(self); |
|
249 } |
|
250 DEBUG_API("<-XASeekItfImpl_Free"); |
|
251 } |
|