19
|
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 |
*
|
25
|
14 |
* Description: Media Recorder Adaptation for GST
|
19
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include <string.h>
|
20
|
19 |
#include <gst/gst.h>
|
19
|
20 |
#include "xacapabilitiesmgr.h"
|
|
21 |
#include "xamediarecorderadaptctx.h"
|
53
|
22 |
#include "xaobjectitf.h"
|
19
|
23 |
/*forward declarations*/
|
|
24 |
GstElement* XAMediaRecorderAdapt_CreateEncodeBin(
|
|
25 |
XAMediaRecorderAdaptationCtx* ctx);
|
|
26 |
XAresult XAMediaRecorderAdapt_CreatePipeline(
|
|
27 |
XAMediaRecorderAdaptationCtx* ctx);
|
28
|
28 |
|
19
|
29 |
|
|
30 |
/*
|
|
31 |
* gboolean XAMediaRecorderAdapt_GstBusCb( GstBus *bus, GstMessage *message, gpointer data )
|
|
32 |
* MediaPlayer Gst-bus message handler (Callback)
|
|
33 |
*/
|
|
34 |
gboolean XAMediaRecorderAdapt_GstBusCb(GstBus *bus, GstMessage *message,
|
|
35 |
gpointer data)
|
53
|
36 |
{
|
19
|
37 |
XAAdaptationGstCtx* bCtx = (XAAdaptationGstCtx*) data;
|
53
|
38 |
XAMediaRecorderAdaptationCtx* mCtx = (XAMediaRecorderAdaptationCtx*)data;
|
|
39 |
|
19
|
40 |
/* only listen to pipeline messages */
|
53
|
41 |
DEBUG_API_A2_STR("->XAMediaRecorderAdapt_GstBusCb:\"%s\" from object \"%s\"",
|
|
42 |
GST_MESSAGE_TYPE_NAME(message), GST_OBJECT_NAME(GST_MESSAGE_SRC(message)));
|
19
|
43 |
|
53
|
44 |
switch( GST_MESSAGE_TYPE(message))
|
19
|
45 |
{
|
53
|
46 |
case GST_MESSAGE_EOS:
|
19
|
47 |
{
|
53
|
48 |
if (GST_MESSAGE_SRC(message)==GST_OBJECT(bCtx->bin))
|
|
49 |
{
|
19
|
50 |
/* stop position tracking */
|
|
51 |
if(mCtx->runpositiontimer > 0)
|
53
|
52 |
{
|
19
|
53 |
g_source_remove(mCtx->runpositiontimer);
|
53
|
54 |
mCtx->runpositiontimer=0;
|
|
55 |
}
|
19
|
56 |
|
|
57 |
/* complete any ongoing client async operations */
|
|
58 |
XAAdaptationGst_CompleteAsyncWait(bCtx);
|
|
59 |
|
|
60 |
if(mCtx->positionCb)
|
53
|
61 |
{
|
19
|
62 |
mCtx->positionCb(bCtx);
|
53
|
63 |
}
|
19
|
64 |
bCtx->binWantedState = GST_STATE_PAUSED;
|
53
|
65 |
|
|
66 |
if(bCtx->busError)
|
19
|
67 |
{
|
53
|
68 |
XAObjItfCBData objdata = {XA_OBJECT_EVENT_RESOURCES_LOST, XA_RESULT_RESOURCE_ERROR, XA_OBJECT_STATE_UNREALIZED, NULL};
|
|
69 |
XAAdaptEvent event = {XA_OBJECTITFEVENTS, 0, sizeof(objdata), NULL };
|
|
70 |
event.data = &objdata;
|
|
71 |
/* send needed events */
|
|
72 |
|
|
73 |
XAAdaptationBase_SendAdaptEvents(&bCtx->baseObj, &event );
|
19
|
74 |
}
|
|
75 |
}
|
53
|
76 |
break;
|
|
77 |
}
|
|
78 |
case GST_MESSAGE_STATE_CHANGED:
|
|
79 |
{
|
|
80 |
if (GST_MESSAGE_SRC(message)==GST_OBJECT(bCtx->bin))
|
19
|
81 |
{
|
53
|
82 |
GstState oldstate, newstate, pendingstate, gsttargetstate;
|
|
83 |
gst_message_parse_state_changed(message, &oldstate, &newstate, &pendingstate);
|
|
84 |
gsttargetstate = GST_STATE_TARGET(bCtx->bin);
|
|
85 |
DEBUG_INFO_A4("old %d -> new %d (-> pending %d -> gsttarget %d)",
|
|
86 |
oldstate, newstate, pendingstate, gsttargetstate);
|
|
87 |
if(gsttargetstate!=bCtx->binWantedState)
|
|
88 |
{
|
|
89 |
DEBUG_ERR_A1("WARNING: Gst target is not wanted target [%d]!!!", bCtx->binWantedState);
|
|
90 |
}
|
|
91 |
/* print out some more info */
|
|
92 |
if( pendingstate == GST_STATE_VOID_PENDING )
|
19
|
93 |
{
|
53
|
94 |
if( newstate != bCtx->binWantedState )
|
|
95 |
{
|
|
96 |
DEBUG_INFO_A2("Gst in intermediate state transition (curr %d, target %d)",
|
|
97 |
newstate,bCtx->binWantedState);
|
|
98 |
}
|
|
99 |
else
|
|
100 |
{
|
|
101 |
DEBUG_INFO_A1("Gst in wanted target state (%d)",newstate);
|
|
102 |
}
|
|
103 |
}
|
|
104 |
if( oldstate!=GST_STATE_PLAYING && newstate==GST_STATE_PLAYING )
|
|
105 |
{
|
|
106 |
XAAdaptEvent event = {XA_RECORDITFEVENTS, XA_RECORDEVENT_HEADMOVING, 0, NULL };
|
|
107 |
/* send needed events */
|
|
108 |
XAAdaptationBase_SendAdaptEvents(&bCtx->baseObj, &event );
|
|
109 |
/* enable position tracking if needed */
|
|
110 |
if( mCtx->runpositiontimer==0 && mCtx->trackpositionenabled && mCtx->positionCb )
|
|
111 |
{
|
|
112 |
mCtx->runpositiontimer = g_timeout_add(XA_ADAPT_PU_INTERVAL, mCtx->positionCb, mCtx);
|
|
113 |
}
|
19
|
114 |
}
|
|
115 |
}
|
|
116 |
break;
|
|
117 |
}
|
|
118 |
|
53
|
119 |
case GST_MESSAGE_ASYNC_DONE:
|
19
|
120 |
{
|
|
121 |
/* some async sequence ended */
|
|
122 |
XAAdaptationGst_CompleteAsyncWait(bCtx);
|
|
123 |
break;
|
|
124 |
}
|
|
125 |
|
53
|
126 |
case GST_MESSAGE_ERROR:
|
19
|
127 |
{
|
|
128 |
gchar* debug;
|
53
|
129 |
gst_message_parse_error(message, &(bCtx->busError), &debug);
|
|
130 |
DEBUG_ERR_A1_STR("Gst reports error \"%s\"", debug);
|
|
131 |
|
19
|
132 |
/* stop waiting any ongoing async operations */
|
|
133 |
XAAdaptationGst_CompleteAsyncWait(bCtx);
|
|
134 |
break;
|
|
135 |
}
|
53
|
136 |
case GST_MESSAGE_WARNING:
|
19
|
137 |
{
|
|
138 |
GError* error;
|
|
139 |
gchar* debug;
|
|
140 |
gst_message_parse_warning(message, &error, &debug);
|
53
|
141 |
DEBUG_ERR_A1_STR("Gst reports warning \"%s\"", debug);
|
19
|
142 |
/* stop waiting any ongoing async operations */
|
|
143 |
XAAdaptationGst_CompleteAsyncWait(bCtx);
|
|
144 |
break;
|
|
145 |
}
|
53
|
146 |
default:
|
|
147 |
break;
|
19
|
148 |
}
|
|
149 |
DEBUG_API("<-XAMediaRecorderAdapt_GstBusCb");
|
|
150 |
return TRUE;
|
|
151 |
}
|
|
152 |
|
|
153 |
/*
|
|
154 |
* XAAdaptationGstCtx* XAMediaRecorderAdapt_Create()
|
|
155 |
* Allocates memory for Media Recorder Adaptation Context and makes 1st phase initialization
|
|
156 |
* @param XADataSource *pAudioSrc - pointer to OMX-AL audio source
|
|
157 |
* @param XADataSource *pImageVideoSrc - pointer image/video source
|
|
158 |
* @param XADataSink *pDataSnk - pointer to OMX-AL sink
|
|
159 |
* @returns XAMediaRecorderAdaptationCtx* - Pointer to created context, NULL if error occurs.
|
|
160 |
*/
|
|
161 |
XAAdaptationBaseCtx* XAMediaRecorderAdapt_Create(XADataSource* pAudioSrc,
|
|
162 |
XADataSource* pImageVideoSrc, XADataSink* pDataSnk, XAuint8 recModes)
|
53
|
163 |
{
|
19
|
164 |
XAMediaRecorderAdaptationCtx *pSelf = NULL;
|
|
165 |
DEBUG_API("->XAMediaRecorderAdapt_Create");
|
|
166 |
|
|
167 |
pSelf = (XAMediaRecorderAdaptationCtx*)calloc(1, sizeof(XAMediaRecorderAdaptationCtx));
|
|
168 |
if (pSelf)
|
53
|
169 |
{
|
19
|
170 |
if (XAAdaptationGst_Init(&(pSelf->baseObj),
|
|
171 |
XAMediaRecorderAdaptation) != XA_RESULT_SUCCESS)
|
53
|
172 |
{
|
19
|
173 |
DEBUG_ERR("Failed to init base context!!!");
|
|
174 |
free(pSelf);
|
|
175 |
pSelf = NULL;
|
|
176 |
DEBUG_API("<-XAMediaRecorderAdapt_Create");
|
|
177 |
return NULL;
|
53
|
178 |
}
|
19
|
179 |
else
|
53
|
180 |
{
|
19
|
181 |
pSelf->baseObj.baseObj.fwtype = FWMgrFWGST;
|
|
182 |
pSelf->xaAudioSource = pAudioSrc;
|
|
183 |
pSelf->xaVideoSource = pImageVideoSrc;
|
|
184 |
pSelf->xaSink = pDataSnk;
|
|
185 |
pSelf->xaRecordState = XA_RECORDSTATE_STOPPED;
|
|
186 |
pSelf->recModes = recModes;
|
|
187 |
pSelf->isRecord = XA_BOOLEAN_FALSE;
|
|
188 |
|
|
189 |
/* defaults from API spec */
|
|
190 |
/* no specified defaults for rest, determined later from container type */
|
|
191 |
pSelf->audioEncSettings.encoderId = XA_ADAPTID_UNINITED;
|
28
|
192 |
pSelf->audioEncSettings.channelsIn = 0;
|
|
193 |
pSelf->audioEncSettings.channelsOut = 0;
|
|
194 |
pSelf->audioEncSettings.bitsPerSample = 0;
|
|
195 |
pSelf->audioEncSettings.bitRate = 0;
|
|
196 |
pSelf->audioEncSettings.sampleRate = 0;
|
|
197 |
pSelf->audioEncSettings.rateControl = 0;
|
|
198 |
pSelf->audioEncSettings.profileSetting = 0;
|
|
199 |
pSelf->audioEncSettings.levelSetting = 0;
|
|
200 |
pSelf->audioEncSettings.channelMode = 0;
|
|
201 |
pSelf->audioEncSettings.streamFormat = 0;
|
|
202 |
pSelf->audioEncSettings.encodeOptions = 0;
|
|
203 |
pSelf->audioEncSettings.blockAlignment = 0;
|
53
|
204 |
}
|
19
|
205 |
}
|
|
206 |
|
|
207 |
DEBUG_API("<-XAMediaRecorderAdapt_Create");
|
|
208 |
return (XAAdaptationBaseCtx*) &pSelf->baseObj;
|
53
|
209 |
}
|
19
|
210 |
|
|
211 |
/*
|
|
212 |
* XAresult XAMediaRecorderAdapt_PostInit()
|
|
213 |
* 2nd phase initialization of Media Recorder Adaptation Context
|
|
214 |
* @param XAAdaptationGstCtx* ctx - pointer to Media Recorder adaptation context
|
|
215 |
* @return XAresult - Success value
|
|
216 |
*/
|
|
217 |
XAresult XAMediaRecorderAdapt_PostInit(XAAdaptationGstCtx* bCtx)
|
53
|
218 |
{
|
19
|
219 |
GstStateChangeReturn gret;
|
|
220 |
|
|
221 |
XAresult ret = XA_RESULT_SUCCESS;
|
|
222 |
XAMediaRecorderAdaptationCtx* ctx = NULL;
|
|
223 |
DEBUG_API("->XAMediaRecorderAdapt_PostInit");
|
|
224 |
if (bCtx == NULL || bCtx->baseObj.ctxId != XAMediaRecorderAdaptation)
|
53
|
225 |
{
|
33
|
226 |
DEBUG_ERR("Invalid parameter!!");
|
|
227 |
DEBUG_API("<-XAMediaRecorderAdapt_PostInit");
|
19
|
228 |
return XA_RESULT_PARAMETER_INVALID;
|
53
|
229 |
}
|
19
|
230 |
ctx = (XAMediaRecorderAdaptationCtx*) bCtx;
|
|
231 |
|
|
232 |
ret = XAAdaptationGst_PostInit(bCtx);
|
|
233 |
if (ret != XA_RESULT_SUCCESS)
|
53
|
234 |
{
|
19
|
235 |
DEBUG_ERR("Gst context postinit failed!!");
|
|
236 |
return ret;
|
53
|
237 |
}
|
19
|
238 |
|
|
239 |
/* top level bin for media recorder */
|
|
240 |
bCtx->bin = gst_pipeline_new("media_recorder");
|
|
241 |
|
|
242 |
/* Create Gst bus listener. */
|
|
243 |
ret = XAAdaptationGst_InitGstListener(bCtx);
|
|
244 |
if (ret != XA_RESULT_SUCCESS)
|
53
|
245 |
{
|
19
|
246 |
DEBUG_ERR("Bus listener creation failed!!");
|
|
247 |
return ret;
|
53
|
248 |
}
|
19
|
249 |
/* Add Media Recorder specific handler */
|
|
250 |
if (bCtx->bus)
|
53
|
251 |
{
|
19
|
252 |
bCtx->busCb = XAMediaRecorderAdapt_GstBusCb;
|
|
253 |
gst_bus_add_signal_watch(bCtx->bus);
|
|
254 |
g_signal_connect(bCtx->bus, "message::eos", G_CALLBACK(bCtx->busCb), ctx );
|
|
255 |
g_signal_connect(bCtx->bus, "message::error", G_CALLBACK(bCtx->busCb), ctx );
|
|
256 |
g_signal_connect(bCtx->bus, "message::warning", G_CALLBACK(bCtx->busCb), ctx );
|
|
257 |
g_signal_connect(bCtx->bus, "message::state-changed", G_CALLBACK(bCtx->busCb), ctx );
|
|
258 |
g_signal_connect(bCtx->bus, "message::segment-done", G_CALLBACK(bCtx->busCb), ctx );
|
|
259 |
g_signal_connect(bCtx->bus, "message::async-done", G_CALLBACK(bCtx->busCb), ctx );
|
53
|
260 |
}
|
19
|
261 |
else
|
53
|
262 |
{
|
19
|
263 |
DEBUG_ERR("Failed to create message bus");
|
|
264 |
return XA_RESULT_INTERNAL_ERROR;
|
53
|
265 |
}
|
19
|
266 |
|
|
267 |
/* create pipeline */
|
|
268 |
ret = XAMediaRecorderAdapt_CreatePipeline(ctx);
|
|
269 |
if (ret != XA_RESULT_SUCCESS)
|
53
|
270 |
{
|
19
|
271 |
DEBUG_ERR("Failed to create recorder pipeline");
|
|
272 |
return XA_RESULT_INTERNAL_ERROR;
|
53
|
273 |
}
|
19
|
274 |
|
|
275 |
#ifdef XA_IMPL_MEASURE_GST_DELAY
|
|
276 |
bCtx->startTime = clock();
|
|
277 |
#endif /* XA_IMPL_MEASURE_GST_DELAY */
|
53
|
278 |
|
19
|
279 |
/* roll up bin */
|
53
|
280 |
bCtx->binWantedState = GST_STATE_READY;
|
19
|
281 |
XAAdaptationGst_PrepareAsyncWait(bCtx);
|
|
282 |
gret = gst_element_set_state(GST_ELEMENT(bCtx->bin), bCtx->binWantedState);
|
|
283 |
if (gret == GST_STATE_CHANGE_ASYNC)
|
53
|
284 |
{
|
19
|
285 |
DEBUG_INFO("Wait for preroll");
|
|
286 |
XAAdaptationGst_StartAsyncWait(bCtx);DEBUG_INFO("Preroll ready");
|
53
|
287 |
}
|
19
|
288 |
else if (gret == GST_STATE_CHANGE_FAILURE)
|
53
|
289 |
{
|
19
|
290 |
DEBUG_ERR("Preroll FAILED");
|
|
291 |
/*ret = XA_RESULT_INTERNAL_ERROR;*/
|
53
|
292 |
}
|
19
|
293 |
#ifdef XA_IMPL_MEASURE_GST_DELAY
|
|
294 |
bCtx->endTime = clock();
|
|
295 |
double diff = bCtx->endTime - bCtx->startTime;
|
|
296 |
diff = diff / CLOCKS_PER_SEC;
|
|
297 |
DEBUG_API_A1( "Starting up bin took %.4lf secs",diff);
|
|
298 |
#endif /* XA_IMPL_MEASURE_GST_DELAY */
|
53
|
299 |
|
19
|
300 |
|
|
301 |
bCtx->waitingasyncop = XA_BOOLEAN_FALSE;
|
|
302 |
|
|
303 |
DEBUG_API("<-XAMediaRecorderAdapt_PostInit");
|
|
304 |
return ret;
|
53
|
305 |
}
|
19
|
306 |
|
|
307 |
/*
|
|
308 |
* void XAMediaRecorderAdapt_Destroy( XAAdaptationGstCtx* bCtx )
|
|
309 |
* Destroys Media Recorder Adaptation Context
|
|
310 |
* @param ctx - Media Recorder Adaptation context to be destroyed
|
|
311 |
*/
|
|
312 |
void XAMediaRecorderAdapt_Destroy(XAAdaptationGstCtx* bCtx)
|
53
|
313 |
{
|
19
|
314 |
XAMediaRecorderAdaptationCtx* ctx = NULL;
|
|
315 |
char* fname = NULL;
|
|
316 |
DEBUG_API("->XAMediaRecorderAdapt_Destroy");
|
|
317 |
|
|
318 |
if (bCtx == NULL || bCtx->baseObj.ctxId != XAMediaRecorderAdaptation)
|
53
|
319 |
{
|
33
|
320 |
DEBUG_ERR("Invalid parameter!!");
|
|
321 |
DEBUG_API("<-XAMediaRecorderAdapt_Destroy");
|
19
|
322 |
return;
|
53
|
323 |
}
|
19
|
324 |
ctx = (XAMediaRecorderAdaptationCtx*) bCtx;
|
|
325 |
|
|
326 |
if (ctx->isRecord == XA_BOOLEAN_FALSE)
|
53
|
327 |
{
|
19
|
328 |
DEBUG_INFO("Removing unnecessary file.");
|
53
|
329 |
|
|
330 |
if (ctx->xaSink && *((XAuint32*) (ctx->xaSink->pLocator))
|
|
331 |
== XA_DATALOCATOR_URI)
|
19
|
332 |
{
|
53
|
333 |
if (strncmp(
|
|
334 |
(char *) ((XADataLocator_URI*) (ctx->xaSink->pLocator))->URI,
|
|
335 |
"file:///", 8) == 0)
|
|
336 |
{
|
|
337 |
fname
|
|
338 |
= (char *) &(((XADataLocator_URI*) (ctx->xaSink->pLocator))->URI[8]);
|
|
339 |
}
|
19
|
340 |
else
|
53
|
341 |
{
|
|
342 |
fname
|
|
343 |
= (char *) ((XADataLocator_URI*) (ctx->xaSink->pLocator))->URI;
|
|
344 |
}
|
|
345 |
|
19
|
346 |
if (remove(fname) != 0)
|
53
|
347 |
{
|
|
348 |
DEBUG_ERR_A1_STR("Cannot remove file %s", (char *)fname);
|
|
349 |
}
|
19
|
350 |
}
|
|
351 |
}
|
|
352 |
|
|
353 |
if (bCtx->bus)
|
53
|
354 |
{
|
19
|
355 |
gst_bus_remove_signal_watch(bCtx->bus);
|
53
|
356 |
}
|
19
|
357 |
XAAdaptationGst_CancelAsyncWait(bCtx);
|
|
358 |
|
|
359 |
if (ctx->runpositiontimer)
|
53
|
360 |
{
|
19
|
361 |
g_source_remove(ctx->runpositiontimer);
|
53
|
362 |
}
|
|
363 |
|
19
|
364 |
XAAdaptationGst_Free(bCtx);
|
|
365 |
|
|
366 |
free(ctx);
|
|
367 |
ctx = NULL;
|
|
368 |
|
|
369 |
DEBUG_API("<-XAMediaRecorderAdapt_Destroy");
|
53
|
370 |
}
|
19
|
371 |
|
|
372 |
/***************** INTERNAL FUNCTIONS *******************************/
|
|
373 |
|
53
|
374 |
/*
|
|
375 |
* void XAMediaRecorderAdapt_CreatePipeline( XAMediaRecorderAdaptationCtx* ctx );
|
|
376 |
*/
|
19
|
377 |
XAresult XAMediaRecorderAdapt_CreatePipeline(
|
|
378 |
XAMediaRecorderAdaptationCtx* ctx)
|
53
|
379 |
{
|
19
|
380 |
XAresult ret = XA_RESULT_SUCCESS;
|
|
381 |
DEBUG_API("->XAMediaRecorderAdapt_CreatePipeline");
|
|
382 |
|
|
383 |
/* Create the audio src */
|
|
384 |
if ( ctx->xaAudioSource )
|
53
|
385 |
{
|
19
|
386 |
/* create audio pipe source */
|
|
387 |
ctx->audiosource = XAAdaptationGst_CreateGstSource( ctx->xaAudioSource, "audiosource",
|
53
|
388 |
NULL );
|
|
389 |
|
19
|
390 |
if( ctx->audiosource )
|
53
|
391 |
{
|
19
|
392 |
if (gst_bin_add(GST_BIN(ctx->baseObj.bin), ctx->audiosource))
|
53
|
393 |
{
|
19
|
394 |
DEBUG_API("Added audiosource to bin");
|
53
|
395 |
}
|
19
|
396 |
else
|
53
|
397 |
{
|
19
|
398 |
DEBUG_API("Could not add audiosource to bin");
|
|
399 |
return XA_RESULT_INTERNAL_ERROR;
|
53
|
400 |
}
|
|
401 |
}
|
|
402 |
else
|
|
403 |
{
|
|
404 |
DEBUG_ERR("Could not create audio source!!!!");
|
|
405 |
return XA_RESULT_INTERNAL_ERROR;
|
19
|
406 |
}
|
43
|
407 |
}
|
19
|
408 |
|
|
409 |
/* create and add video pipeline */
|
|
410 |
ctx->codecbin = XAMediaRecorderAdapt_CreateEncodeBin(ctx);
|
|
411 |
if (ctx->codecbin)
|
53
|
412 |
{
|
19
|
413 |
if (gst_bin_add(GST_BIN(ctx->baseObj.bin), ctx->codecbin))
|
53
|
414 |
{
|
19
|
415 |
DEBUG_API("->XAMediaRecorderAdapt_CreatePipeline: gst_bin_add success");
|
53
|
416 |
}
|
19
|
417 |
else
|
53
|
418 |
{
|
19
|
419 |
DEBUG_ERR("Could not add codec bin");
|
|
420 |
return XA_RESULT_INTERNAL_ERROR;
|
53
|
421 |
}
|
19
|
422 |
}
|
|
423 |
else
|
53
|
424 |
{
|
19
|
425 |
DEBUG_ERR("Could not create encoding bin!!!");
|
|
426 |
return XA_RESULT_INTERNAL_ERROR;
|
43
|
427 |
}
|
19
|
428 |
|
|
429 |
/* create and add audio pipeline */
|
|
430 |
if ( ctx->audiosource )
|
53
|
431 |
{
|
|
432 |
//if(!gst_element_link(ctx->audiofilter, ctx->codecbin ))
|
|
433 |
if(!gst_element_link(ctx->audiosource, ctx->codecbin ))
|
43
|
434 |
{
|
53
|
435 |
DEBUG_ERR("Could not link audiosource to codecbin!!");
|
19
|
436 |
return XA_RESULT_INTERNAL_ERROR;
|
|
437 |
}
|
53
|
438 |
else
|
43
|
439 |
{
|
53
|
440 |
DEBUG_INFO("Warning: link audiosource to codecbin is successfull with muxcaps!!");
|
43
|
441 |
}
|
|
442 |
}
|
53
|
443 |
else
|
43
|
444 |
{
|
53
|
445 |
DEBUG_INFO("No audio input");
|
43
|
446 |
}
|
19
|
447 |
|
|
448 |
/* create and add data sink */
|
53
|
449 |
ctx->datasink = XAAdaptationGst_CreateGstSink( ctx->xaSink, "datasink" );
|
19
|
450 |
if( ctx->datasink )
|
43
|
451 |
{
|
19
|
452 |
if (gst_bin_add(GST_BIN(ctx->baseObj.bin), ctx->datasink))
|
53
|
453 |
{
|
19
|
454 |
DEBUG_INFO("Added datasink to bin");
|
53
|
455 |
}
|
19
|
456 |
else
|
53
|
457 |
{
|
19
|
458 |
DEBUG_ERR("Could not add datasink to bin");
|
|
459 |
return XA_RESULT_INTERNAL_ERROR;
|
53
|
460 |
}
|
19
|
461 |
if(!gst_element_link(ctx->codecbin, ctx->datasink))
|
53
|
462 |
{
|
19
|
463 |
DEBUG_ERR("Could not link codec to sink!!");
|
|
464 |
return XA_RESULT_INTERNAL_ERROR;
|
53
|
465 |
}
|
43
|
466 |
}
|
53
|
467 |
else
|
43
|
468 |
{
|
19
|
469 |
DEBUG_ERR("Could not create data sink!!!");
|
|
470 |
return XA_RESULT_INTERNAL_ERROR;
|
53
|
471 |
}
|
19
|
472 |
DEBUG_API("<-XAMediaRecorderAdapt_CreatePipeline");
|
|
473 |
return ret;
|
53
|
474 |
}
|
19
|
475 |
|
43
|
476 |
/*
|
|
477 |
* XAresult XAMediaRecorderAdapt_CheckCodec( XAMediaRecorderAdaptationCtx_* mCtx );
|
|
478 |
* Check codec compatibility and support with initiated datasink content
|
|
479 |
*/
|
|
480 |
XAresult XAMediaRecorderAdapt_CheckCodec( XAMediaRecorderAdaptationCtx_* mCtx, XACapsType encType, XAuint32 encoderId )
|
|
481 |
{
|
|
482 |
XAresult ret = XA_RESULT_SUCCESS;
|
53
|
483 |
XAuint32 format = 0;
|
43
|
484 |
XACapabilities temp;
|
|
485 |
|
|
486 |
DEBUG_API("->XAMediaRecorderAdapt_CheckCodec");
|
|
487 |
|
|
488 |
/*first, check if codec supported at all*/
|
|
489 |
ret = XACapabilitiesMgr_GetCapsById(mCtx->baseObj.baseObj.capslist,(XACapsType)(XACAP_ENCODER|encType), encoderId, &temp);
|
|
490 |
|
|
491 |
if( ret==XA_RESULT_SUCCESS )
|
53
|
492 |
{
|
43
|
493 |
if(encType & (XACAP_VIDEO|XACAP_AUDIO))
|
19
|
494 |
{
|
53
|
495 |
if(mCtx->xaSink && mCtx->xaSink->pFormat)
|
|
496 |
{
|
43
|
497 |
format = *(XAuint32*)(mCtx->xaSink->pFormat);
|
53
|
498 |
}
|
19
|
499 |
else
|
53
|
500 |
{
|
43
|
501 |
ret=XA_RESULT_FEATURE_UNSUPPORTED;
|
53
|
502 |
}
|
43
|
503 |
}
|
53
|
504 |
|
43
|
505 |
if(ret==XA_RESULT_SUCCESS)
|
53
|
506 |
{
|
|
507 |
switch ( format )
|
43
|
508 |
{
|
53
|
509 |
case XA_DATAFORMAT_PCM:
|
|
510 |
if ( (encType == XACAP_AUDIO) && (encoderId == XA_AUDIOCODEC_PCM) )
|
|
511 |
{
|
|
512 |
ret=XA_RESULT_SUCCESS;
|
|
513 |
}
|
|
514 |
else
|
43
|
515 |
{
|
53
|
516 |
ret=XA_RESULT_FEATURE_UNSUPPORTED;
|
43
|
517 |
}
|
53
|
518 |
break;
|
|
519 |
|
|
520 |
case XA_DATAFORMAT_MIME:
|
|
521 |
DEBUG_INFO("XA_DATAFORMAT_MIME ");
|
43
|
522 |
{
|
53
|
523 |
XADataFormat_MIME* mime = ((XADataFormat_MIME*)mCtx->xaSink->pFormat);
|
|
524 |
DEBUG_INFO_A1("mime->containerType:%u",(int)mime->containerType);
|
|
525 |
DEBUG_INFO_A1_STR("mime->mimeType:%s", (char *)mime->mimeType);
|
|
526 |
switch ( mime->containerType )
|
43
|
527 |
{
|
53
|
528 |
case XA_CONTAINERTYPE_RAW:
|
|
529 |
if((encType == XACAP_AUDIO) && (encoderId == XA_AUDIOCODEC_PCM))
|
|
530 |
{
|
|
531 |
ret=XA_RESULT_SUCCESS;
|
|
532 |
}
|
|
533 |
else
|
|
534 |
{
|
|
535 |
ret=XA_RESULT_FEATURE_UNSUPPORTED;
|
|
536 |
}
|
19
|
537 |
break;
|
53
|
538 |
|
|
539 |
case XA_CONTAINERTYPE_WAV:
|
|
540 |
if(encType == XACAP_AUDIO)
|
|
541 |
{
|
|
542 |
switch(encoderId)
|
|
543 |
{
|
|
544 |
case XA_AUDIOCODEC_PCM:
|
|
545 |
ret=XA_RESULT_SUCCESS;
|
|
546 |
break;
|
|
547 |
default:
|
|
548 |
ret=XA_RESULT_FEATURE_UNSUPPORTED;
|
|
549 |
break;
|
|
550 |
}
|
|
551 |
}
|
|
552 |
else
|
|
553 |
{
|
|
554 |
ret=XA_RESULT_FEATURE_UNSUPPORTED;
|
|
555 |
}
|
19
|
556 |
break;
|
53
|
557 |
|
|
558 |
case XA_CONTAINERTYPE_UNSPECIFIED:
|
|
559 |
{
|
|
560 |
ret=XA_RESULT_FEATURE_UNSUPPORTED;
|
|
561 |
}
|
19
|
562 |
break;
|
53
|
563 |
case XA_CONTAINERTYPE_AMR:
|
|
564 |
if(encType == XACAP_AUDIO)
|
|
565 |
{
|
|
566 |
switch(encoderId)
|
|
567 |
{
|
|
568 |
case XA_AUDIOCODEC_AMR:
|
|
569 |
ret=XA_RESULT_SUCCESS;
|
|
570 |
break;
|
|
571 |
default:
|
|
572 |
ret=XA_RESULT_FEATURE_UNSUPPORTED;
|
|
573 |
break;
|
|
574 |
}
|
|
575 |
}
|
|
576 |
else
|
|
577 |
{
|
|
578 |
ret=XA_RESULT_FEATURE_UNSUPPORTED;
|
|
579 |
}
|
19
|
580 |
break;
|
53
|
581 |
case XA_CONTAINERTYPE_MP4:
|
|
582 |
if(encType == XACAP_AUDIO )
|
|
583 |
{
|
|
584 |
switch(encoderId)
|
|
585 |
{
|
|
586 |
case XA_AUDIOCODEC_AAC:
|
|
587 |
ret=XA_RESULT_SUCCESS;
|
|
588 |
break;
|
|
589 |
default:
|
|
590 |
ret=XA_RESULT_FEATURE_UNSUPPORTED;
|
|
591 |
break;
|
|
592 |
}
|
|
593 |
}
|
|
594 |
else
|
|
595 |
{
|
|
596 |
ret=XA_RESULT_FEATURE_UNSUPPORTED;
|
|
597 |
}
|
|
598 |
break;
|
|
599 |
default: /*switch (containertype)*/
|
|
600 |
ret = XA_RESULT_FEATURE_UNSUPPORTED;
|
19
|
601 |
break;
|
|
602 |
}
|
|
603 |
break;
|
43
|
604 |
}
|
53
|
605 |
default: /*switch (format)*/
|
|
606 |
ret = XA_RESULT_FEATURE_UNSUPPORTED;
|
19
|
607 |
break;
|
43
|
608 |
}
|
19
|
609 |
}
|
|
610 |
}
|
43
|
611 |
if( ret!=XA_RESULT_SUCCESS )
|
53
|
612 |
{
|
43
|
613 |
DEBUG_ERR("cannot accommodate given codec & datasink pair!!!");
|
53
|
614 |
}
|
43
|
615 |
DEBUG_API("<-XAMediaRecorderAdapt_CheckCodec");
|
|
616 |
return ret;
|
53
|
617 |
}
|
19
|
618 |
/*
|
|
619 |
* XAresult XAMediaRecorderAdapt_ChangeEncoders( XAMediaRecorderAdaptationCtx* mCtx );
|
|
620 |
* re-create encodebin based on new encoder settings
|
|
621 |
*/
|
|
622 |
XAresult XAMediaRecorderAdapt_ChangeEncoders( XAMediaRecorderAdaptationCtx* mCtx )
|
53
|
623 |
{
|
19
|
624 |
XAresult ret = XA_RESULT_SUCCESS;
|
28
|
625 |
GstElement *encoderelement = NULL;
|
19
|
626 |
XAAdaptationGstCtx* bCtx = &(mCtx->baseObj);
|
|
627 |
|
|
628 |
DEBUG_API("->XAMediaRecorderAdapt_ChangeEncoders");
|
|
629 |
/* check state */
|
|
630 |
if(GST_STATE(mCtx->baseObj.bin)<GST_STATE_PLAYING)
|
53
|
631 |
{
|
19
|
632 |
GstElement* newBin = XAMediaRecorderAdapt_CreateEncodeBin(mCtx);
|
|
633 |
if(newBin)
|
53
|
634 |
{ /* replace old bin with new */
|
19
|
635 |
GstStateChangeReturn gret;
|
|
636 |
GstPad *asink=NULL, *linkedasrc=NULL;
|
|
637 |
GstPad *src=NULL, *linkedsink=NULL;
|
|
638 |
GstCaps* encSrcCaps = NULL;
|
28
|
639 |
GstPad *afiltsrc=NULL, *afiltsink=NULL;
|
19
|
640 |
|
|
641 |
/* pipeline must be unrolled for renegotiation */
|
|
642 |
DEBUG_INFO("Unroll pipeline");
|
|
643 |
bCtx->binWantedState = GST_STATE_READY;
|
|
644 |
gret = gst_element_set_state( GST_ELEMENT(bCtx->bin), bCtx->binWantedState);
|
53
|
645 |
if(gret == GST_STATE_CHANGE_FAILURE)
|
|
646 |
{
|
|
647 |
DEBUG_ERR("Failed to Unroll Pipeline!!");
|
|
648 |
return XA_RESULT_INTERNAL_ERROR;
|
|
649 |
}
|
|
650 |
|
19
|
651 |
gret = gst_element_get_state( GST_ELEMENT(bCtx->bin), NULL, NULL, XA_ADAPT_ASYNC_TIMEOUT_SHORT_NSEC);
|
|
652 |
|
43
|
653 |
if(!mCtx ->audiofilter)
|
53
|
654 |
{
|
|
655 |
//creating caps filter
|
|
656 |
mCtx->audiofilter = gst_element_factory_make("capsfilter", "audiofilter");
|
|
657 |
if ( mCtx->audiofilter )
|
|
658 |
{
|
|
659 |
gst_bin_add(GST_BIN(bCtx->bin), mCtx->audiofilter);
|
|
660 |
encSrcCaps = gst_caps_new_full(
|
|
661 |
gst_structure_new("audio/x-raw-int",
|
|
662 |
"channels", G_TYPE_INT, mCtx->audioEncSettings.channelsOut,
|
|
663 |
"rate", G_TYPE_INT, (mCtx->audioEncSettings.sampleRate / 1000),
|
|
664 |
"depth", G_TYPE_INT, mCtx->audioEncSettings.bitsPerSample,
|
|
665 |
"signed",G_TYPE_BOOLEAN, TRUE,
|
|
666 |
"endianness",G_TYPE_INT, mCtx->audioEncSettings.blockAlignment,
|
|
667 |
NULL),
|
|
668 |
gst_structure_new("audio/amr",
|
|
669 |
"signed",G_TYPE_BOOLEAN, TRUE,
|
|
670 |
"endianness",G_TYPE_INT, mCtx->audioEncSettings.blockAlignment,
|
|
671 |
"depth", G_TYPE_INT, mCtx->audioEncSettings.bitsPerSample,
|
|
672 |
"rate", G_TYPE_INT, (mCtx->audioEncSettings.sampleRate / 1000),
|
|
673 |
"channels", G_TYPE_INT, mCtx->audioEncSettings.channelsOut,
|
|
674 |
NULL),
|
|
675 |
gst_structure_new("audio/x-raw-float",
|
|
676 |
"channels", G_TYPE_INT, mCtx->audioEncSettings.channelsOut,
|
|
677 |
"width", G_TYPE_INT, mCtx->audioEncSettings.bitsPerSample,
|
|
678 |
"rate", G_TYPE_INT , mCtx->audioEncSettings.sampleRate / 1000,
|
|
679 |
NULL),
|
|
680 |
NULL);
|
|
681 |
DEBUG_INFO_A1_STR("new audio encoder config from settings: %s",gst_caps_to_string(encSrcCaps));
|
|
682 |
g_object_set( G_OBJECT(mCtx->audiofilter), "caps",encSrcCaps,NULL);
|
|
683 |
|
|
684 |
gst_caps_unref(encSrcCaps);
|
43
|
685 |
|
53
|
686 |
}else
|
|
687 |
{
|
|
688 |
DEBUG_ERR("cannot create caps filter");
|
|
689 |
return XA_RESULT_INTERNAL_ERROR;
|
|
690 |
}
|
|
691 |
|
19
|
692 |
}
|
|
693 |
|
|
694 |
DEBUG_INFO("Unlink and remove old encodebin");
|
|
695 |
asink = gst_element_get_static_pad(mCtx->codecbin,"sink");
|
|
696 |
if(asink)
|
53
|
697 |
{
|
19
|
698 |
linkedasrc = gst_pad_get_peer(asink);
|
|
699 |
if(linkedasrc)
|
53
|
700 |
{
|
19
|
701 |
gst_pad_unlink(linkedasrc,asink);
|
53
|
702 |
}
|
19
|
703 |
}
|
53
|
704 |
|
19
|
705 |
src = gst_element_get_static_pad(mCtx->codecbin,"src");
|
|
706 |
if(src)
|
53
|
707 |
{
|
19
|
708 |
linkedsink = gst_pad_get_peer(src);
|
|
709 |
if(linkedsink)
|
53
|
710 |
{
|
19
|
711 |
gst_pad_unlink(src,linkedsink);
|
53
|
712 |
}
|
19
|
713 |
}
|
|
714 |
|
|
715 |
gst_element_set_state( GST_ELEMENT(mCtx->codecbin), GST_STATE_NULL );
|
|
716 |
gst_element_get_state( GST_ELEMENT(mCtx->codecbin),NULL,NULL,1000 );
|
|
717 |
gst_bin_remove( GST_BIN(bCtx->bin), mCtx->codecbin );
|
|
718 |
/*reset filesink too*/
|
|
719 |
gst_element_set_state(GST_ELEMENT(mCtx->datasink),GST_STATE_NULL);
|
|
720 |
gst_element_sync_state_with_parent(mCtx->datasink);
|
|
721 |
gst_element_get_state(mCtx->datasink,NULL,NULL,XA_ADAPT_ASYNC_TIMEOUT_SHORT_NSEC);
|
|
722 |
|
|
723 |
DEBUG_INFO("Link new encodebin");
|
|
724 |
mCtx->codecbin = newBin;
|
|
725 |
gst_bin_add(GST_BIN(bCtx->bin), mCtx->codecbin);
|
|
726 |
asink = gst_element_get_static_pad(mCtx->codecbin,"sink");
|
28
|
727 |
afiltsink = gst_element_get_static_pad(mCtx->audiofilter,"sink");
|
|
728 |
afiltsrc = gst_element_get_static_pad(mCtx->audiofilter,"src");
|
|
729 |
if(linkedasrc && afiltsink)
|
|
730 |
{
|
53
|
731 |
if(gst_pad_link(linkedasrc , afiltsink ) != GST_PAD_LINK_OK)
|
|
732 |
{
|
|
733 |
DEBUG_ERR("Could not link audiosource to audiofilter!!");
|
|
734 |
return XA_RESULT_INTERNAL_ERROR;
|
|
735 |
}
|
19
|
736 |
}
|
53
|
737 |
if(asink && afiltsrc)
|
|
738 |
{
|
|
739 |
if(gst_pad_link(afiltsrc , asink) != GST_PAD_LINK_OK)
|
43
|
740 |
{
|
53
|
741 |
DEBUG_ERR("Could not link audiosource to audiofilter!!");
|
|
742 |
return XA_RESULT_INTERNAL_ERROR;
|
43
|
743 |
}
|
53
|
744 |
}
|
19
|
745 |
src = gst_element_get_static_pad(mCtx->codecbin,"src");
|
|
746 |
if(src && linkedsink)
|
|
747 |
{
|
53
|
748 |
if(gst_pad_link(src,linkedsink) != GST_PAD_LINK_OK)
|
|
749 |
{
|
|
750 |
DEBUG_ERR("Could not link codecbin src pad to linkedsink!!");
|
|
751 |
return XA_RESULT_INTERNAL_ERROR;
|
|
752 |
}
|
19
|
753 |
}
|
43
|
754 |
|
28
|
755 |
//setting the Bitrate and other properties for elements
|
53
|
756 |
if(mCtx->audioEncSettings.encoderId == XA_AUDIOCODEC_AAC)
|
|
757 |
{
|
|
758 |
encoderelement = gst_bin_get_by_name((GstBin*)mCtx->codecbin, "audioenc") ;
|
|
759 |
if(encoderelement)
|
|
760 |
{
|
|
761 |
g_object_set(G_OBJECT(encoderelement),"bitrate" , mCtx->audioEncSettings.bitRate , NULL );
|
|
762 |
g_object_set(G_OBJECT(encoderelement),"profile", mCtx->audioEncSettings.levelSetting , NULL );
|
|
763 |
g_object_set(G_OBJECT(encoderelement),"output-format", mCtx->audioEncSettings.streamFormat , NULL );
|
|
764 |
gst_object_unref (encoderelement);
|
|
765 |
}
|
|
766 |
else
|
|
767 |
{
|
|
768 |
DEBUG_ERR("Encoder Element not found for AAC");
|
|
769 |
}
|
|
770 |
}
|
|
771 |
else if(mCtx->audioEncSettings.encoderId == XA_AUDIOCODEC_AMR)
|
|
772 |
{
|
|
773 |
g_object_set(G_OBJECT(mCtx->audiosource),"speechbitrate", mCtx->audioEncSettings.bitRate , NULL );
|
|
774 |
}
|
|
775 |
else
|
|
776 |
{
|
|
777 |
DEBUG_INFO("No properties for PCM or Wav");
|
|
778 |
}
|
|
779 |
|
|
780 |
DEBUG_INFO_A1_STR("Pipeline in state %s",gst_element_state_get_name(GST_STATE(bCtx->bin)));
|
43
|
781 |
}
|
53
|
782 |
else
|
43
|
783 |
{
|
19
|
784 |
/* could not support wanted encoders */
|
|
785 |
DEBUG_ERR("Failed to create encodebin with new settings, using old one!");
|
|
786 |
ret = XA_RESULT_FEATURE_UNSUPPORTED;
|
53
|
787 |
}
|
19
|
788 |
}
|
|
789 |
else
|
53
|
790 |
{ /* n/a while playing */
|
19
|
791 |
DEBUG_ERR("Cannot change encoder when recording ongoing!");
|
|
792 |
ret = XA_RESULT_PRECONDITIONS_VIOLATED;
|
53
|
793 |
}
|
19
|
794 |
DEBUG_API("<-XAMediaRecorderAdapt_ChangeEncoders");
|
|
795 |
return ret;
|
53
|
796 |
}
|
19
|
797 |
|
|
798 |
/**
|
|
799 |
* GstElement* XAMediaRecorderAdapt_CreateEncodeBin( XAMediaRecorderAdaptationCtx* ctx )
|
|
800 |
* @return GstElement* - pointer to created bin element
|
|
801 |
* Decription: Create encoder/muxer element based on given format and encoder settings
|
|
802 |
*/
|
|
803 |
GstElement* XAMediaRecorderAdapt_CreateEncodeBin( XAMediaRecorderAdaptationCtx* ctx )
|
53
|
804 |
{
|
19
|
805 |
XAresult ret = XA_RESULT_SUCCESS;
|
53
|
806 |
GstElement *audioenc = NULL, *mux=NULL;
|
19
|
807 |
GstElement *codecbin = gst_bin_new( "mrcodecbin" );
|
53
|
808 |
GstPad *ghostsrc = NULL, *ghostaudiosink = NULL;
|
19
|
809 |
XAuint32 format;
|
|
810 |
XACapabilities temp;
|
|
811 |
|
|
812 |
DEBUG_API("->XAMediaRecorderAdapt_CreateEncodeBin");
|
|
813 |
if(ctx->recModes & XA_RECMODE_STREAM)
|
53
|
814 |
{
|
19
|
815 |
if(ctx->xaSink && ctx->xaSink->pFormat)
|
53
|
816 |
{
|
19
|
817 |
format = *(XAuint32*)(ctx->xaSink->pFormat);
|
|
818 |
switch ( format )
|
53
|
819 |
{
|
19
|
820 |
case XA_DATAFORMAT_PCM:
|
53
|
821 |
DEBUG_INFO("XA_DATAFORMAT_PCM");
|
|
822 |
{
|
|
823 |
XADataFormat_PCM* pcm = ((XADataFormat_PCM*)ctx->xaSink->pFormat);
|
|
824 |
if(!ctx->xaAudioSource)
|
|
825 |
{
|
|
826 |
DEBUG_ERR("Unsupported dataformat for given data sources");
|
|
827 |
return NULL;
|
|
828 |
}
|
|
829 |
/* no need for codec, just pass data on */
|
|
830 |
mux = gst_element_factory_make("identity", "mux");
|
|
831 |
gst_bin_add(GST_BIN(codecbin), mux);
|
|
832 |
ghostsrc = gst_element_get_static_pad(mux,"src");
|
|
833 |
ghostaudiosink = gst_element_get_static_pad(mux,"sink");
|
|
834 |
/*set usable audio settings from the sink structure*/
|
|
835 |
ctx->audioEncSettings.encoderId = XA_AUDIOCODEC_PCM;
|
|
836 |
ctx->audioEncSettings.channelsOut = pcm->numChannels;
|
|
837 |
ctx->audioEncSettings.bitsPerSample = pcm->bitsPerSample;
|
|
838 |
}
|
|
839 |
break;
|
19
|
840 |
|
|
841 |
case XA_DATAFORMAT_MIME:
|
53
|
842 |
DEBUG_INFO("XA_DATAFORMAT_MIME ");
|
|
843 |
{
|
19
|
844 |
XADataFormat_MIME* mime = ((XADataFormat_MIME*)ctx->xaSink->pFormat);
|
|
845 |
DEBUG_INFO_A1("mime->containerType:%u",(int)mime->containerType);
|
53
|
846 |
DEBUG_INFO_A1_STR("mime->mimeType:%s", (char *)mime->mimeType);
|
19
|
847 |
switch ( mime->containerType )
|
43
|
848 |
{
|
53
|
849 |
case XA_CONTAINERTYPE_WAV:
|
43
|
850 |
{
|
53
|
851 |
DEBUG_INFO("XA_CONTAINERTYPE_WAV");
|
|
852 |
audioenc = gst_element_factory_make("wavenc", "audioenc");
|
|
853 |
if(audioenc)
|
43
|
854 |
{
|
53
|
855 |
if (gst_bin_add(GST_BIN(codecbin), audioenc))
|
|
856 |
{
|
|
857 |
DEBUG_INFO("added audioenc to codecbin");
|
|
858 |
}
|
|
859 |
else
|
|
860 |
{
|
|
861 |
DEBUG_ERR("Could not add audioenc to codecbin");
|
19
|
862 |
return NULL;
|
53
|
863 |
}
|
|
864 |
/*use this as linkpoint*/
|
|
865 |
ghostsrc = gst_element_get_static_pad(audioenc,"src");
|
|
866 |
ghostaudiosink = gst_element_get_static_pad(audioenc,"sink");
|
|
867 |
if ( ghostsrc == NULL || ghostaudiosink == NULL)
|
|
868 |
{
|
|
869 |
DEBUG_ERR("Could not get src or sink ghoset element(s)");
|
|
870 |
return NULL;
|
|
871 |
}
|
43
|
872 |
}
|
53
|
873 |
/* no other codecs needed */
|
|
874 |
break;
|
19
|
875 |
}
|
|
876 |
|
53
|
877 |
case XA_CONTAINERTYPE_UNSPECIFIED:
|
43
|
878 |
{
|
53
|
879 |
DEBUG_INFO("No support for requested encoder...try to select encoder from mime string");
|
|
880 |
DEBUG_INFO("No support for requested mime/container type.");
|
|
881 |
ret = XA_RESULT_CONTENT_UNSUPPORTED;
|
|
882 |
break;
|
19
|
883 |
}
|
53
|
884 |
case XA_CONTAINERTYPE_MP4:
|
|
885 |
{
|
|
886 |
DEBUG_INFO("XA_CONTAINERTYPE_MP4");
|
|
887 |
mux = gst_element_factory_make("mp4mux", "mp4mux");
|
19
|
888 |
if(mux)
|
53
|
889 |
{
|
|
890 |
if (gst_bin_add(GST_BIN(codecbin), mux))
|
|
891 |
{
|
|
892 |
DEBUG_INFO("Added mux to codecbin");
|
|
893 |
}
|
|
894 |
else
|
|
895 |
{
|
|
896 |
DEBUG_ERR("Could not add mux to codecbin");
|
|
897 |
return NULL;
|
|
898 |
}
|
19
|
899 |
/*use this as linkpoint*/
|
|
900 |
ghostsrc = gst_element_get_static_pad(mux,"src");
|
43
|
901 |
}
|
53
|
902 |
/* Add and link audio/video codecs */
|
|
903 |
|
|
904 |
/*set audio defaults*/
|
|
905 |
if(ctx->audioEncSettings.encoderId == XA_ADAPTID_UNINITED)
|
|
906 |
ctx->audioEncSettings.encoderId = XA_AUDIOCODEC_AAC;
|
|
907 |
if(ctx->xaAudioSource)
|
43
|
908 |
{
|
53
|
909 |
if(XACapabilitiesMgr_GetCapsById(ctx->baseObj.baseObj.capslist, (XACapsType)(XACAP_ENCODER|XACAP_AUDIO), ctx->audioEncSettings.encoderId, &temp) == XA_RESULT_SUCCESS)
|
19
|
910 |
{
|
53
|
911 |
if(temp.adaptId)
|
43
|
912 |
{
|
53
|
913 |
audioenc = gst_element_factory_make((char*)temp.adaptId, "audioenc");
|
43
|
914 |
}
|
19
|
915 |
}
|
53
|
916 |
if(audioenc)
|
19
|
917 |
{
|
53
|
918 |
gst_bin_add(GST_BIN(codecbin), audioenc);
|
|
919 |
if(!gst_element_link(audioenc, mux))
|
|
920 |
{
|
|
921 |
DEBUG_ERR("Could not link audioenc to mux!!");
|
|
922 |
DEBUG_API("<-XAMediaRecorderAdapt_CreateEncodeBin");
|
|
923 |
return NULL;
|
|
924 |
}
|
|
925 |
ghostaudiosink = gst_element_get_static_pad(audioenc,"sink");
|
43
|
926 |
}
|
53
|
927 |
else
|
43
|
928 |
{
|
53
|
929 |
/*no audio codec but audio source = PCM case, explicity request audio pad*/
|
|
930 |
ghostaudiosink = gst_element_get_request_pad(mux,"audio_%d");
|
19
|
931 |
}
|
|
932 |
}
|
53
|
933 |
break;
|
|
934 |
}
|
|
935 |
case XA_CONTAINERTYPE_AMR:
|
43
|
936 |
{
|
19
|
937 |
DEBUG_INFO("XA_CONTAINERTYPE_AMR");
|
|
938 |
if(ctx->audioEncSettings.encoderId == XA_ADAPTID_UNINITED)
|
|
939 |
ctx->audioEncSettings.encoderId = XA_AUDIOCODEC_AMR;
|
|
940 |
mux = gst_element_factory_make("amrmux", "mux");
|
|
941 |
if(mux)
|
53
|
942 |
{
|
19
|
943 |
if (gst_bin_add(GST_BIN(codecbin), mux))
|
53
|
944 |
{
|
19
|
945 |
DEBUG_INFO("Added mux to codecbin");
|
53
|
946 |
/*Setting the buffer size on src since amr generates
|
19
|
947 |
* small amounts of data */
|
|
948 |
g_object_set (G_OBJECT (ctx->audiosource),
|
|
949 |
"blocksize", 1280,
|
53
|
950 |
NULL);
|
|
951 |
}
|
19
|
952 |
else
|
53
|
953 |
{
|
19
|
954 |
DEBUG_ERR("Could not add mux to codecbin");
|
|
955 |
return NULL;
|
53
|
956 |
}
|
19
|
957 |
/*use this as linkpoint*/
|
|
958 |
ghostsrc = gst_element_get_static_pad(mux,"src");
|
53
|
959 |
}
|
19
|
960 |
/*set audio defaults*/
|
|
961 |
if(ctx->xaAudioSource)
|
53
|
962 |
{
|
19
|
963 |
/*no audio codec but audio source = PCM case, explicity request audio pad*/
|
|
964 |
ghostaudiosink = gst_element_get_static_pad(mux,"sink");
|
53
|
965 |
}
|
|
966 |
break;
|
|
967 |
}
|
|
968 |
|
|
969 |
/* case XA_CONTAINERTYPE_3GPP:
|
|
970 |
case XA_CONTAINERTYPE_MOBILE_DLS:
|
19
|
971 |
case XA_CONTAINERTYPE_BMP:
|
|
972 |
case XA_CONTAINERTYPE_ASF:
|
|
973 |
case XA_CONTAINERTYPE_M4A:
|
|
974 |
case XA_CONTAINERTYPE_MP3:
|
|
975 |
case XA_CONTAINERTYPE_JPG2000:
|
|
976 |
case XA_CONTAINERTYPE_MPEG_ES:
|
|
977 |
case XA_CONTAINERTYPE_MPEG_PS:
|
|
978 |
case XA_CONTAINERTYPE_MPEG_TS:
|
|
979 |
case XA_CONTAINERTYPE_QT:
|
|
980 |
case XA_CONTAINERTYPE_XMF_0:
|
|
981 |
case XA_CONTAINERTYPE_XMF_1:
|
|
982 |
case XA_CONTAINERTYPE_XMF_2:
|
|
983 |
case XA_CONTAINERTYPE_XMF_3:
|
|
984 |
case XA_CONTAINERTYPE_XMF_GENERIC:
|
|
985 |
case XA_CONTAINERTYPE_AAC:
|
|
986 |
case XA_CONTAINERTYPE_3GA:
|
|
987 |
case XA_CONTAINERTYPE_RM:
|
53
|
988 |
case XA_CONTAINERTYPE_DMF:*/
|
|
989 |
|
19
|
990 |
default:
|
53
|
991 |
DEBUG_INFO("No support for requested container type.");
|
|
992 |
ret = XA_RESULT_CONTENT_UNSUPPORTED;
|
|
993 |
break;
|
|
994 |
}
|
|
995 |
break;
|
43
|
996 |
}
|
53
|
997 |
default:
|
|
998 |
DEBUG_ERR("Incorrect data format type.");
|
|
999 |
ret = XA_RESULT_PARAMETER_INVALID;
|
|
1000 |
break;
|
43
|
1001 |
}
|
53
|
1002 |
}
|
|
1003 |
else
|
|
1004 |
{
|
|
1005 |
DEBUG_ERR("Invalid data sink for stream recording!!");
|
|
1006 |
ret = XA_RESULT_PARAMETER_INVALID;
|
19
|
1007 |
}
|
43
|
1008 |
}
|
19
|
1009 |
else
|
53
|
1010 |
{/* stream recording not requested, datasink ignored, use uncoded recordstream*/
|
19
|
1011 |
mux = gst_element_factory_make("identity", "mux");
|
|
1012 |
gst_bin_add(GST_BIN(codecbin), mux);
|
|
1013 |
ghostsrc = gst_element_get_static_pad(mux,"src");
|
53
|
1014 |
}
|
19
|
1015 |
|
|
1016 |
/*set default codecs for unrecognized*/
|
|
1017 |
if(ctx->audioEncSettings.encoderId == XA_ADAPTID_UNINITED)
|
|
1018 |
ctx->audioEncSettings.encoderId = XA_AUDIOCODEC_PCM;
|
|
1019 |
|
|
1020 |
if ( ret != XA_RESULT_SUCCESS )
|
53
|
1021 |
{
|
19
|
1022 |
gst_object_unref(codecbin);
|
|
1023 |
codecbin=NULL;
|
53
|
1024 |
}
|
19
|
1025 |
else
|
53
|
1026 |
{
|
19
|
1027 |
/*add ghost pad(s) to link to*/
|
|
1028 |
if(ghostsrc)
|
53
|
1029 |
{
|
19
|
1030 |
gst_element_add_pad(codecbin, gst_ghost_pad_new("src",ghostsrc));
|
|
1031 |
gst_object_unref(GST_OBJECT(ghostsrc));
|
53
|
1032 |
}
|
19
|
1033 |
if(ghostaudiosink)
|
53
|
1034 |
{
|
19
|
1035 |
gst_element_add_pad(codecbin, gst_ghost_pad_new("sink",ghostaudiosink));
|
|
1036 |
gst_object_unref(GST_OBJECT(ghostaudiosink));
|
53
|
1037 |
}
|
|
1038 |
|
|
1039 |
DEBUG_INFO_A1("Created encoder bin at %x", (int)codecbin);
|
43
|
1040 |
}
|
19
|
1041 |
|
|
1042 |
DEBUG_API("<-XAMediaRecorderAdapt_CreateEncodeBin");
|
|
1043 |
return codecbin;
|
|
1044 |
|
43
|
1045 |
}
|
19
|
1046 |
|
|
1047 |
|