~medibuntu-maintainers/mplayer/medibuntu.precise

« back to all changes in this revision

Viewing changes to ffmpeg/libavcodec/xan.c

  • Committer: Gauvain Pocentek
  • Date: 2012-03-06 11:59:12 UTC
  • mfrom: (66.1.15 precise)
  • Revision ID: gauvain@pocentek.net-20120306115912-h9d6kt9j0l532oo5
* Merge from Ubuntu:
  - put back faac support
  - recommends apport-hooks-medibuntu
  - change Maintainer, Uploaders & Vcs-* fields.
* New upstream snapshot
* upload to unstable
* Build against external libmpeg2
* drop 51_FTBFS_arm.patch again
* no longer build depend on libcdparanoia-dev on the Hurd
* Fix FTBFS on the hurd.
  Thanks to Samuel Thibault <sthibault@debian.org> (Closes: #654974)
* Fix FTBFS on arm
* New upstream snapshot, Closes: #650339, #643621, #481807
* Imported Upstream version 1.0~rc4+svn34492
* Bump standards version
* Bump dependency on libav >= 4:0.8~, Closes: #653887
* Fix build-indep
* Build mplayer-gui again, Closes: #568514
* Drop debian/all-lang-config-mak.sh, no longer needed
* include .dfsg1 in version number
* remove get-orig-source target
* no longer prune compiler flags from the environment
* No longer advertise nor build 3fdx, mga and dxr3 backends,
  Closes: #496106, #442181, #533546
* beautify mplayer version identification string
* Brown paperbag upload.
* Next try to fix build failure on sparce after recent binutils change.
* Brown paperbag upload.
* Really fix build failure on sparc after recent binutils change.
* Properly set Replaces/Conflicts on mplayer2{,-dbg} to avoid
  file overwrite errors.
* Adjust versioning of mplayer listed in the mplayer-dbg's Depends field.
* Fix build failure on sparc after recent binutils change.
* Urgency medium bumped because of RC-level bugfix
  and speeding up x264 transition.
* Update to my @debian.org email.
* Upload to unstable
* Enable joystick support on Linux only, Closes: #638408
* Rebuild fixes toolchain issue on arm, Closes: #637077
* New upstream snapshot
* following the discussion started by Diego Biurrun <diego@biurrun.de>
  in debian-devel, I have prepared a new packaging of 'mplayer'
  (with code that comes from CVS)
* the upstream tar.bz cannot be distributed by Debian, since it contains
   CSS code; so I am repackaging it 
* I have tried my best to address all known issues:
  - the package contains the detailed Copyright made by Diego Biurrun 
  - the package does not contain CSS code, or  AFAIK other code on which 
     there is active patent enforcement
  - there is a script  debian/cvs-changelog.sh  that shows all changes
     done to files included in this source.
    This should comply with GPLv2 sec 2.a  (in spirit if not in letter)
    For this reason, the source code contains CVS directories.
* needs   make (>= 3.80) for 'html-chunked-$(1)' in DOCS/xml/Makefile

* some corrections, as suggested Diego Biurrun
  - binary codecs should go into /usr/lib/codecs (upstream default)
  - better template 'mplayer/install_codecs'
  - an empty 'font=' in mplayer.conf breaks mplayer: postinst corrected
* correction in 'mplayer/cfgnote'
* better mplayer.postinst and mplayer.config

* New upstream release
* better debian/copyright file
* do not ship a skin
* New upstream release
* changed DEB_BUILD_OPTIONS to DEB_BUILD_CONFIGURE ,
  DEB_BUILD_OPTIONS is used as in debian policy
* use gcc-3.4
* changed xlibs-dev to a long list of dependencies, for Debian/etch
* try to adhere to  http://www.mplayerhq.hu/DOCS/tech/binary-packaging.txt
  (see README.Debian for details)
* removed dependency on xlibmesa-dev, disabled opengl
* New upstream release
* Simon McVittie <hacks@pseudorandom.co.uk> wonderful work:
- Work around Debian bug #267442 (glibc's sys/uio.h and gcc's altivec.h have
  conflicting uses for __vector) by re-ordering #includes
