RTP h264 stream

Big Gaz earthwormgaz at gmail.com
Sun Mar 16 10:29:54 PDT 2014


Hi,

I'm trying to save some video to disk. I can do it with the command
line, but my C code isn't working.

gst-launch-1.0 -e rtspsrc
location="rtsp://admin:12345@192.168.1.201:554//Streaming/Channels/1" !
rtph264depay ! h264parse ! matroskamux ! filesink location=foo1.mkv

That works fine. Can anyone help with the C code?

#include <iostream>

#include <gst/gst.h>

static void cb_new_rtspsrc_pad
(
 GstElement * element,
 GstPad     * pad,
 gpointer    data
 )
{
	gchar *name;

	name = gst_pad_get_name(pad);
	g_print("A new pad %s was created\n", name);

	// here, you would setup a new pad link for the newly created pad
	// sooo, now find that rtph264depay is needed and link them?
	GstCaps * p_caps = gst_pad_get_pad_template_caps (pad);

	gchar * description = gst_caps_to_string(p_caps);
	std::cout << p_caps << ", " << description << std::endl;
	g_free(description);

	GstElement * p_rtph264depay = GST_ELEMENT(data);

	// try to link the pads then ...
	if(gst_element_link_pads(element, name, p_rtph264depay, "sink") ==
false)
	{
		std::cout << "Failed to link elements 3" << std::endl;
	}

	g_free(name);
}

static void cb_new_matroskamux_pad
(
 GstElement * element,
 GstPad     * pad,
 gpointer    data
 )
{
	gchar *name;

	name = gst_pad_get_name(pad);
	g_print("A new pad %s was created\n", name);
	
	GstCaps * p_caps = gst_pad_get_pad_template_caps (pad);

	gchar * description = gst_caps_to_string(p_caps);
	std::cout << p_caps << ", " << description << std::endl;
	g_free(description);

	GstElement * p_h264parse = GST_ELEMENT(data);

	// try to link the pads then ...
	if(gst_element_link_pads(p_h264parse, "src", element, name) == false)
	{
		std::cout << "Failed to link elements 4" << std::endl;
	}

	g_free(name);
}

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

	gst_debug_set_active(true);
	gst_debug_set_threshold_for_name ("*", GST_LEVEL_INFO );

	/*
	 * gst-launch-1.0 -e rtspsrc location=rtsp://... ! rtph264depay !
h264parse ! matroskamux ! filesink location=foo.mkv   might be a good
start
	 * gst-launch-1.0 -e rtspsrc
location="rtsp://admin:12345@192.168.1.201:554//Streaming/Channels/1" !
rtph264depay ! h264parse ! matroskamux ! filesink location=foo1.mkv
	 <__tim> then you translate that into C code :)
<earthw0rm> Hmm, I see
<earthw0rm> So each part of that pipeline has a C equivalent?
<__tim> either use gst_parse_launch() or create the elements one by one
(if the latter: note that rtspsrc has sometimes pads, see "pad-added"
signal,
 and matroskamux has request pads; parse_launch() handles these things
for you)
*/

	GstElement *pipeline = gst_pipeline_new("my_pipeline");

	// create source
	GstElement * rtspsrc = gst_element_factory_make("rtspsrc", "rtspsrc");
	g_object_set(G_OBJECT(rtspsrc), "location",
"rtsp://192.168.1.201:554//Streaming/Channels/1", NULL);
	g_object_set(G_OBJECT(rtspsrc), "user-id", "admin", NULL);
	g_object_set(G_OBJECT(rtspsrc), "user-pw", "12345", NULL);

	// create other pipeline elements
	GstElement * p_rtph264depay = gst_element_factory_make("rtph264depay",
"rtph264depay");
	GstElement * p_h264parse = gst_element_factory_make("h264parse",
"h264parse");
	GstElement * p_matroskamux = gst_element_factory_make("matroskamux",
"matroskamux");
	GstElement * p_filesink = gst_element_factory_make("filesink",
"filesink");

	g_object_set(G_OBJECT(p_filesink), "location", "foo.mkv", NULL);

	// listen for newly created pads
	g_signal_connect(rtspsrc, "pad-added", G_CALLBACK(cb_new_rtspsrc_pad),
p_rtph264depay);
	g_signal_connect(p_matroskamux, "pad-added",
G_CALLBACK(cb_new_matroskamux_pad), p_h264parse);
	
	// put together a pipeline
	gst_bin_add_many(GST_BIN(pipeline), rtspsrc, p_rtph264depay,
p_h264parse, p_matroskamux, p_filesink, NULL);

	// link elements
	if(gst_element_link_pads(p_rtph264depay, "src", p_h264parse, "sink") ==
false)
	{
		std::cout << "Failed to link elements 1" << std::endl;
	}

	if(gst_element_link_pads(p_matroskamux, "src", p_filesink, "sink") ==
false)
	{
		std::cout << "Failed to link elements 2" << std::endl;
	}

	// start the pipeline
	gst_element_set_state(GST_ELEMENT(pipeline), GST_STATE_PLAYING);
	GMainLoop * loop = g_main_loop_new(NULL, FALSE);
	g_main_loop_run(loop);

	// TODO: clean up
	//gst_object_unref(GST_OBJECT(element));

	return 1;
}// end main

