From 75f86ba6c5204dc60c78366c0cd33a223d1955ae Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Thu, 1 Aug 2024 11:55:38 +0200 Subject: [PATCH] rxtx/rtsp: delay server creation + tx callback We pass the video_codec as RTSP parameters but until we receive first frame we cannot know the actual codec, so that delay the creation until we receive the first frame. --- src/rtsp/c_basicRTSPOnlyServer.cpp | 3 +++ src/video_rxtx/h264_rtp.cpp | 22 +++++++++++++++------- src/video_rxtx/h264_rtp.hpp | 8 +++++++- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/rtsp/c_basicRTSPOnlyServer.cpp b/src/rtsp/c_basicRTSPOnlyServer.cpp index 77885504b..d81b92885 100644 --- a/src/rtsp/c_basicRTSPOnlyServer.cpp +++ b/src/rtsp/c_basicRTSPOnlyServer.cpp @@ -64,6 +64,9 @@ c_start_server(struct rtsp_server_parameters params) } void c_stop_server(rtsp_serv_t* server){ + if (server == nullptr) { + return; + } server->watch = 1; pthread_join(server->server_th, nullptr); } diff --git a/src/video_rxtx/h264_rtp.cpp b/src/video_rxtx/h264_rtp.cpp index 8bcb19c2f..18ed5731b 100644 --- a/src/video_rxtx/h264_rtp.cpp +++ b/src/video_rxtx/h264_rtp.cpp @@ -75,19 +75,27 @@ h264_rtp_video_rxtx::h264_rtp_video_rxtx(std::map const &p rtsp_params.rtp_port = params.at("rx_port").i; //server rtp port rtsp_params.rtp_port_audio = params.at("a_rx_port").i; rtsp_params.video_codec = H264; - - m_rtsp_server = c_start_server(rtsp_params); } void h264_rtp_video_rxtx::send_frame(shared_ptr tx_frame) noexcept { - if (tx_frame->color_spec != H264) { - MSG(ERROR, - "codecs other than H.264 currently not supported, got %s\n", - get_codec_name(tx_frame->color_spec)); + if (m_rtsp_server == nullptr) { + if (tx_frame->color_spec == H264) { + tx_send_std = tx_send_h264; + } else { + MSG(ERROR, + "codecs other than H.264 currently not " + "supported, got %s\n", + get_codec_name(tx_frame->color_spec)); + return; + } + rtsp_params.video_codec = tx_frame->color_spec; + m_rtsp_server = c_start_server(rtsp_params); } - tx_send_h264(m_tx, tx_frame.get(), m_network_device); + + tx_send_std(m_tx, tx_frame.get(), m_network_device); + if ((m_rxtx_mode & MODE_RECEIVER) == 0) { // send RTCP (receiver thread would otherwise do this time_ns_t curr_time = get_time_in_ns(); uint32_t ts = (curr_time - m_start_time) / 100'000 * 9; // at 90000 Hz diff --git a/src/video_rxtx/h264_rtp.hpp b/src/video_rxtx/h264_rtp.hpp index 88216a588..1636eb4f3 100644 --- a/src/video_rxtx/h264_rtp.hpp +++ b/src/video_rxtx/h264_rtp.hpp @@ -46,6 +46,10 @@ #include "video_rxtx.hpp" #include "video_rxtx/rtp.hpp" +struct rtp; +struct tx; +struct video_frame; + class h264_rtp_video_rxtx : public rtp_video_rxtx { public: h264_rtp_video_rxtx(std::map const &, int); @@ -57,7 +61,9 @@ private: return NULL; } struct rtsp_server_parameters rtsp_params; - rtsp_serv_t *m_rtsp_server; + rtsp_serv_t *m_rtsp_server = nullptr; + void (*tx_send_std)(struct tx *tx_session, struct video_frame *frame, + struct rtp *rtp_session); }; #endif // VIDEO_RXTX_H264_RTP_H_