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 <assert.h> |
|
19 #include <string.h> |
|
20 #include "xaadaptationcontextbasemmf.h" |
|
21 #include "xaadaptationmmf.h" |
|
22 #include "xaobjectitf.h" |
|
23 #include "xamediaplayeradaptctxmmf.h" |
|
24 |
|
25 /* |
|
26 * XAAdaptationBaseCtx* XAAdaptationBase_Create() |
|
27 * 1st phase initialization function for Adaptation Base context structure. |
|
28 * Reserves memory for base context and initializes GStreamer FW. |
|
29 */ |
|
30 XAresult XAAdaptationBaseMMF_Init( XAAdaptationBaseMMFCtx* pSelf, XAuint32 ctxId ) |
|
31 { |
|
32 DEBUG_API("->XAAdaptationBase_Init"); |
|
33 |
|
34 if ( pSelf ) |
|
35 { |
|
36 pSelf->evtHdlrs = g_array_new (FALSE, FALSE, sizeof (XAAdaptEvtHdlrMMF)); |
|
37 pSelf->ctxId = ctxId; |
|
38 } |
|
39 else |
|
40 { |
|
41 DEBUG_ERR("Invalid Adaptation Base Context.") |
|
42 return XA_RESULT_PARAMETER_INVALID; |
|
43 } |
|
44 |
|
45 DEBUG_API("<-XAAdaptationBase_Init"); |
|
46 return XA_RESULT_SUCCESS; |
|
47 } |
|
48 |
|
49 /* |
|
50 * XAresult XAAdaptationBase_PostInit() |
|
51 * 2nd phase initialization for Adaptation Base. |
|
52 */ |
|
53 XAresult XAAdaptationBaseMMF_PostInit( XAAdaptationBaseMMFCtx* ctx ) |
|
54 { |
|
55 XAresult ret = XA_RESULT_SUCCESS; |
|
56 DEBUG_API("->XAAdaptationBase_PostInit"); |
|
57 |
|
58 |
|
59 |
|
60 DEBUG_API("<-XAAdaptationBase_PostInit"); |
|
61 return ret; |
|
62 } |
|
63 |
|
64 /* |
|
65 * void XAAdaptationBase_Free( XAAdaptationBaseCtx* ctx ) |
|
66 * Frees all Base context variables . |
|
67 */ |
|
68 void XAAdaptationBaseMMF_Free( XAAdaptationBaseMMFCtx* ctx ) |
|
69 { |
|
70 g_array_free(ctx->evtHdlrs, TRUE); |
|
71 DEBUG_API("<-XAAdaptationBase_Free"); |
|
72 } |
|
73 |
|
74 /* |
|
75 * XAresult XAAdaptationBase_AddEventHandler |
|
76 * Adds event handler for certain event types. |
|
77 */ |
|
78 XAresult XAAdaptationBaseMMF_AddEventHandler( XAAdaptationBaseMMFCtx* ctx, xaAdaptEventHandlerMMF evtHandler, |
|
79 XAuint32 evtTypes, void *pHandlerCtx ) |
|
80 { |
|
81 XAuint32 i; |
|
82 XAAdaptEvtHdlrMMF tmp; |
|
83 DEBUG_API("->XAAdaptationBase_AddEventHandler"); |
|
84 if(!ctx) |
|
85 { |
|
86 DEBUG_ERR("no context"); |
|
87 return XA_RESULT_PARAMETER_INVALID; |
|
88 } |
|
89 |
|
90 for(i=0; i<ctx->evtHdlrs->len; i++) |
|
91 { |
|
92 if( (g_array_index(ctx->evtHdlrs, XAAdaptEvtHdlrMMF, i)).handlerfunc == evtHandler ) |
|
93 { |
|
94 return XA_RESULT_PARAMETER_INVALID; |
|
95 } |
|
96 } |
|
97 tmp.handlerfunc = evtHandler; |
|
98 tmp.handlercontext = pHandlerCtx; |
|
99 tmp.eventtypes = evtTypes; |
|
100 g_array_append_val(ctx->evtHdlrs, tmp); |
|
101 DEBUG_API("<-XAAdaptationBase_AddEventHandler"); |
|
102 return XA_RESULT_SUCCESS; |
|
103 } |
|
104 |
|
105 /* |
|
106 * XAresult XAAdaptationBase_RemoveEventHandler |
|
107 * Removes event handler for certain event types. |
|
108 */ |
|
109 XAresult XAAdaptationBaseMMF_RemoveEventHandler( XAAdaptationBaseMMFCtx* ctx, xaAdaptEventHandlerMMF evtHandler) |
|
110 { |
|
111 XAuint32 i; |
|
112 DEBUG_API("->XAAdaptationBase_RemoveEventHandler"); |
|
113 if(!ctx) |
|
114 { |
|
115 DEBUG_ERR("no context"); |
|
116 return XA_RESULT_PARAMETER_INVALID; |
|
117 } |
|
118 for(i=0; i<ctx->evtHdlrs->len; i++) |
|
119 { |
|
120 if( (g_array_index(ctx->evtHdlrs, XAAdaptEvtHdlrMMF, i)).handlerfunc == evtHandler ) |
|
121 { |
|
122 g_array_remove_index(ctx->evtHdlrs, i); |
|
123 return XA_RESULT_SUCCESS; |
|
124 } |
|
125 } |
|
126 DEBUG_API("<-XAAdaptationBase_RemoveEventHandler"); |
|
127 /*did not find, return error*/ |
|
128 return XA_RESULT_PARAMETER_INVALID; |
|
129 } |
|
130 |
|
131 void XAAdaptationBaseMMF_SendAdaptEvents(XAAdaptationBaseMMFCtx* ctx, XAAdaptEventMMF* event) |
|
132 { |
|
133 XAuint32 i; |
|
134 XAAdaptEvtHdlrMMF* tmp; |
|
135 for(i=0; i<ctx->evtHdlrs->len; i++) |
|
136 { |
|
137 tmp = &g_array_index(ctx->evtHdlrs, XAAdaptEvtHdlrMMF, i); |
|
138 if( tmp->eventtypes & event->eventtype ) |
|
139 { |
|
140 (tmp->handlerfunc)(tmp->handlercontext, event); |
|
141 } |
|
142 } |
|
143 } |
|