Revision 42315dab

View differences:

Changelog
81 81
- Apple HTTP Live Streaming protocol handler
82 82
- sndio support for playback and record
83 83
- Linux framebuffer input device added
84
- Chronomaster DFA decoder
84 85

  
85 86

  
86 87
version 0.6:
doc/general.texi
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 373
@item Cirrus Logic AccuPak   @tab     @tab  X
372 374
    @tab fourcc: CLJR
373 375
@item Creative YUV (CYUV)    @tab     @tab  X
376
@item DFA                    @tab     @tab  X
377
    @tab Codec used in Chronomaster game.
374 378
@item Dirac                  @tab  E  @tab  E
375 379
    @tab supported through external libdirac/libschroedinger libraries
376 380
@item Deluxe Paint Animation @tab     @tab  X
libavcodec/Makefile
103 103
OBJS-$(CONFIG_CSCD_DECODER)            += cscd.o
104 104
OBJS-$(CONFIG_CYUV_DECODER)            += cyuv.o
105 105
OBJS-$(CONFIG_DCA_DECODER)             += dca.o synth_filter.o dcadsp.o
106
OBJS-$(CONFIG_DFA_DECODER)             += dfa.o
106 107
OBJS-$(CONFIG_DNXHD_DECODER)           += dnxhddec.o dnxhddata.o
107 108
OBJS-$(CONFIG_DNXHD_ENCODER)           += dnxhdenc.o dnxhddata.o       \
108 109
                                          mpegvideo_enc.o motion_est.o \
libavcodec/allcodecs.c
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);
libavcodec/avcodec.h
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,
libavcodec/dfa.c
1
/*
2
 * Chronomaster DFA Video Decoder
3
 * Copyright (c) 2011 Konstantin Shishkov
4
 * based on work by Vladimir "VAG" Gneushev
5
 *
6
 * This file is part of Libav.
7
 *
8
 * Libav 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
 * Libav 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 Libav; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
 */
22

  
23
#include "avcodec.h"
24
#include "libavutil/intreadwrite.h"
25
#include "bytestream.h"
26
#include "libavutil/lzo.h" // for av_memcpy_backptr
27

  
28
typedef struct DfaContext {
29
    AVFrame pic;
30

  
31
    uint32_t pal[256];
32
    uint8_t *frame_buf;
33
} DfaContext;
34

  
35
static av_cold int dfa_decode_init(AVCodecContext *avctx)
36
{
37
    DfaContext *s = avctx->priv_data;
38

  
39
    avctx->pix_fmt = PIX_FMT_PAL8;
40

  
41
    s->frame_buf = av_mallocz(avctx->width * avctx->height + AV_LZO_OUTPUT_PADDING);
42
    if (!s->frame_buf)
43
        return AVERROR(ENOMEM);
44

  
45
    return 0;
46
}
47

  
48
static int decode_copy(uint8_t *frame, int width, int height,
49
                       const uint8_t *src, const uint8_t *src_end)
50
{
51
    const int size = width * height;
52

  
53
    if (src_end - src < size)
54
        return -1;
55
    bytestream_get_buffer(&src, frame, size);
56
    return 0;
57
}
58

  
59
static int decode_tsw1(uint8_t *frame, int width, int height,
60
                       const uint8_t *src, const uint8_t *src_end)
61
{
62
    const uint8_t *frame_start = frame;
63
    const uint8_t *frame_end   = frame + width * height;
64
    int mask = 0x10000, bitbuf = 0;
65
    int v, offset, count, segments;
66

  
67
    segments = bytestream_get_le32(&src);
68
    frame   += bytestream_get_le32(&src);
69
    if (frame < frame_start || frame > frame_end)
70
        return -1;
71
    while (segments--) {
72
        if (mask == 0x10000) {
73
            if (src >= src_end)
74
                return -1;
75
            bitbuf = bytestream_get_le16(&src);
76
            mask = 1;
77
        }
78
        if (src_end - src < 2 || frame_end - frame < 2)
79
            return -1;
80
        if (bitbuf & mask) {
81
            v = bytestream_get_le16(&src);
82
            offset = (v & 0x1FFF) << 1;
83
            count = ((v >> 13) + 2) << 1;
84
            if (frame - offset < frame_start || frame_end - frame < count)
85
                return -1;
86
            av_memcpy_backptr(frame, offset, count);
87
            frame += count;
88
        } else {
89
            *frame++ = *src++;
90
            *frame++ = *src++;
91
        }
92
        mask <<= 1;
93
    }
94

  
95
    return 0;
96
}
97

  
98
static int decode_dsw1(uint8_t *frame, int width, int height,
99
                       const uint8_t *src, const uint8_t *src_end)
100
{
101
    const uint8_t *frame_start = frame;
102
    const uint8_t *frame_end   = frame + width * height;
103
    int mask = 0x10000, bitbuf = 0;
104
    int v, offset, count, segments;
105

  
106
    segments = bytestream_get_le16(&src);
107
    while (segments--) {
108
        if (mask == 0x10000) {
109
            if (src >= src_end)
110
                return -1;
111
            bitbuf = bytestream_get_le16(&src);
112
            mask = 1;
113
        }
114
        if (src_end - src < 2 || frame_end - frame < 2)
115
            return -1;
116
        if (bitbuf & mask) {
117
            v = bytestream_get_le16(&src);
118
            offset = (v & 0x1FFF) << 1;
119
            count = ((v >> 13) + 2) << 1;
120
            if (frame - offset < frame_start || frame_end - frame < count)
121
                return -1;
122
            // can't use av_memcpy_backptr() since it can overwrite following pixels
123
            for (v = 0; v < count; v++)
124
                frame[v] = frame[v - offset];
125
            frame += count;
126
        } else if (bitbuf & (mask << 1)) {
127
            frame += bytestream_get_le16(&src);
128
        } else {
129
            *frame++ = *src++;
130
            *frame++ = *src++;
131
        }
132
        mask <<= 2;
133
    }
134

  
135
    return 0;
136
}
137

  
138
static int decode_dds1(uint8_t *frame, int width, int height,
139
                       const uint8_t *src, const uint8_t *src_end)
140
{
141
    const uint8_t *frame_start = frame;
142
    const uint8_t *frame_end   = frame + width * height;
143
    int mask = 0x10000, bitbuf = 0;
144
    int i, v, offset, count, segments;
145

  
146
    segments = bytestream_get_le16(&src);
147
    while (segments--) {
148
        if (mask == 0x10000) {
149
            if (src >= src_end)
150
                return -1;
151
            bitbuf = bytestream_get_le16(&src);
152
            mask = 1;
153
        }
154
        if (src_end - src < 2 || frame_end - frame < 2)
155
            return -1;
156
        if (bitbuf & mask) {
157
            v = bytestream_get_le16(&src);
158
            offset = (v & 0x1FFF) << 2;
159
            count = ((v >> 13) + 2) << 1;
160
            if (frame - offset < frame_start || frame_end - frame < count*2 + width)
161
                return -1;
162
            for (i = 0; i < count; i++) {
163
                frame[0] = frame[1] =
164
                frame[width] = frame[width + 1] = frame[-offset];
165

  
166
                frame += 2;
167
            }
168
        } else if (bitbuf & (mask << 1)) {
169
            frame += bytestream_get_le16(&src) * 2;
170
        } else {
171
            frame[0] = frame[1] =
172
            frame[width] = frame[width + 1] =  *src++;
173
            frame += 2;
174
            frame[0] = frame[1] =
175
            frame[width] = frame[width + 1] =  *src++;
176
            frame += 2;
177
        }
178
        mask <<= 2;
179
    }
180

  
181
    return 0;
182
}
183

  
184
static int decode_bdlt(uint8_t *frame, int width, int height,
185
                       const uint8_t *src, const uint8_t *src_end)
