Created
April 28, 2021 12:20
-
-
Save justinjoy/54dd44c70e267e47385edf1d2ac745e2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "config.h" | |
#include <gst/gst.h> | |
#include <glib-unix.h> | |
static GstPadProbeReturn | |
_link_klv_cb (GstPad * pad, GstPadProbeInfo * info, gpointer user_data) | |
{ | |
GstElement *pipeline = user_data; | |
GstElement *sinkbin = NULL; | |
GstElement *first = NULL; | |
GstPad *qpad = NULL; | |
GstPad *gpad = NULL; | |
sinkbin = | |
gst_parse_launch | |
("queue name=q ! rtpklvdepay ! identity dump=true ! fakesink sync=false", | |
NULL); | |
gst_bin_add (GST_BIN (pipeline), sinkbin); | |
first = gst_bin_get_by_name (sinkbin, "q"); | |
qpad = gst_element_get_static_pad (first, "sink"); | |
gpad = gst_ghost_pad_new (NULL, qpad); | |
gst_pad_link (pad, gpad); | |
gst_pad_set_active (gpad, TRUE); | |
gst_element_sync_state_with_parent (sinkbin); | |
return GST_PAD_PROBE_REMOVE; | |
} | |
static GstPadProbeReturn | |
_link_cb (GstPad * pad, GstPadProbeInfo * info, gpointer user_data) | |
{ | |
GstElement *pipeline = user_data; | |
GstElement *sinkbin = NULL; | |
GstElement *first = NULL; | |
GstPad *qpad = NULL; | |
GstPad *gpad = NULL; | |
g_print ("pad link probe : %s\n", GST_PAD_NAME (pad)); | |
sinkbin = | |
gst_parse_launch | |
("queue name=q ! rtpvp8depay ! decodebin ! autovideosink async=true", | |
NULL); | |
gst_bin_add (GST_BIN (pipeline), sinkbin); | |
first = gst_bin_get_by_name (sinkbin, "q"); | |
qpad = gst_element_get_static_pad (first, "sink"); | |
gpad = gst_ghost_pad_new (NULL, qpad); | |
gst_pad_link (pad, gpad); | |
gst_pad_set_active (gpad, TRUE); | |
gst_element_sync_state_with_parent (sinkbin); | |
return GST_PAD_PROBE_REMOVE; | |
} | |
static void | |
pad_added (GstElement * self, GstPad * new_pad, gpointer user_data) | |
{ | |
GstElement *pipeline = user_data; | |
g_print ("new pad: %s\n", GST_PAD_NAME (new_pad)); | |
} | |
static void | |
new_payload_type (GstElement * element, guint pt, GstPad * pad, | |
gpointer user_data) | |
{ | |
GstElement *pipeline = user_data; | |
g_print ("new payload type pt: %d\n", pt); | |
if (pt == 96) { | |
gst_pad_add_probe (pad, GST_PAD_PROBE_TYPE_IDLE, _link_cb, pipeline, NULL); | |
} else if (pt == 99) { | |
gst_pad_add_probe (pad, GST_PAD_PROBE_TYPE_IDLE, | |
_link_klv_cb, pipeline, NULL); | |
} | |
} | |
static GstCaps * | |
request_pt_map (GstElement * demux, guint pt, gpointer user_data) | |
{ | |
GstCaps *caps = NULL; | |
g_print ("request pt map: %d\n", pt); | |
if (pt == 96) { | |
caps = | |
gst_caps_from_string | |
("application/x-rtp, encoding-name=(string)VP8, media=(string)video, clock-rate=(int)90000"); | |
} else if (pt == 99) { | |
caps = | |
gst_caps_from_string | |
("application/x-rtp, encoding-name=(string)SMPTE336M, media=(string)application, clock-rate=(int)90000"); | |
} | |
return caps; | |
} | |
int | |
main (int argc, char *argv[]) | |
{ | |
g_autoptr (GMainLoop) loop = NULL; | |
g_autoptr (GstElement) pipeline = NULL; | |
g_autoptr (GstElement) rtpdemux = NULL; | |
gst_init (&argc, &argv); | |
loop = g_main_loop_new (NULL, FALSE); | |
pipeline = | |
gst_parse_launch | |
("srtsrc uri=\"srt://127.0.0.1:9999?mode=caller\" ! queue ! rtpptdemux name=rtpdemux ", | |
NULL); | |
rtpdemux = gst_bin_get_by_name (GST_BIN (pipeline), "rtpdemux"); | |
g_signal_connect (rtpdemux, "new-payload-type", new_payload_type, pipeline); | |
g_signal_connect (rtpdemux, "request-pt-map", request_pt_map, NULL); | |
g_signal_connect (rtpdemux, "pad-added", pad_added, pipeline); | |
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