CselecT
CselecT

Reputation: 81

Gstreamer RTSP Decoding Frame Timestamps

We are decoding RTSP stream frames using Gstreamer in C++. We need to read the frame NTP timestamps, which we think that resides in RTCP packets. After some documentation digging, we found an element called GstRTPBaseDepayload, which has a property called "stats", which has a field "timestamp", explained as the "last seen RTP timestamp".

Our original pipeline:

gst-launch-1.0 rtspsrc port-range=5000-5100 location="rtsp://.." latency=300 is-live=true ! queue ! rtph265depay name=depayer! video/x-h265 , stream-format=byte-stream, alignment=au ! h265parse ! video/x-h265 , stream-format=byte-stream, alignment=au ! appsink name=mysink sync=true

I named the depay element as rtph265depay name=dp, then:

    depayer_=gst_bin_get_by_name(GST_BIN(pipeline_), "dp");
    GstStructure * stat;
    g_object_get((GstRTPBaseDepayload*)depayer_,"stats",stat);
    GType type = gst_structure_get_field_type(stat,"timestamp");

It gave an error saying that the stat structure does not have a field, in fact, it did not have any fields. I did not find any example usage of GstRTPBaseDepayload, and the documentation is lacking as always. I would appreciate any guidance regarding the frame timestamps.

Edit:

I also tried to check if depayer_ has a null value:

depayer_=gst_bin_get_by_name(GST_BIN(pipeline_), "dp");
    if(depayer_!=nullptr){
      GstStructure * stat;
      // GstRTPBaseDepayload* depayload;
      g_object_get(depayer_,"stats",stat,NULL);
      if(gst_structure_has_field(stat,"timestamp")){ //this line causes segfault
        guint timestamp;
        gst_structure_get_uint(stat,"timestamp",&timestamp);
      }
    }

Neither depayer nor stat object is null, however gst_structure_has_field(stat,"timestamp") causes a segfault. Any help is much appreciated.

Upvotes: 3

Views: 2507

Answers (1)

fengjiongmax
fengjiongmax

Reputation: 96

I guess you can try

GstStructure *stat;
// GstRTPBaseDepayload* depayload;
g_object_get(depayer_,"stats",&stat,NULL);

notice I used &stat in g_object_get, not stat.

https://docs.gtk.org/gobject/method.Object.get.html

I found an example: https://github.com/pexip/gst-rtsp-server/blob/master/examples/test-mp4.c#L38-L42

Upvotes: 1

Related Questions