I'm using gstreamer to pull an rtsp stream from an IP camera. Currently, I am using appsink to get the frame data out of the stream but I also need the original RTP timestamp associated with each frame. Is it possible to get the rtp timestamp? In the example I am using the GST_BUFFER_TIMESTAMP macro to get a timestamp but I do not think its the original rtp timestamp.
#include <gst/gst.h>
#include <gst/app/app.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
gst_init (&argc, &argv);
auto pipeline = gst_parse_launch(
"rtspsrc location=rtsp://10.0.0.171:554/h264/video.sdp name=rtspsrc latency=100 ! queue ! rtpbin buffer-mode=none ! rtph264depay ! h264parse ! appsink name=appsink",
nullptr);
auto rtspsrc = gst_bin_get_by_name((GstBin*)pipeline, "rtspsrc");
if(rtspsrc) {
g_object_set(rtspsrc, "user-id", "user", nullptr);
g_object_set(rtspsrc, "user-pw", "password", nullptr);
}
auto appsink = (GstAppSink*)gst_bin_get_by_name((GstBin*)pipeline, "appsink");
gst_element_set_state(pipeline, GST_STATE_PLAYING);
while(true)
{
auto sample = gst_app_sink_pull_sample(appsink);
if(sample)
{
auto buffer = gst_sample_get_buffer(sample);
GstClockTime timestamp = GST_BUFFER_TIMESTAMP(buffer);
if(buffer)
{
GstMapInfo info;
gst_buffer_map(buffer, &info, GST_MAP_READ);
printf("{%lu, %p, %ld}\n",timestamp,info.data,info.size);
}
}
printf(".");
fflush(stdout);
}
auto bus = gst_element_get_bus(pipeline);
auto msg = gst_bus_timed_pop_filtered(bus, GST_CLOCK_TIME_NONE, (GstMessageType)(GST_MESSAGE_ERROR | GST_MESSAGE_EOS));
if (msg != NULL)
gst_message_unref(msg);
gst_object_unref(bus);
gst_element_set_state(pipeline, GST_STATE_NULL);
gst_object_unref(pipeline);
return 0;
}