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 16 // Number of blocks in the internal queue
55 #define GST_ELEMENT_GET_STATE_RETRY_CNT_MAX 5
57 #define ENABLE_MAIN_LOOP_CONTEXT 0
67 void* psbcdecCapsFilter;
72 #if !(ENABLE_MAIN_LOOP_CONTEXT)
74 GMutex gMtxMainLoopRunLock;
75 GCond gCndMainLoopRun;
82 GstClockTime gstClkTStamp;
85 fPtr_BTRMgr_SI_GstStatusCb fpcBSiGstStatus;
92 static GstState btrMgr_SI_validateStateWithTimeout (GstElement* element, GstState stateToValidate, guint msTimeOut);
95 static gpointer btrMgr_SI_g_main_loop_Task (gpointer apstBtrMgrSiGst);
98 #if !(ENABLE_MAIN_LOOP_CONTEXT)
99 static gboolean btrMgr_SI_g_main_loop_RunningCb (gpointer apstBtrMgrSiGst);
101 static gboolean btrMgr_SI_gstBusCallCb (GstBus* bus, GstMessage* msg, gpointer apstBtrMgrSiGst);
106 btrMgr_SI_validateStateWithTimeout (
108 GstState stateToValidate,
111 GstState gst_current = GST_STATE_VOID_PENDING;
112 GstState gst_pending = GST_STATE_VOID_PENDING;
113 float timeout = BTRMGR_WAIT_TIMEOUT_MS;
114 gint gstGetStateCnt = GST_ELEMENT_GET_STATE_RETRY_CNT_MAX;
116 GstStateChangeReturn gstStChangeRet = GST_STATE_CHANGE_FAILURE;
119 gstStChangeRet = gst_element_get_state(GST_ELEMENT(element), &gst_current, &gst_pending, timeout * GST_MSECOND);
120 if (((GST_STATE_CHANGE_SUCCESS == gstStChangeRet) || (GST_STATE_CHANGE_NO_PREROLL == gstStChangeRet)) && (gst_current == stateToValidate)) {
121 BTRMGRLOG_INFO(
"gst_element_get_state - SUCCESS : St = %d Pend = %d StValidate = %d StChRet = %d\n", gst_current, gst_pending, stateToValidate, gstStChangeRet);
124 usleep(msTimeOut * 1000);
125 }
while (((gstStChangeRet == GST_STATE_CHANGE_ASYNC) || (gst_current != stateToValidate)) && (gstGetStateCnt-- != 0)) ;
127 BTRMGRLOG_ERROR(
"gst_element_get_state - FAILURE : St = %d Pend = %d StValidate = %d StChRet = %d\n", gst_current, gst_pending, stateToValidate, gstStChangeRet);
129 if (gst_pending == stateToValidate)
138 btrMgr_SI_g_main_loop_Task (
139 gpointer apstBtrMgrSiGst
143 if (!pstBtrMgrSiGst || !pstBtrMgrSiGst->pLoop) {
144 BTRMGRLOG_ERROR (
"GMainLoop Error - In arguments Exiting\n");
148 #if !(ENABLE_MAIN_LOOP_CONTEXT)
149 GstElement* fdsrc = NULL;
150 GstElement* rtpcapsfilter = NULL;
151 GstElement* rtpauddepay = NULL;
152 GstElement* audparse = NULL;
153 GstElement* auddec = NULL;
154 GstElement* volume = NULL;
155 GstElement* fdsink = NULL;
156 GstElement* pipeline = NULL;
158 GSource* idleSource = NULL;
159 GMainLoop* loop = NULL;
160 GMainContext* mainContext = NULL;
164 if (!pstBtrMgrSiGst->pContext) {
165 BTRMGRLOG_ERROR (
"GMainLoop Error - No context\n");
170 mainContext = pstBtrMgrSiGst->pContext;
171 g_main_context_push_thread_default (mainContext);
173 idleSource = g_idle_source_new ();
174 g_source_set_callback (idleSource, (GSourceFunc) btrMgr_SI_g_main_loop_RunningCb, pstBtrMgrSiGst, NULL);
175 g_source_attach (idleSource, mainContext);
176 g_source_unref (idleSource);
180 fdsrc = gst_element_factory_make (
"fdsrc",
"btmgr-si-fdsrc");
183 rtpcapsfilter = gst_element_factory_make (
"capsfilter",
"btmgr-si-rtpcapsfilter");
184 rtpauddepay = gst_element_factory_make (
"rtpsbcdepay",
"btmgr-si-rtpsbcdepay");
185 audparse = gst_element_factory_make (
"sbcparse",
"btmgr-si-rtpsbcparse");
186 auddec = gst_element_factory_make (
"sbcdec",
"btmgr-si-sbcdec");
187 volume = gst_element_factory_make (
"volume",
"btmgr-si-volume");
189 #if defined BUILD_FOR_BRCM
191 fdsink = gst_element_factory_make (
"brcmpcmsink",
"btmgr-si-pcmsink");
194 fdsink = gst_element_factory_make (
"autoaudiosink",
"btmgr-si-pcmsink");
198 pipeline = gst_pipeline_new (
"btmgr-si-pipeline");
200 loop = pstBtrMgrSiGst->pLoop;
202 if (!fdsrc || !rtpcapsfilter || !rtpauddepay || !audparse || !auddec || !volume || !fdsink || !loop || !pipeline) {
203 BTRMGRLOG_ERROR (
"Gstreamer plugin missing for streamIn\n");
207 pstBtrMgrSiGst->pPipeline = (
void*)pipeline;
208 pstBtrMgrSiGst->pSrc = (
void*)fdsrc;
209 pstBtrMgrSiGst->pSrcCapsFilter = (
void*)rtpcapsfilter;
210 pstBtrMgrSiGst->pRtpAudioDePay = (
void*)rtpauddepay;
211 pstBtrMgrSiGst->pAudioParse = (
void*)audparse;
212 pstBtrMgrSiGst->pAudioDec = (
void*)auddec;
213 pstBtrMgrSiGst->pVolume = (
void*)volume;
214 pstBtrMgrSiGst->pSink = (
void*)fdsink;
215 pstBtrMgrSiGst->pLoop = (
void*)loop;
216 pstBtrMgrSiGst->gstClkTStamp = 0;
217 pstBtrMgrSiGst->inBufOffset = 0;
220 bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline));
221 busWatchId = gst_bus_add_watch (bus, btrMgr_SI_gstBusCallCb, pstBtrMgrSiGst);
222 pstBtrMgrSiGst->busWId = busWatchId;
223 g_object_unref (bus);
226 gst_bin_add_many (GST_BIN (pipeline), fdsrc, rtpcapsfilter, rtpauddepay, audparse, auddec, volume, fdsink, NULL);
227 gst_element_link_many (fdsrc, rtpcapsfilter, rtpauddepay, audparse, auddec, volume, fdsink, NULL);
232 BTRMGRLOG_INFO (
"GMainLoop Running\n");
233 g_main_loop_run (pstBtrMgrSiGst->pLoop);
236 #if !(ENABLE_MAIN_LOOP_CONTEXT)
238 GSource *busSource = g_main_context_find_source_by_id(mainContext, busWatchId);
240 g_source_destroy(busSource);
243 pstBtrMgrSiGst->busWId = busWatchId;
247 g_main_context_pop_thread_default (mainContext);
250 BTRMGRLOG_INFO (
"GMainLoop Exiting\n");
251 return pstBtrMgrSiGst;
258 tBTRMgrSiGstHdl* phBTRMgrSiGstHdl,
259 fPtr_BTRMgr_SI_GstStatusCb afpcBSiGstStatus,
262 #if (ENABLE_MAIN_LOOP_CONTEXT)
263 GstElement* fdsrc = NULL;
264 GstElement* rtpcapsfilter = NULL;
265 GstElement* rtpauddepay = NULL;
266 GstElement* audparse = NULL;
267 GstElement* auddec = NULL;
268 GstElement* volume = NULL;
269 GstElement* fdsink = NULL;
270 GstElement* pipeline = NULL;
274 GMainContext* mainContext = NULL;
278 GThread* mainLoopThread = NULL;
279 GMainLoop* loop = NULL;
283 BTRMGRLOG_ERROR (
"Unable to allocate memory\n");
284 return eBTRMgrSIGstFailure;
289 gst_init (NULL, NULL);
291 #if (ENABLE_MAIN_LOOP_CONTEXT)
293 fdsrc = gst_element_factory_make (
"fdsrc",
"btmgr-si-fdsrc");
296 rtpcapsfilter = gst_element_factory_make (
"capsfilter",
"btmgr-si-rtpcapsfilter");
297 rtpauddepay = gst_element_factory_make (
"rtpsbcdepay",
"btmgr-si-rtpsbcdepay");
298 audparse = gst_element_factory_make (
"sbcparse",
"btmgr-si-rtpsbcparse");
299 auddec = gst_element_factory_make (
"sbcdec",
"btmgr-si-sbcdec");
300 volume = gst_element_factory_make (
"volume",
"btmgr-si-volume");
302 #if defined BUILD_FOR_BRCM
304 fdsink = gst_element_factory_make (
"brcmpcmsink",
"btmgr-si-pcmsink");
307 fdsink = gst_element_factory_make (
"autoaudiosink",
"btmgr-si-pcmsink");
311 loop = g_main_loop_new (NULL, FALSE);
313 g_mutex_init (&pstBtrMgrSiGst->gMtxMainLoopRunLock);
314 g_cond_init (&pstBtrMgrSiGst->gCndMainLoopRun);
316 mainContext = g_main_context_new();
320 loop = g_main_loop_new (mainContext, FALSE);
325 #if (ENABLE_MAIN_LOOP_CONTEXT)
327 pipeline = gst_pipeline_new (
"btmgr-si-pipeline");
329 if (!fdsrc || !rtpcapsfilter || !rtpauddepay || !audparse || !auddec || !volume || !fdsink || !loop || !pipeline) {
330 BTRMGRLOG_ERROR (
"Gstreamer plugin missing for streamIn\n");
332 return eBTRMgrSIGstFailure;
335 pstBtrMgrSiGst->pPipeline = (
void*)pipeline;
336 pstBtrMgrSiGst->pSrc = (
void*)fdsrc;
337 pstBtrMgrSiGst->pSrcCapsFilter = (
void*)rtpcapsfilter;
338 pstBtrMgrSiGst->pRtpAudioDePay = (
void*)rtpauddepay;
339 pstBtrMgrSiGst->pAudioParse = (
void*)audparse;
340 pstBtrMgrSiGst->pAudioDec = (
void*)auddec;
341 pstBtrMgrSiGst->pVolume = (
void*)volume;
342 pstBtrMgrSiGst->pSink = (
void*)fdsink;
343 pstBtrMgrSiGst->pLoop = (
void*)loop;
344 pstBtrMgrSiGst->gstClkTStamp = 0;
345 pstBtrMgrSiGst->inBufOffset = 0;
346 pstBtrMgrSiGst->fpcBSiGstStatus = NULL;
347 pstBtrMgrSiGst->pvcBUserData = NULL;
350 if (afpcBSiGstStatus) {
351 pstBtrMgrSiGst->fpcBSiGstStatus = afpcBSiGstStatus;
352 pstBtrMgrSiGst->pvcBUserData = apvUserData;
356 bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline));
357 busWatchId = gst_bus_add_watch (bus, btrMgr_SI_gstBusCallCb, pstBtrMgrSiGst);
358 pstBtrMgrSiGst->busWId = busWatchId;
359 g_object_unref (bus);
362 gst_bin_add_many (GST_BIN (pipeline), fdsrc, rtpcapsfilter, rtpauddepay, audparse, auddec, volume, fdsink, NULL);
363 gst_element_link_many (fdsrc, rtpcapsfilter, rtpauddepay, audparse, auddec, volume, fdsink, NULL);
366 mainLoopThread = g_thread_new(
"btrMgr_SI_g_main_loop_Task", btrMgr_SI_g_main_loop_Task, pstBtrMgrSiGst);
367 pstBtrMgrSiGst->pLoopThread = (
void*)mainLoopThread;
370 pstBtrMgrSiGst->pContext = (
void*)mainContext;
371 pstBtrMgrSiGst->pLoop = (
void*)loop;
372 pstBtrMgrSiGst->fpcBSiGstStatus = NULL;
373 pstBtrMgrSiGst->pvcBUserData = NULL;
375 if (afpcBSiGstStatus) {
376 pstBtrMgrSiGst->fpcBSiGstStatus = afpcBSiGstStatus;
377 pstBtrMgrSiGst->pvcBUserData = apvUserData;
381 g_mutex_lock (&pstBtrMgrSiGst->gMtxMainLoopRunLock);
383 mainLoopThread = g_thread_new(
"btrMgr_SI_g_main_loop_Task", btrMgr_SI_g_main_loop_Task, pstBtrMgrSiGst);
384 pstBtrMgrSiGst->pLoopThread = (
void*)mainLoopThread;
387 while (!loop || !g_main_loop_is_running (loop)) {
388 g_cond_wait (&pstBtrMgrSiGst->gCndMainLoopRun, &pstBtrMgrSiGst->gMtxMainLoopRunLock);
391 g_mutex_unlock (&pstBtrMgrSiGst->gMtxMainLoopRunLock);
395 gst_element_set_state(GST_ELEMENT(pstBtrMgrSiGst->pPipeline), GST_STATE_NULL);
396 if (btrMgr_SI_validateStateWithTimeout(pstBtrMgrSiGst->pPipeline, GST_STATE_NULL, BTRMGR_SLEEP_TIMEOUT_MS)!= GST_STATE_NULL) {
397 BTRMGRLOG_ERROR (
"Unable to perform Operation\n");
399 return eBTRMgrSIGstFailure;
403 *phBTRMgrSiGstHdl = (tBTRMgrSiGstHdl)pstBtrMgrSiGst;
405 return eBTRMgrSIGstSuccess;
411 tBTRMgrSiGstHdl hBTRMgrSiGstHdl
415 if (!pstBtrMgrSiGst) {
416 BTRMGRLOG_ERROR (
"Invalid input argument\n");
417 return eBTRMgrSIGstFailInArg;
420 GstElement* pipeline = (GstElement*)pstBtrMgrSiGst->pPipeline;
421 GMainLoop* loop = (GMainLoop*)pstBtrMgrSiGst->pLoop;
422 GThread* mainLoopThread = (GThread*)pstBtrMgrSiGst->pLoopThread;
423 #if (ENABLE_MAIN_LOOP_CONTEXT)
424 guint busWatchId = pstBtrMgrSiGst->busWId;
426 GMainContext* mainContext = (GMainContext*)pstBtrMgrSiGst->pContext;
431 gst_object_unref(GST_OBJECT(pipeline));
435 #if (ENABLE_MAIN_LOOP_CONTEXT)
437 GSource *busSource = g_main_context_find_source_by_id(g_main_context_get_thread_default(), busWatchId);
439 g_source_destroy(busSource);
446 g_main_loop_quit(loop);
449 if (mainLoopThread) {
450 g_thread_join(mainLoopThread);
451 mainLoopThread = NULL;
455 g_main_loop_unref(loop);
459 #if !(ENABLE_MAIN_LOOP_CONTEXT)
461 g_main_context_unref(mainContext);
466 if (pstBtrMgrSiGst->fpcBSiGstStatus)
467 pstBtrMgrSiGst->fpcBSiGstStatus = NULL;
470 #if !(ENABLE_MAIN_LOOP_CONTEXT)
471 g_cond_clear(&pstBtrMgrSiGst->gCndMainLoopRun);
472 g_mutex_clear(&pstBtrMgrSiGst->gMtxMainLoopRunLock);
477 free((
void*)pstBtrMgrSiGst);
478 pstBtrMgrSiGst = NULL;
480 return eBTRMgrSIGstSuccess;
486 tBTRMgrSiGstHdl hBTRMgrSiGstHdl,
490 unsigned int aiBTDevSFreq,
491 const char* apcAudioInType
495 if (!pstBtrMgrSiGst || !apcAudioInType) {
496 BTRMGRLOG_ERROR (
"Invalid input argument\n");
497 return eBTRMgrSIGstFailInArg;
500 GstElement* pipeline = (GstElement*)pstBtrMgrSiGst->pPipeline;
501 GstElement* fdsrc = (GstElement*)pstBtrMgrSiGst->pSrc;
502 GstElement* rtpcapsfilter = (GstElement*)pstBtrMgrSiGst->pSrcCapsFilter;
503 GstElement* auddec = (GstElement*)pstBtrMgrSiGst->pAudioDec;
504 GstElement* fdsink = (GstElement*)pstBtrMgrSiGst->pSink;
506 guint busWatchId = pstBtrMgrSiGst->busWId;
507 gint rtpPaylodVal= 0;
509 GstCaps* fdsrcSrcCaps = NULL;
517 if (btrMgr_SI_validateStateWithTimeout(pipeline, GST_STATE_NULL, BTRMGR_SLEEP_TIMEOUT_MS) != GST_STATE_NULL) {
518 BTRMGRLOG_ERROR (
"Incorrect State to perform Operation\n");
519 return eBTRMgrSIGstFailure;
522 pstBtrMgrSiGst->gstClkTStamp = 0;
523 pstBtrMgrSiGst->inBufOffset = 0;
526 if (!strncmp(apcAudioInType, BTRMGR_AUDIO_INPUT_TYPE_SBC, strlen(BTRMGR_AUDIO_INPUT_TYPE_SBC))) {
529 else if (!strncmp(apcAudioInType, BTRMGR_AUDIO_INPUT_TYPE_AAC, strlen(BTRMGR_AUDIO_INPUT_TYPE_AAC))) {
534 fdsrcSrcCaps = gst_caps_new_simple (
"application/x-rtp",
535 "media", G_TYPE_STRING,
"audio",
536 "encoding-name", G_TYPE_STRING, apcAudioInType,
537 "clock-rate", G_TYPE_INT, aiBTDevSFreq,
538 "payload", G_TYPE_INT, rtpPaylodVal,
541 g_object_set (fdsrc,
"fd", aiBTDevFd, NULL);
542 g_object_set (fdsrc,
"blocksize", aiBTDevMTU, NULL);
543 g_object_set (fdsrc,
"do-timestamp",
TRUE, NULL);
544 g_object_set (rtpcapsfilter,
"caps",fdsrcSrcCaps, NULL);
545 g_object_set (fdsink,
"sync", FALSE, NULL);
548 gst_caps_unref(fdsrcSrcCaps);
551 gst_element_set_state(GST_ELEMENT(pipeline), GST_STATE_PLAYING);
552 if (btrMgr_SI_validateStateWithTimeout(pipeline, GST_STATE_PLAYING, BTRMGR_SLEEP_TIMEOUT_MS) != GST_STATE_PLAYING) {
553 BTRMGRLOG_ERROR (
"Unable to perform Operation\n");
554 return eBTRMgrSIGstFailure;
557 return eBTRMgrSIGstSuccess;
563 tBTRMgrSiGstHdl hBTRMgrSiGstHdl
567 if (!pstBtrMgrSiGst) {
568 BTRMGRLOG_ERROR (
"Invalid input argument\n");
569 return eBTRMgrSIGstFailInArg;
572 GstElement* pipeline = (GstElement*)pstBtrMgrSiGst->pPipeline;
573 GstElement* fdsrc = (GstElement*)pstBtrMgrSiGst->pSrc;
574 GMainLoop* loop = (GMainLoop*)pstBtrMgrSiGst->pLoop;
575 guint busWatchId = pstBtrMgrSiGst->busWId;
583 gst_element_set_state(GST_ELEMENT(pipeline), GST_STATE_NULL);
584 if (btrMgr_SI_validateStateWithTimeout(pipeline, GST_STATE_NULL, BTRMGR_SLEEP_TIMEOUT_MS) != GST_STATE_NULL) {
585 BTRMGRLOG_ERROR (
"- Unable to perform Operation\n");
586 return eBTRMgrSIGstFailure;
589 pstBtrMgrSiGst->gstClkTStamp = 0;
590 pstBtrMgrSiGst->inBufOffset = 0;
592 return eBTRMgrSIGstSuccess;
598 tBTRMgrSiGstHdl hBTRMgrSiGstHdl
602 if (!pstBtrMgrSiGst) {
603 BTRMGRLOG_ERROR (
"Invalid input argument\n");
604 return eBTRMgrSIGstFailInArg;
607 GstElement* pipeline = (GstElement*)pstBtrMgrSiGst->pPipeline;
608 GstElement* fdsrc = (GstElement*)pstBtrMgrSiGst->pSrc;
609 GMainLoop* loop = (GMainLoop*)pstBtrMgrSiGst->pLoop;
610 guint busWatchId = pstBtrMgrSiGst->busWId;
618 if (btrMgr_SI_validateStateWithTimeout(pipeline, GST_STATE_PLAYING, BTRMGR_SLEEP_TIMEOUT_MS) != GST_STATE_PLAYING) {
619 BTRMGRLOG_ERROR (
"Incorrect State to perform Operation\n");
620 return eBTRMgrSIGstFailure;
624 gst_element_set_state(GST_ELEMENT(pipeline), GST_STATE_PAUSED);
625 if (btrMgr_SI_validateStateWithTimeout(pipeline, GST_STATE_PAUSED, BTRMGR_SLEEP_TIMEOUT_MS) != GST_STATE_PAUSED) {
626 BTRMGRLOG_ERROR (
"Unable to perform Operation\n");
627 return eBTRMgrSIGstFailure;
630 return eBTRMgrSIGstSuccess;
636 tBTRMgrSiGstHdl hBTRMgrSiGstHdl
640 if (!pstBtrMgrSiGst) {
641 BTRMGRLOG_ERROR (
"Invalid input argument\n");
642 return eBTRMgrSIGstFailInArg;
645 GstElement* pipeline = (GstElement*)pstBtrMgrSiGst->pPipeline;
646 GstElement* fdsrc = (GstElement*)pstBtrMgrSiGst->pSrc;
647 GMainLoop* loop = (GMainLoop*)pstBtrMgrSiGst->pLoop;
648 guint busWatchId = pstBtrMgrSiGst->busWId;
656 if (btrMgr_SI_validateStateWithTimeout(pipeline, GST_STATE_PAUSED, BTRMGR_SLEEP_TIMEOUT_MS) != GST_STATE_PAUSED) {
657 BTRMGRLOG_ERROR (
"Incorrect State to perform Operation\n");
658 return eBTRMgrSIGstFailure;
662 gst_element_set_state(GST_ELEMENT(pipeline), GST_STATE_PLAYING);
663 if (btrMgr_SI_validateStateWithTimeout(pipeline, GST_STATE_PLAYING, BTRMGR_SLEEP_TIMEOUT_MS) != GST_STATE_PLAYING) {
664 BTRMGRLOG_ERROR (
"Unable to perform Operation\n");
665 return eBTRMgrSIGstFailure;
668 return eBTRMgrSIGstSuccess;
674 tBTRMgrSiGstHdl hBTRMgrSiGstHdl,
675 unsigned char ui8Volume
679 if (!pstBtrMgrSiGst) {
680 BTRMGRLOG_ERROR (
"Invalid input argument\n");
681 return eBTRMgrSIGstFailInArg;
684 GstElement* pipeline = (GstElement*)pstBtrMgrSiGst->pPipeline;
685 GstElement* volume = (GstElement*)pstBtrMgrSiGst->pVolume;
690 BTRMGRLOG_DEBUG(
"Volume at StreamIn Gst = %d, %f\n", ui8Volume, ui8Volume/100.0);
691 g_object_set (volume,
"volume", (
double)(ui8Volume/100.0), NULL);
693 return eBTRMgrSIGstSuccess;
699 tBTRMgrSiGstHdl hBTRMgrSiGstHdl,
705 if (!pstBtrMgrSiGst) {
706 BTRMGRLOG_ERROR (
"Invalid input argument\n");
707 return eBTRMgrSIGstFailInArg;
710 GstElement* pipeline = (GstElement*)pstBtrMgrSiGst->pPipeline;
711 GstElement* fdsrc = (GstElement*)pstBtrMgrSiGst->pSrc;
712 GMainLoop* loop = (GMainLoop*)pstBtrMgrSiGst->pLoop;
713 guint busWatchId = pstBtrMgrSiGst->busWId;
723 GstMapInfo gstBufMap;
725 gstBuf = gst_buffer_new_and_alloc (aiInBufSize);
726 gst_buffer_map (gstBuf, &gstBufMap, GST_MAP_WRITE);
729 memcpy (gstBufMap.data, pcInBuf, aiInBufSize);
733 GST_BUFFER_PTS (gstBuf) = pstBtrMgrSiGst->gstClkTStamp;
734 GST_BUFFER_DURATION (gstBuf) = GST_USECOND * (aiInBufSize * 1000)/(48 * (16/8) * 2);
735 pstBtrMgrSiGst->gstClkTStamp += GST_BUFFER_DURATION (gstBuf);
737 GST_BUFFER_OFFSET (gstBuf) = pstBtrMgrSiGst->inBufOffset;
738 pstBtrMgrSiGst->inBufOffset += aiInBufSize;
739 GST_BUFFER_OFFSET_END (gstBuf) = pstBtrMgrSiGst->inBufOffset - 1;
741 gst_app_src_push_buffer (GST_APP_SRC (fdsrc), gstBuf);
743 gst_buffer_unmap (gstBuf, &gstBufMap);
746 return eBTRMgrSIGstSuccess;
752 tBTRMgrSiGstHdl hBTRMgrSiGstHdl
756 if (!pstBtrMgrSiGst) {
757 BTRMGRLOG_ERROR (
"Invalid input argument\n");
758 return eBTRMgrSIGstFailInArg;
761 GstElement* pipeline = (GstElement*)pstBtrMgrSiGst->pPipeline;
762 GstElement* fdsrc = (GstElement*)pstBtrMgrSiGst->pSrc;
763 GMainLoop* loop = (GMainLoop*)pstBtrMgrSiGst->pLoop;
764 guint busWatchId = pstBtrMgrSiGst->busWId;
772 gst_element_send_event (pipeline, gst_event_new_eos ());
774 return eBTRMgrSIGstSuccess;
781 #if !(ENABLE_MAIN_LOOP_CONTEXT)
783 btrMgr_SI_g_main_loop_RunningCb (
784 gpointer apstBtrMgrSiGst
788 if (!pstBtrMgrSiGst) {
789 BTRMGRLOG_ERROR (
"GMainLoop Error - In arguments Exiting\n");
790 return G_SOURCE_REMOVE;
793 BTRMGRLOG_INFO (
"GMainLoop running now");
795 g_mutex_lock (&pstBtrMgrSiGst->gMtxMainLoopRunLock);
796 g_cond_signal (&pstBtrMgrSiGst->gCndMainLoopRun);
797 g_mutex_unlock (&pstBtrMgrSiGst->gMtxMainLoopRunLock);
799 return G_SOURCE_REMOVE;
804 btrMgr_SI_gstBusCallCb (
807 gpointer apstBtrMgrSiGst
811 switch (GST_MESSAGE_TYPE (msg)) {
813 case GST_MESSAGE_EOS: {
815 BTRMGRLOG_INFO (
"End-of-stream\n");
816 if (pstBtrMgrSiGst) {
817 if (pstBtrMgrSiGst->pLoop) {
818 g_main_loop_quit(pstBtrMgrSiGst->pLoop);
825 case GST_MESSAGE_STATE_CHANGED: {
826 if (pstBtrMgrSiGst && (pstBtrMgrSiGst->pPipeline) && (GST_MESSAGE_SRC (msg) == GST_OBJECT (pstBtrMgrSiGst->pPipeline))) {
827 GstState prevState, currentState;
829 gst_message_parse_state_changed (msg, &prevState, ¤tState, NULL);
830 BTRMGRLOG_INFO (
"From: %s -> To: %s\n",
831 gst_element_state_get_name (prevState), gst_element_state_get_name (currentState));
837 case GST_MESSAGE_ERROR: {
841 gst_message_parse_error (msg, &err, &debug);
842 BTRMGRLOG_DEBUG (
"Debugging info: %s\n", (debug) ? debug :
"none");
845 BTRMGRLOG_ERROR (
"Error: %s\n", err->message);
848 if (pstBtrMgrSiGst) {
849 if (pstBtrMgrSiGst->pLoop) {
850 g_main_loop_quit(pstBtrMgrSiGst->pLoop);
856 case GST_MESSAGE_WARNING:{
860 gst_message_parse_warning (msg, &warn, &debug);
861 BTRMGRLOG_DEBUG (
"Debugging info: %s\n", (debug) ? debug :
"none");
864 BTRMGRLOG_WARN (
"Warning: %s\n", warn->message);