Possible to have appSrc need-data respect framerate

Shaunak Gupte shaunakg at nvidia.com
Mon Sep 18 04:00:01 UTC 2017


Hi Sean,

You need to set the sync property of fakesink to TRUE which is FALSE by default.

-Shaunak
________________________________________
From: gstreamer-devel <gstreamer-devel-bounces at lists.freedesktop.org> on behalf of Sean DuBois <sean at siobud.com>
Sent: Sunday, September 17, 2017 12:57 PM
To: gstreamer-devel at lists.freedesktop.org
Subject: Possible to have appSrc need-data respect framerate

In an attempt to make my code as simple as possible I am trying to use
the appSrc 'need-data' event. Everything works great, however it pulls
as fast as it can (and not the framerate I have set any where) I posted
the example pipeline below. So right now this will fire the need-data
event as much as it can (until CPU usage hits 100%)

I would like to avoid spinning up another thread just to push buffers
onto the appsrc behind a timer. If I do that I have to query the state
of the pipeline and make sure I stop pushing. But if that is the
idiomatic way that is fine, I just want to check if what I want to do is
possible.

----

#include <gst/app/gstappsrc.h>
#include <gst/gst.h>

#define WIDTH 500
#define HEIGHT 500
#define STRING(s) #s

void VideoAppsrcNeedData(GstElement *object, guint arg0, GstElement *pipeline) {
  auto gst_buffer = gst_buffer_new_and_alloc(WIDTH * HEIGHT * 4);
  GST_BUFFER_DURATION(gst_buffer) = gst_util_uint64_scale_int(1, GST_SECOND, 30);

  gst_app_src_push_buffer((GstAppSrc *)object, gst_buffer);
}

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

  auto loop = g_main_loop_new(NULL, FALSE);
  auto pipeline = gst_parse_launch("appsrc name=appsrc do-timestamp=true format=time ! fakesink", nullptr);

  g_signal_connect(gst_bin_get_by_name(GST_BIN(pipeline), "appsrc"), "need-data", G_CALLBACK(VideoAppsrcNeedData),
                   pipeline);

  g_object_set(
      gst_bin_get_by_name(GST_BIN(pipeline), "appsrc"), "caps",
      gst_caps_from_string("video/x-raw,format=BGRA,height=" STRING(HEIGHT) ",width=" STRING(WIDTH) ",framerate=30/1"));

  gst_element_set_state(pipeline, GST_STATE_PLAYING);
  g_main_loop_run(loop);
}

_______________________________________________
gstreamer-devel mailing list
gstreamer-devel at lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel


More information about the gstreamer-devel mailing list