1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-29 10:32:15 +00:00

Dynamically increase probe size for lavf demuxer up to 2 MB.

This will read progressively more data if we still did not detect
the format. The lavfpref demuxer is unaffected to avoid hanging
for a long time in case of a slow network stream that some native
demuxer may be able to handle.


git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@30547 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
reimar 2010-02-12 20:38:29 +00:00
parent 92e3238508
commit 59d3c04b58

View File

@ -42,7 +42,8 @@
#include "mp_taglists.h"
#define PROBE_BUF_SIZE (32*1024)
#define INITIAL_PROBE_SIZE (32*1024)
#define PROBE_BUF_SIZE (2*1024*1024)
extern char *audio_lang;
extern char *dvdsub_lang;
@ -68,7 +69,7 @@ typedef struct lavf_priv_t{
AVInputFormat *avif;
AVFormatContext *avfc;
ByteIOContext *pb;
uint8_t buffer[FFMAX(BIO_BUFFER_SIZE, PROBE_BUF_SIZE)];
uint8_t buffer[BIO_BUFFER_SIZE];
int audio_streams;
int video_streams;
int sub_streams;
@ -133,7 +134,8 @@ static void list_formats(void) {
static int lavf_check_file(demuxer_t *demuxer){
AVProbeData avpd;
lavf_priv_t *priv;
int probe_data_size;
int probe_data_size = 0;
int read_size = INITIAL_PROBE_SIZE;
if(!demuxer->priv)
demuxer->priv=calloc(sizeof(lavf_priv_t),1);
@ -155,16 +157,26 @@ static int lavf_check_file(demuxer_t *demuxer){
return DEMUXER_TYPE_LAVF;
}
probe_data_size = stream_read(demuxer->stream, priv->buffer, PROBE_BUF_SIZE);
if(probe_data_size < 0)
avpd.buf = av_mallocz(FFMAX(BIO_BUFFER_SIZE, PROBE_BUF_SIZE) +
FF_INPUT_BUFFER_PADDING_SIZE);
do {
read_size = stream_read(demuxer->stream, avpd.buf + probe_data_size, read_size);
if(read_size < 0) {
av_free(avpd.buf);
return 0;
}
probe_data_size += read_size;
avpd.filename= demuxer->stream->url;
if (!strncmp(avpd.filename, "ffmpeg://", 9))
avpd.filename += 9;
avpd.buf= priv->buffer;
avpd.buf_size= probe_data_size;
priv->avif= av_probe_input_format(&avpd, probe_data_size > 0);
read_size = FFMIN(2*read_size, PROBE_BUF_SIZE - probe_data_size);
} while (demuxer->desc->type != DEMUXER_TYPE_LAVF_PREFERRED &&
!priv->avif && read_size > 0 && probe_data_size < PROBE_BUF_SIZE);
av_free(avpd.buf);
if(!priv->avif){
mp_msg(MSGT_HEADER,MSGL_V,"LAVF_check: no clue about this gibberish!\n");
return 0;