gst-rtsp-server add RTP header extension

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

gst-rtsp-server add RTP header extension

Andrey Panteleev

Greetings everybody,


We use gst-rtsp-server to stream media content and want to use RTP Header Extensions (RFC5285) to add additional information to the stream.


However, we can't find way to do that. We thought that through RTSPMediaFactory configuration we can add some options to internal rtpbin. But that is not the case, because rtpbin doesn't have any option like that.


There is a low-level way to add extension (with GstRTPBuffer), though wedon't see where we can use it. Media pipeline is too soon, but after we pass it to MediaFactory we have no control.


The question is how to set extension header for each buffer comes out of the constructed pipeline.


Best regards,

Andrey P.


_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: gst-rtsp-server add RTP header extension

omer.tal
This post was updated on .
Hey Andrey,

I found this post after searching for a solution myself.
So I will share my solution for the next person who struggles with this:

First, step is to understand how to add the metadata to the RTP payloader. That is being done using a probe on the source pad of the rtp payloader element (Appendix A).

Once this is clear we're ready to tackle the problem with RTSP server.
The issue here is we don't have direct access to the payloader, since that element isn't exist until a connection is made.
Therefore we must connect a signal from the factory to a callback which gets called when a connection was made (or in other words - an GstRTSPMedia object was constructed. The gst-rtsp-server package has a good example for that (test-multicast2.c.

When that callback is called we can extract the payloader element and do step #1 as I described in the begining (Appendix B).


Appendix:
=========
Appendix A:


static GstPadProbeReturn load_telemetry_to_rtp(GstPad *pad, GstPadProbeInfo *info, gpointer data) {

    GstBuffer *buffer = GST_PAD_PROBE_INFO_BUFFER(info);
    GstRTPBuffer rtp_buffer;
    memset(&rtp_buffer, 0, sizeof(GstRTPBuffer));

    if (buffer != NULL) {
        if (gst_rtp_buffer_map(buffer, (GstMapFlags)GST_MAP_READWRITE, &rtp_buffer)) {
            GstCall(gst_rtp_buffer_add_extension_twobytes_header(&rtp_buffer, 0, 1, &telemetry_version, sizeof(telemetry_version)));
            GstCall(gst_rtp_buffer_add_extension_twobytes_header(&rtp_buffer, 0, 2, ¤t_telemetry, sizeof(current_telemetry)));
            std::cout << "Added metadata to packet !!!!!!!!" << std::endl;
        }
        else {
            Error("RTP buffer not mapped");
        }
    }
    else {
        Error("Gst buffer is NULL");
    }
    gst_rtp_buffer_unmap(&rtp_buffer);    
}


Appendix B:
static void media_constructed_callback (GstRTSPMediaFactory * factory, GstRTSPMedia *media, gpointer user_data) {
    std::cout << "New media constructed..." << std::endl;
    GstElement *pipeline = gst_rtsp_media_get_element(media);
    GstElement *rtp_payloader = gst_bin_get_by_name(GST_BIN(pipeline), "pay0");
    GstPad *rtp_payloader_src;
    if (rtp_payloader) {
        std::cout << "Got element payloader" << std::endl;
    }
    rtp_payloader_src = gst_element_get_static_pad(rtp_payloader, "src");
   
    gst_pad_add_probe(rtp_payloader_src, GST_PAD_PROBE_TYPE_BUFFER, (GstPadProbeCallback)load_telemetry_to_rtp, NULL, NULL);
}


And within the main function:

g_signal_connect(factory, "media-constructed", (GCallback)media_constructed_callback, nullptr);


Hope this will help anyone in the future...

--
Sent from: http://gstreamer-devel.966125.n4.nabble.com/
_______________________________________________
gstreamer-devel mailing list
gstreamer-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: gst-rtsp-server add RTP header extension

deegor
This doesn't work. At least anymore because `GstBuffer` inside `GstPadProbeInfo` is not writable. It seems like the only “allowed” way to add an extension is to subclass `GstRTPHeaderExtension`. How to do it exactly is poorly documented (should read as “not documented at all”). From what I saw in the GStreamer's source code, I've concluded that you must create a GStreamer plugin, register the RTP extension as an element, then construct it using `gst_rtp_header_extension_create_from_uri`. GStreamer's release notes advertise it as an improvement that made things really “easy”.