FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
truemotion2.c
Go to the documentation of this file.
1 /*
2  * Duck/ON2 TrueMotion 2 Decoder
3  * Copyright (c) 2005 Konstantin Shishkov
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 /**
23  * @file
24  * Duck TrueMotion2 decoder.
25  */
26 
27 #include <inttypes.h>
28 
29 #include "avcodec.h"
30 #include "bswapdsp.h"
31 #include "bytestream.h"
32 #include "get_bits.h"
33 #include "internal.h"
34 
35 #define TM2_ESCAPE 0x80000000
36 #define TM2_DELTAS 64
37 
38 /* Huffman-coded streams of different types of blocks */
40  TM2_C_HI = 0,
48 };
49 
50 /* Block types */
51 enum TM2_BLOCKS {
59 };
60 
61 typedef struct TM2Context {
64 
66  int error;
68 
71 
72  /* TM2 streams */
77  /* for blocks decoding */
78  int D[4];
79  int CD[4];
80  int *last;
81  int *clast;
82 
83  /* data for current and previous frame */
85  int *Y1, *U1, *V1, *Y2, *U2, *V2;
87  int cur;
88 } TM2Context;
89 
90 /**
91 * Huffman codes for each of streams
92 */
93 typedef struct TM2Codes {
94  VLC vlc; ///< table for FFmpeg bitstream reader
95  int bits;
96  int *recode; ///< table for converting from code indexes to values
97  int length;
98 } TM2Codes;
99 
100 /**
101 * structure for gathering Huffman codes information
102 */
103 typedef struct TM2Huff {
104  int val_bits; ///< length of literal
105  int max_bits; ///< maximum length of code
106  int min_bits; ///< minimum length of code
107  int nodes; ///< total number of nodes in tree
108  int num; ///< current number filled
109  int max_num; ///< total number of codes
110  int *nums; ///< literals
111  uint32_t *bits; ///< codes
112  int *lens; ///< codelengths
113 } TM2Huff;
114 
115 static int tm2_read_tree(TM2Context *ctx, uint32_t prefix, int length, TM2Huff *huff)
116 {
117  int ret;
118  if (length > huff->max_bits) {
119  av_log(ctx->avctx, AV_LOG_ERROR, "Tree exceeded its given depth (%i)\n",
120  huff->max_bits);
121  return AVERROR_INVALIDDATA;
122  }
123 
124  if (!get_bits1(&ctx->gb)) { /* literal */
125  if (length == 0) {
126  length = 1;
127  }
128  if (huff->num >= huff->max_num) {
129  av_log(ctx->avctx, AV_LOG_DEBUG, "Too many literals\n");
130  return AVERROR_INVALIDDATA;
131  }
132  huff->nums[huff->num] = get_bits_long(&ctx->gb, huff->val_bits);
133  huff->bits[huff->num] = prefix;
134  huff->lens[huff->num] = length;
135  huff->num++;
136  return 0;
137  } else { /* non-terminal node */
138  if ((ret = tm2_read_tree(ctx, prefix << 1, length + 1, huff)) < 0)
139  return ret;
140  if ((ret = tm2_read_tree(ctx, (prefix << 1) | 1, length + 1, huff)) < 0)
141  return ret;
142  }
143  return 0;
144 }
145 
147 {
148  TM2Huff huff;
149  int res = 0;
150 
151  huff.val_bits = get_bits(&ctx->gb, 5);
152  huff.max_bits = get_bits(&ctx->gb, 5);
153  huff.min_bits = get_bits(&ctx->gb, 5);
154  huff.nodes = get_bits_long(&ctx->gb, 17);
155  huff.num = 0;
156 
157  /* check for correct codes parameters */
158  if ((huff.val_bits < 1) || (huff.val_bits > 32) ||
159  (huff.max_bits < 0) || (huff.max_bits > 25)) {
160  av_log(ctx->avctx, AV_LOG_ERROR, "Incorrect tree parameters - literal "
161  "length: %i, max code length: %i\n", huff.val_bits, huff.max_bits);
162  return AVERROR_INVALIDDATA;
163  }
164  if ((huff.nodes <= 0) || (huff.nodes > 0x10000)) {
165  av_log(ctx->avctx, AV_LOG_ERROR, "Incorrect number of Huffman tree "
166  "nodes: %i\n", huff.nodes);
167  return AVERROR_INVALIDDATA;
168  }
169  /* one-node tree */
170  if (huff.max_bits == 0)
171  huff.max_bits = 1;
172 
173  /* allocate space for codes - it is exactly ceil(nodes / 2) entries */
174  huff.max_num = (huff.nodes + 1) >> 1;
175  huff.nums = av_calloc(huff.max_num, sizeof(int));
176  huff.bits = av_calloc(huff.max_num, sizeof(uint32_t));
177  huff.lens = av_calloc(huff.max_num, sizeof(int));
178 
179  if (!huff.nums || !huff.bits || !huff.lens) {
180  res = AVERROR(ENOMEM);
181  goto out;
182  }
183 
184  res = tm2_read_tree(ctx, 0, 0, &huff);
185 
186  if (huff.num != huff.max_num) {
187  av_log(ctx->avctx, AV_LOG_ERROR, "Got less codes than expected: %i of %i\n",
188  huff.num, huff.max_num);
189  res = AVERROR_INVALIDDATA;
190  }
191 
192  /* convert codes to vlc_table */
193  if (res >= 0) {
194  int i;
195 
196  res = init_vlc(&code->vlc, huff.max_bits, huff.max_num,
197  huff.lens, sizeof(int), sizeof(int),
198  huff.bits, sizeof(uint32_t), sizeof(uint32_t), 0);
199  if (res < 0)
200  av_log(ctx->avctx, AV_LOG_ERROR, "Cannot build VLC table\n");
201  else {
202  code->bits = huff.max_bits;
203  code->length = huff.max_num;
204  code->recode = av_malloc_array(code->length, sizeof(int));
205  if (!code->recode) {
206  res = AVERROR(ENOMEM);
207  goto out;
208  }
209  for (i = 0; i < code->length; i++)
210  code->recode[i] = huff.nums[i];
211  }
212  }
213 
214 out:
215  /* free allocated memory */
216  av_free(huff.nums);
217  av_free(huff.bits);
218  av_free(huff.lens);
219 
220  return res;
221 }
222 
223 static void tm2_free_codes(TM2Codes *code)
224 {
225  av_free(code->recode);
226  if (code->vlc.table)
227  ff_free_vlc(&code->vlc);
228 }
229 
230 static inline int tm2_get_token(GetBitContext *gb, TM2Codes *code)
231 {
232  int val;
233  val = get_vlc2(gb, code->vlc.table, code->bits, 1);
234  if(val<0)
235  return -1;
236  return code->recode[val];
237 }
238 
239 #define TM2_OLD_HEADER_MAGIC 0x00000100
240 #define TM2_NEW_HEADER_MAGIC 0x00000101
241 
242 static inline int tm2_read_header(TM2Context *ctx, const uint8_t *buf)
243 {
244  uint32_t magic = AV_RL32(buf);
245 
246  switch (magic) {
248  avpriv_request_sample(ctx->avctx, "Old TM2 header");
249  return 0;
251  return 0;
252  default:
253  av_log(ctx->avctx, AV_LOG_ERROR, "Not a TM2 header: 0x%08"PRIX32"\n",
254  magic);
255  return AVERROR_INVALIDDATA;
256  }
257 }
258 
259 static int tm2_read_deltas(TM2Context *ctx, int stream_id)
260 {
261  int d, mb;
262  int i, v;
263 
264  d = get_bits(&ctx->gb, 9);
265  mb = get_bits(&ctx->gb, 5);
266 
267  av_assert2(mb < 32);
268  if ((d < 1) || (d > TM2_DELTAS) || (mb < 1)) {
269  av_log(ctx->avctx, AV_LOG_ERROR, "Incorrect delta table: %i deltas x %i bits\n", d, mb);
270  return AVERROR_INVALIDDATA;
271  }
272 
273  for (i = 0; i < d; i++) {
274  v = get_bits_long(&ctx->gb, mb);
275  if (v & (1 << (mb - 1)))
276  ctx->deltas[stream_id][i] = v - (1U << mb);
277  else
278  ctx->deltas[stream_id][i] = v;
279  }
280  for (; i < TM2_DELTAS; i++)
281  ctx->deltas[stream_id][i] = 0;
282 
283  return 0;
284 }
285 
286 static int tm2_read_stream(TM2Context *ctx, const uint8_t *buf, int stream_id, int buf_size)
287 {
288  int i, ret;
289  int skip = 0;
290  int len, toks, pos;
291  TM2Codes codes;
292  GetByteContext gb;
293 
294  if (buf_size < 4) {
295  av_log(ctx->avctx, AV_LOG_ERROR, "not enough space for len left\n");
296  return AVERROR_INVALIDDATA;
297  }
298 
299  /* get stream length in dwords */
300  bytestream2_init(&gb, buf, buf_size);
301  len = bytestream2_get_be32(&gb);
302 
303  if (len == 0)
304  return 4;
305 
306  if (len >= INT_MAX / 4 - 1 || len < 0 || len * 4 + 4 > buf_size) {
307  av_log(ctx->avctx, AV_LOG_ERROR, "Error, invalid stream size.\n");
308  return AVERROR_INVALIDDATA;
309  }
310  skip = len * 4 + 4;
311 
312  toks = bytestream2_get_be32(&gb);
313  if (toks & 1) {
314  len = bytestream2_get_be32(&gb);
315  if (len == TM2_ESCAPE) {
316  len = bytestream2_get_be32(&gb);
317  }
318  if (len > 0) {
319  pos = bytestream2_tell(&gb);
320  if (skip <= pos)
321  return AVERROR_INVALIDDATA;
322  init_get_bits(&ctx->gb, buf + pos, (skip - pos) * 8);
323  if ((ret = tm2_read_deltas(ctx, stream_id)) < 0)
324  return ret;
325  bytestream2_skip(&gb, ((get_bits_count(&ctx->gb) + 31) >> 5) << 2);
326  }
327  }
328  /* skip unused fields */
329  len = bytestream2_get_be32(&gb);
330  if (len == TM2_ESCAPE) { /* some unknown length - could be escaped too */
331  bytestream2_skip(&gb, 8); /* unused by decoder */
332  } else {
333  bytestream2_skip(&gb, 4); /* unused by decoder */
334  }
335 
336  pos = bytestream2_tell(&gb);
337  if (skip <= pos)
338  return AVERROR_INVALIDDATA;
339  init_get_bits(&ctx->gb, buf + pos, (skip - pos) * 8);
340  if ((ret = tm2_build_huff_table(ctx, &codes)) < 0)
341  return ret;
342  bytestream2_skip(&gb, ((get_bits_count(&ctx->gb) + 31) >> 5) << 2);
343 
344  toks >>= 1;
345  /* check if we have sane number of tokens */
346  if ((toks < 0) || (toks > 0xFFFFFF)) {
347  av_log(ctx->avctx, AV_LOG_ERROR, "Incorrect number of tokens: %i\n", toks);
348  ret = AVERROR_INVALIDDATA;
349  goto end;
350  }
351  ret = av_reallocp_array(&ctx->tokens[stream_id], toks, sizeof(int));
352  if (ret < 0) {
353  ctx->tok_lens[stream_id] = 0;
354  goto end;
355  }
356  ctx->tok_lens[stream_id] = toks;
357  len = bytestream2_get_be32(&gb);
358  if (len > 0) {
359  pos = bytestream2_tell(&gb);
360  if (skip <= pos) {
361  ret = AVERROR_INVALIDDATA;
362  goto end;
363  }
364  init_get_bits(&ctx->gb, buf + pos, (skip - pos) * 8);
365  for (i = 0; i < toks; i++) {
366  if (get_bits_left(&ctx->gb) <= 0) {
367  av_log(ctx->avctx, AV_LOG_ERROR, "Incorrect number of tokens: %i\n", toks);
368  ret = AVERROR_INVALIDDATA;
369  goto end;
370  }
371  ctx->tokens[stream_id][i] = tm2_get_token(&ctx->gb, &codes);
372  if (stream_id <= TM2_MOT && ctx->tokens[stream_id][i] >= TM2_DELTAS || ctx->tokens[stream_id][i]<0) {
373  av_log(ctx->avctx, AV_LOG_ERROR, "Invalid delta token index %d for type %d, n=%d\n",
374  ctx->tokens[stream_id][i], stream_id, i);
375  ret = AVERROR_INVALIDDATA;
376  goto end;
377  }
378  }
379  } else {
380  if (len < 0) {
381  ret = AVERROR_INVALIDDATA;
382  goto end;
383  }
384  for (i = 0; i < toks; i++) {
385  ctx->tokens[stream_id][i] = codes.recode[0];
386  if (stream_id <= TM2_MOT && ctx->tokens[stream_id][i] >= TM2_DELTAS) {
387  av_log(ctx->avctx, AV_LOG_ERROR, "Invalid delta token index %d for type %d, n=%d\n",
388  ctx->tokens[stream_id][i], stream_id, i);
389  ret = AVERROR_INVALIDDATA;
390  goto end;
391  }
392  }
393  }
394 
395  ret = skip;
396 
397 end:
398  tm2_free_codes(&codes);
399  return ret;
400 }
401 
402 static inline int GET_TOK(TM2Context *ctx,int type)
403 {
404  if (ctx->tok_ptrs[type] >= ctx->tok_lens[type]) {
405  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]);
406  ctx->error = 1;
407  return 0;
408  }
409  if (type <= TM2_MOT) {
410  if (ctx->tokens[type][ctx->tok_ptrs[type]] >= TM2_DELTAS) {
411  av_log(ctx->avctx, AV_LOG_ERROR, "token %d is too large\n", ctx->tokens[type][ctx->tok_ptrs[type]]);
412  return 0;
413  }
414  return ctx->deltas[type][ctx->tokens[type][ctx->tok_ptrs[type]++]];
415  }
416  return ctx->tokens[type][ctx->tok_ptrs[type]++];
417 }
418 
419 /* blocks decoding routines */
420 
421 /* common Y, U, V pointers initialisation */
422 #define TM2_INIT_POINTERS() \
423  int *last, *clast; \
424  int *Y, *U, *V;\
425  int Ystride, Ustride, Vstride;\
426 \
427  Ystride = ctx->y_stride;\
428  Vstride = ctx->uv_stride;\
429  Ustride = ctx->uv_stride;\
430  Y = (ctx->cur?ctx->Y2:ctx->Y1) + by * 4 * Ystride + bx * 4;\
431  V = (ctx->cur?ctx->V2:ctx->V1) + by * 2 * Vstride + bx * 2;\
432  U = (ctx->cur?ctx->U2:ctx->U1) + by * 2 * Ustride + bx * 2;\
433  last = ctx->last + bx * 4;\
434  clast = ctx->clast + bx * 4;
435 
436 #define TM2_INIT_POINTERS_2() \
437  int *Yo, *Uo, *Vo;\
438  int oYstride, oUstride, oVstride;\
439 \
440  TM2_INIT_POINTERS();\
441  oYstride = Ystride;\
442  oVstride = Vstride;\
443  oUstride = Ustride;\
444  Yo = (ctx->cur?ctx->Y1:ctx->Y2) + by * 4 * oYstride + bx * 4;\
445  Vo = (ctx->cur?ctx->V1:ctx->V2) + by * 2 * oVstride + bx * 2;\
446  Uo = (ctx->cur?ctx->U1:ctx->U2) + by * 2 * oUstride + bx * 2;
447 
448 /* recalculate last and delta values for next blocks */
449 #define TM2_RECALC_BLOCK(CHR, stride, last, CD) {\
450  CD[0] = (unsigned)CHR[ 1] - (unsigned)last[1];\
451  CD[1] = (unsigned)CHR[stride + 1] - (unsigned) CHR[1];\
452  last[0] = (int)CHR[stride + 0];\
453  last[1] = (int)CHR[stride + 1];}
454 
455 /* common operations - add deltas to 4x4 block of luma or 2x2 blocks of chroma */
456 static inline void tm2_apply_deltas(TM2Context *ctx, int* Y, int stride, int *deltas, int *last)
457 {
458  unsigned ct, d;
459  int i, j;
460 
461  for (j = 0; j < 4; j++){
462  ct = ctx->D[j];
463  for (i = 0; i < 4; i++){
464  d = deltas[i + j * 4];
465  ct += d;
466  last[i] += ct;
467  Y[i] = av_clip_uint8(last[i]);
468  }
469  Y += stride;
470  ctx->D[j] = ct;
471  }
472 }
473 
474 static inline void tm2_high_chroma(int *data, int stride, int *last, unsigned *CD, int *deltas)
475 {
476  int i, j;
477  for (j = 0; j < 2; j++) {
478  for (i = 0; i < 2; i++) {
479  CD[j] += deltas[i + j * 2];
480  last[i] += CD[j];
481  data[i] = last[i];
482  }
483  data += stride;
484  }
485 }
486 
487 static inline void tm2_low_chroma(int *data, int stride, int *clast, int *CD, int *deltas, int bx)
488 {
489  int t;
490  int l;
491  int prev;
492 
493  if (bx > 0)
494  prev = clast[-3];
495  else
496  prev = 0;
497  t = (CD[0] + CD[1]) >> 1;
498  l = (prev - CD[0] - CD[1] + clast[1]) >> 1;
499  CD[1] = CD[0] + CD[1] - t;
500  CD[0] = t;
501  clast[0] = l;
502 
503  tm2_high_chroma(data, stride, clast, CD, deltas);
504 }
505 
506 static inline void tm2_hi_res_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
507 {
508  int i;
509  int deltas[16];
511 
512  /* hi-res chroma */
513  for (i = 0; i < 4; i++) {
514  deltas[i] = GET_TOK(ctx, TM2_C_HI);
515  deltas[i + 4] = GET_TOK(ctx, TM2_C_HI);
516  }
517  tm2_high_chroma(U, Ustride, clast, ctx->CD, deltas);
518  tm2_high_chroma(V, Vstride, clast + 2, ctx->CD + 2, deltas + 4);
519 
520  /* hi-res luma */
521  for (i = 0; i < 16; i++)
522  deltas[i] = GET_TOK(ctx, TM2_L_HI);
523 
524  tm2_apply_deltas(ctx, Y, Ystride, deltas, last);
525 }
526 
527 static inline void tm2_med_res_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
528 {
529  int i;
530  int deltas[16];
532 
533  /* low-res chroma */
534  deltas[0] = GET_TOK(ctx, TM2_C_LO);
535  deltas[1] = deltas[2] = deltas[3] = 0;
536  tm2_low_chroma(U, Ustride, clast, ctx->CD, deltas, bx);
537 
538  deltas[0] = GET_TOK(ctx, TM2_C_LO);
539  deltas[1] = deltas[2] = deltas[3] = 0;
540  tm2_low_chroma(V, Vstride, clast + 2, ctx->CD + 2, deltas, bx);
541 
542  /* hi-res luma */
543  for (i = 0; i < 16; i++)
544  deltas[i] = GET_TOK(ctx, TM2_L_HI);
545 
546  tm2_apply_deltas(ctx, Y, Ystride, deltas, last);
547 }
548 
549 static inline void tm2_low_res_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
550 {
551  int i;
552  int t1, t2;
553  int deltas[16];
555 
556  /* low-res chroma */
557  deltas[0] = GET_TOK(ctx, TM2_C_LO);
558  deltas[1] = deltas[2] = deltas[3] = 0;
559  tm2_low_chroma(U, Ustride, clast, ctx->CD, deltas, bx);
560 
561  deltas[0] = GET_TOK(ctx, TM2_C_LO);
562  deltas[1] = deltas[2] = deltas[3] = 0;
563  tm2_low_chroma(V, Vstride, clast + 2, ctx->CD + 2, deltas, bx);
564 
565  /* low-res luma */
566  for (i = 0; i < 16; i++)
567  deltas[i] = 0;
568 
569  deltas[ 0] = GET_TOK(ctx, TM2_L_LO);
570  deltas[ 2] = GET_TOK(ctx, TM2_L_LO);
571  deltas[ 8] = GET_TOK(ctx, TM2_L_LO);
572  deltas[10] = GET_TOK(ctx, TM2_L_LO);
573 
574  if (bx > 0)
575  last[0] = (last[-1] - ctx->D[0] - ctx->D[1] - ctx->D[2] - ctx->D[3] + last[1]) >> 1;
576  else
577  last[0] = (last[1] - ctx->D[0] - ctx->D[1] - ctx->D[2] - ctx->D[3])>> 1;
578  last[2] = (last[1] + last[3]) >> 1;
579 
580  t1 = ctx->D[0] + ctx->D[1];
581  ctx->D[0] = t1 >> 1;
582  ctx->D[1] = t1 - (t1 >> 1);
583  t2 = ctx->D[2] + ctx->D[3];
584  ctx->D[2] = t2 >> 1;
585  ctx->D[3] = t2 - (t2 >> 1);
586 
587  tm2_apply_deltas(ctx, Y, Ystride, deltas, last);
588 }
589 
590 static inline void tm2_null_res_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
591 {
592  int i;
593  int ct;
594  int left, right, diff;
595  int deltas[16];
597 
598  /* null chroma */
599  deltas[0] = deltas[1] = deltas[2] = deltas[3] = 0;
600  tm2_low_chroma(U, Ustride, clast, ctx->CD, deltas, bx);
601 
602  deltas[0] = deltas[1] = deltas[2] = deltas[3] = 0;
603  tm2_low_chroma(V, Vstride, clast + 2, ctx->CD + 2, deltas, bx);
604 
605  /* null luma */
606  for (i = 0; i < 16; i++)
607  deltas[i] = 0;
608 
609  ct = ctx->D[0] + ctx->D[1] + ctx->D[2] + ctx->D[3];
610 
611  if (bx > 0)
612  left = last[-1] - ct;
613  else
614  left = 0;
615 
616  right = last[3];
617  diff = right - left;
618  last[0] = left + (diff >> 2);
619  last[1] = left + (diff >> 1);
620  last[2] = right - (diff >> 2);
621  last[3] = right;
622  {
623  int tp = left;
624 
625  ctx->D[0] = (tp + (ct >> 2)) - left;
626  left += ctx->D[0];
627  ctx->D[1] = (tp + (ct >> 1)) - left;
628  left += ctx->D[1];
629  ctx->D[2] = ((tp + ct) - (ct >> 2)) - left;
630  left += ctx->D[2];
631  ctx->D[3] = (tp + ct) - left;
632  }
633  tm2_apply_deltas(ctx, Y, Ystride, deltas, last);
634 }
635 
636 static inline void tm2_still_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
637 {
638  int i, j;
640 
641  /* update chroma */
642  for (j = 0; j < 2; j++) {
643  for (i = 0; i < 2; i++){
644  U[i] = Uo[i];
645  V[i] = Vo[i];
646  }
647  U += Ustride; V += Vstride;
648  Uo += oUstride; Vo += oVstride;
649  }
650  U -= Ustride * 2;
651  V -= Vstride * 2;
652  TM2_RECALC_BLOCK(U, Ustride, clast, ctx->CD);
653  TM2_RECALC_BLOCK(V, Vstride, (clast + 2), (ctx->CD + 2));
654 
655  /* update deltas */
656  ctx->D[0] = Yo[3] - last[3];
657  ctx->D[1] = Yo[3 + oYstride] - Yo[3];
658  ctx->D[2] = Yo[3 + oYstride * 2] - Yo[3 + oYstride];
659  ctx->D[3] = Yo[3 + oYstride * 3] - Yo[3 + oYstride * 2];
660 
661  for (j = 0; j < 4; j++) {
662  for (i = 0; i < 4; i++) {
663  Y[i] = Yo[i];
664  last[i] = Yo[i];
665  }
666  Y += Ystride;
667  Yo += oYstride;
668  }
669 }
670 
671 static inline void tm2_update_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
672 {
673  int i, j;
674  int d;
676 
677  /* update chroma */
678  for (j = 0; j < 2; j++) {
679  for (i = 0; i < 2; i++) {
680  U[i] = Uo[i] + GET_TOK(ctx, TM2_UPD);
681  V[i] = Vo[i] + GET_TOK(ctx, TM2_UPD);
682  }
683  U += Ustride;
684  V += Vstride;
685  Uo += oUstride;
686  Vo += oVstride;
687  }
688  U -= Ustride * 2;
689  V -= Vstride * 2;
690  TM2_RECALC_BLOCK(U, Ustride, clast, ctx->CD);
691  TM2_RECALC_BLOCK(V, Vstride, (clast + 2), (ctx->CD + 2));
692 
693  /* update deltas */
694  ctx->D[0] = Yo[3] - last[3];
695  ctx->D[1] = Yo[3 + oYstride] - Yo[3];
696  ctx->D[2] = Yo[3 + oYstride * 2] - Yo[3 + oYstride];
697  ctx->D[3] = Yo[3 + oYstride * 3] - Yo[3 + oYstride * 2];
698 
699  for (j = 0; j < 4; j++) {
700  d = last[3];
701  for (i = 0; i < 4; i++) {
702  Y[i] = Yo[i] + GET_TOK(ctx, TM2_UPD);
703  last[i] = Y[i];
704  }
705  ctx->D[j] = last[3] - d;
706  Y += Ystride;
707  Yo += oYstride;
708  }
709 }
710 
711 static inline void tm2_motion_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
712 {
713  int i, j;
714  int mx, my;
716 
717  mx = GET_TOK(ctx, TM2_MOT);
718  my = GET_TOK(ctx, TM2_MOT);
719  mx = av_clip(mx, -(bx * 4 + 4), ctx->avctx->width - bx * 4);
720  my = av_clip(my, -(by * 4 + 4), ctx->avctx->height - by * 4);
721 
722  if (4*bx+mx<0 || 4*by+my<0 || 4*bx+mx+4 > ctx->avctx->width || 4*by+my+4 > ctx->avctx->height) {
723  av_log(ctx->avctx, AV_LOG_ERROR, "MV out of picture\n");
724  return;
725  }
726 
727  Yo += my * oYstride + mx;
728  Uo += (my >> 1) * oUstride + (mx >> 1);
729  Vo += (my >> 1) * oVstride + (mx >> 1);
730 
731  /* copy chroma */
732  for (j = 0; j < 2; j++) {
733  for (i = 0; i < 2; i++) {
734  U[i] = Uo[i];
735  V[i] = Vo[i];
736  }
737  U += Ustride;
738  V += Vstride;
739  Uo += oUstride;
740  Vo += oVstride;
741  }
742  U -= Ustride * 2;
743  V -= Vstride * 2;
744  TM2_RECALC_BLOCK(U, Ustride, clast, ctx->CD);
745  TM2_RECALC_BLOCK(V, Vstride, (clast + 2), (ctx->CD + 2));
746 
747  /* copy luma */
748  for (j = 0; j < 4; j++) {
749  for (i = 0; i < 4; i++) {
750  Y[i] = Yo[i];
751  }
752  Y += Ystride;
753  Yo += oYstride;
754  }
755  /* calculate deltas */
756  Y -= Ystride * 4;
757  ctx->D[0] = Y[3] - last[3];
758  ctx->D[1] = Y[3 + Ystride] - Y[3];
759  ctx->D[2] = Y[3 + Ystride * 2] - Y[3 + Ystride];
760  ctx->D[3] = Y[3 + Ystride * 3] - Y[3 + Ystride * 2];
761  for (i = 0; i < 4; i++)
762  last[i] = Y[i + Ystride * 3];
763 }
764 
766 {
767  int i, j;
768  int w = ctx->avctx->width, h = ctx->avctx->height, bw = w >> 2, bh = h >> 2, cw = w >> 1;
769  int type;
770  int keyframe = 1;
771  int *Y, *U, *V;
772  uint8_t *dst;
773 
774  for (i = 0; i < TM2_NUM_STREAMS; i++)
775  ctx->tok_ptrs[i] = 0;
776 
777  if (ctx->tok_lens[TM2_TYPE]<bw*bh) {
778  av_log(ctx->avctx,AV_LOG_ERROR,"Got %i tokens for %i blocks\n",ctx->tok_lens[TM2_TYPE],bw*bh);
779  return AVERROR_INVALIDDATA;
780  }
781 
782  memset(ctx->last, 0, 4 * bw * sizeof(int));
783  memset(ctx->clast, 0, 4 * bw * sizeof(int));
784 
785  for (j = 0; j < bh; j++) {
786  memset(ctx->D, 0, 4 * sizeof(int));
787  memset(ctx->CD, 0, 4 * sizeof(int));
788  for (i = 0; i < bw; i++) {
789  type = GET_TOK(ctx, TM2_TYPE);
790  switch(type) {
791  case TM2_HI_RES:
792  tm2_hi_res_block(ctx, p, i, j);
793  break;
794  case TM2_MED_RES:
795  tm2_med_res_block(ctx, p, i, j);
796  break;
797  case TM2_LOW_RES:
798  tm2_low_res_block(ctx, p, i, j);
799  break;
800  case TM2_NULL_RES:
801  tm2_null_res_block(ctx, p, i, j);
802  break;
803  case TM2_UPDATE:
804  tm2_update_block(ctx, p, i, j);
805  keyframe = 0;
806  break;
807  case TM2_STILL:
808  tm2_still_block(ctx, p, i, j);
809  keyframe = 0;
810  break;
811  case TM2_MOTION:
812  tm2_motion_block(ctx, p, i, j);
813  keyframe = 0;
814  break;
815  default:
816  av_log(ctx->avctx, AV_LOG_ERROR, "Skipping unknown block type %i\n", type);
817  }
818  if (ctx->error)
819  return AVERROR_INVALIDDATA;
820  }
821  }
822 
823  /* copy data from our buffer to AVFrame */
824  Y = (ctx->cur?ctx->Y2:ctx->Y1);
825  U = (ctx->cur?ctx->U2:ctx->U1);
826  V = (ctx->cur?ctx->V2:ctx->V1);
827  dst = p->data[0];
828  for (j = 0; j < h; j++) {
829  for (i = 0; i < w; i++) {
830  int y = Y[i], u = U[i >> 1], v = V[i >> 1];
831  dst[3*i+0] = av_clip_uint8(y + v);
832  dst[3*i+1] = av_clip_uint8(y);
833  dst[3*i+2] = av_clip_uint8(y + u);
834  }
835 
836  /* horizontal edge extension */
837  Y[-4] = Y[-3] = Y[-2] = Y[-1] = Y[0];
838  Y[w + 3] = Y[w + 2] = Y[w + 1] = Y[w] = Y[w - 1];
839 
840  /* vertical edge extension */
841  if (j == 0) {
842  memcpy(Y - 4 - 1 * ctx->y_stride, Y - 4, ctx->y_stride);
843  memcpy(Y - 4 - 2 * ctx->y_stride, Y - 4, ctx->y_stride);
844  memcpy(Y - 4 - 3 * ctx->y_stride, Y - 4, ctx->y_stride);
845  memcpy(Y - 4 - 4 * ctx->y_stride, Y - 4, ctx->y_stride);
846  } else if (j == h - 1) {
847  memcpy(Y - 4 + 1 * ctx->y_stride, Y - 4, ctx->y_stride);
848  memcpy(Y - 4 + 2 * ctx->y_stride, Y - 4, ctx->y_stride);
849  memcpy(Y - 4 + 3 * ctx->y_stride, Y - 4, ctx->y_stride);
850  memcpy(Y - 4 + 4 * ctx->y_stride, Y - 4, ctx->y_stride);
851  }
852 
853  Y += ctx->y_stride;
854  if (j & 1) {
855  /* horizontal edge extension */
856  U[-2] = U[-1] = U[0];
857  V[-2] = V[-1] = V[0];
858  U[cw + 1] = U[cw] = U[cw - 1];
859  V[cw + 1] = V[cw] = V[cw - 1];
860 
861  /* vertical edge extension */
862  if (j == 1) {
863  memcpy(U - 2 - 1 * ctx->uv_stride, U - 2, ctx->uv_stride);
864  memcpy(V - 2 - 1 * ctx->uv_stride, V - 2, ctx->uv_stride);
865  memcpy(U - 2 - 2 * ctx->uv_stride, U - 2, ctx->uv_stride);
866  memcpy(V - 2 - 2 * ctx->uv_stride, V - 2, ctx->uv_stride);
867  } else if (j == h - 1) {
868  memcpy(U - 2 + 1 * ctx->uv_stride, U - 2, ctx->uv_stride);
869  memcpy(V - 2 + 1 * ctx->uv_stride, V - 2, ctx->uv_stride);
870  memcpy(U - 2 + 2 * ctx->uv_stride, U - 2, ctx->uv_stride);
871  memcpy(V - 2 + 2 * ctx->uv_stride, V - 2, ctx->uv_stride);
872  }
873 
874  U += ctx->uv_stride;
875  V += ctx->uv_stride;
876  }
877  dst += p->linesize[0];
878  }
879 
880  return keyframe;
881 }
882 
883 static const int tm2_stream_order[TM2_NUM_STREAMS] = {
885 };
886 
887 #define TM2_HEADER_SIZE 40
888 
889 static int decode_frame(AVCodecContext *avctx,
890  void *data, int *got_frame,
891  AVPacket *avpkt)
892 {
893  TM2Context * const l = avctx->priv_data;
894  const uint8_t *buf = avpkt->data;
895  int buf_size = avpkt->size & ~3;
896  AVFrame * const p = l->pic;
897  int offset = TM2_HEADER_SIZE;
898  int i, t, ret;
899 
900  l->error = 0;
901 
902  av_fast_padded_malloc(&l->buffer, &l->buffer_size, buf_size);
903  if (!l->buffer) {
904  av_log(avctx, AV_LOG_ERROR, "Cannot allocate temporary buffer\n");
905  return AVERROR(ENOMEM);
906  }
907 
908  if ((ret = ff_reget_buffer(avctx, p)) < 0)
909  return ret;
910 
911  l->bdsp.bswap_buf((uint32_t *) l->buffer, (const uint32_t *) buf,
912  buf_size >> 2);
913 
914  if ((ret = tm2_read_header(l, l->buffer)) < 0) {
915  return ret;
916  }
917 
918  for (i = 0; i < TM2_NUM_STREAMS; i++) {
919  if (offset >= buf_size) {
920  av_log(avctx, AV_LOG_ERROR, "no space for tm2_read_stream\n");
921  return AVERROR_INVALIDDATA;
922  }
923 
924  t = tm2_read_stream(l, l->buffer + offset, tm2_stream_order[i],
925  buf_size - offset);
926  if (t < 0) {
927  int j = tm2_stream_order[i];
928  if (l->tok_lens[j])
929  memset(l->tokens[j], 0, sizeof(**l->tokens) * l->tok_lens[j]);
930  return t;
931  }
932  offset += t;
933  }
934  p->key_frame = tm2_decode_blocks(l, p);
935  if (p->key_frame)
937  else
939 
940  l->cur = !l->cur;
941  *got_frame = 1;
942  ret = av_frame_ref(data, l->pic);
943 
944  return (ret < 0) ? ret : buf_size;
945 }
946 
948 {
949  TM2Context * const l = avctx->priv_data;
950  int i, w = avctx->width, h = avctx->height;
951 
952  if ((avctx->width & 3) || (avctx->height & 3)) {
953  av_log(avctx, AV_LOG_ERROR, "Width and height must be multiple of 4\n");
954  return AVERROR(EINVAL);
955  }
956 
957  l->avctx = avctx;
958  avctx->pix_fmt = AV_PIX_FMT_BGR24;
959 
960  l->pic = av_frame_alloc();
961  if (!l->pic)
962  return AVERROR(ENOMEM);
963 
964  ff_bswapdsp_init(&l->bdsp);
965 
966  l->last = av_malloc_array(w >> 2, 4 * sizeof(*l->last) );
967  l->clast = av_malloc_array(w >> 2, 4 * sizeof(*l->clast));
968 
969  for (i = 0; i < TM2_NUM_STREAMS; i++) {
970  l->tokens[i] = NULL;
971  l->tok_lens[i] = 0;
972  }
973 
974  w += 8;
975  h += 8;
976  l->Y1_base = av_calloc(w * h, sizeof(*l->Y1_base));
977  l->Y2_base = av_calloc(w * h, sizeof(*l->Y2_base));
978  l->y_stride = w;
979  w = (w + 1) >> 1;
980  h = (h + 1) >> 1;
981  l->U1_base = av_calloc(w * h, sizeof(*l->U1_base));
982  l->V1_base = av_calloc(w * h, sizeof(*l->V1_base));
983  l->U2_base = av_calloc(w * h, sizeof(*l->U2_base));
984  l->V2_base = av_calloc(w * h, sizeof(*l->V1_base));
985  l->uv_stride = w;
986  l->cur = 0;
987  if (!l->Y1_base || !l->Y2_base || !l->U1_base ||
988  !l->V1_base || !l->U2_base || !l->V2_base ||
989  !l->last || !l->clast) {
990  av_freep(&l->Y1_base);
991  av_freep(&l->Y2_base);
992  av_freep(&l->U1_base);
993  av_freep(&l->U2_base);
994  av_freep(&l->V1_base);
995  av_freep(&l->V2_base);
996  av_freep(&l->last);
997  av_freep(&l->clast);
998  av_frame_free(&l->pic);
999  return AVERROR(ENOMEM);
1000  }
1001  l->Y1 = l->Y1_base + l->y_stride * 4 + 4;
1002  l->Y2 = l->Y2_base + l->y_stride * 4 + 4;
1003  l->U1 = l->U1_base + l->uv_stride * 2 + 2;
1004  l->U2 = l->U2_base + l->uv_stride * 2 + 2;
1005  l->V1 = l->V1_base + l->uv_stride * 2 + 2;
1006  l->V2 = l->V2_base + l->uv_stride * 2 + 2;
1007 
1008  return 0;
1009 }
1010 
1012 {
1013  TM2Context * const l = avctx->priv_data;
1014  int i;
1015 
1016  av_free(l->last);
1017  av_free(l->clast);
1018  for (i = 0; i < TM2_NUM_STREAMS; i++)
1019  av_freep(&l->tokens[i]);
1020  if (l->Y1) {
1021  av_freep(&l->Y1_base);
1022  av_freep(&l->U1_base);
1023  av_freep(&l->V1_base);
1024  av_freep(&l->Y2_base);
1025  av_freep(&l->U2_base);
1026  av_freep(&l->V2_base);
1027  }
1028  av_freep(&l->buffer);
1029  l->buffer_size = 0;
1030 
1031  av_frame_free(&l->pic);
1032 
1033  return 0;
1034 }
1035 
1037  .name = "truemotion2",
1038  .long_name = NULL_IF_CONFIG_SMALL("Duck TrueMotion 2.0"),
1039  .type = AVMEDIA_TYPE_VIDEO,
1041  .priv_data_size = sizeof(TM2Context),
1042  .init = decode_init,
1043  .close = decode_end,
1044  .decode = decode_frame,
1045  .capabilities = AV_CODEC_CAP_DR1,
1046 };
void(* bswap_buf)(uint32_t *dst, const uint32_t *src, int w)
Definition: bswapdsp.h:25
#define NULL
Definition: coverity.c:32
static void tm2_low_chroma(int *data, int stride, int *clast, int *CD, int *deltas, int bx)
Definition: truemotion2.c:487
const char const char void * val
Definition: avisynth_c.h:771
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
This structure describes decoded (raw) audio or video data.
Definition: frame.h:226
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
int * V2
Definition: truemotion2.c:85
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:381
int * U1_base
Definition: truemotion2.c:84
int D[4]
Definition: truemotion2.c:78
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
int * last
Definition: truemotion2.c:80
int * recode
table for converting from code indexes to values
Definition: truemotion2.c:96
int size
Definition: avcodec.h:1446
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1743
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
Definition: bytestream.h:133
void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
Same behaviour av_fast_malloc but the buffer has additional AV_INPUT_BUFFER_PADDING_SIZE at the end w...
Definition: utils.c:70
AVCodec ff_truemotion2_decoder
Definition: truemotion2.c:1036
AVCodec.
Definition: avcodec.h:3424
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
Definition: decode_audio.c:42
int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame)
Identical in function to av_frame_make_writable(), except it uses ff_get_buffer() to allocate the buf...
Definition: decode.c:1965
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
Definition: mem.c:244
int num
current number filled
Definition: truemotion2.c:108
static int tm2_read_header(TM2Context *ctx, const uint8_t *buf)
Definition: truemotion2.c:242
#define TM2_HEADER_SIZE
Definition: truemotion2.c:887
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
structure for gathering Huffman codes information
Definition: truemotion2.c:103
uint8_t
#define av_cold
Definition: attributes.h:82
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:189
#define mb
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition: avassert.h:64
TM2_STREAMS
Definition: truemotion2.c:39
static const int tm2_stream_order[TM2_NUM_STREAMS]
Definition: truemotion2.c:883
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:90
AVCodecContext * avctx
Definition: truemotion2.c:62
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
Definition: frame.c:443
int max_bits
maximum length of code
Definition: truemotion2.c:105
#define u(width, name, range_min, range_max)
Definition: cbs_h2645.c:253
static int tm2_read_deltas(TM2Context *ctx, int stream_id)
Definition: truemotion2.c:259
static void tm2_free_codes(TM2Codes *code)
Definition: truemotion2.c:223
uint8_t * data
Definition: avcodec.h:1445
int min_bits
minimum length of code
Definition: truemotion2.c:106
int * U2
Definition: truemotion2.c:85
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:219
static int tm2_read_tree(TM2Context *ctx, uint32_t prefix, int length, TM2Huff *huff)
Definition: truemotion2.c:115
VLC vlc
table for FFmpeg bitstream reader
Definition: truemotion2.c:94
bitstream reader API header.
static void tm2_hi_res_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
Definition: truemotion2.c:506
static int tm2_read_stream(TM2Context *ctx, const uint8_t *buf, int stream_id, int buf_size)
Definition: truemotion2.c:286
#define av_log(a,...)
static void tm2_update_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
Definition: truemotion2.c:671
#define U(x)
Definition: vp56_arith.h:37
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:814
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
int val_bits
length of literal
Definition: truemotion2.c:104
#define init_vlc(vlc, nb_bits, nb_codes,bits, bits_wrap, bits_size,codes, codes_wrap, codes_size,flags)
Definition: vlc.h:38
#define AVERROR(e)
Definition: error.h:43
static int tm2_build_huff_table(TM2Context *ctx, TM2Codes *code)
Definition: truemotion2.c:146
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
Definition: bytestream.h:164
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:202
static void tm2_low_res_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
Definition: truemotion2.c:549
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:186
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
static int tm2_decode_blocks(TM2Context *ctx, AVFrame *p)
Definition: truemotion2.c:765
int * tokens[TM2_NUM_STREAMS]
Definition: truemotion2.c:73
#define t1
Definition: regdef.h:29
GLsizei GLsizei * length
Definition: opengl_enc.c:115
const char * name
Name of the codec implementation.
Definition: avcodec.h:3431
int * clast
Definition: truemotion2.c:81
static const uint8_t offset[127][2]
Definition: vf_spp.c:92
Definition: vlc.h:26
int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
Definition: mem.c:205
AVFrame * pic
Definition: truemotion2.c:63
int * V1
Definition: truemotion2.c:85
int * V2_base
Definition: truemotion2.c:84
int max_num
total number of codes
Definition: truemotion2.c:109
int bits
Definition: truemotion2.c:95
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:309
#define Y
Definition: boxblur.h:38
static int GET_TOK(TM2Context *ctx, int type)
Definition: truemotion2.c:402
int width
picture width / height.
Definition: avcodec.h:1706
uint8_t w
Definition: llviddspenc.c:38
#define TM2_OLD_HEADER_MAGIC
Definition: truemotion2.c:239
AVFormatContext * ctx
Definition: movenc.c:48
int uv_stride
Definition: truemotion2.c:86
uint8_t * buffer
Definition: truemotion2.c:69
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE(*table)[2], int bits, int max_depth)
Parse a vlc code.
Definition: get_bits.h:762
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:69
static int tm2_get_token(GetBitContext *gb, TM2Codes *code)
Definition: truemotion2.c:230
int CD[4]
Definition: truemotion2.c:79
int * nums
literals
Definition: truemotion2.c:110
int nodes
total number of nodes in tree
Definition: truemotion2.c:107
static av_cold int decode_end(AVCodecContext *avctx)
Definition: truemotion2.c:1011
int * Y1
Definition: truemotion2.c:85
int * V1_base
Definition: truemotion2.c:84
static av_always_inline int bytestream2_tell(GetByteContext *g)
Definition: bytestream.h:188
Libavcodec external API header.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:257
#define TM2_INIT_POINTERS_2()
Definition: truemotion2.c:436
main external API structure.
Definition: avcodec.h:1533
static void tm2_still_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
Definition: truemotion2.c:636
#define TM2_DELTAS
Definition: truemotion2.c:36
void * buf
Definition: avisynth_c.h:690
GLint GLenum type
Definition: opengl_enc.c:105
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:487
#define TM2_INIT_POINTERS()
Definition: truemotion2.c:422
int * Y1_base
Definition: truemotion2.c:84
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:615
static void tm2_med_res_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
Definition: truemotion2.c:527
static void tm2_motion_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
Definition: truemotion2.c:711
uint32_t * bits
codes
Definition: truemotion2.c:111
int length
Definition: truemotion2.c:97
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
Definition: get_bits.h:531
static void tm2_apply_deltas(TM2Context *ctx, int *Y, int stride, int *deltas, int *last)
Definition: truemotion2.c:456
#define TM2_ESCAPE
Definition: truemotion2.c:35
#define TM2_RECALC_BLOCK(CHR, stride, last, CD)
Definition: truemotion2.c:449
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:240
int * U1
Definition: truemotion2.c:85
int * Y2
Definition: truemotion2.c:85
GLint GLenum GLboolean GLsizei stride
Definition: opengl_enc.c:105
common internal api header.
if(ret< 0)
Definition: vf_mcdeint.c:279
int y_stride
Definition: truemotion2.c:86
static void tm2_null_res_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
Definition: truemotion2.c:590
int deltas[TM2_NUM_STREAMS][TM2_DELTAS]
Definition: truemotion2.c:76
int * lens
codelengths
Definition: truemotion2.c:112
static av_cold int decode_init(AVCodecContext *avctx)
Definition: truemotion2.c:947
int * Y2_base
Definition: truemotion2.c:84
int buffer_size
Definition: truemotion2.c:70
static void tm2_high_chroma(int *data, int stride, int *last, unsigned *CD, int *deltas)
Definition: truemotion2.c:474
#define TM2_NEW_HEADER_MAGIC
Definition: truemotion2.c:240
av_cold void ff_bswapdsp_init(BswapDSPContext *c)
Definition: bswapdsp.c:49
void * priv_data
Definition: avcodec.h:1560
int * U2_base
Definition: truemotion2.c:84
TM2_BLOCKS
Definition: truemotion2.c:51
static av_always_inline int diff(const uint32_t a, const uint32_t b)
#define av_free(p)
GetBitContext gb
Definition: truemotion2.c:65
int len
VLC_TYPE(* table)[2]
code, bits
Definition: vlc.h:28
int tok_lens[TM2_NUM_STREAMS]
Definition: truemotion2.c:74
int key_frame
1 -> keyframe, 0-> not
Definition: frame.h:304
FILE * out
Definition: movenc.c:54
#define av_freep(p)
Huffman codes for each of streams.
Definition: truemotion2.c:93
#define av_malloc_array(a, b)
#define stride
int tok_ptrs[TM2_NUM_STREAMS]
Definition: truemotion2.c:75
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
Definition: bytestream.h:87
This structure stores compressed data.
Definition: avcodec.h:1422
void ff_free_vlc(VLC *vlc)
Definition: bitstream.c:354
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:968
BswapDSPContext bdsp
Definition: truemotion2.c:67
#define t2
Definition: regdef.h:30
Predicted.
Definition: avutil.h:275
#define V
Definition: avdct.c:30
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: truemotion2.c:889