diff options
author | Kevin Mitchell <kevmitch@gmail.com> | 2017-07-09 00:52:32 -0700 |
---|---|---|
committer | Kevin Mitchell <kevmitch@gmail.com> | 2017-07-09 13:46:13 -0700 |
commit | a081c8d372106a4b45b597631968d7774afb5814 (patch) | |
tree | c203f39336c0fd4cfeb87662b180f722aadace22 /audio/out | |
parent | 03abd704eccf88b3d48b91803d352c6c73a32ad5 (diff) | |
download | mpv-a081c8d372106a4b45b597631968d7774afb5814.tar.bz2 mpv-a081c8d372106a4b45b597631968d7774afb5814.tar.xz |
audio/out: correct copy length in ao_read_data_converted
Previously, the entire convert_buffer was being copied to the desination without
regard to the fact that it may be packed and therefore smaller.
The allocated conversion buffer was also way to big
bytes * (channels * samples) ** 2
instead of
bytes * channels * samples
Diffstat (limited to 'audio/out')
-rw-r--r-- | audio/out/pull.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/audio/out/pull.c b/audio/out/pull.c index fc8dc893c3..fc8844a136 100644 --- a/audio/out/pull.c +++ b/audio/out/pull.c @@ -182,7 +182,7 @@ end: return bytes / ao->sstride; } -// Same as ao_read_data(), but read pre-converted data according to *fmt. +// Same as ao_read_data(), but convert data according to *fmt. // fmt->src_fmt and fmt->channels must be the same as the AO parameters. int ao_read_data_converted(struct ao *ao, struct ao_convert_fmt *fmt, void **data, int samples, int64_t out_time_us) @@ -200,23 +200,24 @@ int ao_read_data_converted(struct ao *ao, struct ao_convert_fmt *fmt, bool planar = af_fmt_is_planar(fmt->src_fmt); int planes = planar ? fmt->channels : 1; - int plane_size = af_fmt_to_bytes(fmt->src_fmt) * samples * - (planar ? 1: fmt->channels); + int plane_samples = samples * (planar ? 1: fmt->channels); + int src_plane_size = plane_samples * af_fmt_to_bytes(fmt->src_fmt); + int dst_plane_size = plane_samples * fmt->dst_bits / 8; - int needed = plane_size * planes * fmt->channels * samples; + int needed = src_plane_size * planes; if (needed > talloc_get_size(p->convert_buffer) || !p->convert_buffer) { talloc_free(p->convert_buffer); p->convert_buffer = talloc_size(NULL, needed); } for (int n = 0; n < planes; n++) - ndata[n] = p->convert_buffer + n * plane_size; + ndata[n] = p->convert_buffer + n * src_plane_size; int res = ao_read_data(ao, ndata, samples, out_time_us); ao_convert_inplace(fmt, ndata, samples); for (int n = 0; n < planes; n++) - memcpy(data[n], ndata[n], plane_size); + memcpy(data[n], ndata[n], dst_plane_size); return res; } |