Skip to content

Commit

Permalink
modernize playback APIs
Browse files Browse the repository at this point in the history
THe APIs were already recently updated so modernize it by using bool
where the return value is semantically boolean value. Using TRUE/FALSE is
inherently ambiguous because it is not obvious from the prototype if
success is 0 or TRUE (1).
  • Loading branch information
MartinPulec committed Jul 18, 2023
1 parent 2748e36 commit 05c71ba
Show file tree
Hide file tree
Showing 57 changed files with 398 additions and 376 deletions.
6 changes: 3 additions & 3 deletions src/aja_win32_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ static const struct video_capture_info vidcap_aja_info = {
REGISTER_MODULE(aja, &vidcap_aja_info, LIBRARY_CLASS_VIDEO_CAPTURE, VIDEO_CAPTURE_ABI_VERSION);

extern "C" {
__declspec(dllimport) int display_aja_get_property(void *state, int property, void *val, size_t *len);
__declspec(dllimport) bool display_aja_get_property(void *state, int property, void *val, size_t *len);
__declspec(dllimport) void display_aja_probe(struct device_info **available_cards, int *count, void (**deleter)(void *));
__declspec(dllimport) int display_aja_reconfigure(void *state, struct video_desc desc);
__declspec(dllimport) bool display_aja_reconfigure(void *state, struct video_desc desc);
__declspec(dllimport) void *display_aja_init(struct module * /* parent */, const char *fmt, unsigned int flags);
__declspec(dllimport) void display_aja_done(void *state);
__declspec(dllimport) struct video_frame *display_aja_getf(void *state);
__declspec(dllimport) bool display_aja_putf(void *state, struct video_frame *frame, long long nonblock);
__declspec(dllimport) void display_aja_put_audio_frame(void *state, const struct audio_frame *frame);
__declspec(dllimport) int display_aja_reconfigure_audio(void *state, int quant_samples, int channels,
__declspec(dllimport) bool display_aja_reconfigure_audio(void *state, int quant_samples, int channels,
int sample_rate);
}

Expand Down
8 changes: 7 additions & 1 deletion src/audio/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1128,7 +1128,13 @@ void audio_sdi_send(struct state_audio *s, struct audio_frame *frame) {
sdi_capture_new_incoming_frame(sdi_capture, frame);
}

void audio_register_display_callbacks(struct state_audio *s, void *udata, void (*putf)(void *, const struct audio_frame *), int (*reconfigure)(void *, int, int, int), int (*get_property)(void *, int, void *, size_t *))
void
audio_register_display_callbacks(struct state_audio *s, void *udata,
void (*putf)(void *,
const struct audio_frame *),
bool (*reconfigure)(void *, int, int, int),
bool (*get_property)(void *, int, void *,
size_t *))
{
struct state_sdi_playback *sdi_playback;
if(!audio_playback_get_display_flags(s->audio_playback_device))
Expand Down
7 changes: 6 additions & 1 deletion src/audio/audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,12 @@ void audio_join(struct state_audio *s);
void audio_sdi_send(struct state_audio *s, struct audio_frame *frame);
struct audio_frame * sdi_get_frame(void *state);
void sdi_put_frame(void *state, struct audio_frame *frame);
void audio_register_display_callbacks(struct state_audio *s, void *udata, void (*putf)(void *, const struct audio_frame *), int (*reconfigure)(void *, int, int, int), int (*get_property)(void *, int, void *, size_t *));
void audio_register_display_callbacks(struct state_audio *s, void *udata,
void (*putf)(void *,
const struct audio_frame *),
bool (*reconfigure)(void *, int, int, int),
bool (*get_property)(void *, int, void *,
size_t *));

struct audio_frame * audio_get_frame(struct state_audio *s);

Expand Down
2 changes: 1 addition & 1 deletion src/audio/audio_playback.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ bool audio_playback_ctl(struct state_audio_playback *s, int request, void *data,
return s->funcs->ctl(s->state, request, data, len);
}

int audio_playback_reconfigure(struct state_audio_playback *s, int quant_samples, int channels,
bool audio_playback_reconfigure(struct state_audio_playback *s, int quant_samples, int channels,
int sample_rate)
{
return s->funcs->reconfigure(s->state, (struct audio_desc){quant_samples / 8, sample_rate, channels, AC_PCM});
Expand Down
14 changes: 7 additions & 7 deletions src/audio/audio_playback.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ struct audio_frame;

#ifdef __cplusplus
extern "C" {
#else
#include <stdbool.h>
#endif

#define AUDIO_PLAYBACK_ABI_VERSION 10
#define AUDIO_PLAYBACK_ABI_VERSION 11

/** @anchor audio_playback_ctl_reqs
* @name Audio playback control requests
Expand Down Expand Up @@ -81,7 +83,7 @@ struct audio_playback_info {
void (*write)(void *state, const struct audio_frame *frame);
/** Returns device supported format that matches best with propsed audio desc */
bool (*ctl)(void *state, int request, void *data, size_t *len);
int (*reconfigure)(void *state, struct audio_desc);
bool (*reconfigure)(void *state, struct audio_desc);
void (*done)(void *state);
};

Expand Down Expand Up @@ -114,12 +116,10 @@ bool audio_playback_ctl(struct state_audio_playback *s, int request, void *data,
* @param[in] quant_samples number of quantization bits
* @param[in] channels number of channels to be played back
* @param[in] sample_rate sample rate
* @retval TRUE if reconfiguration succeeded
* @retval FALSE if reconfiguration failed
*/
int audio_playback_reconfigure(struct state_audio_playback *state,
int quant_samples, int channels,
int sample_rate);
bool audio_playback_reconfigure(struct state_audio_playback *state,
int quant_samples, int channels,
int sample_rate);
void audio_playback_put_frame(struct state_audio_playback *state, const struct audio_frame *frame);
void audio_playback_finish(struct state_audio_playback *state);
void audio_playback_done(struct state_audio_playback *state);
Expand Down
20 changes: 10 additions & 10 deletions src/audio/playback/alsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ ADD_TO_PARAM("alsa-play-period-size", "* alsa-play-period-size=<frames>\n"
* with PulseAudio. However, may underrun with different drivers/devices (Juli@?) where
* the buffer size is significantly lower.
*/
static int audio_play_alsa_reconfigure(void *state, struct audio_desc desc)
static bool audio_play_alsa_reconfigure(void *state, struct audio_desc desc)
{
struct state_alsa_playback *s = (struct state_alsa_playback *) state;
snd_pcm_hw_params_t *params;
Expand Down Expand Up @@ -479,7 +479,7 @@ static int audio_play_alsa_reconfigure(void *state, struct audio_desc desc)
if (rc < 0) {
log_msg(LOG_LEVEL_ERROR, MOD_NAME "cannot obtain default hw parameters: %s\n",
snd_strerror(rc));
return FALSE;
return false;
}

/* Set the desired hardware parameters. */
Expand All @@ -495,7 +495,7 @@ static int audio_play_alsa_reconfigure(void *state, struct audio_desc desc)
if (rc < 0) {
log_msg(LOG_LEVEL_ERROR, MOD_NAME "cannot set non-interleaved hw access: %s\n",
snd_strerror(rc));
return FALSE;
return false;
}
s->non_interleaved = true;
} else {
Expand All @@ -505,7 +505,7 @@ static int audio_play_alsa_reconfigure(void *state, struct audio_desc desc)
if (desc.bps > 4 || desc.bps < 1) {
log_msg(LOG_LEVEL_ERROR, MOD_NAME "Unsupported BPS for audio (%d).\n",
desc.bps * 8);
return FALSE;
return false;

}
format = bps_to_snd_fmts[desc.bps];
Expand All @@ -516,15 +516,15 @@ static int audio_play_alsa_reconfigure(void *state, struct audio_desc desc)
if (rc < 0) {
log_msg(LOG_LEVEL_ERROR, MOD_NAME "cannot set format: %s\n",
snd_strerror(rc));
return FALSE;
return false;
}

/* Two channels (stereo) */
rc = snd_pcm_hw_params_set_channels(s->handle, params, desc.ch_count);
if (rc < 0) {
log_msg(LOG_LEVEL_ERROR, MOD_NAME "cannot set requested channel count: %s\n",
snd_strerror(rc));
return FALSE;
return false;
}

/* we want to resample if device doesn't support default sample rate */
Expand All @@ -545,7 +545,7 @@ static int audio_play_alsa_reconfigure(void *state, struct audio_desc desc)
if (rc < 0) {
log_msg(LOG_LEVEL_ERROR, MOD_NAME "cannot set requested sample rate: %s\n",
snd_strerror(rc));
return FALSE;
return false;
}

/* Set period to its minimal size.
Expand Down Expand Up @@ -599,7 +599,7 @@ static int audio_play_alsa_reconfigure(void *state, struct audio_desc desc)
if (rc < 0) {
log_msg(LOG_LEVEL_ERROR, MOD_NAME "unable to set hw parameters: %s\n",
snd_strerror(rc));
return FALSE;
return false;
}

snd_pcm_hw_params_current(s->handle, params);
Expand Down Expand Up @@ -653,9 +653,9 @@ static int audio_play_alsa_reconfigure(void *state, struct audio_desc desc)
}
}

return TRUE;
return true;
error:
return FALSE;
return false;
}

static void audio_play_alsa_probe(struct device_info **available_devices, int *count, void (**deleter)(void *))
Expand Down
6 changes: 3 additions & 3 deletions src/audio/playback/coreaudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ static bool audio_play_ca_ctl(void *state [[gnu::unused]], int request, void *da

ADD_TO_PARAM("ca-disable-adaptive-buf", "* ca-disable-adaptive-buf\n"
" Core Audio - use fixed audio playback buffer instead of an adaptive one\n");
static int audio_play_ca_reconfigure(void *state, struct audio_desc desc)
static bool audio_play_ca_reconfigure(void *state, struct audio_desc desc)
{
struct state_ca_playback *s = (struct state_ca_playback *)state;
AudioStreamBasicDescription stream_desc;
Expand Down Expand Up @@ -242,10 +242,10 @@ static int audio_play_ca_reconfigure(void *state, struct audio_desc desc)

s->initialized = true;

return TRUE;
return true;

error:
return FALSE;
return false;
}


Expand Down
10 changes: 5 additions & 5 deletions src/audio/playback/decklink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ static bool audio_play_decklink_ctl(void *state [[gnu::unused]], int request, vo
}
}

static int audio_play_decklink_reconfigure(void *state, struct audio_desc desc) {
static bool audio_play_decklink_reconfigure(void *state, struct audio_desc desc) {
struct state_decklink *s = (struct state_decklink *)state;
BMDAudioSampleType sample_type;

Expand All @@ -407,7 +407,7 @@ static int audio_play_decklink_reconfigure(void *state, struct audio_desc desc)
s->audio_desc.ch_count != 16) {
fprintf(stderr, "[decklink] requested channel count isn't supported: "
"%d\n", s->audio_desc.ch_count);
return FALSE;
return false;
}

/* toggle one channel to supported two */
Expand All @@ -419,7 +419,7 @@ static int audio_play_decklink_reconfigure(void *state, struct audio_desc desc)
desc.sample_rate != 48000) {
LOG(LOG_LEVEL_ERROR) << "[decklink] audio format isn't supported: " <<
desc;
return FALSE;
return false;
}
switch(desc.bps) {
case 2:
Expand All @@ -429,7 +429,7 @@ static int audio_play_decklink_reconfigure(void *state, struct audio_desc desc)
sample_type = bmdAudioSampleType32bitInteger;
break;
default:
return FALSE;
return false;
}

s->deckLinkOutput->EnableAudioOutput(bmdAudioSampleRate48kHz,
Expand All @@ -438,7 +438,7 @@ static int audio_play_decklink_reconfigure(void *state, struct audio_desc desc)
bmdAudioOutputStreamContinuous);
s->deckLinkOutput->StartScheduledPlayback(0, s->frameRateScale, s->frameRateDuration);

return TRUE;
return true;
}

static void audio_play_decklink_done(void *state)
Expand Down
4 changes: 2 additions & 2 deletions src/audio/playback/dummy.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ static bool audio_play_dummy_ctl(void *state, int request, void *data, size_t *l
}
}

static int audio_play_dummy_reconfigure(void *state, struct audio_desc desc)
static bool audio_play_dummy_reconfigure(void *state, struct audio_desc desc)
{
UNUSED(state), UNUSED(desc);
return TRUE;
return true;
}

static const struct audio_playback_info aplay_dummy_info = {
Expand Down
2 changes: 1 addition & 1 deletion src/audio/playback/dump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ static void audio_play_dump_put_frame(void *state, const struct audio_frame *f)
audio_export(s->exporter.get(), f);
}

static int audio_play_dump_reconfigure(void *state, struct audio_desc new_desc)
static bool audio_play_dump_reconfigure(void *state, struct audio_desc new_desc)
{
auto *s = static_cast<audio_dump_state *>(state);
s->desc = new_desc;
Expand Down
10 changes: 5 additions & 5 deletions src/audio/playback/jack.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ static bool audio_play_jack_ctl(void *state, int request, void *data, size_t *le
}
}

static int audio_play_jack_reconfigure(void *state, struct audio_desc desc)
static bool audio_play_jack_reconfigure(void *state, struct audio_desc desc)
{
struct state_jack_playback *s = (struct state_jack_playback *) state;
const char **ports;
Expand All @@ -307,7 +307,7 @@ static int audio_play_jack_reconfigure(void *state, struct audio_desc desc)
ports = s->libjack->get_ports(s->client, s->jack_ports_pattern, NULL, JackPortIsInput);
if(ports == NULL) {
log_msg(LOG_LEVEL_ERROR, MOD_NAME "Unable to input ports matching %s.\n", s->jack_ports_pattern);
return FALSE;
return false;
}

if(desc.ch_count > s->jack_ports_count) {
Expand Down Expand Up @@ -356,18 +356,18 @@ static int audio_play_jack_reconfigure(void *state, struct audio_desc desc)

if (s->libjack->activate(s->client)) {
log_msg(LOG_LEVEL_ERROR, MOD_NAME "Cannot activate client.\n");
return FALSE;
return false;
}

for(i = 0; i < desc.ch_count; ++i) {
if (s->libjack->connect (s->client, s->libjack->port_name (s->output_port[i]), ports[i])) {
log_msg(LOG_LEVEL_ERROR, MOD_NAME "Cannot connect output port: %d.\n", i);
return FALSE;
return false;
}
}
free(ports);

return TRUE;
return true;
}

static void audio_play_jack_put_frame(void *state, const struct audio_frame *frame)
Expand Down
4 changes: 2 additions & 2 deletions src/audio/playback/mixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,11 +473,11 @@ static bool audio_play_mixer_ctl(void *state, int request, void *data, size_t *l
}
}

static int audio_play_mixer_reconfigure(void *state [[gnu::unused]], struct audio_desc desc)
static bool audio_play_mixer_reconfigure(void *state [[gnu::unused]], struct audio_desc desc)
{
audio_desc requested{BPS, SAMPLE_RATE, CHANNELS, AC_PCM};
assert(desc == requested);
return TRUE;
return true;
}

static const struct audio_playback_info aplay_mixer_info = {
Expand Down
4 changes: 2 additions & 2 deletions src/audio/playback/none.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ static bool audio_play_none_ctl(void *state, int request, void *data, size_t *le
return false;
}

static int audio_play_none_reconfigure(void *state, struct audio_desc desc)
static bool audio_play_none_reconfigure(void *state, struct audio_desc desc)
{
UNUSED(desc);
struct state_audio_playback_none *s =
(struct state_audio_playback_none *) state;
assert(s->magic == AUDIO_PLAYBACK_NONE_MAGIC);

return TRUE;
return true;
}

static const struct audio_playback_info aplay_none_info = {
Expand Down
12 changes: 6 additions & 6 deletions src/audio/playback/portaudio.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ static int callback( const void *inputBuffer, void *outputBuffer,
PaStreamCallbackFlags statusFlags,
void *userData );
static void cleanup(struct state_portaudio_playback * s);
static int audio_play_portaudio_reconfigure(void *state, struct audio_desc);
static bool audio_play_portaudio_reconfigure(void *state, struct audio_desc);

/*
* Shared functions
Expand Down Expand Up @@ -317,7 +317,7 @@ static bool audio_play_portaudio_ctl(void *state, int request, void *data, size_
}
}

static int audio_play_portaudio_reconfigure(void *state, struct audio_desc desc)
static bool audio_play_portaudio_reconfigure(void *state, struct audio_desc desc)
{
struct state_portaudio_playback * s =
(struct state_portaudio_playback *) state;
Expand All @@ -344,7 +344,7 @@ static int audio_play_portaudio_reconfigure(void *state, struct audio_desc desc)
if (error != paNoError) {
log_msg(LOG_LEVEL_ERROR, MOD_NAME "error initializing portaudio\n");
log_msg(LOG_LEVEL_ERROR, "\tPortAudio error: %s\n", Pa_GetErrorText( error ) );
return FALSE;
return false;
}

log_msg(LOG_LEVEL_INFO, "Using PortAudio version: %s\n", Pa_GetVersionText());
Expand Down Expand Up @@ -393,14 +393,14 @@ static int audio_play_portaudio_reconfigure(void *state, struct audio_desc desc)
if (error != paNoError) {
log_msg(LOG_LEVEL_ERROR, "[Portaudio] Unable to open stream: %s\n",
Pa_GetErrorText(error));
return FALSE;
return false;
}

if (!portaudio_start_stream(s->stream)) {
return FALSE;
return false;
}

return TRUE;
return true;
}

/* This routine will be called by the PortAudio engine when audio is needed.
Expand Down
Loading

0 comments on commit 05c71ba

Please sign in to comment.