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  for (i = 0; i < toks; i++) {
381  ctx->tokens[stream_id][i] = codes.recode[0];
382  if (stream_id <= TM2_MOT && ctx->tokens[stream_id][i] >= TM2_DELTAS) {
383  av_log(ctx->avctx, AV_LOG_ERROR, "Invalid delta token index %d for type %d, n=%d\n",
384  ctx->tokens[stream_id][i], stream_id, i);
385  ret = AVERROR_INVALIDDATA;
386  goto end;
387  }
388  }
389  }
390 
391  ret = skip;
392 
393 end:
394  tm2_free_codes(&codes);
395  return ret;
396 }
397 
398 static inline int GET_TOK(TM2Context *ctx,int type)
399 {
400  if (ctx->tok_ptrs[type] >= ctx->tok_lens[type]) {
401  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]);
402  ctx->error = 1;
403  return 0;
404  }
405  if (type <= TM2_MOT) {
406  if (ctx->tokens[type][ctx->tok_ptrs[type]] >= TM2_DELTAS) {
407  av_log(ctx->avctx, AV_LOG_ERROR, "token %d is too large\n", ctx->tokens[type][ctx->tok_ptrs[type]]);
408  return 0;
409  }
410  return ctx->deltas[type][ctx->tokens[type][ctx->tok_ptrs[type]++]];
411  }
412  return ctx->tokens[type][ctx->tok_ptrs[type]++];
413 }
414 
415 /* blocks decoding routines */
416 
417 /* common Y, U, V pointers initialisation */
418 #define TM2_INIT_POINTERS() \
419  int *last, *clast; \
420  int *Y, *U, *V;\
421  int Ystride, Ustride, Vstride;\
422 \
423  Ystride = ctx->y_stride;\
424  Vstride = ctx->uv_stride;\
425  Ustride = ctx->uv_stride;\
426  Y = (ctx->cur?ctx->Y2:ctx->Y1) + by * 4 * Ystride + bx * 4;\
427  V = (ctx->cur?ctx->V2:ctx->V1) + by * 2 * Vstride + bx * 2;\
428  U = (ctx->cur?ctx->U2:ctx->U1) + by * 2 * Ustride + bx * 2;\
429  last = ctx->last + bx * 4;\
430  clast = ctx->clast + bx * 4;
431 
432 #define TM2_INIT_POINTERS_2() \
433  int *Yo, *Uo, *Vo;\
434  int oYstride, oUstride, oVstride;\
435 \
436  TM2_INIT_POINTERS();\
437  oYstride = Ystride;\
438  oVstride = Vstride;\
439  oUstride = Ustride;\
440  Yo = (ctx->cur?ctx->Y1:ctx->Y2) + by * 4 * oYstride + bx * 4;\
441  Vo = (ctx->cur?ctx->V1:ctx->V2) + by * 2 * oVstride + bx * 2;\
442  Uo = (ctx->cur?ctx->U1:ctx->U2) + by * 2 * oUstride + bx * 2;
443 
444 /* recalculate last and delta values for next blocks */
445 #define TM2_RECALC_BLOCK(CHR, stride, last, CD) {\
446  CD[0] = (unsigned)CHR[ 1] - (unsigned)last[1];\
447  CD[1] = (unsigned)CHR[stride + 1] - (unsigned) CHR[1];\
448  last[0] = (int)CHR[stride + 0];\
449  last[1] = (int)CHR[stride + 1];}
450 
451 /* common operations - add deltas to 4x4 block of luma or 2x2 blocks of chroma */
452 static inline void tm2_apply_deltas(TM2Context *ctx, int* Y, int stride, int *deltas, int *last)
453 {
454  int ct, d;
455  int i, j;
456 
457  for (j = 0; j < 4; j++){
458  ct = ctx->D[j];
459  for (i = 0; i < 4; i++){
460  d = deltas[i + j * 4];
461  ct += d;
462  last[i] += ct;
463  Y[i] = av_clip_uint8(last[i]);
464  }
465  Y += stride;
466  ctx->D[j] = ct;
467  }
468 }
469 
470 static inline void tm2_high_chroma(int *data, int stride, int *last, unsigned *CD, int *deltas)
471 {
472  int i, j;
473  for (j = 0; j < 2; j++) {
474  for (i = 0; i < 2; i++) {
475  CD[j] += deltas[i + j * 2];
476  last[i] += CD[j];
477  data[i] = last[i];
478  }
479  data += stride;
480  }
481 }
482 
483 static inline void tm2_low_chroma(int *data, int stride, int *clast, int *CD, int *deltas, int bx)
484 {
485  int t;
486  int l;
487  int prev;
488 
489  if (bx > 0)
490  prev = clast[-3];
491  else
492  prev = 0;
493  t = (CD[0] + CD[1]) >> 1;
494  l = (prev - CD[0] - CD[1] + clast[1]) >> 1;
495  CD[1] = CD[0] + CD[1] - t;
496  CD[0] = t;
497  clast[0] = l;
498 
499  tm2_high_chroma(data, stride, clast, CD, deltas);
500 }
501 
502 static inline void tm2_hi_res_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
503 {
504  int i;
505  int deltas[16];
507 
508  /* hi-res chroma */
509  for (i = 0; i < 4; i++) {
510  deltas[i] = GET_TOK(ctx, TM2_C_HI);
511  deltas[i + 4] = GET_TOK(ctx, TM2_C_HI);
512  }
513  tm2_high_chroma(U, Ustride, clast, ctx->CD, deltas);
514  tm2_high_chroma(V, Vstride, clast + 2, ctx->CD + 2, deltas + 4);
515 
516  /* hi-res luma */
517  for (i = 0; i < 16; i++)
518  deltas[i] = GET_TOK(ctx, TM2_L_HI);
519 
520  tm2_apply_deltas(ctx, Y, Ystride, deltas, last);
521 }
522 
523 static inline void tm2_med_res_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
524 {
525  int i;
526  int deltas[16];
528 
529  /* low-res chroma */
530  deltas[0] = GET_TOK(ctx, TM2_C_LO);
531  deltas[1] = deltas[2] = deltas[3] = 0;
532  tm2_low_chroma(U, Ustride, clast, ctx->CD, deltas, bx);
533 
534  deltas[0] = GET_TOK(ctx, TM2_C_LO);
535  deltas[1] = deltas[2] = deltas[3] = 0;
536  tm2_low_chroma(V, Vstride, clast + 2, ctx->CD + 2, deltas, bx);
537 
538  /* hi-res luma */
539  for (i = 0; i < 16; i++)
540  deltas[i] = GET_TOK(ctx, TM2_L_HI);
541 
542  tm2_apply_deltas(ctx, Y, Ystride, deltas, last);
543 }
544 
545 static inline void tm2_low_res_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
546 {
547  int i;
548  int t1, t2;
549  int deltas[16];
551 
552  /* low-res chroma */
553  deltas[0] = GET_TOK(ctx, TM2_C_LO);
554  deltas[1] = deltas[2] = deltas[3] = 0;
555  tm2_low_chroma(U, Ustride, clast, ctx->CD, deltas, bx);
556 
557  deltas[0] = GET_TOK(ctx, TM2_C_LO);
558  deltas[1] = deltas[2] = deltas[3] = 0;
559  tm2_low_chroma(V, Vstride, clast + 2, ctx->CD + 2, deltas, bx);
560 
561  /* low-res luma */
562  for (i = 0; i < 16; i++)
563  deltas[i] = 0;
564 
565  deltas[ 0] = GET_TOK(ctx, TM2_L_LO);
566  deltas[ 2] = GET_TOK(ctx, TM2_L_LO);
567  deltas[ 8] = GET_TOK(ctx, TM2_L_LO);
568  deltas[10] = GET_TOK(ctx, TM2_L_LO);
569 
570  if (bx > 0)
571  last[0] = (last[-1] - ctx->D[0] - ctx->D[1] - ctx->D[2] - ctx->D[3] + last[1]) >> 1;
572  else
573  last[0] = (last[1] - ctx->D[0] - ctx->D[1] - ctx->D[2] - ctx->D[3])>> 1;
574  last[2] = (last[1] + last[3]) >> 1;
575 
576  t1 = ctx->D[0] + ctx->D[1];
577  ctx->D[0] = t1 >> 1;
578  ctx->D[1] = t1 - (t1 >> 1);
579  t2 = ctx->D[2] + ctx->D[3];
580  ctx->D[2] = t2 >> 1;
581  ctx->D[3] = t2 - (t2 >> 1);
582 
583  tm2_apply_deltas(ctx, Y, Ystride, deltas, last);
584 }
585 
586 static inline void tm2_null_res_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
587 {
588  int i;
589  int ct;
590  int left, right, diff;
591  int deltas[16];
593 
594  /* null chroma */
595  deltas[0] = deltas[1] = deltas[2] = deltas[3] = 0;
596  tm2_low_chroma(U, Ustride, clast, ctx->CD, deltas, bx);
597 
598  deltas[0] = deltas[1] = deltas[2] = deltas[3] = 0;
599  tm2_low_chroma(V, Vstride, clast + 2, ctx->CD + 2, deltas, bx);
600 
601  /* null luma */
602  for (i = 0; i < 16; i++)
603  deltas[i] = 0;
604 
605  ct = ctx->D[0] + ctx->D[1] + ctx->D[2] + ctx->D[3];
606 
607  if (bx > 0)
608  left = last[-1] - ct;
609  else
610  left = 0;
611 
612  right = last[3];
613  diff = right - left;
614  last[0] = left + (diff >> 2);
615  last[1] = left + (diff >> 1);
616  last[2] = right - (diff >> 2);
617  last[3] = right;
618  {
619  int tp = left;
620 
621  ctx->D[0] = (tp + (ct >> 2)) - left;
622  left += ctx->D[0];
623  ctx->D[1] = (tp + (ct >> 1)) - left;
624  left += ctx->D[1];
625  ctx->D[2] = ((tp + ct) - (ct >> 2)) - left;
626  left += ctx->D[2];
627  ctx->D[3] = (tp + ct) - left;
628  }
629  tm2_apply_deltas(ctx, Y, Ystride, deltas, last);
630 }
631 
632 static inline void tm2_still_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
633 {
634  int i, j;
636 
637  /* update chroma */
638  for (j = 0; j < 2; j++) {
639  for (i = 0; i < 2; i++){
640  U[i] = Uo[i];
641  V[i] = Vo[i];
642  }
643  U += Ustride; V += Vstride;
644  Uo += oUstride; Vo += oVstride;
645  }
646  U -= Ustride * 2;
647  V -= Vstride * 2;
648  TM2_RECALC_BLOCK(U, Ustride, clast, ctx->CD);
649  TM2_RECALC_BLOCK(V, Vstride, (clast + 2), (ctx->CD + 2));
650 
651  /* update deltas */
652  ctx->D[0] = Yo[3] - last[3];
653  ctx->D[1] = Yo[3 + oYstride] - Yo[3];
654  ctx->D[2] = Yo[3 + oYstride * 2] - Yo[3 + oYstride];
655  ctx->D[3] = Yo[3 + oYstride * 3] - Yo[3 + oYstride * 2];
656 
657  for (j = 0; j < 4; j++) {
658  for (i = 0; i < 4; i++) {
659  Y[i] = Yo[i];
660  last[i] = Yo[i];
661  }
662  Y += Ystride;
663  Yo += oYstride;
664  }
665 }
666 
667 static inline void tm2_update_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
668 {
669  int i, j;
670  int d;
672 
673  /* update chroma */
674  for (j = 0; j < 2; j++) {
675  for (i = 0; i < 2; i++) {
676  U[i] = Uo[i] + GET_TOK(ctx, TM2_UPD);
677  V[i] = Vo[i] + GET_TOK(ctx, TM2_UPD);
678  }
679  U += Ustride;
680  V += Vstride;
681  Uo += oUstride;
682  Vo += oVstride;
683  }
684  U -= Ustride * 2;
685  V -= Vstride * 2;
686  TM2_RECALC_BLOCK(U, Ustride, clast, ctx->CD);
687  TM2_RECALC_BLOCK(V, Vstride, (clast + 2), (ctx->CD + 2));
688 
689  /* update deltas */
690  ctx->D[0] = Yo[3] - last[3];
691  ctx->D[1] = Yo[3 + oYstride] - Yo[3];
692  ctx->D[2] = Yo[3 + oYstride * 2] - Yo[3 + oYstride];
693  ctx->D[3] = Yo[3 + oYstride * 3] - Yo[3 + oYstride * 2];
694 
695  for (j = 0; j < 4; j++) {
696  d = last[3];
697  for (i = 0; i < 4; i++) {
698  Y[i] = Yo[i] + GET_TOK(ctx, TM2_UPD);
699  last[i] = Y[i];
700  }
701  ctx->D[j] = last[3] - d;
702  Y += Ystride;
703  Yo += oYstride;
704  }
705 }
706 
707 static inline void tm2_motion_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
708 {
709  int i, j;
710  int mx, my;
712 
713  mx = GET_TOK(ctx, TM2_MOT);
714  my = GET_TOK(ctx, TM2_MOT);
715  mx = av_clip(mx, -(bx * 4 + 4), ctx->avctx->width - bx * 4);
716  my = av_clip(my, -(by * 4 + 4), ctx->avctx->height - by * 4);
717 
718  if (4*bx+mx<0 || 4*by+my<0 || 4*bx+mx+4 > ctx->avctx->width || 4*by+my+4 > ctx->avctx->height) {
719  av_log(ctx->avctx, AV_LOG_ERROR, "MV out of picture\n");
720  return;
721  }
722 
723  Yo += my * oYstride + mx;
724  Uo += (my >> 1) * oUstride + (mx >> 1);
725  Vo += (my >> 1) * oVstride + (mx >> 1);
726 
727  /* copy chroma */
728  for (j = 0; j < 2; j++) {
729  for (i = 0; i < 2; i++) {
730  U[i] = Uo[i];
731  V[i] = Vo[i];
732  }
733  U += Ustride;
734  V += Vstride;
735  Uo += oUstride;
736  Vo += oVstride;
737  }
738  U -= Ustride * 2;
739  V -= Vstride * 2;
740  TM2_RECALC_BLOCK(U, Ustride, clast, ctx->CD);
741  TM2_RECALC_BLOCK(V, Vstride, (clast + 2), (ctx->CD + 2));
742 
743  /* copy luma */
744  for (j = 0; j < 4; j++) {
745  for (i = 0; i < 4; i++) {
746  Y[i] = Yo[i];
747  }
748  Y += Ystride;
749  Yo += oYstride;
750  }
751  /* calculate deltas */
752  Y -= Ystride * 4;
753  ctx->D[0] = Y[3] - last[3];
754  ctx->D[1] = Y[3 + Ystride] - Y[3];
755  ctx->D[2] = Y[3 + Ystride * 2] - Y[3 + Ystride];
756  ctx->D[3] = Y[3 + Ystride * 3] - Y[3 + Ystride * 2];
757  for (i = 0; i < 4; i++)
758  last[i] = Y[i + Ystride * 3];
759 }
760 
762 {
763  int i, j;
764  int w = ctx->avctx->width, h = ctx->avctx->height, bw = w >> 2, bh = h >> 2, cw = w >> 1;
765  int type;
766  int keyframe = 1;
767  int *Y, *U, *V;
768  uint8_t *dst;
769 
770  for (i = 0; i < TM2_NUM_STREAMS; i++)
771  ctx->tok_ptrs[i] = 0;
772 
773  if (ctx->tok_lens[TM2_TYPE]<bw*bh) {
774  av_log(ctx->avctx,AV_LOG_ERROR,"Got %i tokens for %i blocks\n",ctx->tok_lens[TM2_TYPE],bw*bh);
775  return AVERROR_INVALIDDATA;
776  }
777 
778  memset(ctx->last, 0, 4 * bw * sizeof(int));
779  memset(ctx->clast, 0, 4 * bw * sizeof(int));
780 
781  for (j = 0; j < bh; j++) {
782  memset(ctx->D, 0, 4 * sizeof(int));
783  memset(ctx->CD, 0, 4 * sizeof(int));
784  for (i = 0; i < bw; i++) {
785  type = GET_TOK(ctx, TM2_TYPE);
786  switch(type) {
787  case TM2_HI_RES:
788  tm2_hi_res_block(ctx, p, i, j);
789  break;
790  case TM2_MED_RES:
791  tm2_med_res_block(ctx, p, i, j);
792  break;
793  case TM2_LOW_RES:
794  tm2_low_res_block(ctx, p, i, j);
795  break;
796  case TM2_NULL_RES:
797  tm2_null_res_block(ctx, p, i, j);
798  break;
799  case TM2_UPDATE:
800  tm2_update_block(ctx, p, i, j);
801  keyframe = 0;
802  break;
803  case TM2_STILL:
804  tm2_still_block(ctx, p, i, j);
805  keyframe = 0;
806  break;
807  case TM2_MOTION:
808  tm2_motion_block(ctx, p, i, j);
809  keyframe = 0;
810  break;
811  default:
812  av_log(ctx->avctx, AV_LOG_ERROR, "Skipping unknown block type %i\n", type);
813  }
814  if (ctx->error)
815  return AVERROR_INVALIDDATA;
816  }
817  }
818 
819  /* copy data from our buffer to AVFrame */
820  Y = (ctx->cur?ctx->Y2:ctx->Y1);
821  U = (ctx->cur?ctx->U2:ctx->U1);
822  V = (ctx->cur?ctx->V2:ctx->V1);
823  dst = p->data[0];
824  for (j = 0; j < h; j++) {
825  for (i = 0; i < w; i++) {
826  int y = Y[i], u = U[i >> 1], v = V[i >> 1];
827  dst[3*i+0] = av_clip_uint8(y + v);
828  dst[3*i+1] = av_clip_uint8(y);
829  dst[3*i+2] = av_clip_uint8(y + u);
830  }
831 
832  /* horizontal edge extension */
833  Y[-4] = Y[-3] = Y[-2] = Y[-1] = Y[0];
834  Y[w + 3] = Y[w + 2] = Y[w + 1] = Y[w] = Y[w - 1];
835 
836  /* vertical edge extension */
837  if (j == 0) {
838  memcpy(Y - 4 - 1 * ctx->y_stride, Y - 4, ctx->y_stride);
839  memcpy(Y - 4 - 2 * ctx->y_stride, Y - 4, ctx->y_stride);
840  memcpy(Y - 4 - 3 * ctx->y_stride, Y - 4, ctx->y_stride);
841  memcpy(Y - 4 - 4 * ctx->y_stride, Y - 4, ctx->y_stride);
842  } else if (j == h - 1) {
843  memcpy(Y - 4 + 1 * ctx->y_stride, Y - 4, ctx->y_stride);
844  memcpy(Y - 4 + 2 * ctx->y_stride, Y - 4, ctx->y_stride);
845  memcpy(Y - 4 + 3 * ctx->y_stride, Y - 4, ctx->y_stride);
846  memcpy(Y - 4 + 4 * ctx->y_stride, Y - 4, ctx->y_stride);
847  }
848 
849  Y += ctx->y_stride;
850  if (j & 1) {
851  /* horizontal edge extension */
852  U[-2] = U[-1] = U[0];
853  V[-2] = V[-1] = V[0];
854  U[cw + 1] = U[cw] = U[cw - 1];
855  V[cw + 1] = V[cw] = V[cw - 1];
856 
857  /* vertical edge extension */
858  if (j == 1) {
859  memcpy(U - 2 - 1 * ctx->uv_stride, U - 2, ctx->uv_stride);
860  memcpy(V - 2 - 1 * ctx->uv_stride, V - 2, ctx->uv_stride);
861  memcpy(U - 2 - 2 * ctx->uv_stride, U - 2, ctx->uv_stride);
862  memcpy(V - 2 - 2 * ctx->uv_stride, V - 2, ctx->uv_stride);
863  } else if (j == h - 1) {
864  memcpy(U - 2 + 1 * ctx->uv_stride, U - 2, ctx->uv_stride);
865  memcpy(V - 2 + 1 * ctx->uv_stride, V - 2, ctx->uv_stride);
866  memcpy(U - 2 + 2 * ctx->uv_stride, U - 2, ctx->uv_stride);
867  memcpy(V - 2 + 2 * ctx->uv_stride, V - 2, ctx->uv_stride);
868  }
869 
870  U += ctx->uv_stride;
871  V += ctx->uv_stride;
872  }
873  dst += p->linesize[0];
874  }
875 
876  return keyframe;
877 }
878 
879 static const int tm2_stream_order[TM2_NUM_STREAMS] = {
881 };
882 
883 #define TM2_HEADER_SIZE 40
884 
885 static int decode_frame(AVCodecContext *avctx,
886  void *data, int *got_frame,
887  AVPacket *avpkt)
888 {
889  TM2Context * const l = avctx->priv_data;
890  const uint8_t *buf = avpkt->data;
891  int buf_size = avpkt->size & ~3;
892  AVFrame * const p = l->pic;
893  int offset = TM2_HEADER_SIZE;
894  int i, t, ret;
895 
896  l->error = 0;
897 
898  av_fast_padded_malloc(&l->buffer, &l->buffer_size, buf_size);
899  if (!l->buffer) {
900  av_log(avctx, AV_LOG_ERROR, "Cannot allocate temporary buffer\n");
901  return AVERROR(ENOMEM);
902  }
903 
904  if ((ret = ff_reget_buffer(avctx, p)) < 0)
905  return ret;
906 
907  l->bdsp.bswap_buf((uint32_t *) l->buffer, (const uint32_t *) buf,
908  buf_size >> 2);
909 
910  if ((ret = tm2_read_header(l, l->buffer)) < 0) {
911  return ret;
912  }
913 
914  for (i = 0; i < TM2_NUM_STREAMS; i++) {
915  if (offset >= buf_size) {
916  av_log(avctx, AV_LOG_ERROR, "no space for tm2_read_stream\n");
917  return AVERROR_INVALIDDATA;
918  }
919 
920  t = tm2_read_stream(l, l->buffer + offset, tm2_stream_order[i],
921  buf_size - offset);
922  if (t < 0) {
923  int j = tm2_stream_order[i];
924  if (l->tok_lens[j])
925  memset(l->tokens[j], 0, sizeof(**l->tokens) * l->tok_lens[j]);
926  return t;
927  }
928  offset += t;
929  }
930  p->key_frame = tm2_decode_blocks(l, p);
931  if (p->key_frame)
933  else
935 
936  l->cur = !l->cur;
937  *got_frame = 1;
938  ret = av_frame_ref(data, l->pic);
939 
940  return (ret < 0) ? ret : buf_size;
941 }
942 
944 {
945  TM2Context * const l = avctx->priv_data;
946  int i, w = avctx->width, h = avctx->height;
947 
948  if ((avctx->width & 3) || (avctx->height & 3)) {
949  av_log(avctx, AV_LOG_ERROR, "Width and height must be multiple of 4\n");
950  return AVERROR(EINVAL);
951  }
952 
953  l->avctx = avctx;
954  avctx->pix_fmt = AV_PIX_FMT_BGR24;
955 
956  l->pic = av_frame_alloc();
957  if (!l->pic)
958  return AVERROR(ENOMEM);
959 
960  ff_bswapdsp_init(&l->bdsp);
961 
962  l->last = av_malloc_array(w >> 2, 4 * sizeof(*l->last) );
963  l->clast = av_malloc_array(w >> 2, 4 * sizeof(*l->clast));
964 
965  for (i = 0; i < TM2_NUM_STREAMS; i++) {
966  l->tokens[i] = NULL;
967  l->tok_lens[i] = 0;
968  }
969 
970  w += 8;
971  h += 8;
972  l->Y1_base = av_calloc(w * h, sizeof(*l->Y1_base));
973  l->Y2_base = av_calloc(w * h, sizeof(*l->Y2_base));
974  l->y_stride = w;
975  w = (w + 1) >> 1;
976  h = (h + 1) >> 1;
977  l->U1_base = av_calloc(w * h, sizeof(*l->U1_base));
978  l->V1_base = av_calloc(w * h, sizeof(*l->V1_base));
979  l->U2_base = av_calloc(w * h, sizeof(*l->U2_base));
980  l->V2_base = av_calloc(w * h, sizeof(*l->V1_base));
981  l->uv_stride = w;
982  l->cur = 0;
983  if (!l->Y1_base || !l->Y2_base || !l->U1_base ||
984  !l->V1_base || !l->U2_base || !l->V2_base ||
985  !l->last || !l->clast) {
986  av_freep(&l->Y1_base);
987  av_freep(&l->Y2_base);
988  av_freep(&l->U1_base);
989  av_freep(&l->U2_base);
990  av_freep(&l->V1_base);
991  av_freep(&l->V2_base);
992  av_freep(&l->last);
993  av_freep(&l->clast);
994  av_frame_free(&l->pic);
995  return AVERROR(ENOMEM);
996  }
997  l->Y1 = l->Y1_base + l->y_stride * 4 + 4;
998  l->Y2 = l->Y2_base + l->y_stride * 4 + 4;
999  l->U1 = l->U1_base + l->uv_stride * 2 + 2;
1000  l->U2 = l->U2_base + l->uv_stride * 2 + 2;
1001  l->V1 = l->V1_base + l->uv_stride * 2 + 2;
1002  l->V2 = l->V2_base + l->uv_stride * 2 + 2;
1003 
1004  return 0;
1005 }
1006 
1008 {
1009  TM2Context * const l = avctx->priv_data;
1010  int i;
1011 
1012  av_free(l->last);
1013  av_free(l->clast);
1014  for (i = 0; i < TM2_NUM_STREAMS; i++)
1015  av_freep(&l->tokens[i]);
1016  if (l->Y1) {
1017  av_freep(&l->Y1_base);
1018  av_freep(&l->U1_base);
1019  av_freep(&l->V1_base);
1020  av_freep(&l->Y2_base);
1021  av_freep(&l->U2_base);
1022  av_freep(&l->V2_base);
1023  }
1024  av_freep(&l->buffer);
1025  l->buffer_size = 0;
1026 
1027  av_frame_free(&l->pic);
1028 
1029  return 0;
1030 }
1031 
1033  .name = "truemotion2",
1034  .long_name = NULL_IF_CONFIG_SMALL("Duck TrueMotion 2.0"),
1035  .type = AVMEDIA_TYPE_VIDEO,
1037  .priv_data_size = sizeof(TM2Context),
1038  .init = decode_init,
1039  .close = decode_end,
1040  .decode = decode_frame,
1041  .capabilities = AV_CODEC_CAP_DR1,
1042 };
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:483
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:218
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:269
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:1431
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1727
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:1032
AVCodec.
Definition: avcodec.h:3408
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:1938
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:883
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
#define Y
Definition: vf_boxblur.c:76
TM2_STREAMS
Definition: truemotion2.c:39
static const int tm2_stream_order[TM2_NUM_STREAMS]
Definition: truemotion2.c:879
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:441
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:1430
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:200
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:502
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:667
#define U(x)
Definition: vp56_arith.h:37
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:596
#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:545
#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:761
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:3415
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:301
static int GET_TOK(TM2Context *ctx, int type)
Definition: truemotion2.c:398
int width
picture width / height.
Definition: avcodec.h:1690
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:563
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:65
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:1007
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:249
#define TM2_INIT_POINTERS_2()
Definition: truemotion2.c:432
main external API structure.
Definition: avcodec.h:1518
static void tm2_still_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
Definition: truemotion2.c:632
#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:321
#define TM2_INIT_POINTERS()
Definition: truemotion2.c:418
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:433
static void tm2_med_res_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
Definition: truemotion2.c:523
static void tm2_motion_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
Definition: truemotion2.c:707
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:354
static void tm2_apply_deltas(TM2Context *ctx, int *Y, int stride, int *deltas, int *last)
Definition: truemotion2.c:452
#define TM2_ESCAPE
Definition: truemotion2.c:35
#define TM2_RECALC_BLOCK(CHR, stride, last, CD)
Definition: truemotion2.c:445
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:232
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:586
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:943
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:470
#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:1545
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:296
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:1407
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:959
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:885