mirror of
https://github.com/cookiengineer/audacity
synced 2025-07-20 22:48:05 +02:00
remove unneeded probing code, ffmpeg does that already so no need to duplicate it
Signed-off-by: Michael Niedermayer <michaelni@gmx.at> Signed-off-by: Benjamin Drung <bdrung@debian.org>
This commit is contained in:
parent
60fe57463e
commit
6ac83ae299
@ -256,10 +256,6 @@ int ufile_fopen(AVIOContext **s, const wxString & name, int flags)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Size of probe buffer, for guessing file type from file contents
|
|
||||||
#define PROBE_BUF_MIN 2048
|
|
||||||
#define PROBE_BUF_MAX (1<<20)
|
|
||||||
|
|
||||||
// Detect type of input file and open it if recognized. Routine
|
// Detect type of input file and open it if recognized. Routine
|
||||||
// based on the av_open_input_file() libavformat function.
|
// based on the av_open_input_file() libavformat function.
|
||||||
int ufile_fopen_input(AVFormatContext **ic_ptr, wxString & name)
|
int ufile_fopen_input(AVFormatContext **ic_ptr, wxString & name)
|
||||||
@ -267,108 +263,29 @@ int ufile_fopen_input(AVFormatContext **ic_ptr, wxString & name)
|
|||||||
wxFileName f(name);
|
wxFileName f(name);
|
||||||
wxCharBuffer fname;
|
wxCharBuffer fname;
|
||||||
const char *filename;
|
const char *filename;
|
||||||
AVProbeData pd;
|
|
||||||
AVIOContext *pb = NULL;
|
AVIOContext *pb = NULL;
|
||||||
AVInputFormat *fmt = NULL;
|
|
||||||
AVInputFormat *fmt1;
|
|
||||||
int probe_size;
|
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
fname = f.GetFullName().mb_str();
|
fname = f.GetFullName().mb_str();
|
||||||
filename = (const char *) fname;
|
filename = (const char *) fname;
|
||||||
|
|
||||||
// Initialize probe data...go ahead and preallocate the maximum buffer size.
|
|
||||||
pd.filename = filename;
|
|
||||||
pd.buf_size = 0;
|
|
||||||
pd.buf = (unsigned char *) av_malloc(PROBE_BUF_MAX + AVPROBE_PADDING_SIZE);
|
|
||||||
if (pd.buf == NULL) {
|
|
||||||
err = AVERROR(ENOMEM);
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Open the file to prepare for probing
|
// Open the file to prepare for probing
|
||||||
if ((err = ufile_fopen(&pb, name, AVIO_FLAG_READ)) < 0) {
|
if ((err = ufile_fopen(&pb, name, AVIO_FLAG_READ)) < 0) {
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (probe_size = PROBE_BUF_MIN; probe_size <= PROBE_BUF_MAX && !fmt; probe_size <<= 1) {
|
|
||||||
int score_max = probe_size < PROBE_BUF_MAX ? AVPROBE_SCORE_MAX / 4 : 0;
|
|
||||||
|
|
||||||
// Read up to a "probe_size" worth of data
|
|
||||||
pd.buf_size = avio_read(pb, pd.buf, probe_size);
|
|
||||||
|
|
||||||
// AWD: with zero-length input files buf_size can come back negative;
|
|
||||||
// this causes problems so we might as well just fail
|
|
||||||
if (pd.buf_size < 0) {
|
|
||||||
err = AVERROR_INVALIDDATA;
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clear up to a "AVPROBE_PADDING_SIZE" worth of unused buffer
|
|
||||||
memset(pd.buf + pd.buf_size, 0, AVPROBE_PADDING_SIZE);
|
|
||||||
|
|
||||||
// Reposition file for succeeding scan
|
|
||||||
if (avio_seek(pb, 0, SEEK_SET) < 0) {
|
|
||||||
err = AVERROR(EIO);
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Scan all input formats
|
|
||||||
fmt = NULL;
|
|
||||||
for (fmt1 = av_iformat_next(NULL); fmt1 != NULL; fmt1 = av_iformat_next(fmt1)) {
|
|
||||||
int score = 0;
|
|
||||||
|
|
||||||
// Ignore the ones that are not file based
|
|
||||||
if (fmt1->flags & AVFMT_NOFILE) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the format can probe the file then try that first
|
|
||||||
if (fmt1->read_probe) {
|
|
||||||
score = fmt1->read_probe(&pd);
|
|
||||||
}
|
|
||||||
// Otherwize, resort to extension matching if available
|
|
||||||
else if (fmt1->extensions) {
|
|
||||||
if (av_match_ext(filename, fmt1->extensions)) {
|
|
||||||
score = 50;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remember this format if it scored higher than a previous match
|
|
||||||
if (score > score_max) {
|
|
||||||
score_max = score;
|
|
||||||
fmt = fmt1;
|
|
||||||
}
|
|
||||||
else if (score == score_max) {
|
|
||||||
fmt = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Didn't find a suitable format, so bail
|
|
||||||
if (!fmt) {
|
|
||||||
err = AVERROR(EILSEQ);
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
*ic_ptr = avformat_alloc_context();
|
*ic_ptr = avformat_alloc_context();
|
||||||
(*ic_ptr)->pb = pb;
|
(*ic_ptr)->pb = pb;
|
||||||
|
|
||||||
// And finally, attempt to associate an input stream with the file
|
// And finally, attempt to associate an input stream with the file
|
||||||
err = avformat_open_input(ic_ptr, filename, fmt, NULL);
|
err = avformat_open_input(ic_ptr, filename, NULL, NULL);
|
||||||
if (err) {
|
if (err) {
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Done with the probe buffer
|
|
||||||
av_freep(&pd.buf);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
if (pd.buf) {
|
|
||||||
av_freep(&pd.buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pb) {
|
if (pb) {
|
||||||
ufile_close(pb);
|
ufile_close(pb);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user