~ubuntu-branches/ubuntu/jaunty/xvidcap/jaunty-proposed

« back to all changes in this revision

Viewing changes to ffmpeg/libavcodec/truemotion1.c

  • Committer: Bazaar Package Importer
  • Author(s): Lionel Le Folgoc, Andrew Starr-Bochicchio, Lionel Le Folgoc
  • Date: 2008-12-26 00:10:06 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20081226001006-2040ls9680bd1blt
Tags: 1.1.7-0.2ubuntu1
[ Andrew Starr-Bochicchio ]
* Merge from debian-multimedia (LP: #298547), Ubuntu Changes:
 - For ffmpeg-related build-deps, fix versionized dependencies
   as the ubuntu versioning is different than debian-multimedia's.

[ Lionel Le Folgoc ]
* LP: #311412 is fixed since the 1.1.7~rc1-0.1 revision.
* debian/patches/03_ffmpeg.diff: updated to fix FTBFS due to libswscale API
  change (cherry-pick from Gentoo #234383).

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
/**
23
23
 * @file truemotion1.c
24
24
 * Duck TrueMotion v1 Video Decoder by
25
 
 * Alex Beregszaszi (alex@fsn.hu) and
 
25
 * Alex Beregszaszi and
26
26
 * Mike Melanson (melanson@pcisys.net)
27
27
 *
28
28
 * The TrueMotion v1 decoder presently only decodes 16-bit TM1 data and
34
34
#include <string.h>
35
35
#include <unistd.h>
36
36
 
37
 
#include "common.h"
38
37
#include "avcodec.h"
39
38
#include "dsputil.h"
40
39
 
43
42
typedef struct TrueMotion1Context {
44
43
    AVCodecContext *avctx;
45
44
    AVFrame frame;
46
 
    AVFrame prev_frame;
47
45
 
48
 
    uint8_t *buf;
 
46
    const uint8_t *buf;
49
47
    int size;
50
48
 
51
 
    uint8_t *mb_change_bits;
 
49
    const uint8_t *mb_change_bits;
52
50
    int mb_change_bits_row_size;
53
 
    uint8_t *index_stream;
 
51
    const uint8_t *index_stream;
54
52
    int index_stream_size;
55
53
 
56
54
    int flags;
463
461
    return header.header_size;
464
462
}
465
463
 
466
 
static int truemotion1_decode_init(AVCodecContext *avctx)
 
464
static av_cold int truemotion1_decode_init(AVCodecContext *avctx)
467
465
{
468
 
    TrueMotion1Context *s = (TrueMotion1Context *)avctx->priv_data;
 
466
    TrueMotion1Context *s = avctx->priv_data;
469
467
 
470
468
    s->avctx = avctx;
471
469
 
475
473
//    else
476
474
//        avctx->pix_fmt = PIX_FMT_RGB555;
477
475
 
478
 
    avctx->has_b_frames = 0;
479
 
    s->frame.data[0] = s->prev_frame.data[0] = NULL;
 
476
    s->frame.data[0] = NULL;
480
477
 
481
478
    /* there is a vertical predictor for each pixel in a line; each vertical
482
479
     * predictor is 0 to start with */
592
589
 
593
590
#define OUTPUT_PIXEL_PAIR() \
594
591
    *current_pixel_pair = *vert_pred + horiz_pred; \
595
 
    *vert_pred++ = *current_pixel_pair++; \
596
 
    prev_pixel_pair++;
 
592
    *vert_pred++ = *current_pixel_pair++;
597
593
 
598
594
static void truemotion1_decode_16bit(TrueMotion1Context *s)
599
595
{
603
599
    unsigned int horiz_pred;
604
600
    unsigned int *vert_pred;
605
601
    unsigned int *current_pixel_pair;
606
 
    unsigned int *prev_pixel_pair;
607
602
    unsigned char *current_line = s->frame.data[0];
608
 
    unsigned char *prev_line = s->prev_frame.data[0];
609
603
    int keyframe = s->flags & FLAG_KEYFRAME;
610
604
 
611
605
    /* these variables are for managing the stream of macroblock change bits */
612
 
    unsigned char *mb_change_bits = s->mb_change_bits;
 
606
    const unsigned char *mb_change_bits = s->mb_change_bits;
613
607
    unsigned char mb_change_byte;
614
608
    unsigned char mb_change_byte_mask;
615
609
    int mb_change_index;
628
622
        /* re-init variables for the next line iteration */
629
623
        horiz_pred = 0;
630
624
        current_pixel_pair = (unsigned int *)current_line;
631
 
        prev_pixel_pair = (unsigned int *)prev_line;
632
625
        vert_pred = s->vert_pred;
633
626
        mb_change_index = 0;
634
627
        mb_change_byte = mb_change_bits[mb_change_index++];
697
690
 
698
691
                /* skip (copy) four pixels, but reassign the horizontal
699
692
                 * predictor */
700
 
                *current_pixel_pair = *prev_pixel_pair++;
701
693
                *vert_pred++ = *current_pixel_pair++;
702
 
                *current_pixel_pair = *prev_pixel_pair++;
703
694
                horiz_pred = *current_pixel_pair - *vert_pred;
704
695
                *vert_pred++ = *current_pixel_pair++;
705
696
 
723
714
            mb_change_bits += s->mb_change_bits_row_size;
724
715
 
725
716
        current_line += s->frame.linesize[0];
726
 
        prev_line += s->prev_frame.linesize[0];
727
717
    }
728
718
}
729
719
 
735
725
    unsigned int horiz_pred;
736
726
    unsigned int *vert_pred;
737
727
    unsigned int *current_pixel_pair;
738
 
    unsigned int *prev_pixel_pair;
739
728
    unsigned char *current_line = s->frame.data[0];
740
 
    unsigned char *prev_line = s->prev_frame.data[0];
741
729
    int keyframe = s->flags & FLAG_KEYFRAME;
742
730
 
743
731
    /* these variables are for managing the stream of macroblock change bits */
744
 
    unsigned char *mb_change_bits = s->mb_change_bits;
 
732
    const unsigned char *mb_change_bits = s->mb_change_bits;
745
733
    unsigned char mb_change_byte;
746
734
    unsigned char mb_change_byte_mask;
747
735
    int mb_change_index;
760
748
        /* re-init variables for the next line iteration */
761
749
        horiz_pred = 0;
762
750
        current_pixel_pair = (unsigned int *)current_line;
763
 
        prev_pixel_pair = (unsigned int *)prev_line;
764
751
        vert_pred = s->vert_pred;
765
752
        mb_change_index = 0;
766
753
        mb_change_byte = mb_change_bits[mb_change_index++];
829
816
 
830
817
                /* skip (copy) four pixels, but reassign the horizontal
831
818
                 * predictor */
832
 
                *current_pixel_pair = *prev_pixel_pair++;
833
819
                *vert_pred++ = *current_pixel_pair++;
834
 
                *current_pixel_pair = *prev_pixel_pair++;
835
820
                horiz_pred = *current_pixel_pair - *vert_pred;
836
821
                *vert_pred++ = *current_pixel_pair++;
837
822
 
855
840
            mb_change_bits += s->mb_change_bits_row_size;
856
841
 
857
842
        current_line += s->frame.linesize[0];
858
 
        prev_line += s->prev_frame.linesize[0];
859
843
    }
