mirror of https://git.ffmpeg.org/ffmpeg.git
dynamically increase probe buffer until format is detected
Originally committed as revision 4920 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
parent
7d453f4500
commit
a877eedce5
|
@ -508,7 +508,8 @@ int av_open_input_stream(AVFormatContext **ic_ptr,
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Size of probe buffer, for guessing file type from file contents. */
|
/** Size of probe buffer, for guessing file type from file contents. */
|
||||||
#define PROBE_BUF_SIZE 2048
|
#define PROBE_BUF_MIN 2048
|
||||||
|
#define PROBE_BUF_MAX 131072
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open a media file as input. The codec are not opened. Only the file
|
* Open a media file as input. The codec are not opened. Only the file
|
||||||
|
@ -526,8 +527,7 @@ int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
|
||||||
int buf_size,
|
int buf_size,
|
||||||
AVFormatParameters *ap)
|
AVFormatParameters *ap)
|
||||||
{
|
{
|
||||||
int err, must_open_file, file_opened;
|
int err, must_open_file, file_opened, probe_size;
|
||||||
uint8_t buf[PROBE_BUF_SIZE];
|
|
||||||
AVProbeData probe_data, *pd = &probe_data;
|
AVProbeData probe_data, *pd = &probe_data;
|
||||||
ByteIOContext pb1, *pb = &pb1;
|
ByteIOContext pb1, *pb = &pb1;
|
||||||
|
|
||||||
|
@ -535,7 +535,7 @@ int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
|
||||||
pd->filename = "";
|
pd->filename = "";
|
||||||
if (filename)
|
if (filename)
|
||||||
pd->filename = filename;
|
pd->filename = filename;
|
||||||
pd->buf = buf;
|
pd->buf = NULL;
|
||||||
pd->buf_size = 0;
|
pd->buf_size = 0;
|
||||||
|
|
||||||
if (!fmt) {
|
if (!fmt) {
|
||||||
|
@ -561,9 +561,11 @@ int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
|
||||||
if (buf_size > 0) {
|
if (buf_size > 0) {
|
||||||
url_setbufsize(pb, buf_size);
|
url_setbufsize(pb, buf_size);
|
||||||
}
|
}
|
||||||
if (!fmt) {
|
|
||||||
|
for(probe_size= PROBE_BUF_MIN; probe_size<=PROBE_BUF_MAX && !fmt; probe_size<<=1){
|
||||||
/* read probe data */
|
/* read probe data */
|
||||||
pd->buf_size = get_buffer(pb, buf, PROBE_BUF_SIZE);
|
pd->buf= av_realloc(pd->buf, probe_size);
|
||||||
|
pd->buf_size = get_buffer(pb, pd->buf, probe_size);
|
||||||
if (url_fseek(pb, 0, SEEK_SET) == (offset_t)-EPIPE) {
|
if (url_fseek(pb, 0, SEEK_SET) == (offset_t)-EPIPE) {
|
||||||
url_fclose(pb);
|
url_fclose(pb);
|
||||||
if (url_fopen(pb, filename, URL_RDONLY) < 0) {
|
if (url_fopen(pb, filename, URL_RDONLY) < 0) {
|
||||||
|
@ -571,12 +573,10 @@ int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/* guess file format */
|
||||||
|
fmt = av_probe_input_format(pd, 1);
|
||||||
}
|
}
|
||||||
}
|
av_freep(&pd->buf);
|
||||||
|
|
||||||
/* guess file format */
|
|
||||||
if (!fmt) {
|
|
||||||
fmt = av_probe_input_format(pd, 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if still no format found, error */
|
/* if still no format found, error */
|
||||||
|
@ -606,6 +606,7 @@ int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
|
||||||
goto fail;
|
goto fail;
|
||||||
return 0;
|
return 0;
|
||||||
fail:
|
fail:
|
||||||
|
av_freep(&pd->buf);
|
||||||
if (file_opened)
|
if (file_opened)
|
||||||
url_fclose(pb);
|
url_fclose(pb);
|
||||||
*ic_ptr = NULL;
|
*ic_ptr = NULL;
|
||||||
|
@ -3223,7 +3224,7 @@ int av_read_image(ByteIOContext *pb, const char *filename,
|
||||||
AVImageFormat *fmt,
|
AVImageFormat *fmt,
|
||||||
int (*alloc_cb)(void *, AVImageInfo *info), void *opaque)
|
int (*alloc_cb)(void *, AVImageInfo *info), void *opaque)
|
||||||
{
|
{
|
||||||
uint8_t buf[PROBE_BUF_SIZE];
|
uint8_t buf[PROBE_BUF_MIN];
|
||||||
AVProbeData probe_data, *pd = &probe_data;
|
AVProbeData probe_data, *pd = &probe_data;
|
||||||
offset_t pos;
|
offset_t pos;
|
||||||
int ret;
|
int ret;
|
||||||
|
@ -3232,7 +3233,7 @@ int av_read_image(ByteIOContext *pb, const char *filename,
|
||||||
pd->filename = filename;
|
pd->filename = filename;
|
||||||
pd->buf = buf;
|
pd->buf = buf;
|
||||||
pos = url_ftell(pb);
|
pos = url_ftell(pb);
|
||||||
pd->buf_size = get_buffer(pb, buf, PROBE_BUF_SIZE);
|
pd->buf_size = get_buffer(pb, buf, PROBE_BUF_MIN);
|
||||||
url_fseek(pb, pos, SEEK_SET);
|
url_fseek(pb, pos, SEEK_SET);
|
||||||
fmt = av_probe_image_format(pd);
|
fmt = av_probe_image_format(pd);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue