annotate truemotion2.c @ 2908:21068c2fcb1d libavcodec

gcc 2.95 fix, courtesy of Luca Abeni
author melanson
date Fri, 14 Oct 2005 16:17:40 +0000
parents e578b3572987
children a1d02ca0d339
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2906
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
1 /*
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
2 * Duck/ON2 TrueMotion 2 Decoder
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
3 * Copyright (c) 2005 Konstantin Shishkov
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
4 *
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
9 *
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
13 * Lesser General Public License for more details.
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
14 *
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
18 *
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
19 */
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
20
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
21 /**
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
22 * @file truemotion2.c
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
23 * Duck TrueMotion2 decoder.
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
24 */
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
25
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
26 #include "avcodec.h"
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
27 #include "common.h"
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
28 #include "bitstream.h"
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
29 #include "dsputil.h"
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
30
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
31 #define TM2_ESCAPE 0x80000000
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
32 #define TM2_DELTAS 32
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
33 /* Huffman-coded streams of different types of blocks */
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
34 enum TM2_STREAMS{ TM2_C_HI = 0, TM2_C_LO, TM2_L_HI, TM2_L_LO,
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
35 TM2_UPD, TM2_MOT, TM2_TYPE, TM2_NUM_STREAMS};
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
36 /* Block types */
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
37 enum TM2_BLOCKS{ TM2_HI_RES = 0, TM2_MED_RES, TM2_LOW_RES, TM2_NULL_RES,
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
38 TM2_UPDATE, TM2_STILL, TM2_MOTION};
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
39
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
40 typedef struct TM2Context{
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
41 AVCodecContext *avctx;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
42 AVFrame pic;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
43
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
44 GetBitContext gb;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
45 DSPContext dsp;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
46
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
47 /* TM2 streams */
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
48 int *tokens[TM2_NUM_STREAMS];
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
49 int tok_lens[TM2_NUM_STREAMS];
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
50 int tok_ptrs[TM2_NUM_STREAMS];
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
51 int deltas[TM2_NUM_STREAMS][TM2_DELTAS];
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
52 /* for blocks decoding */
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
53 int D[4];
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
54 int CD[4];
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
55 int *last;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
56 int *clast;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
57
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
58 /* data for current and previous frame */
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
59 int *Y1, *U1, *V1, *Y2, *U2, *V2;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
60 int cur;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
61 } TM2Context;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
62
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
63 /**
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
64 * Huffman codes for each of streams
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
65 */
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
66 typedef struct TM2Codes{
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
67 VLC vlc; ///< table for FFmpeg bitstream reader
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
68 int bits;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
69 int *recode; ///< table for converting from code indexes to values
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
70 int length;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
71 } TM2Codes;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
72
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
73 /**
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
74 * structure for gathering Huffman codes information
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
75 */
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
76 typedef struct TM2Huff{
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
77 int val_bits; ///< length of literal
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
78 int max_bits; ///< maximum length of code
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
79 int min_bits; ///< minimum length of code
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
80 int nodes; ///< total number of nodes in tree
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
81 int num; ///< current number filled
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
82 int max_num; ///< total number of codes
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
83 int *nums; ///< literals
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
84 uint32_t *bits; ///< codes
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
85 int *lens; ///< codelengths
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
86 } TM2Huff;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
87
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
88 static int tm2_read_tree(TM2Context *ctx, uint32_t prefix, int length, TM2Huff *huff)
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
89 {
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
90 if(length > huff->max_bits) {
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
91 av_log(ctx->avctx, AV_LOG_ERROR, "Tree exceeded its given depth (%i)\n", huff->max_bits);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
92 return -1;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
93 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
94
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
95 if(!get_bits1(&ctx->gb)) { /* literal */
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
96 if (length == 0) {
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
97 length = 1;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
98 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
99 if(huff->num >= huff->max_num) {
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
100 av_log(ctx->avctx, AV_LOG_DEBUG, "Too many literals\n");
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
101 return -1;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
102 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
103 huff->nums[huff->num] = get_bits_long(&ctx->gb, huff->val_bits);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
104 huff->bits[huff->num] = prefix;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
105 huff->lens[huff->num] = length;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
106 huff->num++;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
107 return 0;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
108 } else { /* non-terminal node */
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
109 if(tm2_read_tree(ctx, prefix << 1, length + 1, huff) == -1)
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
110 return -1;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
111 if(tm2_read_tree(ctx, (prefix << 1) | 1, length + 1, huff) == -1)
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
112 return -1;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
113 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
114 return 0;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
115 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
116
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
117 static int tm2_build_huff_table(TM2Context *ctx, TM2Codes *code)
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
118 {
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
119 TM2Huff huff;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
120 int res = 0;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
121
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
122 huff.val_bits = get_bits(&ctx->gb, 5);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
123 huff.max_bits = get_bits(&ctx->gb, 5);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
124 huff.min_bits = get_bits(&ctx->gb, 5);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
125 huff.nodes = get_bits_long(&ctx->gb, 17);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
126 huff.num = 0;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
127
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
128 /* check for correct codes parameters */
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
129 if((huff.val_bits < 1) || (huff.val_bits > 32) ||
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
130 (huff.max_bits < 0) || (huff.max_bits > 32)) {
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
131 av_log(ctx->avctx, AV_LOG_ERROR, "Incorrect tree parameters - literal length: %i, max code length: %i\n",
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
132 huff.val_bits, huff.max_bits);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
133 return -1;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
134 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
135 if((huff.nodes < 0) || (huff.nodes > 0x10000)) {
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
136 av_log(ctx->avctx, AV_LOG_ERROR, "Incorrect number of Huffman tree nodes: %i\n", huff.nodes);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
137 return -1;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
138 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
139 /* one-node tree */
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
140 if(huff.max_bits == 0)
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
141 huff.max_bits = 1;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
142
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
143 /* allocate space for codes - it is exactly ceil(nodes / 2) entries */
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
144 huff.max_num = (huff.nodes + 1) >> 1;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
145 huff.nums = av_mallocz(huff.max_num * sizeof(int));
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
146 huff.bits = av_mallocz(huff.max_num * sizeof(uint32_t));
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
147 huff.lens = av_mallocz(huff.max_num * sizeof(int));
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
148
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
149 if(tm2_read_tree(ctx, 0, 0, &huff) == -1)
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
150 res = -1;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
151
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
152 if(huff.num != huff.max_num) {
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
153 av_log(ctx->avctx, AV_LOG_ERROR, "Got less codes than expected: %i of %i\n",
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
154 huff.num, huff.max_num);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
155 res = -1;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
156 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
157
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
158 /* convert codes to vlc_table */
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
159 if(res != -1) {
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
160 int i;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
161
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
162 res = init_vlc(&code->vlc, huff.max_bits, huff.max_num,
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
163 huff.lens, sizeof(int), sizeof(int),
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
164 huff.bits, sizeof(uint32_t), sizeof(uint32_t), 0);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
165 if(res < 0) {
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
166 av_log(ctx->avctx, AV_LOG_ERROR, "Cannot build VLC table\n");
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
167 res = -1;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
168 } else
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
169 res = 0;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
170 if(res != -1) {
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
171 code->bits = huff.max_bits;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
172 code->length = huff.max_num;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
173 code->recode = av_malloc(code->length * sizeof(int));
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
174 for(i = 0; i < code->length; i++)
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
175 code->recode[i] = huff.nums[i];
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
176 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
177 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
178 /* free allocated memory */
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
179 av_free(huff.nums);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
180 av_free(huff.bits);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
181 av_free(huff.lens);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
182
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
183 return res;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
184 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
185
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
186 static void tm2_free_codes(TM2Codes *code)
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
187 {
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
188 if(code->recode)
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
189 av_free(code->recode);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
190 if(code->vlc.table)
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
191 free_vlc(&code->vlc);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
192 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
193
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
194 static inline int tm2_get_token(GetBitContext *gb, TM2Codes *code)
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
195 {
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
196 int val;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
197 val = get_vlc2(gb, code->vlc.table, code->bits, 1);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
198 return code->recode[val];
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
199 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
200
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
201 static inline int tm2_read_header(TM2Context *ctx, uint8_t *buf)
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
202 {
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
203 uint32_t magic;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
204 uint8_t *obuf;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
205 int length;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
206
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
207 obuf = buf;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
208
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
209 magic = LE_32(buf);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
210 buf += 4;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
211
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
212 if(magic == 0x00000100) { /* old header */
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
213 /* av_log (ctx->avctx, AV_LOG_ERROR, "TM2 old header: not implemented (yet)\n"); */
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
214 return 40;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
215 } else if(magic == 0x00000101) { /* new header */
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
216 int w, h, size, flags, xr, yr;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
217
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
218 length = LE_32(buf);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
219 buf += 4;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
220
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
221 init_get_bits(&ctx->gb, buf, 32);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
222 size = get_bits_long(&ctx->gb, 31);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
223 h = get_bits(&ctx->gb, 15);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
224 w = get_bits(&ctx->gb, 15);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
225 flags = get_bits_long(&ctx->gb, 31);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
226 yr = get_bits(&ctx->gb, 9);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
227 xr = get_bits(&ctx->gb, 9);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
228
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
229 return 40;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
230 } else {
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
231 av_log (ctx->avctx, AV_LOG_ERROR, "Not a TM2 header: 0x%08X\n", magic);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
232 return -1;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
233 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
234
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
235 return (buf - obuf);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
236 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
237
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
238 static int tm2_read_deltas(TM2Context *ctx, int stream_id) {
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
239 int d, mb;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
240 int i, v;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
241
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
242 d = get_bits(&ctx->gb, 9);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
243 mb = get_bits(&ctx->gb, 5);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
244
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
245 if((d < 1) || (d > TM2_DELTAS) || (mb < 1) || (mb > 32)) {
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
246 av_log(ctx->avctx, AV_LOG_ERROR, "Incorrect delta table: %i deltas x %i bits\n", d, mb);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
247 return -1;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
248 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
249
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
250 for(i = 0; i < d; i++) {
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
251 v = get_bits_long(&ctx->gb, mb);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
252 if(v & (1 << (mb - 1)))
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
253 ctx->deltas[stream_id][i] = v - (1 << mb);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
254 else
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
255 ctx->deltas[stream_id][i] = v;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
256 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
257 for(; i < TM2_DELTAS; i++)
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
258 ctx->deltas[stream_id][i] = 0;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
259
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
260 return 0;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
261 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
262
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
263 static int tm2_read_stream(TM2Context *ctx, uint8_t *buf, int stream_id) {
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
264 int i;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
265 int cur = 0;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
266 int skip = 0;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
267 int len, toks;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
268 TM2Codes codes;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
269
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
270 /* get stream length in dwords */
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
271 len = BE_32(buf); buf += 4; cur += 4;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
272 skip = len * 4 + 4;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
273
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
274 if(len == 0)
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
275 return 4;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
276
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
277 toks = BE_32(buf); buf += 4; cur += 4;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
278 if(toks & 1) {
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
279 len = BE_32(buf); buf += 4; cur += 4;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
280 if(len == TM2_ESCAPE) {
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
281 len = BE_32(buf); buf += 4; cur += 4;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
282 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
283 if(len > 0) {
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
284 init_get_bits(&ctx->gb, buf, skip - cur);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
285 if(tm2_read_deltas(ctx, stream_id) == -1)
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
286 return -1;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
287 buf += ((get_bits_count(&ctx->gb) + 31) >> 5) << 2;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
288 cur += ((get_bits_count(&ctx->gb) + 31) >> 5) << 2;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
289 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
290 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
291 /* skip unused fields */
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
292 if(BE_32(buf) == TM2_ESCAPE) {
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
293 buf += 4; cur += 4; /* some unknown length - could be escaped too */
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
294 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
295 buf += 4; cur += 4;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
296 buf += 4; cur += 4; /* unused by decoder */
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
297
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
298 init_get_bits(&ctx->gb, buf, skip - cur);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
299 if(tm2_build_huff_table(ctx, &codes) == -1)
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
300 return -1;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
301 buf += ((get_bits_count(&ctx->gb) + 31) >> 5) << 2;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
302 cur += ((get_bits_count(&ctx->gb) + 31) >> 5) << 2;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
303
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
304 toks >>= 1;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
305 /* check if we have sane number of tokens */
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
306 if((toks < 0) || (toks > 0xFFFFFF)){
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
307 av_log(ctx->avctx, AV_LOG_ERROR, "Incorrect number of tokens: %i\n", toks);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
308 tm2_free_codes(&codes);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
309 return -1;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
310 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
311 ctx->tokens[stream_id] = av_realloc(ctx->tokens[stream_id], toks * sizeof(int));
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
312 ctx->tok_lens[stream_id] = toks;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
313 len = BE_32(buf); buf += 4; cur += 4;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
314 if(len > 0) {
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
315 init_get_bits(&ctx->gb, buf, skip - cur);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
316 for(i = 0; i < toks; i++)
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
317 ctx->tokens[stream_id][i] = tm2_get_token(&ctx->gb, &codes);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
318 } else {
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
319 memset(ctx->tokens[stream_id], 0, toks * sizeof(int));
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
320 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
321 tm2_free_codes(&codes);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
322
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
323 return skip;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
324 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
325
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
326 static inline int GET_TOK(TM2Context *ctx,int type) {
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
327 if(ctx->tok_ptrs[type] >= ctx->tok_lens[type]) {
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
328 av_log(ctx->avctx, AV_LOG_ERROR, "Read token from stream %i out of bounds (%i>=%i)\n", type, ctx->tok_ptrs[type], ctx->tok_lens[type]);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
329 return 0;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
330 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
331 if(type <= TM2_MOT)
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
332 return ctx->deltas[type][ctx->tokens[type][ctx->tok_ptrs[type]++]];
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
333 return ctx->tokens[type][ctx->tok_ptrs[type]++];
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
334 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
335
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
336 /* blocks decoding routines */
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
337
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
338 /* common Y, U, V pointers initialisation */
2908
21068c2fcb1d gcc 2.95 fix, courtesy of Luca Abeni
melanson
parents: 2906
diff changeset
339 #define TM2_INIT_POINTERS() \
2906
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
340 int *last, *clast; \
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
341 int *Y, *U, *V;\
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
342 int Ystride, Ustride, Vstride;\
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
343 \
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
344 Ystride = ctx->avctx->width;\
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
345 Vstride = (ctx->avctx->width + 1) >> 1;\
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
346 Ustride = (ctx->avctx->width + 1) >> 1;\
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
347 Y = (ctx->cur?ctx->Y2:ctx->Y1) + by * 4 * Ystride + bx * 4;\
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
348 V = (ctx->cur?ctx->V2:ctx->V1) + by * 2 * Vstride + bx * 2;\
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
349 U = (ctx->cur?ctx->U2:ctx->U1) + by * 2 * Ustride + bx * 2;\
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
350 last = ctx->last + bx * 4;\
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
351 clast = ctx->clast + bx * 4;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
352
2908
21068c2fcb1d gcc 2.95 fix, courtesy of Luca Abeni
melanson
parents: 2906
diff changeset
353 #define TM2_INIT_POINTERS_2() \
2906
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
354 int *Yo, *Uo, *Vo;\
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
355 int oYstride, oUstride, oVstride;\
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
356 \
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
357 TM2_INIT_POINTERS();\
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
358 oYstride = Ystride;\
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
359 oVstride = Vstride;\
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
360 oUstride = Ustride;\
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
361 Yo = (ctx->cur?ctx->Y1:ctx->Y2) + by * 4 * oYstride + bx * 4;\
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
362 Vo = (ctx->cur?ctx->V1:ctx->V2) + by * 2 * oVstride + bx * 2;\
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
363 Uo = (ctx->cur?ctx->U1:ctx->U2) + by * 2 * oUstride + bx * 2;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
364
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
365 /* recalculate last and delta values for next blocks */
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
366 #define TM2_RECALC_BLOCK(CHR, stride, last, CD) {\
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
367 CD[0] = (CHR[1] - 128) - last[1];\
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
368 CD[1] = (int)CHR[stride + 1] - (int)CHR[1];\
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
369 last[0] = (int)CHR[stride + 0] - 128;\
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
370 last[1] = (int)CHR[stride + 1] - 128;}
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
371
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
372 /* common operations - add deltas to 4x4 block of luma or 2x2 blocks of chroma */
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
373 static inline void tm2_apply_deltas(TM2Context *ctx, int* Y, int stride, int *deltas, int *last)
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
374 {
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
375 int ct, d;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
376 int i, j;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
377
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
378 for(j = 0; j < 4; j++){
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
379 ct = ctx->D[j];
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
380 for(i = 0; i < 4; i++){
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
381 d = deltas[i + j * 4];
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
382 ct += d;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
383 last[i] += ct;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
384 Y[i] = clip_uint8(last[i]);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
385 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
386 Y += stride;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
387 ctx->D[j] = ct;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
388 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
389 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
390
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
391 static inline void tm2_high_chroma(int *data, int stride, int *last, int *CD, int *deltas)
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
392 {
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
393 int i, j;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
394 for(j = 0; j < 2; j++){
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
395 for(i = 0; i < 2; i++){
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
396 CD[j] += deltas[i + j * 2];
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
397 last[i] += CD[j];
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
398 data[i] = last[i] + 128;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
399 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
400 data += stride;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
401 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
402 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
403
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
404 static inline void tm2_low_chroma(int *data, int stride, int *clast, int *CD, int *deltas, int bx)
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
405 {
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
406 int t;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
407 int l;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
408 int prev;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
409
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
410 if(bx > 0)
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
411 prev = clast[-3];
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
412 else
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
413 prev = 0;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
414 t = (CD[0] + CD[1]) >> 1;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
415 l = (prev - CD[0] - CD[1] + clast[1] + 1) >> 1;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
416 CD[1] = CD[0] + CD[1] - t;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
417 CD[0] = t;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
418 clast[0] = l;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
419
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
420 tm2_high_chroma(data, stride, clast, CD, deltas);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
421 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
422
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
423 static inline void tm2_hi_res_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
424 {
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
425 int i;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
426 int deltas[16];
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
427 TM2_INIT_POINTERS();
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
428
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
429 /* hi-res chroma */
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
430 for(i = 0; i < 4; i++) {
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
431 deltas[i] = GET_TOK(ctx, TM2_C_HI);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
432 deltas[i + 4] = GET_TOK(ctx, TM2_C_HI);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
433 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
434 tm2_high_chroma(U, Ustride, clast, ctx->CD, deltas);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
435 tm2_high_chroma(V, Vstride, clast + 2, ctx->CD + 2, deltas + 4);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
436
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
437 /* hi-res luma */
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
438 for(i = 0; i < 16; i++)
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
439 deltas[i] = GET_TOK(ctx, TM2_L_HI);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
440
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
441 tm2_apply_deltas(ctx, Y, Ystride, deltas, last);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
442 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
443
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
444 static inline void tm2_med_res_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
445 {
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
446 int i;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
447 int deltas[16];
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
448 TM2_INIT_POINTERS();
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
449
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
450 /* low-res chroma */
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
451 deltas[0] = GET_TOK(ctx, TM2_C_LO);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
452 deltas[1] = deltas[2] = deltas[3] = 0;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
453 tm2_low_chroma(U, Ustride, clast, ctx->CD, deltas, bx);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
454
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
455 deltas[0] = GET_TOK(ctx, TM2_C_LO);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
456 deltas[1] = deltas[2] = deltas[3] = 0;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
457 tm2_low_chroma(V, Vstride, clast + 2, ctx->CD + 2, deltas, bx);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
458
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
459 /* hi-res luma */
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
460 for(i = 0; i < 16; i++)
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
461 deltas[i] = GET_TOK(ctx, TM2_L_HI);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
462
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
463 tm2_apply_deltas(ctx, Y, Ystride, deltas, last);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
464 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
465
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
466 static inline void tm2_low_res_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
467 {
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
468 int i;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
469 int t1, t2;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
470 int deltas[16];
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
471 TM2_INIT_POINTERS();
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
472
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
473 /* low-res chroma */
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
474 deltas[0] = GET_TOK(ctx, TM2_C_LO);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
475 deltas[1] = deltas[2] = deltas[3] = 0;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
476 tm2_low_chroma(U, Ustride, clast, ctx->CD, deltas, bx);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
477
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
478 deltas[0] = GET_TOK(ctx, TM2_C_LO);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
479 deltas[1] = deltas[2] = deltas[3] = 0;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
480 tm2_low_chroma(V, Vstride, clast + 2, ctx->CD + 2, deltas, bx);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
481
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
482 /* low-res luma */
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
483 for(i = 0; i < 16; i++)
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
484 deltas[i] = 0;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
485
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
486 deltas[ 0] = GET_TOK(ctx, TM2_L_LO);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
487 deltas[ 2] = GET_TOK(ctx, TM2_L_LO);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
488 deltas[ 8] = GET_TOK(ctx, TM2_L_LO);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
489 deltas[10] = GET_TOK(ctx, TM2_L_LO);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
490
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
491 if(bx > 0)
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
492 last[0] = (last[-1] - ctx->D[0] - ctx->D[1] - ctx->D[2] - ctx->D[3] + last[1]) >> 1;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
493 else
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
494 last[0] = (last[1] - ctx->D[0] - ctx->D[1] - ctx->D[2] - ctx->D[3])>> 1;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
495 last[2] = (last[1] + last[3]) >> 1;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
496
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
497 t1 = ctx->D[0] + ctx->D[1];
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
498 ctx->D[0] = t1 >> 1;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
499 ctx->D[1] = t1 - (t1 >> 1);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
500 t2 = ctx->D[2] + ctx->D[3];
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
501 ctx->D[2] = t2 >> 1;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
502 ctx->D[3] = t2 - (t2 >> 1);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
503
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
504 tm2_apply_deltas(ctx, Y, Ystride, deltas, last);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
505 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
506
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
507 static inline void tm2_null_res_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
508 {
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
509 int i;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
510 int ct;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
511 int left, right, diff;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
512 int deltas[16];
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
513 TM2_INIT_POINTERS();
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
514
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
515 /* null chroma */
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
516 deltas[0] = deltas[1] = deltas[2] = deltas[3] = 0;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
517 tm2_low_chroma(U, Ustride, clast, ctx->CD, deltas, bx);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
518
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
519 deltas[0] = deltas[1] = deltas[2] = deltas[3] = 0;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
520 tm2_low_chroma(V, Vstride, clast + 2, ctx->CD + 2, deltas, bx);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
521
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
522 /* null luma */
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
523 for(i = 0; i < 16; i++)
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
524 deltas[i] = 0;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
525
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
526 ct = ctx->D[0] + ctx->D[1] + ctx->D[2] + ctx->D[3];
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
527
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
528 if(bx > 0)
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
529 left = last[-1] - ct;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
530 else
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
531 left = 0;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
532
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
533 right = last[3];
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
534 diff = right - left;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
535 last[0] = left + (diff >> 2);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
536 last[1] = left + (diff >> 1);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
537 last[2] = right - (diff >> 2);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
538 last[3] = right;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
539 {
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
540 int tp = left;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
541
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
542 ctx->D[0] = (tp + (ct >> 2)) - left;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
543 left += ctx->D[0];
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
544 ctx->D[1] = (tp + (ct >> 1)) - left;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
545 left += ctx->D[1];
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
546 ctx->D[2] = ((tp + ct) - (ct >> 2)) - left;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
547 left += ctx->D[2];
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
548 ctx->D[3] = (tp + ct) - left;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
549 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
550 tm2_apply_deltas(ctx, Y, Ystride, deltas, last);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
551 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
552
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
553 static inline void tm2_still_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
554 {
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
555 int i, j;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
556 TM2_INIT_POINTERS_2();
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
557
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
558 /* update chroma */
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
559 for(j = 0; j < 2; j++){
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
560 for(i = 0; i < 2; i++){
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
561 U[i] = Uo[i];
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
562 V[i] = Vo[i];
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
563 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
564 U += Ustride; V += Vstride;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
565 Uo += oUstride; Vo += oVstride;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
566 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
567 U -= Ustride * 2;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
568 V -= Vstride * 2;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
569 TM2_RECALC_BLOCK(U, Ustride, clast, ctx->CD);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
570 TM2_RECALC_BLOCK(V, Vstride, (clast + 2), (ctx->CD + 2));
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
571
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
572 /* update deltas */
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
573 ctx->D[0] = Yo[3] - last[3];
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
574 ctx->D[1] = Yo[3 + oYstride] - Yo[3];
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
575 ctx->D[2] = Yo[3 + oYstride * 2] - Yo[3 + oYstride];
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
576 ctx->D[3] = Yo[3 + oYstride * 3] - Yo[3 + oYstride * 2];
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
577
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
578 for(j = 0; j < 4; j++){
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
579 for(i = 0; i < 4; i++){
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
580 Y[i] = Yo[i];
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
581 last[i] = Yo[i];
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
582 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
583 Y += Ystride;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
584 Yo += oYstride;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
585 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
586 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
587
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
588 static inline void tm2_update_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
589 {
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
590 int i, j;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
591 int d;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
592 TM2_INIT_POINTERS_2();
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
593
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
594 /* update chroma */
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
595 for(j = 0; j < 2; j++){
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
596 for(i = 0; i < 2; i++){
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
597 U[i] = Uo[i] + GET_TOK(ctx, TM2_UPD);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
598 V[i] = Vo[i] + GET_TOK(ctx, TM2_UPD);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
599 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
600 U += Ustride; V += Vstride;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
601 Uo += oUstride; Vo += oVstride;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
602 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
603 U -= Ustride * 2;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
604 V -= Vstride * 2;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
605 TM2_RECALC_BLOCK(U, Ustride, clast, ctx->CD);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
606 TM2_RECALC_BLOCK(V, Vstride, (clast + 2), (ctx->CD + 2));
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
607
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
608 /* update deltas */
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
609 ctx->D[0] = Yo[3] - last[3];
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
610 ctx->D[1] = Yo[3 + oYstride] - Yo[3];
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
611 ctx->D[2] = Yo[3 + oYstride * 2] - Yo[3 + oYstride];
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
612 ctx->D[3] = Yo[3 + oYstride * 3] - Yo[3 + oYstride * 2];
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
613
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
614 for(j = 0; j < 4; j++){
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
615 d = last[3];
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
616 for(i = 0; i < 4; i++){
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
617 Y[i] = Yo[i] + GET_TOK(ctx, TM2_UPD);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
618 last[i] = Y[i];
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
619 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
620 ctx->D[j] = last[3] - d;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
621 Y += Ystride;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
622 Yo += oYstride;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
623 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
624 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
625
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
626 static inline void tm2_motion_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
627 {
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
628 int i, j;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
629 int mx, my;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
630 TM2_INIT_POINTERS_2();
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
631
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
632 mx = GET_TOK(ctx, TM2_MOT);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
633 my = GET_TOK(ctx, TM2_MOT);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
634
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
635 Yo += my * oYstride + mx;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
636 Uo += (my >> 1) * oUstride + (mx >> 1);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
637 Vo += (my >> 1) * oVstride + (mx >> 1);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
638
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
639 /* copy chroma */
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
640 for(j = 0; j < 2; j++){
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
641 for(i = 0; i < 2; i++){
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
642 U[i] = Uo[i];
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
643 V[i] = Vo[i];
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
644 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
645 U += Ustride; V += Vstride;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
646 Uo += oUstride; Vo += oVstride;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
647 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
648 U -= Ustride * 2;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
649 V -= Vstride * 2;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
650 TM2_RECALC_BLOCK(U, Ustride, clast, ctx->CD);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
651 TM2_RECALC_BLOCK(V, Vstride, (clast + 2), (ctx->CD + 2));
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
652
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
653 /* copy luma */
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
654 for(j = 0; j < 4; j++){
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
655 for(i = 0; i < 4; i++){
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
656 Y[i] = Yo[i];
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
657 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
658 Y += Ystride;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
659 Yo += oYstride;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
660 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
661 /* calculate deltas */
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
662 Y -= Ystride * 4;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
663 ctx->D[0] = Y[3] - last[3];
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
664 ctx->D[1] = Y[3 + Ystride] - Y[3];
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
665 ctx->D[2] = Y[3 + Ystride * 2] - Y[3 + Ystride];
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
666 ctx->D[3] = Y[3 + Ystride * 3] - Y[3 + Ystride * 2];
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
667 for(i = 0; i < 4; i++)
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
668 last[i] = Y[i + Ystride * 3];
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
669 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
670
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
671 static int tm2_decode_blocks(TM2Context *ctx, AVFrame *p)
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
672 {
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
673 int i, j;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
674 int bw, bh;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
675 int type;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
676 int keyframe = 1;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
677 uint8_t *Y, *U, *V;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
678 int *src;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
679
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
680 bw = ctx->avctx->width >> 2;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
681 bh = ctx->avctx->height >> 2;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
682
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
683 for(i = 0; i < TM2_NUM_STREAMS; i++)
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
684 ctx->tok_ptrs[i] = 0;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
685
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
686 if (ctx->tok_lens[TM2_TYPE]<bw*bh){
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
687 av_log(ctx->avctx,AV_LOG_ERROR,"Got %i tokens for %i blocks\n",ctx->tok_lens[TM2_TYPE],bw*bh);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
688 return -1;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
689 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
690
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
691 memset(ctx->last, 0, 4 * bw * sizeof(int));
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
692 memset(ctx->clast, 0, 4 * bw * sizeof(int));
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
693
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
694 for(j = 0; j < bh; j++) {
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
695 memset(ctx->D, 0, 4 * sizeof(int));
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
696 memset(ctx->CD, 0, 4 * sizeof(int));
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
697 for(i = 0; i < bw; i++) {
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
698 type = GET_TOK(ctx, TM2_TYPE);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
699 switch(type) {
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
700 case TM2_HI_RES:
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
701 tm2_hi_res_block(ctx, p, i, j);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
702 break;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
703 case TM2_MED_RES:
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
704 tm2_med_res_block(ctx, p, i, j);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
705 break;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
706 case TM2_LOW_RES:
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
707 tm2_low_res_block(ctx, p, i, j);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
708 break;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
709 case TM2_NULL_RES:
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
710 tm2_null_res_block(ctx, p, i, j);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
711 break;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
712 case TM2_UPDATE:
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
713 tm2_update_block(ctx, p, i, j);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
714 keyframe = 0;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
715 break;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
716 case TM2_STILL:
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
717 tm2_still_block(ctx, p, i, j);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
718 keyframe = 0;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
719 break;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
720 case TM2_MOTION:
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
721 tm2_motion_block(ctx, p, i, j);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
722 keyframe = 0;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
723 break;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
724 default:
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
725 av_log(ctx->avctx, AV_LOG_ERROR, "Skipping unknown block type %i\n", type);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
726 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
727 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
728 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
729
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
730 /* copy data from our buffer to AVFrame */
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
731 Y = p->data[0];
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
732 src = (ctx->cur?ctx->Y2:ctx->Y1);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
733 for(j = 0; j < ctx->avctx->height; j++){
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
734 for(i = 0; i < ctx->avctx->width; i++){
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
735 Y[i] = clip_uint8(*src++);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
736 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
737 Y += p->linesize[0];
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
738 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
739 U = p->data[2];
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
740 src = (ctx->cur?ctx->U2:ctx->U1);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
741 for(j = 0; j < (ctx->avctx->height + 1) >> 1; j++){
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
742 for(i = 0; i < (ctx->avctx->width + 1) >> 1; i++){
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
743 U[i] = clip_uint8(*src++);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
744 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
745 U += p->linesize[2];
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
746 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
747 V = p->data[1];
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
748 src = (ctx->cur?ctx->V2:ctx->V1);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
749 for(j = 0; j < (ctx->avctx->height + 1) >> 1; j++){
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
750 for(i = 0; i < (ctx->avctx->width + 1) >> 1; i++){
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
751 V[i] = clip_uint8(*src++);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
752 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
753 V += p->linesize[1];
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
754 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
755
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
756 return keyframe;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
757 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
758
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
759 static int decode_frame(AVCodecContext *avctx,
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
760 void *data, int *data_size,
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
761 uint8_t *buf, int buf_size)
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
762 {
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
763 TM2Context * const l = avctx->priv_data;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
764 AVFrame * const p= (AVFrame*)&l->pic;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
765 int skip, t;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
766
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
767 p->reference = 1;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
768 if(avctx->get_buffer(avctx, p) < 0){
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
769 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
770 return -1;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
771 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
772
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
773 l->dsp.bswap_buf((uint32_t*)buf, (uint32_t*)buf, buf_size >> 2);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
774 skip = tm2_read_header(l, buf);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
775
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
776 if(skip == -1)
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
777 return -1;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
778
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
779 t = tm2_read_stream(l, buf + skip, TM2_C_HI);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
780 if(t == -1)
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
781 return -1;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
782 skip += t;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
783 t = tm2_read_stream(l, buf + skip, TM2_C_LO);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
784 if(t == -1)
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
785 return -1;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
786 skip += t;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
787 t = tm2_read_stream(l, buf + skip, TM2_L_HI);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
788 if(t == -1)
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
789 return -1;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
790 skip += t;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
791 t = tm2_read_stream(l, buf + skip, TM2_L_LO);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
792 if(t == -1)
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
793 return -1;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
794 skip += t;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
795 t = tm2_read_stream(l, buf + skip, TM2_UPD);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
796 if(t == -1)
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
797 return -1;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
798 skip += t;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
799 t = tm2_read_stream(l, buf + skip, TM2_MOT);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
800 if(t == -1)
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
801 return -1;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
802 skip += t;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
803 t = tm2_read_stream(l, buf + skip, TM2_TYPE);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
804 if(t == -1)
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
805 return -1;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
806 p->key_frame = tm2_decode_blocks(l, p);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
807 if(p->key_frame)
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
808 p->pict_type = FF_I_TYPE;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
809 else
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
810 p->pict_type = FF_P_TYPE;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
811
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
812 l->cur = !l->cur;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
813 *data_size = sizeof(AVFrame);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
814 *(AVFrame*)data = l->pic;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
815
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
816 return buf_size;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
817 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
818
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
819 static int decode_init(AVCodecContext *avctx){
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
820 TM2Context * const l = avctx->priv_data;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
821 int i;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
822
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
823 if (avcodec_check_dimensions(avctx, avctx->height, avctx->width) < 0) {
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
824 return -1;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
825 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
826 if((avctx->width & 3) || (avctx->height & 3)){
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
827 av_log(avctx, AV_LOG_ERROR, "Width and height must be multiple of 4\n");
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
828 return -1;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
829 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
830
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
831 l->avctx = avctx;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
832 l->pic.data[0]=NULL;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
833 avctx->has_b_frames = 0;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
834 avctx->pix_fmt = PIX_FMT_YUV420P;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
835
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
836 dsputil_init(&l->dsp, avctx);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
837
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
838 l->last = av_malloc(4 * sizeof(int) * (avctx->width >> 2));
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
839 l->clast = av_malloc(4 * sizeof(int) * (avctx->width >> 2));
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
840
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
841 for(i = 0; i < TM2_NUM_STREAMS; i++) {
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
842 l->tokens[i] = NULL;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
843 l->tok_lens[i] = 0;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
844 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
845
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
846 l->Y1 = av_malloc(sizeof(int) * avctx->width * avctx->height);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
847 l->U1 = av_malloc(sizeof(int) * ((avctx->width + 1) >> 1) * ((avctx->height + 1) >> 1));
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
848 l->V1 = av_malloc(sizeof(int) * ((avctx->width + 1) >> 1) * ((avctx->height + 1) >> 1));
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
849 l->Y2 = av_malloc(sizeof(int) * avctx->width * avctx->height);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
850 l->U2 = av_malloc(sizeof(int) * ((avctx->width + 1) >> 1) * ((avctx->height + 1) >> 1));
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
851 l->V2 = av_malloc(sizeof(int) * ((avctx->width + 1) >> 1) * ((avctx->height + 1) >> 1));
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
852 l->cur = 0;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
853
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
854 return 0;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
855 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
856
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
857 static int decode_end(AVCodecContext *avctx){
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
858 TM2Context * const l = avctx->priv_data;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
859 int i;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
860
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
861 if(l->last)
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
862 av_free(l->last);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
863 if(l->clast)
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
864 av_free(l->clast);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
865 for(i = 0; i < TM2_NUM_STREAMS; i++)
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
866 if(l->tokens[i])
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
867 av_free(l->tokens[i]);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
868 if(l->Y1){
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
869 av_free(l->Y1);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
870 av_free(l->U1);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
871 av_free(l->V1);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
872 av_free(l->Y2);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
873 av_free(l->U2);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
874 av_free(l->V2);
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
875 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
876 return 0;
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
877 }
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
878
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
879 AVCodec truemotion2_decoder = {
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
880 "truemotion2",
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
881 CODEC_TYPE_VIDEO,
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
882 CODEC_ID_TRUEMOTION2,
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
883 sizeof(TM2Context),
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
884 decode_init,
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
885 NULL,
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
886 decode_end,
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
887 decode_frame,
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
888 CODEC_CAP_DR1,
e578b3572987 Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff changeset
889 };