Browse code

cdxl: add read_probe function

Signed-off-by: Paul B Mahol <onemda@gmail.com>

Paul B Mahol authored on 2012/11/05 01:16:01
Showing 1 changed files
... ...
@@ -38,6 +38,48 @@ typedef struct CDXLDemuxContext {
38 38
     int         audio_stream_index;
39 39
 } CDXLDemuxContext;
40 40
 
41
+static int cdxl_read_probe(AVProbeData *p)
42
+{
43
+    int score = AVPROBE_SCORE_MAX / 2 + 10;
44
+
45
+    if (p->buf_size < CDXL_HEADER_SIZE)
46
+        return 0;
47
+
48
+    /* reserved bytes should always be set to 0 */
49
+    if (AV_RN64(&p->buf[24]) || AV_RN16(&p->buf[10]))
50
+        return 0;
51
+
52
+    /* check type */
53
+    if (p->buf[0] != 1)
54
+        return 0;
55
+
56
+    /* check palette size */
57
+    if (AV_RB16(&p->buf[20]) > 512)
58
+        return 0;
59
+
60
+    /* check number of planes */
61
+    if (p->buf[18] || !p->buf[19])
62
+        return 0;
63
+
64
+    /* check widh and height */
65
+    if (!AV_RN16(&p->buf[14]) || !AV_RN16(&p->buf[16]))
66
+        return 0;
67
+
68
+    /* chunk size */
69
+    if (AV_RB32(&p->buf[2]) < AV_RB16(&p->buf[22]) + AV_RB16(&p->buf[20]) + CDXL_HEADER_SIZE)
70
+        return 0;
71
+
72
+    /* previous chunk size */
73
+    if (AV_RN32(&p->buf[6]))
74
+        score /= 2;
75
+
76
+    /* current frame number, usually starts from 1 */
77
+    if (AV_RB16(&p->buf[12]) != 1)
78
+        score /= 2;
79
+
80
+    return score;
81
+}
82
+
41 83
 static int cdxl_read_header(AVFormatContext *s)
42 84
 {
43 85
     CDXLDemuxContext *cdxl = s->priv_data;
... ...
@@ -173,6 +215,7 @@ AVInputFormat ff_cdxl_demuxer = {
173 173
     .name           = "cdxl",
174 174
     .long_name      = NULL_IF_CONFIG_SMALL("Commodore CDXL video"),
175 175
     .priv_data_size = sizeof(CDXLDemuxContext),
176
+    .read_probe     = cdxl_read_probe,
176 177
     .read_header    = cdxl_read_header,
177 178
     .read_packet    = cdxl_read_packet,
178 179
     .extensions     = "cdxl,xl",