Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to do filesrc loop with gst-interpipe? #138

Open
pinjiang opened this issue Oct 14, 2022 · 1 comment
Open

How to do filesrc loop with gst-interpipe? #138

pinjiang opened this issue Oct 14, 2022 · 1 comment

Comments

@pinjiang
Copy link

pinjiang commented Oct 14, 2022

I use SEEK to loop the filesrc with success.
But I use interpipe to have two pipeline branches after interpipe, it no longer works.
I use seek in the pipeline before interpipe when EOS event, but it doesn't work anymore. The play pipeline get stuck.
How to solve it?

#include <stdio.h>
#include <gst/gst.h>

gchar *base_stream = "/home/j00412711/git/pion_benchmark/server/videos/FaceTestVideo.mp4";
gchar *stream = NULL;

static gboolean gstreamer_send_bus_call(GstBus *bus, GstMessage *msg, gpointer data) {
  GstElement *pipeline = GST_ELEMENT(data);

  switch (GST_MESSAGE_TYPE(msg)) {
  case GST_MESSAGE_EOS:
    g_print("EOS");
    if (!gst_element_seek (pipeline, 1.0, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_KEY_UNIT | GST_SEEK_FLAG_SKIP,
             GST_SEEK_TYPE_SET, 0,
             GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE)) {
        g_print ("EOS restart failed\n");
        exit(1);
    }
    break;

  case GST_MESSAGE_ERROR: {
    gchar *debug;
    GError *error;

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

    g_printerr("GStreamer Error: %s\n", error->message);
    g_error_free(error);
    exit(1);
  }
  default:
    break;
  }

  return TRUE;
}

typedef struct
{
    GstPipeline *sink1;
    GstPipeline *src;
    GstElement *intersrc;
} gst_element;

int main(int argc, char *argv[])
{
    GstPipeline *src;
    GstPipeline *sink1;
    GstPipeline *sink2;

    GError *error = NULL;
    GMainLoop *loop;
    gst_init(&argc, &argv);

    gchar *str1 = (gchar *)"filesrc location=";
    gchar *str2 = (gchar *)" name=vtsrc1 ! decodebin name=demux ! queue ! interpipesink name=intersink sync=false async=false";
    stream = g_strconcat(str1, base_stream, str2, NULL);

    src = GST_PIPELINE(gst_parse_launch(stream, &error));
    // vtsrc1 = gst_bin_get_by_name(GST_BIN(sink1), "vtsrc1");

    sink1 =
        GST_PIPELINE(gst_parse_launch("interpipesrc name=intersrc1 listen-to=intersink is-live=true format=time ! "
                                      "autovideosink name=asink1",
                                      &error));
    //intersrc1 = gst_bin_get_by_name(GST_BIN(sink1), "intersrc1");

    sink2 =
        GST_PIPELINE(gst_parse_launch("interpipesrc name=intersrc2 listen-to=intersink is-live=true format=time ! "
                                      "autovideosink name=asink2",
                                      &error));
    //intersrc2 = gst_bin_get_by_name(GST_BIN(sink2), "intersrc2");

    GstBus *bus = gst_pipeline_get_bus(GST_PIPELINE(src));
    gst_bus_add_watch(bus, gstreamer_send_bus_call, src);
    gst_object_unref(bus);

    gst_element_set_state(GST_ELEMENT(src), GST_STATE_PLAYING);
    gst_element_set_state(GST_ELEMENT(sink1), GST_STATE_PLAYING);
    gst_element_set_state(GST_ELEMENT(sink2), GST_STATE_PLAYING);

    loop = g_main_loop_new(NULL, TRUE);

    g_main_loop_run(loop);
    g_main_loop_unref(loop);

    gst_element_set_state(GST_ELEMENT(src), GST_STATE_NULL);
    gst_element_set_state(GST_ELEMENT(sink1), GST_STATE_NULL);
    gst_element_set_state(GST_ELEMENT(sink2), GST_STATE_NULL);

    g_object_unref(src);
    g_object_unref(sink1);
    g_object_unref(sink2);

    return TRUE;

@clogwog
Copy link

clogwog commented Oct 15, 2022

can you run this with
GST_DEBUG=3 ./yourapplication

when i do this i see the following after the EOS printout:

EOS0:00:58.801434302   460   0x5591f21b50 ERROR         v4l2bufferpool gstv4l2bufferpool.c:747:gst_v4l2_buffer_pool_alloc_buffer:<nvv4l2decoder0:pool:src> failed to allocate buffer
0:00:58.801523159   460   0x5591f21b50 WARN              bufferpool gstbufferpool.c:310:do_alloc_buffer:<nvv4l2decoder0:pool:src> alloc function failed
0:00:58.802511059   460   0x7f78008940 ERROR         v4l2bufferpool gstv4l2bufferpool.c:747:gst_v4l2_buffer_pool_alloc_buffer:<nvv4l2decoder0:pool:src> failed to allocate buffer
0:00:58.802552258   460   0x7f78008940 WARN              bufferpool gstbufferpool.c:310:do_alloc_buffer:<nvv4l2decoder0:pool:src> alloc function failed

so it looks like something with the autovideosink not being able to handle the restart ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants