summaryrefslogtreecommitdiffstats
path: root/audio/out/buffer.c
diff options
context:
space:
mode:
authorThomas Weißschuh <thomas@t-8ch.de>2023-11-05 09:08:47 +0100
committersfan5 <sfan5@live.de>2023-11-08 20:26:23 +0100
commita96d26e63a78d6325ed0238a24d8bd4a66519d19 (patch)
tree0e36a90a08a1faf378499e6322ef83f67e159acb /audio/out/buffer.c
parent0b43b74c15a6bd99982c3f083faaeed01d3e9517 (diff)
downloadmpv-a96d26e63a78d6325ed0238a24d8bd4a66519d19.tar.bz2
mpv-a96d26e63a78d6325ed0238a24d8bd4a66519d19.tar.xz
audio: avoid unnecessary silence padding in read_buffer()
Not all callers of read_buffer() require the buffer to be padded with silence.
Diffstat (limited to 'audio/out/buffer.c')
-rw-r--r--audio/out/buffer.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/audio/out/buffer.c b/audio/out/buffer.c
index a5520f3a21..71367e47fd 100644
--- a/audio/out/buffer.c
+++ b/audio/out/buffer.c
@@ -114,7 +114,8 @@ struct mp_async_queue *ao_get_queue(struct ao *ao)
}
// Special behavior with data==NULL: caller uses p->pending.
-static int read_buffer(struct ao *ao, void **data, int samples, bool *eof)
+static int read_buffer(struct ao *ao, void **data, int samples, bool *eof,
+ bool pad_silence)
{
struct buffer_state *p = ao->buffer_state;
int pos = 0;
@@ -160,10 +161,12 @@ static int read_buffer(struct ao *ao, void **data, int samples, bool *eof)
}
// pad with silence (underflow/paused/eof)
- for (int n = 0; n < ao->num_planes; n++) {
- af_fill_silence((char *)data[n] + pos * ao->sstride,
- (samples - pos) * ao->sstride,
- ao->format);
+ if (pad_silence) {
+ for (int n = 0; n < ao->num_planes; n++) {
+ af_fill_silence((char *)data[n] + pos * ao->sstride,
+ (samples - pos) * ao->sstride,
+ ao->format);
+ }
}
ao_post_process_data(ao, data, pos);
@@ -171,12 +174,12 @@ static int read_buffer(struct ao *ao, void **data, int samples, bool *eof)
}
static int ao_read_data_unlocked(struct ao *ao, void **data, int samples,
- int64_t out_time_ns)
+ int64_t out_time_ns, bool pad_silence)
{
struct buffer_state *p = ao->buffer_state;
assert(!ao->driver->write);
- int pos = read_buffer(ao, data, samples, &(bool){0});
+ int pos = read_buffer(ao, data, samples, &(bool){0}, pad_silence);
if (pos > 0)
p->end_time_ns = out_time_ns;
@@ -205,7 +208,7 @@ int ao_read_data(struct ao *ao, void **data, int samples, int64_t out_time_ns)
mp_mutex_lock(&p->lock);
- int pos = ao_read_data_unlocked(ao, data, samples, out_time_ns);
+ int pos = ao_read_data_unlocked(ao, data, samples, out_time_ns, true);
mp_mutex_unlock(&p->lock);
@@ -221,7 +224,7 @@ int ao_read_data_nonblocking(struct ao *ao, void **data, int samples, int64_t ou
if (mp_mutex_trylock(&p->lock))
return 0;
- int pos = ao_read_data_unlocked(ao, data, samples, out_time_ns);
+ int pos = ao_read_data_unlocked(ao, data, samples, out_time_ns, false);
mp_mutex_unlock(&p->lock);
@@ -623,7 +626,7 @@ static bool ao_play_data(struct ao *ao)
bool got_eof = false;
if (ao->driver->write_frames) {
TA_FREEP(&p->pending);
- samples = read_buffer(ao, NULL, 1, &got_eof);
+ samples = read_buffer(ao, NULL, 1, &got_eof, false);
planes = (void **)&p->pending;
} else {
if (!realloc_buf(ao, space)) {
@@ -640,7 +643,7 @@ static bool ao_play_data(struct ao *ao)
}
if (!samples) {
- samples = read_buffer(ao, planes, space, &got_eof);
+ samples = read_buffer(ao, planes, space, &got_eof, true);
if (p->paused || (ao->stream_silence && !p->playing))
samples = space; // read_buffer() sets remainder to silent
}