<br><br><div class="gmail_quote">On Wed, Jul 8, 2009 at 11:25 AM, Tiago Katcipis <span dir="ltr">&lt;<a href="mailto:katcipis@inf.ufsc.br">katcipis@inf.ufsc.br</a>&gt;</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;">

Im going to use appsink on a project using gstreamer and started to build a basic example os]f how to use appsink using signals. My problem is that when i simply add the appsink to the pipeline, the pipe simply stops to work.<br>


<br>On the following example im just trying to use the appsink instead the filesink to write the entire stream to a file. If i use the filesink and DONT add the appsink to the pipe, it works fine, if i just add the appsink to the pipe ....it stops working, im not even using the appsink yet, the filesink stops to write data, the result of the test will be an empty file, and no error msg is sent. I dont know what detail im missing on how to use appsink, hope someone can help me. By the way, gst_bin_add returns TRUE when i add the appsink.<br>


<br>the source code of the example:<br><br>#include &lt;gst/gst.h&gt;<br>#include &lt;glib.h&gt;<br>#include &lt;gst/app/gstappsink.h&gt;<br>#include &lt;stdio.h&gt;<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 (&quot;End of stream\n&quot;);<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, &amp;error, &amp;debug);<br>      g_free (debug);<br>


<br>      g_printerr (&quot;Error: %s\n&quot;, error-&gt;message);<br>      g_error_free (error);<br><br>      g_main_loop_quit (loop);<br>      break;<br>    }<br>    default:<br>      g_print(&quot;Msg type[%d], Msg type name[%s]\n&quot;, GST_MESSAGE_TYPE(msg), 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* sink_element)<br>{<br>  if(!gst_element_link(src_element, sink_element))<br>      g_debug(&quot;Error linking %s to %s&quot;, 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(&quot;Error: src_pad is NULL on link_two_pads&quot;);<br>      return;<br>  }<br><br>  if(!sink_pad){<br>


      g_warning(&quot;Error: sink_pad is NULL on link_two_pads&quot;);<br>      return;<br>  }<br><br>  if(gst_pad_link(src_pad, sink_pad) != GST_PAD_LINK_OK)<br>      g_debug(&quot;Error linking pads %s to %s&quot;, gst_pad_get_name(src_pad), 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) != GST_BUFFER_SIZE(buffer)){<br>      g_debug(&quot;Error writing data from appsink to file!!!&quot;);<br>  }else{<br>      g_debug(&quot;Data pulled from appsink and writed to file with success!!&quot;);<br>


  }<br>  <br>}<br><br>// Pipe to test this src: gst-launch audiotestsrc ! audioconvert ! alawenc ! rtppcmapay ! udpsink host=127.0.0.1 port=5000<br>// Equivalent working pipe: gst-launch udpsrc port=5000 caps=application/x-rtp ! gstrtpjitterbuffer ! rtppcmadepay ! alawdec ! 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 &lt; 2){<br>      g_warning(&quot;Usage: %s [port_to_be_listened]&quot;, argv[0]);<br>      return -1;<br>  }<br><br>  udp_port = atoi(argv[1]);<br>


