Skip to content

Commit 4a92c72

Browse files
committed
get rid of additional_audio_data
set in struct audio_options instead
1 parent cf9ef6e commit 4a92c72

7 files changed

Lines changed: 70 additions & 106 deletions

File tree

src/audio/audio.cpp

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ struct state_audio {
187187
double volume = 1.0; // receiver volume scale
188188
bool muted_receiver = false;
189189
bool muted_sender = false;
190-
bool playback_is_sdi = false; // delegating to vdisplay
191190

192191
size_t recv_buf_size = DEFAULT_AUDIO_RECV_BUF_SIZE;
193192

@@ -295,7 +294,7 @@ audio_init_real(struct state_audio *s, const struct audio_options *opt,
295294

296295
s->audio_channel_map = opt->channel_map;
297296
s->audio_scale = opt->scale;
298-
297+
s->vrxtx = opt->vrxtx;
299298
s->resample_to = parse_audio_codec_params(opt->codec_cfg).sample_rate;
300299

301300
s->exporter = common->exporter;
@@ -385,11 +384,19 @@ audio_init_real(struct state_audio *s, const struct audio_options *opt,
385384
opts.parent = s->audio_receiver_module.get();
386385
int ret =
387386
audio_playback_init(playback_dev, &opts, &s->audio_playback_device);
388-
s->playback_is_sdi = (bool) audio_get_display_flags(playback_dev);
387+
bool playback_is_sdi = (audio_get_display_flags(playback_dev) &
388+
DISPLAY_FLAG_AUDIO_ANY) != 0U;
389389
free(playback_dev);
390390
if (ret != 0) {
391391
return ret;
392392
}
393+
if (playback_is_sdi) {
394+
auto *sdi_playback = (struct state_sdi_playback *)
395+
audio_playback_get_state_pointer(s->audio_playback_device);
396+
sdi_register_display_callbacks(
397+
sdi_playback, opt->display, display_put_audio_frame,
398+
display_reconfigure_audio, display_ctl_property);
399+
}
393400

394401
if (s->audio_tx_mode != 0) {
395402
if ((s->audio_network_device = initialize_audio_network(
@@ -1205,27 +1212,6 @@ void audio_sdi_send(struct state_audio *s, struct audio_frame *frame) {
12051212
sdi_capture_new_incoming_frame(sdi_capture, frame);
12061213
}
12071214

1208-
void
1209-
audio_register_aux_data(struct state_audio *s,
1210-
struct additional_audio_data data)
1211-
{
1212-
s->vrxtx = data.vrxtx;
1213-
if (!s->playback_is_sdi) {
1214-
return;
1215-
}
1216-
auto *sdi_playback =
1217-
(struct state_sdi_playback *) audio_playback_get_state_pointer(
1218-
s->audio_playback_device);
1219-
sdi_register_display_callbacks(
1220-
sdi_playback, data.display_callbacks.udata,
1221-
(void (*)(void *,
1222-
const struct audio_frame *)) data.display_callbacks.putf,
1223-
(bool (*)(void *, int, int,
1224-
int)) data.display_callbacks.reconfigure,
1225-
(bool (*)(void *, int, void *,
1226-
size_t *)) data.display_callbacks.get_property);
1227-
}
1228-
12291215
unsigned int
12301216
audio_get_display_flags(const char *playback_dev)
12311217
{

src/audio/audio.h

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,21 @@
6262
struct state_audio;
6363

6464
struct audio_options {
65-
const char *host;
66-
int recv_port;
67-
int send_port;
68-
const char *recv_cfg;
69-
const char *send_cfg;
70-
const char *proto;
71-
const char *proto_cfg;
72-
const char *fec_cfg;
73-
char *channel_map;
74-
const char *scale;
75-
bool echo_cancellation;
76-
const char *codec_cfg;
77-
const char *filter_cfg;
65+
const char *host;
66+
int recv_port;
67+
int send_port;
68+
const char *recv_cfg;
69+
const char *send_cfg;
70+
const char *proto;
71+
const char *proto_cfg;
72+
const char *fec_cfg;
73+
char *channel_map;
74+
const char *scale;
75+
bool echo_cancellation;
76+
const char *codec_cfg;
77+
const char *filter_cfg;
78+
struct video_rxtx *vrxtx;
79+
struct display *display;
7880
};
7981

8082
#define AUDIO_OPTIONS_INIT \
@@ -92,6 +94,8 @@ struct audio_options {
9294
.echo_cancellation = false, \
9395
.codec_cfg = "PCM", \
9496
.filter_cfg = "", \
97+
.vrxtx = nullptr, \
98+
.display = nullptr, \
9599
}
96100

97101
#ifdef __cplusplus
@@ -110,20 +114,6 @@ void audio_sdi_send(struct state_audio *s, struct audio_frame *frame);
110114
struct audio_frame * sdi_get_frame(void *state);
111115
void sdi_put_frame(void *state, struct audio_frame *frame);
112116

113-
struct display;
114-
struct video_rxtx;
115-
struct additional_audio_data {
116-
struct {
117-
void *udata;
118-
void (*putf)(struct display *, const struct audio_frame *);
119-
bool (*reconfigure)(struct display *, int, int, int);
120-
bool (*get_property)(struct display *, int, void *, size_t *);
121-
} display_callbacks;
122-
struct video_rxtx *vrxtx;
123-
};
124-
void audio_register_aux_data(struct state_audio *s,
125-
struct additional_audio_data data);
126-
127117
struct audio_frame * audio_get_frame(struct state_audio *s);
128118

129119
unsigned int audio_get_display_flags(const char *playback_dev);

src/audio/audio_playback.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ bool audio_playback_reconfigure(struct state_audio_playback *state,
136136
int quant_samples, int channels,
137137
int sample_rate);
138138
void audio_playback_put_frame(struct state_audio_playback *state, const struct audio_frame *frame);
139-
void audio_playback_finish(struct state_audio_playback *state);
140139
void audio_playback_done(struct state_audio_playback *state);
141140

142141
/**

src/audio/playback/sdi.c

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @author Martin Pulec <pulec@cesnet.cz>
44
*/
55
/*
6-
* Copyright (c) 2011-2023 CESNET z.s.p.o.
6+
* Copyright (c) 2011-2026 CESNET zájmové sdružení právnických osob
77
* All rights reserved.
88
*
99
* Redistribution and use in source and binary forms, with or without
@@ -50,11 +50,11 @@
5050
#include "video_display.h"
5151

5252
struct state_sdi_playback {
53-
void *udata;
54-
void (*put_callback)(void *, const struct audio_frame *);
55-
bool (*reconfigure_callback)(void *state, int quant_samples,
53+
struct display *display;
54+
void (*put_callback)(struct display *, const struct audio_frame *);
55+
bool (*reconfigure_callback)(struct display *state, int quant_samples,
5656
int channels, int sample_rate);
57-
bool (*get_property_callback)(void *, int, void *, size_t *);
57+
bool (*get_property_callback)(struct display *, int, void *, size_t *);
5858
};
5959

6060
static void audio_play_sdi_probe_common(struct device_info **available_devices, int *count,
@@ -113,16 +113,16 @@ audio_play_sdi_init(const struct audio_playback_opts *opts)
113113
}
114114

115115
void
116-
sdi_register_display_callbacks(void *state, void *udata,
117-
void (*putf)(void *, const struct audio_frame *),
118-
bool (*reconfigure)(void *, int, int, int),
119-
bool (*get_property)(void *, int, void *,
120-
size_t *))
116+
sdi_register_display_callbacks(
117+
void *state, struct display *display,
118+
void (*putf)(struct display *, const struct audio_frame *),
119+
bool (*reconfigure)(struct display *, int, int, int),
120+
bool (*get_property)(struct display *, int, void *, size_t *))
121121
{
122-
struct state_sdi_playback *s = (struct state_sdi_playback *) state;
123-
124-
s->udata = udata;
125-
s->put_callback = putf;
122+
struct state_sdi_playback *s = state;
123+
124+
s->display = display;
125+
s->put_callback = putf;
126126
s->reconfigure_callback = reconfigure;
127127
s->get_property_callback = get_property;
128128
}
@@ -133,24 +133,23 @@ static void audio_play_sdi_put_frame(void *state, const struct audio_frame *fram
133133
s = (struct state_sdi_playback *) state;
134134

135135
if(s->put_callback)
136-
s->put_callback(s->udata, frame);
136+
s->put_callback(s->display, frame);
137137
}
138138

139139
static bool audio_play_sdi_query_format(struct state_sdi_playback *s, void *data, size_t *len)
140140
{
141-
if (s->get_property_callback(s->udata, DISPLAY_PROPERTY_AUDIO_FORMAT, data, len)) {
141+
if (s->get_property_callback(s->display, DISPLAY_PROPERTY_AUDIO_FORMAT, data, len)) {
142142
return true;
143-
} else {
144-
log_msg(LOG_LEVEL_WARNING, "Cannot get audio format from playback card!\n");
145-
struct audio_desc desc = {2, 48000, 2, AC_PCM};
146-
if (*len >= sizeof desc) {
147-
memcpy(data, &desc, sizeof desc);
148-
*len = sizeof desc;
149-
return true;
150-
} else {
151-
return false;
152-
}
153143
}
144+
log_msg(LOG_LEVEL_WARNING,
145+
"Cannot get audio format from playback card!\n");
146+
struct audio_desc desc = { 2, 48000, 2, AC_PCM };
147+
if (*len < sizeof desc) {
148+
return false;
149+
}
150+
memcpy(data, &desc, sizeof desc);
151+
*len = sizeof desc;
152+
return true;
154153
}
155154

156155
static bool audio_play_sdi_ctl(void *state, int request, void *data, size_t *len)
@@ -169,7 +168,7 @@ static bool audio_play_sdi_reconfigure(void *state, struct audio_desc desc)
169168
struct state_sdi_playback *s = state;
170169

171170
if(s->reconfigure_callback) {
172-
return s->reconfigure_callback(s->udata, desc.bps * 8,
171+
return s->reconfigure_callback(s->display, desc.bps * 8,
173172
desc.ch_count, desc.sample_rate);
174173
}
175174
return false;

src/audio/playback/sdi.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @author Martin Pulec <martin.pulec@cesnet.cz>
44
*/
55
/*
6-
* Copyright (c) 2012-2023 CESNET, z. s. p. o.
6+
* Copyright (c) 2012-2026 CESNET, zájmové sdružení právnických osob
77
* All rights reserved.
88
*
99
* Redistribution and use in source and binary forms, with or without
@@ -44,11 +44,13 @@ extern "C" {
4444
#endif
4545

4646
struct audio_frame;
47+
struct display;
4748

48-
void sdi_register_display_callbacks(
49-
void *state, void *udata, void (*putf)(void *, const struct audio_frame *),
50-
bool (*reconfigure)(void *, int, int, int),
51-
bool (*get_property)(void *, int, void *, size_t *));
49+
void sdi_register_display_callbacks(
50+
void *state, struct display *display,
51+
void (*putf)(struct display *, const struct audio_frame *),
52+
bool (*reconfigure)(struct display *, int, int, int),
53+
bool (*get_property)(struct display *, int, void *, size_t *));
5254

5355
#ifdef __cplusplus
5456
}

src/main.cpp

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1422,12 +1422,6 @@ int main(int argc, char *argv[])
14221422
}
14231423
}
14241424

1425-
ret = audio_init(&uv.audio, &opt.audio, &opt.common);
1426-
if (ret != 0) {
1427-
exit_uv(ret < 0 ? EXIT_FAIL_AUDIO : 0);
1428-
goto cleanup;
1429-
}
1430-
14311425
display_flags |= audio_get_display_flags(opt.audio.recv_cfg);
14321426

14331427
// Display initialization should be prior to modules that may use graphic card (eg. GLSL) in order
@@ -1494,6 +1488,14 @@ int main(int argc, char *argv[])
14941488
}
14951489
}
14961490

1491+
opt.audio.vrxtx = uv.state_video_rxtx;
1492+
opt.audio.display = uv.display_device;
1493+
ret = audio_init(&uv.audio, &opt.audio, &opt.common);
1494+
if (ret != 0) {
1495+
exit_uv(ret < 0 ? EXIT_FAIL_AUDIO : 0);
1496+
goto cleanup;
1497+
}
1498+
14971499
if ((opt.video.rxtx_mode & MODE_RECEIVER) != 0U) {
14981500
if (!uv.state_video_rxtx->supports_receiving()) {
14991501
fprintf(stderr, "Selected RX/TX mode doesn't support receiving.\n");
@@ -1520,13 +1522,6 @@ int main(int argc, char *argv[])
15201522
}
15211523
}
15221524

1523-
struct additional_audio_data aux = {
1524-
{ uv.display_device, display_put_audio_frame,
1525-
display_reconfigure_audio, display_ctl_property },
1526-
uv.state_video_rxtx,
1527-
};
1528-
audio_register_aux_data(uv.audio, aux);
1529-
15301525
if (opt.requested_capabilities != nullptr) {
15311526
print_capabilities(opt.requested_capabilities);
15321527
exit_uv(EXIT_SUCCESS);

src/video_capture/ug_input.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -192,21 +192,14 @@ static int vidcap_ug_input_init(const struct vidcap_params *cap_params, void **s
192192
opt.send_port = 0;
193193
opt.recv_cfg = "embedded";
194194
opt.proto = "ultragrid_rtp";
195+
opt.display = s->display;
196+
opt.vrxtx = s->video_rxtx.get();
195197

196198
if (audio_init(&s->audio, &opt, &s->common) != 0) {
197199
delete s;
198200
return VIDCAP_INIT_FAIL;
199201
}
200202

201-
struct additional_audio_data aux_aud_data = {
202-
{ s->display, display_put_audio_frame,
203-
display_reconfigure_audio, display_ctl_property
204-
205-
},
206-
s->video_rxtx.get()
207-
};
208-
audio_register_aux_data(s->audio, aux_aud_data);
209-
210203
audio_start(s->audio);
211204
}
212205
s->t0 = steady_clock::now();

0 commit comments

Comments
 (0)