Skip to content

Commit d87bdbb

Browse files
committed
aplay/sdi: updates
- add magic and check it in done and reconfigure - assert s->display!=0 - previously in some calls, specifically reconfigure was returned false. But I suppose that the display should be either set or the call should not be called at all - free the state in done (was leak, but quite unimportant) - 48000->kHz48
1 parent bc62f12 commit d87bdbb

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

src/audio/playback/sdi.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737

3838
#include "audio/playback/sdi.h"
3939

40+
#include <assert.h> // for assert
41+
#include <stdint.h> // for uint32_t
4042
#include <stdio.h> // for printf, snprintf
4143
#include <stdlib.h> // for free, calloc, malloc
4244
#include <string.h> // for strcmp, strncpy, memcpy
@@ -50,7 +52,10 @@
5052
#include "types.h" // for device_info
5153
#include "video_display.h"
5254

55+
#define MAGIC to_fourcc('A', 'P', 's', 'd')
56+
5357
struct state_sdi_playback {
58+
uint32_t magic;
5459
struct display *display;
5560
};
5661

@@ -104,6 +109,7 @@ audio_play_sdi_init(const struct audio_playback_opts *opts)
104109
return INIT_NOERR;
105110
}
106111
struct state_sdi_playback *s = calloc(1, sizeof *s);
112+
s->magic = MAGIC;
107113
return s;
108114
}
109115

@@ -117,10 +123,7 @@ sdi_register_display(void *state, struct display *display)
117123
static void audio_play_sdi_put_frame(void *state, const struct audio_frame *frame)
118124
{
119125
struct state_sdi_playback *s = state;
120-
121-
if (s->display) {
122-
display_put_audio_frame(s->display, frame);
123-
}
126+
display_put_audio_frame(s->display, frame);
124127
}
125128

126129
static bool audio_play_sdi_query_format(struct state_sdi_playback *s, void *data, size_t *len)
@@ -131,7 +134,7 @@ static bool audio_play_sdi_query_format(struct state_sdi_playback *s, void *data
131134
}
132135
log_msg(LOG_LEVEL_WARNING,
133136
"Cannot get audio format from playback card!\n");
134-
struct audio_desc desc = { 2, 48000, 2, AC_PCM };
137+
struct audio_desc desc = { 2, kHz48, 2, AC_PCM };
135138
if (*len < sizeof desc) {
136139
return false;
137140
}
@@ -154,17 +157,18 @@ static bool audio_play_sdi_ctl(void *state, int request, void *data, size_t *len
154157
static bool audio_play_sdi_reconfigure(void *state, struct audio_desc desc)
155158
{
156159
struct state_sdi_playback *s = state;
160+
assert(s->magic == MAGIC);
161+
assert(s->display != nullptr);
157162

158-
if (s->display) {
159-
return display_reconfigure_audio(
160-
s->display, desc.bps * 8, desc.ch_count, desc.sample_rate);
161-
}
162-
return false;
163+
return display_reconfigure_audio(s->display, desc.bps * 8,
164+
desc.ch_count, desc.sample_rate);
163165
}
164166

165-
static void audio_play_sdi_done(void *s)
167+
static void audio_play_sdi_done(void *state)
166168
{
167-
UNUSED(s);
169+
struct state_sdi_playback *s = state;
170+
assert(s->magic == MAGIC);
171+
free(s);
168172
}
169173

170174
static const struct audio_playback_info aplay_sdi_info_embedded = {

0 commit comments

Comments
 (0)