Finding server port In RTSP server base on RTP with UDP transport

I want to find out Server port is RTSP server with Gstreamer when UDP is selected as Transport. This my source code it just shows Client port not server port(server port is shown = -1).

#include <gst/gst.h>
#include <gst/rtsp-server/rtsp-server.h>
#include <stdio.h>
static gboolean timeout(GstRTSPServer *server) {
    GstRTSPSessionPool *pool;

    pool = gst_rtsp_server_get_session_pool(server);
    gst_rtsp_session_pool_cleanup(pool);
    g_object_unref(pool);

    return TRUE;
}
GstRTSPMediaFactory *Factory;
void static media_configure_handler(GstRTSPMediaFactory *factory,
                                    GstRTSPMedia *media, void *This) {

    printf("n media_configure_handler n");
    GstRTSPContext *ctx;
    ctx = gst_rtsp_context_get_current();
    if (ctx == NULL) {
        printf("n No current RTSP contextn");
        return;
    }
    const GstRTSPTransport *rtsp_transport;
    if(ctx->trans)
    {
        rtsp_transport = gst_rtsp_stream_transport_get_transport (ctx->trans);
        if (!rtsp_transport) {
            g_print ("No RTSP transport foundn");

        }
        else
        {
            if (rtsp_transport->lower_transport == GST_RTSP_LOWER_TRANS_UDP) {
                g_print ("Server RTP min port: %dn", rtsp_transport->server_port.min);
                g_print ("Server RTP max port: %dn", rtsp_transport->server_port.max);
                g_print ("client RTP min port: %dn", rtsp_transport->client_port.min);
                g_print ("client RTP max port: %dn", rtsp_transport->client_port.max);
            } else {
                g_print ("Not using UDP transportn");
            }
        }
    }

}
static GstRTSPStatusCode *
setup_request_callback (GstRTSPClient * self,
                        GstRTSPContext * ctx,
                        gpointer user_data)
{

    printf("n setup_request_callbackn");
    const GstRTSPTransport *rtsp_transport;
    if(ctx->trans)
    {
        rtsp_transport = gst_rtsp_stream_transport_get_transport (ctx->trans);
        if (!rtsp_transport) {
            g_print ("No RTSP transport foundn");

        }
        else
        {
            if (rtsp_transport->lower_transport == GST_RTSP_LOWER_TRANS_UDP) {
                g_print ("Server RTP min port: %dn", rtsp_transport->server_port.min);
                g_print ("Server RTP max port: %dn", rtsp_transport->server_port.max);
                g_print ("client RTP min port: %dn", rtsp_transport->client_port.min);
                g_print ("client RTP max port: %dn", rtsp_transport->client_port.max);
            } else {
                g_print ("Not using UDP transportn");
            }
        }
    }
}
static GstRTSPStatusCode *
play_request_callback (GstRTSPClient * self,
                       GstRTSPContext * ctx,
                       gpointer user_data)
{

    printf("n pre_play_request_callbackn");
    g_signal_connect(Factory, "media_configure",
                     G_CALLBACK(media_configure_handler), nullptr);
    GstRTSPStreamTransport *transport;
    const GstRTSPTransport *rtsp_transport;

    if(ctx->trans)
    {
        rtsp_transport = gst_rtsp_stream_transport_get_transport (ctx->trans);
        if (!rtsp_transport) {
            g_print ("No RTSP transport foundn");

        }
        else
        {
            if (rtsp_transport->lower_transport == GST_RTSP_LOWER_TRANS_UDP) {
                g_print ("Server RTP min port: %dn", rtsp_transport->server_port.min);
                g_print ("Server RTP max port: %dn", rtsp_transport->server_port.max);
                g_print ("client RTP min port: %dn", rtsp_transport->client_port.min);
                g_print ("client RTP max port: %dn", rtsp_transport->client_port.max);
            } else {
                g_print ("Not using UDP transportn");
            }
        }
    }

    //        // Check if it's UDP

}
static void DescribeRequest(GstRTSPClient  *gstrtspclient, GstRTSPContext *arg1, gpointer user_data)
{
    gchar *urlString = gst_rtsp_url_get_request_uri(arg1->uri);



    printf(" DescribeRequest - urlString =  %s",urlString);



}


static GstRTSPStatusCode
pre_setup_request (GstRTSPClient * client,
                   GstRTSPContext * ctx)
{
    printf("n pre- setup_request_callbackn");
    GstRTSPStreamTransport *transport;
    const GstRTSPTransport *rtsp_transport;
    if(ctx->trans)
    {
        rtsp_transport = gst_rtsp_stream_transport_get_transport (ctx->trans);
        if (!rtsp_transport) {
            g_print ("No RTSP transport foundn");

        }
        else
        {
            if (rtsp_transport->lower_transport == GST_RTSP_LOWER_TRANS_UDP) {
                g_print ("Server RTP min port: %dn", rtsp_transport->server_port.min);
                g_print ("Server RTP max port: %dn", rtsp_transport->server_port.max);
                g_print ("client RTP min port: %dn", rtsp_transport->client_port.min);
                g_print ("client RTP max port: %dn", rtsp_transport->client_port.max);
            } else {
                g_print ("Not using UDP transportn");
            }
        }
    }
}


