39 #include <gst/audio/audio.h>
40 #include <gst/app/gstappsrc.h>
44 #include "btrMgr_logger.h"
51 #define BTRMGR_SLEEP_TIMEOUT_MS 1 // Suspend execution of thread. Keep as minimal as possible
52 #define BTRMGR_WAIT_TIMEOUT_MS 2 // Use for blocking operations
53 #define BTRMGR_MAX_INTERNAL_QUEUE_ELEMENTS 8 // Number of blocks in the internal queue
54 #define BTRMGR_INPUT_BUF_INTERVAL_THRES_CNT 4 // Number of buffer threshold based on input buffer interval
56 #define GST_ELEMENT_GET_STATE_RETRY_CNT_MAX 5
58 #define ENABLE_MAIN_LOOP_CONTEXT 0
60 #define BTRMGR_SBC_ALLOCATION_SNR (1 << 1) // Has to match with a2dp-codecs.h
61 #define BTRMGR_SBC_ALLOCATION_LOUDNESS 1 // Need a better way to pass/map this from the upper layers
75 #if !(ENABLE_MAIN_LOOP_CONTEXT)
77 GMutex gMtxMainLoopRunLock;
78 GCond gCndMainLoopRun;
86 GstClockTime gstClkTStamp;
91 unsigned int ui32InBitsPSample;
92 unsigned int ui32InBufIntervalms;
93 unsigned char ui8IpBufThrsCnt;
95 fPtr_BTRMgr_SO_GstStatusCb fpcBSoGstStatus;
98 GMutex pipelineDataMutex;
99 gboolean bPipelineError;
100 gboolean bIsInputPaused;
105 static GstState btrMgr_SO_validateStateWithTimeout (GstElement* element, GstState stateToValidate, guint msTimeOut);
106 static eBTRMgrSOGstRet btrMgr_SO_GstSendBuffer (
stBTRMgrSOGst* pstBtrMgrSoGst,
char* pcInBuf,
int aiInBufSize);
109 static gpointer btrMgr_SO_g_main_loop_Task (gpointer apstBtrMgrSoGst);
112 #if !(ENABLE_MAIN_LOOP_CONTEXT)
113 static gboolean btrMgr_SO_g_main_loop_RunningCb (gpointer apstBtrMgrSoGst);
114 static gboolean btrMgr_SO_g_timeout_EmptyBufPushCb (gpointer apstBtrMgrSoGst);
116 static void btrMgr_SO_NeedDataCb (GstElement* appsrc, guint size, gpointer apstBtrMgrSoGst);
117 static void btrMgr_SO_EnoughDataCb (GstElement* appsrc, gpointer apstBtrMgrSoGst);
118 static gboolean btrMgr_SO_gstBusCallCb (GstBus* bus, GstMessage* msg, gpointer apstBtrMgrSoGst);
123 btrMgr_SO_validateStateWithTimeout (
125 GstState stateToValidate,
128 GstState gst_current = GST_STATE_VOID_PENDING;
129 GstState gst_pending = GST_STATE_VOID_PENDING;
130 float timeout = BTRMGR_WAIT_TIMEOUT_MS;
131 gint gstGetStateCnt = GST_ELEMENT_GET_STATE_RETRY_CNT_MAX;
133 GstStateChangeReturn gstStChangeRet = GST_STATE_CHANGE_FAILURE;
136 gstStChangeRet = gst_element_get_state(GST_ELEMENT(element), &gst_current, &gst_pending, timeout * GST_MSECOND);
137 if (((GST_STATE_CHANGE_SUCCESS == gstStChangeRet) || (GST_STATE_CHANGE_NO_PREROLL == gstStChangeRet)) && (gst_current == stateToValidate)) {
138 BTRMGRLOG_INFO(
"gst_element_get_state - SUCCESS : St = %d, Pend = %d StValidate = %d StChRet = %d\n", gst_current, gst_pending, stateToValidate, gstStChangeRet);
141 usleep(msTimeOut * 1000);
142 }
while (((gstStChangeRet == GST_STATE_CHANGE_ASYNC) || (gst_current != stateToValidate)) && (gstGetStateCnt-- != 0)) ;
144 BTRMGRLOG_ERROR(
"gst_element_get_state - FAILURE : St = %d, Pend = %d StValidate = %d StChRet = %d\n", gst_current, gst_pending, stateToValidate, gstStChangeRet);
146 if (gst_pending == stateToValidate)
155 btrMgr_SO_g_main_loop_Task (
156 gpointer apstBtrMgrSoGst
160 if (!pstBtrMgrSoGst || !pstBtrMgrSoGst->pLoop) {
161 BTRMGRLOG_ERROR (
"GMainLoop Error - In arguments Exiting\n");
165 #if !(ENABLE_MAIN_LOOP_CONTEXT)
166 GstElement* appsrc = NULL;
167 GstElement* volume = NULL;
168 GstElement* audconvert = NULL;
169 GstElement* audresample = NULL;
170 GstElement* audenc = NULL;
171 GstElement* aecapsfilter= NULL;
172 GstElement* rtpaudpay = NULL;
173 GstElement* fdsink = NULL;
174 GstElement* pipeline = NULL;
176 GSource* idleSource = NULL;
177 GMainLoop* loop = NULL;
178 GMainContext* mainContext = NULL;
180 guint idleSrcLoopRunningId;
183 if (!pstBtrMgrSoGst->pContext) {
184 BTRMGRLOG_ERROR (
"GMainLoop Error - No context\n");
188 mainContext = pstBtrMgrSoGst->pContext;
189 g_main_context_push_thread_default (mainContext);
191 idleSource = g_idle_source_new ();
192 g_source_set_callback (idleSource, (GSourceFunc) btrMgr_SO_g_main_loop_RunningCb, pstBtrMgrSoGst, NULL);
193 idleSrcLoopRunningId = g_source_attach (idleSource, mainContext);
194 g_source_unref (idleSource);
198 appsrc = gst_element_factory_make (
"appsrc",
"btmgr-so-appsrc");
199 volume = gst_element_factory_make (
"volume",
"btmgr-so-volume");
200 #if defined(DISABLE_AUDIO_ENCODING)
201 audconvert = gst_element_factory_make (
"queue",
"btmgr-so-aconv");
202 audresample = gst_element_factory_make (
"queue",
"btmgr-so-aresample");
203 audenc = gst_element_factory_make (
"queue",
"btmgr-so-sbcenc");
204 aecapsfilter= gst_element_factory_make (
"queue",
"btmgr-so-aecapsfilter");
205 rtpaudpay = gst_element_factory_make (
"queue",
"btmgr-so-rtpsbcpay");
208 audconvert = gst_element_factory_make (
"audioconvert",
"btmgr-so-aconv");
209 audresample = gst_element_factory_make (
"audioresample",
"btmgr-so-aresample");
210 audenc = gst_element_factory_make (
"sbcenc",
"btmgr-so-sbcenc");
211 aecapsfilter= gst_element_factory_make (
"capsfilter",
"btmgr-so-aecapsfilter");
212 rtpaudpay = gst_element_factory_make (
"rtpsbcpay",
"btmgr-so-rtpsbcpay");
214 fdsink = gst_element_factory_make (
"fdsink",
"btmgr-so-fdsink");
218 pipeline = gst_pipeline_new (
"btmgr-so-pipeline");
220 loop = pstBtrMgrSoGst->pLoop;
222 if (!appsrc || !volume || !audenc || !aecapsfilter || !rtpaudpay || !fdsink || !loop || !pipeline) {
223 BTRMGRLOG_ERROR (
"Gstreamer plugin missing for streamOut\n");
227 pstBtrMgrSoGst->pPipeline = (
void*)pipeline;
228 pstBtrMgrSoGst->pSrc = (
void*)appsrc;
229 pstBtrMgrSoGst->pVolume = (
void*)volume;
230 pstBtrMgrSoGst->pSink = (
void*)fdsink;
231 pstBtrMgrSoGst->pAudioConv = (
void*)audconvert;
232 pstBtrMgrSoGst->pAudioResample = (
void*)audresample;
233 pstBtrMgrSoGst->pAudioEnc = (
void*)audenc;
234 pstBtrMgrSoGst->pAECapsFilter = (
void*)aecapsfilter;
235 pstBtrMgrSoGst->pRtpAudioPay = (
void*)rtpaudpay;
236 pstBtrMgrSoGst->gstClkTStamp = 0;
237 pstBtrMgrSoGst->inBufOffset = 0;
238 pstBtrMgrSoGst->bPipelineError = FALSE;
239 pstBtrMgrSoGst->bIsInputPaused = FALSE;
240 g_mutex_init(&pstBtrMgrSoGst->pipelineDataMutex);
243 bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline));
244 busWatchId = gst_bus_add_watch(bus, btrMgr_SO_gstBusCallCb, pstBtrMgrSoGst);
245 pstBtrMgrSoGst->busWId = busWatchId;
249 gst_bin_add_many (GST_BIN (pipeline), appsrc, volume, audenc, aecapsfilter, rtpaudpay, fdsink, NULL);
250 gst_element_link_many (appsrc, volume, audenc, aecapsfilter, rtpaudpay, fdsink, NULL);
252 g_signal_connect (appsrc,
"need-data", G_CALLBACK(btrMgr_SO_NeedDataCb), pstBtrMgrSoGst);
253 g_signal_connect (appsrc,
"enough-data", G_CALLBACK(btrMgr_SO_EnoughDataCb), pstBtrMgrSoGst);
258 BTRMGRLOG_INFO (
"GMainLoop Running\n");
259 g_main_loop_run (pstBtrMgrSoGst->pLoop);
262 #if !(ENABLE_MAIN_LOOP_CONTEXT)
263 if (pstBtrMgrSoGst->emptyBufPushId) {
264 GSource *emptyBufPushSource = g_main_context_find_source_by_id(mainContext, pstBtrMgrSoGst->emptyBufPushId);
265 if (emptyBufPushSource)
266 g_source_destroy(emptyBufPushSource);
268 pstBtrMgrSoGst->emptyBufPushId = 0;
272 GSource *busSource = g_main_context_find_source_by_id(mainContext, busWatchId);
274 g_source_destroy(busSource);
277 pstBtrMgrSoGst->busWId = busWatchId;
280 if (idleSrcLoopRunningId) {
281 GSource *idleSrcLoopRunning = g_main_context_find_source_by_id(mainContext, idleSrcLoopRunningId);
282 if (idleSrcLoopRunning)
283 g_source_destroy(idleSrcLoopRunning);
285 idleSrcLoopRunningId = 0;
289 g_main_context_pop_thread_default (mainContext);
293 BTRMGRLOG_INFO (
"GMainLoop Exiting\n");
294 return pstBtrMgrSoGst;
301 tBTRMgrSoGstHdl* phBTRMgrSoGstHdl,
302 fPtr_BTRMgr_SO_GstStatusCb afpcBSoGstStatus,
305 #if (ENABLE_MAIN_LOOP_CONTEXT)
306 GstElement* appsrc = NULL;
307 GstElement* volume = NULL;
308 GstElement* audconvert = NULL;
309 GstElement* audresample = NULL;
310 GstElement* audenc = NULL;
311 GstElement* aecapsfilter = NULL;
312 GstElement* rtpaudpay = NULL;
313 GstElement* fdsink = NULL;
314 GstElement* pipeline = NULL;
318 GMainContext* mainContext = NULL;
322 GThread* mainLoopThread = NULL;
323 GMainLoop* loop = NULL;
327 BTRMGRLOG_ERROR (
"Unable to allocate memory\n");
328 return eBTRMgrSOGstFailure;
333 gst_init (NULL, NULL);
335 #if (ENABLE_MAIN_LOOP_CONTEXT)
337 appsrc = gst_element_factory_make (
"appsrc",
"btmgr-so-appsrc");
338 volume = gst_element_factory_make (
"volume",
"btmgr-so-volume");
339 #if defined(DISABLE_AUDIO_ENCODING)
340 audconvert = gst_element_factory_make (
"queue",
"btmgr-so-aconv");
341 audresample = gst_element_factory_make (
"queue",
"btmgr-so-aresample");
342 audenc = gst_element_factory_make (
"queue",
"btmgr-so-sbcenc");
343 aecapsfilter= gst_element_factory_make (
"queue",
"btmgr-so-aecapsfilter");
344 rtpaudpay = gst_element_factory_make (
"queue",
"btmgr-so-rtpsbcpay");
347 audconvert = gst_element_factory_make (
"audioconvert",
"btmgr-so-aconv");
348 audresample = gst_element_factory_make (
"audioresample",
"btmgr-so-aresample");
349 audenc = gst_element_factory_make (
"sbcenc",
"btmgr-so-sbcenc");
350 aecapsfilter= gst_element_factory_make (
"capsfilter",
"btmgr-so-aecapsfilter");
351 rtpaudpay = gst_element_factory_make (
"rtpsbcpay",
"btmgr-so-rtpsbcpay");
353 fdsink = gst_element_factory_make (
"fdsink",
"btmgr-so-fdsink");
356 loop = g_main_loop_new (NULL, FALSE);
358 g_mutex_init (&pstBtrMgrSoGst->gMtxMainLoopRunLock);
359 g_cond_init (&pstBtrMgrSoGst->gCndMainLoopRun);
361 mainContext = g_main_context_new();
365 loop = g_main_loop_new (mainContext, FALSE);
370 #if (ENABLE_MAIN_LOOP_CONTEXT)
372 pipeline = gst_pipeline_new (
"btmgr-so-pipeline");
374 if (!appsrc || !volume || !audenc || !aecapsfilter || !rtpaudpay || !fdsink || !loop || !pipeline) {
375 BTRMGRLOG_ERROR (
"Gstreamer plugin missing for streamOut\n");
377 free((
void*)pstBtrMgrSoGst);
378 return eBTRMgrSOGstFailure;
381 pstBtrMgrSoGst->pPipeline = (
void*)pipeline;
382 pstBtrMgrSoGst->pSrc = (
void*)appsrc;
383 pstBtrMgrSoGst->pVolume = (
void*)volume;
384 pstBtrMgrSoGst->pSink = (
void*)fdsink;
385 pstBtrMgrSoGst->pAudioConv = (
void*)audconvert;
386 pstBtrMgrSoGst->pAudioResample = (
void*)audresample;
387 pstBtrMgrSoGst->pAudioEnc = (
void*)audenc;
388 pstBtrMgrSoGst->pAECapsFilter = (
void*)aecapsfilter;
389 pstBtrMgrSoGst->pRtpAudioPay = (
void*)rtpaudpay;
390 pstBtrMgrSoGst->pLoop = (
void*)loop;
391 pstBtrMgrSoGst->gstClkTStamp = 0;
392 pstBtrMgrSoGst->inBufOffset = 0;
393 pstBtrMgrSoGst->fpcBSoGstStatus = NULL;
394 pstBtrMgrSoGst->pvcBUserData = NULL;
395 pstBtrMgrSoGst->bPipelineError = FALSE;
396 pstBtrMgrSoGst->bIsInputPaused = FALSE;
397 g_mutex_init(&pstBtrMgrSoGst->pipelineDataMutex);
400 if (afpcBSoGstStatus) {
401 pstBtrMgrSoGst->fpcBSoGstStatus = afpcBSoGstStatus;
402 pstBtrMgrSoGst->pvcBUserData = apvUserData;
406 bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline));
407 busWatchId = gst_bus_add_watch(bus, btrMgr_SO_gstBusCallCb, pstBtrMgrSoGst);
408 pstBtrMgrSoGst->busWId = busWatchId;
412 gst_bin_add_many (GST_BIN (pipeline), appsrc, volume, audenc, aecapsfilter, rtpaudpay, fdsink, NULL);
413 gst_element_link_many (appsrc, volume, audenc, aecapsfilter, rtpaudpay, fdsink, NULL);
416 mainLoopThread = g_thread_new(
"btrMgr_SO_g_main_loop_Task", btrMgr_SO_g_main_loop_Task, pstBtrMgrSoGst);
417 pstBtrMgrSoGst->pLoopThread = (
void*)mainLoopThread;
419 g_signal_connect (appsrc,
"need-data", G_CALLBACK(btrMgr_SO_NeedDataCb), pstBtrMgrSoGst);
420 g_signal_connect (appsrc,
"enough-data", G_CALLBACK(btrMgr_SO_EnoughDataCb), pstBtrMgrSoGst);
423 pstBtrMgrSoGst->pContext = (
void*)mainContext;
424 pstBtrMgrSoGst->pLoop = (
void*)loop;
425 pstBtrMgrSoGst->fpcBSoGstStatus = NULL;
426 pstBtrMgrSoGst->pvcBUserData = NULL;
428 if (afpcBSoGstStatus) {
429 pstBtrMgrSoGst->fpcBSoGstStatus = afpcBSoGstStatus;
430 pstBtrMgrSoGst->pvcBUserData = apvUserData;
434 g_mutex_lock (&pstBtrMgrSoGst->gMtxMainLoopRunLock);
436 mainLoopThread = g_thread_new(
"btrMgr_SO_g_main_loop_Task", btrMgr_SO_g_main_loop_Task, pstBtrMgrSoGst);
437 pstBtrMgrSoGst->pLoopThread = (
void*)mainLoopThread;
440 while (!loop || !g_main_loop_is_running (loop)) {
441 g_cond_wait (&pstBtrMgrSoGst->gCndMainLoopRun, &pstBtrMgrSoGst->gMtxMainLoopRunLock);
444 g_mutex_unlock (&pstBtrMgrSoGst->gMtxMainLoopRunLock);
448 gst_element_set_state(GST_ELEMENT(pstBtrMgrSoGst->pPipeline), GST_STATE_NULL);
449 if (btrMgr_SO_validateStateWithTimeout(pstBtrMgrSoGst->pPipeline, GST_STATE_NULL, BTRMGR_SLEEP_TIMEOUT_MS)!= GST_STATE_NULL) {
450 BTRMGRLOG_ERROR (
"Unable to perform Operation\n");
452 return eBTRMgrSOGstFailure;
456 *phBTRMgrSoGstHdl = (tBTRMgrSoGstHdl)pstBtrMgrSoGst;
458 return eBTRMgrSOGstSuccess;
464 tBTRMgrSoGstHdl hBTRMgrSoGstHdl
468 if (!pstBtrMgrSoGst) {
469 BTRMGRLOG_ERROR (
"Invalid input argument\n");
470 return eBTRMgrSOGstFailInArg;
473 GstElement* pipeline = (GstElement*)pstBtrMgrSoGst->pPipeline;
474 GMainLoop* loop = (GMainLoop*)pstBtrMgrSoGst->pLoop;
475 GThread* mainLoopThread = (GThread*)pstBtrMgrSoGst->pLoopThread;
476 #if (ENABLE_MAIN_LOOP_CONTEXT)
477 guint busWatchId = pstBtrMgrSoGst->busWId;
479 GMainContext* mainContext = (GMainContext*)pstBtrMgrSoGst->pContext;
484 gst_object_unref(GST_OBJECT(pipeline));
488 #if (ENABLE_MAIN_LOOP_CONTEXT)
490 GSource *busSource = g_main_context_find_source_by_id(g_main_context_get_thread_default(), busWatchId);
492 g_source_destroy(busSource);
499 g_main_loop_quit(loop);
502 if (mainLoopThread) {
503 g_thread_join(mainLoopThread);
504 mainLoopThread = NULL;
508 g_main_loop_unref(loop);
512 #if !(ENABLE_MAIN_LOOP_CONTEXT)
514 g_main_context_unref(mainContext);
519 if (pstBtrMgrSoGst->fpcBSoGstStatus)
520 pstBtrMgrSoGst->fpcBSoGstStatus = NULL;
523 pstBtrMgrSoGst->bIsInputPaused = FALSE;
525 g_mutex_lock(&pstBtrMgrSoGst->pipelineDataMutex);
526 pstBtrMgrSoGst->bPipelineError = FALSE;
527 g_mutex_unlock(&pstBtrMgrSoGst->pipelineDataMutex);
529 g_mutex_clear(&pstBtrMgrSoGst->pipelineDataMutex);
532 #if !(ENABLE_MAIN_LOOP_CONTEXT)
533 g_cond_clear(&pstBtrMgrSoGst->gCndMainLoopRun);
534 g_mutex_clear(&pstBtrMgrSoGst->gMtxMainLoopRunLock);
539 free((
void*)pstBtrMgrSoGst);
540 pstBtrMgrSoGst = NULL;
542 return eBTRMgrSOGstSuccess;
548 tBTRMgrSoGstHdl hBTRMgrSoGstHdl,
549 int ai32InBufMaxSize,
550 const char* apcInFmt,
555 const char* apcOutChannelMode,
556 unsigned char aui8SbcAllocMethod,
557 unsigned char aui8SbcSubbands,
558 unsigned char aui8SbcBlockLength,
559 unsigned char aui8SbcMinBitpool,
560 unsigned char aui8SbcMaxBitpool,
566 if (!pstBtrMgrSoGst || !apcInFmt) {
567 BTRMGRLOG_ERROR (
"Invalid input argument\n");
568 return eBTRMgrSOGstFailInArg;
571 GstElement* pipeline = (GstElement*)pstBtrMgrSoGst->pPipeline;
572 GstElement* appsrc = (GstElement*)pstBtrMgrSoGst->pSrc;
573 GstElement* volume = (GstElement*)pstBtrMgrSoGst->pVolume;
574 GstElement* fdsink = (GstElement*)pstBtrMgrSoGst->pSink;
575 GstElement* audconvert = (GstElement*)pstBtrMgrSoGst->pAudioConv;
576 GstElement* audresample = (GstElement*)pstBtrMgrSoGst->pAudioResample;
577 GstElement* audenc = (GstElement*)pstBtrMgrSoGst->pAudioEnc;
578 GstElement* aecapsfilter= (GstElement*)pstBtrMgrSoGst->pAECapsFilter;
579 GstElement* rtpaudpay = (GstElement*)pstBtrMgrSoGst->pRtpAudioPay;
581 GstCaps* appsrcSrcCaps = NULL;
582 GstCaps* audEncSrcCaps = NULL;
584 unsigned int lui32InBitsPSample = 0;
585 const char* lpui8StrSbcAllocMethod = NULL;
588 if (btrMgr_SO_validateStateWithTimeout(pipeline, GST_STATE_NULL, BTRMGR_SLEEP_TIMEOUT_MS) != GST_STATE_NULL) {
589 BTRMGRLOG_ERROR (
"Incorrect State to perform Operation\n");
590 return eBTRMgrSOGstFailure;
593 if (((ai32InRate != ai32OutRate) || (ai32InChannels != ai32OutChannels)) && audconvert && audresample) {
597 gst_bin_add_many(GST_BIN(pipeline), audconvert, audresample, NULL);
598 gst_element_unlink(volume, audenc);
599 gst_element_link_many (volume, audconvert, audresample, audenc, NULL);
602 pstBtrMgrSoGst->gstClkTStamp = 0;
603 pstBtrMgrSoGst->inBufOffset = 0;
605 if (!strcmp(apcInFmt, BTRMGR_AUDIO_SFMT_SIGNED_8BIT))
606 lui32InBitsPSample = 8;
607 else if (!strcmp(apcInFmt, BTRMGR_AUDIO_SFMT_SIGNED_LE_16BIT))
608 lui32InBitsPSample = 16;
609 else if (!strcmp(apcInFmt, BTRMGR_AUDIO_SFMT_SIGNED_LE_24BIT))
610 lui32InBitsPSample = 24;
611 else if (!strcmp(apcInFmt, BTRMGR_AUDIO_SFMT_SIGNED_LE_32BIT))
612 lui32InBitsPSample = 32;
614 lui32InBitsPSample = 16;
618 appsrcSrcCaps = gst_caps_new_simple (
"audio/x-raw",
619 "format", G_TYPE_STRING, apcInFmt,
620 "layout", G_TYPE_STRING,
"interleaved",
621 "rate", G_TYPE_INT, ai32InRate,
622 "channels", G_TYPE_INT, ai32InChannels,
625 if (aui8SbcAllocMethod == BTRMGR_SBC_ALLOCATION_SNR)
626 lpui8StrSbcAllocMethod =
"snr";
628 lpui8StrSbcAllocMethod =
"loudness";
630 (void)aui8SbcMinBitpool;
633 audEncSrcCaps = gst_caps_new_simple (
"audio/x-sbc",
634 "rate", G_TYPE_INT, ai32OutRate,
635 "channels", G_TYPE_INT, ai32OutChannels,
636 "channel-mode", G_TYPE_STRING, apcOutChannelMode,
637 "blocks", G_TYPE_INT, aui8SbcBlockLength,
638 "subbands", G_TYPE_INT, aui8SbcSubbands,
639 "allocation-method", G_TYPE_STRING, lpui8StrSbcAllocMethod,
640 "bitpool", G_TYPE_INT, aui8SbcMaxBitpool,
643 g_object_set (appsrc,
"caps", appsrcSrcCaps, NULL);
644 g_object_set (appsrc,
"blocksize", ai32InBufMaxSize, NULL);
646 g_object_set (appsrc,
"max-bytes", BTRMGR_MAX_INTERNAL_QUEUE_ELEMENTS * ai32InBufMaxSize, NULL);
647 g_object_set (appsrc,
"is-live", 1, NULL);
648 g_object_set (appsrc,
"block", 1, NULL);
651 g_object_set (appsrc,
"do-timestamp", 1, NULL);
653 g_object_set (appsrc,
"min-percent", 16, NULL);
654 g_object_set (appsrc,
"min-latency", GST_USECOND * (ai32InBufMaxSize * 1000)/((ai32InRate/1000.0) * (lui32InBitsPSample/8) * ai32InChannels), NULL);
655 g_object_set (appsrc,
"stream-type", GST_APP_STREAM_TYPE_STREAM, NULL);
656 g_object_set (appsrc,
"format", GST_FORMAT_TIME, NULL);
658 g_object_set (audenc,
"perfect-timestamp", 1, NULL);
660 g_object_set (aecapsfilter,
"caps", audEncSrcCaps, NULL);
662 g_object_set (rtpaudpay,
"mtu", ai32BTDevMTU, NULL);
663 g_object_set (rtpaudpay,
"min-frames", -1, NULL);
664 g_object_set (rtpaudpay,
"perfect-rtptime", 1, NULL);
666 g_object_set (fdsink,
"fd", ai32BTDevFd, NULL);
667 g_object_set (fdsink,
"sync", FALSE, NULL);
670 gst_caps_unref(audEncSrcCaps);
671 gst_caps_unref(appsrcSrcCaps);
674 g_mutex_lock(&pstBtrMgrSoGst->pipelineDataMutex);
675 pstBtrMgrSoGst->bPipelineError = FALSE;
676 g_mutex_unlock(&pstBtrMgrSoGst->pipelineDataMutex);
680 gst_element_set_state(GST_ELEMENT(pipeline), GST_STATE_PLAYING);
681 if (btrMgr_SO_validateStateWithTimeout(pipeline, GST_STATE_PLAYING, BTRMGR_SLEEP_TIMEOUT_MS) != GST_STATE_PLAYING) {
682 BTRMGRLOG_ERROR (
"Unable to perform Operation\n");
683 return eBTRMgrSOGstFailure;
686 pstBtrMgrSoGst->bIsInputPaused = FALSE;
687 pstBtrMgrSoGst->i32InBufMaxSize = ai32InBufMaxSize;
688 pstBtrMgrSoGst->i32InRate = ai32InRate;
689 pstBtrMgrSoGst->i32InChannels = ai32InChannels;
690 pstBtrMgrSoGst->ui32InBitsPSample = lui32InBitsPSample;
691 pstBtrMgrSoGst->ui32InBufIntervalms = round((pstBtrMgrSoGst->i32InBufMaxSize * 1000) / (pstBtrMgrSoGst->i32InRate * pstBtrMgrSoGst->i32InChannels * (pstBtrMgrSoGst->ui32InBitsPSample/8)));
692 pstBtrMgrSoGst->ui8IpBufThrsCnt = 0;
694 BTRMGRLOG_WARN (
"i32InRate - %d i32InChannels - %d, ui32InBitsPSample - %d, i32InBufMaxSize - %d ui32InBufIntervalms - %d\n",
695 pstBtrMgrSoGst->i32InRate, pstBtrMgrSoGst->i32InChannels, pstBtrMgrSoGst->ui32InBitsPSample, pstBtrMgrSoGst->i32InBufMaxSize, pstBtrMgrSoGst->ui32InBufIntervalms);
697 #if !(ENABLE_MAIN_LOOP_CONTEXT)
699 GSource* source = g_timeout_source_new(pstBtrMgrSoGst->ui32InBufIntervalms);
700 g_source_set_priority(source, G_PRIORITY_DEFAULT);
701 g_source_set_callback(source, (GSourceFunc) btrMgr_SO_g_timeout_EmptyBufPushCb, pstBtrMgrSoGst, NULL);
703 if (pstBtrMgrSoGst->emptyBufPushId) {
704 g_source_destroy(g_main_context_find_source_by_id(pstBtrMgrSoGst->pContext, pstBtrMgrSoGst->emptyBufPushId));
705 pstBtrMgrSoGst->emptyBufPushId = 0;
708 if ((pstBtrMgrSoGst->emptyBufPushId = g_source_attach(source, pstBtrMgrSoGst->pContext)) != 0) {
709 BTRMGRLOG_DEBUG(
"Empty Buf Push Id = %d\n", pstBtrMgrSoGst->emptyBufPushId);
712 g_source_unref(source);
716 return eBTRMgrSOGstSuccess;
722 tBTRMgrSoGstHdl hBTRMgrSoGstHdl
725 GstElement* pipeline = NULL;
727 if (!pstBtrMgrSoGst) {
728 BTRMGRLOG_ERROR (
"Invalid input argument\n");
729 return eBTRMgrSOGstFailInArg;
732 pipeline = (GstElement*)pstBtrMgrSoGst->pPipeline;
734 pstBtrMgrSoGst->bIsInputPaused = FALSE;
736 g_mutex_lock(&pstBtrMgrSoGst->pipelineDataMutex);
737 pstBtrMgrSoGst->bPipelineError = FALSE;
738 g_mutex_unlock(&pstBtrMgrSoGst->pipelineDataMutex);
742 gst_element_set_state(GST_ELEMENT(pipeline), GST_STATE_NULL);
743 if (btrMgr_SO_validateStateWithTimeout(pipeline, GST_STATE_NULL, BTRMGR_SLEEP_TIMEOUT_MS) != GST_STATE_NULL) {
744 BTRMGRLOG_ERROR (
"- Unable to perform Operation\n");
745 return eBTRMgrSOGstFailure;
748 pstBtrMgrSoGst->gstClkTStamp = 0;
749 pstBtrMgrSoGst->inBufOffset = 0;
751 pstBtrMgrSoGst->i32InBufMaxSize = 0;
752 pstBtrMgrSoGst->i32InRate = 0;
753 pstBtrMgrSoGst->i32InChannels = 0;
754 pstBtrMgrSoGst->ui32InBitsPSample = 0;
755 pstBtrMgrSoGst->ui32InBufIntervalms = 0;
756 pstBtrMgrSoGst->ui8IpBufThrsCnt = 0;
759 return eBTRMgrSOGstSuccess;
765 tBTRMgrSoGstHdl hBTRMgrSoGstHdl
768 GstElement* pipeline = NULL;
770 if (!pstBtrMgrSoGst) {
771 BTRMGRLOG_ERROR (
"Invalid input argument\n");
772 return eBTRMgrSOGstFailInArg;
775 pipeline = (GstElement*)pstBtrMgrSoGst->pPipeline;
779 if (btrMgr_SO_validateStateWithTimeout(pipeline, GST_STATE_PLAYING, BTRMGR_SLEEP_TIMEOUT_MS) != GST_STATE_PLAYING) {
780 BTRMGRLOG_ERROR (
"Incorrect State to perform Operation\n");
781 return eBTRMgrSOGstFailure;
785 gst_element_set_state(GST_ELEMENT(pipeline), GST_STATE_PAUSED);
786 if (btrMgr_SO_validateStateWithTimeout(pipeline, GST_STATE_PAUSED, BTRMGR_SLEEP_TIMEOUT_MS) != GST_STATE_PAUSED) {
787 BTRMGRLOG_ERROR (
"Unable to perform Operation\n");
788 return eBTRMgrSOGstFailure;
791 return eBTRMgrSOGstSuccess;
797 tBTRMgrSoGstHdl hBTRMgrSoGstHdl
800 GstElement* pipeline = NULL;
802 if (!pstBtrMgrSoGst) {
803 BTRMGRLOG_ERROR (
"Invalid input argument\n");
804 return eBTRMgrSOGstFailInArg;
807 pipeline = (GstElement*)pstBtrMgrSoGst->pPipeline;
811 if (btrMgr_SO_validateStateWithTimeout(pipeline, GST_STATE_PAUSED, BTRMGR_SLEEP_TIMEOUT_MS) != GST_STATE_PAUSED) {
812 BTRMGRLOG_ERROR (
"Incorrect State to perform Operation\n");
813 return eBTRMgrSOGstFailure;
817 gst_element_set_state(GST_ELEMENT(pipeline), GST_STATE_PLAYING);
818 if (btrMgr_SO_validateStateWithTimeout(pipeline, GST_STATE_PLAYING, BTRMGR_SLEEP_TIMEOUT_MS) != GST_STATE_PLAYING) {
819 BTRMGRLOG_ERROR (
"Unable to perform Operation\n");
820 return eBTRMgrSOGstFailure;
823 return eBTRMgrSOGstSuccess;
829 tBTRMgrSoGstHdl hBTRMgrSoGstHdl,
830 unsigned char ui8InputPaused
833 eBTRMgrSOGstRet lenBtrMgrSoGstRet = eBTRMgrSOGstFailure;
835 if (!pstBtrMgrSoGst) {
836 BTRMGRLOG_ERROR (
"Invalid input argument\n");
837 return eBTRMgrSOGstFailInArg;
840 #if !(ENABLE_MAIN_LOOP_CONTEXT)
841 if (ui8InputPaused) {
844 BTRMGRLOG_WARN (
"SO Empty Cb i32InRate - %d\n", pstBtrMgrSoGst->i32InRate);
845 BTRMGRLOG_WARN (
"SO Empty Cb i32InChannels - %d\n", pstBtrMgrSoGst->i32InChannels);
846 BTRMGRLOG_WARN (
"SO Empty Cb ui32InBitsPSample - %d\n", pstBtrMgrSoGst->ui32InBitsPSample);
847 BTRMGRLOG_WARN (
"SO Empty Cb i32InBufMaxSize - %d\n", pstBtrMgrSoGst->i32InBufMaxSize);
848 BTRMGRLOG_WARN (
"SO Empty Cb ui32InBufIntervalms- %d\n", pstBtrMgrSoGst->ui32InBufIntervalms);
850 pstBtrMgrSoGst->bIsInputPaused =
TRUE;
851 pstBtrMgrSoGst->ui8IpBufThrsCnt = BTRMGR_INPUT_BUF_INTERVAL_THRES_CNT;
852 source = g_timeout_source_new(pstBtrMgrSoGst->ui32InBufIntervalms);
853 g_source_set_priority(source, G_PRIORITY_DEFAULT);
854 g_source_set_callback(source, (GSourceFunc) btrMgr_SO_g_timeout_EmptyBufPushCb, pstBtrMgrSoGst, NULL);
856 if (pstBtrMgrSoGst->emptyBufPushId) {
857 g_source_destroy(g_main_context_find_source_by_id(pstBtrMgrSoGst->pContext, pstBtrMgrSoGst->emptyBufPushId));
858 pstBtrMgrSoGst->emptyBufPushId = 0;
861 if ((pstBtrMgrSoGst->emptyBufPushId = g_source_attach(source, pstBtrMgrSoGst->pContext)) != 0) {
862 lenBtrMgrSoGstRet = eBTRMgrSOGstSuccess;
865 g_source_unref(source);
868 pstBtrMgrSoGst->bIsInputPaused = FALSE;
869 pstBtrMgrSoGst->ui8IpBufThrsCnt = 0;
870 if (pstBtrMgrSoGst->emptyBufPushId) {
871 BTRMGRLOG_WARN (
"SO Empty Cb GSource Destroy - %d\n", pstBtrMgrSoGst->emptyBufPushId);
872 g_source_destroy(g_main_context_find_source_by_id(pstBtrMgrSoGst->pContext, pstBtrMgrSoGst->emptyBufPushId));
873 pstBtrMgrSoGst->emptyBufPushId = 0;
874 lenBtrMgrSoGstRet = eBTRMgrSOGstSuccess;
879 return lenBtrMgrSoGstRet;
885 tBTRMgrSoGstHdl hBTRMgrSoGstHdl,
886 unsigned char ui8Volume
889 GstElement* volume = NULL;
891 if (!pstBtrMgrSoGst) {
892 BTRMGRLOG_ERROR (
"Invalid input argument\n");
893 return eBTRMgrSOGstFailInArg;
896 volume = (GstElement*)pstBtrMgrSoGst->pVolume;
899 BTRMGRLOG_DEBUG(
"Volume at StreamOut Gst = %d, %f\n", ui8Volume, ui8Volume/255.0);
900 g_object_set (volume,
"volume", (
double)(ui8Volume/255.0), NULL);
902 return eBTRMgrSOGstSuccess;
908 tBTRMgrSoGstHdl hBTRMgrSoGstHdl,
909 unsigned char* ui8Volume
912 GstElement* volume = NULL;
915 if (!pstBtrMgrSoGst || !ui8Volume) {
916 BTRMGRLOG_ERROR (
"Invalid input argument\n");
917 return eBTRMgrSOGstFailInArg;
920 volume = (GstElement*)pstBtrMgrSoGst->pVolume;
921 g_object_get (volume,
"volume", &dvolume, NULL);
922 *ui8Volume = (
unsigned char )((dvolume) * 255) ;
923 BTRMGRLOG_DEBUG(
"Get Volume at StreamOut %d \n", *ui8Volume );
925 return eBTRMgrSOGstSuccess;
931 tBTRMgrSoGstHdl hBTRMgrSoGstHdl,
935 GstElement* volume = NULL;
937 if (!pstBtrMgrSoGst) {
938 BTRMGRLOG_ERROR (
"Invalid input argument\n");
939 return eBTRMgrSOGstFailInArg;
942 volume = (GstElement*)pstBtrMgrSoGst->pVolume;
943 g_object_set (volume,
"mute", mute, NULL);
944 BTRMGRLOG_DEBUG(
"Set mute at StreamOut %d \n", mute );
946 return eBTRMgrSOGstSuccess;
952 tBTRMgrSoGstHdl hBTRMgrSoGstHdl,
956 gboolean mute = FALSE;
957 GstElement* volume = NULL;
959 if (!pstBtrMgrSoGst || !muted) {
960 BTRMGRLOG_ERROR (
"Invalid input argument\n");
961 return eBTRMgrSOGstFailInArg;
964 volume = (GstElement*)pstBtrMgrSoGst->pVolume;
965 g_object_get (volume,
"mute", &mute, NULL);
967 BTRMGRLOG_DEBUG(
"Get mute at StreamOut %d \n", *muted);
969 return eBTRMgrSOGstSuccess;
975 tBTRMgrSoGstHdl hBTRMgrSoGstHdl,
981 if (!pstBtrMgrSoGst || !pcInBuf) {
982 BTRMGRLOG_ERROR (
"Invalid input argument\n");
983 return eBTRMgrSOGstFailInArg;
986 #if !(ENABLE_MAIN_LOOP_CONTEXT)
987 pstBtrMgrSoGst->bIsInputPaused = FALSE;
988 if (pstBtrMgrSoGst->emptyBufPushId && pstBtrMgrSoGst->pContext) {
989 BTRMGRLOG_WARN (
"SO Empty Cb GSource Destroy - %d Context - %p\n", pstBtrMgrSoGst->emptyBufPushId, pstBtrMgrSoGst->pContext);
990 g_source_destroy(g_main_context_find_source_by_id(pstBtrMgrSoGst->pContext, pstBtrMgrSoGst->emptyBufPushId));
991 pstBtrMgrSoGst->emptyBufPushId = 0;
992 if (pstBtrMgrSoGst->ui8IpBufThrsCnt == BTRMGR_INPUT_BUF_INTERVAL_THRES_CNT) {
993 gst_element_send_event(GST_ELEMENT(pstBtrMgrSoGst->pPipeline), gst_event_new_flush_start());
994 gst_element_send_event(GST_ELEMENT(pstBtrMgrSoGst->pPipeline), gst_event_new_flush_stop(FALSE));
998 pstBtrMgrSoGst->ui8IpBufThrsCnt = 0;
1001 return btrMgr_SO_GstSendBuffer(pstBtrMgrSoGst, pcInBuf, aiInBufSize);
1005 static eBTRMgrSOGstRet
1006 btrMgr_SO_GstSendBuffer (
1011 int i32InBufOffset = 0;
1012 GstElement* appsrc = NULL;
1013 gboolean lbPipelineEr = FALSE;
1015 appsrc = (GstElement*)pstBtrMgrSoGst->pSrc;
1018 g_mutex_lock(&pstBtrMgrSoGst->pipelineDataMutex);
1019 lbPipelineEr = pstBtrMgrSoGst->bPipelineError;
1020 g_mutex_unlock(&pstBtrMgrSoGst->pipelineDataMutex);
1023 if (lbPipelineEr ==
TRUE) {
1025 return eBTRMgrSOGstSuccess;
1031 return eBTRMgrSOGstFailure;
1037 while (aiInBufSize > pstBtrMgrSoGst->i32InBufMaxSize) {
1039 GstMapInfo gstBufMap;
1041 gstBuf = gst_buffer_new_and_alloc (pstBtrMgrSoGst->i32InBufMaxSize);
1042 gst_buffer_set_size (gstBuf, pstBtrMgrSoGst->i32InBufMaxSize);
1044 gst_buffer_map (gstBuf, &gstBufMap, GST_MAP_WRITE);
1047 memcpy (gstBufMap.data, pcInBuf + i32InBufOffset, pstBtrMgrSoGst->i32InBufMaxSize);
1051 GST_BUFFER_PTS (gstBuf) = pstBtrMgrSoGst->gstClkTStamp;
1052 GST_BUFFER_DURATION (gstBuf) = GST_USECOND * (pstBtrMgrSoGst->i32InBufMaxSize * 1000)/((pstBtrMgrSoGst->i32InRate/1000.0) * (pstBtrMgrSoGst->ui32InBitsPSample/8) * pstBtrMgrSoGst->i32InChannels);
1053 pstBtrMgrSoGst->gstClkTStamp += GST_BUFFER_DURATION (gstBuf);
1055 GST_BUFFER_OFFSET (gstBuf) = pstBtrMgrSoGst->inBufOffset;
1056 pstBtrMgrSoGst->inBufOffset += pstBtrMgrSoGst->i32InBufMaxSize;
1057 GST_BUFFER_OFFSET_END (gstBuf) = pstBtrMgrSoGst->inBufOffset - 1;
1059 gst_buffer_unmap (gstBuf, &gstBufMap);
1062 gst_app_src_push_buffer (GST_APP_SRC (appsrc), gstBuf);
1064 aiInBufSize -= pstBtrMgrSoGst->i32InBufMaxSize;
1065 i32InBufOffset += pstBtrMgrSoGst->i32InBufMaxSize;
1071 GstMapInfo gstBufMap;
1073 gstBuf = gst_buffer_new_and_alloc (aiInBufSize);
1074 gst_buffer_set_size (gstBuf, aiInBufSize);
1076 gst_buffer_map (gstBuf, &gstBufMap, GST_MAP_WRITE);
1079 memcpy (gstBufMap.data, pcInBuf + i32InBufOffset, aiInBufSize);
1083 GST_BUFFER_PTS (gstBuf) = pstBtrMgrSoGst->gstClkTStamp;
1084 GST_BUFFER_DURATION (gstBuf) = GST_USECOND * (aiInBufSize * 1000)/((pstBtrMgrSoGst->i32InRate/1000.0) * (pstBtrMgrSoGst->ui32InBitsPSample/8) * pstBtrMgrSoGst->i32InChannels);
1085 pstBtrMgrSoGst->gstClkTStamp += GST_BUFFER_DURATION (gstBuf);
1087 GST_BUFFER_OFFSET (gstBuf) = pstBtrMgrSoGst->inBufOffset;
1088 pstBtrMgrSoGst->inBufOffset += aiInBufSize;
1089 GST_BUFFER_OFFSET_END (gstBuf) = pstBtrMgrSoGst->inBufOffset - 1;
1091 gst_buffer_unmap (gstBuf, &gstBufMap);
1094 gst_app_src_push_buffer (GST_APP_SRC (appsrc), gstBuf);
1097 return eBTRMgrSOGstSuccess;
1103 tBTRMgrSoGstHdl hBTRMgrSoGstHdl
1106 GstElement* appsrc = NULL;
1107 gboolean lbPipelineEr = FALSE;
1109 if (!pstBtrMgrSoGst) {
1110 BTRMGRLOG_ERROR (
"Invalid input argument\n");
1111 return eBTRMgrSOGstFailInArg;
1114 appsrc = (GstElement*)pstBtrMgrSoGst->pSrc;
1117 g_mutex_lock(&pstBtrMgrSoGst->pipelineDataMutex);
1118 lbPipelineEr = pstBtrMgrSoGst->bPipelineError;
1119 g_mutex_unlock(&pstBtrMgrSoGst->pipelineDataMutex);
1122 if (lbPipelineEr ==
TRUE) {
1123 return eBTRMgrSOGstFailure;
1128 gst_app_src_end_of_stream (GST_APP_SRC (appsrc));
1129 return eBTRMgrSOGstSuccess;
1137 #if !(ENABLE_MAIN_LOOP_CONTEXT)
1139 btrMgr_SO_g_main_loop_RunningCb (
1140 gpointer apstBtrMgrSoGst
1144 if (!pstBtrMgrSoGst) {
1145 BTRMGRLOG_ERROR (
"GMainLoop Error - In arguments Exiting\n");
1146 return G_SOURCE_REMOVE;
1149 BTRMGRLOG_INFO (
"GMainLoop running now\n");
1151 g_mutex_lock (&pstBtrMgrSoGst->gMtxMainLoopRunLock);
1152 g_cond_signal (&pstBtrMgrSoGst->gCndMainLoopRun);
1153 g_mutex_unlock (&pstBtrMgrSoGst->gMtxMainLoopRunLock);
1155 return G_SOURCE_REMOVE;
1160 btrMgr_SO_g_timeout_EmptyBufPushCb (
1161 gpointer apstBtrMgrSoGst
1164 char* pcInBuf = NULL;
1165 if (!pstBtrMgrSoGst || !pstBtrMgrSoGst->i32InBufMaxSize) {
1166 BTRMGRLOG_ERROR (
"GTimeOut Error - In arguments Exiting\n");
1170 if ((pstBtrMgrSoGst->bIsInputPaused == FALSE) &&
1171 (pstBtrMgrSoGst->ui8IpBufThrsCnt >= BTRMGR_INPUT_BUF_INTERVAL_THRES_CNT)) {
1172 BTRMGRLOG_TRACE (
"Not pushing Empty buffer - %d\n", pstBtrMgrSoGst->ui8IpBufThrsCnt);
1176 if (pstBtrMgrSoGst->ui8IpBufThrsCnt < BTRMGR_INPUT_BUF_INTERVAL_THRES_CNT)
1177 pstBtrMgrSoGst->ui8IpBufThrsCnt++;
1179 if ((pcInBuf = malloc(pstBtrMgrSoGst->i32InBufMaxSize *
sizeof(
char))) == NULL) {
1180 BTRMGRLOG_ERROR (
"GTimeOut Error - Unable to Alloc memory\n");
1184 memset(pcInBuf, 0, pstBtrMgrSoGst->i32InBufMaxSize);
1185 if (btrMgr_SO_GstSendBuffer(pstBtrMgrSoGst, pcInBuf, pstBtrMgrSoGst->i32InBufMaxSize) != eBTRMgrSOGstSuccess) {
1186 BTRMGRLOG_WARN (
"GTimeOut - Unable to Push Enpty Buffer\n");
1197 btrMgr_SO_NeedDataCb (
1200 gpointer apstBtrMgrSoGst
1205 if (pstBtrMgrSoGst && pstBtrMgrSoGst->fpcBSoGstStatus) {
1206 pstBtrMgrSoGst->fpcBSoGstStatus(eBTRMgrSOGstStUnderflow, pstBtrMgrSoGst->pvcBUserData);
1212 btrMgr_SO_EnoughDataCb (
1214 gpointer apstBtrMgrSoGst
1219 if (pstBtrMgrSoGst && pstBtrMgrSoGst->fpcBSoGstStatus) {
1220 pstBtrMgrSoGst->fpcBSoGstStatus(eBTRMgrSOGstStOverflow, pstBtrMgrSoGst->pvcBUserData);
1226 btrMgr_SO_gstBusCallCb (
1229 gpointer apstBtrMgrSoGst
1233 switch (GST_MESSAGE_TYPE (msg)) {
1235 case GST_MESSAGE_EOS: {
1236 BTRMGRLOG_INFO (
"End-of-stream\n");
1237 if (pstBtrMgrSoGst) {
1238 if (pstBtrMgrSoGst->pLoop) {
1239 g_main_loop_quit(pstBtrMgrSoGst->pLoop);
1242 if (pstBtrMgrSoGst->fpcBSoGstStatus) {
1243 BTRMGRLOG_INFO (
"EOS: Trigger Final Status cB\n");
1244 pstBtrMgrSoGst->fpcBSoGstStatus(pstBtrMgrSoGst->bPipelineError ==
TRUE ? eBTRMgrSOGstStError : eBTRMgrSOGstStCompleted,
1245 pstBtrMgrSoGst->pvcBUserData);
1251 case GST_MESSAGE_STATE_CHANGED: {
1252 if (pstBtrMgrSoGst && (pstBtrMgrSoGst->pPipeline) && (GST_MESSAGE_SRC (msg) == GST_OBJECT (pstBtrMgrSoGst->pPipeline))) {
1253 GstState prevState, currentState;
1255 gst_message_parse_state_changed (msg, &prevState, ¤tState, NULL);
1256 BTRMGRLOG_INFO (
"From: %s -> To: %s\n",
1257 gst_element_state_get_name (prevState), gst_element_state_get_name (currentState));
1262 case GST_MESSAGE_ERROR: {
1266 if (pstBtrMgrSoGst) {
1267 g_mutex_lock(&pstBtrMgrSoGst->pipelineDataMutex);
1268 pstBtrMgrSoGst->bPipelineError =
TRUE;
1269 g_mutex_unlock(&pstBtrMgrSoGst->pipelineDataMutex);
1272 gst_message_parse_error (msg, &err, &debug);
1273 BTRMGRLOG_DEBUG (
"Debugging info: %s\n", (debug) ? debug :
"none");
1276 BTRMGRLOG_ERROR (
"Error: %s\n", err->message);
1279 if (pstBtrMgrSoGst) {
1280 if (pstBtrMgrSoGst->pLoop) {
1281 g_main_loop_quit(pstBtrMgrSoGst->pLoop);
1284 if (pstBtrMgrSoGst->fpcBSoGstStatus) {
1285 BTRMGRLOG_INFO (
"ERROR: Trigger Final Status cB\n");
1286 pstBtrMgrSoGst->fpcBSoGstStatus(pstBtrMgrSoGst->bPipelineError ==
TRUE ? eBTRMgrSOGstStError : eBTRMgrSOGstStCompleted,
1287 pstBtrMgrSoGst->pvcBUserData);
1293 case GST_MESSAGE_WARNING:{
1297 gst_message_parse_warning (msg, &warn, &debug);
1298 BTRMGRLOG_DEBUG (
"Debugging info: %s\n", (debug) ? debug :
"none");
1301 BTRMGRLOG_WARN (
"Warning: %s\n", warn->message);
1302 g_error_free (warn);
1304 if (pstBtrMgrSoGst && pstBtrMgrSoGst->fpcBSoGstStatus) {
1305 pstBtrMgrSoGst->fpcBSoGstStatus(eBTRMgrSOGstStWarning, pstBtrMgrSoGst->pvcBUserData);