Gstreamer : mastroskamux error : not linked

3k views Asked by At

I tried to play a video encoded in h264 and muxed with matroskamux, but I can't achieve it. I'm on embedded platform, an iMX6.

My pipeline works with gst-lauch:

gst-launch-1.0 filesrc location=video.mkv ! matroskademux ! h264parse ! imxvpudec ! imxipuvideosink

I created it in C, but it don't work. I removed error handling, i use a structure rep containing all elements:

rep->pipeline = gst_pipeline_new("pipeline");
rep->src = gst_element_factory_make("filesrc","source0");
rep->demux = gst_element_factory_make("matroskademux","demux0");
rep->queue = gst_element_factory_make("queue2","queue0");
rep->parser = gst_element_factory_make("h264parse","parser0");  
rep->decoder = gst_element_factory_make("imxvpudec","dec0");
rep->sink = gst_element_factory_make("imxipuvideosink","sink0");
gst_bin_add_many (GST_BIN(rep->pipeline), rep->src, rep->demux, rep->queue, rep->parser, rep->decoder,rep->sink, NULL);
g_object_set(rep->src, "location", "video.mkv", NULL);
g_object_set(rep->sink, "use-vsync", TRUE, NULL);
gst_element_link_many(rep->src, rep->demux, rep->queue, rep->parser, rep->decoder, rep->sink, NULL);
g_print("start pipeline\n");
gst_element_set_state (rep->pipeline, GST_STATE_PLAYING);
g_main_loop_run (loop);

The video does not display and the application is stuck. With GST_DEBUG=4 I get a lot of debug, but in the last lines :

0:00:00.168590667   577    0xe24c0 WARN           matroskademux matroska-demux.c:4500:gst_matroska_demux_loop:<demux0> error: stream stopped, reason not-linked
0:00:00.168777333   577    0xe24c0 INFO        GST_ERROR_SYSTEM gstelement.c:1835:gst_element_message_full:<demux0> posting message: GStreamer encountered a general stream error.
0:00:00.169084667   577    0xe24c0 INFO        GST_ERROR_SYSTEM gstelement.c:1858:gst_element_message_full:<demux0> posted error message: GStreamer encountered a general stream error.
0:00:00.169268000   577    0xe24c0 INFO                    task gsttask.c:300:gst_task_func:<demux0:sink> Task going to paused

I tried to force the linking of demuxer's pads, because it has a "sometimes" source pad.

I don't know how to proceed to make it works. Thanks for the help.

EDIT : Log file here. It's a linking problem, I don't know how to resolve it.

1

There are 1 answers

0
peper0 On BEST ANSWER

The problem is, that demux has no source pads in the NULL state when you are tryink to link it. Demux adds output pads in the PAUSED state since at this moment it starts processing the input file. Therefore you cannot simply link it at the beginning and then start.

You must connect to the "on-pad-added" event of the demuxer with something like this:

g_signal_connect (rep->demux, "pad-added", G_CALLBACK (on_pad_added), rep->queue);

And write proper on_pad_added function, like this:

void
on_pad_added (GstElement *element,
              GstPad     *pad,
              gpointer    data)
{
  GstPad *sinkpad;
  GstElement *queue = (GstElement *) data;

  g_print ("Dynamic pad created, linking demuxer/decoder\n");

  sinkpad = gst_element_get_static_pad (queue, "sink");

  gst_pad_link (pad, sinkpad);

  gst_object_unref (sinkpad);
}

I didn't check if my code compiles but I'm sure you catch an idea.

You may be also interested in this example.

BTW, gst-launch uses some smart machinery that supports such delayed linking. In code you must do it manually.