860
844
}
861
845
 
862
846
 
863
847
static int truemotion1_decode_frame(AVCodecContext *avctx,
864
848
                                    void *data, int *data_size,
865
 
                                    uint8_t *buf, int buf_size)
 
849
                                    const uint8_t *buf, int buf_size)
866
850
{
867
 
    TrueMotion1Context *s = (TrueMotion1Context *)avctx->priv_data;
 
851
    TrueMotion1Context *s = avctx->priv_data;
868
852
 
869
853
    s->buf = buf;
870
854
    s->size = buf_size;
873
857
        return -1;
874
858
 
875
859
    s->frame.reference = 1;
876
 
    if (avctx->get_buffer(avctx, &s->frame) < 0) {
 
860
    s->frame.buffer_hints = FF_BUFFER_HINTS_VALID |
 
861
        FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
 
862
    if (avctx->reget_buffer(avctx, &s->frame) < 0) {
877
863
        av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n");
878
864
        return -1;
879
865
    }
880
866
 
881
 
    /* check for a do-nothing frame and copy the previous frame */
882
 
    if (compression_types[s->compression].algorithm == ALGO_NOP)
883
 
    {
884
 
        memcpy(s->frame.data[0], s->prev_frame.data[0],
885
 
            s->frame.linesize[0] * s->avctx->height);
886
 
    } else if (compression_types[s->compression].algorithm == ALGO_RGB24H) {
 
867
    if (compression_types[s->compression].algorithm == ALGO_RGB24H) {
887
868
        truemotion1_decode_24bit(s);
888
 
    } else {
 
869
    } else if (compression_types[s->compression].algorithm != ALGO_NOP) {
889
870
        truemotion1_decode_16bit(s);
890
871
    }
891
872
 
892
 
    if (s->prev_frame.data[0])
893
 
        avctx->release_buffer(avctx, &s->prev_frame);
894
 
 
895
 
    /* shuffle frames */
896
 
    s->prev_frame = s->frame;
897
 
 
898
873
    *data_size = sizeof(AVFrame);
899
874
    *(AVFrame*)data = s->frame;
900
875
 
902
877
    return buf_size;
903
878
}
904
879
 
905
 
static int truemotion1_decode_end(AVCodecContext *avctx)
 
880
static av_cold int truemotion1_decode_end(AVCodecContext *avctx)
906
881
{
907
 
    TrueMotion1Context *s = (TrueMotion1Context *)avctx->priv_data;
 
882
    TrueMotion1Context *s = avctx->priv_data;
908
883
 
909
 
    /* release the last frame */
910
 
    if (s->prev_frame.data[0])
911
 
        avctx->release_buffer(avctx, &s->prev_frame);
 
884
    if (s->frame.data[0])
 
885
        avctx->release_buffer(avctx, &s->frame);
912
886
 
913
887
    av_free(s->vert_pred);
914
888
 
925
899
    truemotion1_decode_end,
926
900
    truemotion1_decode_frame,
927
901
    CODEC_CAP_DR1,
 
902
    .long_name = "Duck TrueMotion 1.0",
928
903
};