Browse code

Merge remote-tracking branch 'newdev/master'

* newdev/master:
ac3enc: avoid memcpy() of exponents and baps in EXP_REUSE case by using exponent reference blocks.
Chronomaster DFA decoder
DUPLICATE: framebuffer device demuxer
NOT MERGED: cosmetics: fix dashed line length after 070c5d0
http: header field names are case insensitive

Conflicts:
LICENSE
README
doc/indevs.texi
libavdevice/fbdev.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>

Michael Niedermayer authored on 2011/03/29 09:46:11
Showing 15 changed files
... ...
@@ -78,9 +78,10 @@ version <next>:
78 78
 - movie source added
79 79
 - Bink version 'b' audio and video decoder
80 80
 - Bitmap Brothers JV playback system
81
-- Linux framebuffer input device added
82 81
 - Apple HTTP Live Streaming protocol handler
83 82
 - sndio support for playback and record
83
+- Linux framebuffer input device added
84
+- Chronomaster DFA decoder
84 85
 
85 86
 
86 87
 version 0.6:
... ...
@@ -81,6 +81,8 @@ library:
81 81
     @tab Audio format used in some games by CRYO Interactive Entertainment.
82 82
 @item D-Cinema audio            @tab X @tab X
83 83
 @item Deluxe Paint Animation    @tab   @tab X
84
+@item DFA                       @tab   @tab X
85
+    @tab This format is used in Chronomaster game
84 86
 @item DV video                  @tab X @tab X
85 87
 @item DXA                       @tab   @tab X
86 88
     @tab This format is used in the non-Windows version of the Feeble Files
... ...
@@ -371,6 +373,8 @@ following image formats are supported:
371 371
 @item Cirrus Logic AccuPak   @tab     @tab  X
372 372
     @tab fourcc: CLJR
373 373
 @item Creative YUV (CYUV)    @tab     @tab  X
374
+@item DFA                    @tab     @tab  X
375
+    @tab Codec used in Chronomaster game.
374 376
 @item Dirac                  @tab  E  @tab  E
375 377
     @tab supported through external libdirac/libschroedinger libraries
376 378
 @item Deluxe Paint Animation @tab     @tab  X
... ...
@@ -71,7 +71,7 @@ console. It is accessed through a file device node, usually
71 71
 For more detailed information read the file
72 72
 Documentation/fb/framebuffer.txt included in the Linux source tree.
73 73
 
74
-For example, to record from the framebuffer device @file{/dev/fb0} with
74
+To record from the framebuffer device @file{/dev/fb0} with
75 75
 @file{ffmpeg}:
76 76
 @example
77 77
 ffmpeg -f fbdev -r 10 -i /dev/fb0 out.avi
... ...
@@ -104,6 +104,7 @@ OBJS-$(CONFIG_COOK_DECODER)            += cook.o
104 104
 OBJS-$(CONFIG_CSCD_DECODER)            += cscd.o
105 105
 OBJS-$(CONFIG_CYUV_DECODER)            += cyuv.o
106 106
 OBJS-$(CONFIG_DCA_DECODER)             += dca.o synth_filter.o dcadsp.o
107
+OBJS-$(CONFIG_DFA_DECODER)             += dfa.o
107 108
 OBJS-$(CONFIG_DNXHD_DECODER)           += dnxhddec.o dnxhddata.o
108 109
 OBJS-$(CONFIG_DNXHD_ENCODER)           += dnxhdenc.o dnxhddata.o       \
109 110
                                           mpegvideo_enc.o motion_est.o \
... ...
@@ -112,6 +112,7 @@ typedef struct AC3Block {
112 112
     uint8_t  coeff_shift[AC3_MAX_CHANNELS];     ///< fixed-point coefficient shift values
113 113
     uint8_t  new_rematrixing_strategy;          ///< send new rematrixing flags in this block
114 114
     uint8_t  rematrixing_flags[4];              ///< rematrixing flags
115
+    struct AC3Block *exp_ref_block[AC3_MAX_CHANNELS]; ///< reference blocks for EXP_REUSE
115 116
 } AC3Block;
116 117
 