It fails with these messages ...

0:00:00.157460582 29771 0x7f3b50005400 INFO              GST_STATES
gstelement.c:2303:gst_element_continue_state:<rtpjitterbuffer0>
committing state from READY to PAUSED, pending PLAYING, next PLAYING
0:00:00.157486081 29771 0x7f3b50005400 INFO              GST_STATES
gstelement.c:2233:_priv_gst_element_state_changed:<rtpjitterbuffer0>
notifying about state-changed READY to PAUSED (PLAYING pending)
0:00:00.157516723 29771 0x7f3b50005400 INFO              GST_STATES
gstelement.c:2310:gst_element_continue_state:<rtpjitterbuffer0> continue
state change PAUSED to PLAYING, final PLAYING
0:00:00.157544516 29771 0x7f3b50005400 INFO              GST_STATES
gstelement.c:2328:gst_element_continue_state:<rtpjitterbuffer0>
completed state change to PLAYING
0:00:00.157567741 29771 0x7f3b50005400 INFO              GST_STATES
gstelement.c:2233:_priv_gst_element_state_changed:<rtpjitterbuffer0>
notifying about state-changed PAUSED to PLAYING (VOID_PENDING pending)
0:00:00.157600347 29771 0x7f3b50005400 INFO        GST_ELEMENT_PADS
gstelement.c:897:gst_element_get_static_pad: found pad
rtpssrcdemux0:src_1034261883
0:00:00.157622066 29771 0x7f3b50005400 INFO        GST_ELEMENT_PADS
gstelement.c:897:gst_element_get_static_pad: found pad
rtpjitterbuffer0:sink
0:00:00.157650077 29771 0x7f3b50005400 INFO                GST_PADS
gstpad.c:2120:gst_pad_link_prepare: trying to link
rtpssrcdemux0:src_1034261883 and rtpjitterbuffer0:sink
0:00:00.157674805 29771 0x7f3b50005400 INFO                GST_PADS
gstpad.c:2322:gst_pad_link_full: linked rtpssrcdemux0:src_1034261883 and
rtpjitterbuffer0:sink, successful
0:00:00.157704075 29771 0x7f3b50005400 INFO               GST_EVENT
gstevent.c:1313:gst_event_new_reconfigure: creating reconfigure event
0:00:00.157755339 29771 0x7f3b50005400 INFO        GST_ELEMENT_PADS
gstelement.c:897:gst_element_get_static_pad: found pad
rtpssrcdemux0:rtcp_src_1034261883
0:00:00.157779606 29771 0x7f3b50005400 INFO        GST_ELEMENT_PADS
gstelement.c:894:gst_element_get_static_pad: no such pad 'sink_rtcp' in
element "rtpjitterbuffer0"
0:00:00.157849460 29771 0x7f3b50005400 INFO        GST_ELEMENT_PADS
gstelement.c:646:gst_element_add_pad:<rtpjitterbuffer0> adding pad
'sink_rtcp'
0:00:00.157883645 29771 0x7f3b50005400 INFO                GST_PADS
gstpad.c:2120:gst_pad_link_prepare: trying to link
rtpssrcdemux0:rtcp_src_1034261883 and rtpjitterbuffer0:sink_rtcp
0:00:00.157908892 29771 0x7f3b50005400 INFO                GST_PADS
gstpad.c:2322:gst_pad_link_full: linked
rtpssrcdemux0:rtcp_src_1034261883 and rtpjitterbuffer0:sink_rtcp,
successful
0:00:00.157930670 29771 0x7f3b50005400 INFO               GST_EVENT
gstevent.c:1313:gst_event_new_reconfigure: creating reconfigure event
0:00:00.158025936 29771 0x7f3b50005400 WARN         rtpjitterbuffer
rtpjitterbuffer.c:183:rtp_jitter_buffer_set_clock_rate: Clock rate
changed from 0 to 90000
0:00:00.158167617 29771 0x7f3b40001770 INFO               GST_EVENT
gstevent.c:628:gst_event_new_caps: creating caps event
application/x-rtp, media=(string)video, payload=(int)96,
clock-rate=(int)90000, encoding-name=(string)H264,
profile-level-id=(string)420029, packetization-mode=(string)1,
sprop-parameter-sets=(string)"Z00AKZpmA8ARPyzUBAQFAAADA+gAAMNQBA\=\=
\,aO48gA\=\=", a-Media_header=(string)"MEDIAINFO
\=494D4B48010100000400010000000000000000000000000000000000000000000000000000000000\;", a-appversion=(string)1.0, clock-base=(uint)786867504, seqnum-base=(uint)12983, npt-start=(guint64)0, play-speed=(double)1, play-scale=(double)1
0:00:00.158283874 29771 0x7f3b40001770 INFO        GST_ELEMENT_PADS
gstelement.c:646:gst_element_add_pad:<rtpptdemux0> adding pad 'src_96'
0:00:00.158377158 29771 0x7f3b40001770 INFO                GST_PADS
gstpad.c:2120:gst_pad_link_prepare: trying to link rtpptdemux0:src_96
and recv_rtp_src_0_1034261883_96:proxypad3
0:00:00.158407781 29771 0x7f3b40001770 INFO                GST_PADS
gstpad.c:2322:gst_pad_link_full: linked rtpptdemux0:src_96 and
recv_rtp_src_0_1034261883_96:proxypad3, successful
0:00:00.158430910 29771 0x7f3b40001770 INFO               GST_EVENT
gstevent.c:1313:gst_event_new_reconfigure: creating reconfigure event
0:00:00.158507325 29771 0x7f3b40001770 INFO        GST_ELEMENT_PADS
gstelement.c:646:gst_element_add_pad:<manager> adding pad
'recv_rtp_src_0_1034261883_96'
0:00:00.158622779 29771 0x7f3b40001770 INFO                GST_PADS
gstpad.c:2120:gst_pad_link_prepare: trying to link
manager:recv_rtp_src_0_1034261883_96 and
recv_rtp_src_0_1034261883_96:proxypad4
0:00:00.158657346 29771 0x7f3b40001770 INFO                GST_PADS
gstpad.c:2322:gst_pad_link_full: linked
manager:recv_rtp_src_0_1034261883_96 and
recv_rtp_src_0_1034261883_96:proxypad4, successful
0:00:00.158680054 29771 0x7f3b40001770 INFO               GST_EVENT
gstevent.c:1313:gst_event_new_reconfigure: creating reconfigure event
0:00:00.158768431 29771 0x7f3b40001770 INFO        GST_ELEMENT_PADS
gstelement.c:646:gst_element_add_pad:<rtspsrc> adding pad
'recv_rtp_src_0_1034261883_96'
A new pad recv_rtp_src_0_1034261883_96 was created
0x23eae30, application/x-rtp; application/x-rdt
0:00:00.158909614 29771 0x7f3b40001770 INFO        GST_ELEMENT_PADS
gstutils.c:1543:gst_element_link_pads_full: trying to link element
rtspsrc:recv_rtp_src_0_1034261883_96 to element rtph264depay:sink
0:00:00.158937915 29771 0x7f3b40001770 INFO        GST_ELEMENT_PADS
gstelement.c:897:gst_element_get_static_pad: found pad
rtspsrc:recv_rtp_src_0_1034261883_96
0:00:00.158960733 29771 0x7f3b40001770 INFO        GST_ELEMENT_PADS
gstelement.c:897:gst_element_get_static_pad: found pad rtph264depay:sink
0:00:00.158982041 29771 0x7f3b40001770 INFO                GST_PADS
gstutils.c:1443:prepare_link_maybe_ghosting: rtspsrc and rtph264depay in
same bin, no need for ghost pads
0:00:00.159015973 29771 0x7f3b40001770 INFO                GST_PADS
gstpad.c:2120:gst_pad_link_prepare: trying to link
rtspsrc:recv_rtp_src_0_1034261883_96 and rtph264depay:sink
0:00:00.159091339 29771 0x7f3b40001770 INFO                GST_PADS
gstpad.c:2322:gst_pad_link_full: linked
rtspsrc:recv_rtp_src_0_1034261883_96 and rtph264depay:sink, successful
0:00:00.159117046 29771 0x7f3b40001770 INFO               GST_EVENT
gstevent.c:1313:gst_event_new_reconfigure: creating reconfigure event
0:00:00.159379528 29771 0x7f3b40001770 INFO                GST_PADS
gstpad.c:3675:gst_pad_peer_query:<h264parse:src> pad has no peer
0:00:00.159502645 29771 0x7f3b40001770 INFO               GST_EVENT
gstevent.c:628:gst_event_new_caps: creating caps event video/x-h264,
stream-format=(string)avc, alignment=(string)au,
codec_data=(buffer)014d0029ffe10019674d00299a6603c0113f2cd404040500000303e80000c3500401000468ee3c80
0:00:00.159570362 29771 0x7f3b40001770 INFO                GST_PADS
gstpad.c:3675:gst_pad_peer_query:<h264parse:src> pad has no peer
0:00:00.171480674 29771 0x7f3b40001770 INFO               GST_EVENT
gstevent.c:709:gst_event_new_segment: creating segment event time
segment start=0:00:00.000000000, stop=99:99:99.999999999, rate=1.000000,
applied_rate=1.000000, flags=0x00, time=0:00:00.000000000,
base=0:00:00.000000000, position 0:00:00.000000000, duration
99:99:99.999999999
0:00:00.171612970 29771 0x7f3b40001770 INFO               h264parse
gsth264parse.c:1258:gst_h264_parse_update_src_caps:<h264parse>
resolution changed 1920x1080
0:00:00.171662988 29771 0x7f3b40001770 INFO               GST_EVENT
gstevent.c:628:gst_event_new_caps: creating caps event video/x-h264,
stream-format=(string)byte-stream, alignment=(string)au,
width=(int)1920, height=(int)1080, parsed=(boolean)true
0:00:00.171925728 29771 0x7f3b40001770 INFO                    task
gsttask.c:300:gst_task_func:<rtpjitterbuffer0:src> Task going to paused
0:00:00.207741859 29771 0x7f3b50005400 INFO                 basesrc
gstbasesrc.c:2785:gst_base_src_loop:<udpsrc0> pausing after
gst_pad_push() = not-linked
0:00:00.207820982 29771 0x7f3b50005400 WARN                 basesrc
gstbasesrc.c:2865:gst_base_src_loop:<udpsrc0> error: Internal data flow
error.
0:00:00.207840802 29771 0x7f3b50005400 WARN                 basesrc
gstbasesrc.c:2865:gst_base_src_loop:<udpsrc0> error: streaming task
paused, reason not-linked (-1)
0:00:00.207876964 29771 0x7f3b50005400 INFO        GST_ERROR_SYSTEM
gstelement.c:1835:gst_element_message_full:<udpsrc0> posting message:
Internal data flow error.
0:00:00.207925487 29771 0x7f3b50005400 INFO        GST_ERROR_SYSTEM
gstelement.c:1858:gst_element_message_full:<udpsrc0> posted error
message: Internal data flow error.
0:00:00.207984106 29771 0x7f3b50005400 INFO                    task
gsttask.c:300:gst_task_func:<udpsrc0:src> Task going to paused
0:00:03.157010361 29771 0x7f3b50024190 INFO               GST_EVENT
gstevent.c:628:gst_event_new_caps: creating caps event
application/x-rtcp
0:00:03.157168413 29771 0x7f3b50024190 INFO               GST_EVENT
gstevent.c:709:gst_event_new_segment: creating segment event time
segment start=0:00:00.000000000, stop=99:99:99.999999999, rate=1.000000,
applied_rate=1.000000, flags=0x00, time=0:00:00.000000000,
base=0:00:00.000000000, position 0:00:00.000000000, duration
99:99:99.999999999
0:00:03.489885234 29771 0x7f3b50005450 INFO               GST_EVENT
gstevent.c:709:gst_event_new_segment: creating segment event time
segment start=0:00:00.000000000, stop=99:99:99.999999999, rate=1.000000,
applied_rate=1.000000, flags=0x00, time=0:00:00.000000000,
base=0:00:00.000000000, position 0:00:00.000000000, duration
99:99:99.999999999
0:00:03.490247549 29771 0x7f3b50005450 INFO                 basesrc
gstbasesrc.c:2772:gst_base_src_loop:<udpsrc1> marking pending DISCONT
0:00:03.490424944 29771 0x7f3b50005450 INFO               GST_EVENT
gstevent.c:628:gst_event_new_caps: creating caps event
application/x-rtcp, ssrc=(uint)1034261883
0:00:03.490728048 29771 0x7f3b50005450 INFO               GST_EVENT
gstevent.c:628:gst_event_new_caps: creating caps event
application/x-rtcp
0:00:03.490875829 29771 0x7f3b50005450 INFO               GST_EVENT
gstevent.c:628:gst_event_new_caps: creating caps event
application/x-rtcp, ssrc=(uint)1034261883



More information about the gstreamer-devel mailing list