| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * Image format | ||
| 3 | * Copyright (c) 2000, 2001, 2002 Fabrice Bellard | ||
| 4 | * Copyright (c) 2004 Michael Niedermayer | ||
| 5 | * | ||
| 6 | * This file is part of FFmpeg. | ||
| 7 | * | ||
| 8 | * FFmpeg is free software; you can redistribute it and/or | ||
| 9 | * modify it under the terms of the GNU Lesser General Public | ||
| 10 | * License as published by the Free Software Foundation; either | ||
| 11 | * version 2.1 of the License, or (at your option) any later version. | ||
| 12 | * | ||
| 13 | * FFmpeg is distributed in the hope that it will be useful, | ||
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 16 | * Lesser General Public License for more details. | ||
| 17 | * | ||
| 18 | * You should have received a copy of the GNU Lesser General Public | ||
| 19 | * License along with FFmpeg; if not, write to the Free Software | ||
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 21 | */ | ||
| 22 | |||
| 23 | #include "config_components.h" | ||
| 24 | |||
| 25 | #define _DEFAULT_SOURCE | ||
| 26 | #define _BSD_SOURCE | ||
| 27 | #include <sys/stat.h> | ||
| 28 | #include "libavutil/avassert.h" | ||
| 29 | #include "libavutil/avstring.h" | ||
| 30 | #include "libavutil/bprint.h" | ||
| 31 | #include "libavutil/log.h" | ||
| 32 | #include "libavutil/mem.h" | ||
| 33 | #include "libavutil/opt.h" | ||
| 34 | #include "libavutil/pixdesc.h" | ||
| 35 | #include "libavutil/intreadwrite.h" | ||
| 36 | #include "libavcodec/gif.h" | ||
| 37 | #include "avformat.h" | ||
| 38 | #include "avio_internal.h" | ||
| 39 | #include "demux.h" | ||
| 40 | #include "internal.h" | ||
| 41 | #include "img2.h" | ||
| 42 | #include "os_support.h" | ||
| 43 | #include "libavcodec/jpegxl_parse.h" | ||
| 44 | #include "libavcodec/mjpeg.h" | ||
| 45 | #include "libavcodec/vbn.h" | ||
| 46 | #include "libavcodec/xwd.h" | ||
| 47 | #include "subtitles.h" | ||
| 48 | |||
| 49 | #if HAVE_GLOB | ||
| 50 | /* Locally define as 0 (bitwise-OR no-op) any missing glob options that | ||
| 51 | are non-posix glibc/bsd extensions. */ | ||
| 52 | #ifndef GLOB_NOMAGIC | ||
| 53 | #define GLOB_NOMAGIC 0 | ||
| 54 | #endif | ||
| 55 | #ifndef GLOB_BRACE | ||
| 56 | #define GLOB_BRACE 0 | ||
| 57 | #endif | ||
| 58 | |||
| 59 | #endif /* HAVE_GLOB */ | ||
| 60 | |||
| 61 | static const int sizes[][2] = { | ||
| 62 | { 640, 480 }, | ||
| 63 | { 720, 480 }, | ||
| 64 | { 720, 576 }, | ||
| 65 | { 352, 288 }, | ||
| 66 | { 352, 240 }, | ||
| 67 | { 160, 128 }, | ||
| 68 | { 512, 384 }, | ||
| 69 | { 640, 352 }, | ||
| 70 | { 640, 240 }, | ||
| 71 | }; | ||
| 72 | |||
| 73 | ✗ | static int infer_size(int *width_ptr, int *height_ptr, int size) | |
| 74 | { | ||
| 75 | int i; | ||
| 76 | |||
| 77 | ✗ | for (i = 0; i < FF_ARRAY_ELEMS(sizes); i++) { | |
| 78 | ✗ | if ((sizes[i][0] * sizes[i][1]) == size) { | |
| 79 | ✗ | *width_ptr = sizes[i][0]; | |
| 80 | ✗ | *height_ptr = sizes[i][1]; | |
| 81 | ✗ | return 0; | |
| 82 | } | ||
| 83 | } | ||
| 84 | |||
| 85 | ✗ | return -1; | |
| 86 | } | ||
| 87 | |||
| 88 | /** | ||
| 89 | * Get index range of image files matched by path. | ||
| 90 | * | ||
| 91 | * @param pfirst_index pointer to index updated with the first number in the range | ||
| 92 | * @param plast_index pointer to index updated with the last number in the range | ||
| 93 | * @param path path which has to be matched by the image files in the range | ||
| 94 | * @param start_index minimum accepted value for the first index in the range | ||
| 95 | * @return -1 if no image file could be found | ||
| 96 | */ | ||
| 97 | 3115 | static int find_image_range(int *pfirst_index, int *plast_index, | |
| 98 | const char *path, int start_index, int start_index_range) | ||
| 99 | { | ||
| 100 | int range, last_index, range1, first_index, ret; | ||
| 101 | AVBPrint filename; | ||
| 102 | |||
| 103 | 3115 | av_bprint_init(&filename, 0, AV_BPRINT_SIZE_UNLIMITED); | |
| 104 | /* find the first image */ | ||
| 105 |
1/2✓ Branch 0 taken 3174 times.
✗ Branch 1 not taken.
|
3174 | for (first_index = start_index; first_index < start_index + start_index_range; first_index++) { |
| 106 | 3174 | av_bprint_clear(&filename); | |
| 107 | 3174 | ret = ff_bprint_get_frame_filename(&filename, path, first_index, 0); | |
| 108 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 3170 times.
|
3174 | if (ret < 0) |
| 109 | 4 | goto fail; | |
| 110 |
2/2✓ Branch 1 taken 3111 times.
✓ Branch 2 taken 59 times.
|
3170 | if (avio_check(filename.str, AVIO_FLAG_READ) > 0) |
| 111 | 3111 | break; | |
| 112 | } | ||
| 113 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3111 times.
|
3111 | if (first_index == start_index + start_index_range) { |
| 114 | ✗ | ret = AVERROR(EINVAL); | |
| 115 | ✗ | goto fail; | |
| 116 | } | ||
| 117 | |||
| 118 | /* find the last image */ | ||
| 119 | 3111 | last_index = first_index; | |
| 120 | for (;;) { | ||
| 121 | 12369 | range = 0; | |
| 122 | for (;;) { | ||
| 123 |
2/2✓ Branch 0 taken 12369 times.
✓ Branch 1 taken 36949 times.
|
49318 | if (!range) |
| 124 | 12369 | range1 = 1; | |
| 125 | else | ||
| 126 | 36949 | range1 = 2 * range; | |
| 127 | 49318 | av_bprint_clear(&filename); | |
| 128 | 49318 | ret = ff_bprint_get_frame_filename(&filename, path, last_index + range1, 0); | |
| 129 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 49318 times.
|
49318 | if (ret < 0) |
| 130 | ✗ | goto fail; | |
| 131 |
2/2✓ Branch 1 taken 12369 times.
✓ Branch 2 taken 36949 times.
|
49318 | if (avio_check(filename.str, AVIO_FLAG_READ) <= 0) |
| 132 | 12369 | break; | |
| 133 | 36949 | range = range1; | |
| 134 | /* just in case... */ | ||
| 135 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 36949 times.
|
36949 | if (range >= (1 << 30)) { |
| 136 | ✗ | ret = AVERROR(EINVAL); | |
| 137 | ✗ | goto fail; | |
| 138 | } | ||
| 139 | } | ||
| 140 | /* we are sure than image last_index + range exists */ | ||
| 141 |
2/2✓ Branch 0 taken 3111 times.
✓ Branch 1 taken 9258 times.
|
12369 | if (!range) |
| 142 | 3111 | break; | |
| 143 | 9258 | last_index += range; | |
| 144 | } | ||
| 145 | 3111 | *pfirst_index = first_index; | |
| 146 | 3111 | *plast_index = last_index; | |
| 147 | 3111 | ret = 0; | |
| 148 | 3115 | fail: | |
| 149 | 3115 | av_bprint_finalize(&filename, NULL); | |
| 150 | 3115 | return ret; | |
| 151 | } | ||
| 152 | |||
| 153 | 11450 | static int img_read_probe(const AVProbeData *p) | |
| 154 | { | ||
| 155 |
4/4✓ Branch 0 taken 8286 times.
✓ Branch 1 taken 3164 times.
✓ Branch 3 taken 763 times.
✓ Branch 4 taken 7523 times.
|
11450 | if (p->filename && ff_guess_image2_codec(p->filename)) { |
| 156 |
2/2✓ Branch 1 taken 193 times.
✓ Branch 2 taken 570 times.
|
763 | if (av_filename_number_test(p->filename)) |
| 157 | 193 | return AVPROBE_SCORE_MAX; | |
| 158 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 570 times.
|
570 | else if (p->filename[strcspn(p->filename, "*?{")]) // probably PT_GLOB |
| 159 | ✗ | return AVPROBE_SCORE_EXTENSION + 2; // score chosen to be a tad above the image pipes | |
| 160 |
2/2✓ Branch 0 taken 285 times.
✓ Branch 1 taken 285 times.
|
570 | else if (p->buf_size == 0) |
| 161 | 285 | return 0; | |
| 162 |
2/4✓ Branch 1 taken 285 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 285 times.
|
285 | else if (av_match_ext(p->filename, "raw") || av_match_ext(p->filename, "gif")) |
| 163 | ✗ | return 5; | |
| 164 | else | ||
| 165 | 285 | return AVPROBE_SCORE_EXTENSION; | |
| 166 | } | ||
| 167 | 10687 | return 0; | |
| 168 | } | ||
| 169 | |||
| 170 | 3438 | int ff_img_read_header(AVFormatContext *s1) | |
| 171 | { | ||
| 172 | 3438 | VideoDemuxData *s = s1->priv_data; | |
| 173 | 3438 | int first_index = 1, last_index = 1; | |
| 174 | AVStream *st; | ||
| 175 | 3438 | enum AVPixelFormat pix_fmt = AV_PIX_FMT_NONE; | |
| 176 | |||
| 177 | 3438 | s1->ctx_flags |= AVFMTCTX_NOHEADER; | |
| 178 | |||
| 179 | 3438 | st = avformat_new_stream(s1, NULL); | |
| 180 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3438 times.
|
3438 | if (!st) { |
| 181 | ✗ | return AVERROR(ENOMEM); | |
| 182 | } | ||
| 183 | |||
| 184 |
3/4✓ Branch 0 taken 9 times.
✓ Branch 1 taken 3429 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
|
3447 | if (s->pixel_format && |
| 185 | 9 | (pix_fmt = av_get_pix_fmt(s->pixel_format)) == AV_PIX_FMT_NONE) { | |
| 186 | ✗ | av_log(s1, AV_LOG_ERROR, "No such pixel format: %s.\n", | |
| 187 | s->pixel_format); | ||
| 188 | ✗ | return AVERROR(EINVAL); | |
| 189 | } | ||
| 190 | |||
| 191 | 3438 | s->img_number = 0; | |
| 192 | 3438 | s->img_count = 0; | |
| 193 | |||
| 194 | /* find format */ | ||
| 195 |
2/2✓ Branch 0 taken 3142 times.
✓ Branch 1 taken 296 times.
|
3438 | if (s1->iformat->flags & AVFMT_NOFILE) |
| 196 | 3142 | s->is_pipe = 0; | |
| 197 | else { | ||
| 198 | 296 | s->is_pipe = 1; | |
| 199 | 296 | ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL; | |
| 200 | } | ||
| 201 | |||
| 202 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3438 times.
|
3438 | if (s->ts_from_file == 2) { |
| 203 | #if !HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC | ||
| 204 | av_log(s1, AV_LOG_ERROR, "POSIX.1-2008 not supported, nanosecond file timestamps unavailable\n"); | ||
| 205 | return AVERROR(ENOSYS); | ||
| 206 | #endif | ||
| 207 | ✗ | avpriv_set_pts_info(st, 64, 1, 1000000000); | |
| 208 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3438 times.
|
3438 | } else if (s->ts_from_file) |
| 209 | ✗ | avpriv_set_pts_info(st, 64, 1, 1); | |
| 210 | else { | ||
| 211 | 3438 | avpriv_set_pts_info(st, 64, s->framerate.den, s->framerate.num); | |
| 212 | 3438 | st->avg_frame_rate = st->r_frame_rate = s->framerate; | |
| 213 | } | ||
| 214 | |||
| 215 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 3438 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
3438 | if (s->width && s->height) { |
| 216 | ✗ | st->codecpar->width = s->width; | |
| 217 | ✗ | st->codecpar->height = s->height; | |
| 218 | } | ||
| 219 | |||
| 220 |
2/2✓ Branch 0 taken 3142 times.
✓ Branch 1 taken 296 times.
|
3438 | if (!s->is_pipe) { |
| 221 |
1/2✓ Branch 0 taken 3142 times.
✗ Branch 1 not taken.
|
3142 | if (s->pattern_type == PT_DEFAULT) { |
| 222 |
2/2✓ Branch 0 taken 27 times.
✓ Branch 1 taken 3115 times.
|
3142 | if (s1->pb) { |
| 223 | 27 | s->pattern_type = PT_NONE; | |
| 224 | } else | ||
| 225 | 3115 | s->pattern_type = PT_SEQUENCE; | |
| 226 | } | ||
| 227 |
2/2✓ Branch 0 taken 3115 times.
✓ Branch 1 taken 27 times.
|
3142 | if (s->pattern_type == PT_SEQUENCE) { |
| 228 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 2 taken 3111 times.
|
3115 | if (find_image_range(&first_index, &last_index, s1->url, |
| 229 | s->start_number, s->start_number_range) < 0) { | ||
| 230 |
2/4✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
|
4 | if (s1->pb || avio_check(s1->url, AVIO_FLAG_READ) > 0) { |
| 231 | // Fallback to normal mode | ||
| 232 | 4 | s->pattern_type = PT_NONE; | |
| 233 | } else { | ||
| 234 | ✗ | av_log(s1, AV_LOG_ERROR, | |
| 235 | "Could find no file or sequence with path '%s' and index in the range %d-%d\n", | ||
| 236 | ✗ | s1->url, s->start_number, s->start_number + s->start_number_range - 1); | |
| 237 | ✗ | return AVERROR(ENOENT); | |
| 238 | } | ||
| 239 | } | ||
| 240 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 27 times.
|
27 | } else if (s->pattern_type == PT_GLOB) { |
| 241 | #if HAVE_GLOB | ||
| 242 | int gerr; | ||
| 243 | ✗ | gerr = glob(s1->url, GLOB_NOCHECK|GLOB_BRACE|GLOB_NOMAGIC, NULL, &s->globstate); | |
| 244 | ✗ | if (gerr != 0) { | |
| 245 | ✗ | return AVERROR(ENOENT); | |
| 246 | } | ||
| 247 | ✗ | first_index = 0; | |
| 248 | ✗ | last_index = s->globstate.gl_pathc - 1; | |
| 249 | ✗ | s->use_glob = 1; | |
| 250 | #else | ||
| 251 | av_log(s1, AV_LOG_ERROR, | ||
| 252 | "Pattern type 'glob' was selected but globbing " | ||
| 253 | "is not supported by this libavformat build\n"); | ||
| 254 | return AVERROR(ENOSYS); | ||
| 255 | #endif | ||
| 256 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 27 times.
|
27 | } else if (s->pattern_type != PT_NONE) { |
| 257 | ✗ | av_log(s1, AV_LOG_ERROR, | |
| 258 | "Unknown value '%d' for pattern_type option\n", s->pattern_type); | ||
| 259 | ✗ | return AVERROR(EINVAL); | |
| 260 | } | ||
| 261 | 3142 | s->img_first = first_index; | |
| 262 | 3142 | s->img_last = last_index; | |
| 263 | 3142 | s->img_number = first_index; | |
| 264 | /* compute duration */ | ||
| 265 |
1/2✓ Branch 0 taken 3142 times.
✗ Branch 1 not taken.
|
3142 | if (!s->ts_from_file) { |
| 266 | 3142 | st->start_time = 0; | |
| 267 | 3142 | st->duration = last_index - first_index + 1; | |
| 268 | } | ||
| 269 | } | ||
| 270 | |||
| 271 |
2/2✓ Branch 0 taken 3043 times.
✓ Branch 1 taken 395 times.
|
3438 | if (s1->video_codec_id) { |
| 272 | 3043 | st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; | |
| 273 | 3043 | st->codecpar->codec_id = s1->video_codec_id; | |
| 274 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 395 times.
|
395 | } else if (s1->audio_codec_id) { |
| 275 | ✗ | st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; | |
| 276 | ✗ | st->codecpar->codec_id = s1->audio_codec_id; | |
| 277 |
2/2✓ Branch 1 taken 282 times.
✓ Branch 2 taken 113 times.
|
395 | } else if (ffifmt(s1->iformat)->raw_codec_id) { |
| 278 | 282 | st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; | |
| 279 | 282 | st->codecpar->codec_id = ffifmt(s1->iformat)->raw_codec_id; | |
| 280 | } else { | ||
| 281 | 113 | const char *str = strrchr(s1->url, '.'); | |
| 282 |
2/4✓ Branch 0 taken 113 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 113 times.
|
113 | s->split_planes = str && !av_strcasecmp(str + 1, "y"); |
| 283 | 113 | st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; | |
| 284 |
2/2✓ Branch 0 taken 36 times.
✓ Branch 1 taken 77 times.
|
113 | if (s1->pb) { |
| 285 | 36 | int probe_buffer_size = 2048; | |
| 286 | 36 | uint8_t *probe_buffer = av_realloc(NULL, probe_buffer_size + AVPROBE_PADDING_SIZE); | |
| 287 | 36 | const AVInputFormat *fmt = NULL; | |
| 288 | 36 | void *fmt_iter = NULL; | |
| 289 | 36 | AVProbeData pd = { 0 }; | |
| 290 | |||
| 291 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 36 times.
|
36 | if (!probe_buffer) |
| 292 | ✗ | return AVERROR(ENOMEM); | |
| 293 | |||
| 294 | 36 | probe_buffer_size = avio_read(s1->pb, probe_buffer, probe_buffer_size); | |
| 295 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 36 times.
|
36 | if (probe_buffer_size < 0) { |
| 296 | ✗ | av_free(probe_buffer); | |
| 297 | ✗ | return probe_buffer_size; | |
| 298 | } | ||
| 299 | 36 | memset(probe_buffer + probe_buffer_size, 0, AVPROBE_PADDING_SIZE); | |
| 300 | |||
| 301 | 36 | pd.buf = probe_buffer; | |
| 302 | 36 | pd.buf_size = probe_buffer_size; | |
| 303 | 36 | pd.filename = s1->url; | |
| 304 | |||
| 305 |
2/2✓ Branch 1 taken 12554 times.
✓ Branch 2 taken 15 times.
|
12569 | while ((fmt = av_demuxer_iterate(&fmt_iter))) { |
| 306 | 12554 | const FFInputFormat *fmt2 = ffifmt(fmt); | |
| 307 |
2/2✓ Branch 0 taken 1037 times.
✓ Branch 1 taken 11517 times.
|
12554 | if (fmt2->read_header != ff_img_read_header || |
| 308 |
2/2✓ Branch 0 taken 1001 times.
✓ Branch 1 taken 36 times.
|
1037 | !fmt2->read_probe || |
| 309 |
2/2✓ Branch 0 taken 965 times.
✓ Branch 1 taken 36 times.
|
1001 | (fmt->flags & AVFMT_NOFILE) || |
| 310 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 965 times.
|
965 | !fmt2->raw_codec_id) |
| 311 | 11589 | continue; | |
| 312 |
2/2✓ Branch 1 taken 21 times.
✓ Branch 2 taken 944 times.
|
965 | if (fmt2->read_probe(&pd) > 0) { |
| 313 | 21 | st->codecpar->codec_id = fmt2->raw_codec_id; | |
| 314 | 21 | break; | |
| 315 | } | ||
| 316 | } | ||
| 317 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 36 times.
|
36 | if (s1->flags & AVFMT_FLAG_CUSTOM_IO) { |
| 318 | ✗ | avio_seek(s1->pb, 0, SEEK_SET); | |
| 319 | ✗ | av_freep(&probe_buffer); | |
| 320 | } else | ||
| 321 | 36 | ffio_rewind_with_probe_data(s1->pb, &probe_buffer, probe_buffer_size); | |
| 322 | } | ||
| 323 |
2/2✓ Branch 0 taken 92 times.
✓ Branch 1 taken 21 times.
|
113 | if (st->codecpar->codec_id == AV_CODEC_ID_NONE) |
| 324 | 92 | st->codecpar->codec_id = ff_guess_image2_codec(s1->url); | |
| 325 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 113 times.
|
113 | if (st->codecpar->codec_id == AV_CODEC_ID_LJPEG) |
| 326 | ✗ | st->codecpar->codec_id = AV_CODEC_ID_MJPEG; | |
| 327 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 113 times.
|
113 | if (st->codecpar->codec_id == AV_CODEC_ID_ALIAS_PIX) // we cannot distinguish this from BRENDER_PIX |
| 328 | ✗ | st->codecpar->codec_id = AV_CODEC_ID_NONE; | |
| 329 | } | ||
| 330 |
3/4✓ Branch 0 taken 3438 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 3429 times.
|
3438 | if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && |
| 331 | pix_fmt != AV_PIX_FMT_NONE) | ||
| 332 | 9 | st->codecpar->format = pix_fmt; | |
| 333 | |||
| 334 | 3438 | return 0; | |
| 335 | } | ||
| 336 | |||
| 337 | /** | ||
| 338 | * Add this frame's source path and basename to packet's sidedata | ||
| 339 | * as a dictionary, so it can be used by filters like 'drawtext'. | ||
| 340 | */ | ||
| 341 | ✗ | static int add_filename_as_pkt_side_data(char *filename, AVPacket *pkt) { | |
| 342 | ✗ | AVDictionary *d = NULL; | |
| 343 | ✗ | char *packed_metadata = NULL; | |
| 344 | size_t metadata_len; | ||
| 345 | int ret; | ||
| 346 | |||
| 347 | ✗ | av_dict_set(&d, "lavf.image2dec.source_path", filename, 0); | |
| 348 | ✗ | av_dict_set(&d, "lavf.image2dec.source_basename", av_basename(filename), 0); | |
| 349 | |||
| 350 | ✗ | packed_metadata = av_packet_pack_dictionary(d, &metadata_len); | |
| 351 | ✗ | av_dict_free(&d); | |
| 352 | ✗ | if (!packed_metadata) | |
| 353 | ✗ | return AVERROR(ENOMEM); | |
| 354 | ✗ | ret = av_packet_add_side_data(pkt, AV_PKT_DATA_STRINGS_METADATA, | |
| 355 | packed_metadata, metadata_len); | ||
| 356 | ✗ | if (ret < 0) { | |
| 357 | ✗ | av_freep(&packed_metadata); | |
| 358 | ✗ | return ret; | |
| 359 | } | ||
| 360 | ✗ | return 0; | |
| 361 | } | ||
| 362 | |||
| 363 | 117134 | int ff_img_read_packet(AVFormatContext *s1, AVPacket *pkt) | |
| 364 | { | ||
| 365 | 117134 | VideoDemuxData *s = s1->priv_data; | |
| 366 | AVBPrint filename; | ||
| 367 | int i, res; | ||
| 368 | 117134 | int ret[3] = { 0 }; | |
| 369 | 117134 | int64_t size[3] = { 0 }; | |
| 370 | 117134 | AVIOContext *f[3] = { NULL }; | |
| 371 | 117134 | AVCodecParameters *par = s1->streams[0]->codecpar; | |
| 372 | |||
| 373 | 117134 | av_bprint_init(&filename, 0, AV_BPRINT_SIZE_UNLIMITED); | |
| 374 |
2/2✓ Branch 0 taken 102523 times.
✓ Branch 1 taken 14611 times.
|
117134 | if (!s->is_pipe) { |
| 375 | /* loop over input */ | ||
| 376 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 102523 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
102523 | if (s->loop && s->img_number > s->img_last) { |
| 377 | ✗ | s->img_number = s->img_first; | |
| 378 | } | ||
| 379 |
2/2✓ Branch 0 taken 233 times.
✓ Branch 1 taken 102290 times.
|
102523 | if (s->img_number > s->img_last) |
| 380 | 233 | return AVERROR_EOF; | |
| 381 |
2/2✓ Branch 0 taken 31 times.
✓ Branch 1 taken 102259 times.
|
102290 | if (s->pattern_type == PT_NONE) { |
| 382 | 31 | av_bprintf(&filename, "%s", s1->url); | |
| 383 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 102259 times.
|
102259 | } else if (s->use_glob) { |
| 384 | #if HAVE_GLOB | ||
| 385 | ✗ | av_bprintf(&filename, "%s", s->globstate.gl_pathv[s->img_number]); | |
| 386 | #endif | ||
| 387 | } else { | ||
| 388 | 102259 | int ret = ff_bprint_get_frame_filename(&filename, s1->url, s->img_number, 0); | |
| 389 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 102259 times.
|
102259 | if (ret < 0) { |
| 390 | ✗ | av_bprint_finalize(&filename, NULL); | |
| 391 | ✗ | return ret; | |
| 392 | } | ||
| 393 | } | ||
| 394 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 102290 times.
|
102290 | if (!av_bprint_is_complete(&filename)) { |
| 395 | ✗ | av_bprint_finalize(&filename, NULL); | |
| 396 | ✗ | return AVERROR(ENOMEM); | |
| 397 | } | ||
| 398 |
1/2✓ Branch 0 taken 102290 times.
✗ Branch 1 not taken.
|
102290 | for (i = 0; i < 3; i++) { |
| 399 |
2/2✓ Branch 0 taken 27 times.
✓ Branch 1 taken 102263 times.
|
102290 | if (s1->pb && |
| 400 |
1/2✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
|
27 | !strcmp(filename.str, s1->url) && |
| 401 |
1/2✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
|
27 | !s->loop && |
| 402 |
1/2✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
|
27 | !s->split_planes) { |
| 403 | 27 | f[i] = s1->pb; | |
| 404 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 102263 times.
|
102263 | } else if ((res = s1->io_open(s1, &f[i], filename.str, AVIO_FLAG_READ, NULL)) < 0) { |
| 405 | ✗ | if (i >= 1) | |
| 406 | ✗ | break; | |
| 407 | ✗ | av_log(s1, AV_LOG_ERROR, "Could not open file : %s\n", | |
| 408 | filename.str); | ||
| 409 | ✗ | av_bprint_finalize(&filename, NULL); | |
| 410 | ✗ | return res; | |
| 411 | } | ||
| 412 | 102290 | size[i] = avio_size(f[i]); | |
| 413 | |||
| 414 |
1/2✓ Branch 0 taken 102290 times.
✗ Branch 1 not taken.
|
102290 | if (!s->split_planes) |
| 415 | 102290 | break; | |
| 416 | ✗ | filename.str[filename.len - 1] = 'U' + i; | |
| 417 | } | ||
| 418 | 102290 | av_bprint_finalize(&filename, NULL); | |
| 419 | |||
| 420 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 102290 times.
|
102290 | if (par->codec_id == AV_CODEC_ID_NONE) { |
| 421 | ✗ | AVProbeData pd = { 0 }; | |
| 422 | const FFInputFormat *ifmt; | ||
| 423 | uint8_t header[PROBE_BUF_MIN + AVPROBE_PADDING_SIZE]; | ||
| 424 | int ret; | ||
| 425 | ✗ | int score = 0; | |
| 426 | |||
| 427 | ✗ | ret = avio_read(f[0], header, PROBE_BUF_MIN); | |
| 428 | ✗ | if (ret < 0) { | |
| 429 | ✗ | av_bprint_finalize(&filename, NULL); | |
| 430 | ✗ | return ret; | |
| 431 | } | ||
| 432 | ✗ | memset(header + ret, 0, sizeof(header) - ret); | |
| 433 | ✗ | avio_skip(f[0], -ret); | |
| 434 | ✗ | pd.buf = header; | |
| 435 | ✗ | pd.buf_size = ret; | |
| 436 | ✗ | pd.filename = filename.str; | |
| 437 | |||
| 438 | ✗ | ifmt = ffifmt(av_probe_input_format3(&pd, 1, &score)); | |
| 439 | ✗ | if (ifmt && ifmt->read_packet == ff_img_read_packet && ifmt->raw_codec_id) | |
| 440 | ✗ | par->codec_id = ifmt->raw_codec_id; | |
| 441 | } | ||
| 442 | |||
| 443 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 102290 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
102290 | if (par->codec_id == AV_CODEC_ID_RAWVIDEO && !par->width) |
| 444 | ✗ | infer_size(&par->width, &par->height, size[0]); | |
| 445 | } else { | ||
| 446 | 14611 | f[0] = s1->pb; | |
| 447 |
3/6✓ Branch 1 taken 440 times.
✓ Branch 2 taken 14171 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 440 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
|
14611 | if (avio_feof(f[0]) && s->loop && s->is_pipe) |
| 448 | ✗ | avio_seek(f[0], 0, SEEK_SET); | |
| 449 |
2/2✓ Branch 1 taken 440 times.
✓ Branch 2 taken 14171 times.
|
14611 | if (avio_feof(f[0])) |
| 450 | 440 | return AVERROR_EOF; | |
| 451 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 14171 times.
|
14171 | if (s->frame_size > 0) { |
| 452 | ✗ | size[0] = s->frame_size; | |
| 453 |
2/2✓ Branch 1 taken 385 times.
✓ Branch 2 taken 13786 times.
|
14171 | } else if (!ffstream(s1->streams[0])->parser) { |
| 454 | 385 | size[0] = avio_size(s1->pb); | |
| 455 | } else { | ||
| 456 | 13786 | size[0] = 4096; | |
| 457 | } | ||
| 458 | } | ||
| 459 | |||
| 460 | 116461 | int total_size = 0; | |
| 461 |
2/2✓ Branch 0 taken 349383 times.
✓ Branch 1 taken 116461 times.
|
465844 | for (int i = 0; i < 3; i++) { |
| 462 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 349383 times.
|
349383 | if ((uint64_t)size[i] > INT_MAX - total_size) |
| 463 | ✗ | return AVERROR_INVALIDDATA; | |
| 464 | |||
| 465 | 349383 | total_size += size[i]; | |
| 466 | } | ||
| 467 | |||
| 468 | 116461 | res = av_new_packet(pkt, total_size); | |
| 469 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 116461 times.
|
116461 | if (res < 0) { |
| 470 | ✗ | goto fail; | |
| 471 | } | ||
| 472 | 116461 | pkt->stream_index = 0; | |
| 473 | 116461 | pkt->flags |= AV_PKT_FLAG_KEY; | |
| 474 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 116461 times.
|
116461 | if (s->ts_from_file) { |
| 475 | struct stat img_stat; | ||
| 476 | ✗ | av_assert0(!s->is_pipe); // The ts_from_file option is not supported by piped input demuxers | |
| 477 | ✗ | if (stat(filename.str, &img_stat)) { | |
| 478 | ✗ | res = AVERROR(errno); | |
| 479 | ✗ | goto fail; | |
| 480 | } | ||
| 481 | ✗ | pkt->pts = (int64_t)img_stat.st_mtime; | |
| 482 | #if HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC | ||
| 483 | ✗ | if (s->ts_from_file == 2) | |
| 484 | ✗ | pkt->pts = 1000000000*pkt->pts + img_stat.st_mtim.tv_nsec; | |
| 485 | #endif | ||
| 486 | ✗ | av_add_index_entry(s1->streams[0], s->img_number, pkt->pts, 0, 0, AVINDEX_KEYFRAME); | |
| 487 |
2/2✓ Branch 0 taken 102290 times.
✓ Branch 1 taken 14171 times.
|
116461 | } else if (!s->is_pipe) { |
| 488 | 102290 | pkt->pts = s->pts; | |
| 489 | } | ||
| 490 | |||
| 491 |
2/2✓ Branch 0 taken 14171 times.
✓ Branch 1 taken 102290 times.
|
116461 | if (s->is_pipe) |
| 492 | 14171 | pkt->pos = avio_tell(f[0]); | |
| 493 | |||
| 494 | /* | ||
| 495 | * export_path_metadata must be explicitly enabled via | ||
| 496 | * command line options for path metadata to be exported | ||
| 497 | * as packet side_data. | ||
| 498 | */ | ||
| 499 |
3/4✓ Branch 0 taken 102290 times.
✓ Branch 1 taken 14171 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 102290 times.
|
116461 | if (!s->is_pipe && s->export_path_metadata == 1) { |
| 500 | ✗ | res = add_filename_as_pkt_side_data(filename.str, pkt); | |
| 501 | ✗ | if (res < 0) | |
| 502 | ✗ | goto fail; | |
| 503 | } | ||
| 504 | 116461 | av_bprint_finalize(&filename, NULL); | |
| 505 | |||
| 506 | 116461 | pkt->size = 0; | |
| 507 |
2/2✓ Branch 0 taken 349383 times.
✓ Branch 1 taken 116461 times.
|
465844 | for (i = 0; i < 3; i++) { |
| 508 |
2/2✓ Branch 0 taken 116461 times.
✓ Branch 1 taken 232922 times.
|
349383 | if (f[i]) { |
| 509 | 116461 | ret[i] = avio_read(f[i], pkt->data + pkt->size, size[i]); | |
| 510 |
1/6✗ Branch 0 not taken.
✓ Branch 1 taken 116461 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
116461 | if (s->loop && s->is_pipe && ret[i] == AVERROR_EOF) { |
| 511 | ✗ | if (avio_seek(f[i], 0, SEEK_SET) >= 0) { | |
| 512 | ✗ | pkt->pos = 0; | |
| 513 | ✗ | ret[i] = avio_read(f[i], pkt->data + pkt->size, size[i]); | |
| 514 | } | ||
| 515 | } | ||
| 516 |
4/4✓ Branch 0 taken 102290 times.
✓ Branch 1 taken 14171 times.
✓ Branch 2 taken 102263 times.
✓ Branch 3 taken 27 times.
|
116461 | if (!s->is_pipe && f[i] != s1->pb) |
| 517 | 102263 | ff_format_io_close(s1, &f[i]); | |
| 518 |
2/2✓ Branch 0 taken 116272 times.
✓ Branch 1 taken 189 times.
|
116461 | if (ret[i] > 0) |
| 519 | 116272 | pkt->size += ret[i]; | |
| 520 | } | ||
| 521 | } | ||
| 522 | |||
| 523 |
4/6✓ Branch 0 taken 116272 times.
✓ Branch 1 taken 189 times.
✓ Branch 2 taken 116272 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 116272 times.
|
116461 | if (ret[0] <= 0 || ret[1] < 0 || ret[2] < 0) { |
| 524 |
1/2✓ Branch 0 taken 189 times.
✗ Branch 1 not taken.
|
189 | if (ret[0] < 0) { |
| 525 | 189 | res = ret[0]; | |
| 526 | ✗ | } else if (ret[1] < 0) { | |
| 527 | ✗ | res = ret[1]; | |
| 528 | ✗ | } else if (ret[2] < 0) { | |
| 529 | ✗ | res = ret[2]; | |
| 530 | } else { | ||
| 531 | ✗ | res = AVERROR_EOF; | |
| 532 | } | ||
| 533 | 189 | goto fail; | |
| 534 | } else { | ||
| 535 | 116272 | memset(pkt->data + pkt->size, 0, AV_INPUT_BUFFER_PADDING_SIZE); | |
| 536 | 116272 | s->img_count++; | |
| 537 | 116272 | s->img_number++; | |
| 538 | 116272 | s->pts++; | |
| 539 | 116272 | return 0; | |
| 540 | } | ||
| 541 | |||
| 542 | 189 | fail: | |
| 543 | 189 | av_bprint_finalize(&filename, NULL); | |
| 544 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 189 times.
|
189 | if (!s->is_pipe) { |
| 545 | ✗ | for (i = 0; i < 3; i++) { | |
| 546 | ✗ | if (f[i] != s1->pb) | |
| 547 | ✗ | ff_format_io_close(s1, &f[i]); | |
| 548 | } | ||
| 549 | } | ||
| 550 | 189 | return res; | |
| 551 | } | ||
| 552 | |||
| 553 | 3142 | static int img_read_close(struct AVFormatContext* s1) | |
| 554 | { | ||
| 555 | #if HAVE_GLOB | ||
| 556 | 3142 | VideoDemuxData *s = s1->priv_data; | |
| 557 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3142 times.
|
3142 | if (s->use_glob) { |
| 558 | ✗ | globfree(&s->globstate); | |
| 559 | } | ||
| 560 | #endif | ||
| 561 | 3142 | return 0; | |
| 562 | } | ||
| 563 | |||
| 564 | 208 | static int img_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags) | |
| 565 | { | ||
| 566 | 208 | VideoDemuxData *s1 = s->priv_data; | |
| 567 | 208 | AVStream *st = s->streams[0]; | |
| 568 | |||
| 569 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 208 times.
|
208 | if (s1->ts_from_file) { |
| 570 | ✗ | int index = av_index_search_timestamp(st, timestamp, flags); | |
| 571 | ✗ | if(index < 0) | |
| 572 | ✗ | return -1; | |
| 573 | ✗ | s1->img_number = ffstream(st)->index_entries[index].pos; | |
| 574 | ✗ | return 0; | |
| 575 | } | ||
| 576 | |||
| 577 |
5/6✓ Branch 0 taken 144 times.
✓ Branch 1 taken 64 times.
✓ Branch 2 taken 144 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 120 times.
✓ Branch 5 taken 24 times.
|
208 | if (timestamp < 0 || !s1->loop && timestamp > s1->img_last - s1->img_first) |
| 578 | 184 | return -1; | |
| 579 | 24 | s1->img_number = timestamp%(s1->img_last - s1->img_first + 1) + s1->img_first; | |
| 580 | 24 | s1->pts = timestamp; | |
| 581 | 24 | return 0; | |
| 582 | } | ||
| 583 | |||
| 584 | #define OFFSET(x) offsetof(VideoDemuxData, x) | ||
| 585 | #define DEC AV_OPT_FLAG_DECODING_PARAM | ||
| 586 | #define COMMON_OPTIONS \ | ||
| 587 | { "framerate", "set the video framerate", OFFSET(framerate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT_MAX, DEC }, \ | ||
| 588 | { "pixel_format", "set video pixel format", OFFSET(pixel_format), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC }, \ | ||
| 589 | { "video_size", "set video size", OFFSET(width), AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL}, 0, 0, DEC }, \ | ||
| 590 | { "loop", "force loop over input file sequence", OFFSET(loop), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, DEC }, \ | ||
| 591 | { NULL }, | ||
| 592 | |||
| 593 | #if CONFIG_IMAGE2_DEMUXER | ||
| 594 | const AVOption ff_img_options[] = { | ||
| 595 | { "pattern_type", "set pattern type", OFFSET(pattern_type), AV_OPT_TYPE_INT, {.i64=PT_DEFAULT}, 0, INT_MAX, DEC, .unit = "pattern_type"}, | ||
| 596 | { "glob", "select glob pattern type", 0, AV_OPT_TYPE_CONST, {.i64=PT_GLOB }, INT_MIN, INT_MAX, DEC, .unit = "pattern_type" }, | ||
| 597 | { "sequence", "select sequence pattern type", 0, AV_OPT_TYPE_CONST, {.i64=PT_SEQUENCE }, INT_MIN, INT_MAX, DEC, .unit = "pattern_type" }, | ||
| 598 | { "none", "disable pattern matching", 0, AV_OPT_TYPE_CONST, {.i64=PT_NONE }, INT_MIN, INT_MAX, DEC, .unit = "pattern_type" }, | ||
| 599 | { "start_number", "set first number in the sequence", OFFSET(start_number), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, DEC }, | ||
| 600 | { "start_number_range", "set range for looking at the first sequence number", OFFSET(start_number_range), AV_OPT_TYPE_INT, {.i64 = 5}, 1, INT_MAX, DEC }, | ||
| 601 | { "ts_from_file", "set frame timestamp from file's one", OFFSET(ts_from_file), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, 2, DEC, .unit = "ts_type" }, | ||
| 602 | { "none", "none", 0, AV_OPT_TYPE_CONST, {.i64 = 0 }, 0, 2, DEC, .unit = "ts_type" }, | ||
| 603 | { "sec", "second precision", 0, AV_OPT_TYPE_CONST, {.i64 = 1 }, 0, 2, DEC, .unit = "ts_type" }, | ||
| 604 | { "ns", "nano second precision", 0, AV_OPT_TYPE_CONST, {.i64 = 2 }, 0, 2, DEC, .unit = "ts_type" }, | ||
| 605 | { "export_path_metadata", "enable metadata containing input path information", OFFSET(export_path_metadata), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, DEC }, \ | ||
| 606 | COMMON_OPTIONS | ||
| 607 | }; | ||
| 608 | |||
| 609 | static const AVClass img2_class = { | ||
| 610 | .class_name = "image2 demuxer", | ||
| 611 | .item_name = av_default_item_name, | ||
| 612 | .option = ff_img_options, | ||
| 613 | .version = LIBAVUTIL_VERSION_INT, | ||
| 614 | }; | ||
| 615 | const FFInputFormat ff_image2_demuxer = { | ||
| 616 | .p.name = "image2", | ||
| 617 | .p.long_name = NULL_IF_CONFIG_SMALL("image2 sequence"), | ||
| 618 | .p.flags = AVFMT_NOFILE, | ||
| 619 | .p.priv_class = &img2_class, | ||
| 620 | .priv_data_size = sizeof(VideoDemuxData), | ||
| 621 | .read_probe = img_read_probe, | ||
| 622 | .read_header = ff_img_read_header, | ||
| 623 | .read_packet = ff_img_read_packet, | ||
| 624 | .read_close = img_read_close, | ||
| 625 | .read_seek = img_read_seek, | ||
| 626 | }; | ||
| 627 | #endif | ||
| 628 | |||
| 629 | static const AVOption img2pipe_options[] = { | ||
| 630 | { "frame_size", "force frame size in bytes", OFFSET(frame_size), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, INT_MAX, DEC }, | ||
| 631 | COMMON_OPTIONS | ||
| 632 | }; | ||
| 633 | static const AVClass imagepipe_class = { | ||
| 634 | .class_name = "imagepipe demuxer", | ||
| 635 | .item_name = av_default_item_name, | ||
| 636 | .option = img2pipe_options, | ||
| 637 | .version = LIBAVUTIL_VERSION_INT, | ||
| 638 | }; | ||
| 639 | |||
| 640 | #if CONFIG_IMAGE2PIPE_DEMUXER | ||
| 641 | const FFInputFormat ff_image2pipe_demuxer = { | ||
| 642 | .p.name = "image2pipe", | ||
| 643 | .p.long_name = NULL_IF_CONFIG_SMALL("piped image2 sequence"), | ||
| 644 | .p.priv_class = &imagepipe_class, | ||
| 645 | .priv_data_size = sizeof(VideoDemuxData), | ||
| 646 | .read_header = ff_img_read_header, | ||
| 647 | .read_packet = ff_img_read_packet, | ||
| 648 | }; | ||
| 649 | #endif | ||
| 650 | |||
| 651 | 7510 | static int bmp_probe(const AVProbeData *p) | |
| 652 | { | ||
| 653 | 7510 | const uint8_t *b = p->buf; | |
| 654 | int ihsize; | ||
| 655 | |||
| 656 |
2/2✓ Branch 0 taken 7495 times.
✓ Branch 1 taken 15 times.
|
7510 | if (AV_RB16(b) != 0x424d) |
| 657 | 7495 | return 0; | |
| 658 | |||
| 659 | 15 | ihsize = AV_RL32(b+14); | |
| 660 |
2/4✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 15 times.
|
15 | if (ihsize < 12 || ihsize > 255) |
| 661 | ✗ | return 0; | |
| 662 | |||
| 663 |
1/2✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
|
15 | if (!AV_RN32(b + 6)) { |
| 664 | 15 | return AVPROBE_SCORE_EXTENSION + 1; | |
| 665 | } | ||
| 666 | ✗ | return AVPROBE_SCORE_EXTENSION / 4; | |
| 667 | } | ||
| 668 | |||
| 669 | 7509 | static int cri_probe(const AVProbeData *p) | |
| 670 | { | ||
| 671 | 7509 | const uint8_t *b = p->buf; | |
| 672 | |||
| 673 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 7499 times.
|
7509 | if ( AV_RL32(b) == 1 |
| 674 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
|
10 | && AV_RL32(b + 4) == 4 |
| 675 | ✗ | && AV_RN32(b + 8) == AV_RN32("DVCC")) | |
| 676 | ✗ | return AVPROBE_SCORE_MAX - 1; | |
| 677 | 7509 | return 0; | |
| 678 | } | ||
| 679 | |||
| 680 | 7509 | static int dds_probe(const AVProbeData *p) | |
| 681 | { | ||
| 682 | 7509 | const uint8_t *b = p->buf; | |
| 683 | |||
| 684 |
2/2✓ Branch 0 taken 48 times.
✓ Branch 1 taken 7461 times.
|
7509 | if ( AV_RB64(b) == 0x444453207c000000 |
| 685 |
1/2✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
|
48 | && AV_RL32(b + 8) |
| 686 |
1/2✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
|
48 | && AV_RL32(b + 12)) |
| 687 | 48 | return AVPROBE_SCORE_MAX - 1; | |
| 688 | 7461 | return 0; | |
| 689 | } | ||
| 690 | |||
| 691 | 7509 | static int dpx_probe(const AVProbeData *p) | |
| 692 | { | ||
| 693 | 7509 | const uint8_t *b = p->buf; | |
| 694 | int w, h; | ||
| 695 | 7509 | int is_big = (AV_RN32(b) == AV_RN32("SDPX")); | |
| 696 | |||
| 697 |
2/2✓ Branch 0 taken 109 times.
✓ Branch 1 taken 7400 times.
|
7509 | if (p->buf_size < 0x304+8) |
| 698 | 109 | return 0; | |
| 699 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 7399 times.
|
7400 | w = is_big ? AV_RB32(p->buf + 0x304) : AV_RL32(p->buf + 0x304); |
| 700 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 7399 times.
|
7400 | h = is_big ? AV_RB32(p->buf + 0x308) : AV_RL32(p->buf + 0x308); |
| 701 |
4/4✓ Branch 0 taken 3510 times.
✓ Branch 1 taken 3890 times.
✓ Branch 2 taken 744 times.
✓ Branch 3 taken 2766 times.
|
7400 | if (w <= 0 || h <= 0) |
| 702 | 4634 | return 0; | |
| 703 | |||
| 704 |
4/4✓ Branch 0 taken 2765 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 2763 times.
|
2766 | if (is_big || AV_RN32(b) == AV_RN32("XPDS")) |
| 705 | 3 | return AVPROBE_SCORE_EXTENSION + 1; | |
| 706 | 2763 | return 0; | |
| 707 | } | ||
| 708 | |||
| 709 | 7508 | static int exr_probe(const AVProbeData *p) | |
| 710 | { | ||
| 711 | 7508 | const uint8_t *b = p->buf; | |
| 712 | |||
| 713 |
2/2✓ Branch 0 taken 74 times.
✓ Branch 1 taken 7434 times.
|
7508 | if (AV_RL32(b) == 20000630) |
| 714 | 74 | return AVPROBE_SCORE_EXTENSION + 1; | |
| 715 | 7434 | return 0; | |
| 716 | } | ||
| 717 | |||
| 718 | 7508 | static int j2k_probe(const AVProbeData *p) | |
| 719 | { | ||
| 720 | 7508 | const uint8_t *b = p->buf; | |
| 721 | |||
| 722 |
1/2✓ Branch 0 taken 7508 times.
✗ Branch 1 not taken.
|
7508 | if (AV_RB64(b) == 0x0000000c6a502020 || |
| 723 |
2/2✓ Branch 0 taken 15 times.
✓ Branch 1 taken 7493 times.
|
7508 | AV_RB32(b) == 0xff4fff51) |
| 724 | 15 | return AVPROBE_SCORE_EXTENSION + 1; | |
| 725 | 7493 | return 0; | |
| 726 | } | ||
| 727 | |||
| 728 | 7508 | static int jpeg_probe(const AVProbeData *p) | |
| 729 | { | ||
| 730 | 7508 | const uint8_t *b = p->buf; | |
| 731 | 7508 | int i, state = SOI, got_header = 0; | |
| 732 | |||
| 733 |
2/2✓ Branch 0 taken 34 times.
✓ Branch 1 taken 7474 times.
|
7508 | if (AV_RB16(b) != 0xFFD8 || |
| 734 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 30 times.
|
34 | AV_RB32(b) == 0xFFD8FFF7) |
| 735 | 7478 | return 0; | |
| 736 | |||
| 737 | 30 | b += 2; | |
| 738 |
2/2✓ Branch 0 taken 27903 times.
✓ Branch 1 taken 26 times.
|
27929 | for (i = 0; i < p->buf_size - 3; i++) { |
| 739 | int c; | ||
| 740 |
2/2✓ Branch 0 taken 27546 times.
✓ Branch 1 taken 357 times.
|
27903 | if (b[i] != 0xFF) |
| 741 | 27546 | continue; | |
| 742 | 357 | c = b[i + 1]; | |
| 743 |
7/8✗ Branch 0 not taken.
✓ Branch 1 taken 19 times.
✓ Branch 2 taken 118 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 18 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 45 times.
✓ Branch 7 taken 154 times.
|
357 | switch (c) { |
| 744 | ✗ | case SOI: | |
| 745 | ✗ | return 0; | |
| 746 | 19 | case SOF0: | |
| 747 | case SOF1: | ||
| 748 | case SOF2: | ||
| 749 | case SOF3: | ||
| 750 | case SOF5: | ||
| 751 | case SOF6: | ||
| 752 | case SOF7: | ||
| 753 | 19 | i += AV_RB16(&b[i + 2]) + 1; | |
| 754 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 19 times.
|
19 | if (state != SOI) |
| 755 | ✗ | return 0; | |
| 756 | 19 | state = SOF0; | |
| 757 | 19 | break; | |
| 758 | 118 | case SOS: | |
| 759 | 118 | i += AV_RB16(&b[i + 2]) + 1; | |
| 760 |
4/4✓ Branch 0 taken 99 times.
✓ Branch 1 taken 19 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 95 times.
|
118 | if (state != SOF0 && state != SOS) |
| 761 | 4 | return 0; | |
| 762 | 114 | state = SOS; | |
| 763 | 114 | break; | |
| 764 | 1 | case EOI: | |
| 765 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (state != SOS) |
| 766 | ✗ | return 0; | |
| 767 | 1 | state = EOI; | |
| 768 | 1 | break; | |
| 769 | 18 | case APP0: | |
| 770 |
3/4✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✓ Branch 3 taken 2 times.
|
18 | if (c == APP0 && AV_RL32(&b[i + 4]) == MKTAG('J','F','I','F')) |
| 771 | 16 | got_header = 1; | |
| 772 | /* fallthrough */ | ||
| 773 | case APP1: | ||
| 774 |
3/4✓ Branch 0 taken 2 times.
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
20 | if (c == APP1 && AV_RL32(&b[i + 4]) == MKTAG('E','x','i','f')) |
| 775 | 2 | got_header = 1; | |
| 776 | /* fallthrough */ | ||
| 777 | case APP2: | ||
| 778 | case APP3: | ||
| 779 | case APP4: | ||
| 780 | case APP5: | ||
| 781 | case APP6: | ||
| 782 | case APP7: | ||
| 783 | case APP8: | ||
| 784 | case APP9: | ||
| 785 | case APP10: | ||
| 786 | case APP11: | ||
| 787 | case APP12: | ||
| 788 | case APP13: | ||
| 789 | case APP14: | ||
| 790 | case APP15: | ||
| 791 | case DQT: /* fallthrough */ | ||
| 792 | case COM: | ||
| 793 | 65 | i += AV_RB16(&b[i + 2]) + 1; | |
| 794 | 65 | break; | |
| 795 | 154 | default: | |
| 796 |
3/4✓ Branch 0 taken 106 times.
✓ Branch 1 taken 48 times.
✓ Branch 2 taken 106 times.
✗ Branch 3 not taken.
|
154 | if ( (c > TEM && c < SOF0) |
| 797 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 154 times.
|
154 | || c == JPG) |
| 798 | ✗ | return 0; | |
| 799 | } | ||
| 800 | } | ||
| 801 | |||
| 802 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 25 times.
|
26 | if (state == EOI) |
| 803 | 1 | return AVPROBE_SCORE_EXTENSION + 1; | |
| 804 |
2/2✓ Branch 0 taken 18 times.
✓ Branch 1 taken 7 times.
|
25 | if (state == SOS) |
| 805 | 18 | return AVPROBE_SCORE_EXTENSION / 2 + got_header; | |
| 806 | 7 | return AVPROBE_SCORE_EXTENSION / 8 + 1; | |
| 807 | } | ||
| 808 | |||
| 809 | 7498 | static int jpegls_probe(const AVProbeData *p) | |
| 810 | { | ||
| 811 | 7498 | const uint8_t *b = p->buf; | |
| 812 | |||
| 813 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 7494 times.
|
7498 | if (AV_RB32(b) == 0xffd8fff7) |
| 814 | 4 | return AVPROBE_SCORE_EXTENSION + 1; | |
| 815 | 7494 | return 0; | |
| 816 | } | ||
| 817 | |||
| 818 | 7498 | static int jpegxl_probe(const AVProbeData *p) | |
| 819 | { | ||
| 820 | 7498 | const uint8_t *b = p->buf; | |
| 821 | |||
| 822 | /* ISOBMFF-based container */ | ||
| 823 | /* 0x4a584c20 == "JXL " */ | ||
| 824 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 7494 times.
|
7498 | if (AV_RL64(b) == FF_JPEGXL_CONTAINER_SIGNATURE_LE) |
| 825 | 4 | return AVPROBE_SCORE_EXTENSION + 1; | |
| 826 | /* Raw codestreams all start with 0xff0a */ | ||
| 827 |
2/2✓ Branch 0 taken 7491 times.
✓ Branch 1 taken 3 times.
|
7494 | if (AV_RL16(b) != FF_JPEGXL_CODESTREAM_SIGNATURE_LE) |
| 828 | 7491 | return 0; | |
| 829 | #if CONFIG_IMAGE_JPEGXL_PIPE_DEMUXER | ||
| 830 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
3 | if (ff_jpegxl_parse_codestream_header(p->buf, p->buf_size, NULL, 5) >= 0) |
| 831 | 3 | return AVPROBE_SCORE_MAX - 2; | |
| 832 | #endif | ||
| 833 | ✗ | return 0; | |
| 834 | } | ||
| 835 | |||
| 836 | 7498 | static int jpegxs_probe(const AVProbeData *p) | |
| 837 | { | ||
| 838 | 7498 | const uint8_t *b = p->buf; | |
| 839 | |||
| 840 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 7497 times.
|
7498 | if (AV_RB32(b) == 0xff10ff50) |
| 841 | 1 | return AVPROBE_SCORE_EXTENSION + 1; | |
| 842 | 7497 | return 0; | |
| 843 | } | ||
| 844 | |||
| 845 | 7497 | static int pcx_probe(const AVProbeData *p) | |
| 846 | { | ||
| 847 | 7497 | const uint8_t *b = p->buf; | |
| 848 | |||
| 849 |
2/2✓ Branch 0 taken 7490 times.
✓ Branch 1 taken 7 times.
|
7497 | if ( p->buf_size < 128 |
| 850 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7490 times.
|
7490 | || b[0] != 10 |
| 851 | ✗ | || b[1] > 5 | |
| 852 | ✗ | || b[2] > 1 | |
| 853 | ✗ | || av_popcount(b[3]) != 1 || b[3] > 8 | |
| 854 | ✗ | || AV_RL16(&b[4]) > AV_RL16(&b[8]) | |
| 855 | ✗ | || AV_RL16(&b[6]) > AV_RL16(&b[10]) | |
| 856 | ✗ | || b[64]) | |
| 857 | 7497 | return 0; | |
| 858 | ✗ | b += 73; | |
| 859 | ✗ | while (++b < p->buf + 128) | |
| 860 | ✗ | if (*b) | |
| 861 | ✗ | return AVPROBE_SCORE_EXTENSION / 4; | |
| 862 | |||
| 863 | ✗ | return AVPROBE_SCORE_EXTENSION + 1; | |
| 864 | } | ||
| 865 | |||
| 866 | 7493 | static int qdraw_probe(const AVProbeData *p) | |
| 867 | { | ||
| 868 | 7493 | const uint8_t *b = p->buf; | |
| 869 | |||
| 870 |
2/2✓ Branch 0 taken 7397 times.
✓ Branch 1 taken 96 times.
|
7493 | if ( p->buf_size >= 528 |
| 871 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7397 times.
|
7397 | && (AV_RB64(b + 520) & 0xFFFFFFFFFFFF) == 0x001102ff0c00 |
| 872 | ✗ | && AV_RB16(b + 520) | |
| 873 | ✗ | && AV_RB16(b + 518)) | |
| 874 | ✗ | return AVPROBE_SCORE_MAX * 3 / 4; | |
| 875 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 7491 times.
|
7493 | if ( (AV_RB64(b + 8) & 0xFFFFFFFFFFFF) == 0x001102ff0c00 |
| 876 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | && AV_RB16(b + 8) |
| 877 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | && AV_RB16(b + 6)) |
| 878 | 2 | return AVPROBE_SCORE_EXTENSION / 4; | |
| 879 | 7491 | return 0; | |
| 880 | } | ||
| 881 | |||
| 882 | 7496 | static int pictor_probe(const AVProbeData *p) | |
| 883 | { | ||
| 884 | 7496 | const uint8_t *b = p->buf; | |
| 885 | |||
| 886 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 7494 times.
|
7496 | if (AV_RL16(b) == 0x1234) |
| 887 | 2 | return AVPROBE_SCORE_EXTENSION / 4; | |
| 888 | 7494 | return 0; | |
| 889 | } | ||
| 890 | |||
| 891 | 7495 | static int png_probe(const AVProbeData *p) | |
| 892 | { | ||
| 893 | 7495 | const uint8_t *b = p->buf; | |
| 894 | |||
| 895 |
2/2✓ Branch 0 taken 50 times.
✓ Branch 1 taken 7445 times.
|
7495 | if (AV_RB64(b) == 0x89504e470d0a1a0a) |
| 896 | 50 | return AVPROBE_SCORE_MAX - 1; | |
| 897 | 7445 | return 0; | |
| 898 | } | ||
| 899 | |||
| 900 | 7493 | static int psd_probe(const AVProbeData *p) | |
| 901 | { | ||
| 902 | 7493 | const uint8_t *b = p->buf; | |
| 903 | 7493 | int ret = 0; | |
| 904 | uint16_t color_mode; | ||
| 905 | |||
| 906 |
2/2✓ Branch 0 taken 16 times.
✓ Branch 1 taken 7477 times.
|
7493 | if (AV_RL32(b) == MKTAG('8','B','P','S')) { |
| 907 | 16 | ret += 1; | |
| 908 | } else { | ||
| 909 | 7477 | return 0; | |
| 910 | } | ||
| 911 | |||
| 912 |
2/4✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
|
16 | if ((b[4] == 0) && (b[5] == 1)) {/* version 1 is PSD, version 2 is PSB */ |
| 913 | 16 | ret += 1; | |
| 914 | } else { | ||
| 915 | ✗ | return 0; | |
| 916 | } | ||
| 917 | |||
| 918 |
2/4✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
|
16 | if ((AV_RL32(b+6) == 0) && (AV_RL16(b+10) == 0))/* reserved must be 0 */ |
| 919 | 16 | ret += 1; | |
| 920 | |||
| 921 | 16 | color_mode = AV_RB16(b+24); | |
| 922 |
3/6✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
|
16 | if ((color_mode <= 9) && (color_mode != 5) && (color_mode != 6)) |
| 923 | 16 | ret += 1; | |
| 924 | |||
| 925 | 16 | return AVPROBE_SCORE_EXTENSION + ret; | |
| 926 | } | ||
| 927 | |||
| 928 | 7491 | static int sgi_probe(const AVProbeData *p) | |
| 929 | { | ||
| 930 | 7491 | const uint8_t *b = p->buf; | |
| 931 | |||
| 932 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 7479 times.
|
7491 | if (AV_RB16(b) == 474 && |
| 933 |
1/2✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
|
12 | (b[2] & ~1) == 0 && |
| 934 |
2/4✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
|
12 | (b[3] & ~3) == 0 && b[3] && |
| 935 |
2/4✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
|
12 | (AV_RB16(b + 4) & ~7) == 0 && AV_RB16(b + 4)) |
| 936 | 12 | return AVPROBE_SCORE_EXTENSION + 1; | |
| 937 | 7479 | return 0; | |
| 938 | } | ||
| 939 | |||
| 940 | 7491 | static int sunrast_probe(const AVProbeData *p) | |
| 941 | { | ||
| 942 | 7491 | const uint8_t *b = p->buf; | |
| 943 | |||
| 944 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 7484 times.
|
7491 | if (AV_RB32(b) == 0x59a66a95) |
| 945 | 7 | return AVPROBE_SCORE_EXTENSION + 1; | |
| 946 | 7484 | return 0; | |
| 947 | } | ||
| 948 | |||
| 949 | 7491 | static int svg_probe(const AVProbeData *p) | |
| 950 | { | ||
| 951 | 7491 | const uint8_t *b = p->buf; | |
| 952 | 7491 | const uint8_t *end = p->buf + p->buf_size; | |
| 953 |
3/4✓ Branch 0 taken 7569 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 78 times.
✓ Branch 3 taken 7491 times.
|
7569 | while (b < end && av_isspace(*b)) |
| 954 | 78 | b++; | |
| 955 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7491 times.
|
7491 | if (b >= end - 5) |
| 956 | ✗ | return 0; | |
| 957 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7491 times.
|
7491 | if (!memcmp(b, "<svg", 4)) |
| 958 | ✗ | return AVPROBE_SCORE_EXTENSION + 1; | |
| 959 |
2/4✓ Branch 0 taken 7491 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7491 times.
✗ Branch 3 not taken.
|
7491 | if (memcmp(p->buf, "<?xml", 5) && memcmp(b, "<!--", 4)) |
| 960 | 7491 | return 0; | |
| 961 | ✗ | while (b < end) { | |
| 962 | ✗ | int inc = ff_subtitles_next_line(b); | |
| 963 | ✗ | if (!inc) | |
| 964 | ✗ | break; | |
| 965 | ✗ | b += inc; | |
| 966 | ✗ | if (b >= end - 4) | |
| 967 | ✗ | return 0; | |
| 968 | ✗ | if (!memcmp(b, "<svg", 4)) | |
| 969 | ✗ | return AVPROBE_SCORE_EXTENSION + 1; | |
| 970 | } | ||
| 971 | ✗ | return 0; | |
| 972 | } | ||
| 973 | |||
| 974 | 7491 | static int tiff_probe(const AVProbeData *p) | |
| 975 | { | ||
| 976 | 7491 | const uint8_t *b = p->buf; | |
| 977 | |||
| 978 |
2/2✓ Branch 0 taken 7480 times.
✓ Branch 1 taken 11 times.
|
7491 | if (AV_RB32(b) == 0x49492a00 || |
| 979 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 7478 times.
|
7480 | AV_RB32(b) == 0x4D4D002a) |
| 980 | 13 | return AVPROBE_SCORE_EXTENSION + 1; | |
| 981 | 7478 | return 0; | |
| 982 | } | ||
| 983 | |||
| 984 | 7491 | static int webp_probe(const AVProbeData *p) | |
| 985 | { | ||
| 986 | 7491 | const uint8_t *b = p->buf; | |
| 987 | |||
| 988 |
2/2✓ Branch 0 taken 988 times.
✓ Branch 1 taken 6503 times.
|
7491 | if (AV_RB32(b) == 0x52494646 && |
| 989 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 980 times.
|
988 | AV_RB32(b + 8) == 0x57454250) |
| 990 | 8 | return AVPROBE_SCORE_MAX - 1; | |
| 991 | 7483 | return 0; | |
| 992 | } | ||
| 993 | |||
| 994 | 97456 | static int pnm_magic_check(const AVProbeData *p, int magic) | |
| 995 | { | ||
| 996 | 97456 | const uint8_t *b = p->buf; | |
| 997 | |||
| 998 |
4/4✓ Branch 0 taken 298 times.
✓ Branch 1 taken 97158 times.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 289 times.
|
97456 | return b[0] == 'P' && b[1] == magic + '0'; |
| 999 | } | ||
| 1000 | |||
| 1001 | 9 | static inline int pnm_probe(const AVProbeData *p) | |
| 1002 | { | ||
| 1003 | 9 | const uint8_t *b = p->buf; | |
| 1004 | |||
| 1005 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
|
9 | while (b[2] == '\r') |
| 1006 | ✗ | b++; | |
| 1007 |
5/8✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 8 times.
✗ Branch 7 not taken.
|
9 | if (b[2] == '\n' && (b[3] == '#' || (b[3] >= '0' && b[3] <= '9'))) |
| 1008 | 9 | return AVPROBE_SCORE_EXTENSION + 2; | |
| 1009 | ✗ | return 0; | |
| 1010 | } | ||
| 1011 | |||
| 1012 | 7498 | static int pbm_probe(const AVProbeData *p) | |
| 1013 | { | ||
| 1014 |
3/4✓ Branch 1 taken 7498 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 7496 times.
|
7498 | return pnm_magic_check(p, 1) || pnm_magic_check(p, 4) ? pnm_probe(p) : 0; |
| 1015 | } | ||
| 1016 | |||
| 1017 | 7497 | static int pfm_probe(const AVProbeData *p) | |
| 1018 | { | ||
| 1019 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 7497 times.
|
14994 | return pnm_magic_check(p, 'F' - '0') || |
| 1020 |
1/2✓ Branch 0 taken 7497 times.
✗ Branch 1 not taken.
|
14994 | pnm_magic_check(p, 'f' - '0') ? pnm_probe(p) : 0; |
| 1021 | } | ||
| 1022 | |||
| 1023 | 7496 | static int phm_probe(const AVProbeData *p) | |
| 1024 | { | ||
| 1025 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 7496 times.
|
14992 | return pnm_magic_check(p, 'H' - '0') || |
| 1026 |
1/2✓ Branch 0 taken 7496 times.
✗ Branch 1 not taken.
|
14992 | pnm_magic_check(p, 'h' - '0') ? pnm_probe(p) : 0; |
| 1027 | } | ||
| 1028 | |||
| 1029 | 14994 | static inline int pgmx_probe(const AVProbeData *p) | |
| 1030 | { | ||
| 1031 |
3/4✓ Branch 1 taken 14994 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✓ Branch 5 taken 14990 times.
|
14994 | return pnm_magic_check(p, 2) || pnm_magic_check(p, 5) ? pnm_probe(p) : 0; |
| 1032 | } | ||
| 1033 | |||
| 1034 | 7497 | static int pgm_probe(const AVProbeData *p) | |
| 1035 | { | ||
| 1036 | 7497 | int ret = pgmx_probe(p); | |
| 1037 |
3/4✓ Branch 0 taken 2 times.
✓ Branch 1 taken 7495 times.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
|
7497 | return ret && !av_match_ext(p->filename, "pgmyuv") ? ret : 0; |
| 1038 | } | ||
| 1039 | |||
| 1040 | 7497 | static int pgmyuv_probe(const AVProbeData *p) // custom FFmpeg format recognized by file extension | |
| 1041 | { | ||
| 1042 | 7497 | int ret = pgmx_probe(p); | |
| 1043 |
3/4✓ Branch 0 taken 2 times.
✓ Branch 1 taken 7495 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
|
7497 | return ret && av_match_ext(p->filename, "pgmyuv") ? ret : 0; |
| 1044 | } | ||
| 1045 | |||
| 1046 | 7496 | static int pgx_probe(const AVProbeData *p) | |
| 1047 | { | ||
| 1048 | 7496 | const uint8_t *b = p->buf; | |
| 1049 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7496 times.
|
7496 | if (!memcmp(b, "PG ML ", 6)) |
| 1050 | ✗ | return AVPROBE_SCORE_EXTENSION + 1; | |
| 1051 | 7496 | return 0; | |
| 1052 | } | ||
| 1053 | |||
| 1054 | 7494 | static int ppm_probe(const AVProbeData *p) | |
| 1055 | { | ||
| 1056 |
3/4✓ Branch 1 taken 7494 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 7491 times.
|
7494 | return pnm_magic_check(p, 3) || pnm_magic_check(p, 6) ? pnm_probe(p) : 0; |
| 1057 | } | ||
| 1058 | |||
| 1059 | 7498 | static int pam_probe(const AVProbeData *p) | |
| 1060 | { | ||
| 1061 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 7498 times.
|
7498 | return pnm_magic_check(p, 7) ? pnm_probe(p) : 0; |
| 1062 | } | ||
| 1063 | |||
| 1064 | 7508 | static int hdr_probe(const AVProbeData *p) | |
| 1065 | { | ||
| 1066 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7508 times.
|
7508 | if (!memcmp(p->buf, "#?RADIANCE\n", 11)) |
| 1067 | ✗ | return AVPROBE_SCORE_MAX; | |
| 1068 | 7508 | return 0; | |
| 1069 | } | ||
| 1070 | |||
| 1071 | 7491 | static int xbm_probe(const AVProbeData *p) | |
| 1072 | { | ||
| 1073 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 7490 times.
|
7491 | if (!memcmp(p->buf, "/* XBM X10 format */", 20)) |
| 1074 | 1 | return AVPROBE_SCORE_MAX; | |
| 1075 | |||
| 1076 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 7488 times.
|
7490 | if (!memcmp(p->buf, "#define", 7)) |
| 1077 | 2 | return AVPROBE_SCORE_MAX - 1; | |
| 1078 | 7488 | return 0; | |
| 1079 | } | ||
| 1080 | |||
| 1081 | 7490 | static int xpm_probe(const AVProbeData *p) | |
| 1082 | { | ||
| 1083 | 7490 | const uint8_t *b = p->buf; | |
| 1084 | |||
| 1085 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 7490 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
7490 | if (AV_RB64(b) == 0x2f2a2058504d202a && *(b+8) == '/') |
| 1086 | ✗ | return AVPROBE_SCORE_MAX - 1; | |
| 1087 | 7490 | return 0; | |
| 1088 | } | ||
| 1089 | |||
| 1090 | 7490 | static int xwd_probe(const AVProbeData *p) | |
| 1091 | { | ||
| 1092 | 7490 | const uint8_t *b = p->buf; | |
| 1093 | unsigned width, bpp, bpad, lsize; | ||
| 1094 | |||
| 1095 |
2/2✓ Branch 0 taken 7484 times.
✓ Branch 1 taken 6 times.
|
7490 | if ( p->buf_size < XWD_HEADER_SIZE |
| 1096 |
2/2✓ Branch 0 taken 6453 times.
✓ Branch 1 taken 1031 times.
|
7484 | || AV_RB32(b ) < XWD_HEADER_SIZE // header size |
| 1097 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 6452 times.
|
6453 | || AV_RB32(b + 4) != XWD_VERSION // version |
| 1098 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | || AV_RB32(b + 8) != XWD_Z_PIXMAP // format |
| 1099 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | || AV_RB32(b + 12) > 32 || !AV_RB32(b + 12) // depth |
| 1100 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | || AV_RB32(b + 16) == 0 // width |
| 1101 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | || AV_RB32(b + 20) == 0 // height |
| 1102 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | || AV_RB32(b + 28) > 1 // byteorder |
| 1103 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | || AV_RB32(b + 32) & ~56 || av_popcount(AV_RB32(b + 32)) != 1 // bitmap unit |
| 1104 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | || AV_RB32(b + 36) > 1 // bitorder |
| 1105 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | || AV_RB32(b + 40) & ~56 || av_popcount(AV_RB32(b + 40)) != 1 // padding |
| 1106 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | || AV_RB32(b + 44) > 32 || !AV_RB32(b + 44) // bpp |
| 1107 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | || AV_RB32(b + 68) > 256) // colours |
| 1108 | 7489 | return 0; | |
| 1109 | |||
| 1110 | 1 | width = AV_RB32(b + 16); | |
| 1111 | 1 | bpad = AV_RB32(b + 40); | |
| 1112 | 1 | bpp = AV_RB32(b + 44); | |
| 1113 | 1 | lsize = AV_RB32(b + 48); | |
| 1114 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (lsize < FFALIGN(width * bpp, bpad) >> 3) |
| 1115 | ✗ | return 0; | |
| 1116 | |||
| 1117 | 1 | return AVPROBE_SCORE_MAX / 2 + 1; | |
| 1118 | } | ||
| 1119 | |||
| 1120 | 7508 | static int gif_probe(const AVProbeData *p) | |
| 1121 | { | ||
| 1122 | /* check magick */ | ||
| 1123 |
3/4✓ Branch 0 taken 7508 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7493 times.
✓ Branch 3 taken 15 times.
|
7508 | if (memcmp(p->buf, gif87a_sig, 6) && memcmp(p->buf, gif89a_sig, 6)) |
| 1124 | 7493 | return 0; | |
| 1125 | |||
| 1126 | /* width or height contains zero? */ | ||
| 1127 |
2/4✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 15 times.
|
15 | if (!AV_RL16(&p->buf[6]) || !AV_RL16(&p->buf[8])) |
| 1128 | ✗ | return 0; | |
| 1129 | |||
| 1130 | 15 | return AVPROBE_SCORE_MAX - 1; | |
| 1131 | } | ||
| 1132 | |||
| 1133 | 7496 | static int photocd_probe(const AVProbeData *p) | |
| 1134 | { | ||
| 1135 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7496 times.
|
7496 | if (!memcmp(p->buf, "PCD_OPA", 7)) |
| 1136 | ✗ | return AVPROBE_SCORE_MAX - 1; | |
| 1137 | |||
| 1138 |
3/4✓ Branch 0 taken 3352 times.
✓ Branch 1 taken 4144 times.
✓ Branch 2 taken 3352 times.
✗ Branch 3 not taken.
|
7496 | if (p->buf_size < 0x807 || memcmp(p->buf + 0x800, "PCD_IPI", 7)) |
| 1139 | 7496 | return 0; | |
| 1140 | |||
| 1141 | ✗ | return AVPROBE_SCORE_MAX - 1; | |
| 1142 | } | ||
| 1143 | |||
| 1144 | 7492 | static int qoi_probe(const AVProbeData *p) | |
| 1145 | { | ||
| 1146 |
2/2✓ Branch 0 taken 7491 times.
✓ Branch 1 taken 1 times.
|
7492 | if (memcmp(p->buf, "qoif", 4)) |
| 1147 | 7491 | return 0; | |
| 1148 | |||
| 1149 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
1 | if (AV_RB32(p->buf + 4) == 0 || AV_RB32(p->buf + 8) == 0) |
| 1150 | ✗ | return 0; | |
| 1151 | |||
| 1152 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
1 | if (p->buf[12] != 3 && p->buf[12] != 4) |
| 1153 | ✗ | return 0; | |
| 1154 | |||
| 1155 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (p->buf[13] > 1) |
| 1156 | ✗ | return 0; | |
| 1157 | |||
| 1158 | 1 | return AVPROBE_SCORE_MAX - 1; | |
| 1159 | } | ||
| 1160 | |||
| 1161 | 7508 | static int gem_probe(const AVProbeData *p) | |
| 1162 | { | ||
| 1163 | 7508 | const uint8_t *b = p->buf; | |
| 1164 |
4/4✓ Branch 0 taken 6063 times.
✓ Branch 1 taken 1445 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 6062 times.
|
7508 | if ( AV_RB16(b ) >= 1 && AV_RB16(b ) <= 3 && |
| 1165 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
1 | AV_RB16(b + 2) >= 8 && AV_RB16(b + 2) <= 779 && |
| 1166 | ✗ | (AV_RB16(b + 4) > 0 && AV_RB16(b + 4) <= 32) && /* planes */ | |
| 1167 | ✗ | (AV_RB16(b + 6) > 0 && AV_RB16(b + 6) <= 8) && /* pattern_size */ | |
| 1168 | ✗ | AV_RB16(b + 8) && | |
| 1169 | ✗ | AV_RB16(b + 10) && | |
| 1170 | ✗ | AV_RB16(b + 12) && | |
| 1171 | ✗ | AV_RB16(b + 14)) { | |
| 1172 | ✗ | if (AV_RN32(b + 16) == AV_RN32("STTT") || | |
| 1173 | ✗ | AV_RN32(b + 16) == AV_RN32("TIMG") || | |
| 1174 | ✗ | AV_RN32(b + 16) == AV_RN32("XIMG")) | |
| 1175 | ✗ | return AVPROBE_SCORE_EXTENSION + 1; | |
| 1176 | ✗ | return AVPROBE_SCORE_EXTENSION / 4; | |
| 1177 | } | ||
| 1178 | 7508 | return 0; | |
| 1179 | } | ||
| 1180 | |||
| 1181 | 7491 | static int vbn_probe(const AVProbeData *p) | |
| 1182 | { | ||
| 1183 | 7491 | const uint8_t *b = p->buf; | |
| 1184 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 7487 times.
|
7491 | if (AV_RL32(b ) == VBN_MAGIC && |
| 1185 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | AV_RL32(b + 4) == VBN_MAJOR && |
| 1186 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | AV_RL32(b + 8) == VBN_MINOR) |
| 1187 | 4 | return AVPROBE_SCORE_MAX - 1; | |
| 1188 | 7487 | return 0; | |
| 1189 | } | ||
| 1190 | |||
| 1191 | #define IMAGEAUTO_DEMUXER_0(imgname, codecid) | ||
| 1192 | #define IMAGEAUTO_DEMUXER_1(imgname, codecid)\ | ||
| 1193 | const FFInputFormat ff_image_ ## imgname ## _pipe_demuxer = {\ | ||
| 1194 | .p.name = AV_STRINGIFY(imgname) "_pipe",\ | ||
| 1195 | .p.long_name = NULL_IF_CONFIG_SMALL("piped " AV_STRINGIFY(imgname) " sequence"),\ | ||
| 1196 | .p.priv_class = &imagepipe_class,\ | ||
| 1197 | .p.flags = AVFMT_GENERIC_INDEX,\ | ||
| 1198 | .priv_data_size = sizeof(VideoDemuxData),\ | ||
| 1199 | .read_probe = imgname ## _probe,\ | ||
| 1200 | .read_header = ff_img_read_header,\ | ||
| 1201 | .read_packet = ff_img_read_packet,\ | ||
| 1202 | .raw_codec_id = codecid,\ | ||
| 1203 | }; | ||
| 1204 | |||
| 1205 | #define IMAGEAUTO_DEMUXER_2(imgname, codecid, enabled) \ | ||
| 1206 | IMAGEAUTO_DEMUXER_ ## enabled(imgname, codecid) | ||
| 1207 | #define IMAGEAUTO_DEMUXER_3(imgname, codecid, config) \ | ||
| 1208 | IMAGEAUTO_DEMUXER_2(imgname, codecid, config) | ||
| 1209 | #define IMAGEAUTO_DEMUXER_EXT(imgname, codecid, uppercase_name) \ | ||
| 1210 | IMAGEAUTO_DEMUXER_3(imgname, AV_CODEC_ID_ ## codecid, \ | ||
| 1211 | CONFIG_IMAGE_ ## uppercase_name ## _PIPE_DEMUXER) | ||
| 1212 | #define IMAGEAUTO_DEMUXER(imgname, codecid) \ | ||
| 1213 | IMAGEAUTO_DEMUXER_EXT(imgname, codecid, codecid) | ||
| 1214 | |||
| 1215 | IMAGEAUTO_DEMUXER(bmp, BMP) | ||
| 1216 | IMAGEAUTO_DEMUXER(cri, CRI) | ||
| 1217 | IMAGEAUTO_DEMUXER(dds, DDS) | ||
| 1218 | IMAGEAUTO_DEMUXER(dpx, DPX) | ||
| 1219 | IMAGEAUTO_DEMUXER(exr, EXR) | ||
| 1220 | IMAGEAUTO_DEMUXER(gem, GEM) | ||
| 1221 | IMAGEAUTO_DEMUXER(gif, GIF) | ||
| 1222 | IMAGEAUTO_DEMUXER_EXT(hdr, RADIANCE_HDR, HDR) | ||
| 1223 | IMAGEAUTO_DEMUXER_EXT(j2k, JPEG2000, J2K) | ||
| 1224 | IMAGEAUTO_DEMUXER_EXT(jpeg, MJPEG, JPEG) | ||
| 1225 | IMAGEAUTO_DEMUXER(jpegxs, JPEGXS) | ||
| 1226 | IMAGEAUTO_DEMUXER(jpegls, JPEGLS) | ||
| 1227 | IMAGEAUTO_DEMUXER(jpegxl, JPEGXL) | ||
| 1228 | IMAGEAUTO_DEMUXER(pam, PAM) | ||
| 1229 | IMAGEAUTO_DEMUXER(pbm, PBM) | ||
| 1230 | IMAGEAUTO_DEMUXER(pcx, PCX) | ||
| 1231 | IMAGEAUTO_DEMUXER(pfm, PFM) | ||
| 1232 | IMAGEAUTO_DEMUXER(pgm, PGM) | ||
| 1233 | IMAGEAUTO_DEMUXER(pgmyuv, PGMYUV) | ||
| 1234 | IMAGEAUTO_DEMUXER(pgx, PGX) | ||
| 1235 | IMAGEAUTO_DEMUXER(phm, PHM) | ||
| 1236 | IMAGEAUTO_DEMUXER(photocd, PHOTOCD) | ||
| 1237 | IMAGEAUTO_DEMUXER(pictor, PICTOR) | ||
| 1238 | IMAGEAUTO_DEMUXER(png, PNG) | ||
| 1239 | IMAGEAUTO_DEMUXER(ppm, PPM) | ||
| 1240 | IMAGEAUTO_DEMUXER(psd, PSD) | ||
| 1241 | IMAGEAUTO_DEMUXER(qdraw, QDRAW) | ||
| 1242 | IMAGEAUTO_DEMUXER(qoi, QOI) | ||
| 1243 | IMAGEAUTO_DEMUXER(sgi, SGI) | ||
| 1244 | IMAGEAUTO_DEMUXER(sunrast, SUNRAST) | ||
| 1245 | IMAGEAUTO_DEMUXER(svg, SVG) | ||
| 1246 | IMAGEAUTO_DEMUXER(tiff, TIFF) | ||
| 1247 | IMAGEAUTO_DEMUXER(vbn, VBN) | ||
| 1248 | IMAGEAUTO_DEMUXER(webp, WEBP) | ||
| 1249 | IMAGEAUTO_DEMUXER(xbm, XBM) | ||
| 1250 | IMAGEAUTO_DEMUXER(xpm, XPM) | ||
| 1251 | IMAGEAUTO_DEMUXER(xwd, XWD) | ||
| 1252 |