Thanks for the help Andoni, tomorow im going to test this.<br><br>best regards,<br>Katcipis<br><br><div class="gmail_quote">On Wed, Jul 8, 2009 at 7:51 PM, Andoni Morales <span dir="ltr"><<a href="mailto:ylatuya@gmail.com">ylatuya@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">2009/7/9 Tiago Katcipis <<a href="mailto:katcipis@inf.ufsc.br">katcipis@inf.ufsc.br</a>>:<br>
<div class="im">> Puting appsink on the place of filesink dont works too. My problem is that<br>
> even filesink stops to work when i just add the appsink to the bin. It seens<br>
</div>If you need to have an element in the pipeline that it's not linked<br>
b/c you may want to link it dinamically you need to lock it's state<br>
usin GST_STATE_LOCK(appsink), this way state changes won't affect to<br>
this element.<br>
Andoni<br>
<div><div></div><div class="h5">> that only adding the appsink to the bin makes the pipe stop working.<br>
><br>
> best regards,<br>
> Katcipis<br>
><br>
> On Wed, Jul 8, 2009 at 7:32 PM, thiagoss <<a href="mailto:thiagossantos@gmail.com">thiagossantos@gmail.com</a>> wrote:<br>
>><br>
>><br>
>> On Wed, Jul 8, 2009 at 11:25 AM, Tiago Katcipis <<a href="mailto:katcipis@inf.ufsc.br">katcipis@inf.ufsc.br</a>><br>
>> wrote:<br>
>>><br>
>>> Im going to use appsink on a project using gstreamer and started to build<br>
>>> a basic example os]f how to use appsink using signals. My problem is that<br>
>>> when i simply add the appsink to the pipeline, the pipe simply stops to<br>
>>> work.<br>
>>><br>
>>> On the following example im just trying to use the appsink instead the<br>
>>> filesink to write the entire stream to a file. If i use the filesink and<br>
>>> DONT add the appsink to the pipe, it works fine, if i just add the appsink<br>
>>> to the pipe ....it stops working, im not even using the appsink yet, the<br>
>>> filesink stops to write data, the result of the test will be an empty file,<br>
>>> and no error msg is sent. I dont know what detail im missing on how to use<br>
>>> appsink, hope someone can help me. By the way, gst_bin_add returns TRUE when<br>
>>> i add the appsink.<br>
>>><br>
>>> the source code of the example:<br>
>>><br>
>>> #include <gst/gst.h><br>
>>> #include <glib.h><br>
>>> #include <gst/app/gstappsink.h><br>
>>> #include <stdio.h><br>
>>><br>
>>> static gboolean<br>
>>> bus_call (GstBus *bus,<br>
>>> GstMessage *msg,<br>
>>> gpointer data)<br>
>>> {<br>
>>> GMainLoop *loop = (GMainLoop *) data;<br>
>>><br>
>>> switch (GST_MESSAGE_TYPE (msg)) {<br>
>>><br>
>>> case GST_MESSAGE_EOS:<br>
>>> g_print ("End of stream\n");<br>
>>> g_main_loop_quit (loop);<br>
>>> break;<br>
>>><br>
>>> case GST_MESSAGE_ERROR: {<br>
>>> gchar *debug;<br>
>>> GError *error;<br>
>>><br>
>>> gst_message_parse_error (msg, &error, &debug);<br>
>>> g_free (debug);<br>
>>><br>
>>> g_printerr ("Error: %s\n", error->message);<br>
>>> g_error_free (error);<br>
>>><br>
>>> g_main_loop_quit (loop);<br>
>>> break;<br>
>>> }<br>
>>> default:<br>
>>> g_print("Msg type[%d], Msg type name[%s]\n", GST_MESSAGE_TYPE(msg),<br>
>>> GST_MESSAGE_TYPE_NAME(msg));<br>
>>> break;<br>
>>> }<br>
>>><br>
>>> return TRUE;<br>
>>> }<br>
>>><br>
>>><br>
>>> static void link_two_elements(GstElement* src_element, GstElement*<br>
>>> sink_element)<br>
>>> {<br>
>>> if(!gst_element_link(src_element, sink_element))<br>
>>> g_debug("Error linking %s to %s",<br>
>>> gst_element_get_name(src_element), gst_element_get_name(sink_element));<br>
>>><br>
>>> }<br>
>>><br>
>>> static void link_two_pads(GstPad* src_pad, GstPad* sink_pad)<br>
>>> {<br>
>>> if(!src_pad){<br>
>>> g_warning("Error: src_pad is NULL on link_two_pads");<br>
>>> return;<br>
>>> }<br>
>>><br>
>>> if(!sink_pad){<br>
>>> g_warning("Error: sink_pad is NULL on link_two_pads");<br>
>>> return;<br>
>>> }<br>
>>><br>
>>> if(gst_pad_link(src_pad, sink_pad) != GST_PAD_LINK_OK)<br>
>>> g_debug("Error linking pads %s to %s", gst_pad_get_name(src_pad),<br>
>>> gst_pad_get_name(sink_pad));<br>
>>><br>
>>> }<br>
>>><br>
>>> static void on_new_buffer (GstElement* object,<br>
>>> gpointer user_data)<br>
>>> {<br>
>>> FILE* file = (FILE*) user_data;<br>
>>> GstAppSink* app_sink = (GstAppSink*) object;<br>
>>> GstBuffer * buffer = gst_app_sink_pull_buffer(app_sink);<br>
>>><br>
>>> if(fwrite (GST_BUFFER_DATA(buffer), 1 , GST_BUFFER_SIZE(buffer) , file)<br>
>>> != GST_BUFFER_SIZE(buffer)){<br>
>>> g_debug("Error writing data from appsink to file!!!");<br>
>>> }else{<br>
>>> g_debug("Data pulled from appsink and writed to file with<br>
>>> success!!");<br>
>>> }<br>
>>><br>
>>> }<br>
>>><br>
>>> // Pipe to test this src: gst-launch audiotestsrc ! audioconvert !<br>
>>> alawenc ! rtppcmapay ! udpsink host=127.0.0.1 port=5000<br>
>>> // Equivalent working pipe: gst-launch udpsrc port=5000<br>
>>> caps=application/x-rtp ! gstrtpjitterbuffer ! rtppcmadepay ! alawdec !<br>
>>> audioconvert ! lame ! appsink<br>
>>> int<br>
>>> main (int argc,<br>
>>> char *argv[])<br>
>>> {<br>
>>> GMainLoop *loop;<br>
>>><br>
>>> GstElement *pipeline, *source, *rtp_jitter, *rtp_alaw_depay,<br>
>>> *alaw_decoder, *audio_convert, *lame, *filesink, *appsink;<br>
>>> GstBus* bus;<br>
>>> GstCaps* udp_caps;<br>
>>> FILE* appsink_file;<br>
>>> int udp_port;<br>
>>><br>
>>> if(argc < 2){<br>
>>> g_warning("Usage: %s [port_to_be_listened]", argv[0]);<br>
>>> return -1;<br>
>>> }<br>
>>><br>
>>> udp_port = atoi(argv[1]);<br>
>>><br>
>>> /* Initialisation */<br>
>>> gst_init (&argc, &argv);<br>
>>><br>
>>> udp_caps = gst_caps_from_string("application/x-rtp");<br>
>>> if(!udp_caps){<br>
>>> g_warning("Error alocating the udp caps");<br>
>>> return -1;<br>
>>> }<br>
>>><br>
>>> loop = g_main_loop_new (NULL, FALSE);<br>
>>><br>
>>> /* Create gstreamer elements */<br>
>>> pipeline = gst_pipeline_new("rtp-mp3-stream-decoder");<br>
>>> source = gst_element_factory_make("udpsrc", "udp-rtp-source");<br>
>>> rtp_jitter = gst_element_factory_make("gstrtpjitterbuffer",<br>
>>> "rtp-jitter-buffer");<br>
>>> rtp_alaw_depay = gst_element_factory_make("rtppcmadepay",<br>
>>> "rtp_alaw_depay");<br>
>>> alaw_decoder = gst_element_factory_make("alawdec","alaw-decoder");<br>
>>> audio_convert =<br>
>>> gst_element_factory_make("audioconvert","audio-convert");<br>
>>> lame = gst_element_factory_make("lame","mp3-encoder");<br>
>>> filesink = gst_element_factory_make("filesink",<br>
>>> "file-mp3-output");<br>
>>> appsink = gst_element_factory_make("appsink", "sink-buffer");<br>
>>><br>
>>><br>
>>> if (!pipeline || !source || !rtp_jitter || !appsink ||<br>
>>> !rtp_alaw_depay || !alaw_decoder || !audio_convert || !lame ||<br>
>>> !filesink) {<br>
>>> g_printerr ("Elements could not be created. Exiting.\n");<br>
>>> return -1;<br>
>>> }<br>
>>><br>
>>> appsink_file = fopen("received_audio_appsink.mp3", "w");<br>
>>> if(!appsink_file){<br>
>>> g_printerr ("Appsink file could not be created. Exiting.\n");<br>
>>> return -1;<br>
>>> }<br>
>>><br>
>>> /* Set up the pipeline */<br>
>>><br>
>>> /* we set the properties to the source element to receive only rtp<br>
>>> packets*/<br>
>>> g_object_set(G_OBJECT (source), "port", udp_port, NULL);<br>
>>> g_object_set(G_OBJECT (source), "caps", udp_caps, NULL);<br>
>>> /* we set the location of the mp3 generated file */<br>
>>> g_object_set(G_OBJECT (filesink), "location",<br>
>>> "received_audio_filesink.mp3", NULL);<br>
>>><br>
>>> /*<br>
>>> Make appsink emit the "new-preroll" and "new-buffer" signals. This<br>
>>> option is by default disabled because<br>
>>> signal emission is expensive and unneeded when the application<br>
>>> prefers to operate in pull mode.<br>
>>> */<br>
>>> gst_app_sink_set_emit_signals ((GstAppSink*) appsink, TRUE);<br>
>>><br>
>>> /* we add a message handler */<br>
>>> bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));<br>
>>> gst_bus_add_watch (bus, bus_call, loop);<br>
>>> gst_object_unref (bus);<br>
>>><br>
>>> /* we add all elements into the pipeline */<br>
>>> gst_bin_add_many (GST_BIN (pipeline),<br>
>>> source, rtp_jitter, rtp_alaw_depay, alaw_decoder,<br>
>>> audio_convert, lame, filesink, NULL);<br>
>>><br>
>>> /* When i just addn the appsink this the example stops to work and the<br>
>>> file will be empty (and im not using the appsink, just the filesink)<br>
>>> if(gst_bin_add(GST_BIN (pipeline), appsink)){<br>
>>> g_debug("Adcionou appsink com sucesso");<br>
>>> }else{<br>
>>> g_debug("Erro ao Adcionar appsink");<br>
>>> }*/<br>
>>><br>
>>> /* we link all the elements together */<br>
>>> link_two_elements(source, rtp_jitter);<br>
>>> link_two_elements(rtp_jitter, rtp_alaw_depay);<br>
>>> link_two_elements(rtp_alaw_depay, alaw_decoder);<br>
>>> link_two_elements(alaw_decoder, audio_convert);<br>
>>> link_two_elements(audio_convert, lame);<br>
>>> link_two_elements(lame, filesink);<br>
>><br>
>> Appsink (in this case of yours) is meant to *replace* filesink. You don't<br>
>> seem to link appsink to anything and also you link filesink to lame. So,<br>
>> remove filesink from your pipeline, and use appsink in its place.<br>
>><br>
>>><br>
>>> /* Conecting to the new-buffer signal emited by the appsink */<br>
>>> g_signal_connect (appsink, "new-buffer", G_CALLBACK (on_new_buffer),<br>
>>> appsink_file);<br>
>>><br>
>>> /* Set the pipeline to "playing" state*/<br>
>>> g_print ("Now listening on port: %d\n", udp_port);<br>
>>> gst_element_set_state (pipeline, GST_STATE_PLAYING);<br>
>>><br>
>>> /* Iterate */<br>
>>> g_print ("Running...\n");<br>
>>> g_main_loop_run (loop);<br>
>>><br>
>>> /* Out of the main loop, clean up nicely */<br>
>>> g_print ("Returned, stopping listening\n");<br>
>>> gst_element_set_state (pipeline, GST_STATE_NULL);<br>
>>><br>
>>> g_print ("Deleting pipeline\n");<br>
>>> gst_object_unref (GST_OBJECT (pipeline));<br>
>>> fclose(appsink_file);<br>
>>><br>
>>> return 0;<br>
>>> }<br>
>>><br>
>>><br>
>>><br>
>>> best regards,<br>
>>> Katcipis<br>
>>> --<br>
>>> "it might be a profitable thing to learn Java, but it has no intellectual<br>
>>> value whatsoever" Alexander Stepanov<br>
>>><br>
>>><br>
>>> ------------------------------------------------------------------------------<br>
>>> Enter the BlackBerry Developer Challenge<br>
>>> This is your chance to win up to $100,000 in prizes! For a limited time,<br>
>>> vendors submitting new applications to BlackBerry App World(TM) will have<br>
>>> the opportunity to enter the BlackBerry Developer Challenge. See full<br>
>>> prize<br>
>>> details at: <a href="http://p.sf.net/sfu/Challenge" target="_blank">http://p.sf.net/sfu/Challenge</a><br>
>>> _______________________________________________<br>
>>> gstreamer-devel mailing list<br>
>>> <a href="mailto:gstreamer-devel@lists.sourceforge.net">gstreamer-devel@lists.sourceforge.net</a><br>
>>> <a href="https://lists.sourceforge.net/lists/listinfo/gstreamer-devel" target="_blank">https://lists.sourceforge.net/lists/listinfo/gstreamer-devel</a><br>
>>><br>
>><br>
>><br>
>><br>
>> --<br>
>> Thiago Sousa Santos<br>
>><br>
>> Embedded Systems and Pervasive Computing Lab (Embedded)<br>
>> Center of Electrical Engineering and Informatics (CEEI)<br>
>> Federal University of Campina Grande (UFCG)<br>
>><br>
>><br>
>> ------------------------------------------------------------------------------<br>
>> Enter the BlackBerry Developer Challenge<br>
>> This is your chance to win up to $100,000 in prizes! For a limited time,<br>
>> vendors submitting new applications to BlackBerry App World(TM) will have<br>
>> the opportunity to enter the BlackBerry Developer Challenge. See full<br>
>> prize<br>
>> details at: <a href="http://p.sf.net/sfu/Challenge" target="_blank">http://p.sf.net/sfu/Challenge</a><br>
>> _______________________________________________<br>
>> gstreamer-devel mailing list<br>
>> <a href="mailto:gstreamer-devel@lists.sourceforge.net">gstreamer-devel@lists.sourceforge.net</a><br>
>> <a href="https://lists.sourceforge.net/lists/listinfo/gstreamer-devel" target="_blank">https://lists.sourceforge.net/lists/listinfo/gstreamer-devel</a><br>
>><br>
><br>
><br>
><br>
> --<br>
> "it might be a profitable thing to learn Java, but it has no intellectual<br>
> value whatsoever" Alexander Stepanov<br>
><br>
> ------------------------------------------------------------------------------<br>
> Enter the BlackBerry Developer Challenge<br>
> This is your chance to win up to $100,000 in prizes! For a limited time,<br>
> vendors submitting new applications to BlackBerry App World(TM) will have<br>
> the opportunity to enter the BlackBerry Developer Challenge. See full prize<br>
> details at: <a href="http://p.sf.net/sfu/Challenge" target="_blank">http://p.sf.net/sfu/Challenge</a><br>
> _______________________________________________<br>
> gstreamer-devel mailing list<br>
> <a href="mailto:gstreamer-devel@lists.sourceforge.net">gstreamer-devel@lists.sourceforge.net</a><br>
> <a href="https://lists.sourceforge.net/lists/listinfo/gstreamer-devel" target="_blank">https://lists.sourceforge.net/lists/listinfo/gstreamer-devel</a><br>
><br>
><br>
<br>
<br>
<br>
--<br>
</div></div>Andoni Morales Alastruey<br>
<br>
LongoMatch:The Digital Coach<br>
<a href="http://www.longomatch.ylatuya.es" target="_blank">http://www.longomatch.ylatuya.es</a><br>
<div><div></div><div class="h5"><br>
------------------------------------------------------------------------------<br>
Enter the BlackBerry Developer Challenge<br>
This is your chance to win up to $100,000 in prizes! For a limited time,<br>
vendors submitting new applications to BlackBerry App World(TM) will have<br>
the opportunity to enter the BlackBerry Developer Challenge. See full prize<br>
details at: <a href="http://p.sf.net/sfu/Challenge" target="_blank">http://p.sf.net/sfu/Challenge</a><br>
_______________________________________________<br>
gstreamer-devel mailing list<br>
<a href="mailto:gstreamer-devel@lists.sourceforge.net">gstreamer-devel@lists.sourceforge.net</a><br>
<a href="https://lists.sourceforge.net/lists/listinfo/gstreamer-devel" target="_blank">https://lists.sourceforge.net/lists/listinfo/gstreamer-devel</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>"it might be a profitable thing to learn Java, but it has no intellectual value whatsoever" Alexander Stepanov<br>