diff options
author | Uoti Urpala <uau@mplayer2.org> | 2011-05-07 20:20:13 +0300 |
---|---|---|
committer | Uoti Urpala <uau@mplayer2.org> | 2011-05-07 22:17:51 +0300 |
commit | b21e7dc7a94448066bdcc66287d6c5a68a3e1978 (patch) | |
tree | 40b81be806f10b0b9be597353e5fadbb436ed533 | |
parent | daafc5a368266dc2206b7da0c107b98e0ca042d6 (diff) | |
download | mpv-b21e7dc7a94448066bdcc66287d6c5a68a3e1978.tar.bz2 mpv-b21e7dc7a94448066bdcc66287d6c5a68a3e1978.tar.xz |
audio: disallow partial samples, fix ad_pcm to comply
Add some asserts to check that decoders/filters produce complete
samples (byte amounts must be multiples of channels*datatype_size) and
that audio output drivers also accept input in complete units. Fix
ad_pcm which was known to violate this if its last input packet didn't
stop at a sample boundary.
-rw-r--r-- | libmpcodecs/ad_pcm.c | 11 | ||||
-rw-r--r-- | mplayer.c | 3 |
2 files changed, 11 insertions, 3 deletions
diff --git a/libmpcodecs/ad_pcm.c b/libmpcodecs/ad_pcm.c index 1920f396f4..9ff4d6a90c 100644 --- a/libmpcodecs/ad_pcm.c +++ b/libmpcodecs/ad_pcm.c @@ -160,14 +160,14 @@ static int control(sh_audio_t *sh, int cmd, void *arg, ...) static int decode_audio(sh_audio_t *sh_audio, unsigned char *buf, int minlen, int maxlen) { - int len = sh_audio->channels * sh_audio->samplesize; - minlen = (minlen + len - 1) / len * len; + int unitsize = sh_audio->channels * sh_audio->samplesize; + minlen = (minlen + unitsize - 1) / unitsize * unitsize; if (minlen > maxlen) // if someone needs hundreds of channels adjust audio_out_minsize // based on channels in preinit() return -1; - len = 0; + int len = 0; struct ad_pcm_context *ctx = sh_audio->context; while (len < minlen) { if (ctx->buffer_len - ctx->buffer_pos <= 0) { @@ -197,6 +197,11 @@ static int decode_audio(sh_audio_t *sh_audio, unsigned char *buf, int minlen, sh_audio->pts_bytes += from_stored; len += from_stored; } + if (len % unitsize) { + mp_msg(MSGT_DECAUDIO, MSGL_WARN, "[ad_pcm] discarding partial sample " + "at end\n"); + len -= len % unitsize; + } if (len == 0) len = -1; // The loop above only exits at error/EOF if (len > 0 && sh_audio->channels >= 5) { @@ -23,6 +23,7 @@ #include <stdlib.h> #include <stdbool.h> #include <math.h> +#include <assert.h> #include "config.h" #include "talloc.h" @@ -2454,6 +2455,7 @@ static int fill_audio_out_buffers(struct MPContext *mpctx) } } + assert(sh_audio->a_out_buffer_len % unitsize == 0); if (playsize > sh_audio->a_out_buffer_len) { partial_fill = true; playsize = sh_audio->a_out_buffer_len; @@ -2472,6 +2474,7 @@ static int fill_audio_out_buffers(struct MPContext *mpctx) // would not having access to this make them more broken? ao->pts = ((mpctx->sh_video?mpctx->sh_video->timer:0)+mpctx->delay)*90000.0; playsize = ao_play(ao, sh_audio->a_out_buffer, playsize, playflags); + assert(playsize % unitsize == 0); if (playsize > 0) { sh_audio->a_out_buffer_len -= playsize; |