【问题标题】:GStreamer connection to VLC using GstRTSP libraryGStreamer 使用 GstRTSP 库连接到 VLC
【发布时间】:2019-10-17 05:25:44
【问题描述】:

我正在尝试编写一个 C 应用程序来连接 VLC RTSP(通过 RTP)流并将帧保存为图像。 我使用 GStreamer RTSP 库:https://gstreamer.freedesktop.org/documentation/gst-plugins-base-rtsp-1.0/index.html?gi-language=c

我已经编写了一些如下所示的简单代码,但应用程序等待来自 VLC 的消息。我不确定这是否是一种很好的连接方式,但我现在陷入困境。也许我应该先向 VLC 发送一些东西,但我不知道该怎么做。谁能帮助或指出一些如何使用 GStreamer RTSP 的资源/示例?

#include <gstreamer-1.0/gst/rtsp/rtsp.h>
#include <stdio.h>

int main() 
{
    GstRTSPUrl *gstUrl = NULL;
    const char* url = "rtsp://10.30.1.163:8554/test.sdp";
    if(gst_rtsp_url_parse(url, &gstUrl) == GST_RTSP_OK) {
        printf("URL PARSE");
        GstRTSPConnection *gstRTSPConnection = NULL;
        if(gst_rtsp_connection_create(gstUrl, &gstRTSPConnection) == GST_RTSP_OK) {
            printf("Connection created\n");
            GstRTSPMessage *message = NULL;
            gst_rtsp_message_new(&message);
            GstRTSPResult result = gst_rtsp_connection_connect_with_response(gstRTSPConnection, NULL, message);
            if(result == GST_RTSP_ETIMEOUT){
                printf("Timeout\n");
            } else if(result == GST_RTSP_OK) {
                printf("Connected\n");
                printf("%s\n", gst_rtsp_connection_get_ip(gstRTSPConnection));
                printf("Is tunelled: %d\n", gst_rtsp_connection_is_tunneled(gstRTSPConnection));
                gst_rtsp_connection_receive(gstRTSPConnection, message, NULL);
            }
        }
    }    

    return 0;
}

【问题讨论】:

    标签: gstreamer vlc rtsp rtp sdp


    【解决方案1】:

    好的。我会处理这个。问题是我需要先根据 RTSP 协议向服务器发送一些消息。下面的解决方案(带有一些转储消息):

    #include <gstreamer-1.0/gst/rtsp/rtsp.h>
    #include <stdio.h>
    
    int main() 
    {
        GstRTSPUrl *gstUrl = NULL;
        const char* url = "rtsp://10.30.1.163:8554";
        if(gst_rtsp_url_parse(url, &gstUrl) == GST_RTSP_OK) {
            printf("URL PARSE");
            GstRTSPConnection *gstRTSPConnection = NULL;
            if(gst_rtsp_connection_create(gstUrl, &gstRTSPConnection) == GST_RTSP_OK) {
                printf("Connection created\n");
                GstRTSPMessage *message = NULL;
                gst_rtsp_message_new(&message);
                GstRTSPResult result = gst_rtsp_connection_connect_with_response(gstRTSPConnection, NULL, message);
                if(result == GST_RTSP_ETIMEOUT){
                    printf("Timeout\n");
                } else if(result == GST_RTSP_OK) {
                    printf("Connected\n");
                    printf("%s\n", gst_rtsp_connection_get_ip(gstRTSPConnection));
                    printf("Is tunelled: %d\n", gst_rtsp_connection_is_tunneled(gstRTSPConnection));
    
                    gst_rtsp_message_new(&message);
                    gst_rtsp_message_init_request(message, GST_RTSP_DESCRIBE, "rtsp://10.30.1.163:8554/test.sdp");
                    gst_rtsp_message_add_header(message, GST_RTSP_HDR_CSEQ, "1");
                    printf("Message Type %d", gst_rtsp_message_get_type(message));
    
    
                    gst_rtsp_message_dump(message);
    
                    if(gst_rtsp_connection_send(gstRTSPConnection, message, NULL) == GST_RTSP_OK){
                        printf("Message sent");
                    }else {
                        printf("Message not sent");
                    }
                    gst_rtsp_connection_receive(gstRTSPConnection, message, NULL);
    
                    gst_rtsp_message_dump(message);
                }
            }
        }    
    
        return 0;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-12-10
      • 1970-01-01
      • 2013-10-31
      • 1970-01-01
      • 2021-09-02
      • 1970-01-01
      • 1970-01-01
      • 2023-04-10
      相关资源
      最近更新 更多