static void handle_response_callback (GstRTSPClient * self,
                                      GstRTSPContext * ctx,
                                      gpointer user_data)
{
    printf("n handle_response_callback n");
    GstRTSPStreamTransport *transport;
    const GstRTSPTransport *rtsp_transport;
    if(ctx->trans)
    {
        rtsp_transport = gst_rtsp_stream_transport_get_transport (ctx->trans);
        if (!rtsp_transport) {
            g_print ("No RTSP transport foundn");

        }
        else
        {
            if (rtsp_transport->lower_transport == GST_RTSP_LOWER_TRANS_UDP) {
                g_print ("Server RTP min port: %dn", rtsp_transport->server_port.min);
                g_print ("Server RTP max port: %dn", rtsp_transport->server_port.max);
                g_print ("client RTP min port: %dn", rtsp_transport->client_port.min);
                g_print ("client RTP max port: %dn", rtsp_transport->client_port.max);
            } else {
                g_print ("Not using UDP transportn");
            }
        }
    }
}
void static closed_callback (GstRTSPClient * self,
                 gpointer user_data)
{
    printf("n closed_callback n");
    GstRTSPStreamTransport *transport;
    const GstRTSPTransport *rtsp_transport;
    GstRTSPContext *ctx;


    // Get the current RTSP context
    ctx = gst_rtsp_context_get_current();
    if (ctx == NULL) {
        printf("n No current RTSP contextn");
        return;
    }
    if(ctx->trans)
    {
        rtsp_transport = gst_rtsp_stream_transport_get_transport (ctx->trans);
        if (!rtsp_transport) {
            g_print ("No RTSP transport foundn");

        }
        else
        {
            if (rtsp_transport->lower_transport == GST_RTSP_LOWER_TRANS_UDP) {
                g_print ("Server RTP min port: %dn", rtsp_transport->server_port.min);
                g_print ("Server RTP max port: %dn", rtsp_transport->server_port.max);
                g_print ("client RTP min port: %dn", rtsp_transport->client_port.min);
                g_print ("client RTP max port: %dn", rtsp_transport->client_port.max);
            } else {
                g_print ("Not using UDP transportn");
            }
        }
    }
}
void static set_parameter_request_callback (GstRTSPClient * self,
                                            GstRTSPContext * ctx,
                                            gpointer user_data)
{
    printf("n set_parameter_request_callback n");
    GstRTSPStreamTransport *transport;
    const GstRTSPTransport *rtsp_transport;
    if(ctx->trans)
    {
        rtsp_transport = gst_rtsp_stream_transport_get_transport (ctx->trans);
        if (!rtsp_transport) {
            g_print ("No RTSP transport foundn");

        }
        else
        {
            if (rtsp_transport->lower_transport == GST_RTSP_LOWER_TRANS_UDP) {
                g_print ("Server RTP min port: %dn", rtsp_transport->server_port.min);
                g_print ("Server RTP max port: %dn", rtsp_transport->server_port.max);
                g_print ("client RTP min port: %dn", rtsp_transport->client_port.min);
                g_print ("client RTP max port: %dn", rtsp_transport->client_port.max);
            } else {
                g_print ("Not using UDP transportn");
            }
        }
    }
}
void static get_parameter_request_callback (GstRTSPClient * self,
                                            GstRTSPContext * ctx,
                                            gpointer user_data)
{
    printf("n get_parameter_request_callback n");
    GstRTSPStreamTransport *transport;
    const GstRTSPTransport *rtsp_transport;
    if(ctx->trans)
    {
        rtsp_transport = gst_rtsp_stream_transport_get_transport (ctx->trans);

        if (!rtsp_transport) {
            g_print ("No RTSP transport foundn");

        }
        else
        {
            if (rtsp_transport->lower_transport == GST_RTSP_LOWER_TRANS_UDP) {
                g_print ("Server RTP min port: %dn", rtsp_transport->server_port.min);
                g_print ("Server RTP max port: %dn", rtsp_transport->server_port.max);
                g_print ("client RTP min port: %dn", rtsp_transport->client_port.min);
                g_print ("client RTP max port: %dn", rtsp_transport->client_port.max);
            } else {
                g_print ("Not using UDP transportn");
            }
        }
    }
}





static void new_session_callback (GstRTSPClient * self,
                                  GstRTSPSession * object,
                                  gpointer user_data)
{

    GstRTSPContext *ctx;


    // Get the current RTSP context
    ctx = gst_rtsp_context_get_current();
    if (ctx == NULL) {
        printf("n No current RTSP contextn");
        return;
    }
    printf("n new_session_callback n");
    GstRTSPStreamTransport *transport;
    const GstRTSPTransport *rtsp_transport;
    if(ctx->trans)
    {
        rtsp_transport = gst_rtsp_stream_transport_get_transport (ctx->trans);
        if (!rtsp_transport) {
            g_print ("No RTSP transport foundn");

        }
        else
        {
            if (rtsp_transport->lower_transport == GST_RTSP_LOWER_TRANS_UDP) {
                g_print ("Server RTP min port: %dn", rtsp_transport->server_port.min);
                g_print ("Server RTP max port: %dn", rtsp_transport->server_port.max);
                g_print ("client RTP min port: %dn", rtsp_transport->client_port.min);
                g_print ("client RTP max port: %dn", rtsp_transport->client_port.max);
            } else {
                g_print ("Not using UDP transportn");
            }
        }
    }

}

static void options_request_callback (GstRTSPClient * self,
                                      GstRTSPContext * ctx,
                                      gpointer user_data)
{
    printf("n options_request_callback n");
    GstRTSPStreamTransport *transport;
    const GstRTSPTransport *rtsp_transport;
    if(ctx->trans)
    {
        rtsp_transport = gst_rtsp_stream_transport_get_transport (ctx->trans);
        if (!rtsp_transport) {
            g_print ("No RTSP transport foundn");

        }
        else
        {
            if (rtsp_transport->lower_transport == GST_RTSP_LOWER_TRANS_UDP) {
                g_print ("Server RTP min port: %dn", rtsp_transport->server_port.min);
                g_print ("Server RTP max port: %dn", rtsp_transport->server_port.max);
                g_print ("client RTP min port: %dn", rtsp_transport->client_port.min);
                g_print ("client RTP max port: %dn", rtsp_transport->client_port.max);
            } else {
                g_print ("Not using UDP transportn");
            }
        }
    }
}

static void teardown_request_callback (GstRTSPClient * self,
                                       GstRTSPContext * ctx,
                                       gpointer user_data)
{
    printf("n teardown_request_callback n");
    GstRTSPStreamTransport *transport;
    const GstRTSPTransport *rtsp_transport;
    if(ctx->trans)
    {
        rtsp_transport = gst_rtsp_stream_transport_get_transport (ctx->trans);
        if (!rtsp_transport) {
            g_print ("No RTSP transport foundn");

        }
        else
        {
            if (rtsp_transport->lower_transport == GST_RTSP_LOWER_TRANS_UDP) {
                g_print ("Server RTP min port: %dn", rtsp_transport->server_port.min);
                g_print ("Server RTP max port: %dn", rtsp_transport->server_port.max);
                g_print ("client RTP min port: %dn", rtsp_transport->client_port.min);
                g_print ("client RTP max port: %dn", rtsp_transport->client_port.max);
            } else {
                g_print ("Not using UDP transportn");
            }
        }
    }


}
static void send_message_callback (GstRTSPClient * self,
                                   GstRTSPSession * session,
                                   gpointer message,
                                   gpointer user_data)
{
    GstRTSPContext *ctx;

    printf("n send_message_callback %s n",(char * )message);
    // Get the current RTSP context
    ctx = gst_rtsp_context_get_current();
    if (ctx == NULL) {
        printf("n No current RTSP contextn");
        return;
    }

    GstRTSPStreamTransport *transport;
    const GstRTSPTransport *rtsp_transport;
    if(ctx->trans)
    {
        rtsp_transport = gst_rtsp_stream_transport_get_transport (ctx->trans);
        if (!rtsp_transport) {
            g_print ("No RTSP transport foundn");

        }
        else
        {
            if (rtsp_transport->lower_transport == GST_RTSP_LOWER_TRANS_UDP) {
                g_print ("Server RTP min port: %dn", rtsp_transport->server_port.min);
                g_print ("Server RTP max port: %dn", rtsp_transport->server_port.max);
                g_print ("client RTP min port: %dn", rtsp_transport->client_port.min);
                g_print ("client RTP max port: %dn", rtsp_transport->client_port.max);
            } else {
                g_print ("Not using UDP transportn");
            }
        }
    }
}
 static  GstRTSPStatusCode *
pre_setup_request_callback (GstRTSPClient * self,
                            GstRTSPContext * ctx,
                            gpointer user_data)
{
       printf("n pre_setup_request_callback n");
       const GstRTSPTransport *rtsp_transport;
       if(ctx->trans)
       {
           rtsp_transport = gst_rtsp_stream_transport_get_transport (ctx->trans);
           if (!rtsp_transport) {
               g_print ("No RTSP transport foundn");

           }
           else
           {
               if (rtsp_transport->lower_transport == GST_RTSP_LOWER_TRANS_UDP) {
                   g_print ("Server RTP min port: %dn", rtsp_transport->server_port.min);
                   g_print ("Server RTP max port: %dn", rtsp_transport->server_port.max);
                   g_print ("client RTP min port: %dn", rtsp_transport->client_port.min);
                   g_print ("client RTP max port: %dn", rtsp_transport->client_port.max);
               } else {
                   g_print ("Not using UDP transportn");
               }
           }
       }

}



static void ClientConnected(GstRTSPServer *gstrtspserver, GstRTSPClient *arg1, gpointer user_data)
{
    g_signal_connect(arg1, "setup-request", (GCallback)setup_request_callback, user_data);
    g_signal_connect(arg1, "closed", (GCallback)closed_callback, user_data);
    g_signal_connect(arg1, "handle-response", (GCallback)handle_response_callback, user_data);
    g_signal_connect(arg1, "get-parameter-request", (GCallback)get_parameter_request_callback, user_data);
    g_signal_connect(arg1, "set-parameter-request", (GCallback)set_parameter_request_callback, user_data);
    g_signal_connect(arg1, "play-request", (GCallback)play_request_callback, user_data);
    g_signal_connect(arg1, "teardown-request", (GCallback)teardown_request_callback, user_data);
    g_signal_connect(arg1, "new-session", (GCallback)new_session_callback, user_data);
    g_signal_connect(arg1, "options-request", (GCallback)options_request_callback, user_data);
    g_signal_connect(arg1, "send-message", (GCallback)send_message_callback, user_data);
    g_signal_connect(arg1, "describe-request", (GCallback)DescribeRequest, user_data);

}
int main(int argc, char *argv[]) {
    GMainLoop *loop;
    GstRTSPServer *server;
    GstRTSPMountPoints *mounts;
    GstRTSPMediaFactory *factory;
    GstRTSPAddressPool *pool;

    gst_init(&argc, &argv);

    loop = g_main_loop_new(NULL, FALSE);

    /* create a server instance */
    server = gst_rtsp_server_new();
    g_object_set(server, "service", "8554", NULL);

    /* get the mount points for this server, every server has a default object
   * that be used to map uri mount points to media factories */
    mounts = gst_rtsp_server_get_mount_points(server);

    /* make a media factory for a test stream. The default media factory can use
   * gst-launch syntax to create pipelines.
   * any launch line works as long as it contains elements named pay%d. Each
   * element with pay%d names will be a stream */
    factory = gst_rtsp_media_factory_new();
    gst_rtsp_media_factory_set_launch(
                factory,
                "videotestsrc ! video/x-raw,width=352,height=288,framerate=15/1 !  "
      "x264enc ! rtph264pay name=pay0 pt=96 ");

    gst_rtsp_media_factory_set_shared(factory, TRUE);
    /* only allow multicast */
    gst_rtsp_media_factory_set_protocols(
                factory, GstRTSPLowerTrans(GST_RTSP_LOWER_TRANS_UDP));

    /* attach the test factory to the /test url */
    gst_rtsp_mount_points_add_factory(mounts, "/test", factory);
    Factory = factory;

    /* don't need the ref to the mapper anymore */
    g_object_unref(mounts);

    /* attach the server to the default maincontext */
    if (gst_rtsp_server_attach(server, NULL) == 0) goto failed;

    g_timeout_add_seconds(300, (GSourceFunc)timeout, server);
    g_signal_connect(server, "client-connected", (GCallback)ClientConnected, nullptr);

    /* start serving */
    g_print("stream ready at rtsp://127.0.0.1:8554/testn");
    g_main_loop_run(loop);

    return 0;

    /* ERRORS */
failed : {
        g_print("failed to attach the servern");
        return -1;
    }
}

So which signal has information about the server port? A server port is selected in RTSP protocol when a setup request from client to server is established and server responses to client (here server port is selected).
“play-request” does not have transport information “play-request”
“pre-setup request” makes the server stop working “pre-setup-request”
“setup request” shows server port -1 “pre-setup-request”
“get-parameter-request” does not have information about the transport layer.
“set-parameter-request” does not have information about the transport layer.
“handle-response” signal hasn’t been called .why?
“send-message” signal is called multiple times just one time it shows server port -1
“options-request” signal does not have information about the transport layer.
The “new-session” signal does not have information about the transport layer.
Even a “teardown-request” signal does not have information about the transport layer.
Even a “closed” signal does not have information about the transport layer.(even doesn’t have RTSP context)
Thanks so much.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật