Appsrc webrtcsink example

Matthew Larsen via gstreamer-devel <[email protected]>
Newsgroups gmane.comp.video.gstreamer.devel
Message-ID <CAD7ObFqhN8XZMs=52O=Hp_ejc7cLg1Pt-5hUP2Yggkm0zBTKtg@mail.gmail.com>
I am new to gstreamer and I am trying to evaluate it for a project that
streams video to web browsers.

I can run the video test src example using gst-launch and that works just
fine. What I am having some trouble with is modifying the example to send
raw video frames via appsrc. The modified example runs with playbin and I
can see my test video. When the sink is webrtcsink, it runs without
complaining, but the signaling server is never contacted based on the logs
I see. Is there some configuration I am missing?

Source

#include <gst/gst.h>

static GMainLoop *loop;
#define WIDTH 640
#define HEIGHT 480

static void
cb_need_data (GstElement *appsrc,
          guint       unused_size,
          gpointer    user_data)
{
  static gboolean white = FALSE;
  GstBuffer *buffer;
  GstFlowReturn ret;
  GstMapInfo map;
  static int sample = 0;
  g_print("sample\n");
  buffer = gst_buffer_new_and_alloc (WIDTH * HEIGHT * 3);
  gst_buffer_map (buffer, &map, GST_MAP_WRITE);

  guchar *raw = (guchar *) map.data;
  int i = 0;
  guchar value = sample % 255;
  for( i = 0; i < WIDTH * HEIGHT * 3; i++) {
    raw[i] = value;
  }

  g_signal_emit_by_name (appsrc, "push-buffer", buffer, &ret);

  if (ret != GST_FLOW_OK) {
    /* something wrong, stop pushing */
    g_main_loop_quit (loop);
  }

  gst_buffer_unmap (buffer, &map);
  sample++;
}

gint
main (gint argc, gchar *argv[])
{
  GstElement *pipeline, *appsrc, *conv, *videosink;

  /* init GStreamer */
  gst_init (&argc, &argv);
  loop = g_main_loop_new (NULL, FALSE);

  /* setup pipeline */
  pipeline = gst_pipeline_new ("pipeline");
  appsrc = gst_element_factory_make ("appsrc", "source");
  conv = gst_element_factory_make ("videoconvert", "conv");
  videosink = gst_element_factory_make ("webrtcsink", "videosink");
  GstStructure *meta = gst_structure_from_string("meta,name=gst-stream",
NULL);
  g_object_set(videosink, "meta", meta, NULL);

  /* setup */
  g_object_set (G_OBJECT (appsrc), "caps",
        gst_caps_new_simple ("video/x-raw",
                     "format", G_TYPE_STRING, "RGB",
                     "width", G_TYPE_INT, WIDTH,
                     "height", G_TYPE_INT, HEIGHT,
                     "framerate", GST_TYPE_FRACTION, 1, 1,
                     NULL), NULL);

  gst_bin_add_many (GST_BIN (pipeline), appsrc, conv, videosink, NULL);
  gst_element_link_many (appsrc, conv, videosink, NULL);
  /* setup appsrc */
  g_object_set (G_OBJECT (appsrc),
        "stream-type", 0,
        "is-live", TRUE,
        "format", GST_FORMAT_TIME, NULL);
  g_signal_connect (appsrc, "need-data", G_CALLBACK (cb_need_data), NULL);

  /* play */
  gst_element_set_state (pipeline, GST_STATE_PLAYING);
  g_main_loop_run (loop);

  /* clean up */
  gst_element_set_state (pipeline, GST_STATE_NULL);
  gst_object_unref (GST_OBJECT (pipeline));
  g_main_loop_unref (loop);

  return 0;
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.