Skip to content

Commit

Permalink
rxrx/sdp: set actual audio specs
Browse files Browse the repository at this point in the history
Instead of deducing from audio parameters, defer the creation until we
receive some audio data.

This complements identical change for RTSP in the commit 41b0388
(2024-08-13).
  • Loading branch information
MartinPulec committed Aug 14, 2024
1 parent 337a771 commit 4964139
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 30 deletions.
26 changes: 3 additions & 23 deletions src/audio/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,6 @@ sdp_send_change_address_message(struct module *root,
free_response(resp);
}

static void
sdp_change_address_callback(void *udata, const char *address)
{
enum module_class path_sender[] = { MODULE_CLASS_AUDIO, MODULE_CLASS_SENDER, MODULE_CLASS_NONE };
sdp_send_change_address_message((module*) udata, path_sender, address);
}

/**
* take care that addrs can also be comma-separated list of addresses !
* @retval 0 state succesfully initialized
Expand Down Expand Up @@ -417,20 +410,6 @@ int audio_init(struct state_audio **ret,
&s->audio_network_device, &len);
}

if ((s->audio_tx_mode & MODE_SENDER) && strcasecmp(opt->proto, "sdp") == 0) {
const audio_codec_params params =
parse_audio_codec_params(opt->codec_cfg);
if (sdp_add_audio(rtp_is_ipv6(s->audio_network_device),
opt->send_port,
IF_NOT_NULL_ELSE(params.sample_rate, kHz48),
audio_capture_channels, params.codec,
sdp_change_address_callback,
get_root_module(common->parent)) != 0) {
MSG(ERROR,"Cannot add audio to SDP!\n");
goto error;
}
}

if ((s->audio_tx_mode & MODE_SENDER) != 0U || "help"s == opt->codec_cfg) {
if ((s->audio_encoder = audio_codec_init_cfg(opt->codec_cfg, AUDIO_CODER)) == nullptr) {
goto error;
Expand Down Expand Up @@ -1070,7 +1049,7 @@ static int find_codec_sample_rate(int sample_rate, const int *supported) {

static void
set_audio_spec_to_vrxtx(struct video_rxtx *vrxtx, audio_frame2 *compressed_frm,
struct rtp *netdev, bool *audio_spec_to_vrxtx_set)
struct rtp *netdev, int tx_port, bool *audio_spec_to_vrxtx_set)
{
if (*audio_spec_to_vrxtx_set) {
return;
Expand All @@ -1085,7 +1064,7 @@ set_audio_spec_to_vrxtx(struct video_rxtx *vrxtx, audio_frame2 *compressed_frm,
audio_desc_to_cstring(desc), rx_port);

assert(vrxtx != nullptr);
vrxtx->set_audio_spec(&desc, rx_port);
vrxtx->set_audio_spec(&desc, rx_port, tx_port, rtp_is_ipv6(netdev));
}

static void *audio_sender_thread(void *arg)
Expand Down Expand Up @@ -1181,6 +1160,7 @@ static void *audio_sender_thread(void *arg)
set_audio_spec_to_vrxtx(
s->vrxtx, &compressed,
s->audio_network_device,
s->audio_network_parameters.send_port,
&audio_spec_to_vrxtx_set);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/video_rxtx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ void video_rxtx::list(bool full)

void
video_rxtx::set_audio_spec(const struct audio_desc * /* desc */,
int /* audio_rx_port */)
int /* audio_rx_port */, int /* audio_tx_port */,
bool /* ipv6 */)
{
MSG(INFO, "video RXTX not h264_rtp, not setting audio...\n");
}
4 changes: 3 additions & 1 deletion src/video_rxtx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ struct video_rxtx {
virtual void join();
static video_rxtx *create(std::string const & name, std::map<std::string, param_u> const &);
static void list(bool full);
virtual void set_audio_spec(const struct audio_desc *desc, int audio_rx_port);
virtual void set_audio_spec(const struct audio_desc *desc,
int audio_rx_port, int audio_tx_port,
bool ipv6);
std::string m_port_id;
protected:
video_rxtx(std::map<std::string, param_u> const &);
Expand Down
3 changes: 2 additions & 1 deletion src/video_rxtx/h264_rtp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ void h264_rtp_video_rxtx::join()

void
h264_rtp_video_rxtx::set_audio_spec(const struct audio_desc *desc,
int audio_rx_port)
int audio_rx_port, int /* audio_tx_port */,
bool /* ipv6 */)
{
rtsp_params.adesc = *desc;
rtsp_params.rtp_port_audio = audio_rx_port;
Expand Down
4 changes: 3 additions & 1 deletion src/video_rxtx/h264_rtp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ class h264_rtp_video_rxtx : public rtp_video_rxtx {
h264_rtp_video_rxtx(std::map<std::string, param_u> const &, int);
virtual ~h264_rtp_video_rxtx();
void join() override;
void set_audio_spec(const struct audio_desc *desc, int audio_rx_port) override;
void set_audio_spec(const struct audio_desc *desc, int audio_rx_port,
int audio_tx_port, bool ipv6) override;

private:
virtual void send_frame(std::shared_ptr<video_frame>) noexcept override;
virtual void *(*get_receiver_thread() noexcept)(void *arg) override {
Expand Down
21 changes: 19 additions & 2 deletions src/video_rxtx/h264_sdp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
#include "video_rxtx.hpp"

#define DEFAULT_SDP_COMPRESSION "lavc:codec=MJPEG:safe"
#define MOD_NAME "[vrxtx/sdp] "

using std::cout;
using std::exception;
Expand Down Expand Up @@ -169,10 +170,26 @@ h264_sdp_video_rxtx::send_frame(shared_ptr<video_frame> tx_frame) noexcept
}
}

static void
sdp_change_address_callback(void *udata, const char *address)
{
const enum module_class path_sender[] = { MODULE_CLASS_AUDIO,
MODULE_CLASS_SENDER,
MODULE_CLASS_NONE };
sdp_send_change_address_message((module *) udata, path_sender, address);
}

void
h264_sdp_video_rxtx::set_audio_spec(const struct audio_desc * /* desc */,
int /* audio_rx_port */)
h264_sdp_video_rxtx::set_audio_spec(const struct audio_desc *desc,
int /* audio_rx_port */, int audio_tx_port, bool ipv6)
{
if (sdp_add_audio(ipv6, audio_tx_port,
desc->sample_rate,
desc->ch_count, desc->codec,
sdp_change_address_callback,
get_root_module(m_common.parent)) != 0) {
MSG(ERROR, "Cannot add audio to SDP!\n");
}
}

static video_rxtx *create_video_rxtx_h264_sdp(std::map<std::string, param_u> const &params)
Expand Down
3 changes: 2 additions & 1 deletion src/video_rxtx/h264_sdp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ class h264_sdp_video_rxtx : public rtp_video_rxtx {
virtual void *(*get_receiver_thread() noexcept)(void *arg) override {
return nullptr;
}
void set_audio_spec(const struct audio_desc *desc, int audio_rx_port) override;
void set_audio_spec(const struct audio_desc *desc, int audio_rx_port,
int audio_tx_port, bool ipv6) override;
void sdp_add_video(codec_t codec);
codec_t m_sdp_configured_codec = VIDEO_CODEC_NONE;
int m_saved_tx_port;
Expand Down

0 comments on commit 4964139

Please sign in to comment.