gst-launch pipeline vs its exact C analog

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

gst-launch pipeline vs its exact C analog

Sergei Vorobyov
Hi!

Your help will be greatly appreciated.

I am struggling to understand and wondering why

gst-launch filesrc location=file.avi ! decodebin2 ! ffmpegcolorspace !
autovideosink

works just fine as expected, whereas its straightforward C-programmed analog

  src = gst_element_factory_make ("filesrc", "source");
  g_object_set (src, "location", "file.avi", NULL);

  dec = gst_element_factory_make ("decodebin2", "decoder"); // won't
link to the next
  conv = gst_element_factory_make ("ffmpegcolorspace", "ffmpeg-colorspace");
  sink = gst_element_factory_make ("autovideosink", "sink");

  gst_bin_add_many (GST_BIN (pipeline),
                    src,
                    dec,
                    conv,
                    sink, NULL);

  if (!gst_element_link (src, dec)) {
    g_print("cannot link src and dec\n");
    return -1;
  }

  if (!gst_element_link (dec, conv)) { // FAILS here
    g_print("cannot link dec and conv\n");
    return -1;
  }

reports "cannot link dec and conv", i.e., gst_element_link (dec, conv) FAILS.

If I take away return -1, allowing it to proceed, it results in:

Error from element avidemux0: Internal data stream error.
Debug: gstavidemux.c(5204): gst_avi_demux_loop ():
/GstPipeline:length/GstDecodeBin2:decoder/GstAviDemux:avidemux0:
streaming stopped, reason not-linked

caught in the callback for the loop/pipeline


    if (msg_type & GST_MESSAGE_ERROR) {
      g_print ("ERROR message\n");
      gchar *debug;
      GError *err;

      gst_message_parse_error (msg, &err, &debug);
      g_free (debug);

      g_print ("Error from element %s: %s\n",
               GST_OBJECT_NAME (msg->src),
               err->message);
      g_print ("Debug: %s\n", (debug) ? debug : "none");
      g_error_free (err);
      g_free (debug);

      g_main_loop_quit (loop);
    }
_______________________________________________
gstreamer-devel mailing list
[hidden email]
http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: gst-launch pipeline vs its exact C analog

Martijn Grendelman
On 28-03-12 11:13, Sergei Vorobyov wrote:

> Hi!
>
> Your help will be greatly appreciated.
>
> I am struggling to understand and wondering why
>
> gst-launch filesrc location=file.avi ! decodebin2 ! ffmpegcolorspace !
> autovideosink
>
> works just fine as expected, whereas its straightforward C-programmed analog
>
>   src = gst_element_factory_make ("filesrc", "source");
>   g_object_set (src, "location", "file.avi", NULL);
>
>   dec = gst_element_factory_make ("decodebin2", "decoder"); // won't
> link to the next
>   conv = gst_element_factory_make ("ffmpegcolorspace", "ffmpeg-colorspace");
>   sink = gst_element_factory_make ("autovideosink", "sink");
>
>   gst_bin_add_many (GST_BIN (pipeline),
>    src,
>    dec,
>    conv,
>    sink, NULL);
>
>   if (!gst_element_link (src, dec)) {
>     g_print("cannot link src and dec\n");
>     return -1;
>   }
>
>   if (!gst_element_link (dec, conv)) { // FAILS here
>     g_print("cannot link dec and conv\n");
>     return -1;
>   }
>
> reports "cannot link dec and conv", i.e., gst_element_link (dec, conv) FAILS.
>
> If I take away return -1, allowing it to proceed, it results in:
>
> Error from element avidemux0: Internal data stream error.
> Debug: gstavidemux.c(5204): gst_avi_demux_loop ():
> /GstPipeline:length/GstDecodeBin2:decoder/GstAviDemux:avidemux0:
> streaming stopped, reason not-linked

Decodebin2's source pads are dynamic, meaning they will only be added when
appropriate. I don't know when exactly that is, but it is at least after
the demuxer/decoder have determined what kind of media types are present
in the input.

You have to catch its "pad-added" signals and link the pads from there.

> caught in the callback for the loop/pipeline
>
>
>     if (msg_type & GST_MESSAGE_ERROR) {
>       g_print ("ERROR message\n");
>       gchar *debug;
>       GError *err;
>
>       gst_message_parse_error (msg, &err, &debug);
>       g_free (debug);
>
>       g_print ("Error from element %s: %s\n",
>       GST_OBJECT_NAME (msg->src),
>       err->message);
>       g_print ("Debug: %s\n", (debug) ? debug : "none");
>       g_error_free (err);
>       g_free (debug);
>
>       g_main_loop_quit (loop);
>     }

Best regards,
Martijn Grendelman
_______________________________________________
gstreamer-devel mailing list
[hidden email]
http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: gst-launch pipeline vs its exact C analog

Stefan Sauer
In reply to this post by Sergei Vorobyov
On 03/28/2012 11:13 AM, Sergei Vorobyov wrote:

> Hi!
>
> Your help will be greatly appreciated.
>
> I am struggling to understand and wondering why
>
> gst-launch filesrc location=file.avi ! decodebin2 ! ffmpegcolorspace !
> autovideosink
>
> works just fine as expected, whereas its straightforward C-programmed analog
>
>   src = gst_element_factory_make ("filesrc", "source");
>   g_object_set (src, "location", "file.avi", NULL);
>
>   dec = gst_element_factory_make ("decodebin2", "decoder"); // won't
> link to the next
>   conv = gst_element_factory_make ("ffmpegcolorspace", "ffmpeg-colorspace");
>   sink = gst_element_factory_make ("autovideosink", "sink");
>
>   gst_bin_add_many (GST_BIN (pipeline),
>    src,
>    dec,
>    conv,
>    sink, NULL);
>
>   if (!gst_element_link (src, dec)) {
>     g_print("cannot link src and dec\n");
>     return -1;
>   }
>
>   if (!gst_element_link (dec, conv)) { // FAILS here
>     g_print("cannot link dec and conv\n");
>     return -1;
>   }
>
> reports "cannot link dec and conv", i.e., gst_element_link (dec, conv) FAILS.
FAQ. Please read up on sometimes pads and look at the docs for the
GstElement pad-added signal.

Stefan

> If I take away return -1, allowing it to proceed, it results in:
>
> Error from element avidemux0: Internal data stream error.
> Debug: gstavidemux.c(5204): gst_avi_demux_loop ():
> /GstPipeline:length/GstDecodeBin2:decoder/GstAviDemux:avidemux0:
> streaming stopped, reason not-linked
>
> caught in the callback for the loop/pipeline
>
>
>     if (msg_type & GST_MESSAGE_ERROR) {
>       g_print ("ERROR message\n");
>       gchar *debug;
>       GError *err;
>
>       gst_message_parse_error (msg, &err, &debug);
>       g_free (debug);
>
>       g_print ("Error from element %s: %s\n",
>       GST_OBJECT_NAME (msg->src),
>       err->message);
>       g_print ("Debug: %s\n", (debug) ? debug : "none");
>       g_error_free (err);
>       g_free (debug);
>
>       g_main_loop_quit (loop);
>     }
> _______________________________________________
> gstreamer-devel mailing list
> [hidden email]
> http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel

_______________________________________________
gstreamer-devel mailing list
[hidden email]
http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: gst-launch pipeline vs its exact C analog

Sergei Vorobyov
Right, instead of

gst_element_link (dec, conv)

which does not work because dec ("decodebin2") has dynamic source
pads, I should have linked with

g_signal_connect (dec, "pad-added", G_CALLBACK (on_pad_added), conv);

where

void on_pad_added (GstElement *src_element,
                   GstPad *pad, // dynamic source pad
                   gpointer target_element)
{
  GstElement *target = (GstElement*) target_element;
  g_print ("*** Linking a dynamic source pad of %s to the static sink
pad of %s...\n",
           GST_OBJECT_NAME (src_element), GST_OBJECT_NAME (target));
  GstPad *sinkpad = gst_element_get_static_pad (target, "sink");
  gst_pad_link (pad, sinkpad);
  gst_object_unref (sinkpad);
}

and this works as expected.

Many thanks!

On Wed, Mar 28, 2012 at 12:50 PM, Stefan Sauer <[hidden email]> wrote:

> On 03/28/2012 11:13 AM, Sergei Vorobyov wrote:
>> Hi!
>>
>> Your help will be greatly appreciated.
>>
>> I am struggling to understand and wondering why
>>
>> gst-launch filesrc location=file.avi ! decodebin2 ! ffmpegcolorspace !
>> autovideosink
>>
>> works just fine as expected, whereas its straightforward C-programmed analog
>>
>>   src = gst_element_factory_make ("filesrc", "source");
>>   g_object_set (src, "location", "file.avi", NULL);
>>
>>   dec = gst_element_factory_make ("decodebin2", "decoder"); // won't
>> link to the next
>>   conv = gst_element_factory_make ("ffmpegcolorspace", "ffmpeg-colorspace");
>>   sink = gst_element_factory_make ("autovideosink", "sink");
>>
>>   gst_bin_add_many (GST_BIN (pipeline),
>>                   src,
>>                   dec,
>>                   conv,
>>                   sink, NULL);
>>
>>   if (!gst_element_link (src, dec)) {
>>     g_print("cannot link src and dec\n");
>>     return -1;
>>   }
>>
>>   if (!gst_element_link (dec, conv)) { // FAILS here
>>     g_print("cannot link dec and conv\n");
>>     return -1;
>>   }
>>
>> reports "cannot link dec and conv", i.e., gst_element_link (dec, conv) FAILS.
> FAQ. Please read up on sometimes pads and look at the docs for the
> GstElement pad-added signal.
>
> Stefan
>
>> If I take away return -1, allowing it to proceed, it results in:
>>
>> Error from element avidemux0: Internal data stream error.
>> Debug: gstavidemux.c(5204): gst_avi_demux_loop ():
>> /GstPipeline:length/GstDecodeBin2:decoder/GstAviDemux:avidemux0:
>> streaming stopped, reason not-linked
>>
>> caught in the callback for the loop/pipeline
>>
>>
>>     if (msg_type & GST_MESSAGE_ERROR) {
>>       g_print ("ERROR message\n");
>>       gchar *debug;
>>       GError *err;
>>
>>       gst_message_parse_error (msg, &err, &debug);
>>       g_free (debug);
>>
>>       g_print ("Error from element %s: %s\n",
>>              GST_OBJECT_NAME (msg->src),
>>              err->message);
>>       g_print ("Debug: %s\n", (debug) ? debug : "none");
>>       g_error_free (err);
>>       g_free (debug);
>>
>>       g_main_loop_quit (loop);
>>     }
>> _______________________________________________
>> gstreamer-devel mailing list
>> [hidden email]
>> http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
>
> _______________________________________________
> gstreamer-devel mailing list
> [hidden email]
> http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
_______________________________________________
gstreamer-devel mailing list
[hidden email]
http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel