comparison libmpdemux/demux_lavf.c @ 30505:580319e640b3

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.
author reimar
date Fri, 12 Feb 2010 20:38:29 +0000
parents f6721168aee8
children df6c41f16b40
comparison
equal deleted inserted replaced
30504:cc27da5d7286 30505:580319e640b3
40 #include "libavutil/avstring.h" 40 #include "libavutil/avstring.h"
41 #include "libavcodec/opt.h" 41 #include "libavcodec/opt.h"
42 42
43 #include "mp_taglists.h" 43 #include "mp_taglists.h"
44 44
45 #define PROBE_BUF_SIZE (32*1024) 45 #define INITIAL_PROBE_SIZE (32*1024)
46 #define PROBE_BUF_SIZE (2*1024*1024)
46 47
47 extern char *audio_lang; 48 extern char *audio_lang;
48 extern char *dvdsub_lang; 49 extern char *dvdsub_lang;
49 extern int dvdsub_id; 50 extern int dvdsub_id;
50 static unsigned int opt_probesize = 0; 51 static unsigned int opt_probesize = 0;
66 67
67 typedef struct lavf_priv_t{ 68 typedef struct lavf_priv_t{
68 AVInputFormat *avif; 69 AVInputFormat *avif;
69 AVFormatContext *avfc; 70 AVFormatContext *avfc;
70 ByteIOContext *pb; 71 ByteIOContext *pb;
71 uint8_t buffer[FFMAX(BIO_BUFFER_SIZE, PROBE_BUF_SIZE)]; 72 uint8_t buffer[BIO_BUFFER_SIZE];
72 int audio_streams; 73 int audio_streams;
73 int video_streams; 74 int video_streams;
74 int sub_streams; 75 int sub_streams;
75 int64_t last_pts; 76 int64_t last_pts;
76 int astreams[MAX_A_STREAMS]; 77 int astreams[MAX_A_STREAMS];
131 } 132 }
132 133
133 static int lavf_check_file(demuxer_t *demuxer){ 134 static int lavf_check_file(demuxer_t *demuxer){
134 AVProbeData avpd; 135 AVProbeData avpd;
135 lavf_priv_t *priv; 136 lavf_priv_t *priv;
136 int probe_data_size; 137 int probe_data_size = 0;
138 int read_size = INITIAL_PROBE_SIZE;
137 139
138 if(!demuxer->priv) 140 if(!demuxer->priv)
139 demuxer->priv=calloc(sizeof(lavf_priv_t),1); 141 demuxer->priv=calloc(sizeof(lavf_priv_t),1);
140 priv= demuxer->priv; 142 priv= demuxer->priv;
141 143
153 } 155 }
154 mp_msg(MSGT_DEMUX,MSGL_INFO,"Forced lavf %s demuxer\n", priv->avif->long_name); 156 mp_msg(MSGT_DEMUX,MSGL_INFO,"Forced lavf %s demuxer\n", priv->avif->long_name);
155 return DEMUXER_TYPE_LAVF; 157 return DEMUXER_TYPE_LAVF;
156 } 158 }
157 159
158 probe_data_size = stream_read(demuxer->stream, priv->buffer, PROBE_BUF_SIZE); 160 avpd.buf = av_mallocz(FFMAX(BIO_BUFFER_SIZE, PROBE_BUF_SIZE) +
159 if(probe_data_size < 0) 161 FF_INPUT_BUFFER_PADDING_SIZE);
162 do {
163 read_size = stream_read(demuxer->stream, avpd.buf + probe_data_size, read_size);
164 if(read_size < 0) {
165 av_free(avpd.buf);
160 return 0; 166 return 0;
167 }
168 probe_data_size += read_size;
161 avpd.filename= demuxer->stream->url; 169 avpd.filename= demuxer->stream->url;
162 if (!strncmp(avpd.filename, "ffmpeg://", 9)) 170 if (!strncmp(avpd.filename, "ffmpeg://", 9))
163 avpd.filename += 9; 171 avpd.filename += 9;
164 avpd.buf= priv->buffer;
165 avpd.buf_size= probe_data_size; 172 avpd.buf_size= probe_data_size;
166 173
167 priv->avif= av_probe_input_format(&avpd, probe_data_size > 0); 174 priv->avif= av_probe_input_format(&avpd, probe_data_size > 0);
175 read_size = FFMIN(2*read_size, PROBE_BUF_SIZE - probe_data_size);
176 } while (demuxer->desc->type != DEMUXER_TYPE_LAVF_PREFERRED &&
177 !priv->avif && read_size > 0 && probe_data_size < PROBE_BUF_SIZE);
178 av_free(avpd.buf);
179
168 if(!priv->avif){ 180 if(!priv->avif){
169 mp_msg(MSGT_HEADER,MSGL_V,"LAVF_check: no clue about this gibberish!\n"); 181 mp_msg(MSGT_HEADER,MSGL_V,"LAVF_check: no clue about this gibberish!\n");
170 return 0; 182 return 0;
171 }else 183 }else
172 mp_msg(MSGT_HEADER,MSGL_V,"LAVF_check: %s\n", priv->avif->long_name); 184 mp_msg(MSGT_HEADER,MSGL_V,"LAVF_check: %s\n", priv->avif->long_name);