|
1 /* |
|
2 * Copyright (c) 2010 Ixonos Plc. |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the "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 * Ixonos Plc |
|
14 * |
|
15 * Description: |
|
16 * Frame type -dependent settings. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 /* |
|
24 * Includes |
|
25 */ |
|
26 |
|
27 |
|
28 #include "h263dConfig.h" |
|
29 |
|
30 #include "vdefrt.h" |
|
31 #include "vde.h" |
|
32 #include "h263dapi.h" |
|
33 |
|
34 |
|
35 |
|
36 /* |
|
37 * Defines |
|
38 */ |
|
39 |
|
40 /* The following two definitions are used to indicate that all image |
|
41 widths/heights belong to the scope of the correponding setting. */ |
|
42 #define VDEFRT_ALL_WIDTHS 0 |
|
43 #define VDEFRT_ALL_HEIGHTS 0 |
|
44 |
|
45 |
|
46 /* |
|
47 * Structures and typedefs |
|
48 */ |
|
49 |
|
50 /* Size list item */ |
|
51 typedef struct { |
|
52 LST_ITEM_SKELETON |
|
53 |
|
54 int width; /* image width associated with this item */ |
|
55 int height; /* image height associated with this item */ |
|
56 u_char fSnapshot; /* snapshot flag associated with this item */ |
|
57 |
|
58 u_int32 dataHandle; /* handle to generic data */ |
|
59 void (*dealloc) (void *); /* function for dataHandle dealloction */ |
|
60 } vdeFrtSizeListItem_t; |
|
61 |
|
62 /* NOTE: Currently the snapshot scope must be used together with the frame |
|
63 size scope. It is not possible to store or retrieve an item based |
|
64 on the snapshot flag only. */ |
|
65 |
|
66 /* |
|
67 * Local function prototypes |
|
68 */ |
|
69 |
|
70 static int vdeFrtRemoveAll(vdeFrtStore_t *store); |
|
71 |
|
72 static int vdeFrtSeekSize(lst_t *sizeList, int width, int height, |
|
73 vdeFrtSizeListItem_t **seekHit); |
|
74 |
|
75 static int vdeFrtSeekItem(lst_t *sizeList, int width, int height, |
|
76 u_char fSnapshot, vdeFrtSizeListItem_t **seekHit); |
|
77 |
|
78 |
|
79 /* |
|
80 * Global functions |
|
81 */ |
|
82 |
|
83 /* {{-output"vdeFrtClose.txt"}} */ |
|
84 /* |
|
85 * vdeFrtClose |
|
86 * |
|
87 * Parameters: |
|
88 * store a pointer to a frame type store |
|
89 * |
|
90 * Function: |
|
91 * This function closes the given frame type store. |
|
92 * |
|
93 * Returns: |
|
94 * VDE_OK if the function was successful |
|
95 * VDE_ERROR if an error occured |
|
96 * |
|
97 * |
|
98 */ |
|
99 |
|
100 int vdeFrtClose(vdeFrtStore_t *store) |
|
101 /* {{-output"vdeFrtClose.txt"}} */ |
|
102 { |
|
103 int retValue; |
|
104 |
|
105 retValue = vdeFrtRemoveAll(store); |
|
106 if (retValue < 0) |
|
107 return retValue; |
|
108 |
|
109 if (lstClose(&store->sizeList) < 0) |
|
110 return VDE_ERROR; |
|
111 |
|
112 return VDE_OK; |
|
113 } |
|
114 |
|
115 |
|
116 /* {{-output"vdeFrtGetItem.txt"}} */ |
|
117 /* |
|
118 * vdeFrtGetItem |
|
119 * |
|
120 * Parameters: |
|
121 * store a pointer to a frame type store |
|
122 * frameType specifies the frame type for the wanted item |
|
123 * item used to return an item from the store |
|
124 * |
|
125 * Function: |
|
126 * This function fetches the item from the given store which corresponds |
|
127 * to the given frame type. |
|
128 * |
|
129 * Returns: |
|
130 * VDE_OK if the function was successful |
|
131 * VDE_ERROR if an error occured |
|
132 * |
|
133 * |
|
134 */ |
|
135 |
|
136 int vdeFrtGetItem(vdeFrtStore_t *store, h263dFrameType_t *frameType, u_int32 *item) |
|
137 /* {{-output"vdeFrtGetItem.txt"}} */ |
|
138 { |
|
139 switch (frameType->scope) { |
|
140 case H263D_FTYPE_NDEF: |
|
141 case H263D_FTYPE_SIZE + H263D_FTYPE_SNAPSHOT: |
|
142 { |
|
143 int retValue; |
|
144 vdeFrtSizeListItem_t *listItem; |
|
145 |
|
146 /* seek item with matching size and snapshot flag */ |
|
147 retValue = vdeFrtSeekItem(&store->sizeList, frameType->width, |
|
148 frameType->height, frameType->fSnapshot, &listItem); |
|
149 if (retValue < 0) |
|
150 return retValue; |
|
151 |
|
152 if (listItem) |
|
153 *item = listItem->dataHandle; |
|
154 |
|
155 else { |
|
156 if (lstTail(&store->sizeList, (void **) &listItem) < 0) |
|
157 return VDE_ERROR; |
|
158 |
|
159 /* If a default item exists */ |
|
160 if (listItem && |
|
161 listItem->width == VDEFRT_ALL_WIDTHS && |
|
162 listItem->height == VDEFRT_ALL_HEIGHTS) |
|
163 *item = listItem->dataHandle; |
|
164 |
|
165 else { |
|
166 *item = 0; |
|
167 return VDE_OK_NOT_AVAILABLE; |
|
168 } |
|
169 } |
|
170 |
|
171 return VDE_OK; |
|
172 |
|
173 } |
|
174 |
|
175 case H263D_FTYPE_SIZE: |
|
176 { |
|
177 int retValue; |
|
178 vdeFrtSizeListItem_t *listItem; |
|
179 |
|
180 retValue = vdeFrtSeekSize(&store->sizeList, frameType->width, |
|
181 frameType->height, &listItem); |
|
182 if (retValue < 0) |
|
183 return retValue; |
|
184 |
|
185 if (listItem) |
|
186 *item = listItem->dataHandle; |
|
187 |
|
188 else { |
|
189 if (lstTail(&store->sizeList, (void **) &listItem) < 0) |
|
190 return VDE_ERROR; |
|
191 |
|
192 /* If a default item exists */ |
|
193 if (listItem && |
|
194 listItem->width == VDEFRT_ALL_WIDTHS && |
|
195 listItem->height == VDEFRT_ALL_HEIGHTS) |
|
196 *item = listItem->dataHandle; |
|
197 |
|
198 else { |
|
199 *item = 0; |
|
200 return VDE_OK_NOT_AVAILABLE; |
|
201 } |
|
202 } |
|
203 |
|
204 return VDE_OK; |
|
205 } |
|
206 |
|
207 case H263D_FTYPE_DEF: |
|
208 { |
|
209 vdeFrtSizeListItem_t *tailItem; |
|
210 |
|
211 if (lstTail(&store->sizeList, (void **) &tailItem) < 0) |
|
212 return VDE_ERROR; |
|
213 |
|
214 /* If a default item exists */ |
|
215 if (tailItem->width == VDEFRT_ALL_WIDTHS && |
|
216 tailItem->height == VDEFRT_ALL_HEIGHTS) { |
|
217 *item = tailItem->dataHandle; |
|
218 return VDE_OK; |
|
219 } |
|
220 |
|
221 else { |
|
222 *item = 0; |
|
223 return VDE_OK_NOT_AVAILABLE; |
|
224 } |
|
225 } |
|
226 |
|
227 default: |
|
228 return VDE_ERROR; |
|
229 } |
|
230 } |
|
231 |
|
232 |
|
233 /* {{-output"vdeFrtOpen.txt"}} */ |
|
234 /* |
|
235 * vdeFrtOpen |
|
236 * |
|
237 * Parameters: |
|
238 * store a pointer to a frame type store |
|
239 * |
|
240 * Function: |
|
241 * This function initializes the given frame type store. |
|
242 * |
|
243 * Returns: |
|
244 * VDE_OK if the function was successful |
|
245 * VDE_ERROR if an error occured |
|
246 * |
|
247 * |
|
248 */ |
|
249 |
|
250 int vdeFrtOpen(vdeFrtStore_t *store) |
|
251 /* {{-output"vdeFrtOpen.txt"}} */ |
|
252 { |
|
253 if (lstOpen(&store->sizeList) < 0) |
|
254 return VDE_ERROR; |
|
255 |
|
256 return VDE_OK; |
|
257 } |
|
258 |
|
259 |
|
260 /* {{-output"vdeFrtPutItem.txt"}} */ |
|
261 /* |
|
262 * vdeFrtPutItem |
|
263 * |
|
264 * Parameters: |
|
265 * store a pointer to a frame type store |
|
266 * frameType specifies the frame type for the given item |
|
267 * item a data handle to store |
|
268 * removeItem a function which is used to deallocate |
|
269 * the data handle when it is removed from |
|
270 * the store. NULL may be given if no |
|
271 * deallocation is needed. |
|
272 * |
|
273 * Function: |
|
274 * This function puts a data handle to the frame type store. |
|
275 * |
|
276 * Returns: |
|
277 * VDE_OK if the function was successful |
|
278 * VDE_ERROR if an error occured |
|
279 * |
|
280 * |
|
281 */ |
|
282 |
|
283 int vdeFrtPutItem(vdeFrtStore_t *store, h263dFrameType_t *frameType, |
|
284 u_int32 item, void (*removeItem) (void *)) |
|
285 /* {{-output"vdeFrtPutItem.txt"}} */ |
|
286 { |
|
287 switch (frameType->scope) { |
|
288 case H263D_FTYPE_ALL: |
|
289 { |
|
290 int retValue; |
|
291 vdeFrtSizeListItem_t *newItem; |
|
292 |
|
293 retValue = vdeFrtRemoveAll(store); |
|
294 if (retValue < 0) |
|
295 return retValue; |
|
296 |
|
297 newItem = (vdeFrtSizeListItem_t *) |
|
298 vdeMalloc(sizeof(vdeFrtSizeListItem_t)); |
|
299 if (!newItem) |
|
300 return VDE_ERROR; |
|
301 |
|
302 newItem->width = VDEFRT_ALL_WIDTHS; |
|
303 newItem->height = VDEFRT_ALL_HEIGHTS; |
|
304 newItem->fSnapshot = 0; |
|
305 newItem->dataHandle = item; |
|
306 newItem->dealloc = removeItem; |
|
307 |
|
308 if (lstAdd(&store->sizeList, newItem) < 0) { |
|
309 vdeDealloc(newItem); |
|
310 return VDE_ERROR; |
|
311 } |
|
312 |
|
313 return VDE_OK; |
|
314 } |
|
315 |
|
316 case H263D_FTYPE_DEF: |
|
317 { |
|
318 vdeFrtSizeListItem_t *tailItem; |
|
319 |
|
320 if (lstTail(&store->sizeList, (void **) &tailItem) < 0) |
|
321 return VDE_ERROR; |
|
322 |
|
323 /* If a default item exists */ |
|
324 if (tailItem->width == VDEFRT_ALL_WIDTHS && |
|
325 tailItem->height == VDEFRT_ALL_HEIGHTS) { |
|
326 |
|
327 if (tailItem->dealloc) |
|
328 tailItem->dealloc((void *) tailItem->dataHandle); |
|
329 |
|
330 /* Overwrite its data handle */ |
|
331 tailItem->dataHandle = item; |
|
332 } |
|
333 |
|
334 else { |
|
335 vdeFrtSizeListItem_t *newItem; |
|
336 |
|
337 newItem = (vdeFrtSizeListItem_t *) |
|
338 vdeMalloc(sizeof(vdeFrtSizeListItem_t)); |
|
339 if (!newItem) |
|
340 return VDE_ERROR; |
|
341 |
|
342 newItem->width = VDEFRT_ALL_WIDTHS; |
|
343 newItem->height = VDEFRT_ALL_HEIGHTS; |
|
344 newItem->fSnapshot = 0; |
|
345 newItem->dataHandle = item; |
|
346 newItem->dealloc = removeItem; |
|
347 |
|
348 if (lstEnd(&store->sizeList) < 0) { |
|
349 vdeDealloc(newItem); |
|
350 return VDE_ERROR; |
|
351 } |
|
352 |
|
353 if (lstAdd(&store->sizeList, newItem) < 0) { |
|
354 vdeDealloc(newItem); |
|
355 return VDE_ERROR; |
|
356 } |
|
357 } |
|
358 |
|
359 return VDE_OK; |
|
360 } |
|
361 |
|
362 case H263D_FTYPE_SIZE: |
|
363 { |
|
364 int retValue; |
|
365 vdeFrtSizeListItem_t *listItem; |
|
366 |
|
367 retValue = vdeFrtSeekSize(&store->sizeList, frameType->width, |
|
368 frameType->height, &listItem); |
|
369 if (retValue < 0) |
|
370 return retValue; |
|
371 |
|
372 /* If a setting with the same size already exists */ |
|
373 if (listItem) { |
|
374 |
|
375 if (listItem->dealloc) |
|
376 listItem->dealloc((void *) listItem->dataHandle); |
|
377 |
|
378 /* Overwrite its data handle */ |
|
379 listItem->dataHandle = item; |
|
380 } |
|
381 |
|
382 else { |
|
383 vdeFrtSizeListItem_t *newItem; |
|
384 |
|
385 if (lstHead(&store->sizeList, (void **) &listItem) < 0) |
|
386 return VDE_ERROR; |
|
387 |
|
388 newItem = (vdeFrtSizeListItem_t *) |
|
389 vdeMalloc(sizeof(vdeFrtSizeListItem_t)); |
|
390 if (!newItem) |
|
391 return VDE_ERROR; |
|
392 |
|
393 newItem->width = frameType->width; |
|
394 newItem->height = frameType->height; |
|
395 newItem->fSnapshot = 0; |
|
396 newItem->dataHandle = item; |
|
397 newItem->dealloc = removeItem; |
|
398 |
|
399 if (lstAdd(&store->sizeList, newItem) < 0) { |
|
400 vdeDealloc(newItem); |
|
401 return VDE_ERROR; |
|
402 } |
|
403 } |
|
404 |
|
405 return VDE_OK; |
|
406 } |
|
407 |
|
408 case H263D_FTYPE_SIZE + H263D_FTYPE_SNAPSHOT: |
|
409 { |
|
410 int retValue; |
|
411 vdeFrtSizeListItem_t *listItem; |
|
412 |
|
413 retValue = vdeFrtSeekItem(&store->sizeList, frameType->width, |
|
414 frameType->height, frameType->fSnapshot, &listItem); |
|
415 if (retValue < 0) |
|
416 return retValue; |
|
417 |
|
418 /* If a setting with the same parameters already exists */ |
|
419 if (listItem) { |
|
420 |
|
421 if (listItem->dealloc) |
|
422 listItem->dealloc((void *) listItem->dataHandle); |
|
423 |
|
424 /* Overwrite its data handle */ |
|
425 listItem->dataHandle = item; |
|
426 } |
|
427 |
|
428 else { |
|
429 vdeFrtSizeListItem_t *newItem; |
|
430 |
|
431 if (lstHead(&store->sizeList, (void **) &listItem) < 0) |
|
432 return VDE_ERROR; |
|
433 |
|
434 newItem = (vdeFrtSizeListItem_t *) |
|
435 vdeMalloc(sizeof(vdeFrtSizeListItem_t)); |
|
436 if (!newItem) |
|
437 return VDE_ERROR; |
|
438 |
|
439 newItem->width = frameType->width; |
|
440 newItem->height = frameType->height; |
|
441 newItem->fSnapshot = frameType->fSnapshot; |
|
442 newItem->dataHandle = item; |
|
443 newItem->dealloc = removeItem; |
|
444 |
|
445 if (lstAdd(&store->sizeList, newItem) < 0) { |
|
446 vdeDealloc(newItem); |
|
447 return VDE_ERROR; |
|
448 } |
|
449 } |
|
450 |
|
451 return VDE_OK; |
|
452 |
|
453 } |
|
454 default: |
|
455 return VDE_ERROR; |
|
456 } |
|
457 } |
|
458 |
|
459 |
|
460 /* {{-output"vdeFrtRemoveItem.txt"}} */ |
|
461 /* |
|
462 * vdeFrtRemoveItem |
|
463 * |
|
464 * Parameters: |
|
465 * store a pointer to a frame type store |
|
466 * frameType specifies the frame type for the item to remove |
|
467 * |
|
468 * Function: |
|
469 * This function removes an entry from the given frame type store. |
|
470 * The entry corresponds to the given frame type. |
|
471 * |
|
472 * Returns: |
|
473 * VDE_OK if the function was successful |
|
474 * VDE_ERROR if an error occured |
|
475 * |
|
476 * |
|
477 */ |
|
478 |
|
479 int vdeFrtRemoveItem(vdeFrtStore_t *store, h263dFrameType_t *frameType) |
|
480 /* {{-output"vdeFrtRemoveItem.txt"}} */ |
|
481 { |
|
482 switch (frameType->scope) { |
|
483 case H263D_FTYPE_ALL: |
|
484 { |
|
485 int retValue; |
|
486 |
|
487 retValue = vdeFrtRemoveAll(store); |
|
488 if (retValue < 0) |
|
489 return retValue; |
|
490 |
|
491 return VDE_OK; |
|
492 } |
|
493 |
|
494 case H263D_FTYPE_DEF: |
|
495 { |
|
496 vdeFrtSizeListItem_t *tailItem; |
|
497 |
|
498 if (lstTail(&store->sizeList, (void **) &tailItem) < 0) |
|
499 return VDE_ERROR; |
|
500 |
|
501 /* If a default item exists */ |
|
502 if (tailItem && tailItem->width == VDEFRT_ALL_WIDTHS && |
|
503 tailItem->height == VDEFRT_ALL_HEIGHTS) { |
|
504 |
|
505 /* Remove it */ |
|
506 if (lstRemove(&store->sizeList, (void **) &tailItem) < 0) |
|
507 return VDE_ERROR; |
|
508 |
|
509 if (tailItem->dealloc) |
|
510 tailItem->dealloc((void *) tailItem->dataHandle); |
|
511 |
|
512 vdeDealloc(tailItem); |
|
513 } |
|
514 |
|
515 return VDE_OK; |
|
516 } |
|
517 |
|
518 case H263D_FTYPE_SIZE: |
|
519 { |
|
520 int retValue; |
|
521 vdeFrtSizeListItem_t *listItem; |
|
522 |
|
523 retValue = vdeFrtSeekSize(&store->sizeList, frameType->width, |
|
524 frameType->height, &listItem); |
|
525 if (retValue < 0) |
|
526 return retValue; |
|
527 |
|
528 /* If an item with the same size already exists */ |
|
529 if (listItem) { |
|
530 |
|
531 /* Remove it */ |
|
532 if (lstRemove(&store->sizeList, (void **) &listItem) < 0) |
|
533 return VDE_ERROR; |
|
534 |
|
535 if (listItem->dealloc) |
|
536 listItem->dealloc((void *) listItem->dataHandle); |
|
537 |
|
538 vdeDealloc(listItem); |
|
539 } |
|
540 |
|
541 return VDE_OK; |
|
542 } |
|
543 |
|
544 case H263D_FTYPE_SIZE + H263D_FTYPE_SNAPSHOT: |
|
545 { |
|
546 int retValue; |
|
547 vdeFrtSizeListItem_t *listItem; |
|
548 |
|
549 retValue = vdeFrtSeekItem(&store->sizeList, frameType->width, |
|
550 frameType->height, frameType->fSnapshot, &listItem); |
|
551 if (retValue < 0) |
|
552 return retValue; |
|
553 |
|
554 /* If an item with the same parameters already exists */ |
|
555 if (listItem) { |
|
556 |
|
557 /* Remove it */ |
|
558 if (lstRemove(&store->sizeList, (void **) &listItem) < 0) |
|
559 return VDE_ERROR; |
|
560 |
|
561 if (listItem->dealloc) |
|
562 listItem->dealloc((void *) listItem->dataHandle); |
|
563 |
|
564 vdeDealloc(listItem); |
|
565 } |
|
566 return VDE_OK; |
|
567 |
|
568 } |
|
569 |
|
570 default: |
|
571 return VDE_ERROR; |
|
572 } |
|
573 } |
|
574 |
|
575 |
|
576 /* |
|
577 * Local functions |
|
578 */ |
|
579 |
|
580 /* |
|
581 * vdeFrtRemoveAll |
|
582 * This function removes all items from the given store. |
|
583 */ |
|
584 |
|
585 static int vdeFrtRemoveAll(vdeFrtStore_t *store) |
|
586 { |
|
587 vdeFrtSizeListItem_t *listItem; |
|
588 |
|
589 if (lstHead(&store->sizeList, (void **) &listItem) < 0) |
|
590 return VDE_ERROR; |
|
591 |
|
592 do { |
|
593 if (lstRemove(&store->sizeList, (void **) &listItem) < 0) |
|
594 return VDE_ERROR; |
|
595 |
|
596 if (listItem) { |
|
597 if (listItem->dealloc) |
|
598 listItem->dealloc((void *) listItem->dataHandle); |
|
599 vdeDealloc(listItem); |
|
600 } |
|
601 } while (listItem); |
|
602 |
|
603 return VDE_OK; |
|
604 } |
|
605 |
|
606 |
|
607 /* |
|
608 * vdeFrtSeekSize |
|
609 * This function seeks for the given width and height from the given |
|
610 * size list. It returns the matching size list item (if there is one). |
|
611 */ |
|
612 |
|
613 static int vdeFrtSeekSize(lst_t *sizeList, int width, int height, |
|
614 vdeFrtSizeListItem_t **seekHit) |
|
615 { |
|
616 vdeFrtSizeListItem_t *listItem; |
|
617 |
|
618 *seekHit = NULL; |
|
619 |
|
620 if (lstHead(sizeList, (void **) &listItem) < 0) |
|
621 return VDE_ERROR; |
|
622 |
|
623 while (listItem) { |
|
624 if (lstNext(sizeList, (void **) &listItem) < 0) |
|
625 return VDE_ERROR; |
|
626 |
|
627 if (listItem && listItem->width == width && listItem->height == height) { |
|
628 *seekHit = listItem; |
|
629 break; |
|
630 } |
|
631 } |
|
632 |
|
633 return VDE_OK; |
|
634 } |
|
635 |
|
636 /* |
|
637 * vdeFrtSeekItem |
|
638 * This function seeks for an item with the given parameters from the |
|
639 * size list. It returns the matching list item (if there is one). |
|
640 */ |
|
641 |
|
642 static int vdeFrtSeekItem(lst_t *sizeList, int width, int height, |
|
643 u_char fSnapshot, vdeFrtSizeListItem_t **seekHit) |
|
644 { |
|
645 vdeFrtSizeListItem_t *listItem; |
|
646 |
|
647 *seekHit = NULL; |
|
648 |
|
649 if (lstHead(sizeList, (void **) &listItem) < 0) |
|
650 return VDE_ERROR; |
|
651 |
|
652 while (listItem) { |
|
653 |
|
654 if (listItem && listItem->width == width && listItem->height == height && |
|
655 listItem->fSnapshot == fSnapshot) { |
|
656 *seekHit = listItem; |
|
657 break; |
|
658 } |
|
659 if (lstNext(sizeList, (void **) &listItem) < 0) |
|
660 return VDE_ERROR; |
|
661 } |
|
662 |
|
663 return VDE_OK; |
|
664 } |
|
665 |
|
666 // End of File |