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: Media Player Adapt Code MMF |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <assert.h> |
|
19 #include <stdlib.h> |
|
20 #include "xamediaplayeradaptctxmmf.h" |
|
21 #include "xaadaptationmmf.h" |
|
22 #include "xaobjectitf.h" |
|
23 #include "cmmfbackendengine.h" |
|
24 #include "cmetadatautilityitf.h" |
|
25 |
|
26 /* |
|
27 * XAMediaPlayerAdaptationMMFCtx* XAMediaPlayerAdapt_Create() |
|
28 * Allocates memory for Media Player Adaptation Context and makes 1st phase initialization |
|
29 * @param XADataSource *pDataSrc - pointer to OMX-AL data source |
|
30 * @param XADataSource *pBankSrc - pointer to instrument bank structure in Mobile DLS, if NULL default will be used. |
|
31 * @param XADataSink *pAudioSnk - pointer to OMX-AL audio sink definition |
|
32 * @param XADataSink *pImageVideoSnk - pointer to OMX-AL image and video sink definition |
|
33 * @returns XAMediaPlayerAdaptationMMFCtx* - Pointer to created context, NULL if error occurs. |
|
34 */ |
|
35 XAAdaptationBaseCtx* XAMediaPlayerAdaptMMF_Create(XADataSource *pDataSrc, |
|
36 XADataSource *pBankSrc, XADataSink *pAudioSnk, |
|
37 XADataSink *pImageVideoSnk, XADataSink *pVibra, XADataSink *pLEDArray) |
|
38 { |
|
39 XAMediaPlayerAdaptationMMFCtx *pSelf = NULL; |
|
40 XAuint32 locType = 0; |
|
41 XADataLocator_IODevice *ioDevice; |
|
42 XAresult res; |
|
43 DEBUG_API("->XAMediaPlayerAdaptMMF_Create"); |
|
44 |
|
45 pSelf = calloc(1, sizeof(XAMediaPlayerAdaptationMMFCtx)); |
|
46 if (pSelf) |
|
47 { |
|
48 if (pDataSrc) |
|
49 { |
|
50 locType = *((XAuint32*) (pDataSrc->pLocator)); |
|
51 if (locType == XA_DATALOCATOR_IODEVICE) |
|
52 { |
|
53 ioDevice = (XADataLocator_IODevice*) (pDataSrc->pLocator); |
|
54 if (ioDevice->deviceType == XA_IODEVICE_RADIO) |
|
55 { |
|
56 return XAMediaPlayerAdaptMMF_CreateRadio(pSelf, pDataSrc, |
|
57 pBankSrc, pAudioSnk, pImageVideoSnk, pVibra, |
|
58 pLEDArray); |
|
59 } |
|
60 } |
|
61 } |
|
62 if (XAAdaptationBaseMMF_Init(&(pSelf->baseObj), |
|
63 XAMediaPlayerAdaptation) != XA_RESULT_SUCCESS) |
|
64 { |
|
65 DEBUG_ERR("Failed to init base context!!!"); |
|
66 free(pSelf); |
|
67 pSelf = NULL; |
|
68 } |
|
69 else |
|
70 { |
|
71 pSelf->isForRadio = XA_BOOLEAN_FALSE; |
|
72 pSelf->baseObj.baseObj.fwtype = FWMgrFWMMF; |
|
73 pSelf->xaSource = pDataSrc; |
|
74 pSelf->xaBankSrc = pBankSrc; |
|
75 pSelf->xaAudioSink = pAudioSnk; |
|
76 pSelf->xaVideoSink = pImageVideoSnk; |
|
77 pSelf->xaLEDArray = pLEDArray; |
|
78 pSelf->xaVibra = pVibra; |
|
79 pSelf->curMirror = XA_VIDEOMIRROR_NONE; |
|
80 pSelf->curRotation = 0; |
|
81 pSelf->isobjsrc = XA_BOOLEAN_FALSE; |
|
82 pSelf->cameraSinkSynced = XA_BOOLEAN_FALSE; |
|
83 pSelf->rateprops = XA_RATEPROP_SMOOTHVIDEO | XA_RATEPROP_NOPITCHCORAUDIO; |
|
84 pSelf->playrate = 1000; |
|
85 } |
|
86 } |
|
87 else |
|
88 { |
|
89 DEBUG_ERR("Failed to create XAMediaPlayerAdaptationMMFCtx !!!"); |
|
90 return NULL; |
|
91 } |
|
92 |
|
93 if (pSelf) |
|
94 { |
|
95 res = mmf_backend_engine_init(&(pSelf->mmfContext)); |
|
96 if (!(pSelf->mmfContext) || (res != XA_RESULT_SUCCESS)) |
|
97 { |
|
98 /* TODO Check to make sure there is no undeleted MMF objects here*/ |
|
99 DEBUG_ERR("Failed to init mmf context!!!"); |
|
100 free(pSelf); |
|
101 pSelf = NULL; |
|
102 return NULL; |
|
103 } |
|
104 res = mmf_set_play_adapt_context(pSelf->mmfContext, |
|
105 &(pSelf->baseObj)); |
|
106 if (pDataSrc) |
|
107 { |
|
108 pSelf->mmfMetadataContext |
|
109 = mmf_metadata_utility_init( |
|
110 (char *) (((XADataLocator_URI*) (pDataSrc->pLocator))->URI)); |
|
111 if (!pSelf->mmfMetadataContext) |
|
112 { |
|
113 DEBUG_ERR("Failed to init mmf metadata context!!!"); |
|
114 pSelf->mmfMetadataContext = NULL; |
|
115 } |
|
116 } |
|
117 else |
|
118 { |
|
119 DEBUG_ERR("Failed to create XAMediaPlayerAdaptationMMFCtx !!!"); |
|
120 return NULL; |
|
121 } |
|
122 } |
|
123 |
|
124 DEBUG_API("<-XAMediaPlayerAdaptMMF_Create"); |
|
125 return (XAAdaptationBaseCtx*) (&pSelf->baseObj.baseObj); |
|
126 } |
|
127 |
|
128 /* |
|
129 * XAMediaPlayerAdaptationMMFCtx* XAMediaPlayerAdapt_CreateRadio() |
|
130 |
|
131 * @returns XAMediaPlayerAdaptationMMFCtx* - Pointer to created context, NULL if error occurs. |
|
132 */ |
|
133 XAAdaptationBaseCtx* XAMediaPlayerAdaptMMF_CreateRadio( |
|
134 XAMediaPlayerAdaptationMMFCtx *pSelf, XADataSource *pDataSrc, |
|
135 XADataSource *pBankSrc, XADataSink *pAudioSnk, |
|
136 XADataSink *pImageVideoSnk, XADataSink *pVibra, XADataSink *pLEDArray) |
|
137 { |
|
138 XAresult res; |
|
139 DEBUG_API("->XAMediaPlayerAdaptMMF_CreateRadio"); |
|
140 |
|
141 res = XAAdaptationBaseMMF_Init(&(pSelf->baseObj), XARadioAdaptation); |
|
142 if (res != XA_RESULT_SUCCESS) |
|
143 { |
|
144 DEBUG_ERR("Failed to init base context!!!"); |
|
145 free(pSelf); |
|
146 pSelf = NULL; |
|
147 return NULL; |
|
148 } |
|
149 |
|
150 pSelf->isForRadio = XA_BOOLEAN_TRUE; |
|
151 pSelf->baseObj.baseObj.fwtype = FWMgrFWMMF; |
|
152 pSelf->xaSource = pDataSrc; |
|
153 pSelf->xaBankSrc = pBankSrc; |
|
154 pSelf->xaAudioSink = pAudioSnk; |
|
155 pSelf->xaVideoSink = pImageVideoSnk; |
|
156 pSelf->xaLEDArray = pLEDArray; |
|
157 pSelf->xaVibra = pVibra; |
|
158 pSelf->curMirror = XA_VIDEOMIRROR_NONE; |
|
159 pSelf->curRotation = 0; |
|
160 pSelf->isobjsrc = XA_BOOLEAN_FALSE; |
|
161 pSelf->cameraSinkSynced = XA_BOOLEAN_FALSE; |
|
162 /*pSelf->waitData = XA_BOOLEAN_FALSE;*/ |
|
163 |
|
164 res = mmf_backend_engine_init(&(pSelf->mmfContext)); |
|
165 if (!(pSelf->mmfContext) || (res != XA_RESULT_SUCCESS)) |
|
166 { |
|
167 /* TODO Check to make sure there is no undeleted MMF objects here*/ |
|
168 DEBUG_ERR("Failed to init mmf context!!!"); |
|
169 free(pSelf); |
|
170 pSelf = NULL; |
|
171 return NULL; |
|
172 } |
|
173 DEBUG_API("<-XAMediaPlayerAdaptMMF_Create"); |
|
174 return (XAAdaptationBaseCtx*) (&pSelf->baseObj.baseObj); |
|
175 } |
|
176 |
|
177 /* |
|
178 * XAresult XAMediaPlayerAdaptMMF_PostInit() |
|
179 * 2nd phase initialization of Media Player Adaptation Context |
|
180 * @param XAMediaPlayerAdaptationMMFCtx* ctx - pointer to Media Player adaptation context |
|
181 * @return XAresult - Success value |
|
182 */ |
|
183 XAresult XAMediaPlayerAdaptMMF_PostInit(XAAdaptationMMFCtx* bCtx) |
|
184 { |
|
185 XAresult ret = XA_RESULT_PRECONDITIONS_VIOLATED; |
|
186 XAMediaPlayerAdaptationMMFCtx *pSelf = NULL; |
|
187 if(!bCtx) |
|
188 { |
|
189 ret = XA_RESULT_PARAMETER_INVALID; |
|
190 return ret; |
|
191 } |
|
192 |
|
193 pSelf = (XAMediaPlayerAdaptationMMFCtx*) bCtx; |
|
194 |
|
195 DEBUG_API("->XAMediaPlayerAdaptMMF_PostInit"); |
|
196 |
|
197 ret = XAAdaptationBaseMMF_PostInit(bCtx); |
|
198 if(ret == XA_RESULT_SUCCESS) |
|
199 { |
|
200 if (pSelf->isForRadio) |
|
201 { |
|
202 DEBUG_API("<-XAMediaPlayerAdaptMMF_PostInit"); |
|
203 return XA_RESULT_SUCCESS; |
|
204 } |
|
205 |
|
206 if (pSelf->mmfContext) |
|
207 { |
|
208 XADataLocator_URI* tempUri = |
|
209 (XADataLocator_URI*) (pSelf->xaSource->pLocator); |
|
210 XADataFormat_MIME* tempFormat = |
|
211 (XADataFormat_MIME*) (pSelf->xaSource->pFormat); |
|
212 ret = XA_RESULT_SUCCESS; |
|
213 if (pSelf->xaVideoSink) |
|
214 { |
|
215 ret = mmf_setup_native_display(pSelf->mmfContext, |
|
216 pSelf->xaVideoSink); |
|
217 } |
|
218 if (ret == XA_RESULT_SUCCESS) |
|
219 { |
|
220 ret = mmf_set_player_uri(pSelf->mmfContext, |
|
221 (char *) (tempUri->URI), tempFormat->containerType); |
|
222 } |
|
223 } |
|
224 } |
|
225 DEBUG_API("<-XAMediaPlayerAdaptMMF_PostInit"); |
|
226 return ret; |
|
227 } |
|
228 |
|
229 /* |
|
230 * void XAMediaPlayerAdaptMMF_Destroy( XAMediaPlayerAdaptationMMFCtx* ctx ) |
|
231 * Destroys Media Player Adaptation Context |
|
232 * @param ctx - Media Player Adaptation context to be destroyed |
|
233 */ |
|
234 void XAMediaPlayerAdaptMMF_Destroy(XAAdaptationMMFCtx* bCtx) |
|
235 { |
|
236 XAMediaPlayerAdaptationMMFCtx* ctx = NULL; |
|
237 |
|
238 DEBUG_API("->XAMediaPlayerAdaptMMF_Destroy"); |
|
239 if (bCtx == NULL) |
|
240 { |
|
241 DEBUG_ERR("Invalid parameter!!"); |
|
242 DEBUG_API("<-XAMediaPlayerAdaptMMF_Destroy"); |
|
243 return; |
|
244 } |
|
245 ctx = (XAMediaPlayerAdaptationMMFCtx*) bCtx; |
|
246 |
|
247 if (ctx->mmfContext) |
|
248 { |
|
249 mmf_backend_engine_deinit(ctx->mmfContext); |
|
250 } |
|
251 |
|
252 if (ctx->mmfMetadataContext) |
|
253 { |
|
254 mmf_metadata_utility_destroy(ctx->mmfMetadataContext); |
|
255 } |
|
256 |
|
257 XAAdaptationBaseMMF_Free(bCtx); |
|
258 |
|
259 free(ctx); |
|
260 ctx = NULL; |
|
261 |
|
262 DEBUG_API("<-XAMediaPlayerAdaptMMF_Destroy"); |
|
263 } |
|
264 |
|