117 118
 /**
... ...
@@ -692,7 +693,7 @@ static void encode_exponents_blk_ch(uint8_t *exp, int nb_exps, int exp_strategy)
692 692
 static void encode_exponents(AC3EncodeContext *s)
693 693
 {
694 694
     int blk, blk1, ch;
695
-    uint8_t *exp, *exp1, *exp_strategy;
695
+    uint8_t *exp, *exp_strategy;
696 696
     int nb_coefs, num_reuse_blocks;
697 697
 
698 698
     for (ch = 0; ch < s->channels; ch++) {
... ...
@@ -704,9 +705,13 @@ static void encode_exponents(AC3EncodeContext *s)
704 704
         while (blk < AC3_MAX_BLOCKS) {
705 705
             blk1 = blk + 1;
706 706
 
707
-            /* count the number of EXP_REUSE blocks after the current block */
708
-            while (blk1 < AC3_MAX_BLOCKS && exp_strategy[blk1] == EXP_REUSE)
707
+            /* count the number of EXP_REUSE blocks after the current block
708
+               and set exponent reference block pointers */
709
+            s->blocks[blk].exp_ref_block[ch] = &s->blocks[blk];
710
+            while (blk1 < AC3_MAX_BLOCKS && exp_strategy[blk1] == EXP_REUSE) {
711
+                s->blocks[blk1].exp_ref_block[ch] = &s->blocks[blk];
709 712
                 blk1++;
713
+            }
710 714
             num_reuse_blocks = blk1 - blk - 1;
711 715
 
712 716
             /* for the EXP_REUSE case we select the min of the exponents */
... ...
@@ -714,15 +719,8 @@ static void encode_exponents(AC3EncodeContext *s)
714 714
 
715 715
             encode_exponents_blk_ch(exp, nb_coefs, exp_strategy[blk]);
716 716
 
717
-            /* copy encoded exponents for reuse case */
718
-            exp1 = exp + AC3_MAX_COEFS;
719
-            while (blk < blk1-1) {
720
-                memcpy(exp1, exp, nb_coefs * sizeof(*exp));
721
-                exp1 += AC3_MAX_COEFS;
722
-                blk++;
723
-            }
717
+            exp += AC3_MAX_COEFS * (num_reuse_blocks + 1);
724 718
             blk = blk1;
725
-            exp = exp1;
726 719
         }
727 720
     }
728 721
 }
... ...
@@ -1035,7 +1033,7 @@ static int bit_alloc(AC3EncodeContext *s, int snr_offset)
1035 1035
     reset_block_bap(s);
1036 1036
     mantissa_bits = 0;
1037 1037
     for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
1038
-        AC3Block *block = &s->blocks[blk];
1038
+        AC3Block *block;
1039 1039
         // initialize grouped mantissa counts. these are set so that they are
1040 1040
         // padded to the next whole group size when bits are counted in
1041 1041
         // compute_mantissa_size_final
... ...
@@ -1047,9 +1045,8 @@ static int bit_alloc(AC3EncodeContext *s, int snr_offset)
1047 1047
                blocks within a frame are the exponent values.  We can take
1048 1048
                advantage of that by reusing the bit allocation pointers
1049 1049
                whenever we reuse exponents. */
