Restart gst pipeline

Viewed 14

For some reason when I try to restart working gst pipeline, that reads and decodes mp4 or mkv file, I got "not-linked" failure at second pipeline state change to PLAYING. Sequence of actions looks like:

  1. create pipeline (filesrc ! decodebin ! fakesink)
  2. change state to PLAYING
  3. wait for state change (gst_element_get_state)
  4. stop pipeline (NULL)
  5. restart pipeline with changing state to PLAYING again
  6. wait for state change (gst_element_get_state)

So, at point 6 I have next error: streaming stopped, reason not-linked (-1) - qtdemux or matroskademux - doesn't matter, each time I got not-linked error. But why? This pipeline is working, it was already working. Why it fails?

Min Ex:

#include "gst/gstclock.h"
#include "gst/gstelement.h"
#include "gst/gstparse.h"
#include <cstdlib>
#include <gst/gst.h>
#include <stdio.h>
#include <string>

using namespace std::string_literals;

int main(int argc, char *argv[]) {
  gst_init(&argc, &argv);

  if (argc != 2) {
    fprintf(stderr, "set filename as first argument\n");
    return EXIT_FAILURE;
  }

  // clang-format off
  std::string pipeline_str = "filesrc location="s + argv[1] + " ! "
                             "decodebin ! "
                             "fakesink"
    ;
  // clang-format on
  GError *gerr = nullptr;
  GstElement *pipeline = gst_parse_launch(pipeline_str.c_str(), &gerr);
  if (pipeline == nullptr) {
    fprintf(stderr, "can not parse pipeline: %s\n", gerr->message);
    return EXIT_FAILURE;
  }

  // start pipeline
  fprintf(stderr, "start pipeline\n");
  GstStateChangeReturn result;
  GstState state;
  if (gst_element_set_state(pipeline, GST_STATE_PLAYING) ==
      GST_STATE_CHANGE_FAILURE) {
    fprintf(stderr, "set: can not start pipeline\n");
    return EXIT_FAILURE;
  }
  if (gst_element_get_state(pipeline, &state, nullptr, GST_CLOCK_TIME_NONE) ==
      GST_STATE_CHANGE_FAILURE) {
    fprintf(stderr, "get: can not start pipeline\n");
    return EXIT_FAILURE;
  }
  fprintf(stderr, "current pipeline state: %d\n", state);

  // stop pipeline
  fprintf(stderr, "stop pipeline\n");
  if (gst_element_set_state(pipeline, GST_STATE_NULL) ==
      GST_STATE_CHANGE_FAILURE) {
    fprintf(stderr, "set: can not stop pipeline\n");
    return EXIT_FAILURE;
  }
  if (gst_element_get_state(pipeline, &state, nullptr, GST_CLOCK_TIME_NONE) ==
      GST_STATE_CHANGE_FAILURE) {
    fprintf(stderr, "get:can not stop pipeline\n");
    return EXIT_FAILURE;
  }
  fprintf(stderr, "current pipeline state: %d\n", state);

  // restart pipeline
  fprintf(stderr, "restart pipeline\n");
  if (gst_element_set_state(pipeline, GST_STATE_PLAYING) ==
      GST_STATE_CHANGE_FAILURE) {
    fprintf(stderr, "set: can not restart pipeline\n");
    return EXIT_FAILURE;
  }
  if (gst_element_get_state(pipeline, &state, nullptr, GST_CLOCK_TIME_NONE) ==
      GST_STATE_CHANGE_FAILURE) {
    fprintf(stderr, "get: can not restart pipeline\n");
    return EXIT_FAILURE;
  }
  fprintf(stderr, "current pipeline state: %d\n", state);

  return EXIT_SUCCESS;
}

Program output with GST_DEBUG=2:

start pipeline
0:00:00.010198214 [335m22522[00m 0x55e7aa2e8b60 [33;01mWARN   [00m [00m             basesrc gstbasesrc.c:3583:gst_base_src_start_complete:<filesrc0>[00m pad not activated yet
0:00:00.013832890 [335m22522[00m 0x7f4b6007ba80 [33;01mWARN   [00m [00m             qtdemux qtdemux_types.c:233:qtdemux_type_get:[00m unknown QuickTime node type pasp
0:00:00.013857586 [335m22522[00m 0x7f4b6007ba80 [33;01mWARN   [00m [00m             qtdemux qtdemux.c:3031:qtdemux_parse_trex:<qtdemux0>[00m failed to find fragment defaults for stream 1
0:00:00.016950917 [335m22522[00m 0x7f4b6007ba80 [33;01mWARN   [00m [00m               vaapi gstvaapiutils.c:77:gst_vaapi_warning:[00m va_getDriverName() failed with unknown libva error,driver_name=(null)
0:00:00.065998280 [335m22522[00m 0x7f4b6007ba80 [33;01mWARN   [00m [00m               vaapi gstvaapiutils.c:77:gst_vaapi_warning:[00m va_getDriverName() failed with unknown libva error,driver_name=(null)
current pipeline state: 4
stop pipeline
current pipeline state: 1
restart pipeline
0:00:00.085806957 [335m22522[00m 0x55e7aa2e8b60 [33;01mWARN   [00m [00m             basesrc gstbasesrc.c:3583:gst_base_src_start_complete:<filesrc0>[00m pad not activated yet
0:00:00.086340274 [335m22522[00m 0x7f4b58007d40 [33;01mWARN   [00m [00m             qtdemux qtdemux_types.c:233:qtdemux_type_get:[00m unknown QuickTime node type pasp
0:00:00.086362061 [335m22522[00m 0x7f4b58007d40 [33;01mWARN   [00m [00m             qtdemux qtdemux.c:3031:qtdemux_parse_trex:<qtdemux1>[00m failed to find fragment defaults for stream 1
0:00:00.103089409 [335m22522[00m 0x7f4b58007d40 [33;01mWARN   [00m [00m               vaapi gstvaapiutils.c:77:gst_vaapi_warning:[00m va_getDriverName() failed with unknown libva error,driver_name=(null)
0:00:00.119275330 [335m22522[00m 0x7f4b58007d40 [33;01mWARN   [00m [00m             qtdemux qtdemux.c:6073:gst_qtdemux_loop:<qtdemux1>[00m error: Internal data stream error.
0:00:00.119296247 [335m22522[00m 0x7f4b58007d40 [33;01mWARN   [00m [00m             qtdemux qtdemux.c:6073:gst_qtdemux_loop:<qtdemux1>[00m error: streaming stopped, reason not-linked (-1)
get: can not restart pipeline
0:00:00.119853982 [335m22522[00m 0x55e7aa2e8280 [33;01mWARN   [00m [00m               queue gstqueue.c:988:gst_queue_handle_sink_event:<vaapi-queue>[00m error: Internal data stream error.
0:00:00.119865713 [335m22522[00m 0x55e7aa2e8280 [33;01mWARN   [00m [00m               queue gstqueue.c:988:gst_queue_handle_sink_event:<vaapi-queue>[00m error: streaming stopped, reason not-linked (-1)
0 Answers
Related