| @@ -41,7 +41,6 @@ · 40 unmodified lines |
| 41 | | 41 | |
| 42 | #include "audiointerleave.h" | 42 | #include "audiointerleave.h" |
| 43 | #include "avformat.h" | 43 | #include "avformat.h" |
| 44 | #include "avio_internal.h" | | |
| 45 | #include "id3v2.h" | 44 | #include "id3v2.h" |
| 46 | #include "internal.h" | 45 | #include "internal.h" |
| 47 | #include "metadata.h" | 46 | #include "metadata.h" |
| @@ -139,67 +138,6 @@ int av_filename_number_test(const char *filename) · 91 unmodified lines |
| 139 | (av_get_frame_filename(buf, sizeof(buf), filename, 1) >= 0); | 138 | (av_get_frame_filename(buf, sizeof(buf), filename, 1) >= 0); |
| 140 | } | 139 | } |
| 141 | | 140 | |
| 142 | AVInputFormat *av_probe_input_format2(AVProbeData *pd, int is_opened, | | |
| 143 | int *score_max) | | |
| 144 | { | | |
| 145 | AVProbeData lpd = *pd; | | |
| 146 | AVInputFormat *fmt1 = NULL, *fmt; | | |
| 147 | int score, id3 = 0; | | |
| 148 | | | |
| 149 | if (lpd.buf_size > 10 && ff_id3v2_match(lpd.buf, ID3v2_DEFAULT_MAGIC)) { | | |
| 150 | int id3len = ff_id3v2_tag_len(lpd.buf); | | |
| 151 | if (lpd.buf_size > id3len + 16) { | | |
| 152 | lpd.buf += id3len; | | |
| 153 | lpd.buf_size -= id3len; | | |
| 154 | } | | |
| 155 | id3 = 1; | | |
| 156 | } | | |
| 157 | | | |
| 158 | fmt = NULL; | | |
| 159 | while ((fmt1 = av_iformat_next(fmt1))) { | | |
| 160 | if (!is_opened == !(fmt1->flags & AVFMT_NOFILE)) | | |
| 161 | continue; | | |
| 162 | score = 0; | | |
| 163 | if (fmt1->read_probe) { | | |
| 164 | score = fmt1->read_probe(&lpd); | | |
| 165 | } else if (fmt1->extensions) { | | |
| 166 | if (av_match_ext(lpd.filename, fmt1->extensions)) | | |
| 167 | score = AVPROBE_SCORE_EXTENSION; | | |
| 168 | } | | |
| 169 | if (score > *score_max) { | | |
| 170 | *score_max = score; | | |
| 171 | fmt = fmt1; | | |
| 172 | } else if (score == *score_max) | | |
| 173 | fmt = NULL; | | |
| 174 | } | | |
| 175 | | | |
| 176 | // A hack for files with huge id3v2 tags -- try to guess by file extension. | | |
| 177 | if (!fmt && is_opened && *score_max < AVPROBE_SCORE_EXTENSION / 2) { | | |
| 178 | while ((fmt = av_iformat_next(fmt))) | | |
| 179 | if (fmt->extensions && | | |
| 180 | av_match_ext(lpd.filename, fmt->extensions)) { | | |
| 181 | *score_max = AVPROBE_SCORE_EXTENSION / 2; | | |
| 182 | break; | | |
| 183 | } | | |
| 184 | } | | |
| 185 | | | |
| 186 | if (!fmt && id3 && *score_max < AVPROBE_SCORE_EXTENSION / 2 - 1) { | | |
| 187 | while ((fmt = av_iformat_next(fmt))) | | |
| 188 | if (fmt->extensions && av_match_ext("mp3", fmt->extensions)) { | | |
| 189 | *score_max = AVPROBE_SCORE_EXTENSION / 2 - 1; | | |
| 190 | break; | | |
| 191 | } | | |
| 192 | } | | |
| 193 | | | |
| 194 | return fmt; | | |
| 195 | } | | |
| 196 | | | |
| 197 | AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened) | | |
| 198 | { | | |
| 199 | int score = 0; | | |
| 200 | return av_probe_input_format2(pd, is_opened, &score); | | |
| 201 | } | | |
| 202 | | | |
| 203 | static int set_codec_from_probe_data(AVFormatContext *s, AVStream *st, | 141 | static int set_codec_from_probe_data(AVFormatContext *s, AVStream *st, |
| 204 | AVProbeData *pd, int score) | 142 | AVProbeData *pd, int score) |
| 205 | { | 143 | { |
| @@ -241,79 +179,6 @@ static int set_codec_from_probe_data(AVFormatContext *s, AVStream *st, · 35 unmodified lines |
| 241 | /************************************************************/ | 179 | /************************************************************/ |
| 242 | /* input media file */ | 180 | /* input media file */ |
| 243 | | 181 | |
| 244 | /** size of probe buffer, for guessing file type from file contents */ | | |
| 245 | #define PROBE_BUF_MIN 2048 | | |
| 246 | #define PROBE_BUF_MAX (1 << 20) | | |
| 247 | | | |
| 248 | int av_probe_input_buffer(AVIOContext *pb, AVInputFormat **fmt, | | |
| 249 | const char *filename, void *logctx, | | |
| 250 | unsigned int offset, unsigned int max_probe_size) | | |
| 251 | { | | |
| 252 | AVProbeData pd = { filename ? filename : "" }; | | |
| 253 | uint8_t *buf = NULL; | | |
| 254 | int ret = 0, probe_size; | | |
| 255 | | | |
| 256 | if (!max_probe_size) | | |
| 257 | max_probe_size = PROBE_BUF_MAX; | | |
| 258 | else if (max_probe_size > PROBE_BUF_MAX) | | |
| 259 | max_probe_size = PROBE_BUF_MAX; | | |
| 260 | else if (max_probe_size < PROBE_BUF_MIN) | | |
| 261 | return AVERROR(EINVAL); | | |
| 262 | | | |
| 263 | if (offset >= max_probe_size) | | |
| 264 | return AVERROR(EINVAL); | | |
| 265 | avio_skip(pb, offset); | | |
| 266 | max_probe_size -= offset; | | |
| 267 | | | |
| 268 | for (probe_size = PROBE_BUF_MIN; probe_size <= max_probe_size && !*fmt; | | |
| 269 | probe_size = FFMIN(probe_size << 1, | | |
| 270 | FFMAX(max_probe_size, probe_size + 1))) { | | |
| 271 | int score = probe_size < max_probe_size ? AVPROBE_SCORE_MAX / 4 : 0; | | |
| 272 | | | |
| 273 | /* Read probe data. */ | | |
| 274 | if ((ret = av_reallocp(&buf, probe_size + AVPROBE_PADDING_SIZE)) < 0) | | |
| 275 | return ret; | | |
| 276 | if ((ret = avio_read(pb, buf + pd.buf_size, | | |
| 277 | probe_size - pd.buf_size)) < 0) { | | |
| 278 | /* Fail if error was not end of file, otherwise, lower score. */ | | |
| 279 | if (ret != AVERROR_EOF) { | | |
| 280 | av_free(buf); | | |
| 281 | return ret; | | |
| 282 | } | | |
| 283 | score = 0; | | |
| 284 | ret = 0; /* error was end of file, nothing read */ | | |
| 285 | } | | |
| 286 | pd.buf_size += ret; | | |
| 287 | pd.buf = buf; | | |
| 288 | | | |
| 289 | memset(pd.buf + pd.buf_size, 0, AVPROBE_PADDING_SIZE); | | |
| 290 | | | |
| 291 | /* Guess file format. */ | | |
| 292 | *fmt = av_probe_input_format2(&pd, 1, &score); | | |
| 293 | if (*fmt) { | | |
| 294 | /* This can only be true in the last iteration. */ | | |
| 295 | if (score <= AVPROBE_SCORE_MAX / 4) { | | |
| 296 | av_log(logctx, AV_LOG_WARNING, | | |
| 297 | "Format detected only with low score of %d, " | | |
| 298 | "misdetection possible!\n", score); | | |
| 299 | } else | | |
| 300 | av_log(logctx, AV_LOG_DEBUG, | | |
| 301 | "Probed with size=%d and score=%d\n", probe_size, score); | | |
| 302 | } | | |
| 303 | } | | |
| 304 | | | |
| 305 | if (!*fmt) { | | |
| 306 | av_free(buf); | | |
| 307 | return AVERROR_INVALIDDATA; | | |
| 308 | } | | |
| 309 | | | |
| 310 | /* Rewind. Reuse probe buffer to avoid seeking. */ | | |
| 311 | if ((ret = ffio_rewind_with_probe_data(pb, buf, pd.buf_size)) < 0) | | |
| 312 | av_free(buf); | | |
| 313 | | | |
| 314 | return ret; | | |
| 315 | } | | |
| 316 | | | |
| 317 | /* Open input file and probe the format if necessary. */ | 182 | /* Open input file and probe the format if necessary. */ |
| 318 | static int init_input(AVFormatContext *s, const char *filename, | 183 | static int init_input(AVFormatContext *s, const char *filename, |
| 319 | AVDictionary **options) | 184 | AVDictionary **options) |