Skip to content

Commit 1b2d778

Browse files
committed
vrxtx/rtp: refactor the rtp common state
- no longer a class but merely a POD struct - aggregate rather than inherite from this struct
1 parent b85cd20 commit 1b2d778

9 files changed

Lines changed: 232 additions & 190 deletions

File tree

src/hd-rum-translator/hd-rum-decompress.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,8 @@ ssize_t hd_rum_decompress_write(void *state, void *buf, size_t count)
137137
{
138138
auto *s = static_cast<state_transcoder_decompress *>(state);
139139

140-
auto *ultragrid_rtp = static_cast<ultragrid_rtp_video_rxtx *>(
141-
vrxtx_get_impl_state(s->video_rxtx));
142-
assert(ultragrid_rtp != nullptr);
143-
return rtp_send_raw_rtp_data(ultragrid_rtp->m_network_device,
144-
(char *) buf, count);
140+
return ultragrid_rtp_send_raw_rtp_data(
141+
vrxtx_get_impl_state(s->video_rxtx), (char *) buf, count);
145142
}
146143

147144
void state_transcoder_decompress::worker()

src/video_rxtx/h264_rtp.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ using std::shared_ptr;
6969

7070
h264_rtp_video_rxtx::h264_rtp_video_rxtx(const struct vrxtx_params *params,
7171
const struct common_opts *common, int rtsp_port) :
72-
rtp_video_rxtx(params, common),
7372
m_parent(common->parent),
7473
m_start_time(common->start_time)
7574
{
@@ -86,6 +85,7 @@ h264_rtp_video_rxtx::h264_rtp_video_rxtx(const struct vrxtx_params *params,
8685
rtsp_params.avType = avType;;
8786

8887
rtsp_params.rtp_port_video = params->rx_port; //server rtp port
88+
m_rtp_common = rtp_rxtx_common_init(params, common);
8989
}
9090

9191
/**
@@ -128,7 +128,7 @@ h264_rtp_video_rxtx::configure_rtsp_server_video()
128128
void
129129
h264_rtp_video_rxtx::send_frame(shared_ptr<video_frame> tx_frame) noexcept
130130
{
131-
rtp_process_sender_messages();
131+
rtp_process_sender_messages(m_rtp_common);
132132
// requestt compress reconfiguration if receivng raw data
133133
if (!is_codec_opaque(tx_frame->color_spec)) {
134134
if (!m_sent_compress_change) {
@@ -152,25 +152,27 @@ h264_rtp_video_rxtx::send_frame(shared_ptr<video_frame> tx_frame) noexcept
152152
return;
153153
}
154154

155-
tx_send_std(m_tx, tx_frame.get(), m_network_device);
155+
tx_send_std(m_rtp_common->tx, tx_frame.get(),
156+
m_rtp_common->network_device);
156157

157-
if ((m_rxtx_mode & MODE_RECEIVER) == 0) { // send RTCP (receiver thread would otherwise do this
158+
if (m_rtp_common->rxtx_mode & MODE_RECEIVER) { // send RTCP (receiver thread would otherwise do this
158159
time_ns_t curr_time = get_time_in_ns();
159160
uint32_t ts = (curr_time - m_start_time) / 100'000 * 9; // at 90000 Hz
160-
rtp_update(m_network_device, curr_time);
161-
rtp_send_ctrl(m_network_device, ts, nullptr, curr_time);
161+
rtp_update(m_rtp_common->network_device, curr_time);
162+
rtp_send_ctrl(m_rtp_common->network_device, ts, nullptr, curr_time);
162163

163164
// receive RTCP
164165
struct timeval timeout;
165166
timeout.tv_sec = 0;
166167
timeout.tv_usec = 0;
167-
rtp_recv_r(m_network_device, &timeout, ts);
168+
rtp_recv_r(m_rtp_common->network_device, &timeout, ts);
168169
}
169170
}
170171

171172
h264_rtp_video_rxtx::~h264_rtp_video_rxtx()
172173
{
173174
free(m_rtsp_server);
175+
rtp_rxtx_common_done(m_rtp_common);
174176
}
175177

176178
void h264_rtp_video_rxtx::join()

src/video_rxtx/h264_rtp.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,18 @@
5252

5353
struct video_frame;
5454

55-
class h264_rtp_video_rxtx : public rtp_video_rxtx {
55+
class h264_rtp_video_rxtx {
5656
public:
5757
h264_rtp_video_rxtx(const struct vrxtx_params *params,
5858
const struct common_opts *common, int rtsp_port);
59-
virtual ~h264_rtp_video_rxtx();
59+
~h264_rtp_video_rxtx();
6060
void join();
6161
void set_audio_spec(const struct audio_desc *desc, int audio_rx_port,
6262
int audio_tx_port, bool ipv6);
63-
virtual void send_frame(std::shared_ptr<video_frame>) noexcept;
63+
void send_frame(std::shared_ptr<video_frame>) noexcept;
6464

6565
private:
66+
struct rtp_rxtx_common *m_rtp_common;
6667
void configure_rtsp_server_video();
6768
struct rtsp_server_parameters rtsp_params{};
6869
std::atomic<bool> audio_params_set = false;

src/video_rxtx/h264_sdp.cpp

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,23 @@ using std::string;
7272

7373
h264_sdp_video_rxtx::h264_sdp_video_rxtx(const struct vrxtx_params *params,
7474
const struct common_opts *common)
75-
: rtp_video_rxtx(params, common),
76-
m_parent(common->parent)
75+
: m_parent(common->parent)
7776
{
7877
auto opts = params->protocol_opts;
7978
LOG(LOG_LEVEL_WARNING) << "Warning: SDP support is experimental only. Things may be broken - feel free to report them but the support may be limited.\n";
80-
m_saved_addr = m_requested_receiver;
8179
m_saved_tx_port = params->tx_port;
8280

8381
sdp_set_properties(common->receiver, params->send_video, params->send_audio);
8482

8583
if (int ret = sdp_set_options(opts)) {
8684
throw ret == 1 ? 0 : 1;
8785
}
86+
m_rtp_common = rtp_rxtx_common_init(params, common);
87+
m_saved_addr = m_rtp_common->requested_receiver;
88+
}
89+
90+
h264_sdp_video_rxtx::~h264_sdp_video_rxtx() {
91+
rtp_rxtx_common_done(m_rtp_common);
8892
}
8993

9094
void h264_sdp_video_rxtx::change_address_callback(void *udata, const char *address)
@@ -104,7 +108,7 @@ void h264_sdp_video_rxtx::change_address_callback(void *udata, const char *addre
104108
void h264_sdp_video_rxtx::sdp_add_video(codec_t codec)
105109
{
106110
const int rc = ::sdp_add_video(
107-
rtp_is_ipv6(m_network_device), m_saved_tx_port, codec,
111+
rtp_is_ipv6(m_rtp_common->network_device), m_saved_tx_port, codec,
108112
h264_sdp_video_rxtx::change_address_callback, this);
109113
if (rc == -2) {
110114
throw ug_runtime_error("[SDP] Unsupported video codec for SDP (allowed H.264 and JPEG)!\n");
@@ -123,7 +127,7 @@ void h264_sdp_video_rxtx::sdp_add_video(codec_t codec)
123127
void
124128
h264_sdp_video_rxtx::send_frame(shared_ptr<video_frame> tx_frame) noexcept
125129
{
126-
rtp_process_sender_messages();
130+
rtp_process_sender_messages(m_rtp_common);
127131
if (!is_codec_opaque(tx_frame->color_spec)) {
128132
if (m_sent_compress_change) {
129133
return;
@@ -149,22 +153,24 @@ h264_sdp_video_rxtx::send_frame(shared_ptr<video_frame> tx_frame) noexcept
149153
}
150154

151155
if (m_sdp_configured_codec == H264) {
152-
tx_send_h264(m_tx, tx_frame.get(), m_network_device);
156+
tx_send_h264(m_rtp_common->tx, tx_frame.get(),
157+
m_rtp_common->network_device);
153158
} else {
154-
tx_send_jpeg(m_tx, tx_frame.get(), m_network_device);
159+
tx_send_jpeg(m_rtp_common->tx, tx_frame.get(),
160+
m_rtp_common->network_device);
155161
}
156-
if ((m_rxtx_mode & MODE_RECEIVER) ==
157-
0) { // send RTCP (receiver thread would otherwise do this)
162+
if (m_rtp_common->rxtx_mode & MODE_RECEIVER) {
163+
// send RTCP (receiver thread would otherwise do this)
158164
uint32_t ts = get_std_video_local_mediatime();
159165
time_ns_t curr_time = get_time_in_ns();
160-
rtp_update(m_network_device, curr_time);
161-
rtp_send_ctrl(m_network_device, ts, nullptr, curr_time);
166+
rtp_update(m_rtp_common->network_device, curr_time);
167+
rtp_send_ctrl(m_rtp_common->network_device, ts, nullptr, curr_time);
162168

163169
// receive RTCP
164170
struct timeval timeout;
165171
timeout.tv_sec = 0;
166172
timeout.tv_usec = 0;
167-
rtp_recv_r(m_network_device, &timeout, ts);
173+
rtp_recv_r(m_rtp_common->network_device, &timeout, ts);
168174
}
169175
}
170176

src/video_rxtx/h264_sdp.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,16 @@
4848
#include "types.h" // for VIDEO_CODEC_NONE, codec_t, video_frame...
4949
#include "video_rxtx/rtp.hpp"
5050

51-
class h264_sdp_video_rxtx : public rtp_video_rxtx {
51+
class h264_sdp_video_rxtx {
5252
public:
5353
h264_sdp_video_rxtx(const struct vrxtx_params *params,
5454
const struct common_opts *common);
55-
~h264_sdp_video_rxtx() override = default;
56-
virtual void send_frame(std::shared_ptr<video_frame>) noexcept;
55+
~h264_sdp_video_rxtx();
56+
void send_frame(std::shared_ptr<video_frame>) noexcept;
5757
void set_audio_spec(const struct audio_desc *desc, int audio_rx_port,
5858
int audio_tx_port, bool ipv6);
5959
private:
60+
struct rtp_rxtx_common *m_rtp_common;
6061
static void change_address_callback(void *udata, const char *address);
6162
void sdp_add_video(codec_t codec);
6263
codec_t m_sdp_configured_codec = VIDEO_CODEC_NONE;

0 commit comments

Comments
 (0)