/src/ffmpeg/libavformat/vc1dec.c
Line | Count | Source |
1 | | /* |
2 | | * VC-1 demuxer |
3 | | * Copyright (c) 2015 Carl Eugen Hoyos |
4 | | * |
5 | | * This file is part of FFmpeg. |
6 | | * |
7 | | * FFmpeg is free software; you can redistribute it and/or |
8 | | * modify it under the terms of the GNU Lesser General Public |
9 | | * License as published by the Free Software Foundation; either |
10 | | * version 2.1 of the License, or (at your option) any later version. |
11 | | * |
12 | | * FFmpeg is distributed in the hope that it will be useful, |
13 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | | * Lesser General Public License for more details. |
16 | | * |
17 | | * You should have received a copy of the GNU Lesser General Public |
18 | | * License along with FFmpeg; if not, write to the Free Software |
19 | | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
20 | | */ |
21 | | |
22 | | #include "avformat.h" |
23 | | #include "rawdec.h" |
24 | | #include "libavutil/intreadwrite.h" |
25 | | #include "libavcodec/vc1_common.h" |
26 | | |
27 | | static int vc1_probe(const AVProbeData *p) |
28 | 936k | { |
29 | 936k | int seq = 0, entry = 0, invalid = 0, frame = 0, i; |
30 | | |
31 | 3.36G | for (i = 0; i < p->buf_size + 5; i++) { |
32 | 3.36G | uint32_t code = AV_RB32(p->buf + i); |
33 | 3.36G | if ((code & 0xffffffe0) == 0x100) { |
34 | 13.2M | int type = code & 0x11f; |
35 | 13.2M | i += 4; |
36 | 13.2M | switch (type) { |
37 | 889k | case VC1_CODE_SEQHDR: { |
38 | 889k | int profile, level, chromaformat; |
39 | 889k | profile = (p->buf[i] & 0xc0) >> 6; |
40 | 889k | if (profile != PROFILE_ADVANCED) { |
41 | 310k | seq = 0; |
42 | 310k | invalid++; |
43 | 310k | continue; |
44 | 310k | } |
45 | 579k | level = (p->buf[i] & 0x38) >> 3; |
46 | 579k | if (level >= 5) { |
47 | 33.9k | seq = 0; |
48 | 33.9k | invalid++; |
49 | 33.9k | continue; |
50 | 33.9k | } |
51 | 545k | chromaformat = (p->buf[i] & 0x6) >> 1; |
52 | 545k | if (chromaformat != 1) { |
53 | 367k | seq = 0; |
54 | 367k | invalid++; |
55 | 367k | continue; |
56 | 367k | } |
57 | 177k | seq++; |
58 | 177k | i += 6; |
59 | 177k | break; |
60 | 545k | } |
61 | 124k | case VC1_CODE_ENTRYPOINT: |
62 | 124k | if (!seq) { |
63 | 62.9k | invalid++; |
64 | 62.9k | continue; |
65 | 62.9k | } |
66 | 61.0k | entry++; |
67 | 61.0k | i += 2; |
68 | 61.0k | break; |
69 | 212k | case VC1_CODE_FRAME: |
70 | 275k | case VC1_CODE_FIELD: |
71 | 397k | case VC1_CODE_SLICE: |
72 | 397k | if (seq && entry) |
73 | 84.1k | frame++; |
74 | 397k | break; |
75 | 13.2M | } |
76 | 13.2M | } |
77 | 3.36G | } |
78 | | |
79 | 936k | if (frame > 1 && frame >> 1 > invalid) |
80 | 1.38k | return AVPROBE_SCORE_EXTENSION / 2 + 1; |
81 | 935k | if (frame >= 1) |
82 | 3.98k | return AVPROBE_SCORE_EXTENSION / 4; |
83 | 931k | return 0; |
84 | 935k | } |
85 | | |
86 | | FF_DEF_RAWVIDEO_DEMUXER2(vc1, "raw VC-1", vc1_probe, "vc1", AV_CODEC_ID_VC1, AVFMT_GENERIC_INDEX|AVFMT_NOTIMESTAMPS) |