1050
-            if (s->exp_strategy[ch][blk] == EXP_REUSE) {
1051
-                memcpy(block->bap[ch], s->blocks[blk-1].bap[ch], AC3_MAX_COEFS);
1052
-            } else {
1050
+            block = s->blocks[blk].exp_ref_block[ch];
1051
+            if (s->exp_strategy[ch][blk] != EXP_REUSE) {
1053 1052
                 ff_ac3_bit_alloc_calc_bap(block->mask[ch], block->psd[ch], 0,
1054 1053
                                           s->nb_coefs[ch], snr_offset,
1055 1054
                                           s->bit_alloc.floor, ff_ac3_bap_tab,
... ...
@@ -1352,12 +1349,14 @@ static void quantize_mantissas(AC3EncodeContext *s)
1352 1352
 
1353 1353
     for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
1354 1354
         AC3Block *block = &s->blocks[blk];
1355
+        AC3Block *ref_block;
1355 1356
         s->mant1_cnt  = s->mant2_cnt  = s->mant4_cnt  = 0;
1356 1357
         s->qmant1_ptr = s->qmant2_ptr = s->qmant4_ptr = NULL;
1357 1358
 
1358 1359
         for (ch = 0; ch < s->channels; ch++) {
1360
+            ref_block = block->exp_ref_block[ch];
1359 1361
             quantize_mantissas_blk_ch(s, block->fixed_coef[ch],
1360
-                                      block->exp[ch], block->bap[ch],
1362
+                                      ref_block->exp[ch], ref_block->bap[ch],
1361 1363
                                       block->qmant[ch], s->nb_coefs[ch]);
1362 1364
         }
1363 1365
     }
... ...
@@ -1516,9 +1515,10 @@ static void output_audio_block(AC3EncodeContext *s, int blk)
1516 1516
     /* mantissas */
1517 1517
     for (ch = 0; ch < s->channels; ch++) {
1518 1518
         int b, q;
1519
+        AC3Block *ref_block = block->exp_ref_block[ch];
1519 1520
         for (i = 0; i < s->nb_coefs[ch]; i++) {
1520 1521
             q = block->qmant[ch][i];
1521
-            b = block->bap[ch][i];
1522
+            b = ref_block->bap[ch][i];
1522 1523
             switch (b) {
1523 1524
             case 0:                                         break;
1524 1525
             case 1: if (q != 128) put_bits(&s->pb,   5, q); break;
... ...
@@ -88,6 +88,7 @@ void avcodec_register_all(void)
88 88
     REGISTER_DECODER (CLJR, cljr);
89 89
     REGISTER_DECODER (CSCD, cscd);
90 90
     REGISTER_DECODER (CYUV, cyuv);
91
+    REGISTER_DECODER (DFA, dfa);
91 92
     REGISTER_ENCDEC  (DNXHD, dnxhd);
92 93
     REGISTER_DECODER (DPX, dpx);
93 94
     REGISTER_DECODER (DSICINVIDEO, dsicinvideo);
... ...
@@ -212,6 +212,7 @@ enum CodecID {
212 212
     CODEC_ID_LAGARITH,
213 213
     CODEC_ID_PRORES,
214 214
     CODEC_ID_JV,
215
+    CODEC_ID_DFA,
215 216
 
216 217
     /* various PCM "codecs" */
217 218
     CODEC_ID_PCM_S16LE= 0x10000,
218 219
new file mode 100644
... ...
@@ -0,0 +1,395 @@
0
+/*
1
+ * Chronomaster DFA Video Decoder
2
+ * Copyright (c) 2011 Konstantin Shishkov
3
+ * based on work by Vladimir "VAG" Gneushev
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 "avcodec.h"
23
+#include "libavutil/intreadwrite.h"
24
+#include "bytestream.h"
25
+#include "libavutil/lzo.h" // for av_memcpy_backptr
26
+
27
+typedef struct DfaContext {
28
+    AVFrame pic;
29
+
30
+    uint32_t pal[256];
31
+    uint8_t *frame_buf;
32
+} DfaContext;
33
+
34
+static av_cold int dfa_decode_init(AVCodecContext *avctx)
35
+{
36
+    DfaContext *s = avctx->priv_data;
37
+
38
+    avctx->pix_fmt = PIX_FMT_PAL8;
39
+
40
+    s->frame_buf = av_mallocz(avctx->width * avctx->height + AV_LZO_OUTPUT_PADDING);
41
+    if (!s->frame_buf)
42
+        return AVERROR(ENOMEM);
43
+
44
+    return 0;
45
+}
46
+
47
+static int decode_copy(uint8_t *frame, int width, int height,
48
+                       const uint8_t *src, const uint8_t *src_end)
49
+{
50
+    const int size = width * height;
51
+
52
+    if (src_end - src < size)
53
+        return -1;
54
+    bytestream_get_buffer(&src, frame, size);
55
+    return 0;
56
+}
57
+
58
+static int decode_tsw1(uint8_t *frame, int width, int height,
59
+                       const uint8_t *src, const uint8_t *src_end)
60
+{
61
+    const uint8_t *frame_start = frame;
62
+    const uint8_t *frame_end   = frame + width * height;
63
+    int mask = 0x10000, bitbuf = 0;
64
+    int v, offset, count, segments;
65
+
66
+    segments = bytestream_get_le32(&src);
67
+    frame   += bytestream_get_le32(&src);
68
+    if (frame < frame_start || frame > frame_end)
69
+        return -1;
70
+    while (segments--) {
71
+        if (mask == 0x10000) {
72
+            if (src >= src_end)
73
+                return -1;
74
+            bitbuf = bytestream_get_le16(&src);
75
+            mask = 1;
76
+        }
77
+        if (src_end - src < 2 || frame_end - frame < 2)
78
+            return -1;
79
+        if (bitbuf & mask) {
80
+            v = bytestream_get_le16(&src);
81
+            offset = (v & 0x1FFF) << 1;
82
+            count = ((v >> 13) + 2) << 1;
83
+            if (frame - offset < frame_start || frame_end - frame < count)
84
+                return -1;
85
+            av_memcpy_backptr(frame, offset, count);
86
+            frame += count;
87
+        } else {
88
+            *frame++ = *src++;
89
+            *frame++ = *src++;
90
+        }
91
+        mask <<= 1;
92
+    }
93
+
94
+    return 0;
95
+}
96
+
97
+static int decode_dsw1(uint8_t *frame, int width, int height,
98
+                       const uint8_t *src, const uint8_t *src_end)
99
+{
100
+    const uint8_t *frame_start = frame;
101
+    const uint8_t *frame_end   = frame + width * height;
102
+    int mask = 0x10000, bitbuf = 0;
103
+    int v, offset, count, segments;
104
+
105
+    segments = bytestream_get_le16(&src);
106
+    while (segments--) {
107
+        if (mask == 0x10000) {
108
+            if (src >= src_end)
109
+                return -1;
110
+            bitbuf = bytestream_get_le16(&src);
111
+            mask = 1;
112
+        }
113
+        if (src_end - src < 2 || frame_end - frame < 2)
114
+            return -1;
115
+        if (bitbuf & mask) {
116
+            v = bytestream_get_le16(&src);
117
+            offset = (v & 0x1FFF) << 1;
118
+            count = ((v >> 13) + 2) << 1;
119
+            if (frame - offset < frame_start || frame_end - frame < count)
120
+                return -1;
121
+            // can't use av_memcpy_backptr() since it can overwrite following pixels
122
+            for (v = 0; v < count; v++)
123
+                frame[v] = frame[v - offset];
124
+            frame += count;
125
+        } else if (bitbuf & (mask << 1)) {
126
+            frame += bytestream_get_le16(&src);
127
+        } else {
128
+            *frame++ = *src++;
129
+            *frame++ = *src++;
130
+        }
131
+        mask <<= 2;
132
+    }
133
+
134
+    return 0;
135
+}
136
+
137
+static int decode_dds1(uint8_t *frame, int width, int height,
138
+                       const uint8_t *src, const uint8_t *src_end)
139
+{
140
+    const uint8_t *frame_start = frame;
141
+    const uint8_t *frame_end   = frame + width * height;
142
+    int mask = 0x10000, bitbuf = 0;
143
+    int i, v, offset, count, segments;
144
+
145
+    segments = bytestream_get_le16(&src);
146
+    while (segments--) {
147
+        if (mask == 0x10000) {
148
+            if (src >= src_end)
149
+                return -1;
150
+            bitbuf = bytestream_get_le16(&src);
151
+            mask = 1;
152
+        }
153
+        if (src_end - src < 2 || frame_end - frame < 2)
154
+            return -1;
155
+        if (bitbuf & mask) {
156
+            v = bytestream_get_le16(&src);
157
+            offset = (v & 0x1FFF) << 2;
158
+            count = ((v >> 13) + 2) << 1;
159
+            if (frame - offset < frame_start || frame_end - frame < count*2 + width)
160
+                return -1;
161
+            for (i = 0; i < count; i++) {
162
+                frame[0] = frame[1] =
163
+                frame[width] = frame[width + 1] = frame[-offset];
164
+
165
+                frame += 2;
166
+            }
167
+        } else if (bitbuf & (mask << 1)) {
168
+            frame += bytestream_get_le16(&src) * 2;
169
+        } else {
170
+            frame[0] = frame[1] =
171
+            frame[width] = frame[width + 1] =  *src++;
172
+            frame += 2;
173
+            frame[0] = frame[1] =
174
+            frame[width] = frame[width + 1] =  *src++;
175
+            frame += 2;
176
+        }
177
+        mask <<= 2;
178
+    }
179
+
180
+    return 0;
181
+}
182
+
183
+static int decode_bdlt(uint8_t *frame, int width, int height,
184
+                       const uint8_t *src, const uint8_t *src_end)
185
+{
186
+    const uint8_t *frame_end = frame + width * height;
187
+    uint8_t *line_ptr;
188
+    int count, lines, segments;
189
+
190
+    count = bytestream_get_le16(&src);
191
+    if (count >= height || width * count < 0)
192
+        return -1;
193
+    frame += width * count;
194
+    lines = bytestream_get_le16(&src);
195
+    if (frame + lines * width > frame_end || src >= src_end)
196
+        return -1;
197
+
198
+    while (lines--) {
199
+        line_ptr = frame;
200
+        frame += width;
201
+        segments = *src++;
202
+        while (segments--) {
203
+            if (src_end - src < 3)
204
+                return -1;
205
+            line_ptr += *src++;
206
+            if (line_ptr >= frame)
207
+                return -1;
208
+            count = (int8_t)*src++;
209
+            if (count >= 0) {
210
+                if (line_ptr + count > frame || src_end - src < count)
211
+                    return -1;
212
+                bytestream_get_buffer(&src, line_ptr, count);
213
+            } else {
214
+                count = -count;
215
+                if (line_ptr + count > frame || src >= src_end)
216
+                    return -1;
217
+                memset(line_ptr, *src++, count);
218
+            }
219
+            line_ptr += count;
220
+        }
221
+    }
222
+
223
+    return 0;
224
+}
225
+
226
+static int decode_wdlt(uint8_t *frame, int width, int height,
227
+                       const uint8_t *src, const uint8_t *src_end)
228
+{
229
+    const uint8_t *frame_end   = frame + width * height;
230
+    uint8_t *line_ptr;
231
+    int count, i, v, lines, segments;
232
+
233
+    lines = bytestream_get_le16(&src);
234
+    if (frame + lines * width > frame_end || src >= src_end)
235
+        return -1;
236
+
237
+    while (lines--) {
238
+        segments = bytestream_get_le16(&src);
239
+        while ((segments & 0xC000) == 0xC000) {
240
+            frame    -= (int16_t)segments * width;
241
+            if (frame >= frame_end)
242
+                return -1;
243
+            segments = bytestream_get_le16(&src);
244
+        }
245
+        if (segments & 0x8000) {
246
+            frame[width - 1] = segments & 0xFF;
247
+            segments = bytestream_get_le16(&src);
248
+        }
249
+        line_ptr = frame;
250
+        frame += width;
251
+        while (segments--) {
252
+            if (src_end - src < 2)
253
+                return -1;
254
+            line_ptr += *src++;
255
+            if (line_ptr >= frame)
256
+                return -1;
257
+            count = (int8_t)*src++;
258
+            if (count >= 0) {
259
+                if (line_ptr + count*2 > frame || src_end - src < count*2)
260
+                    return -1;
261
+                bytestream_get_buffer(&src, line_ptr, count*2);
262
+                line_ptr += count * 2;
263
+            } else {
264
+                count = -count;
265
+                if (line_ptr + count*2 > frame || src_end - src < 2)
266
+                    return -1;
267
+                v = bytestream_get_le16(&src);
268
+                for (i = 0; i < count; i++)
269
+                    bytestream_put_le16(&line_ptr, v);
270
+            }
271
+        }
272
+    }
273
+
274
+    return 0;
275
+}
276
+
277
+static int decode_unk6(uint8_t *frame, int width, int height,
278
+                       const uint8_t *src, const uint8_t *src_end)
279
+{
280
+    return -1;
281
+}
282
+
283
+static int decode_blck(uint8_t *frame, int width, int height,
284
+                       const uint8_t *src, const uint8_t *src_end)
285
+{
286
+    memset(frame, 0, width * height);
287
+    return 0;
288
+}
289
+
290
+
291
+typedef int (*chunk_decoder)(uint8_t *frame, int width, int height,
292
+                             const uint8_t *src, const uint8_t *src_end);
293
+
294
+static const chunk_decoder decoder[8] = {
295
+    decode_copy, decode_tsw1, decode_bdlt, decode_wdlt,
296
+    decode_unk6, decode_dsw1, decode_blck, decode_dds1,
297
+};
298
+
299
+static const char* chunk_name[8] = {
300
+    "COPY", "TSW1", "BDLT", "WDLT", "????", "DSW1", "BLCK", "DDS1"
301
+};
302
+
303
+static int dfa_decode_frame(AVCodecContext *avctx,
304
+                            void *data, int *data_size,
305
+                            AVPacket *avpkt)
306
+{
307
+    DfaContext *s = avctx->priv_data;
308
+    const uint8_t *buf = avpkt->data;
309
+    const uint8_t *buf_end = avpkt->data + avpkt->size;
310
+    const uint8_t *tmp_buf;
311
+    uint32_t chunk_type, chunk_size;
312
+    uint8_t *dst;
313
+    int ret;
314
+    int i, pal_elems;
315
+
316
+    if (s->pic.data[0])
317
+        avctx->release_buffer(avctx, &s->pic);
318
+
319
+    if ((ret = avctx->get_buffer(avctx, &s->pic))) {
320
+        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
321
+        return ret;
322
+    }
323
+
324
+    while (buf < buf_end) {
325
+        chunk_size = AV_RL32(buf + 4);
326
+        chunk_type = AV_RL32(buf + 8);
327
+        buf += 12;
328
+        if (buf_end - buf < chunk_size) {
329
+            av_log(avctx, AV_LOG_ERROR, "Chunk size is too big (%d bytes)\n", chunk_size);
330
+            return -1;
331
+        }
332
+        if (!chunk_type)
333
+            break;
334
+        if (chunk_type == 1) {
335
+            pal_elems = FFMIN(chunk_size / 3, 256);
336
+            tmp_buf = buf;
337
+            for (i = 0; i < pal_elems; i++) {
338
+                s->pal[i] = bytestream_get_be24(&tmp_buf) << 2;
339
+                s->pal[i] |= (s->pal[i] >> 6) & 0x333;
340
+            }
341
+            s->pic.palette_has_changed = 1;
342
+        } else if (chunk_type <= 9) {
343
+            if (decoder[chunk_type - 2](s->frame_buf, avctx->width, avctx->height,
344
+                                        buf, buf + chunk_size)) {
345
+                av_log(avctx, AV_LOG_ERROR, "Error decoding %s chunk\n",
346
+                       chunk_name[chunk_type - 2]);
347
+                return -1;
348
+            }
349
+        } else {
350
+            av_log(avctx, AV_LOG_WARNING, "Ignoring unknown chunk type %d\n",
351
+                   chunk_type);
352
+        }
353
+        buf += chunk_size;
354
+    }
355
+
356
+    buf = s->frame_buf;
357
+    dst = s->pic.data[0];
358
+    for (i = 0; i < avctx->height; i++) {
359
+        memcpy(dst, buf, avctx->width);
360
+        dst += s->pic.linesize[0];
361
+        buf += avctx->width;
362
+    }
363
+    memcpy(s->pic.data[1], s->pal, sizeof(s->pal));
364
+
365
+    *data_size = sizeof(AVFrame);
366
+    *(AVFrame*)data = s->pic;
367
+
368
+    return avpkt->size;
369
+}
370
+
371
+static av_cold int dfa_decode_end(AVCodecContext *avctx)
372
+{
373
+    DfaContext *s = avctx->priv_data;
374
+
375
+    if (s->pic.data[0])
376
+        avctx->release_buffer(avctx, &s->pic);
377
+
378
+    av_freep(&s->frame_buf);
379
+
380
+    return 0;
381
+}
382
+
383
+AVCodec ff_dfa_decoder = {
384
+    "dfa",
385
+    AVMEDIA_TYPE_VIDEO,
386
+    CODEC_ID_DFA,
387
+    sizeof(DfaContext),
388
+    dfa_decode_init,
389
+    NULL,
390
+    dfa_decode_end,
391
+    dfa_decode_frame,
392
+    CODEC_CAP_DR1,
393
+    .long_name = NULL_IF_CONFIG_SMALL("Chronomaster DFA"),
394
+};
... ...
@@ -22,7 +22,7 @@
22 22
 #include "libavutil/avutil.h"
23 23
 
24 24
 #define LIBAVDEVICE_VERSION_MAJOR 52
25
-#define LIBAVDEVICE_VERSION_MINOR  3
25
+#define LIBAVDEVICE_VERSION_MINOR  4
26 26
 #define LIBAVDEVICE_VERSION_MICRO  0
27 27
 
28 28
 #define LIBAVDEVICE_VERSION_INT AV_VERSION_INT(LIBAVDEVICE_VERSION_MAJOR, \
... ...
@@ -57,8 +57,7 @@ static struct rgb_pixfmt_map_entry rgb_pixfmt_map[] = {
57 57
     {  24,      16,           8,           0,            0,   PIX_FMT_BGR24 },
58 58
 };
59 59
 
60
-static enum PixelFormat
61
-get_pixfmt_from_fb_varinfo(struct fb_var_screeninfo *varinfo)
60
+static enum PixelFormat get_pixfmt_from_fb_varinfo(struct fb_var_screeninfo *varinfo)
62 61
 {
63 62
     int i;
64 63
 
... ...
@@ -55,6 +55,7 @@ OBJS-$(CONFIG_CDG_DEMUXER)               += cdg.o
55 55
 OBJS-$(CONFIG_CRC_MUXER)                 += crcenc.o
56 56
 OBJS-$(CONFIG_DAUD_DEMUXER)              += daud.o
57 57
 OBJS-$(CONFIG_DAUD_MUXER)                += daud.o
58
+OBJS-$(CONFIG_DFA_DEMUXER)               += dfa.o
58 59
 OBJS-$(CONFIG_DIRAC_DEMUXER)             += diracdec.o rawdec.o
59 60
 OBJS-$(CONFIG_DIRAC_MUXER)               += rawenc.o
60 61
 OBJS-$(CONFIG_DNXHD_DEMUXER)             += dnxhddec.o rawdec.o
... ...
@@ -75,6 +75,7 @@ void av_register_all(void)
75 75
     REGISTER_DEMUXER  (CDG, cdg);
76 76
     REGISTER_MUXER    (CRC, crc);
77 77
     REGISTER_MUXDEMUX (DAUD, daud);
78
+    REGISTER_DEMUXER  (DFA, dfa);
78 79
     REGISTER_MUXDEMUX (DIRAC, dirac);
79 80
     REGISTER_MUXDEMUX (DNXHD, dnxhd);
80 81
     REGISTER_DEMUXER  (DSICIN, dsicin);
81 82
new file mode 100644
... ...
@@ -0,0 +1,119 @@
0
+/*
1
+ * Chronomaster DFA Format Demuxer
2
+ * Copyright (c) 2011 Konstantin Shishkov
3
+ *
4
+ * This file is part of FFmpeg.
5
+ *
6
+ * FFmpeg is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Lesser General Public
8
+ * License as published by the Free Software Foundation; either
9
+ * version 2.1 of the License, or (at your option) any later version.
10
+ *
11
+ * FFmpeg is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with FFmpeg; if not, write to the Free Software
18
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
+ */
20
+
21
+#include "libavutil/intreadwrite.h"
22
+#include "avformat.h"
23
+
24
+static int dfa_probe(AVProbeData *p)
25
+{
26
+    if (p->buf_size < 4 || AV_RL32(p->buf) != MKTAG('D', 'F', 'I', 'A'))
27
+        return 0;
28
+
29
+    return AVPROBE_SCORE_MAX;
30
+}
31
+
32
+static int dfa_read_header(AVFormatContext *s,
33
+                           AVFormatParameters *ap)
34
+{
35
+    AVIOContext *pb = s->pb;
36
+    AVStream *st;
37
+    int frames;
38
+    uint32_t mspf;
39
+
40
+    if (avio_rl32(pb) != MKTAG('D', 'F', 'I', 'A')) {
41
+        av_log(s, AV_LOG_ERROR, "Invalid magic for DFA\n");
42
+        return AVERROR_INVALIDDATA;
43
+    }
44
+    avio_skip(pb, 2); // unused
45
+    frames = avio_rl16(pb);
46
+
47
+    st = av_new_stream(s, 0);
48
+    if (!st)
49
+        return AVERROR(ENOMEM);
50
+
51
+    st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
52
+    st->codec->codec_id   = CODEC_ID_DFA;
53
+    st->codec->width      = avio_rl16(pb);
54
+    st->codec->height     = avio_rl16(pb);
55
+    mspf = avio_rl32(pb);
56
+    if (!mspf) {
57
+        av_log(s, AV_LOG_WARNING, "Zero FPS reported, defaulting to 10\n");
58
+        mspf = 100;
59
+    }
60
+    av_set_pts_info(st, 24, mspf, 1000);
61
+    avio_skip(pb, 128 - 16); // padding
62
+    st->duration = frames;
63
+
64
+    return 0;
65
+}
66
+
67
+static int dfa_read_packet(AVFormatContext *s, AVPacket *pkt)
68
+{
69
+    AVIOContext *pb = s->pb;
70
+    uint32_t frame_size;
71
+    int ret, first = 1;
72
+
73
+    if (pb->eof_reached)
74
+        return AVERROR_EOF;
75
+
76
+    if (av_get_packet(pb, pkt, 12) != 12)
77
+        return AVERROR(EIO);
78
+    while (!pb->eof_reached) {
79
+        if (!first) {
80
+            ret = av_append_packet(pb, pkt, 12);
81
+            if (ret < 0) {
82
+                av_free_packet(pkt);
83
+                return ret;
84
+            }
85
+        } else
86
+            first = 0;
87
+        frame_size = AV_RL32(pkt->data + pkt->size - 8);
88
+        if (frame_size > INT_MAX - 4) {
89
+            av_log(s, AV_LOG_ERROR, "Too large chunk size: %d\n", frame_size);
90
+            return AVERROR(EIO);
91
+        }
92
+        if (AV_RL32(pkt->data + pkt->size - 12) == MKTAG('E', 'O', 'F', 'R')) {
93
+            if (frame_size) {
94
+                av_log(s, AV_LOG_WARNING, "skipping %d bytes of end-of-frame marker chunk\n",
95
+                       frame_size);
96
+                avio_skip(pb, frame_size);
97
+            }
98
+            return 0;
99
+        }
100
+        ret = av_append_packet(pb, pkt, frame_size);
101
+        if (ret < 0) {
102
+            av_free_packet(pkt);
103
+            return ret;
104
+        }
105
+    }
106
+
107
+    return 0;
108
+}
109
+
110
+AVInputFormat ff_dfa_demuxer = {
111
+    "dfa",
112
+    NULL_IF_CONFIG_SMALL("Chronomaster DFA"),
113
+    0,
114
+    dfa_probe,
115
+    dfa_read_header,
116
+    dfa_read_packet,
117
+    .flags = AVFMT_GENERIC_INDEX,
118
+};
... ...
@@ -246,12 +246,12 @@ static int process_line(URLContext *h, char *line, int line_count,
246 246
         p++;
247 247
         while (isspace(*p))
248 248
             p++;
249
-        if (!strcmp(tag, "Location")) {
249
+        if (!strcasecmp(tag, "Location")) {
250 250
             strcpy(s->location, p);
251 251
             *new_location = 1;
252
-        } else if (!strcmp (tag, "Content-Length") && s->filesize == -1) {
252
+        } else if (!strcasecmp (tag, "Content-Length") && s->filesize == -1) {
253 253
             s->filesize = atoll(p);
254
-        } else if (!strcmp (tag, "Content-Range")) {
254
+        } else if (!strcasecmp (tag, "Content-Range")) {
255 255
             /* "bytes $from-$to/$document_size" */
256 256
             const char *slash;
257 257
             if (!strncmp (p, "bytes ", 6)) {
... ...
@@ -261,14 +261,14 @@ static int process_line(URLContext *h, char *line, int line_count,
261 261
                     s->filesize = atoll(slash+1);
262 262
             }
263 263
             h->is_streamed = 0; /* we _can_ in fact seek */
264
-        } else if (!strcmp (tag, "Transfer-Encoding") && !strncasecmp(p, "chunked", 7)) {
264
+        } else if (!strcasecmp (tag, "Transfer-Encoding") && !strncasecmp(p, "chunked", 7)) {
265 265
             s->filesize = -1;
266 266
             s->chunksize = 0;
267
-        } else if (!strcmp (tag, "WWW-Authenticate")) {
267
+        } else if (!strcasecmp (tag, "WWW-Authenticate")) {
268 268
             ff_http_auth_handle_header(&s->auth_state, tag, p);
269
-        } else if (!strcmp (tag, "Authentication-Info")) {
269
+        } else if (!strcasecmp (tag, "Authentication-Info")) {
270 270
             ff_http_auth_handle_header(&s->auth_state, tag, p);
271
-        } else if (!strcmp (tag, "Connection")) {
271
+        } else if (!strcasecmp (tag, "Connection")) {
272 272
             if (!strcmp(p, "close"))
273 273
                 s->willclose = 1;
274 274
         }
... ...
@@ -24,7 +24,7 @@
24 24
 #include "libavutil/avutil.h"
25 25
 
26 26
 #define LIBAVFORMAT_VERSION_MAJOR 52
27
-#define LIBAVFORMAT_VERSION_MINOR 103
27
+#define LIBAVFORMAT_VERSION_MINOR 104
28 28
 #define LIBAVFORMAT_VERSION_MICRO  0
29 29
 
30 30
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \