19
|
1 |
/*
|
25
|
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: Base GStreamer Adaptation Source
|
|
15 |
*
|
|
16 |
*/
|
19
|
17 |
|
|
18 |
#include <string.h>
|
25
|
19 |
#include <gst/gst.h>
|
|
20 |
#include <gst/gstbuffer.h>
|
53
|
21 |
#include <stdlib.h>
|
|
22 |
#ifdef INPUTSRCSELECTION_FEATURE
|
|
23 |
#include <gst/interfaces/gstaudioinputinterface.h>
|
|
24 |
#endif
|
19
|
25 |
#include "xaobjectitf.h"
|
33
|
26 |
#include "xaadaptationgst.h"
|
19
|
27 |
/*
|
|
28 |
* XAAdaptationGstCtx* XAAdaptationGst_Create()
|
|
29 |
* 1st phase initialization function for Adaptation Base context structure.
|
|
30 |
* Reserves memory for base context and initializes GStreamer FW.
|
|
31 |
*/
|
25
|
32 |
XAresult XAAdaptationGst_Init(XAAdaptationGstCtx* pSelf, XAuint32 ctxId)
|
|
33 |
{
|
19
|
34 |
DEBUG_API("->XAAdaptationGst_Init");
|
|
35 |
|
25
|
36 |
if (pSelf)
|
|
37 |
{
|
|
38 |
if (XAAdaptationBase_Init(&(pSelf->baseObj), ctxId)
|
|
39 |
!= XA_RESULT_SUCCESS)
|
19
|
40 |
{
|
|
41 |
DEBUG_ERR("Failed to init base context!!!");
|
|
42 |
free(pSelf);
|
|
43 |
pSelf = NULL;
|
|
44 |
}
|
|
45 |
else
|
|
46 |
{
|
33
|
47 |
GError* gerror = 0;
|
25
|
48 |
/* Add default handler for Gst-bus messages */
|
53
|
49 |
//pSelf->busCb = XAAdaptationGst_GstBusCb;
|
19
|
50 |
pSelf->cond_mutx_inited = XA_BOOLEAN_FALSE;
|
53
|
51 |
#ifdef PROFILE_HEAP_USAGE
|
|
52 |
xa_heap_total_alloc_print("Before GST Init");
|
|
53 |
#endif
|
25
|
54 |
sem_init(&(pSelf->semAsyncWait), 0, 0);
|
33
|
55 |
if ( !gst_init_check( NULL, NULL, &gerror ) )
|
|
56 |
{
|
|
57 |
DEBUG_ERR("Gst Initalization failure.");
|
|
58 |
return XA_RESULT_INTERNAL_ERROR;
|
|
59 |
}
|
53
|
60 |
#ifdef PROFILE_HEAP_USAGE
|
|
61 |
xa_heap_total_alloc_print("After GST Init");
|
|
62 |
#endif
|
19
|
63 |
}
|
25
|
64 |
}
|
19
|
65 |
else
|
25
|
66 |
{
|
53
|
67 |
DEBUG_ERR("Invalid Gst Base Context.");
|
19
|
68 |
return XA_RESULT_PARAMETER_INVALID;
|
25
|
69 |
}
|
19
|
70 |
|
|
71 |
DEBUG_API("<-XAAdaptationGst_Init");
|
|
72 |
return XA_RESULT_SUCCESS;
|
25
|
73 |
}
|
19
|
74 |
|
|
75 |
/*
|
|
76 |
* XAresult XAAdaptationGst_PostInit()
|
|
77 |
* 2nd phase initialization for Adaptation Base.
|
|
78 |
*/
|
25
|
79 |
XAresult XAAdaptationGst_PostInit(XAAdaptationGstCtx* ctx)
|
|
80 |
{
|
19
|
81 |
XAresult ret = XA_RESULT_SUCCESS;
|
|
82 |
DEBUG_API("->XAAdaptationGst_PostInit");
|
|
83 |
XAAdaptationBase_PostInit(&ctx->baseObj);
|
25
|
84 |
|
19
|
85 |
ctx->thread_launched = XA_BOOLEAN_FALSE;
|
|
86 |
pthread_mutex_init(&(ctx->ds_mutex), NULL);
|
|
87 |
pthread_cond_init(&(ctx->ds_condition), NULL);
|
|
88 |
ctx->cond_mutx_inited = XA_BOOLEAN_TRUE;
|
25
|
89 |
|
19
|
90 |
DEBUG_API("<-XAAdaptationGst_PostInit");
|
|
91 |
return ret;
|
25
|
92 |
}
|
19
|
93 |
|
|
94 |
/*
|
|
95 |
* void XAAdaptationGst_Free( XAAdaptationGstCtx* ctx )
|
|
96 |
* Frees all Base context variables .
|
|
97 |
*/
|
25
|
98 |
void XAAdaptationGst_Free(XAAdaptationGstCtx* ctx)
|
|
99 |
{
|
|
100 |
GstElement* fakesink = NULL;
|
19
|
101 |
DEBUG_API("->XAAdaptationGst_Free");
|
|
102 |
|
25
|
103 |
if (ctx->bin)
|
|
104 |
{
|
|
105 |
fakesink = gst_bin_get_by_name(GST_BIN(ctx->bin), "fakesink");
|
|
106 |
if (fakesink)
|
|
107 |
{
|
|
108 |
gst_element_set_state(GST_ELEMENT(fakesink), GST_STATE_NULL);
|
|
109 |
gst_object_unref(fakesink);
|
|
110 |
}
|
19
|
111 |
|
25
|
112 |
if (gst_element_set_state(GST_ELEMENT(ctx->bin), GST_STATE_NULL)
|
|
113 |
!= GST_STATE_CHANGE_SUCCESS)
|
|
114 |
{ /*not much we can do*/
|
53
|
115 |
DEBUG_ERR("WARNING: Failed to change to NULL state before deletion!!");
|
25
|
116 |
}
|
19
|
117 |
}
|
|
118 |
|
25
|
119 |
if (ctx->asynctimer)
|
|
120 |
{ /*cancel timer*/
|
19
|
121 |
g_source_remove(ctx->asynctimer);
|
25
|
122 |
}
|
19
|
123 |
sem_post(&(ctx->semAsyncWait));
|
|
124 |
sem_destroy(&(ctx->semAsyncWait));
|
|
125 |
|
|
126 |
XAAdaptationGst_StopGstListener(ctx);
|
|
127 |
|
25
|
128 |
if (ctx->bin)
|
|
129 |
{
|
19
|
130 |
gst_object_unref(ctx->bin);
|
25
|
131 |
}
|
19
|
132 |
|
|
133 |
if (ctx->cond_mutx_inited == XA_BOOLEAN_TRUE)
|
|
134 |
{
|
|
135 |
ctx->thread_launched = XA_BOOLEAN_FALSE;
|
|
136 |
pthread_mutex_destroy(&(ctx->ds_mutex));
|
|
137 |
pthread_cond_destroy(&(ctx->ds_condition));
|
|
138 |
ctx->cond_mutx_inited = XA_BOOLEAN_FALSE;
|
|
139 |
}
|
|
140 |
XAAdaptationBase_Free(&ctx->baseObj);
|
25
|
141 |
|
19
|
142 |
DEBUG_API("<-XAAdaptationGst_Free");
|
25
|
143 |
}
|
19
|
144 |
|
|
145 |
XAresult XAAdaptationGst_InitGstListener(XAAdaptationGstCtx* ctx)
|
25
|
146 |
{
|
19
|
147 |
int ret;
|
|
148 |
DEBUG_API("->XAAdaptationGst_InitGstListener");
|
25
|
149 |
if (ctx->bin)
|
|
150 |
{
|
|
151 |
ctx->bus = gst_pipeline_get_bus(GST_PIPELINE( ctx->bin ));
|
|
152 |
}
|
|
153 |
if (!ctx->bus)
|
|
154 |
{
|
53
|
155 |
DEBUG_ERR("could not get gst bus!");
|
19
|
156 |
return XA_RESULT_INTERNAL_ERROR;
|
25
|
157 |
}
|
|
158 |
ret = pthread_create(&(ctx->busloopThr), NULL,
|
|
159 |
(XAAdaptationGst_LaunchGstListener), (void*) ctx);
|
|
160 |
if (ctx->thread_launched == XA_BOOLEAN_FALSE)
|
|
161 |
{
|
19
|
162 |
// Wait until the thread is created
|
|
163 |
pthread_mutex_lock(&(ctx->ds_mutex));
|
|
164 |
pthread_cond_wait(&(ctx->ds_condition), &(ctx->ds_mutex));
|
|
165 |
pthread_mutex_unlock(&(ctx->ds_mutex));
|
25
|
166 |
}
|
|
167 |
if (ret)
|
|
168 |
{
|
53
|
169 |
DEBUG_ERR_A1("could not create thread!! (%d)",ret);
|
19
|
170 |
return XA_RESULT_INTERNAL_ERROR;
|
33
|
171 |
}
|
|
172 |
DEBUG_API("<-XAAdaptationGst_InitGstListener");
|
25
|
173 |
return XA_RESULT_SUCCESS;
|
19
|
174 |
}
|
|
175 |
|
|
176 |
void * XAAdaptationGst_LaunchGstListener(void* args)
|
25
|
177 |
{
|
|
178 |
XAAdaptationGstCtx* ctx = (XAAdaptationGstCtx*) args;
|
19
|
179 |
DEBUG_API("->XAAdaptationGst_LaunchGstListener");
|
|
180 |
// Signal calling thread that this thread creation is completed
|
|
181 |
ctx->thread_launched = XA_BOOLEAN_TRUE;
|
|
182 |
pthread_mutex_lock(&(ctx->ds_mutex));
|
|
183 |
pthread_cond_signal(&(ctx->ds_condition));
|
|
184 |
pthread_mutex_unlock(&(ctx->ds_mutex));
|
|
185 |
|
25
|
186 |
ctx->busloop = g_main_loop_new(NULL, FALSE);
|
|
187 |
if (!ctx->busloop)
|
|
188 |
{
|
|
189 |
DEBUG_ERR("Glib main loop failure.");
|
19
|
190 |
DEBUG_API("<-XAAdaptationGst_LaunchGstListener");
|
25
|
191 |
}
|
19
|
192 |
else
|
25
|
193 |
{
|
53
|
194 |
DEBUG_INFO("Start Glib main loop");
|
19
|
195 |
g_main_loop_run(ctx->busloop);
|
25
|
196 |
DEBUG_INFO("Glib main loop stopped - exiting thread");
|
19
|
197 |
DEBUG_API("<-XAAdaptationGst_LaunchGstListener");
|
|
198 |
pthread_exit(NULL);
|
25
|
199 |
}
|
|
200 |
return NULL;
|
19
|
201 |
}
|
|
202 |
|
|
203 |
void XAAdaptationGst_StopGstListener(XAAdaptationGstCtx* ctx)
|
25
|
204 |
{
|
19
|
205 |
DEBUG_API("->XAAdaptationGst_StopGstListener");
|
25
|
206 |
if (ctx->busloop)
|
|
207 |
{
|
|
208 |
g_main_loop_quit(ctx->busloop);
|
19
|
209 |
g_main_loop_unref(ctx->busloop);
|
25
|
210 |
}
|
|
211 |
if (ctx->bus)
|
|
212 |
{
|
19
|
213 |
gst_object_unref(ctx->bus);
|
|
214 |
ctx->bus = NULL;
|
33
|
215 |
}
|
|
216 |
DEBUG_API("<-XAAdaptationGst_StopGstListener");
|
19
|
217 |
}
|
|
218 |
|
|
219 |
/*
|
|
220 |
* ASynchronous operation managing
|
|
221 |
**/
|
|
222 |
|
|
223 |
/* NOTE: This should NOT be called from gst callbacks - danger of deadlock!!
|
|
224 |
*/
|
|
225 |
void XAAdaptationGst_PrepareAsyncWait(XAAdaptationGstCtx* ctx)
|
25
|
226 |
{
|
19
|
227 |
DEBUG_API("->XAAdaptationGst_PrepareAsyncWait");
|
|
228 |
|
25
|
229 |
if (ctx->waitingasyncop)
|
|
230 |
{ /*wait previous async op*/
|
19
|
231 |
DEBUG_INFO("::WARNING:: previous asynch still ongoing!!!");
|
|
232 |
DEBUG_INFO(">>>> WAIT PREVIOUS");
|
|
233 |
sem_wait(&(ctx->semAsyncWait));
|
|
234 |
DEBUG_INFO("<<<< PREVIOUS COMPLETED");
|
25
|
235 |
}
|
|
236 |
sem_init(&(ctx->semAsyncWait), 0, 0);
|
19
|
237 |
|
|
238 |
ctx->waitingasyncop = XA_BOOLEAN_TRUE;
|
|
239 |
DEBUG_API("<-XAAdaptationGst_PrepareAsyncWait");
|
25
|
240 |
}
|
19
|
241 |
|
|
242 |
void XAAdaptationGst_StartAsyncWait(XAAdaptationGstCtx* ctx)
|
25
|
243 |
{
|
19
|
244 |
DEBUG_API("->XAAdaptationGst_StartAsyncWait");
|
|
245 |
|
|
246 |
/* timeout to try to avoid gst freeze in rollup */
|
|
247 |
ctx->asynctimer = g_timeout_add(XA_ADAPT_ASYNC_TIMEOUT,
|
25
|
248 |
XAAdaptationGst_CancelAsyncWait, ctx);
|
19
|
249 |
/* check flag once again if callback already happened before wait */
|
25
|
250 |
if (ctx->waitingasyncop)
|
|
251 |
{
|
19
|
252 |
DEBUG_INFO(">>>> ASYNC STARTS");
|
|
253 |
sem_wait(&(ctx->semAsyncWait));
|
|
254 |
DEBUG_INFO("<<<< ASYNC COMPLETED");
|
25
|
255 |
}
|
19
|
256 |
else
|
25
|
257 |
{
|
19
|
258 |
DEBUG_INFO("<> async completed already");
|
25
|
259 |
}
|
19
|
260 |
/*cancel timer*/
|
25
|
261 |
if (ctx->asynctimer)
|
|
262 |
{
|
19
|
263 |
g_source_remove(ctx->asynctimer);
|
25
|
264 |
}
|
19
|
265 |
ctx->waitingasyncop = XA_BOOLEAN_FALSE;
|
|
266 |
|
|
267 |
DEBUG_API("<-XAAdaptationGst_StartAsyncWait");
|
25
|
268 |
}
|
19
|
269 |
|
|
270 |
/* async operation timeout callback*/
|
|
271 |
gboolean XAAdaptationGst_CancelAsyncWait(gpointer ctx)
|
25
|
272 |
{
|
|
273 |
XAAdaptationGstCtx* bCtx = (XAAdaptationGstCtx*) ctx;
|
19
|
274 |
DEBUG_API("->XAAdaptationGst_CancelAsyncWait");
|
25
|
275 |
if (bCtx->waitingasyncop)
|
|
276 |
{
|
19
|
277 |
DEBUG_ERR_A3("ASYNC TIMED OUT : current %d, gsttarget %d, wanted %d",
|
25
|
278 |
GST_STATE(bCtx->bin), GST_STATE_TARGET(bCtx->bin), bCtx->binWantedState);
|
19
|
279 |
bCtx->waitingasyncop = XA_BOOLEAN_FALSE;
|
|
280 |
sem_post(&(bCtx->semAsyncWait));
|
33
|
281 |
}
|
|
282 |
DEBUG_API("<-XAAdaptationGst_CancelAsyncWait");
|
19
|
283 |
/* return false to remove timer */
|
|
284 |
return FALSE;
|
25
|
285 |
}
|
19
|
286 |
|
|
287 |
void XAAdaptationGst_CompleteAsyncWait(XAAdaptationGstCtx* ctx)
|
25
|
288 |
{
|
19
|
289 |
DEBUG_API("->XAAdaptationGst_CompleteAsyncWait");
|
25
|
290 |
if (ctx->waitingasyncop)
|
|
291 |
{
|
19
|
292 |
int i;
|
|
293 |
ctx->waitingasyncop = XA_BOOLEAN_FALSE;
|
25
|
294 |
sem_getvalue(&(ctx->semAsyncWait), &i);
|
19
|
295 |
DEBUG_INFO_A1("Asynch operation succeeded, sem value %d",i);
|
25
|
296 |
if (i <= 0)
|
|
297 |
{ /* only post if locked */
|
19
|
298 |
sem_post(&(ctx->semAsyncWait));
|
25
|
299 |
}
|
|
300 |
else if (i > 0)
|
|
301 |
{ /* should not be, reset semaphore */
|
|
302 |
sem_init(&(ctx->semAsyncWait), 0, 0);
|
|
303 |
}
|
33
|
304 |
}
|
|
305 |
DEBUG_API("<-XAAdaptationGst_CompleteAsyncWait");
|
19
|
306 |
}
|
|
307 |
|
|
308 |
/**
|
|
309 |
* GstElement* XAAdaptationGst_CreateGstSource( XADataSource* xaSrc, const XAchar *name )
|
|
310 |
* @param XADataSource* xaSnk - XADataSource defining gst source to create
|
|
311 |
* @param const XAchar *name - string for naming the gst element
|
|
312 |
* @param XAboolean *isobj - (out param) is source another XA object?
|
|
313 |
* @return GstElement* - return newly created gst source element
|
|
314 |
* Description: Create gst source element corresponding to XA source structure
|
|
315 |
*/
|
25
|
316 |
GstElement* XAAdaptationGst_CreateGstSource(XADataSource* xaSrc,
|
53
|
317 |
const char *name, XAboolean *isPCM )
|
25
|
318 |
{
|
19
|
319 |
XAuint32 locType = 0;
|
|
320 |
GstElement* gstSrc = NULL;
|
53
|
321 |
#ifdef INPUTSRCSELECTION_FEATURE
|
|
322 |
GstAudioInputConfigIntfc *audioInputIntfc = NULL;
|
|
323 |
#endif
|
25
|
324 |
char* fname = NULL;
|
19
|
325 |
XADataLocator_URI* uri = NULL;
|
|
326 |
XADataLocator_IODevice* ioDevice = NULL;
|
|
327 |
|
|
328 |
DEBUG_API("->XAAdaptationGst_CreateGstSource");
|
53
|
329 |
if (!xaSrc || !xaSrc->pLocator )
|
25
|
330 |
{
|
19
|
331 |
return NULL;
|
25
|
332 |
}
|
53
|
333 |
|
25
|
334 |
if (xaSrc && xaSrc->pFormat && *((XAuint32*) (xaSrc->pFormat))
|
|
335 |
==XA_DATAFORMAT_PCM && isPCM)
|
|
336 |
{
|
19
|
337 |
*isPCM = XA_BOOLEAN_TRUE;
|
25
|
338 |
}
|
53
|
339 |
|
25
|
340 |
locType = *((XAuint32*) (xaSrc->pLocator));
|
|
341 |
switch (locType)
|
|
342 |
{
|
19
|
343 |
case XA_DATALOCATOR_URI:
|
53
|
344 |
{
|
|
345 |
DEBUG_INFO("XA_DATALOCATOR_URI");
|
25
|
346 |
uri = (XADataLocator_URI*) xaSrc->pLocator;
|
|
347 |
gstSrc = gst_element_factory_make("filesrc", name);
|
|
348 |
if (uri->URI != NULL)
|
|
349 |
{
|
53
|
350 |
DEBUG_INFO_A1_STR("URI: %s", (char *)uri->URI);
|
25
|
351 |
if (strncmp((char *) uri->URI, "file:///", 8) == 0)
|
19
|
352 |
{
|
25
|
353 |
fname = (char *) &((uri->URI)[8]);
|
19
|
354 |
}
|
|
355 |
else
|
|
356 |
{
|
25
|
357 |
fname = (char *) uri->URI;
|
53
|
358 |
}
|
|
359 |
DEBUG_INFO_A1_STR("->filesystem path %s", (char *)fname);
|
25
|
360 |
g_object_set(G_OBJECT(gstSrc), "location", fname, NULL);
|
|
361 |
/*check for pcm - decodebin does not know how to handle raw PCM files */
|
|
362 |
if (isPCM && strstr(fname, ".pcm"))
|
|
363 |
{
|
|
364 |
DEBUG_INFO("PCM file detected");
|
|
365 |
*isPCM = XA_BOOLEAN_TRUE;
|
19
|
366 |
}
|
25
|
367 |
}
|
|
368 |
else
|
19
|
369 |
{
|
|
370 |
DEBUG_ERR("No uri specified.");
|
|
371 |
return NULL;
|
25
|
372 |
}
|
19
|
373 |
break; /* XA_DATALOCATOR_URI */
|
53
|
374 |
}
|
19
|
375 |
case XA_DATALOCATOR_IODEVICE:
|
53
|
376 |
{
|
|
377 |
DEBUG_INFO("XA_DATALOCATOR_IODEVICE");
|
25
|
378 |
ioDevice = (XADataLocator_IODevice*) (xaSrc->pLocator);
|
|
379 |
switch (ioDevice->deviceType)
|
|
380 |
{
|
19
|
381 |
case XA_IODEVICE_AUDIOINPUT:
|
25
|
382 |
{
|
19
|
383 |
DEBUG_INFO("XA_IODEVICE_AUDIOINPUT");
|
|
384 |
DEBUG_INFO_A1("ioDevice->deviceID: %x", ioDevice->deviceID);
|
25
|
385 |
switch (ioDevice->deviceID)
|
19
|
386 |
{
|
53
|
387 |
case XA_ADAPTID_DEVSOUNDSRC_MIC:
|
|
388 |
DEBUG_INFO("devsoundsrc");
|
|
389 |
gstSrc = gst_element_factory_make("devsoundsrc",
|
|
390 |
name);
|
|
391 |
#ifdef INPUTSRCSELECTION_FEATURE
|
|
392 |
if(gstSrc)
|
|
393 |
{
|
|
394 |
audioInputIntfc = GST_AUDIO_INPUT_CONFIG_GET_IFACE(gstSrc);
|
|
395 |
if(audioInputIntfc)
|
|
396 |
{
|
|
397 |
audioInputIntfc->SetAudioInputs(EDefaultMicrophone);
|
|
398 |
}
|
|
399 |
}
|
|
400 |
#endif
|
|
401 |
break;
|
|
402 |
case XA_ADAPTID_DEVSOUNDSRC_FMRX:
|
|
403 |
DEBUG_INFO("devsoundsrc");
|
25
|
404 |
gstSrc = gst_element_factory_make("devsoundsrc",
|
53
|
405 |
name);
|
|
406 |
#ifdef INPUTSRCSELECTION_FEATURE
|
|
407 |
if(gstSrc)
|
|
408 |
{
|
|
409 |
audioInputIntfc = GST_AUDIO_INPUT_CONFIG_GET_IFACE(gstSrc);
|
|
410 |
if(audioInputIntfc)
|
|
411 |
{
|
|
412 |
audioInputIntfc->SetAudioInputs(EFmRadio);
|
|
413 |
}
|
|
414 |
}
|
|
415 |
#endif
|
19
|
416 |
break;
|
53
|
417 |
case XA_ADAPTID_DEVSOUNDSRC_CALL:
|
|
418 |
DEBUG_INFO("devsoundsrc");
|
|
419 |
gstSrc = gst_element_factory_make("devsoundsrc",
|
|
420 |
name);
|
|
421 |
#ifdef INPUTSRCSELECTION_FEATURE
|
|
422 |
if(gstSrc)
|
|
423 |
{
|
|
424 |
audioInputIntfc = GST_AUDIO_INPUT_CONFIG_GET_IFACE(gstSrc);
|
|
425 |
if(audioInputIntfc)
|
|
426 |
{
|
|
427 |
audioInputIntfc->SetAudioInputs(EVoiceCall);
|
|
428 |
}
|
|
429 |
}
|
|
430 |
#endif
|
|
431 |
break;
|
|
432 |
|
25
|
433 |
case XA_ADAPTID_AUDIOTESTSRC:
|
|
434 |
/*fall through*/
|
19
|
435 |
default:
|
53
|
436 |
DEBUG_INFO("audiotestsrc");
|
25
|
437 |
gstSrc = gst_element_factory_make("audiotestsrc",
|
|
438 |
name);
|
19
|
439 |
break;
|
|
440 |
}
|
25
|
441 |
break;
|
19
|
442 |
}
|
25
|
443 |
|
19
|
444 |
default:
|
25
|
445 |
{
|
19
|
446 |
DEBUG_ERR("Unsupported IODevice.");
|
|
447 |
break;
|
25
|
448 |
}
|
19
|
449 |
}
|
|
450 |
break; /* XA_DATALOCATOR_IODEVICE */
|
53
|
451 |
}
|
19
|
452 |
case XA_DATALOCATOR_ADDRESS:
|
|
453 |
default:
|
53
|
454 |
DEBUG_ERR("Incorrect data locator for source.");
|
19
|
455 |
break;
|
25
|
456 |
}
|
19
|
457 |
|
25
|
458 |
if (gstSrc)
|
|
459 |
{
|
53
|
460 |
DEBUG_INFO_A1("Created gstreamer source element at %x", (int)gstSrc);
|
25
|
461 |
}
|
19
|
462 |
|
|
463 |
DEBUG_API("<-XAAdaptationGst_CreateGstSource");
|
|
464 |
return gstSrc;
|
25
|
465 |
}
|
19
|
466 |
|
|
467 |
/**
|
|
468 |
* GstElement* XAAdaptationGst_CreateGstSink( XADataSink* xaSnk, const XAchar *name )
|
|
469 |
* @param XADataSink* xaSnk - XADataSink defining gst sink to create
|
|
470 |
* @param const XAchar *name - string for naming the gst element
|
|
471 |
* @return GstElement* - return newly created gst sink element
|
|
472 |
* Description: Create gst sink element corresponding to XA sink structure
|
|
473 |
*/
|
25
|
474 |
GstElement* XAAdaptationGst_CreateGstSink(XADataSink* xaSnk,
|
53
|
475 |
const char *name)
|
25
|
476 |
{
|
19
|
477 |
XAuint32 locType = 0;
|
|
478 |
GstElement* gstSnk = NULL;
|
|
479 |
XADataLocator_URI* uri = NULL;
|
|
480 |
DEBUG_API("->XAAdaptationGst_CreateGstSink");
|
25
|
481 |
if (!xaSnk || !xaSnk->pLocator)
|
|
482 |
{
|
19
|
483 |
DEBUG_INFO("Warning! No sink specified, use fakesink");
|
25
|
484 |
gstSnk = gst_element_factory_make("fakesink", name);
|
|
485 |
if (!gstSnk)
|
|
486 |
{
|
19
|
487 |
DEBUG_ERR("Cannot create sink!");
|
|
488 |
return NULL;
|
25
|
489 |
}
|
|
490 |
g_object_set(G_OBJECT(gstSnk), "async", FALSE, NULL);
|
19
|
491 |
}
|
|
492 |
else
|
|
493 |
{
|
25
|
494 |
locType = *((XAuint32*) (xaSnk->pLocator));
|
|
495 |
switch (locType)
|
|
496 |
{
|
19
|
497 |
case XA_DATALOCATOR_URI:
|
53
|
498 |
{
|
|
499 |
DEBUG_INFO("XA_DATALOCATOR_URI");
|
25
|
500 |
uri = (XADataLocator_URI*) xaSnk->pLocator;
|
|
501 |
gstSnk = gst_element_factory_make("filesink", name);
|
|
502 |
if (!gstSnk)
|
|
503 |
{
|
19
|
504 |
DEBUG_ERR("Cannot create sink!");
|
|
505 |
return NULL;
|
25
|
506 |
}
|
|
507 |
if (uri->URI != NULL)
|
|
508 |
{
|
19
|
509 |
XAchar *fname;
|
53
|
510 |
DEBUG_INFO_A1_STR("URI: %s", (char *)uri->URI);
|
25
|
511 |
if (strncmp((char *) uri->URI, "file:///", 8) == 0)
|
|
512 |
{
|
19
|
513 |
fname = &((uri->URI)[8]);
|
25
|
514 |
}
|
19
|
515 |
else
|
25
|
516 |
{
|
19
|
517 |
fname = uri->URI;
|
53
|
518 |
}
|
|
519 |
DEBUG_INFO_A1_STR("->filesystem path %s", (char *)fname);
|
25
|
520 |
g_object_set(G_OBJECT(gstSnk), "location", fname,
|
|
521 |
"async", FALSE, "qos", FALSE, "max-lateness",
|
|
522 |
(gint64) (-1), NULL);
|
19
|
523 |
}
|
|
524 |
else
|
25
|
525 |
{
|
19
|
526 |
DEBUG_ERR("No recording output uri specified.");
|
|
527 |
return NULL;
|
25
|
528 |
}
|
19
|
529 |
break;
|
53
|
530 |
}
|
|
531 |
/* case XA_DATALOCATOR_ADDRESS:
|
19
|
532 |
case XA_DATALOCATOR_NATIVEDISPLAY:
|
|
533 |
case XA_DATALOCATOR_OUTPUTMIX:
|
53
|
534 |
case XA_DATALOCATOR_IODEVICE:*/
|
19
|
535 |
/* when only valid IOdevice sinks vibra and LED sinks implemented
|
|
536 |
* at adaptation level, add handling here (in this implementation,
|
|
537 |
* no handling needed as only dummy implementations for those)
|
|
538 |
**/
|
|
539 |
default:
|
53
|
540 |
DEBUG_ERR("Incorrect data locator for sink.");
|
19
|
541 |
break;
|
25
|
542 |
}
|
19
|
543 |
}
|
25
|
544 |
if (gstSnk)
|
|
545 |
{
|
53
|
546 |
DEBUG_INFO_A1("Created gstreamer sink element at %x", (int)gstSnk);
|
33
|
547 |
}
|
|
548 |
DEBUG_API("<-XAAdaptationGst_CreateGstSink");
|
25
|
549 |
return gstSnk;
|
19
|
550 |
}
|
|
551 |
|
|
552 |
/* called when pad is actually blocking/ gets unblocked*/
|
25
|
553 |
void XAAdaptationGst_PadBlockCb(GstPad *pad, gboolean blocked,
|
|
554 |
gpointer user_data)
|
|
555 |
{
|
53
|
556 |
DEBUG_API_A2_STR("->XAAdaptationGst_PadBlockCb pad \"%s\" of \"%s\" ",
|
25
|
557 |
GST_OBJECT_NAME(pad),
|
|
558 |
GST_OBJECT_NAME(gst_pad_get_parent_element(pad)) );
|
19
|
559 |
DEBUG_API_A1("<-XAAdaptationGst_PadBlockCb blocked:%d",blocked);
|
25
|
560 |
}
|
19
|
561 |
|