demux_lavf: use stream_peek() instead of read/unread

Simpler, reduces the amount of copying.

We still have to malloc+memcpy the probe buffer though, because padding
with FF_INPUT_BUFFER_PADDING_SIZE is required by libavformat.
This commit is contained in:
wm4 2013-06-21 21:14:38 +02:00
parent a40ae2de84
commit e3c0fb1aee
1 changed files with 4 additions and 6 deletions

View File

@ -267,12 +267,11 @@ static int lavf_check_file(demuxer_t *demuxer)
while (avpd.buf_size < PROBE_BUF_SIZE) {
int nsize = av_clip(avpd.buf_size * 2, INITIAL_PROBE_SIZE,
PROBE_BUF_SIZE);
int read_size = stream_read(s, avpd.buf + avpd.buf_size,
nsize - avpd.buf_size);
if (read_size <= 0)
bstr buf = stream_peek(s, nsize);
if (buf.len <= avpd.buf_size)
break;
avpd.buf_size += read_size;
memcpy(avpd.buf, buf.start, buf.len);
avpd.buf_size = buf.len;
int score = 0;
priv->avif = av_probe_input_format2(&avpd, avpd.buf_size > 0, &score);
@ -294,7 +293,6 @@ static int lavf_check_file(demuxer_t *demuxer)
priv->avif = NULL;
}
stream_unread_buffer(s, avpd.buf, avpd.buf_size);
av_free(avpd.buf);
if (!priv->avif) {