Appsrc webrtcsink example
Matthew Larsen
larsen.matt1 at gmail.com
Fri Sep 1 17:44:38 UTC 2023
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;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/gstreamer-devel/attachments/20230901/1caff113/attachment-0001.htm>
More information about the gstreamer-devel
mailing list