<br>  /* Initialisation */<br>  gst_init (&amp;argc, &amp;argv);<br><br>  udp_caps = gst_caps_from_string(&quot;application/x-rtp&quot;);<br>  if(!udp_caps){<br>      g_warning(&quot;Error alocating the udp caps&quot;);<br>


      return -1;<br>  }<br><br>  loop = g_main_loop_new (NULL, FALSE);<br><br>  /* Create gstreamer elements */<br>  pipeline      = gst_pipeline_new(&quot;rtp-mp3-stream-decoder&quot;);<br>  source        = gst_element_factory_make(&quot;udpsrc&quot;,  &quot;udp-rtp-source&quot;);<br>


  rtp_jitter     = gst_element_factory_make(&quot;gstrtpjitterbuffer&quot;,  &quot;rtp-jitter-buffer&quot;);<br>  rtp_alaw_depay = gst_element_factory_make(&quot;rtppcmadepay&quot;,  &quot;rtp_alaw_depay&quot;);<br>  alaw_decoder   = gst_element_factory_make(&quot;alawdec&quot;,&quot;alaw-decoder&quot;);<br>


  audio_convert  = gst_element_factory_make(&quot;audioconvert&quot;,&quot;audio-convert&quot;);<br>  lame           = gst_element_factory_make(&quot;lame&quot;,&quot;mp3-encoder&quot;);<br>  filesink       = gst_element_factory_make(&quot;filesink&quot;, &quot;file-mp3-output&quot;);<br>


  appsink        = gst_element_factory_make(&quot;appsink&quot;, &quot;sink-buffer&quot;);<br>  <br><br>  if (!pipeline || !source || !rtp_jitter || !appsink ||<br>      !rtp_alaw_depay || !alaw_decoder || !audio_convert || !lame || !filesink) {<br>


      g_printerr (&quot;Elements could not be created. Exiting.\n&quot;);<br>      return -1;<br>  }<br><br>  appsink_file = fopen(&quot;received_audio_appsink.mp3&quot;, &quot;w&quot;);<br>  if(!appsink_file){<br>      g_printerr (&quot;Appsink file could not be created. Exiting.\n&quot;);<br>


      return -1;<br>  }<br><br>  /* Set up the pipeline */<br><br>  /* we set the properties to the source element to receive only rtp packets*/<br>  g_object_set(G_OBJECT (source), &quot;port&quot;, udp_port, NULL);<br>

  g_object_set(G_OBJECT (source), &quot;caps&quot;, udp_caps, NULL);<br>
  /* we set the location of the mp3 generated file */<br>  g_object_set(G_OBJECT (filesink), &quot;location&quot;, &quot;received_audio_filesink.mp3&quot;, NULL);<br><br>  /*<br>    Make appsink emit the &quot;new-preroll&quot; and &quot;new-buffer&quot; signals. This option is by default disabled because <br>


    signal emission is expensive and unneeded when the application 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, audio_convert, lame, filesink, NULL);<br>


<br>  /* When i just addn the appsink this the example stops to work and the 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(&quot;Adcionou appsink com sucesso&quot;);<br>


  }else{<br>      g_debug(&quot;Erro ao Adcionar appsink&quot;);<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);</blockquote><div><br>Appsink (in this case of yours) is meant to *replace* filesink. You don&#39;t seem to link appsink to anything and also you link filesink to lame. So, remove filesink from your pipeline, and use appsink in its place.<br>

 </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br><br>  /* Conecting to the new-buffer signal emited by the appsink */<br>
  g_signal_connect (appsink, &quot;new-buffer&quot;,  G_CALLBACK (on_new_buffer), appsink_file);<br><br>  /* Set the pipeline to &quot;playing&quot; state*/<br>  g_print (&quot;Now listening on port: %d\n&quot;, udp_port);<br>


  gst_element_set_state (pipeline, GST_STATE_PLAYING);<br><br>  /* Iterate */<br>  g_print (&quot;Running...\n&quot;);<br>  g_main_loop_run (loop);<br><br>  /* Out of the main loop, clean up nicely */<br>  g_print (&quot;Returned, stopping listening\n&quot;);<br>


  gst_element_set_state (pipeline, GST_STATE_NULL);<br><br>  g_print (&quot;Deleting pipeline\n&quot;);<br>  gst_object_unref (GST_OBJECT (pipeline));<br>  fclose(appsink_file);<br><br>  return 0;<br>}<br><br clear="all">


<br><br>best regards,<br>Katcipis<br><font color="#888888">-- <br>&quot;it might be a profitable thing to learn Java, but it has no intellectual value whatsoever&quot; Alexander Stepanov<br>
</font><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></blockquote></div><br><br clear="all"><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>