<div dir="ltr"><div>Yeah, I see the line the creates decodebin element actually is commented out.</div><div>You should add it to the pipeline. decodebin decodes mp3 data to uncompressed audio.</div><div>audioresample, and most audiosinks, cannot take compressed data like mp3</div><div><br></div><div>take a look at <a href="https://gstreamer.freedesktop.org/documentation/application-development/highlevel/playback-components.html">https://gstreamer.freedesktop.org/documentation/application-development/highlevel/playback-components.html</a></div><div><br></div><div>Luca</div><div><b><br></b></div></div><div class="gmail_extra"><br><div class="gmail_quote">2018-03-16 14:13 GMT+01:00 Sujith reddy <span dir="ltr"><<a href="mailto:Sujithreddy6192@gmail.com" target="_blank">Sujithreddy6192@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">HI Luca,<br>
<br>
here in above code i didn't use decodebin element.<br>
<br>
........................<br>
<br>
i came to know that when i am giving mp3/m38u it is giving noise..then i<br>
rechecked the code i found out that i need to use decodebin element for<br>
decoding mp3.<br>
<br>
Now i tried with the below code ..<br>
<br>
it is saying *Elements could not be linked.*<br>
<br>
//////////////////////////////<wbr>///////<br>
<span>/*****************<br>
<br>
<br>
gcc llll.c -o playback-tutorial-7 `pkg-config --cflags --libs gstreamer-1.0<br>
gstreamer-audio-1.0 gstreamer-app-1.0`<br>
*******************/<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
#include <gstreamer-1.0/gst/gst.h><br>
#include <gst/audio/audio.h><br>
#include <string.h><br>
#include <stdio.h><br>
<br>
#define CHUNK_SIZE 4096 /* Amount of bytes we are sending in each buffer<br>
*/<br>
#define SAMPLE_RATE 48000 /* Samples per second we are sending */<br>
<br>
/* Structure to contain all our information, so we can pass it to callbacks<br>
*/<br>
typedef struct _CustomData {<br>
GstElement *pipeline, *app_source, *tee, *audio_queue, *audio_convert1,<br>
</span>*audio_resample, *audio_sink,*app_decode,*<wbr>audio_decode;<br>
<div><div class="h5"> GstElement *app_queue, *audio_convert2, *app_sink;<br>
<br>
<br>
guint64 num_samples; /* Number of samples generated so far (for<br>
timestamp generation) */<br>
// gfloat a, b, c, d; /* For waveform generation */<br>
<br>
guint sourceid; /* To control the GSource */<br>
FILE *fp,*fp1;<br>
GMainLoop *main_loop; /* GLib's Main Loop */<br>
} CustomData;<br>
<br>
/* This method is called by the idle GSource in the mainloop, to feed<br>
CHUNK_SIZE bytes into appsrc.<br>
* The ide handler is added to the mainloop when appsrc requests us to start<br>
sending data (need-data signal)<br>
* and is removed when appsrc has enough data (enough-data signal).<br>
*/<br>
static gboolean push_data (CustomData *data) {<br>
GstBuffer *buffer;<br>
GstFlowReturn ret;<br>
int i,r;<br>
GstMapInfo map;<br>
gint num_samples = CHUNK_SIZE/2; /* Because each sample is 16 bits */<br>
//gfloat freq;<br>
<br>
/* Create a new empty buffer */<br>
buffer = gst_buffer_new_and_alloc (CHUNK_SIZE);<br>
<br>
/* Set its timestamp and duration */<br>
GST_BUFFER_TIMESTAMP (buffer) = gst_util_uint64_scale (data->num_samples,<br>
GST_SECOND, SAMPLE_RATE);<br>
GST_BUFFER_DURATION (buffer) = gst_util_uint64_scale (CHUNK_SIZE,<br>
GST_SECOND, SAMPLE_RATE);<br>
<br>
/* Generate some psychodelic waveforms */<br>
gst_buffer_map (buffer, &map, GST_MAP_WRITE);<br>
r=fread(map.data,2,CHUNK_SIZE/<wbr>2,data->fp);<br>
gst_buffer_unmap (buffer, &map);<br>
data->num_samples += num_samples;<br>
<br>
while(r==NULL)<br>
gst_app_src_end_of_stream (data->app_source);<br>
<br>
<br>
<br>
/* Push the buffer into the appsrc */<br>
g_signal_emit_by_name (data->app_source, "push-buffer", buffer, &ret);<br>
// gst_app_src_end_of_stream (data->app_source);<br>
//gst_app_src_push_buffer (data->app_source, buffer);<br>
/* Free the buffer now that we are done with it */<br>
gst_buffer_unref (buffer);<br>
<br>
if (ret != GST_FLOW_OK) {<br>
/* We got some error, stop sending data */<br>
return FALSE;<br>
}<br>
<br>
return TRUE;<br>
}<br>
<br>
/* This signal callback triggers when appsrc needs data. Here, we add an<br>
idle handler<br>
* to the mainloop to start pushing data into the appsrc */<br>
static void start_feed (GstElement *source, guint size, CustomData *data) {<br>
if (data->sourceid == 0) {<br>
g_print ("Start feeding\n");<br>
data->sourceid = g_idle_add ((GSourceFunc) push_data, data);<br>
}<br>
}<br>
<br>
/* This callback triggers when appsrc has enough data and we can stop<br>
sending.<br>
* We remove the idle handler from the mainloop */<br>
static void stop_feed (GstElement *source, CustomData *data) {<br>
if (data->sourceid != 0) {<br>
g_print ("Stop feeding\n");<br>
g_source_remove (data->sourceid);<br>
data->sourceid = 0;<br>
}<br>
}<br>
<br>
/* The appsink has received a buffer */<br>
<br>
static void new_sample (GstElement *sink, CustomData *data) {<br>
<br>
//printf("sujith1111111");<br>
GstSample *sample;<br>
//////////////////////////////<wbr>/////////////////////////<br>
GstBuffer *buffer;<br>
GstMapInfo map;<br>
g_signal_emit_by_name (data ->app_sink, "pull-sample", &sample,NULL);<br>
if (sample)<br>
{<br>
buffer = gst_sample_get_buffer (sample);<br>
<br>
gst_buffer_map (buffer, &map, GST_MAP_READ);<br>
<br>
g_print("\n here size=%d\n",map.size);<br>
fwrite(map.data,1,map.size,<wbr>data->fp1); ///data is written to a file<br>
gst_buffer_unmap (buffer,&map);<br>
gst_sample_unref(sample);<br>
<br>
//////////////////////////////<wbr>///////////////////<br>
}<br>
}<br>
<br>
/* This function is called when an error message is posted on the bus */<br>
static void error_cb (GstBus *bus, GstMessage *msg, CustomData *data) {<br>
GError *err;<br>
gchar *debug_info;<br>
<br>
/* Print error details on the screen */<br>
gst_message_parse_error (msg, &err, &debug_info);<br>
g_printerr ("Error received from element %s: %s\n", GST_OBJECT_NAME<br>
(msg->src), err->message);<br>
g_printerr ("Debugging information: %s\n", debug_info ? debug_info :<br>
"none");<br>
g_clear_error (&err);<br>
g_free (debug_info);<br>
<br>
g_main_loop_quit (data->main_loop);<br>
}<br>
<br>
int main(int argc, char *argv[]) {<br>
CustomData data;<br>
GstPad *tee_audio_pad,*tee_app_pad;<br>
GstPad *queue_audio_pad, *queue_app_pad;<br>
GstAudioInfo info;<br>
GstCaps *audio_caps;<br>
GstBus *bus;<br>
<br>
/* Initialize cumstom data structure */<br>
memset (&data, 0, sizeof (data));<br>
<br>
</div></div>data.fp=fopen("/home/raghava/<wbr>Documents/llll/songs/<wbr>ChoosiChudangane.mp3","rb");<br>
// data.fp= fopen("./Deviceconnected.raw",<wbr>"rb");<br>
<span> data.fp1 = fopen("1.raw","wb");<br>
/* Initialize GStreamer */<br>
gst_init (&argc, &argv);<br>
<br>
/* Create the elements */<br>
data.app_source = gst_element_factory_make ("appsrc", "audio_source");<br>
data.tee = gst_element_factory_make ("tee", "tee");<br>
data.audio_queue = gst_element_factory_make ("queue", "audio_queue");<br>
</span><span> data.app_decode = gst_element_factory_make ("decodebin", "app_decode");<br>
data.audio_convert1 = gst_element_factory_make ("audioconvert",<br>
"audio_convert1");<br>
data.audio_resample = gst_element_factory_make ("audioresample",<br>
"audio_resample");<br>
data.audio_sink = gst_element_factory_make ("autoaudiosink",<br>
"audio_sink");<br>
data.app_queue = gst_element_factory_make ("queue", "app_queue");<br>
</span><span> data.audio_decode = gst_element_factory_make ("decodebin",<br>
"audio_decode");<br>
data.audio_convert2 = gst_element_factory_make ("audioconvert",<br>
"audio_convert2");<br>
data.app_sink = gst_element_factory_make ("appsink", "app_sink");<br>
<br>
<br>
<br>
/* Create the empty pipeline */<br>
data.pipeline = gst_pipeline_new ("test-pipeline");<br>
<br>
if (!data.pipeline || !data.app_source || !data.tee || !data.audio_queue<br>
|| !data.audio_convert1 ||<br>
!data.audio_resample || !data.audio_sink || !data.audio_convert2 ||<br>
</span> !data.app_queue || !data.app_sink ||!data.audio_decode||<br>
!data.app_decode ) //<br>
<span> {<br>
g_printerr ("Not all elements could be created.\n");<br>
return -1;<br>
}<br>
<br>
<br>
/* Configure appsrc */<br>
gst_audio_info_set_format (&info, GST_AUDIO_FORMAT_S16, SAMPLE_RATE, 1,<br>
NULL);<br>
audio_caps = gst_audio_info_to_caps (&info);<br>
g_object_set (data.app_source, "caps", audio_caps, "format",<br>
GST_FORMAT_TIME, NULL);<br>
</span> //g_object_set (data.app_source, "format", GST_FORMAT_TIME, NULL);<br>
<span> g_signal_connect (data.app_source, "need-data", G_CALLBACK (start_feed),<br>
&data);<br>
g_signal_connect (data.app_source, "enough-data", G_CALLBACK (stop_feed),<br>
&data);<br>
<br>
/* Configure appsink */<br>
g_object_set (data.app_sink, "emit-signals", TRUE, "caps", audio_caps,<br>
NULL);<br>
g_signal_connect (data.app_sink, "new-sample", G_CALLBACK (new_sample),<br>
&data);<br>
gst_caps_unref (audio_caps);<br>
// g_free (audio_caps_text);<br>
<br>
/* Link all elements that can be automatically linked because they have<br>
"Always" pads */<br>
gst_bin_add_many (GST_BIN (data.pipeline), data.app_source, data.tee,<br>
data.audio_queue, data.audio_convert1, data.audio_resample,<br>
data.audio_sink, data.app_queue,<br>
</span>data.audio_convert2,data.app_<wbr>sink,data.audio_decode,data.<wbr>app_decode,<br>
<span>NULL);//,data.audio_decode,<wbr>data.app_decode<br>
if (gst_element_link_many (data.app_source, data.tee, NULL) != TRUE ||<br>
</span> gst_element_link_many (data.audio_queue,data.audio_<wbr>decode,<br>
<span>data.audio_convert1, data.audio_resample, data.audio_sink, NULL) != TRUE ||<br>
</span> gst_element_link_many (data.app_queue,data.app_<wbr>decode,<br>
<div><div class="h5">data.audio_convert2,data.app_<wbr>sink, NULL) != TRUE )//,data.app_decode<br>
,data.audio_decode<br>
{<br>
g_printerr ("Elements could not be linked.\n");<br>
gst_object_unref (data.pipeline);<br>
return -1;<br>
}<br>
<br>
/* Manually link the Tee, which has "Request" pads */<br>
tee_audio_pad = gst_element_get_request_pad (data.tee, "src_%u");<br>
g_print ("Obtained request pad %s for audio branch.\n", gst_pad_get_name<br>
(tee_audio_pad));<br>
queue_audio_pad = gst_element_get_static_pad (data.audio_queue, "sink");<br>
tee_app_pad = gst_element_get_request_pad (data.tee, "src_%u");<br>
g_print ("Obtained request pad %s for app branch.\n", gst_pad_get_name<br>
(tee_app_pad));<br>
queue_app_pad = gst_element_get_static_pad (data.app_queue, "sink");<br>
if (gst_pad_link (tee_audio_pad, queue_audio_pad) != GST_PAD_LINK_OK ||<br>
gst_pad_link (tee_app_pad, queue_app_pad) != GST_PAD_LINK_OK) {<br>
g_printerr ("Tee could not be linked\n");<br>
gst_object_unref (data.pipeline);<br>
return -1;<br>
}<br>
gst_object_unref (queue_audio_pad);<br>
gst_object_unref (queue_app_pad);<br>
<br>
/* Instruct the bus to emit signals for each received message, and connect<br>
to the interesting signals */<br>
bus = gst_element_get_bus (data.pipeline);<br>
gst_bus_add_signal_watch (bus);<br>
g_signal_connect (G_OBJECT (bus), "message::error", (GCallback)error_cb,<br>
&data);<br>
gst_object_unref (bus);<br>
<br>
/* Start playing the pipeline */<br>
gst_element_set_state (data.pipeline, GST_STATE_PLAYING);<br>
</div></div>/* sleep(6);<br>
gst_element_set_state (data.pipeline, GST_STATE_NULL);<br>
g_object_set (data.playbin, "uri", ", NULL);*/<br>
<span> /* Create a GLib Main Loop and set it to run */<br>
</span> int nstreams;<br>
g_object_get (data.pipeline, "n-audio", &nstreams, NULL);<br>
printf("nstreams =%d",nstreams);<br>
<span class="im HOEnZb"> data.main_loop = g_main_loop_new (NULL, FALSE);<br>
g_main_loop_run (data.main_loop);<br>
<br>
/* Release the request pads from the Tee, and unref them */<br>
gst_element_release_request_<wbr>pad (data.tee, tee_audio_pad);<br>
gst_element_release_request_<wbr>pad (data.tee, tee_app_pad);<br>
gst_object_unref (tee_audio_pad);<br>
gst_object_unref (tee_app_pad);<br>
<br>
/* Free resources */<br>
gst_element_set_state (data.pipeline, GST_STATE_NULL);<br>
gst_object_unref (data.pipeline);<br>
return 0;<br>
}<br>
<br>
<br>
Thanks<br>
</span><span class="HOEnZb"><font color="#888888">sujith<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
<br>
--<br>
Sent from: <a href="http://gstreamer-devel.966125.n4.nabble.com/" target="_blank" rel="noreferrer">http://gstreamer-devel.966125.<wbr>n4.nabble.com/</a><br>
______________________________<wbr>_________________<br>
gstreamer-devel mailing list<br>
<a href="mailto:gstreamer-devel@lists.freedesktop.org">gstreamer-devel@lists.<wbr>freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel" target="_blank" rel="noreferrer">https://lists.freedesktop.org/<wbr>mailman/listinfo/gstreamer-<wbr>devel</a><br>
</div></div></blockquote></div><br></div>