summaryrefslogtreecommitdiff
path: root/libavformat/vc1dec.c (plain)
blob: 33f84652ebe8cc6e043af5dd0163ca95fff0a089
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
27static int vc1_probe(AVProbeData *p)
28{
29 int seq = 0, entry = 0, frame = 0, i;
30
31 for (i = 0; i < p->buf_size + 5; i++) {
32 uint32_t code = AV_RB32(p->buf + i);
33 if ((code & 0xffffffe0) == 0x100) {
34 int type = code & 0x11f;
35 i += 4;
36 switch (type) {
37 case VC1_CODE_SEQHDR: {
38 int profile, level, chromaformat;
39 profile = (p->buf[i] & 0xc0) >> 6;
40 if (profile != PROFILE_ADVANCED) {
41 seq = 0;
42 continue;
43 }
44 level = (p->buf[i] & 0x38) >> 3;
45 if (level >= 5) {
46 seq = 0;
47 continue;
48 }
49 chromaformat = (p->buf[i] & 0x6) >> 1;
50 if (chromaformat != 1) {
51 seq = 0;
52 continue;
53 }
54 seq++;
55 i += 6;
56 break;
57 }
58 case VC1_CODE_ENTRYPOINT:
59 if (!seq)
60 continue;
61 entry++;
62 i += 2;
63 break;
64 case VC1_CODE_FRAME:
65 case VC1_CODE_FIELD:
66 case VC1_CODE_SLICE:
67 if (seq && entry)
68 frame++;
69 break;
70 }
71 }
72 }
73
74 if (frame > 1)
75 return AVPROBE_SCORE_EXTENSION / 2 + 1;
76 if (frame == 1)
77 return AVPROBE_SCORE_EXTENSION / 4;
78 return 0;
79}
80
81FF_DEF_RAWVIDEO_DEMUXER2(vc1, "raw VC-1", vc1_probe, "vc1", AV_CODEC_ID_VC1, AVFMT_GENERIC_INDEX|AVFMT_NOTIMESTAMPS)
82