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 /**
116  *
117  * @returns the length of the longest code or an AVERROR code
118  */
119 static int tm2_read_tree(TM2Context *ctx, uint32_t prefix, int length, TM2Huff *huff)
120 {
121  int ret, ret2;
122  if (length > huff->max_bits) {
123  av_log(ctx->avctx, AV_LOG_ERROR, "Tree exceeded its given depth (%i)\n",
124  huff->max_bits);
125  return AVERROR_INVALIDDATA;
126  }
127 
128  if (!get_bits1(&ctx->gb)) { /* literal */
129  if (length == 0) {
130  length = 1;
131  }
132  if (huff->num >= huff->max_num) {
133  av_log(ctx->avctx, AV_LOG_DEBUG, "Too many literals\n");
134  return AVERROR_INVALIDDATA;
135  }
136  huff->nums[huff->num] = get_bits_long(&ctx->gb, huff->val_bits);
137  huff->bits[huff->num] = prefix;
138  huff->lens[huff->num] = length;
139  huff->num++;
140  return length;
141  } else { /* non-terminal node */
142  if ((ret2 = tm2_read_tree(ctx, prefix << 1, length + 1, huff)) < 0)
143  return ret2;
144  if ((ret = tm2_read_tree(ctx, (prefix << 1) | 1, length + 1, huff)) < 0)
145  return ret;
146  }
147  return FFMAX(ret, ret2);
148 }
149 
151 {
152  TM2Huff huff;
153  int res = 0;
154 
155  huff.val_bits = get_bits(&ctx->gb, 5);
156  huff.max_bits = get_bits(&ctx->gb, 5);
157  huff.min_bits = get_bits(&ctx->gb, 5);
158  huff.nodes = get_bits_long(&ctx->gb, 17);
159  huff.num = 0;
160 
161  /* check for correct codes parameters */
162  if ((huff.val_bits < 1) || (huff.val_bits > 32) ||
163  (huff.max_bits < 0) || (huff.max_bits > 25)) {
164  av_log(ctx->avctx, AV_LOG_ERROR, "Incorrect tree parameters - literal "
165  "length: %i, max code length: %i\n", huff.val_bits, huff.max_bits);
166  return AVERROR_INVALIDDATA;
167  }
168  if ((huff.nodes <= 0) || (huff.nodes > 0x10000)) {
169  av_log(ctx->avctx, AV_LOG_ERROR, "Incorrect number of Huffman tree "
170  "nodes: %i\n", huff.nodes);
171  return AVERROR_INVALIDDATA;
172  }
173  /* one-node tree */
174  if (huff.max_bits == 0)
175  huff.max_bits = 1;
176 
177  /* allocate space for codes - it is exactly ceil(nodes / 2) entries */
178  huff.max_num = (huff.nodes + 1) >> 1;
179  huff.nums = av_calloc(huff.max_num, sizeof(int));
180  huff.bits = av_calloc(huff.max_num, sizeof(uint32_t));
181  huff.lens = av_calloc(huff.max_num, sizeof(int));
182 
183  if (!huff.nums || !huff.bits || !huff.lens) {
184  res = AVERROR(ENOMEM);
185  goto out;
186  }
187 
188  res = tm2_read_tree(ctx, 0, 0, &huff);
189 
190  if (res >= 0 && res != huff.max_bits) {
191  av_log(ctx->avctx, AV_LOG_ERROR, "Got less bits than expected: %i of %i\n",
192  res, huff.max_bits);
193  res = AVERROR_INVALIDDATA;
194  }
195  if (huff.num != huff.max_num) {
196  av_log(ctx->avctx, AV_LOG_ERROR, "Got less codes than expected: %i of %i\n",
197  huff.num, huff.max_num);
198  res = AVERROR_INVALIDDATA;
199  }
200 
201  /* convert codes to vlc_table */
202  if (res >= 0) {
203  int i;
204 
205  res = init_vlc(&code->vlc, huff.max_bits, huff.max_num,
206  huff.lens, sizeof(int), sizeof(int),
207  huff.bits, sizeof(uint32_t), sizeof(uint32_t), 0);
208  if (res < 0)
209  av_log(ctx->avctx, AV_LOG_ERROR, "Cannot build VLC table\n");
210  else {
211  code->bits = huff.max_bits;
212  code->length = huff.max_num;
213  code->recode = av_malloc_array(code->length, sizeof(int));
214  if (!code->recode) {
215  res = AVERROR(ENOMEM);
216  goto out;
217  }
218  for (i = 0; i < code->length; i++)
219  code->recode[i] = huff.nums[i];
220  }
221  }
222 
223 out:
224  /* free allocated memory */
225  av_free(huff.nums);
226  av_free(huff.bits);
227  av_free(huff.lens);
228 
229  return res;
230 }
231 
232 static void tm2_free_codes(TM2Codes *code)
233 {
234  av_free(code->recode);
235  if (code->vlc.table)
236  ff_free_vlc(&code->vlc);
237 }
238 
239 static inline int tm2_get_token(GetBitContext *gb, TM2Codes *code)
240 {
241  int val;
242  val = get_vlc2(gb, code->vlc.table, code->bits, 1);
243  if(val<0)
244  return -1;
245  return code->recode[val];
246 }
247 
248 #define TM2_OLD_HEADER_MAGIC 0x00000100
249 #define TM2_NEW_HEADER_MAGIC 0x00000101
250 
251 static inline int tm2_read_header(TM2Context *ctx, const uint8_t *buf)
252 {
253  uint32_t magic = AV_RL32(buf);
254 
255  switch (magic) {
257  avpriv_request_sample(ctx->avctx, "Old TM2 header");
258  return 0;
260  return 0;
261  default:
262  av_log(ctx->avctx, AV_LOG_ERROR, "Not a TM2 header: 0x%08"PRIX32"\n",
263  magic);
264  return AVERROR_INVALIDDATA;
265  }
266 }
267 
268 static int tm2_read_deltas(TM2Context *ctx, int stream_id)
269 {
270  int d, mb;
271  int i, v;
272 
273  d = get_bits(&ctx->gb, 9);
274  mb = get_bits(&ctx->gb, 5);
275 
276  av_assert2(mb < 32);
277  if ((d < 1) || (d > TM2_DELTAS) || (mb < 1)) {
278  av_log(ctx->avctx, AV_LOG_ERROR, "Incorrect delta table: %i deltas x %i bits\n", d, mb);
279  return AVERROR_INVALIDDATA;
280  }
281 
282  for (i = 0; i < d; i++) {
283  v = get_bits_long(&ctx->gb, mb);
284  if (v & (1 << (mb - 1)))
285  ctx->deltas[stream_id][i] = v - (1U << mb);
286  else
287  ctx->deltas[stream_id][i] = v;
288  }
289  for (; i < TM2_DELTAS; i++)
290  ctx->deltas[stream_id][i] = 0;
291 
292  return 0;
293 }
294 
295 static int tm2_read_stream(TM2Context *ctx, const uint8_t *buf, int stream_id, int buf_size)
296 {
297  int i, ret;
298  int skip = 0;
299  int len, toks, pos;
300  TM2Codes codes;
301  GetByteContext gb;
302 
303  if (buf_size < 4) {
304  av_log(ctx->avctx, AV_LOG_ERROR, "not enough space for len left\n");
305  return AVERROR_INVALIDDATA;
306  }
307 
308  /* get stream length in dwords */
309  bytestream2_init(&gb, buf, buf_size);
310  len = bytestream2_get_be32(&gb);
311 
312  if (len == 0)
313  return 4;
314 
315  if (len >= INT_MAX / 4 - 1 || len < 0 || len * 4 + 4 > buf_size) {
316  av_log(ctx->avctx, AV_LOG_ERROR, "Error, invalid stream size.\n");
317  return AVERROR_INVALIDDATA;
318  }
319  skip = len * 4 + 4;
320 
321  toks = bytestream2_get_be32(&gb);
322  if (toks & 1) {
323  len = bytestream2_get_be32(&gb);
324  if (len == TM2_ESCAPE) {
325  len = bytestream2_get_be32(&gb);
326  }
327  if (len > 0) {
328  pos = bytestream2_tell(&gb);
329  if (skip <= pos)
330  return AVERROR_INVALIDDATA;
331  init_get_bits(&ctx->gb, buf + pos, (skip - pos) * 8);
332  if ((ret = tm2_read_deltas(ctx, stream_id)) < 0)
333  return ret;
334  bytestream2_skip(&gb, ((get_bits_count(&ctx->gb) + 31) >> 5) << 2);
335  }
336  }
337  /* skip unused fields */
338  len = bytestream2_get_be32(&gb);
339  if (len == TM2_ESCAPE) { /* some unknown length - could be escaped too */
340  bytestream2_skip(&gb, 8); /* unused by decoder */
341  } else {
342  bytestream2_skip(&gb, 4); /* unused by decoder */
343  }
344 
345  pos = bytestream2_tell(&gb);
346  if (skip <= pos)
347  return AVERROR_INVALIDDATA;
348  init_get_bits(&ctx->gb, buf + pos, (skip - pos) * 8);
349  if ((ret = tm2_build_huff_table(ctx, &codes)) < 0)
350  return ret;
351  bytestream2_skip(&gb, ((get_bits_count(&ctx->gb) + 31) >> 5) << 2);
352 
353  toks >>= 1;
354  /* check if we have sane number of tokens */
355  if ((toks < 0) || (toks > 0xFFFFFF)) {
356  av_log(ctx->avctx, AV_LOG_ERROR, "Incorrect number of tokens: %i\n", toks);
357  ret = AVERROR_INVALIDDATA;
358  goto end;
359  }
360  ret = av_reallocp_array(&ctx->tokens[stream_id], toks, sizeof(int));
361  if (ret < 0) {
362  ctx->tok_lens[stream_id] = 0;
363  goto end;
364  }
365  ctx->tok_lens[stream_id] = toks;
366  len = bytestream2_get_be32(&gb);
367  if (len > 0) {
368  pos = bytestream2_tell(&gb);
369  if (skip <= pos) {
370  ret = AVERROR_INVALIDDATA;
371  goto end;
372  }
373  init_get_bits(&ctx->gb, buf + pos, (skip - pos) * 8);
374  for (i = 0; i < toks; i++) {
375  if (get_bits_left(&ctx->gb) <= 0) {
376  av_log(ctx->avctx, AV_LOG_ERROR, "Incorrect number of tokens: %i\n", toks);
377  ret = AVERROR_INVALIDDATA;
378  goto end;
379  }
380  ctx->tokens[stream_id][i] = tm2_get_token(&ctx->gb, &codes);
381  if (stream_id <= TM2_MOT && ctx->tokens[stream_id][i] >= TM2_DELTAS || ctx->tokens[stream_id][i]<0) {
382  av_log(ctx->avctx, AV_LOG_ERROR, "Invalid delta token index %d for type %d, n=%d\n",
383  ctx->tokens[stream_id][i], stream_id, i);
384  ret = AVERROR_INVALIDDATA;
385  goto end;
386  }
387  }
388  } else {
389  if (len < 0) {
390  ret = AVERROR_INVALIDDATA;
391  goto end;
392  }
393  for (i = 0; i < toks; i++) {
394  ctx->tokens[stream_id][i] = codes.recode[0];
395  if (stream_id <= TM2_MOT && ctx->tokens[stream_id][i] >= TM2_DELTAS) {
396  av_log(ctx->avctx, AV_LOG_ERROR, "Invalid delta token index %d for type %d, n=%d\n",
397  ctx->tokens[stream_id][i], stream_id, i);
398  ret = AVERROR_INVALIDDATA;
399  goto end;
400  }
401  }
402  }
403 
404  ret = skip;
405 
406 end:
407  tm2_free_codes(&codes);
408  return ret;
409 }
410 
411 static inline int GET_TOK(TM2Context *ctx,int type)
412 {
413  if (ctx->tok_ptrs[type] >= ctx->tok_lens[type]) {
414  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]);
415  ctx->error = 1;
416  return 0;
417  }
418  if (type <= TM2_MOT) {
419  if (ctx->tokens[type][ctx->tok_ptrs[type]] >= TM2_DELTAS) {
420  av_log(ctx->avctx, AV_LOG_ERROR, "token %d is too large\n", ctx->tokens[type][ctx->tok_ptrs[type]]);
421  return 0;
422  }
423  return ctx->deltas[type][ctx->tokens[type][ctx->tok_ptrs[type]++]];
424  }
425  return ctx->tokens[type][ctx->tok_ptrs[type]++];
426 }
427 
428 /* blocks decoding routines */
429 
430 /* common Y, U, V pointers initialisation */
431 #define TM2_INIT_POINTERS() \
432  int *last, *clast; \
433  int *Y, *U, *V;\
434  int Ystride, Ustride, Vstride;\
435 \
436  Ystride = ctx->y_stride;\
437  Vstride = ctx->uv_stride;\
438  Ustride = ctx->uv_stride;\
439  Y = (ctx->cur?ctx->Y2:ctx->Y1) + by * 4 * Ystride + bx * 4;\
440  V = (ctx->cur?ctx->V2:ctx->V1) + by * 2 * Vstride + bx * 2;\
441  U = (ctx->cur?ctx->U2:ctx->U1) + by * 2 * Ustride + bx * 2;\
442  last = ctx->last + bx * 4;\
443  clast = ctx->clast + bx * 4;
444 
445 #define TM2_INIT_POINTERS_2() \
446  int *Yo, *Uo, *Vo;\
447  int oYstride, oUstride, oVstride;\
448 \
449  TM2_INIT_POINTERS();\
450  oYstride = Ystride;\
451  oVstride = Vstride;\
452  oUstride = Ustride;\
453  Yo = (ctx->cur?ctx->Y1:ctx->Y2) + by * 4 * oYstride + bx * 4;\
454  Vo = (ctx->cur?ctx->V1:ctx->V2) + by * 2 * oVstride + bx * 2;\
455  Uo = (ctx->cur?ctx->U1:ctx->U2) + by * 2 * oUstride + bx * 2;
456 
457 /* recalculate last and delta values for next blocks */
458 #define TM2_RECALC_BLOCK(CHR, stride, last, CD) {\
459  CD[0] = (unsigned)CHR[ 1] - (unsigned)last[1];\
460  CD[1] = (unsigned)CHR[stride + 1] - (unsigned) CHR[1];\
461  last[0] = (int)CHR[stride + 0];\
462  last[1] = (int)CHR[stride + 1];}
463 
464 /* common operations - add deltas to 4x4 block of luma or 2x2 blocks of chroma */
465 static inline void tm2_apply_deltas(TM2Context *ctx, int* Y, int stride, int *deltas, int *last)
466 {
467  unsigned ct, d;
468  int i, j;
469 
470  for (j = 0; j < 4; j++){
471  ct = ctx->D[j];
472  for (i = 0; i < 4; i++){
473  d = deltas[i + j * 4];
474  ct += d;
475  last[i] += ct;
476  Y[i] = av_clip_uint8(last[i]);
477  }
478  Y += stride;
479  ctx->D[j] = ct;
480  }
481 }
482 
483 static inline void tm2_high_chroma(int *data, int stride, int *last, unsigned *CD, int *deltas)
484 {
485  int i, j;
486  for (j = 0; j < 2; j++) {
487  for (i = 0; i < 2; i++) {
488  CD[j] += deltas[i + j * 2];
489  last[i] += CD[j];
490  data[i] = last[i];
491  }
492  data += stride;
493  }
494 }
495 
496 static inline void tm2_low_chroma(int *data, int stride, int *clast, int *CD, int *deltas, int bx)
497 {
498  int t;
499  int l;
500  int prev;
501 
502  if (bx > 0)
503  prev = clast[-3];
504  else
505  prev = 0;
506  t = (CD[0] + CD[1]) >> 1;
507  l = (prev - CD[0] - CD[1] + clast[1]) >> 1;
508  CD[1] = CD[0] + CD[1] - t;
509  CD[0] = t;
510  clast[0] = l;
511 
512  tm2_high_chroma(data, stride, clast, CD, deltas);
513 }
514 
515 static inline void tm2_hi_res_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
516 {
517  int i;
518  int deltas[16];
520 
521  /* hi-res chroma */
522  for (i = 0; i < 4; i++) {
523  deltas[i] = GET_TOK(ctx, TM2_C_HI);
524  deltas[i + 4] = GET_TOK(ctx, TM2_C_HI);
525  }
526  tm2_high_chroma(U, Ustride, clast, ctx->CD, deltas);
527  tm2_high_chroma(V, Vstride, clast + 2, ctx->CD + 2, deltas + 4);
528 
529  /* hi-res luma */
530  for (i = 0; i < 16; i++)
531  deltas[i] = GET_TOK(ctx, TM2_L_HI);
532 
533  tm2_apply_deltas(ctx, Y, Ystride, deltas, last);
534 }
535 
536 static inline void tm2_med_res_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
537 {
538  int i;
539  int deltas[16];
541 
542  /* low-res chroma */
543  deltas[0] = GET_TOK(ctx, TM2_C_LO);
544  deltas[1] = deltas[2] = deltas[3] = 0;
545  tm2_low_chroma(U, Ustride, clast, ctx->CD, deltas, bx);
546 
547  deltas[0] = GET_TOK(ctx, TM2_C_LO);
548  deltas[1] = deltas[2] = deltas[3] = 0;
549  tm2_low_chroma(V, Vstride, clast + 2, ctx->CD + 2, deltas, bx);
550 
551  /* hi-res luma */
552  for (i = 0; i < 16; i++)
553  deltas[i] = GET_TOK(ctx, TM2_L_HI);
554 
555  tm2_apply_deltas(ctx, Y, Ystride, deltas, last);
556 }
557 
558 static inline void tm2_low_res_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
559 {
560  int i;
561  int t1, t2;
562  int deltas[16];
564 
565  /* low-res chroma */
566  deltas[0] = GET_TOK(ctx, TM2_C_LO);
567  deltas[1] = deltas[2] = deltas[3] = 0;
568  tm2_low_chroma(U, Ustride, clast, ctx->CD, deltas, bx);
569 
570  deltas[0] = GET_TOK(ctx, TM2_C_LO);
571  deltas[1] = deltas[2] = deltas[3] = 0;
572  tm2_low_chroma(V, Vstride, clast + 2, ctx->CD + 2, deltas, bx);
573 
574  /* low-res luma */
575  for (i = 0; i < 16; i++)
576  deltas[i] = 0;
577 
578  deltas[ 0] = GET_TOK(ctx, TM2_L_LO);
579  deltas[ 2] = GET_TOK(ctx, TM2_L_LO);
580  deltas[ 8] = GET_TOK(ctx, TM2_L_LO);
581  deltas[10] = GET_TOK(ctx, TM2_L_LO);
582 
583  if (bx > 0)
584  last[0] = (last[-1] - ctx->D[0] - ctx->D[1] - ctx->D[2] - ctx->D[3] + last[1]) >> 1;
585  else
586  last[0] = (last[1] - ctx->D[0] - ctx->D[1] - ctx->D[2] - ctx->D[3])>> 1;
587  last[2] = (last[1] + last[3]) >> 1;
588 
589  t1 = ctx->D[0] + ctx->D[1];
590  ctx->D[0] = t1 >> 1;
591  ctx->D[1] = t1 - (t1 >> 1);
592  t2 = ctx->D[2] + ctx->D[3];
593  ctx->D[2] = t2 >> 1;
594  ctx->D[3] = t2 - (t2 >> 1);
595 
596  tm2_apply_deltas(ctx, Y, Ystride, deltas, last);
597 }
598 
599 static inline void tm2_null_res_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
600 {
601  int i;
602  int ct;
603  int left, right, diff;
604  int deltas[16];
606 
607  /* null chroma */
608  deltas[0] = deltas[1] = deltas[2] = deltas[3] = 0;
609  tm2_low_chroma(U, Ustride, clast, ctx->CD, deltas, bx);
610 
611  deltas[0] = deltas[1] = deltas[2] = deltas[3] = 0;
612  tm2_low_chroma(V, Vstride, clast + 2, ctx->CD + 2, deltas, bx);
613 
614  /* null luma */
615  for (i = 0; i < 16; i++)
616  deltas[i] = 0;
617 
618  ct = ctx->D[0] + ctx->D[1] + ctx->D[2] + ctx->D[3];
619 
620  if (bx > 0)
621  left = last[-1] - ct;
622  else
623  left = 0;
624 
625  right = last[3];
626  diff = right - left;
627  last[0] = left + (diff >> 2);
628  last[1] = left + (diff >> 1);
629  last[2] = right - (diff >> 2);
630  last[3] = right;
631  {
632  int tp = left;
633 
634  ctx->D[0] = (tp + (ct >> 2)) - left;
635  left += ctx->D[0];
636  ctx->D[1] = (tp + (ct >> 1)) - left;
637  left += ctx->D[1];
638  ctx->D[2] = ((tp + ct) - (ct >> 2)) - left;
639  left += ctx->D[2];
640  ctx->D[3] = (tp + ct) - left;
641  }
642  tm2_apply_deltas(ctx, Y, Ystride, deltas, last);
643 }
644 
645 static inline void tm2_still_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
646 {
647  int i, j;
649 
650  /* update chroma */
651  for (j = 0; j < 2; j++) {
652  for (i = 0; i < 2; i++){
653  U[i] = Uo[i];
654  V[i] = Vo[i];
655  }
656  U += Ustride; V += Vstride;
657  Uo += oUstride; Vo += oVstride;
658  }
659  U -= Ustride * 2;
660  V -= Vstride * 2;
661  TM2_RECALC_BLOCK(U, Ustride, clast, ctx->CD);
662  TM2_RECALC_BLOCK(V, Vstride, (clast + 2), (ctx->CD + 2));
663 
664  /* update deltas */
665  ctx->D[0] = Yo[3] - last[3];
666  ctx->D[1] = Yo[3 + oYstride] - Yo[3];
667  ctx->D[2] = Yo[3 + oYstride * 2] - Yo[3 + oYstride];
668  ctx->D[3] = Yo[3 + oYstride * 3] - Yo[3 + oYstride * 2];
669 
670  for (j = 0; j < 4; j++) {
671  for (i = 0; i < 4; i++) {
672  Y[i] = Yo[i];
673  last[i] = Yo[i];
674  }
675  Y += Ystride;
676  Yo += oYstride;
677  }
678 }
679 
680 static inline void tm2_update_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
681 {
682  int i, j;
683  int d;
685 
686  /* update chroma */
687  for (j = 0; j < 2; j++) {
688  for (i = 0; i < 2; i++) {
689  U[i] = Uo[i] + GET_TOK(ctx, TM2_UPD);
690  V[i] = Vo[i] + GET_TOK(ctx, TM2_UPD);
691  }
692  U += Ustride;
693  V += Vstride;
694  Uo += oUstride;
695  Vo += oVstride;
696  }
697  U -= Ustride * 2;
698  V -= Vstride * 2;
699  TM2_RECALC_BLOCK(U, Ustride, clast, ctx->CD);
700  TM2_RECALC_BLOCK(V, Vstride, (clast + 2), (ctx->CD + 2));
701 
702  /* update deltas */
703  ctx->D[0] = Yo[3] - last[3];
704  ctx->D[1] = Yo[3 + oYstride] - Yo[3];
705  ctx->D[2] = Yo[3 + oYstride * 2] - Yo[3 + oYstride];
706  ctx->D[3] = Yo[3 + oYstride * 3] - Yo[3 + oYstride * 2];
707 
708  for (j = 0; j < 4; j++) {
709  d = last[3];
710  for (i = 0; i < 4; i++) {
711  Y[i] = Yo[i] + GET_TOK(ctx, TM2_UPD);
712  last[i] = Y[i];
713  }
714  ctx->D[j] = last[3] - d;
715  Y += Ystride;
716  Yo += oYstride;
717  }
718 }
719 
720 static inline void tm2_motion_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
721 {
722  int i, j;
723  int mx, my;
725 
726  mx = GET_TOK(ctx, TM2_MOT);
727  my = GET_TOK(ctx, TM2_MOT);
728  mx = av_clip(mx, -(bx * 4 + 4), ctx->avctx->width - bx * 4);
729  my = av_clip(my, -(by * 4 + 4), ctx->avctx->height - by * 4);
730 
731  if (4*bx+mx<0 || 4*by+my<0 || 4*bx+mx+4 > ctx->avctx->width || 4*by+my+4 > ctx->avctx->height) {
732  av_log(ctx->avctx, AV_LOG_ERROR, "MV out of picture\n");
733  return;
734  }
735 
736  Yo += my * oYstride + mx;
737  Uo += (my >> 1) * oUstride + (mx >> 1);
738  Vo += (my >> 1) * oVstride + (mx >> 1);
739 
740  /* copy chroma */
741  for (j = 0; j < 2; j++) {
742  for (i = 0; i < 2; i++) {
743  U[i] = Uo[i];
744  V[i] = Vo[i];
745  }
746  U += Ustride;
747  V += Vstride;
748  Uo += oUstride;
749  Vo += oVstride;
750  }
751  U -= Ustride * 2;
752  V -= Vstride * 2;
753  TM2_RECALC_BLOCK(U, Ustride, clast, ctx->CD);
754  TM2_RECALC_BLOCK(V, Vstride, (clast + 2), (ctx->CD + 2));
755 
756  /* copy luma */
757  for (j = 0; j < 4; j++) {
758  for (i = 0; i < 4; i++) {
759  Y[i] = Yo[i];
760  }
761  Y += Ystride;
762  Yo += oYstride;
763  }
764  /* calculate deltas */
765  Y -= Ystride * 4;
766  ctx->D[0] = Y[3] - last[3];
767  ctx->D[1] = Y[3 + Ystride] - Y[3];
768  ctx->D[2] = Y[3 + Ystride * 2] - Y[3 + Ystride];
769  ctx->D[3] = Y[3 + Ystride * 3] - Y[3 + Ystride * 2];
770  for (i = 0; i < 4; i++)
771  last[i] = Y[i + Ystride * 3];
772 }
773 
775 {
776  int i, j;
777  int w = ctx->avctx->width, h = ctx->avctx->height, bw = w >> 2, bh = h >> 2, cw = w >> 1;
778  int type;
779  int keyframe = 1;
780  int *Y, *U, *V;
781  uint8_t *dst;
782 
783  for (i = 0; i < TM2_NUM_STREAMS; i++)
784  ctx->tok_ptrs[i] = 0;
785 
786  if (ctx->tok_lens[TM2_TYPE]<bw*bh) {
787  av_log(ctx->avctx,AV_LOG_ERROR,"Got %i tokens for %i blocks\n",ctx->tok_lens[TM2_TYPE],bw*bh);
788  return AVERROR_INVALIDDATA;
789  }
790 
791  memset(ctx->last, 0, 4 * bw * sizeof(int));
792  memset(ctx->clast, 0, 4 * bw * sizeof(int));
793 
794  for (j = 0; j < bh; j++) {
795  memset(ctx->D, 0, 4 * sizeof(int));
796  memset(ctx->CD, 0, 4 * sizeof(int));
797  for (i = 0; i < bw; i++) {
798  type = GET_TOK(ctx, TM2_TYPE);
799  switch(type) {
800  case TM2_HI_RES:
801  tm2_hi_res_block(ctx, p, i, j);
802  break;
803  case TM2_MED_RES:
804  tm2_med_res_block(ctx, p, i, j);
805  break;
806  case TM2_LOW_RES:
807  tm2_low_res_block(ctx, p, i, j);
808  break;
809  case TM2_NULL_RES:
810  tm2_null_res_block(ctx, p, i, j);
811  break;
812  case TM2_UPDATE:
813  tm2_update_block(ctx, p, i, j);
814  keyframe = 0;
815  break;
816  case TM2_STILL:
817  tm2_still_block(ctx, p, i, j);
818  keyframe = 0;
819  break;
820  case TM2_MOTION:
821  tm2_motion_block(ctx, p, i, j);
822  keyframe = 0;
823  break;
824  default:
825  av_log(ctx->avctx, AV_LOG_ERROR, "Skipping unknown block type %i\n", type);
826  }
827  if (ctx->error)
828  return AVERROR_INVALIDDATA;
829  }
830  }
831 
832  /* copy data from our buffer to AVFrame */
833  Y = (ctx->cur?ctx->Y2:ctx->Y1);
834  U = (ctx->cur?ctx->U2:ctx->U1);
835  V = (ctx->cur?ctx->V2:ctx->V1);
836  dst = p->data[0];
837  for (j = 0; j < h; j++) {
838  for (i = 0; i < w; i++) {
839  int y = Y[i], u = U[i >> 1], v = V[i >> 1];
840  dst[3*i+0] = av_clip_uint8(y + v);
841  dst[3*i+1] = av_clip_uint8(y);
842  dst[3*i+2] = av_clip_uint8(y + u);
843  }
844 
845  /* horizontal edge extension */
846  Y[-4] = Y[-3] = Y[-2] = Y[-1] = Y[0];
847  Y[w + 3] = Y[w + 2] = Y[w + 1] = Y[w] = Y[w - 1];
848 
849  /* vertical edge extension */
850  if (j == 0) {
851  memcpy(Y - 4 - 1 * ctx->y_stride, Y - 4, ctx->y_stride);
852  memcpy(Y - 4 - 2 * ctx->y_stride, Y - 4, ctx->y_stride);
853  memcpy(Y - 4 - 3 * ctx->y_stride, Y - 4, ctx->y_stride);
854  memcpy(Y - 4 - 4 * ctx->y_stride, Y - 4, ctx->y_stride);
855  } else if (j == h - 1) {
856  memcpy(Y - 4 + 1 * ctx->y_stride, Y - 4, ctx->y_stride);
857  memcpy(Y - 4 + 2 * ctx->y_stride, Y - 4, ctx->y_stride);
858  memcpy(Y - 4 + 3 * ctx->y_stride, Y - 4, ctx->y_stride);
859  memcpy(Y - 4 + 4 * ctx->y_stride, Y - 4, ctx->y_stride);
860  }
861 
862  Y += ctx->y_stride;
863  if (j & 1) {
864  /* horizontal edge extension */
865  U[-2] = U[-1] = U[0];
866  V[-2] = V[-1] = V[0];
867  U[cw + 1] = U[cw] = U[cw - 1];
868  V[cw + 1] = V[cw] = V[cw - 1];
869 
870  /* vertical edge extension */
871  if (j == 1) {
872  memcpy(U - 2 - 1 * ctx->uv_stride, U - 2, ctx->uv_stride);
873  memcpy(V - 2 - 1 * ctx->uv_stride, V - 2, ctx->uv_stride);
874  memcpy(U - 2 - 2 * ctx->uv_stride, U - 2, ctx->uv_stride);
875  memcpy(V - 2 - 2 * ctx->uv_stride, V - 2, ctx->uv_stride);
876  } else if (j == h - 1) {
877  memcpy(U - 2 + 1 * ctx->uv_stride, U - 2, ctx->uv_stride);
878  memcpy(V - 2 + 1 * ctx->uv_stride, V - 2, ctx->uv_stride);
879  memcpy(U - 2 + 2 * ctx->uv_stride, U - 2, ctx->uv_stride);
880  memcpy(V - 2 + 2 * ctx->uv_stride, V - 2, ctx->uv_stride);
881  }
882 
883  U += ctx->uv_stride;
884  V += ctx->uv_stride;
885  }
886  dst += p->linesize[0];
887  }
888 
889  return keyframe;
890 }
891 
892 static const int tm2_stream_order[TM2_NUM_STREAMS] = {
894 };
895 
896 #define TM2_HEADER_SIZE 40
897 
898 static int decode_frame(AVCodecContext *avctx,
899  void *data, int *got_frame,
900  AVPacket *avpkt)
901 {
902  TM2Context * const l = avctx->priv_data;
903  const uint8_t *buf = avpkt->data;
904  int buf_size = avpkt->size & ~3;
905  AVFrame * const p = l->pic;
906  int offset = TM2_HEADER_SIZE;
907  int i, t, ret;
908 
909  l->error = 0;
910 
911  av_fast_padded_malloc(&l->buffer, &l->buffer_size, buf_size);
912  if (!l->buffer) {
913  av_log(avctx, AV_LOG_ERROR, "Cannot allocate temporary buffer\n");
914  return AVERROR(ENOMEM);
915  }
916 
917  if ((ret = ff_reget_buffer(avctx, p)) < 0)
918  return ret;
919 
920  l->bdsp.bswap_buf((uint32_t *) l->buffer, (const uint32_t *) buf,
921  buf_size >> 2);
922 
923  if ((ret = tm2_read_header(l, l->buffer)) < 0) {
924  return ret;
925  }
926 
927  for (i = 0; i < TM2_NUM_STREAMS; i++) {
928  if (offset >= buf_size) {
929  av_log(avctx, AV_LOG_ERROR, "no space for tm2_read_stream\n");
930  return AVERROR_INVALIDDATA;
931  }
932 
933  t = tm2_read_stream(l, l->buffer + offset, tm2_stream_order[i],
934  buf_size - offset);
935  if (t < 0) {
936  int j = tm2_stream_order[i];
937  if (l->tok_lens[j])
938  memset(l->tokens[j], 0, sizeof(**l->tokens) * l->tok_lens[j]);
939  return t;
940  }
941  offset += t;
942  }
943  p->key_frame = tm2_decode_blocks(l, p);
944  if (p->key_frame)
946  else
948 
949  l->cur = !l->cur;
950  *got_frame = 1;
951  ret = av_frame_ref(data, l->pic);
952 
953  return (ret < 0) ? ret : buf_size;
954 }
955 
957 {
958  TM2Context * const l = avctx->priv_data;
959  int i, w = avctx->width, h = avctx->height;
960 
961  if ((avctx->width & 3) || (avctx->height & 3)) {
962  av_log(avctx, AV_LOG_ERROR, "Width and height must be multiple of 4\n");
963  return AVERROR(EINVAL);
964  }
965 
966  l->avctx = avctx;
967  avctx->pix_fmt = AV_PIX_FMT_BGR24;
968 
969  l->pic = av_frame_alloc();
970  if (!l->pic)
971  return AVERROR(ENOMEM);
972 
973  ff_bswapdsp_init(&l->bdsp);
974 
975  l->last = av_malloc_array(w >> 2, 4 * sizeof(*l->last) );
976  l->clast = av_malloc_array(w >> 2, 4 * sizeof(*l->clast));
977 
978  for (i = 0; i < TM2_NUM_STREAMS; i++) {
979  l->tokens[i] = NULL;
980  l->tok_lens[i] = 0;
981  }
982 
983  w += 8;
984  h += 8;
985  l->Y1_base = av_calloc(w * h, sizeof(*l->Y1_base));
986  l->Y2_base = av_calloc(w * h, sizeof(*l->Y2_base));
987  l->y_stride = w;
988  w = (w + 1) >> 1;
989  h = (h + 1) >> 1;
990  l->U1_base = av_calloc(w * h, sizeof(*l->U1_base));
991  l->V1_base = av_calloc(w * h, sizeof(*l->V1_base));
992  l->U2_base = av_calloc(w * h, sizeof(*l->U2_base));
993  l->V2_base = av_calloc(w * h, sizeof(*l->V1_base));
994  l->uv_stride = w;
995  l->cur = 0;
996  if (!l->Y1_base || !l->Y2_base || !l->U1_base ||
997  !l->V1_base || !l->U2_base || !l->V2_base ||
998  !l->last || !l->clast) {
999  av_freep(&l->Y1_base);
1000  av_freep(&l->Y2_base);
1001  av_freep(&l->U1_base);
1002  av_freep(&l->U2_base);
1003  av_freep(&l->V1_base);
1004  av_freep(&l->V2_base);
1005  av_freep(&l->last);
1006  av_freep(&l->clast);
1007  av_frame_free(&l->pic);
1008  return AVERROR(ENOMEM);
1009  }
1010  l->Y1 = l->Y1_base + l->y_stride * 4 + 4;
1011  l->Y2 = l->Y2_base + l->y_stride * 4 + 4;
1012  l->U1 = l->U1_base + l->uv_stride * 2 + 2;
1013  l->U2 = l->U2_base + l->uv_stride * 2 + 2;
1014  l->V1 = l->V1_base + l->uv_stride * 2 + 2;
1015  l->V2 = l->V2_base + l->uv_stride * 2 + 2;
1016 
1017  return 0;
1018 }
1019 
1021 {
1022  TM2Context * const l = avctx->priv_data;
1023  int i;
1024 
1025  av_free(l->last);
1026  av_free(l->clast);
1027  for (i = 0; i < TM2_NUM_STREAMS; i++)
1028  av_freep(&l->tokens[i]);
1029  if (l->Y1) {
1030  av_freep(&l->Y1_base);
1031  av_freep(&l->U1_base);
1032  av_freep(&l->V1_base);
1033  av_freep(&l->Y2_base);
1034  av_freep(&l->U2_base);
1035  av_freep(&l->V2_base);
1036  }
1037  av_freep(&l->buffer);
1038  l->buffer_size = 0;
1039 
1040  av_frame_free(&l->pic);
1041 
1042  return 0;
1043 }
1044 
1046  .name = "truemotion2",
1047  .long_name = NULL_IF_CONFIG_SMALL("Duck TrueMotion 2.0"),
1048  .type = AVMEDIA_TYPE_VIDEO,
1050  .priv_data_size = sizeof(TM2Context),
1051  .init = decode_init,
1052  .close = decode_end,
1053  .decode = decode_frame,
1054  .capabilities = AV_CODEC_CAP_DR1,
1055 };
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:496
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:1453
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1750
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:1045
AVCodec.
Definition: avcodec.h:3441
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:251
#define TM2_HEADER_SIZE
Definition: truemotion2.c:896
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:892
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:268
static void tm2_free_codes(TM2Codes *code)
Definition: truemotion2.c:232
uint8_t * data
Definition: avcodec.h:1452
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:119
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:515
static int tm2_read_stream(TM2Context *ctx, const uint8_t *buf, int stream_id, int buf_size)
Definition: truemotion2.c:295
#define av_log(a,...)
static void tm2_update_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
Definition: truemotion2.c:680
#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:150
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:558
#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:774
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:3448
int * clast
Definition: truemotion2.c:81
static const uint8_t offset[127][2]
Definition: vf_spp.c:92
#define FFMAX(a, b)
Definition: common.h:94
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:411
int width
picture width / height.
Definition: avcodec.h:1713
uint8_t w
Definition: llviddspenc.c:38
#define TM2_OLD_HEADER_MAGIC
Definition: truemotion2.c:248
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:239
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:1020
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:445
main external API structure.
Definition: avcodec.h:1540
static void tm2_still_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
Definition: truemotion2.c:645
#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:431
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:536
static void tm2_motion_block(TM2Context *ctx, AVFrame *pic, int bx, int by)
Definition: truemotion2.c:720
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:465
#define TM2_ESCAPE
Definition: truemotion2.c:35
#define TM2_RECALC_BLOCK(CHR, stride, last, CD)
Definition: truemotion2.c:458
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:599
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:956
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:483
#define TM2_NEW_HEADER_MAGIC
Definition: truemotion2.c:249
av_cold void ff_bswapdsp_init(BswapDSPContext *c)
Definition: bswapdsp.c:49
void * priv_data
Definition: avcodec.h:1567
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:1429
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:898