|
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 <stdio.h> |
|
19 #include <stdlib.h> |
|
20 #include <assert.h> |
|
21 #include "xametadatainsertionitf.h" |
|
22 #ifdef _GSTREAMER_BACKEND_ |
|
23 #include "XAMetadataAdaptation.h" |
|
24 #endif |
|
25 #define MAX_TAGS 255 |
|
26 /* XAMetadataInsertionItfImpl* GetImpl(XAMetadataInsertionItf self) |
|
27 * Description: Validate interface pointer and cast it to implementation pointer. |
|
28 */ |
|
29 static XAMetadataInsertionItfImpl* GetImpl(XAMetadataInsertionItf self) |
|
30 { |
|
31 if( self ) |
|
32 { |
|
33 XAMetadataInsertionItfImpl* impl = (XAMetadataInsertionItfImpl*)(*self); |
|
34 if( impl && (impl == impl->self) ) |
|
35 { |
|
36 return impl; |
|
37 } |
|
38 } |
|
39 return NULL; |
|
40 } |
|
41 |
|
42 /***************************************************************************** |
|
43 * Base interface XAMetadataInsertionItf implementation |
|
44 *****************************************************************************/ |
|
45 |
|
46 /* XAMetadataInsertionItfImpl_CreateChildNode |
|
47 * Description: Creates a new child node for the given parent. |
|
48 */ |
|
49 XAresult XAMetadataInsertionItfImpl_CreateChildNode(XAMetadataInsertionItf self, |
|
50 XAint32 parentNodeID, |
|
51 XAuint32 type, |
|
52 XAchar *mimeType, |
|
53 XAint32 *pChildNodeID) |
|
54 { |
|
55 XAMetadataInsertionItfImpl *impl = NULL; |
|
56 XAresult ret = XA_RESULT_SUCCESS; |
|
57 |
|
58 DEBUG_API("->XAMetadataInsertionItfImpl_CreateChildNode"); |
|
59 impl = GetImpl(self); |
|
60 if(!impl || !mimeType || !pChildNodeID ) |
|
61 { |
|
62 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
63 /* invalid parameter */ |
|
64 ret = XA_RESULT_PARAMETER_INVALID; |
|
65 } |
|
66 else |
|
67 { |
|
68 #ifdef _GSTREAMER_BACKEND_ |
|
69 if( impl->adaptCtx ) |
|
70 { |
|
71 ret = XAMetadataInsertionItfAdapt_CreateChildNode( |
|
72 impl->adaptCtx,parentNodeID,type,mimeType,pChildNodeID); |
|
73 } |
|
74 else |
|
75 { |
|
76 ret = XA_RESULT_INTERNAL_ERROR; |
|
77 } |
|
78 #endif |
|
79 /*******************************************/ |
|
80 /****This is being done since mmf does not |
|
81 * support metadata Insertion |
|
82 *******************************************/ |
|
83 ret = XA_RESULT_FEATURE_UNSUPPORTED; |
|
84 } |
|
85 DEBUG_API("<-XAMetadataInsertionItfImpl_CreateChildNode"); |
|
86 return ret; |
|
87 } |
|
88 |
|
89 /* XAresult XAMetadataInsertionItfImpl_GetSupportedKeysCount |
|
90 * Description: A query method to tell if the metadata keys (for writing metadata) |
|
91 * can be freely chosen by the application or if they are fixed (for the given node). |
|
92 */ |
|
93 XAresult XAMetadataInsertionItfImpl_GetSupportedKeysCount(XAMetadataInsertionItf self, |
|
94 XAint32 nodeID, |
|
95 XAboolean *pFreeKeys, |
|
96 XAuint32 *pKeyCount, |
|
97 XAuint32 *pEncodingCount) |
|
98 { |
|
99 XAMetadataInsertionItfImpl *impl = NULL; |
|
100 XAresult ret = XA_RESULT_SUCCESS; |
|
101 |
|
102 DEBUG_API("->XAMetadataInsertionItfImpl_GetSupportedKeysCount"); |
|
103 impl = GetImpl(self); |
|
104 if(!impl || !pFreeKeys || !pKeyCount || !pEncodingCount ) |
|
105 { |
|
106 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
107 /* invalid parameter */ |
|
108 ret = XA_RESULT_PARAMETER_INVALID; |
|
109 } |
|
110 else |
|
111 { |
|
112 #ifdef _GSTREAMER_BACKEND_ |
|
113 if( impl->adaptCtx ) |
|
114 { |
|
115 ret = XAMetadataInsertionItfAdapt_GetSupportedKeysCount( |
|
116 impl->adaptCtx,nodeID,pFreeKeys,pKeyCount,pEncodingCount); |
|
117 } |
|
118 else |
|
119 { |
|
120 ret = XA_RESULT_INTERNAL_ERROR; |
|
121 } |
|
122 #endif |
|
123 /*******************************************/ |
|
124 /****This is being done since mmf does not |
|
125 * support metadata Insertion |
|
126 *******************************************/ |
|
127 |
|
128 ret = XA_RESULT_PARAMETER_INVALID; |
|
129 } |
|
130 DEBUG_API("<-XAMetadataInsertionItfImpl_GetSupportedKeysCount"); |
|
131 return ret; |
|
132 } |
|
133 |
|
134 /* XAresult XAMetadataInsertionItfImpl_GetKeySize |
|
135 * Description: Returns the byte size required for a supported metadata |
|
136 * key pointed by the given index |
|
137 */ |
|
138 XAresult XAMetadataInsertionItfImpl_GetKeySize(XAMetadataInsertionItf self, |
|
139 XAint32 nodeID, |
|
140 XAuint32 keyIndex, |
|
141 XAuint32 *pKeySize) |
|
142 { |
|
143 XAMetadataInsertionItfImpl *impl = NULL; |
|
144 XAresult ret = XA_RESULT_SUCCESS; |
|
145 |
|
146 DEBUG_API("->XAMetadataInsertionItfImpl_GetKeySize"); |
|
147 impl = GetImpl(self); |
|
148 if(!impl || !pKeySize ) |
|
149 { |
|
150 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
151 /* invalid parameter */ |
|
152 ret = XA_RESULT_PARAMETER_INVALID; |
|
153 } |
|
154 else |
|
155 { |
|
156 #ifdef _GSTREAMER_BACKEND_ |
|
157 if( impl->adaptCtx ) |
|
158 { |
|
159 ret = XAMetadataInsertionItfAdapt_GetKeySize( |
|
160 impl->adaptCtx, nodeID, keyIndex, pKeySize); |
|
161 } |
|
162 else |
|
163 { |
|
164 ret = XA_RESULT_INTERNAL_ERROR; |
|
165 } |
|
166 #endif |
|
167 /*******************************************/ |
|
168 /****This is being done since mmf does not |
|
169 * support metadata Insertion |
|
170 *******************************************/ |
|
171 |
|
172 ret = XA_RESULT_PARAMETER_INVALID; |
|
173 } |
|
174 DEBUG_API("<-XAMetadataInsertionItfImpl_GetKeySize"); |
|
175 return ret; |
|
176 } |
|
177 |
|
178 /* XAresult XAMetadataInsertionItfImpl_GetKey |
|
179 * Description; Returns a XAMetadataInfo structure and associated data |
|
180 * referenced by the structure for a supported key |
|
181 */ |
|
182 XAresult XAMetadataInsertionItfImpl_GetKey(XAMetadataInsertionItf self, |
|
183 XAint32 nodeID, |
|
184 XAuint32 keyIndex, |
|
185 XAuint32 keySize, |
|
186 XAMetadataInfo *pKey) |
|
187 { |
|
188 XAMetadataInsertionItfImpl *impl = NULL; |
|
189 XAresult ret = XA_RESULT_SUCCESS; |
|
190 |
|
191 DEBUG_API("->XAMetadataInsertionItfImpl_GetKey"); |
|
192 impl = GetImpl(self); |
|
193 if(!impl || !pKey ) |
|
194 { |
|
195 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
196 /* invalid parameter */ |
|
197 ret = XA_RESULT_PARAMETER_INVALID; |
|
198 } |
|
199 else |
|
200 { |
|
201 #ifdef _GSTREAMER_BACKEND_ |
|
202 if( impl->adaptCtx ) |
|
203 { |
|
204 ret = XAMetadataInsertionItfAdapt_GetKey( |
|
205 impl->adaptCtx,nodeID,keyIndex,keySize,pKey); |
|
206 } |
|
207 else |
|
208 { |
|
209 ret = XA_RESULT_INTERNAL_ERROR; |
|
210 } |
|
211 #endif |
|
212 /*******************************************/ |
|
213 /****This is being done since mmf does not |
|
214 * support metadata Insertion |
|
215 *******************************************/ |
|
216 |
|
217 ret = XA_RESULT_PARAMETER_INVALID; |
|
218 } |
|
219 DEBUG_API("<-XAMetadataInsertionItfImpl_GetKey"); |
|
220 return ret; |
|
221 } |
|
222 |
|
223 /* XAresult XAMetadataInsertionItfImpl_GetFreeKeysEncoding |
|
224 * Description: A method to be used in case implementation supports |
|
225 * free keys for metadata insertion. |
|
226 */ |
|
227 XAresult XAMetadataInsertionItfImpl_GetFreeKeysEncoding(XAMetadataInsertionItf self, |
|
228 XAint32 nodeID, |
|
229 XAuint32 encodingIndex, |
|
230 XAuint32 *pEncoding) |
|
231 { |
|
232 XAMetadataInsertionItfImpl *impl = NULL; |
|
233 XAresult ret = XA_RESULT_SUCCESS; |
|
234 |
|
235 DEBUG_API("->XAMetadataInsertionItfImpl_GetFreeKeysEncoding"); |
|
236 impl = GetImpl(self); |
|
237 if( !impl || !pEncoding ) |
|
238 { |
|
239 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
240 /* invalid parameter */ |
|
241 ret =XA_RESULT_PARAMETER_INVALID; |
|
242 } |
|
243 else |
|
244 { |
|
245 #ifdef _GSTREAMER_BACKEND_ |
|
246 if( impl->adaptCtx ) |
|
247 { |
|
248 ret = XAMetadataInsertionItfAdapt_GetFreeKeysEncoding( |
|
249 impl->adaptCtx,nodeID,encodingIndex,pEncoding); |
|
250 } |
|
251 else |
|
252 { |
|
253 ret = XA_RESULT_INTERNAL_ERROR; |
|
254 } |
|
255 #endif |
|
256 /*******************************************/ |
|
257 /****This is being done since mmf does not |
|
258 * support metadata Insertion |
|
259 *******************************************/ |
|
260 |
|
261 ret = XA_RESULT_PARAMETER_INVALID; |
|
262 } |
|
263 DEBUG_API("<-XAMetadataInsertionItfImpl_GetFreeKeysEncoding"); |
|
264 return ret; |
|
265 } |
|
266 |
|
267 /* XAresult XAMetadataInsertionItfImpl_InsertMetadataItem |
|
268 * Description: Inserts the key/value pair to the specified node of the metadata tree. |
|
269 */ |
|
270 XAresult XAMetadataInsertionItfImpl_InsertMetadataItem(XAMetadataInsertionItf self, |
|
271 XAint32 nodeID, |
|
272 XAMetadataInfo *pKey, |
|
273 XAMetadataInfo *pValue, |
|
274 XAboolean overwrite) |
|
275 { |
|
276 XAMetadataInsertionItfImpl *impl = NULL; |
|
277 XAresult ret = XA_RESULT_SUCCESS; |
|
278 |
|
279 DEBUG_API("->XAMetadataInsertionItfImpl_InsertMetadataItem"); |
|
280 impl = GetImpl(self); |
|
281 if( !impl || !pKey || !pValue ) |
|
282 { |
|
283 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
284 /* invalid parameter */ |
|
285 ret = XA_RESULT_PARAMETER_INVALID; |
|
286 } |
|
287 else |
|
288 { |
|
289 #ifdef _GSTREAMER_BACKEND_ |
|
290 if( impl->adaptCtx ) |
|
291 { |
|
292 ret = XAMetadataInsertionItfAdapt_InsertMetadataItem( |
|
293 impl->adaptCtx,nodeID,pKey,pValue,overwrite); |
|
294 /*store pointers for callback*/ |
|
295 impl->currentTags.mdeKeys[impl->currentTags.itemcount] = pKey; |
|
296 impl->currentTags.mdeValues[impl->currentTags.itemcount] = pValue; |
|
297 impl->currentTags.itemcount++; |
|
298 } |
|
299 else |
|
300 { |
|
301 ret = XA_RESULT_INTERNAL_ERROR; |
|
302 } |
|
303 #endif |
|
304 /*******************************************/ |
|
305 /****This is being done since mmf does not |
|
306 * support metadata Insertion |
|
307 *******************************************/ |
|
308 |
|
309 ret = XA_RESULT_FEATURE_UNSUPPORTED; |
|
310 } |
|
311 DEBUG_API("<-XAMetadataInsertionItfImpl_InsertMetadataItem"); |
|
312 return ret; |
|
313 } |
|
314 |
|
315 /* XAresult XAMetadataInsertionItfImpl_RegisterCallback |
|
316 * Description: Registers a callback on the object that executes after each of |
|
317 * the actual writings of metadata key/value pairs takes place. |
|
318 */ |
|
319 XAresult XAMetadataInsertionItfImpl_RegisterCallback(XAMetadataInsertionItf self, |
|
320 xaMetadataInsertionCallback callback, |
|
321 void *pContext) |
|
322 { |
|
323 XAMetadataInsertionItfImpl *impl = NULL; |
|
324 |
|
325 DEBUG_API("->XAMetadataInsertionItfImpl_RegisterCallback"); |
|
326 impl = GetImpl(self); |
|
327 if( !impl ) |
|
328 { |
|
329 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
330 DEBUG_API("<-XAMetadataInsertionItfImpl_RegisterCallback"); |
|
331 /* invalid parameter */ |
|
332 return XA_RESULT_PARAMETER_INVALID; |
|
333 } |
|
334 #ifdef _GSTREAMER_BACKEND_ |
|
335 if(callback) |
|
336 { |
|
337 XAAdaptationBase_AddEventHandler( impl->adaptCtx, &XAMetadataInsertionItfImpl_AdaptCb, |
|
338 XA_METADATAEVENTS, impl ); |
|
339 } |
|
340 else |
|
341 { |
|
342 XAAdaptationBase_RemoveEventHandler(impl->adaptCtx, &XAMetadataInsertionItfImpl_AdaptCb ); |
|
343 } |
|
344 #endif |
|
345 impl->callback = callback; |
|
346 impl->cbcontext = pContext; |
|
347 impl->cbPtrToSelf = self; |
|
348 |
|
349 DEBUG_API("<-XAMetadataInsertionItfImpl_RegisterCallback"); |
|
350 return XA_RESULT_SUCCESS; |
|
351 } |
|
352 |
|
353 /***************************************************************************** |
|
354 * XAMetadataTraversalImpl -specific methods |
|
355 *****************************************************************************/ |
|
356 |
|
357 |
|
358 /* XAMetadataInsertionItfImpl* XAMetadataInsertionItfImpl_Create() |
|
359 * Description: Allocate and initialize MetadataInsertionItfImpl |
|
360 */ |
|
361 XAMetadataInsertionItfImpl* XAMetadataInsertionItfImpl_Create( |
|
362 #ifdef _GSTREAMER_BACKEND_ |
|
363 XAAdaptationBaseCtx *adaptCtx |
|
364 #endif |
|
365 ) |
|
366 { |
|
367 XAMetadataInsertionItfImpl* self = (XAMetadataInsertionItfImpl*) |
|
368 calloc(1,sizeof(XAMetadataInsertionItfImpl)); |
|
369 DEBUG_API("->XAMetadataInsertionItfImpl_Create"); |
|
370 if( self ) |
|
371 { |
|
372 /* init itf default implementation */ |
|
373 self->itf.CreateChildNode = XAMetadataInsertionItfImpl_CreateChildNode; |
|
374 self->itf.GetFreeKeysEncoding = XAMetadataInsertionItfImpl_GetFreeKeysEncoding; |
|
375 self->itf.GetKey = XAMetadataInsertionItfImpl_GetKey; |
|
376 self->itf.GetKeySize = XAMetadataInsertionItfImpl_GetKeySize; |
|
377 self->itf.GetSupportedKeysCount = XAMetadataInsertionItfImpl_GetSupportedKeysCount; |
|
378 self->itf.InsertMetadataItem = XAMetadataInsertionItfImpl_InsertMetadataItem; |
|
379 self->itf.RegisterCallback = XAMetadataInsertionItfImpl_RegisterCallback; |
|
380 |
|
381 /* init variables*/ |
|
382 |
|
383 self->callback = NULL; |
|
384 self->cbcontext = NULL; |
|
385 self->cbPtrToSelf = NULL; |
|
386 #ifdef _GSTREAMER_BACKEND_ |
|
387 self->adaptCtx = adaptCtx; |
|
388 self->currentTags.mdeKeys = calloc(MAX_TAGS,sizeof(XAMetadataInfo*)); |
|
389 self->currentTags.mdeValues = calloc(MAX_TAGS,sizeof(XAMetadataInfo*)); |
|
390 #endif |
|
391 self->self = self; |
|
392 |
|
393 } |
|
394 DEBUG_API("<-XAMetadataInsertionItfImpl_Create"); |
|
395 return self; |
|
396 } |
|
397 |
|
398 /* void XAMetadataInsertionItfImpl_Free(XAMetadataInsertionItfImpl* self) |
|
399 * Description: Free all resources reserved at XAMetadataInsertionItfImpl_Create() |
|
400 */ |
|
401 void XAMetadataInsertionItfImpl_Free(XAMetadataInsertionItfImpl* self) |
|
402 { |
|
403 DEBUG_API("->XAMetadataInsertionItfImpl_Free"); |
|
404 assert( self==self->self ); |
|
405 if(self->callback) |
|
406 { |
|
407 #ifdef _GSTREAMER_BACKEND_ |
|
408 XAAdaptationBase_RemoveEventHandler(self->adaptCtx, &XAMetadataInsertionItfImpl_AdaptCb ); |
|
409 #endif |
|
410 } |
|
411 #ifdef _GSTREAMER_BACKEND_ |
|
412 XAMetadataAdapt_FreeImplTagList(&(self->currentTags), XA_BOOLEAN_FALSE); |
|
413 #endif |
|
414 free( self ); |
|
415 DEBUG_API("<-XAMetadataInsertionItfImpl_Free"); |
|
416 } |
|
417 #ifdef _GSTREAMER_BACKEND_ |
|
418 /* With this method, adaptation infroms that tags are written to stream |
|
419 */ |
|
420 void XAMetadataInsertionItfImpl_AdaptCb( void *pHandlerCtx, XAAdaptEvent *event ) |
|
421 { |
|
422 XAMetadataInsertionItfImpl* impl = NULL; |
|
423 XAuint32 idx = 0, nodeID = XA_ROOT_NODE_ID; |
|
424 XAboolean result = XA_BOOLEAN_TRUE; |
|
425 DEBUG_API("->XAMetadataInsertionItfImpl_AdaptCb"); |
|
426 impl = (XAMetadataInsertionItfImpl*)pHandlerCtx; |
|
427 if(!impl) |
|
428 { |
|
429 DEBUG_ERR("XAMetadataInsertionItfImpl_AdaptCb, invalid context pointer!"); |
|
430 DEBUG_API("<-XAMetadataInsertionItfImpl_AdaptCb"); |
|
431 return; |
|
432 } |
|
433 if( event && event->eventid == XA_ADAPT_MDE_TAGS_WRITTEN ) |
|
434 { |
|
435 /*here datasize field is used for return value*/ |
|
436 if(event->datasize != XA_RESULT_SUCCESS) |
|
437 { |
|
438 DEBUG_ERR_A1("Adaptation failed to write metadata (code %x)!",(int)event->datasize); |
|
439 result=XA_BOOLEAN_FALSE; |
|
440 } |
|
441 /*all tags written, send cb for client to free the memory*/ |
|
442 for(idx=0;idx<impl->currentTags.itemcount;idx++) |
|
443 { |
|
444 if(impl->callback) |
|
445 { |
|
446 impl->callback(impl->cbPtrToSelf, impl->cbcontext, |
|
447 impl->currentTags.mdeKeys[idx], |
|
448 impl->currentTags.mdeValues[idx], |
|
449 nodeID, result); |
|
450 } |
|
451 impl->currentTags.mdeKeys[idx]=NULL; |
|
452 impl->currentTags.mdeValues[idx]=NULL; |
|
453 } |
|
454 impl->currentTags.itemcount=0; |
|
455 } |
|
456 else |
|
457 { |
|
458 DEBUG_INFO("unhandled"); |
|
459 } |
|
460 DEBUG_API("<-XAMetadataInsertionItfImpl_AdaptCb"); |
|
461 } |
|
462 |
|
463 #endif |