186
{
187
    const uint8_t *frame_end = frame + width * height;
188
    uint8_t *line_ptr;
189
    int count, lines, segments;
190

  
191
    count = bytestream_get_le16(&src);
192
    if (count >= height || width * count < 0)
193
        return -1;
194
    frame += width * count;
195
    lines = bytestream_get_le16(&src);
196
    if (frame + lines * width > frame_end || src >= src_end)
197
        return -1;
198

  
199
    while (lines--) {
200
        line_ptr = frame;
201
        frame += width;
202
        segments = *src++;
203
        while (segments--) {
204
            if (src_end - src < 3)
205
                return -1;
206
            line_ptr += *src++;
207
            if (line_ptr >= frame)
208
                return -1;
209
            count = (int8_t)*src++;
210
            if (count >= 0) {
211
                if (line_ptr + count > frame || src_end - src < count)
212
                    return -1;
213
                bytestream_get_buffer(&src, line_ptr, count);
214
            } else {
215
                count = -count;
216
                if (line_ptr + count > frame || src >= src_end)
217
                    return -1;
218
                memset(line_ptr, *src++, count);
219
            }
220
            line_ptr += count;
221
        }
222
    }
223

  
224
    return 0;
225
}
226

  
227
static int decode_wdlt(uint8_t *frame, int width, int height,
228
                       const uint8_t *src, const uint8_t *src_end)
229
{
230
    const uint8_t *frame_end   = frame + width * height;
231
    uint8_t *line_ptr;
232
    int count, i, v, lines, segments;
233

  
234
    lines = bytestream_get_le16(&src);
235
    if (frame + lines * width > frame_end || src >= src_end)
236
        return -1;
237

  
238
    while (lines--) {
239
        segments = bytestream_get_le16(&src);
240
        while ((segments & 0xC000) == 0xC000) {
241
            frame    -= (int16_t)segments * width;
242
            if (frame >= frame_end)
243
                return -1;
244
            segments = bytestream_get_le16(&src);
245
        }
246
        if (segments & 0x8000) {
247
            frame[width - 1] = segments & 0xFF;
248
            segments = bytestream_get_le16(&src);
249
        }
250
        line_ptr = frame;
251
        frame += width;
252
        while (segments--) {
253
            if (src_end - src < 2)
254
                return -1;
255
            line_ptr += *src++;
256
            if (line_ptr >= frame)
257
                return -1;
258
            count = (int8_t)*src++;
259
            if (count >= 0) {
260
                if (line_ptr + count*2 > frame || src_end - src < count*2)
261
                    return -1;
262
                bytestream_get_buffer(&src, line_ptr, count*2);
263
                line_ptr += count * 2;
264
            } else {
265
                count = -count;
266
                if (line_ptr + count*2 > frame || src_end - src < 2)
267
                    return -1;
268
                v = bytestream_get_le16(&src);
269
                for (i = 0; i < count; i++)
270
                    bytestream_put_le16(&line_ptr, v);
271
            }
272
        }
273
    }
274

  
275
    return 0;
276
}
277

  
278
static int decode_unk6(uint8_t *frame, int width, int height,
279
                       const uint8_t *src, const uint8_t *src_end)
280
{
281
    return -1;
282
}
283

  
284
static int decode_blck(uint8_t *frame, int width, int height,
285
                       const uint8_t *src, const uint8_t *src_end)
286
{
287
    memset(frame, 0, width * height);
288
    return 0;
289
}
290

  
291

  
292
typedef int (*chunk_decoder)(uint8_t *frame, int width, int height,
293
                             const uint8_t *src, const uint8_t *src_end);
294

  
295
static const chunk_decoder decoder[8] = {
296
    decode_copy, decode_tsw1, decode_bdlt, decode_wdlt,
297
    decode_unk6, decode_dsw1, decode_blck, decode_dds1,
298
};
299

  
300
static const char* chunk_name[8] = {
301
    "COPY", "TSW1", "BDLT", "WDLT", "????", "DSW1", "BLCK", "DDS1"
302
};
303

  
304
static int dfa_decode_frame(AVCodecContext *avctx,
305
                            void *data, int *data_size,
306
                            AVPacket *avpkt)
