Skip to content

Instantly share code, notes, and snippets.

@justinjoy
Created April 28, 2021 12:19
Show Gist options
  • Save justinjoy/d4e91a6e420411a24f219932e3e0a9fc to your computer and use it in GitHub Desktop.
Save justinjoy/d4e91a6e420411a24f219932e3e0a9fc to your computer and use it in GitHub Desktop.
#include "config.h"
#include <gst/gst.h>
#include <glib-unix.h>
#include <gst/app/gstappsrc.h>
static const guint8 klv_data[] = {
0x06, 0x0e, 0x2b, 0x34, 0x02, 0x0b, 0x01, 0x01,
0x0e, 0x01, 0x03, 0x01, 0x01, 0x00, 0x00, 0x00,
0x2a, 0x02, 0x08, 0x00, 0x05, 0x61, 0x0b, 0x43,
0x05, 0xc4, 0x83, 0x0c, 0x0e, 0x47, 0x65, 0x6f,
0x64, 0x65, 0x74, 0x69, 0x63, 0x20, 0x57, 0x47,
0x53, 0x38, 0x34, 0x0d, 0x04, 0x49, 0x2c, 0x4f,
0x42, 0x0e, 0x04, 0xfe, 0x26, 0x9a, 0xc3, 0x0f,
0x02, 0x0b, 0xb5
};
static const gsize klv_size = G_N_ELEMENTS (klv_data);
gint i = 0;
static gboolean
_push (gpointer user_data)
{
GstAppSrc *appsrc = user_data;
GstSegment segment;
GstCaps *caps;
GstSample *sample = NULL;
GstBuffer *buffer =
gst_buffer_new_wrapped_full (GST_MEMORY_FLAG_READONLY, klv_data, klv_size,
0, klv_size, NULL, NULL);
gst_segment_init (&segment, GST_FORMAT_TIME);
gst_segment_set_running_time (&segment, GST_FORMAT_TIME, GST_SECOND);
GST_BUFFER_PTS (buffer) = GST_SECOND * i++;
sample =
gst_sample_new (buffer, gst_caps_from_string ("meta/x-klv,parsed=true"),
&segment, NULL);
if (gst_app_src_push_sample (appsrc, sample) != GST_FLOW_OK) {
g_print ("failed to push \n");
} else {
g_print ("push one \n");
}
return G_SOURCE_CONTINUE;
}
int
main (int argc, char *argv[])
{
g_autoptr (GMainLoop) loop = NULL;
g_autoptr (GstElement) pipeline = NULL;
g_autoptr (GstElement) appsrc = NULL;
gst_init (&argc, &argv);
loop = g_main_loop_new (NULL, FALSE);
pipeline = gst_parse_launch ("rtpmux name=rtpmux ! "
" queue ! srtsink uri=\"srt://:9999?mode=listener\" wait-for-connection=false "
" videotestsrc ! video/x-raw,framerate=30/1 ! vp8enc keyframe-max-dist=15 ! rtpvp8pay mtu=1316 ! application/x-rtp, payload=96, rate=9000 ! rtpmux.sink_0 "
" appsrc format=time is-live=true do-timestamp=true name=appsrc caps=\"meta/x-klv,parsed=true\" ! "
" rtpklvpay mtu=1316 ! application/x-rtp, payload=99, rate=9000 ! rtpmux.sink_1 ",
NULL);
appsrc = gst_bin_get_by_name (pipeline, "appsrc");
g_timeout_add (1000, _push, appsrc);
gst_element_set_state (pipeline, GST_STATE_PLAYING);
g_main_loop_run (loop);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment