Mercurial > libavcodec.hg
annotate truemotion2.c @ 8915:9dd34068523e libavcodec
Proper condition in xvmc decode mb.
The old one would try to use mv blocks that are written outside their buffer,
in case of unhandled error.
author | iive |
---|---|
date | Sun, 15 Feb 2009 09:03:47 +0000 |
parents | 0acc958e87b0 |
children | 54bc8a2727b0 |
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 * |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3800
diff
changeset
|
5 * This file is part of FFmpeg. |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3800
diff
changeset
|
6 * |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3800
diff
changeset
|
7 * FFmpeg is free software; you can redistribute it and/or |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
8 * 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
|
9 * License as published by the Free Software Foundation; either |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3800
diff
changeset
|
10 * version 2.1 of the License, or (at your option) any later version. |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
11 * |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3800
diff
changeset
|
12 * FFmpeg is distributed in the hope that it will be useful, |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
15 * Lesser General Public License for more details. |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
16 * |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
17 * You should have received a copy of the GNU Lesser General Public |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3800
diff
changeset
|
18 * License along with FFmpeg; if not, write to the Free Software |
3036
0b546eab515d
Update licensing information: The FSF changed postal address.
diego
parents:
2967
diff
changeset
|
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
20 */ |
2967 | 21 |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
22 /** |
8718
e9d9d946f213
Use full internal pathname in doxygen @file directives.
diego
parents:
7040
diff
changeset
|
23 * @file libavcodec/truemotion2.c |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
24 * Duck TrueMotion2 decoder. |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
25 */ |
2967 | 26 |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
27 #include "avcodec.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 |
2910 | 32 #define TM2_DELTAS 64 |
2906
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; |
2967 | 46 |
2906
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; |
2967 | 57 |
2906
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; |
2967 | 121 |
2906
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; |
2967 | 127 |
2906
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; |
2967 | 142 |
2906
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)); |
2967 | 148 |
2906
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; |
2967 | 151 |
2906
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 } |
2967 | 157 |
2906
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; |
2967 | 161 |
2906
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; |
2967 | 168 } else |
2906
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); |
2967 | 182 |
2906
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 |
6258 | 201 static inline int tm2_read_header(TM2Context *ctx, const uint8_t *buf) |
2906
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; |
6258 | 204 const uint8_t *obuf; |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
205 int length; |
2967 | 206 |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
207 obuf = buf; |
2967 | 208 |
4364 | 209 magic = AV_RL32(buf); |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
210 buf += 4; |
2967 | 211 |
2906
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; |
2967 | 217 |
4364 | 218 length = AV_RL32(buf); |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
219 buf += 4; |
2967 | 220 |
2910 | 221 init_get_bits(&ctx->gb, buf, 32 * 8); |
2906
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); |
2967 | 228 |
2906
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 } |
2967 | 234 |
6750 | 235 return buf - obuf; |
2906
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; |
2967 | 241 |
2906
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); |
2967 | 244 |
2906
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 } |
2967 | 249 |
2906
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; |
2967 | 259 |
2906
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 |
6258 | 263 static int tm2_read_stream(TM2Context *ctx, const uint8_t *buf, int stream_id) { |
2906
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; |
2967 | 269 |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
270 /* get stream length in dwords */ |
4364 | 271 len = AV_RB32(buf); buf += 4; cur += 4; |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
272 skip = len * 4 + 4; |
2967 | 273 |
2906
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; |
2967 | 276 |
4364 | 277 toks = AV_RB32(buf); buf += 4; cur += 4; |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
278 if(toks & 1) { |
4364 | 279 len = AV_RB32(buf); buf += 4; cur += 4; |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
280 if(len == TM2_ESCAPE) { |
4364 | 281 len = AV_RB32(buf); buf += 4; cur += 4; |
2906
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) { |
2910 | 284 init_get_bits(&ctx->gb, buf, (skip - cur) * 8); |
2906
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 */ |
4364 | 292 if(AV_RB32(buf) == TM2_ESCAPE) { |
2906
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 */ |
2967 | 297 |
2910 | 298 init_get_bits(&ctx->gb, buf, (skip - cur) * 8); |
2906
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; |
2967 | 303 |
2906
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; |
4364 | 313 len = AV_RB32(buf); buf += 4; cur += 4; |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
314 if(len > 0) { |
2910 | 315 init_get_bits(&ctx->gb, buf, (skip - cur) * 8); |
2906
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 { |
2910 | 319 for(i = 0; i < toks; i++) |
320 ctx->tokens[stream_id][i] = codes.recode[0]; | |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
321 } |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
322 tm2_free_codes(&codes); |
2967 | 323 |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
324 return skip; |
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 |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
327 static inline int GET_TOK(TM2Context *ctx,int type) { |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
328 if(ctx->tok_ptrs[type] >= ctx->tok_lens[type]) { |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
329 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
|
330 return 0; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
331 } |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
332 if(type <= TM2_MOT) |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
333 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
|
334 return ctx->tokens[type][ctx->tok_ptrs[type]++]; |
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 |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
337 /* blocks decoding routines */ |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
338 |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
339 /* common Y, U, V pointers initialisation */ |
2908 | 340 #define TM2_INIT_POINTERS() \ |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
341 int *last, *clast; \ |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
342 int *Y, *U, *V;\ |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
343 int Ystride, Ustride, Vstride;\ |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
344 \ |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
345 Ystride = ctx->avctx->width;\ |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
346 Vstride = (ctx->avctx->width + 1) >> 1;\ |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
347 Ustride = (ctx->avctx->width + 1) >> 1;\ |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
348 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
|
349 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
|
350 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
|
351 last = ctx->last + bx * 4;\ |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
352 clast = ctx->clast + bx * 4; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
353 |
2908 | 354 #define TM2_INIT_POINTERS_2() \ |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
355 int *Yo, *Uo, *Vo;\ |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
356 int oYstride, oUstride, oVstride;\ |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
357 \ |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
358 TM2_INIT_POINTERS();\ |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
359 oYstride = Ystride;\ |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
360 oVstride = Vstride;\ |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
361 oUstride = Ustride;\ |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
362 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
|
363 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
|
364 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
|
365 |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
366 /* recalculate last and delta values for next blocks */ |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
367 #define TM2_RECALC_BLOCK(CHR, stride, last, CD) {\ |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
368 CD[0] = (CHR[1] - 128) - last[1];\ |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
369 CD[1] = (int)CHR[stride + 1] - (int)CHR[1];\ |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
370 last[0] = (int)CHR[stride + 0] - 128;\ |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
371 last[1] = (int)CHR[stride + 1] - 128;} |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
372 |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
373 /* 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
|
374 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
|
375 { |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
376 int ct, d; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
377 int i, j; |
2967 | 378 |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
379 for(j = 0; j < 4; j++){ |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
380 ct = ctx->D[j]; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
381 for(i = 0; i < 4; i++){ |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
382 d = deltas[i + j * 4]; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
383 ct += d; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
384 last[i] += ct; |
4594 | 385 Y[i] = av_clip_uint8(last[i]); |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
386 } |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
387 Y += stride; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
388 ctx->D[j] = ct; |
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 |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
392 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
|
393 { |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
394 int i, j; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
395 for(j = 0; j < 2; j++){ |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
396 for(i = 0; i < 2; i++){ |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
397 CD[j] += deltas[i + j * 2]; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
398 last[i] += CD[j]; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
399 data[i] = last[i] + 128; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
400 } |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
401 data += stride; |
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 |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
405 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
|
406 { |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
407 int t; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
408 int l; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
409 int prev; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
410 |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
411 if(bx > 0) |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
412 prev = clast[-3]; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
413 else |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
414 prev = 0; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
415 t = (CD[0] + CD[1]) >> 1; |
2912 | 416 l = (prev - CD[0] - CD[1] + clast[1]) >> 1; |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
417 CD[1] = CD[0] + CD[1] - t; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
418 CD[0] = t; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
419 clast[0] = l; |
2967 | 420 |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
421 tm2_high_chroma(data, stride, clast, CD, deltas); |
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 |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
424 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
|
425 { |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
426 int i; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
427 int deltas[16]; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
428 TM2_INIT_POINTERS(); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
429 |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
430 /* hi-res chroma */ |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
431 for(i = 0; i < 4; i++) { |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
432 deltas[i] = GET_TOK(ctx, TM2_C_HI); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
433 deltas[i + 4] = GET_TOK(ctx, TM2_C_HI); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
434 } |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
435 tm2_high_chroma(U, Ustride, clast, ctx->CD, deltas); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
436 tm2_high_chroma(V, Vstride, clast + 2, ctx->CD + 2, deltas + 4); |
2967 | 437 |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
438 /* hi-res luma */ |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
439 for(i = 0; i < 16; i++) |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
440 deltas[i] = GET_TOK(ctx, TM2_L_HI); |
2967 | 441 |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
442 tm2_apply_deltas(ctx, Y, Ystride, deltas, last); |
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 |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
445 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
|
446 { |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
447 int i; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
448 int deltas[16]; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
449 TM2_INIT_POINTERS(); |
2967 | 450 |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
451 /* low-res chroma */ |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
452 deltas[0] = GET_TOK(ctx, TM2_C_LO); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
453 deltas[1] = deltas[2] = deltas[3] = 0; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
454 tm2_low_chroma(U, Ustride, clast, ctx->CD, deltas, bx); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
455 |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
456 deltas[0] = GET_TOK(ctx, TM2_C_LO); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
457 deltas[1] = deltas[2] = deltas[3] = 0; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
458 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
|
459 |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
460 /* hi-res luma */ |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
461 for(i = 0; i < 16; i++) |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
462 deltas[i] = GET_TOK(ctx, TM2_L_HI); |
2967 | 463 |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
464 tm2_apply_deltas(ctx, Y, Ystride, deltas, last); |
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 |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
467 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
|
468 { |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
469 int i; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
470 int t1, t2; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
471 int deltas[16]; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
472 TM2_INIT_POINTERS(); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
473 |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
474 /* low-res chroma */ |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
475 deltas[0] = GET_TOK(ctx, TM2_C_LO); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
476 deltas[1] = deltas[2] = deltas[3] = 0; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
477 tm2_low_chroma(U, Ustride, clast, ctx->CD, deltas, bx); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
478 |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
479 deltas[0] = GET_TOK(ctx, TM2_C_LO); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
480 deltas[1] = deltas[2] = deltas[3] = 0; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
481 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
|
482 |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
483 /* low-res luma */ |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
484 for(i = 0; i < 16; i++) |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
485 deltas[i] = 0; |
2967 | 486 |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
487 deltas[ 0] = GET_TOK(ctx, TM2_L_LO); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
488 deltas[ 2] = GET_TOK(ctx, TM2_L_LO); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
489 deltas[ 8] = GET_TOK(ctx, TM2_L_LO); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
490 deltas[10] = GET_TOK(ctx, TM2_L_LO); |
2967 | 491 |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
492 if(bx > 0) |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
493 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
|
494 else |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
495 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
|
496 last[2] = (last[1] + last[3]) >> 1; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
497 |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
498 t1 = ctx->D[0] + ctx->D[1]; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
499 ctx->D[0] = t1 >> 1; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
500 ctx->D[1] = t1 - (t1 >> 1); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
501 t2 = ctx->D[2] + ctx->D[3]; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
502 ctx->D[2] = t2 >> 1; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
503 ctx->D[3] = t2 - (t2 >> 1); |
2967 | 504 |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
505 tm2_apply_deltas(ctx, Y, Ystride, deltas, last); |
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 |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
508 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
|
509 { |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
510 int i; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
511 int ct; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
512 int left, right, diff; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
513 int deltas[16]; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
514 TM2_INIT_POINTERS(); |
2967 | 515 |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
516 /* null chroma */ |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
517 deltas[0] = deltas[1] = deltas[2] = deltas[3] = 0; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
518 tm2_low_chroma(U, Ustride, clast, ctx->CD, deltas, bx); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
519 |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
520 deltas[0] = deltas[1] = deltas[2] = deltas[3] = 0; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
521 tm2_low_chroma(V, Vstride, clast + 2, ctx->CD + 2, deltas, bx); |
2967 | 522 |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
523 /* null luma */ |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
524 for(i = 0; i < 16; i++) |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
525 deltas[i] = 0; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
526 |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
527 ct = ctx->D[0] + ctx->D[1] + ctx->D[2] + ctx->D[3]; |
2967 | 528 |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
529 if(bx > 0) |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
530 left = last[-1] - ct; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
531 else |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
532 left = 0; |
2967 | 533 |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
534 right = last[3]; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
535 diff = right - left; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
536 last[0] = left + (diff >> 2); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
537 last[1] = left + (diff >> 1); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
538 last[2] = right - (diff >> 2); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
539 last[3] = right; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
540 { |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
541 int tp = left; |
2967 | 542 |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
543 ctx->D[0] = (tp + (ct >> 2)) - left; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
544 left += ctx->D[0]; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
545 ctx->D[1] = (tp + (ct >> 1)) - left; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
546 left += ctx->D[1]; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
547 ctx->D[2] = ((tp + ct) - (ct >> 2)) - left; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
548 left += ctx->D[2]; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
549 ctx->D[3] = (tp + ct) - left; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
550 } |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
551 tm2_apply_deltas(ctx, Y, Ystride, deltas, last); |
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 |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
554 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
|
555 { |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
556 int i, j; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
557 TM2_INIT_POINTERS_2(); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
558 |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
559 /* update chroma */ |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
560 for(j = 0; j < 2; j++){ |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
561 for(i = 0; i < 2; i++){ |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
562 U[i] = Uo[i]; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
563 V[i] = Vo[i]; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
564 } |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
565 U += Ustride; V += Vstride; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
566 Uo += oUstride; Vo += oVstride; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
567 } |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
568 U -= Ustride * 2; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
569 V -= Vstride * 2; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
570 TM2_RECALC_BLOCK(U, Ustride, clast, ctx->CD); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
571 TM2_RECALC_BLOCK(V, Vstride, (clast + 2), (ctx->CD + 2)); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
572 |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
573 /* update deltas */ |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
574 ctx->D[0] = Yo[3] - last[3]; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
575 ctx->D[1] = Yo[3 + oYstride] - Yo[3]; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
576 ctx->D[2] = Yo[3 + oYstride * 2] - Yo[3 + oYstride]; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
577 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
|
578 |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
579 for(j = 0; j < 4; j++){ |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
580 for(i = 0; i < 4; i++){ |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
581 Y[i] = Yo[i]; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
582 last[i] = Yo[i]; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
583 } |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
584 Y += Ystride; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
585 Yo += oYstride; |
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 |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
589 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
|
590 { |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
591 int i, j; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
592 int d; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
593 TM2_INIT_POINTERS_2(); |
2967 | 594 |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
595 /* update chroma */ |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
596 for(j = 0; j < 2; j++){ |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
597 for(i = 0; i < 2; i++){ |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
598 U[i] = Uo[i] + GET_TOK(ctx, TM2_UPD); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
599 V[i] = Vo[i] + GET_TOK(ctx, TM2_UPD); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
600 } |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
601 U += Ustride; V += Vstride; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
602 Uo += oUstride; Vo += oVstride; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
603 } |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
604 U -= Ustride * 2; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
605 V -= Vstride * 2; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
606 TM2_RECALC_BLOCK(U, Ustride, clast, ctx->CD); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
607 TM2_RECALC_BLOCK(V, Vstride, (clast + 2), (ctx->CD + 2)); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
608 |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
609 /* update deltas */ |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
610 ctx->D[0] = Yo[3] - last[3]; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
611 ctx->D[1] = Yo[3 + oYstride] - Yo[3]; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
612 ctx->D[2] = Yo[3 + oYstride * 2] - Yo[3 + oYstride]; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
613 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
|
614 |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
615 for(j = 0; j < 4; j++){ |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
616 d = last[3]; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
617 for(i = 0; i < 4; i++){ |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
618 Y[i] = Yo[i] + GET_TOK(ctx, TM2_UPD); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
619 last[i] = Y[i]; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
620 } |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
621 ctx->D[j] = last[3] - d; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
622 Y += Ystride; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
623 Yo += oYstride; |
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 |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
627 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
|
628 { |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
629 int i, j; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
630 int mx, my; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
631 TM2_INIT_POINTERS_2(); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
632 |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
633 mx = GET_TOK(ctx, TM2_MOT); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
634 my = GET_TOK(ctx, TM2_MOT); |
2967 | 635 |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
636 Yo += my * oYstride + mx; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
637 Uo += (my >> 1) * oUstride + (mx >> 1); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
638 Vo += (my >> 1) * oVstride + (mx >> 1); |
2967 | 639 |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
640 /* copy chroma */ |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
641 for(j = 0; j < 2; j++){ |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
642 for(i = 0; i < 2; i++){ |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
643 U[i] = Uo[i]; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
644 V[i] = Vo[i]; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
645 } |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
646 U += Ustride; V += Vstride; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
647 Uo += oUstride; Vo += oVstride; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
648 } |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
649 U -= Ustride * 2; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
650 V -= Vstride * 2; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
651 TM2_RECALC_BLOCK(U, Ustride, clast, ctx->CD); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
652 TM2_RECALC_BLOCK(V, Vstride, (clast + 2), (ctx->CD + 2)); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
653 |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
654 /* copy luma */ |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
655 for(j = 0; j < 4; j++){ |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
656 for(i = 0; i < 4; i++){ |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
657 Y[i] = Yo[i]; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
658 } |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
659 Y += Ystride; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
660 Yo += oYstride; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
661 } |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
662 /* calculate deltas */ |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
663 Y -= Ystride * 4; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
664 ctx->D[0] = Y[3] - last[3]; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
665 ctx->D[1] = Y[3 + Ystride] - Y[3]; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
666 ctx->D[2] = Y[3 + Ystride * 2] - Y[3 + Ystride]; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
667 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
|
668 for(i = 0; i < 4; i++) |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
669 last[i] = Y[i + Ystride * 3]; |
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 |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
672 static int tm2_decode_blocks(TM2Context *ctx, AVFrame *p) |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
673 { |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
674 int i, j; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
675 int bw, bh; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
676 int type; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
677 int keyframe = 1; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
678 uint8_t *Y, *U, *V; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
679 int *src; |
2967 | 680 |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
681 bw = ctx->avctx->width >> 2; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
682 bh = ctx->avctx->height >> 2; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
683 |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
684 for(i = 0; i < TM2_NUM_STREAMS; i++) |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
685 ctx->tok_ptrs[i] = 0; |
2967 | 686 |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
687 if (ctx->tok_lens[TM2_TYPE]<bw*bh){ |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
688 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
|
689 return -1; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
690 } |
2967 | 691 |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
692 memset(ctx->last, 0, 4 * bw * sizeof(int)); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
693 memset(ctx->clast, 0, 4 * bw * sizeof(int)); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
694 |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
695 for(j = 0; j < bh; j++) { |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
696 memset(ctx->D, 0, 4 * sizeof(int)); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
697 memset(ctx->CD, 0, 4 * sizeof(int)); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
698 for(i = 0; i < bw; i++) { |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
699 type = GET_TOK(ctx, TM2_TYPE); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
700 switch(type) { |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
701 case TM2_HI_RES: |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
702 tm2_hi_res_block(ctx, p, i, j); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
703 break; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
704 case TM2_MED_RES: |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
705 tm2_med_res_block(ctx, p, i, j); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
706 break; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
707 case TM2_LOW_RES: |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
708 tm2_low_res_block(ctx, p, i, j); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
709 break; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
710 case TM2_NULL_RES: |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
711 tm2_null_res_block(ctx, p, i, j); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
712 break; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
713 case TM2_UPDATE: |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
714 tm2_update_block(ctx, p, i, j); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
715 keyframe = 0; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
716 break; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
717 case TM2_STILL: |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
718 tm2_still_block(ctx, p, i, j); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
719 keyframe = 0; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
720 break; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
721 case TM2_MOTION: |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
722 tm2_motion_block(ctx, p, i, j); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
723 keyframe = 0; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
724 break; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
725 default: |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
726 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
|
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 } |
2967 | 730 |
731 /* copy data from our buffer to AVFrame */ | |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
732 Y = p->data[0]; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
733 src = (ctx->cur?ctx->Y2:ctx->Y1); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
734 for(j = 0; j < ctx->avctx->height; j++){ |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
735 for(i = 0; i < ctx->avctx->width; i++){ |
4594 | 736 Y[i] = av_clip_uint8(*src++); |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
737 } |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
738 Y += p->linesize[0]; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
739 } |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
740 U = p->data[2]; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
741 src = (ctx->cur?ctx->U2:ctx->U1); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
742 for(j = 0; j < (ctx->avctx->height + 1) >> 1; j++){ |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
743 for(i = 0; i < (ctx->avctx->width + 1) >> 1; i++){ |
4594 | 744 U[i] = av_clip_uint8(*src++); |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
745 } |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
746 U += p->linesize[2]; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
747 } |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
748 V = p->data[1]; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
749 src = (ctx->cur?ctx->V2:ctx->V1); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
750 for(j = 0; j < (ctx->avctx->height + 1) >> 1; j++){ |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
751 for(i = 0; i < (ctx->avctx->width + 1) >> 1; i++){ |
4594 | 752 V[i] = av_clip_uint8(*src++); |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
753 } |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
754 V += p->linesize[1]; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
755 } |
2967 | 756 |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
757 return keyframe; |
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 |
8722 | 760 static const int tm2_stream_order[TM2_NUM_STREAMS] = { |
761 TM2_C_HI, TM2_C_LO, TM2_L_HI, TM2_L_LO, TM2_UPD, TM2_MOT, TM2_TYPE | |
762 }; | |
763 | |
2967 | 764 static int decode_frame(AVCodecContext *avctx, |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
765 void *data, int *data_size, |
6258 | 766 const uint8_t *buf, int buf_size) |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
767 { |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
768 TM2Context * const l = avctx->priv_data; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
769 AVFrame * const p= (AVFrame*)&l->pic; |
8722 | 770 int i, skip, t; |
8723
0acc958e87b0
Make TM2 decoder byteswap input into separate buffer instead of doing it in-place.
kostya
parents:
8722
diff
changeset
|
771 uint8_t *swbuf; |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
772 |
8723
0acc958e87b0
Make TM2 decoder byteswap input into separate buffer instead of doing it in-place.
kostya
parents:
8722
diff
changeset
|
773 swbuf = av_malloc(buf_size + FF_INPUT_BUFFER_PADDING_SIZE); |
0acc958e87b0
Make TM2 decoder byteswap input into separate buffer instead of doing it in-place.
kostya
parents:
8722
diff
changeset
|
774 if(!swbuf){ |
0acc958e87b0
Make TM2 decoder byteswap input into separate buffer instead of doing it in-place.
kostya
parents:
8722
diff
changeset
|
775 av_log(avctx, AV_LOG_ERROR, "Cannot allocate temporary buffer\n"); |
0acc958e87b0
Make TM2 decoder byteswap input into separate buffer instead of doing it in-place.
kostya
parents:
8722
diff
changeset
|
776 return -1; |
0acc958e87b0
Make TM2 decoder byteswap input into separate buffer instead of doing it in-place.
kostya
parents:
8722
diff
changeset
|
777 } |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
778 p->reference = 1; |
2910 | 779 p->buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE; |
780 if(avctx->reget_buffer(avctx, p) < 0){ | |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
781 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); |
8723
0acc958e87b0
Make TM2 decoder byteswap input into separate buffer instead of doing it in-place.
kostya
parents:
8722
diff
changeset
|
782 av_free(swbuf); |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
783 return -1; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
784 } |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
785 |
8723
0acc958e87b0
Make TM2 decoder byteswap input into separate buffer instead of doing it in-place.
kostya
parents:
8722
diff
changeset
|
786 l->dsp.bswap_buf((uint32_t*)swbuf, (const uint32_t*)buf, buf_size >> 2); |
0acc958e87b0
Make TM2 decoder byteswap input into separate buffer instead of doing it in-place.
kostya
parents:
8722
diff
changeset
|
787 skip = tm2_read_header(l, swbuf); |
2967 | 788 |
8723
0acc958e87b0
Make TM2 decoder byteswap input into separate buffer instead of doing it in-place.
kostya
parents:
8722
diff
changeset
|
789 if(skip == -1){ |
0acc958e87b0
Make TM2 decoder byteswap input into separate buffer instead of doing it in-place.
kostya
parents:
8722
diff
changeset
|
790 av_free(swbuf); |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
791 return -1; |
8723
0acc958e87b0
Make TM2 decoder byteswap input into separate buffer instead of doing it in-place.
kostya
parents:
8722
diff
changeset
|
792 } |
2967 | 793 |
8722 | 794 for(i = 0; i < TM2_NUM_STREAMS; i++){ |
8723
0acc958e87b0
Make TM2 decoder byteswap input into separate buffer instead of doing it in-place.
kostya
parents:
8722
diff
changeset
|
795 t = tm2_read_stream(l, swbuf + skip, tm2_stream_order[i]); |
8722 | 796 if(t == -1){ |
8723
0acc958e87b0
Make TM2 decoder byteswap input into separate buffer instead of doing it in-place.
kostya
parents:
8722
diff
changeset
|
797 av_free(swbuf); |
8722 | 798 return -1; |
799 } | |
800 skip += t; | |
801 } | |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
802 p->key_frame = tm2_decode_blocks(l, p); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
803 if(p->key_frame) |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
804 p->pict_type = FF_I_TYPE; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
805 else |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
806 p->pict_type = FF_P_TYPE; |
2967 | 807 |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
808 l->cur = !l->cur; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
809 *data_size = sizeof(AVFrame); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
810 *(AVFrame*)data = l->pic; |
8723
0acc958e87b0
Make TM2 decoder byteswap input into separate buffer instead of doing it in-place.
kostya
parents:
8722
diff
changeset
|
811 av_free(swbuf); |
2967 | 812 |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
813 return buf_size; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
814 } |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
815 |
6517
48759bfbd073
Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents:
6258
diff
changeset
|
816 static av_cold int decode_init(AVCodecContext *avctx){ |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
817 TM2Context * const l = avctx->priv_data; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
818 int i; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
819 |
3800
9b75ab171fa9
1l: correct argument order in avcodec_check_dimensions
kostya
parents:
3036
diff
changeset
|
820 if (avcodec_check_dimensions(avctx, avctx->width, avctx->height) < 0) { |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
821 return -1; |
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((avctx->width & 3) || (avctx->height & 3)){ |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
824 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
|
825 return -1; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
826 } |
2967 | 827 |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
828 l->avctx = avctx; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
829 l->pic.data[0]=NULL; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
830 avctx->pix_fmt = PIX_FMT_YUV420P; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
831 |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
832 dsputil_init(&l->dsp, avctx); |
2967 | 833 |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
834 l->last = av_malloc(4 * sizeof(int) * (avctx->width >> 2)); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
835 l->clast = av_malloc(4 * sizeof(int) * (avctx->width >> 2)); |
2967 | 836 |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
837 for(i = 0; i < TM2_NUM_STREAMS; i++) { |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
838 l->tokens[i] = NULL; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
839 l->tok_lens[i] = 0; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
840 } |
2967 | 841 |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
842 l->Y1 = av_malloc(sizeof(int) * avctx->width * avctx->height); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
843 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
|
844 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
|
845 l->Y2 = av_malloc(sizeof(int) * avctx->width * avctx->height); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
846 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
|
847 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
|
848 l->cur = 0; |
2967 | 849 |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
850 return 0; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
851 } |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
852 |
6517
48759bfbd073
Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents:
6258
diff
changeset
|
853 static av_cold int decode_end(AVCodecContext *avctx){ |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
854 TM2Context * const l = avctx->priv_data; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
855 int i; |
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 if(l->last) |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
858 av_free(l->last); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
859 if(l->clast) |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
860 av_free(l->clast); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
861 for(i = 0; i < TM2_NUM_STREAMS; i++) |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
862 if(l->tokens[i]) |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
863 av_free(l->tokens[i]); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
864 if(l->Y1){ |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
865 av_free(l->Y1); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
866 av_free(l->U1); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
867 av_free(l->V1); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
868 av_free(l->Y2); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
869 av_free(l->U2); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
870 av_free(l->V2); |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
871 } |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
872 return 0; |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
873 } |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
874 |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
875 AVCodec truemotion2_decoder = { |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
876 "truemotion2", |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
877 CODEC_TYPE_VIDEO, |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
878 CODEC_ID_TRUEMOTION2, |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
879 sizeof(TM2Context), |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
880 decode_init, |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
881 NULL, |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
882 decode_end, |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
883 decode_frame, |
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
884 CODEC_CAP_DR1, |
7040
e943e1409077
Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents:
6750
diff
changeset
|
885 .long_name = NULL_IF_CONFIG_SMALL("Duck TrueMotion 2.0"), |
2906
e578b3572987
Duck TrueMotion 2 video decoder, courtesy of Konstantin Shishkov
melanson
parents:
diff
changeset
|
886 }; |