Need Help with GStreamer ONVIF-Backchannel

Content: Hello. I am developing a streaming server using the GStreamer package in C that supports video and bidirectional audio. The video is streaming well, but the bidirectional audio through the ONVIF backchannel is not working. Could you please check my source code and provide feedback on what might be the problem?

#include <gst/gst.h>
#include <gst/rtsp-server/rtsp-server.h>
#include <gst/rtsp-server/rtsp-onvif-media-factory.h>

GstRTSPMediaFactory *factory;

static gboolean bus_call(GstBus *bus, GstMessage *msg, gpointer data) {
    GMainLoop *loop = (GMainLoop *)data;

    switch (GST_MESSAGE_TYPE(msg)) {
        case GST_MESSAGE_EOS:
            g_print("End of stream\n");
            g_main_loop_quit(loop);
            break;

        case GST_MESSAGE_ERROR: {
            gchar *debug;
            GError *error;

            gst_message_parse_error(msg, &error, &debug);
            g_free(debug);

            g_printerr("Error: %s\n", error->message);
            g_error_free(error);

            g_main_loop_quit(loop);
            break;
        }
        default:
            break;
    }

    return TRUE;
}

static void client_closed(GstRTSPClient *client) {
    g_print("Client disconnected\n");
}

static GstRTSPResult handle_describe_request(GstRTSPClient *client, GstRTSPContext *ctx, gpointer user_data) {
    g_print("PRE DESCRIBE request...\n");

    GstRTSPMessage *request = ctx->request;
    if(request) {
        gchar *value = NULL;

        if (gst_rtsp_message_get_header(request, GST_RTSP_HDR_REQUIRE, &value, 0) == GST_RTSP_OK) {
            g_print("Require: %s\n", value);
        } else {
            g_print("Require header not found.\n");
        }
    }else {
        g_print("No RTSP request available.\n");
    }

    if(gst_rtsp_onvif_media_factory_requires_backchannel(factory, ctx)) {
        g_print("this is backchannel request.\n");
        gst_rtsp_onvif_media_factory_set_backchannel_launch(GST_RTSP_ONVIF_MEDIA_FACTORY(factory),
            "( capsfilter caps=\"application/x-rtp, media=audio, payload=0, clock-rate=8000, encoding-name=PCMU\" name=depay_backchannel ! "
            "rtppcmudepay ! "
            "mulawdec ! "
            "audioconvert ! "
            "pulsesink device=alsa_output.front_card.analog-stereo async=false buffer-time=200000 latency-time=10000 async=false )"
        );
    } else {
        g_print("this is not backchannel request.\n");
    }

    return GST_RTSP_OK;
}


static void client_connected(GstRTSPServer *server, GstRTSPClient *client, gpointer user_data) {
    g_print("Client connected\n");
    g_signal_connect(client, "pre-describe-request", (GCallback) handle_describe_request, user_data); // Pass factory as user_data
    g_signal_connect(client, "closed", (GCallback) client_closed, NULL);
}

int main(int argc, char *argv[]) {
    GMainLoop *loop;
    GstRTSPServer *server;
    GstRTSPMountPoints *mounts;
    gchar *port;
    gchar *rtsp_path;

    /* Initialize GStreamer */
    gst_init(&argc, &argv);
    loop = g_main_loop_new(NULL, FALSE);
    port = "8554";
    /* Create the RTSP server */
    server = gst_rtsp_onvif_server_new();
    g_object_set(server, "service", port, NULL);

    mounts = gst_rtsp_server_get_mount_points(server);
    factory = gst_rtsp_onvif_media_factory_new();

    gst_rtsp_media_factory_set_launch(factory,
        "( v4l2src device=/dev/video31 io-mode=2 ! "
        "video/x-raw, format=YUY2, width=640, height=360, framerate=30/1 ! "
        "nvvideoconvert ! "
        "video/x-raw(memory:NVMM), format=NV12, width=320, height=240 ! "
        "nvv4l2h264enc bitrate=256000 insert-sps-pps=1 idrinterval=15 iframeinterval=0 maxperf-enable=1 ! "
        "h264parse ! "
        "rtph264pay name=pay0 pt=96 "
        "pulsesrc device=alsa_input.front_card.mono-fallback buffer-time=200000 latency-time=10000 ! "
        "audio/x-raw, rate=44100 ! "
        "audioconvert ! "
        "audioresample quality=10 ! "
        "opusenc ! "
        "rtpopuspay name=pay1 pt=97 )"
    );

    gst_rtsp_media_factory_set_shared(factory, FALSE);
    gst_rtsp_media_factory_set_media_gtype(factory, GST_TYPE_RTSP_ONVIF_MEDIA);
    rtsp_path = "/test";
    gst_rtsp_mount_points_add_factory(mounts, rtsp_path, factory);
    g_object_unref(mounts);

    g_signal_connect(server, "client-connected", (GCallback) client_connected, factory); // Pass factory as user_data

    gst_rtsp_server_attach(server, NULL);

    g_print("Stream ready at rtsp://127.0.0.1:%s%s\n", port, rtsp_path);

    /* Iterate */
    g_main_loop_run(loop);

    /* Free resources */
    g_main_loop_unref(loop);

    return 0;
}

The overall logic involves parsing the describe request to check if there is an ONVIF-backchannel request in the “Require” header, and then executing the gst_rtsp_onvif_media_factory_requires_backchannel method.

I have been struggling with this issue for a month. Please, I really need your help.