<div dir="ltr"><div>Sorry, there is an error:</div><div><br></div><div>decodebin automatically selects the output uncompressed format. So you just need not set the caps property of appsrc.</div><div>So in the original code just change</div><div><br></div><div><span style="text-align:left;color:rgb(80,0,80);text-transform:none;text-indent:0px;letter-spacing:normal;font-family:arial,sans-serif;font-size:12.8px;font-style:normal;font-variant:normal;font-weight:400;text-decoration:none;word-spacing:0px;display:inline;white-space:normal;float:none;background-color:transparent">g_object_set (data.app_source, "caps", audio_caps, "format", GST_FORMAT_TIME, NULL);</span></div><div><span style="text-align:left;color:rgb(80,0,80);text-transform:none;text-indent:0px;letter-spacing:normal;font-family:arial,sans-serif;font-size:12.8px;font-style:normal;font-variant:normal;font-weight:400;text-decoration:none;word-spacing:0px;display:inline;white-space:normal;float:none;background-color:transparent"><br></span></div><div><span style="text-align:left;color:rgb(80,0,80);text-transform:none;text-indent:0px;letter-spacing:normal;font-family:arial,sans-serif;font-size:12.8px;font-style:normal;font-variant:normal;font-weight:400;text-decoration:none;word-spacing:0px;display:inline;white-space:normal;float:none;background-color:transparent">to</span></div><div><span style="text-align:left;color:rgb(80,0,80);text-transform:none;text-indent:0px;letter-spacing:normal;font-family:arial,sans-serif;font-size:12.8px;font-style:normal;font-variant:normal;font-weight:400;text-decoration:none;word-spacing:0px;display:inline;white-space:normal;float:none;background-color:transparent"><br></span></div><div><span style="text-align:left;color:rgb(80,0,80);text-transform:none;text-indent:0px;letter-spacing:normal;font-family:arial,sans-serif;font-size:12.8px;font-variant:normal;word-spacing:0px;display:inline;white-space:normal;float:none;background-color:transparent"><span style="font:400 13.33px arial,sans-serif;text-align:left;color:rgb(34,34,34);text-transform:none;text-indent:0px;letter-spacing:normal;text-decoration:none;word-spacing:0px;display:inline;white-space:normal;font-size-adjust:none;font-stretch:normal;float:none;background-color:transparent">g_object_set (data.app_source, <span style="font:400 13.33px arial,sans-serif;text-align:left;color:rgb(34,34,34);text-transform:none;text-indent:0px;letter-spacing:normal;text-decoration:none;word-spacing:0px;display:inline;white-space:normal;font-size-adjust:none;font-stretch:normal;float:none;background-color:transparent"> "format", GST_FORMAT_TIME, NULL);</span></span></span></div><div><span style="text-align:left;color:rgb(80,0,80);text-transform:none;text-indent:0px;letter-spacing:normal;font-family:arial,sans-serif;font-size:12.8px;font-variant:normal;word-spacing:0px;display:inline;white-space:normal;float:none;background-color:transparent"><span style="font:400 13.33px arial,sans-serif;text-align:left;color:rgb(34,34,34);text-transform:none;text-indent:0px;letter-spacing:normal;text-decoration:none;word-spacing:0px;display:inline;white-space:normal;font-size-adjust:none;font-stretch:normal;float:none;background-color:transparent"><span style="font:400 13.33px arial,sans-serif;text-align:left;color:rgb(34,34,34);text-transform:none;text-indent:0px;letter-spacing:normal;text-decoration:none;word-spacing:0px;display:inline;white-space:normal;font-size-adjust:none;font-stretch:normal;float:none;background-color:transparent"><br></span></span></span></div><div><span style="text-align:left;color:rgb(80,0,80);text-transform:none;text-indent:0px;letter-spacing:normal;font-family:arial,sans-serif;font-size:12.8px;font-variant:normal;word-spacing:0px;display:inline;white-space:normal;float:none;background-color:transparent"><span style="font:400 13.33px arial,sans-serif;text-align:left;color:rgb(34,34,34);text-transform:none;text-indent:0px;letter-spacing:normal;text-decoration:none;word-spacing:0px;display:inline;white-space:normal;font-size-adjust:none;font-stretch:normal;float:none;background-color:transparent"><span style="font:400 13.33px arial,sans-serif;text-align:left;color:rgb(34,34,34);text-transform:none;text-indent:0px;letter-spacing:normal;text-decoration:none;word-spacing:0px;display:inline;white-space:normal;font-size-adjust:none;font-stretch:normal;float:none;background-color:transparent">Luca</span></span><b></b></span></div></div><div class="gmail_extra"><br><div class="gmail_quote">2018-03-16 12:41 GMT+01:00 Luca Bacci <span dir="ltr"><<a href="mailto:luca.bacci982@gmail.com" target="_blank">luca.bacci982@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>in main, audio_caps is set to GST_AUDIO_FORMAT_S16. then you assign it to the "caps" property of the appsrc element, I think that's wrong because appsrc sends compressed (MP3) data to the decodebin, not raw PCM data.</div><div>I think audio_caps should instead be set to the "sink-caps" property of decodebin.</div><div><br></div><div>So try changing the line</div><span><div> g_object_set (data.app_source, "caps", audio_caps, "format", GST_FORMAT_TIME, NULL);<br></div></span><div>to</div><div> <span style="font:400 13.33px arial,sans-serif;text-align:left;color:rgb(34,34,34);text-transform:none;text-indent:0px;letter-spacing:normal;text-decoration:none;word-spacing:0px;display:inline;white-space:normal;font-size-adjust:none;font-stretch:normal;float:none;background-color:transparent">g_object_set (data.app_source, <span style="font:400 13.33px arial,sans-serif;text-align:left;color:rgb(34,34,34);text-transform:none;text-indent:0px;letter-spacing:normal;text-decoration:none;word-spacing:0px;display:inline;white-space:normal;font-size-adjust:none;font-stretch:normal;float:none;background-color:transparent"> "format", GST_FORMAT_TIME, NULL);</span></span></div><div><span style="font:400 13.33px arial,sans-serif;text-align:left;color:rgb(34,34,34);text-transform:none;text-indent:0px;letter-spacing:normal;text-decoration:none;word-spacing:0px;display:inline;white-space:normal;font-size-adjust:none;font-stretch:normal;float:none;background-color:transparent"><span style="font:400 13.33px arial,sans-serif;text-align:left;color:rgb(34,34,34);text-transform:none;text-indent:0px;letter-spacing:normal;text-decoration:none;word-spacing:0px;display:inline;white-space:normal;font-size-adjust:none;font-stretch:normal;float:none;background-color:transparent"> <span style="font:400 13.33px arial,sans-serif;text-align:left;color:rgb(34,34,34);text-transform:none;text-indent:0px;letter-spacing:normal;text-decoration:none;word-spacing:0px;display:inline;white-space:normal;font-size-adjust:none;font-stretch:normal;float:none;background-color:transparent">g_object_set (data.app_decode, <span style="font:400 13.33px arial,sans-serif;text-align:left;color:rgb(34,34,34);text-transform:none;text-indent:0px;letter-spacing:normal;text-decoration:none;word-spacing:0px;display:inline;white-space:normal;font-size-adjust:none;font-stretch:normal;float:none;background-color:transparent"> "sink-caps", <span style="font:400 13.33px arial,sans-serif;text-align:left;color:rgb(34,34,34);text-transform:none;text-indent:0px;letter-spacing:normal;text-decoration:none;word-spacing:0px;display:inline;white-space:normal;font-size-adjust:none;font-stretch:normal;float:none;background-color:transparent">audio_caps</span>, NULL);</span></span></span></span></div><div><b></b><i></i><u></u><sub></sub><sup></sup><strike></strike><b></b><i></i><u></u><sub></sub><sup></sup><strike></strike><b></b><i></i><u></u><sub></sub><sup></sup><strike></strike><b></b><i></i><u></u><sub></sub><sup></sup><strike><br></strike></div><div>Luca</div><div><br></div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">2018-03-16 7:39 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 All,<br>
<br>
Here i wanted to know how to inject a source mp3/m3u8 file to pipeline<br>
appsrc.<br>
<br>
<br>
my code is working for raw data i.e wav(PCM) file as injecting source.<br>
for mp3/m3u8 it is giving noise .<br>
<br>
<br>
Here is mycode can anyone help on this to play mp3/m3u8 by injecting data to<br>
appsrc.<br>
<br>
/*****************<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>
#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>
*audio_resample, *audio_sink;//*app_decode,*aud<wbr>io_decode;<br>
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_<wbr>SIZE/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,dat<wbr>a->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>
//data.fp=fopen("/songs/Choosi<wbr>Chudangane.mp3","rb");<br>
data.fp= fopen("./Deviceconnected.raw",<wbr>"rb");<br>
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>
//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>
//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>
!data.app_queue || !data.app_sink ) //||!data.audio_decode||<br>
!data.app_decode<br>
{<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>
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, data.audio_convert2,data.app_s<wbr>ink,<br>
NULL);//,data.audio_decode,dat<wbr>a.app_decode<br>
if (gst_element_link_many (data.app_source, data.tee, NULL) != TRUE ||<br>
gst_element_link_many (data.audio_queue, data.audio_convert1,<br>
data.audio_resample, data.audio_sink, NULL) != TRUE ||<br>
gst_element_link_many (data.app_queue,<br>
data.audio_convert2,data.app_s<wbr>ink, 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>
<br>
/* Create a GLib Main Loop and set it to run */<br>
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_pa<wbr>d (data.tee, tee_audio_pad);<br>
gst_element_release_request_pa<wbr>d (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>
Thanks<br>
Sujith<br>
<br>
<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" target="_blank">gstreamer-devel@lists.freedesk<wbr>top.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-dev<wbr>el</a><br>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>