307
{
308
    DfaContext *s = avctx->priv_data;
309
    const uint8_t *buf = avpkt->data;
310
    const uint8_t *buf_end = avpkt->data + avpkt->size;
311
    const uint8_t *tmp_buf;
312
    uint32_t chunk_type, chunk_size;
313
    uint8_t *dst;
314
    int ret;
315
    int i, pal_elems;
316

  
317
    if (s->pic.data[0])
318
        avctx->release_buffer(avctx, &s->pic);
319

  
320
    if ((ret = avctx->get_buffer(avctx, &s->pic))) {
321
        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
322
        return ret;
323
    }
324

  
325
    while (buf < buf_end) {
326
        chunk_size = AV_RL32(buf + 4);
327
        chunk_type = AV_RL32(buf + 8);
328
        buf += 12;
329
        if (buf_end - buf < chunk_size) {
330
            av_log(avctx, AV_LOG_ERROR, "Chunk size is too big (%d bytes)\n", chunk_size);
331
            return -1;
332
        }
333
        if (!chunk_type)
334
            break;
335
        if (chunk_type == 1) {
336
            pal_elems = FFMIN(chunk_size / 3, 256);
337
            tmp_buf = buf;
338
            for (i = 0; i < pal_elems; i++) {
339
                s->pal[i] = bytestream_get_be24(&tmp_buf) << 2;
340
                s->pal[i] |= (s->pal[i] >> 6) & 0x333;
341
            }
342
            s->pic.palette_has_changed = 1;
343
        } else if (chunk_type <= 9) {
344
            if (decoder[chunk_type - 2](s->frame_buf, avctx->width, avctx->height,
345
                                        buf, buf + chunk_size)) {
346
                av_log(avctx, AV_LOG_ERROR, "Error decoding %s chunk\n",
347
                       chunk_name[chunk_type - 2]);
348
                return -1;
349
            }
350
        } else {
351
            av_log(avctx, AV_LOG_WARNING, "Ignoring unknown chunk type %d\n",
352
                   chunk_type);
353
        }
354
        buf += chunk_size;
355
    }
356

  
357
    buf = s->frame_buf;
358
    dst = s->pic.data[0];
359
    for (i = 0; i < avctx->height; i++) {
360
        memcpy(dst, buf, avctx->width);
361
        dst += s->pic.linesize[0];
362
        buf += avctx->width;
363
    }
364
    memcpy(s->pic.data[1], s->pal, sizeof(s->pal));
365

  
366
    *data_size = sizeof(AVFrame);
367
    *(AVFrame*)data = s->pic;
368

  
369
    return avpkt->size;
370
}
371

  
372
static av_cold int dfa_decode_end(AVCodecContext *avctx)
373
{
374
    DfaContext *s = avctx->priv_data;
375

  
376
    if (s->pic.data[0])
377
        avctx->release_buffer(avctx, &s->pic);
378

  
379
    av_freep(&s->frame_buf);
380

  
381
    return 0;
382
}
383

  
384
AVCodec ff_dfa_decoder = {
385
    "dfa",
386
    AVMEDIA_TYPE_VIDEO,
387
    CODEC_ID_DFA,
388
    sizeof(DfaContext),
389
    dfa_decode_init,
390
    NULL,
391
    dfa_decode_end,
392
    dfa_decode_frame,
393
    CODEC_CAP_DR1,
394
    .long_name = NULL_IF_CONFIG_SMALL("Chronomaster DFA"),
395
};
libavcodec/version.h
21 21
#define AVCODEC_VERSION_H
22 22

  
23 23
#define LIBAVCODEC_VERSION_MAJOR 52
24
#define LIBAVCODEC_VERSION_MINOR 115
24
#define LIBAVCODEC_VERSION_MINOR 116
25 25
#define LIBAVCODEC_VERSION_MICRO  0
26 26

  
27 27
#define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
libavformat/Makefile
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
libavformat/allformats.c
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);
libavformat/dfa.c
1
/*
2
 * Chronomaster DFA Format Demuxer
3
 * Copyright (c) 2011 Konstantin Shishkov
4
 *
5
 * This file is part of Libav.
6
 *
7
 * Libav 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
 * Libav 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 Libav; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
 */
21

  
22
#include "libavutil/intreadwrite.h"
23
#include "avformat.h"
24

  
25
static int dfa_probe(AVProbeData *p)
26
{
27
    if (p->buf_size < 4 || AV_RL32(p->buf) != MKTAG('D', 'F', 'I', 'A'))
28
        return 0;
29

  
30
    return AVPROBE_SCORE_MAX;
31
}
32

  
33
static int dfa_read_header(AVFormatContext *s,
34
                           AVFormatParameters *ap)
35
{
36
    AVIOContext *pb = s->pb;
37
    AVStream *st;
38
    int frames;
39
    uint32_t mspf;
40

  
41
    if (avio_rl32(pb) != MKTAG('D', 'F', 'I', 'A')) {
42
        av_log(s, AV_LOG_ERROR, "Invalid magic for DFA\n");
43
        return AVERROR_INVALIDDATA;
44
    }
45
    avio_skip(pb, 2); // unused
46
    frames = avio_rl16(pb);
47

  
48
    st = av_new_stream(s, 0);
49
    if (!st)
50
        return AVERROR(ENOMEM);
51

  
52
    st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
53
    st->codec->codec_id   = CODEC_ID_DFA;
54
    st->codec->width      = avio_rl16(pb);
55
    st->codec->height     = avio_rl16(pb);
56
    mspf = avio_rl32(pb);
57
    if (!mspf) {
58
        av_log(s, AV_LOG_WARNING, "Zero FPS reported, defaulting to 10\n");
59
        mspf = 100;
60
    }
61
    av_set_pts_info(st, 24, mspf, 1000);
62
    avio_skip(pb, 128 - 16); // padding
63
    st->duration = frames;
64

  
65
    return 0;
66
}
67

  
68
static int dfa_read_packet(AVFormatContext *s, AVPacket *pkt)
69
{
70
    AVIOContext *pb = s->pb;
71
    uint32_t frame_size;
72
    int ret, first = 1;
73

  
74
    if (pb->eof_reached)
75
        return AVERROR_EOF;
76

  
77
    if (av_get_packet(pb, pkt, 12) != 12)
78
        return AVERROR(EIO);
79
    while (!pb->eof_reached) {
80
        if (!first) {
81
            ret = av_append_packet(pb, pkt, 12);
82
            if (ret < 0) {
83
                av_free_packet(pkt);
84
                return ret;
85
            }
86
        } else
87
            first = 0;
88
        frame_size = AV_RL32(pkt->data + pkt->size - 8);
89
        if (frame_size > INT_MAX - 4) {
90
            av_log(s, AV_LOG_ERROR, "Too large chunk size: %d\n", frame_size);
91
            return AVERROR(EIO);
92
        }
93
        if (AV_RL32(pkt->data + pkt->size - 12) == MKTAG('E', 'O', 'F', 'R')) {
94
            if (frame_size) {
95
                av_log(s, AV_LOG_WARNING, "skipping %d bytes of end-of-frame marker chunk\n",
96
                       frame_size);
97
                avio_skip(pb, frame_size);
98
            }
99
            return 0;
100
        }
101
        ret = av_append_packet(pb, pkt, frame_size);
102
        if (ret < 0) {
103
            av_free_packet(pkt);
104
            return ret;
105
        }
106
    }
107

  
108
    return 0;
109
}
110

  
111
AVInputFormat ff_dfa_demuxer = {
112
    "dfa",
113
    NULL_IF_CONFIG_SMALL("Chronomaster DFA"),
114
    0,
115
    dfa_probe,
116
    dfa_read_header,
117
    dfa_read_packet,
118
    .flags = AVFMT_GENERIC_INDEX,
119
};
libavformat/version.h
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, \

Also available in: Unified diff