This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TDA4VM: Is it able to install gst-rtsp-server libraries on TDA4VM and TDA4VE?

Part Number: TDA4VM

Tool/software:

Is it able to install gst-rtsp-server libraries on TDA4VM and TDA4VE? like:

apt-get install libgstrtspserver-1.0-dev gstreamer1.0-rtsp

Or gst-rtsp-server libraries should be installed from source code?

We uses SDK 8.5 on TDA4VM and TDA4VE.

  • Hi Joy Yang,

    The gst-rtsp-server libraries should already be included in the SDK. Here is a simple way to test RTSP functionality: [FAQ] SK-AM69: How to run GStreamer pipeline with RTSP source - Processors forum - Processors - TI E2E support forums

    Thank you,

    Fabiana

  • Hi Fabiana,

    I would like to use TDA4 as a GStreamer RTSP server (rather than a RTSP client).

    Here is the sample code to start a GStreamer RTSP server:

    #include <gst/gst.h>
    #include <gst/rtsp-server/rtsp-server.h>
    
    #define SERVER_HOST "0.0.0.0"
    #define SERVER_PORT "8554"
    #define SERVER_MAX_CONNECTIONS 10
    #define VIDEO_PATH "video.mp4"
    
    // 當 VLC 切換播放狀態時,處理 timestamp 凍結與恢復
    static void media_new_state(GstRTSPMedia *media, gint state, gpointer user_data) {
        GstElement *pipeline = gst_rtsp_media_get_element(media);
    
        if (state == GST_STATE_PAUSED) {
            g_print("Media paused. Freezing timestamp.\n");
            gst_element_set_start_time(pipeline, GST_CLOCK_TIME_NONE);
        } else if (state == GST_STATE_PLAYING) {
            g_print("Media playing. Resuming timestamp.\n");
            gst_element_set_base_time(pipeline, gst_element_get_base_time(pipeline));
        }
    }
    
    // 當媒體初始化時,設定 clock 和 pipeline
    static void media_configure(GstRTSPMediaFactory *factory, GstRTSPMedia *media, gpointer user_data) {
        GstElement *pipeline = gst_rtsp_media_get_element(media);
        GstClock *clock = gst_element_get_clock(pipeline);
    
        if (clock) {
            GstClockTime base_time = gst_clock_get_time(clock);
            g_print("Media configured. Pipeline clock time: %lu\n", base_time);
    
            // 確保 pipeline 使用相同 clock,避免 VLC 重新計算 timestamp
            gst_rtsp_media_set_clock(media, clock);
        }
    
        // 監聽媒體狀態變更 (播放、暫停、停止)
        g_signal_connect(media, "new-state", G_CALLBACK(media_new_state), NULL);
    }
    
    int main(int argc, char *argv[]) {
        GMainLoop *loop;
        GstRTSPServer *server;
        GstRTSPMountPoints *mounts;
        GstRTSPMediaFactory *factory;
    
        gst_init(&argc, &argv);
        loop = g_main_loop_new(NULL, FALSE);
    
        // 建立 RTSP 伺服器
        server = gst_rtsp_server_new();
        gst_rtsp_server_set_address(server, SERVER_HOST);  // 讓 RTSP 伺服器監聽所有網路介面
        gst_rtsp_server_set_service(server, SERVER_PORT);  // 設定 Port
        gst_rtsp_server_set_backlog(server, SERVER_MAX_CONNECTIONS);  // 設定最大連線數
    
        // 設定 mount point
        mounts = gst_rtsp_server_get_mount_points(server);
        factory = gst_rtsp_media_factory_new();
    
        // 設定 GStreamer pipeline
        gst_rtsp_media_factory_set_launch(factory,
            "( filesrc location=" VIDEO_PATH " ! decodebin ! videoconvert ! "
            "x264enc tune=zerolatency bitrate=2000 key-int-max=10 speed-preset=superfast ! "
            "rtph264pay name=pay0 pt=96 )");
    
        // 設定媒體配置回呼
        g_signal_connect(factory, "media-configure", G_CALLBACK(media_configure), NULL);
    
        // 掛載 stream
        gst_rtsp_mount_points_add_factory(mounts, "/stream", factory);
        g_object_unref(mounts);
    
        // 啟動 RTSP 伺服器
        if (gst_rtsp_server_attach(server, NULL) == 0) {
            g_printerr("Failed to attach the RTSP server\n");
            return -1;
        }
    
        g_print("RTSP server is running at rtsp://%s:%s/stream\n", SERVER_HOST, SERVER_PORT);
        g_main_loop_run(loop);
    
        return 0;
    }

    And it would be built by:

    gcc gst_rtsp_server.c -o gst_rtsp_server \
        -I/usr/include/gstreamer-1.0 \
        -I/usr/include/glib-2.0 \
        -I/usr/lib/glib-2.0/include \
        -L/usr/lib \
        -lgstreamer-1.0 \
        -lgstrtspserver-1.0

    These 2 libraries (libgstreamer-1.0 and libgstrtspserver-1.0) are found at /usr/lib by default:

    root@j721s2-evm:~/gst-rtsp-server# find /usr -name libgstreamer*
    /usr/lib/libgstreamer-1.0.so.0.1603.0
    /usr/lib/libgstreamer-1.0.so
    /usr/lib/libgstreamer-1.0.so.0

    root@j721s2-evm:~/gst-rtsp-server# find /usr -name libgstrtspserver*
    /usr/lib/libgstrtspserver-1.0.so.0.1603.0
    /usr/lib/libgstrtspserver-1.0.so.0

    And these 2 packages are found by using opkg list-installed command:

    gstreamer1.0 - 1.16.3-r0.0
    gstreamer1.0-rtsp-server - 1.16.3-r0.0

    But found error when building on TDA4:

    gst_rtsp_server.c:2:10: fatal error: gst/rtsp-server/rtsp-server.h: No such file or directory
        2 | #include <gst/rtsp-server/rtsp-server.h>
          |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    compilation terminated.
    

    /usr/include/gstreamer-1.0/gst/gst.h (found)

    /usr/include/gstreamer-1.0/gst/rtsp-server/rtsp-server.h (not found)

    Why there is no gst/rtsp-server/ directory?

    Thanks,
    Joy

  • Updated the solution:
    (TDA4VE SDK8.5's missing files?)
    Since there is not rtsp-server header files, so copy headers from github GStreamer/gst-rtsp-server at 1.16 to /usr/include/gstreamer-1.0/gst/rtsp-server/
    cp -r ./include/rtsp-server/ /usr/include/gstreamer-1.0/gst/

    (TDA4VE SDK8.5's missing files?)
    Since there is not soft-link gstrtspserver-1.0.so, so soft link libgstrtspserver-1.0.so.0 to libgstrtspserver-1.0.so
    ln -s /usr/lib/libgstrtspserver-1.0.so.0 /usr/lib/libgstrtspserver-1.0.so
    Rewrite the GStreamer RTSP server sample code:
    #include <gst/gst.h>
    #include <gst/rtsp-server/rtsp-server.h>
    
    #define SERVER_HOST "0.0.0.0"
    #define SERVER_PORT "8554"
    #define SERVER_MAX_CONNECTIONS 10
    #define VIDEO_PATH "video.mp4"
    
    // 當 VLC 切換播放狀態時,處理 timestamp 凍結與恢復
    static void media_new_state(GstRTSPMedia *media, gint state, gpointer user_data) {
        GstElement *pipeline = gst_rtsp_media_get_element(media);
    
        if (state == GST_STATE_PAUSED) {
            g_print("Media paused. Freezing timestamp.\n");
            gst_element_set_start_time(pipeline, GST_CLOCK_TIME_NONE);
        } else if (state == GST_STATE_PLAYING) {
            g_print("Media playing. Resuming timestamp.\n");
            gst_element_set_base_time(pipeline, gst_element_get_base_time(pipeline));
        }
    }
    
    // 當媒體初始化時,設定 clock 和 pipeline
    static void media_configure(GstRTSPMediaFactory *factory, GstRTSPMedia *media, gpointer user_data) {
        GstElement *pipeline = gst_rtsp_media_get_element(media);
        GstClock *clock = gst_element_get_clock(pipeline);
    
        if (clock) {
            GstClockTime base_time = gst_clock_get_time(clock);
            g_print("Media configured. Pipeline clock time: %lu\n", base_time);
    
            // 確保 pipeline 使用相同 clock,避免 VLC 重新計算 timestamp
            gst_rtsp_media_set_clock(media, clock);
        }
    
        // 監聽媒體狀態變更 (播放、暫停、停止)
        g_signal_connect(media, "new-state", G_CALLBACK(media_new_state), NULL);
    }
    
    int main(int argc, char *argv[]) {
        GMainLoop *loop;
        GstRTSPServer *server;
        GstRTSPMountPoints *mounts;
        GstRTSPMediaFactory *factory;
    
        gst_init(&argc, &argv);
        loop = g_main_loop_new(NULL, FALSE);
    
        // 建立 RTSP 伺服器
        server = gst_rtsp_server_new();
        gst_rtsp_server_set_address(server, SERVER_HOST);  // 讓 RTSP 伺服器監聽所有網路介面
        gst_rtsp_server_set_service(server, SERVER_PORT);  // 設定 Port
        gst_rtsp_server_set_backlog(server, SERVER_MAX_CONNECTIONS);  // 設定最大連線數
    
        // 設定 mount point
        mounts = gst_rtsp_server_get_mount_points(server);
        factory = gst_rtsp_media_factory_new();
    
        // 設定 GStreamer pipeline
        gst_rtsp_media_factory_set_launch(factory,
            "( filesrc location=" VIDEO_PATH " ! qtdemux ! h264parse ! "
            "queue max-size-buffers=512 max-size-time=0 max-size-bytes=0 ! "
            "v4l2h264dec ! videoconvert ! "
            "v4l2h264enc bitrate=2000000 gop-size=30 i-period=30 ! "
            "queue max-size-buffers=512 max-size-time=0 max-size-bytes=0 ! "
            "rtph264pay name=pay0 pt=96 config-interval=1 )");
    
        // 設定媒體配置回呼
        g_signal_connect(factory, "media-configure", G_CALLBACK(media_configure), NULL);
    
        // 掛載 stream
        gst_rtsp_mount_points_add_factory(mounts, "/stream", factory);
        g_object_unref(mounts);
    
        // 啟動 RTSP 伺服器
        if (gst_rtsp_server_attach(server, NULL) == 0) {
            g_printerr("Failed to attach the RTSP server\n");
            return -1;
        }
    
        g_print("RTSP server is running at rtsp://%s:%s/stream\n", SERVER_HOST, SERVER_PORT);
        g_main_loop_run(loop);
    
        return 0;
    }
    

     
     
    Build GStreamer RTSP server sample code (GObject-2.0 and GLib-2.0 are required)
    gcc gst_rtsp_server.c -o gst_rtsp_server \
        -I/usr/include/gstreamer-1.0 \
        -I/usr/include/glib-2.0 \
        -I/usr/lib/glib-2.0/include \
        -L/usr/lib \
        -lgstreamer-1.0 \
        -lgstrtspserver-1.0 \
        -lgobject-2.0 \
        -lglib-2.0
    Run the program with debug log:
    GST_DEBUG=3 ./gst_rtsp_server_tda4
    And then open a VLC media play as a client on Windows10 using the URL:
    rtsp://<rtsp_server_ip>:8554/stream