- Fix potential symlink attack in ./configure
- Disable support for binary codecs on platforms for which those codecs
  aren't available; also disable the corresponding Debconf note when it's
  inappropriate
- Changed Build-Depends: so it works in pbuilder
- Explicitly build-depend on libjpeg62-dev, libfontconfig1-dev,
  libungif4-dev 
- Tweak debian/rules to avoid certain errors being ignored
- Use --language=all
* provide a target  'debian/rules get-orig-source' 
  that recreates the orig.tar.gz ; then use the above orig.tar.gz
* rewrote some parts of debian/rules
* don't clean and recompile docs if upstream ships them
* mplayer-doc was shipping too much stuff
* translated man pages where not installed properly
* compile with libdv4-dev
* correct README.Debian
* Forgot build-dep on libtheora
* Must not depend on libxvidcore
* New upstream release
* new release.
* rc1 to become 0.90
* new pre-release
* new pre-release
* gtk bug fixed.
* new release.
* version bumped
* 0.60 pre2 release
* 0.60 pre-release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
#include "libavutil/intreadwrite.h"
36
36
#include "avcodec.h"
37
37
#include "bytestream.h"
38
 
#define ALT_BITSTREAM_READER_LE
 
38
#define BITSTREAM_READER_LE
39
39
#include "get_bits.h"
40
40
// for av_memcpy_backptr
41
41
#include "libavutil/lzo.h"
95
95
    return 0;
96
96
}
97
97
 
98
 
static int xan_huffman_decode(unsigned char *dest, const unsigned char *src,
99
 
    int dest_len)
 
98
static int xan_huffman_decode(unsigned char *dest, int dest_len,
 
99
                              const unsigned char *src, int src_len)
