Подключение GStreamer к VLC с использованием библиотеки GstRTSP

Я пытаюсь написать приложение 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;
}

person michalk93    schedule 31.05.2019    source источник


Ответы (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;
}
person michalk93    schedule 31.05.2019