100
100
{
101
101
    unsigned char byte = *src++;
102
102
    unsigned char ival = byte + 0x16;
103
103
    const unsigned char * ptr = src + byte*2;
 
104
    int ptr_len = src_len - 1 - byte*2;
104
105
    unsigned char val = ival;
105
106
    unsigned char *dest_end = dest + dest_len;
106
107
    GetBitContext gb;
107
108
 
108
 
    init_get_bits(&gb, ptr, 0); // FIXME: no src size available
109
 
 
110
 
    while ( val != 0x16 ) {
111
 
        val = src[val - 0x17 + get_bits1(&gb) * byte];
112
 
 
113
 
        if ( val < 0x16 ) {
 
109
    if (ptr_len < 0)
 
110
        return AVERROR_INVALIDDATA;
 
111
 
 
112
    init_get_bits(&gb, ptr, ptr_len * 8);
 
113
 
 
114
    while (val != 0x16) {
 
115
        unsigned idx = val - 0x17 + get_bits1(&gb) * byte;
 
116
        if (idx >= 2 * byte)
 
117
            return -1;
 
118
        val = src[idx];
 
119
 
 
120
        if (val < 0x16) {
114
121
            if (dest >= dest_end)
115
122
                return 0;
116
123
            *dest++ = val;
126
133
 *
127
134
 * @param dest destination buffer of dest_len, must be padded with at least 130 bytes
128
135
 */
129
 
static void xan_unpack(unsigned char *dest, const unsigned char *src, int dest_len)
 
136
static void xan_unpack(unsigned char *dest, int dest_len,
 
137
                       const unsigned char *src, int src_len)
130
138
{
131
139
    unsigned char opcode;
132
140
    int size;
 
141
    unsigned char *dest_org = dest;
133
142
    unsigned char *dest_end = dest + dest_len;
 
143
    const unsigned char *src_end = src + src_len;
134
144
 
135
 
    while (dest < dest_end) {
 
145
    while (dest < dest_end && src < src_end) {
136
146
        opcode = *src++;
137
147
 
138
148
        if (opcode < 0xe0) {
139
149
            int size2, back;
140
 
            if ( (opcode & 0x80) == 0 ) {
141
 
 
 
150
            if ((opcode & 0x80) == 0) {
142
151
                size = opcode & 3;
143
152
 
144
153
                back  = ((opcode & 0x60) << 3) + *src++ + 1;
145
154
                size2 = ((opcode & 0x1c) >> 2) + 3;
146
 
 
147
 
            } else if ( (opcode & 0x40) == 0 ) {
148
 
 
 
155
            } else if ((opcode & 0x40) == 0) {
149
156
                size = *src >> 6;
150
157
 
151
158
                back  = (bytestream_get_be16(&src) & 0x3fff) + 1;
152
159
                size2 = (opcode & 0x3f) + 4;
153
 
 
154
160
            } else {
155
 
 
156
161
                size = opcode & 3;
157
162
 
158
163
                back  = ((opcode & 0x10) << 12) + bytestream_get_be16(&src) + 1;
159
164
                size2 = ((opcode & 0x0c) <<  6) + *src++ + 5;
160
 
                if (size + size2 > dest_end - dest)
161
 
                    return;
162
165
            }
 
166
 
 
167
            if (dest_end - dest < size + size2 ||
 
168
                dest + size - dest_org < back ||
 
169
                src_end - src < size)
 
170
                return;
163
171
            memcpy(dest, src, size);  dest += size;  src += size;
164
172
            av_memcpy_backptr(dest, back, size2);
165
173
            dest += size2;
167
175
            int finish = opcode >= 0xfc;
168
176
            size = finish ? opcode & 3 : ((opcode & 0x1f) << 2) + 4;
169
177
 
 
178
            if (dest_end - dest < size || src_end - src < size)
 
179
                return;
170
180
            memcpy(dest, src, size);  dest += size;  src += size;
171
181
            if (finish)
172
182
                return;
189
199
    line_inc = stride - width;
190
200
    index = y * stride + x;
191
201
    current_x = x;
192
 
    while(pixel_count && (index < s->frame_size)) {
 
202
    while (pixel_count && index < s->frame_size) {
193
203
        int count = FFMIN(pixel_count, width - current_x);
194
204
        memcpy(palette_plane + index, pixel_buffer, count);
195
205
        pixel_count  -= count;
204
214
    }
205
215
}
206
216
 
207
 
static inline void xan_wc3_copy_pixel_run(XanContext *s,
208
 
    int x, int y, int pixel_count, int motion_x, int motion_y)
 
217
static inline void xan_wc3_copy_pixel_run(XanContext *s, int x, int y,
 
218
                                          int pixel_count, int motion_x,
 
219
                                          int motion_y)
209
220
{
210
221
    int stride;
211
222
    int line_inc;
214
225
    int width = s->avctx->width;
215
226
    unsigned char *palette_plane, *prev_palette_plane;
216
227
 
 
228
    if (y + motion_y < 0 || y + motion_y >= s->avctx->height ||
 
229
        x + motion_x < 0 || x + motion_x >= s->avctx->width)
 
230
        return;
 
231
 
217
232
    palette_plane = s->current_frame.data[0];
218
233
    prev_palette_plane = s->last_frame.data[0];
 
234
    if (!prev_palette_plane)
 
235
        prev_palette_plane = palette_plane;
219
236
    stride = s->current_frame.linesize[0];
220
237
    line_inc = stride - width;
221
238
    curframe_index = y * stride + x;
222
239
    curframe_x = x;
223
240
    prevframe_index = (y + motion_y) * stride + x + motion_x;
224
241
    prevframe_x = x + motion_x;
225
 
    while(pixel_count && (curframe_index < s->frame_size)) {
226
 
        int count = FFMIN3(pixel_count, width - curframe_x, width - prevframe_x);
 
242
    while (pixel_count &&
 
243
           curframe_index  < s->frame_size &&
 
244
           prevframe_index < s->frame_size) {
 
245
        int count = FFMIN3(pixel_count, width - curframe_x,
 
246
                           width - prevframe_x);
227
247
 
228
 
        memcpy(palette_plane + curframe_index, prev_palette_plane + prevframe_index, count);
 
248
        memcpy(palette_plane + curframe_index,
 
249
               prev_palette_plane + prevframe_index, count);
229
250
        pixel_count     -= count;
230
251
        curframe_index  += count;
231
252
        prevframe_index += count;
244
265
    }
245
266
}
246
267
 
247
 
static void xan_wc3_decode_frame(XanContext *s) {
 
268
static int xan_wc3_decode_frame(XanContext *s) {
248
269
 
249
 
    int width = s->avctx->width;
 
270
    int width  = s->avctx->width;
250
271
    int height = s->avctx->height;
251
272
    int total_pixels = width * height;
252
273
    unsigned char opcode;
256
277
    int x, y;
257
278
 
258
279
    unsigned char *opcode_buffer = s->buffer1;
 
280
    unsigned char *opcode_buffer_end = s->buffer1 + s->buffer1_size;
259
281
    int opcode_buffer_size = s->buffer1_size;
260
282
    const unsigned char *imagedata_buffer = s->buffer2;
261
283
 
264
286
    const unsigned char *size_segment;
265
287
    const unsigned char *vector_segment;
266
288
    const unsigned char *imagedata_segment;
267
 
 
268
 
    huffman_segment =   s->buf + AV_RL16(&s->buf[0]);
269
 
    size_segment =      s->buf + AV_RL16(&s->buf[2]);
270
 
    vector_segment =    s->buf + AV_RL16(&s->buf[4]);
271
 
    imagedata_segment = s->buf + AV_RL16(&s->buf[6]);
272
 
 
273
 
    xan_huffman_decode(opcode_buffer, huffman_segment, opcode_buffer_size);
274
 
 
275
 
    if (imagedata_segment[0] == 2)
276
 
        xan_unpack(s->buffer2, &imagedata_segment[1], s->buffer2_size);
277
 
    else
 
289
    int huffman_offset, size_offset, vector_offset, imagedata_offset,
 
290
        imagedata_size;
 
291
 
 
292
    if (s->size < 8)
 
293
        return AVERROR_INVALIDDATA;
 
294
 
 
295
    huffman_offset    = AV_RL16(&s->buf[0]);
 
296
    size_offset       = AV_RL16(&s->buf[2]);
 
297
    vector_offset     = AV_RL16(&s->buf[4]);
 
298
    imagedata_offset  = AV_RL16(&s->buf[6]);
 
299
 
 
300
    if (huffman_offset   >= s->size ||
 
301
        size_offset      >= s->size ||
 
302
        vector_offset    >= s->size ||
 
303
        imagedata_offset >= s->size)
 
304
        return AVERROR_INVALIDDATA;
 
305
 
 
306
    huffman_segment   = s->buf + huffman_offset;
 
307
    size_segment      = s->buf + size_offset;
 
308
    vector_segment    = s->buf + vector_offset;
 
309
    imagedata_segment = s->buf + imagedata_offset;
 
310
 
 
311
    if (xan_huffman_decode(opcode_buffer, opcode_buffer_size,
 
312
                           huffman_segment, s->size - huffman_offset) < 0)
 
313
        return AVERROR_INVALIDDATA;
 
314
 
 
315
    if (imagedata_segment[0] == 2) {
 
316
        xan_unpack(s->buffer2, s->buffer2_size,
 
317
                   &imagedata_segment[1], s->size - imagedata_offset - 1);
 
318
        imagedata_size = s->buffer2_size;
 
319
    } else {
 
320
        imagedata_size = s->size - imagedata_offset - 1;
278
321
        imagedata_buffer = &imagedata_segment[1];
 
322
    }
279
323
 
280
324
    /* use the decoded data segments to build the frame */
281
325
    x = y = 0;
282
 
    while (total_pixels) {
 
326
    while (total_pixels && opcode_buffer < opcode_buffer_end) {
283
327
 
284
328
        opcode = *opcode_buffer++;
285
329
        size = 0;
329
373
            break;
330
374
        }
331
375
 
 
376
        if (size > total_pixels)
 
377
            break;
 
378
 
332
379
        if (opcode < 12) {
333
380
            flag ^= 1;
334
381
            if (flag) {
336
383
                xan_wc3_copy_pixel_run(s, x, y, size, 0, 0);
337
384
            } else {
338
385
                /* output a run of pixels from imagedata_buffer */
 
386
                if (imagedata_size < size)
 
387
                    break;
339
388
                xan_wc3_output_pixel_run(s, imagedata_buffer, x, y, size);
340
389
                imagedata_buffer += size;
 
390
                imagedata_size -= size;
341
391
            }
342
392
        } else {
343
393
            /* run-based motion compensation from last frame */
356
406
        y += (x + size) / width;
357
407
        x  = (x + size) % width;
358
408
    }
 
409
    return 0;
359
410
}
360
411
 
361
412
#if RUNTIME_GAMMA
466
517
                    return AVERROR_INVALIDDATA;
467
518
                if (s->palettes_count >= PALETTES_MAX)
468
519
                    return AVERROR_INVALIDDATA;
469
 
                tmpptr = av_realloc(s->palettes, (s->palettes_count + 1) * AVPALETTE_SIZE);
 
520
                tmpptr = av_realloc(s->palettes,
 
521
                                    (s->palettes_count + 1) * AVPALETTE_SIZE);
470
522
                if (!tmpptr)
471
523
                    return AVERROR(ENOMEM);
472
524
                s->palettes = tmpptr;
503
555
        }
504
556
        buf_size = buf_end - buf;
505
557
    }
 
558
    if (s->palettes_count <= 0) {
 
559
        av_log(s->avctx, AV_LOG_ERROR, "No palette found\n");
 
560
        return AVERROR_INVALIDDATA;
 
561
    }
 
562
 
506
563
    if ((ret = avctx->get_buffer(avctx, &s->current_frame))) {
507
564
        av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n");
508
565
        return ret;
512
569
    if (!s->frame_size)
513
570
        s->frame_size = s->current_frame.linesize[0] * s->avctx->height;
514
571
 
515
 
    memcpy(s->current_frame.data[1], s->palettes + s->cur_palette * AVPALETTE_COUNT, AVPALETTE_SIZE);
 
572
    memcpy(s->current_frame.data[1],
 
573
           s->palettes + s->cur_palette * AVPALETTE_COUNT, AVPALETTE_SIZE);
516
574
 
517
575
    s->buf = buf;
518
576
    s->size = buf_size;
519
577
 
520
 
    xan_wc3_decode_frame(s);
 
578
    if (xan_wc3_decode_frame(s) < 0)
 
579
        return AVERROR_INVALIDDATA;
521
580
 
522
581
    /* release the last frame if it is allocated */
523
582
    if (s->last_frame.data[0])
551
610
}
552
611
 
553
612
AVCodec ff_xan_wc3_decoder = {
554
 
    "xan_wc3",
555
 
    AVMEDIA_TYPE_VIDEO,
556
 
    CODEC_ID_XAN_WC3,
557
 
    sizeof(XanContext),
558
 
    xan_decode_init,
559
 
    NULL,
560
 
    xan_decode_end,
561
 
    xan_decode_frame,
562
 
    CODEC_CAP_DR1,
563
 
    .long_name = NULL_IF_CONFIG_SMALL("Wing Commander III / Xan"),
 
613
    .name           = "xan_wc3",
 
614
    .type           = AVMEDIA_TYPE_VIDEO,
 
615
    .id             = CODEC_ID_XAN_WC3,
 
616
    .priv_data_size = sizeof(XanContext),
 
617
    .init           = xan_decode_init,
 
618
    .close          = xan_decode_end,
 
619
    .decode         = xan_decode_frame,
 
620
    .capabilities   = CODEC_CAP_DR1,
 
621
    .long_name      = NULL_IF_CONFIG_SMALL("Wing Commander III / Xan"),
564
622
};
565