FFmpeg
imm4.c
Go to the documentation of this file.
1 /*
2  * Infinity IMM4 decoder
3  *
4  * Copyright (c) 2018 Paul B Mahol
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 #include <stddef.h>
24 #include <string.h>
25 
26 #include "libavutil/mem_internal.h"
27 #include "libavutil/thread.h"
28 
29 #include "avcodec.h"
30 #include "bswapdsp.h"
31 #include "codec_internal.h"
32 #include "decode.h"
33 #include "copy_block.h"
34 #include "get_bits.h"
35 #include "idctdsp.h"
36 
37 #define CBPLO_VLC_BITS 6
38 #define CBPHI_VLC_BITS 6
39 #define BLKTYPE_VLC_BITS 9
40 #define BLOCK_VLC_BITS 12
41 
42 typedef struct IMM4Context {
45 
47  uint8_t *bitstream;
49 
50  int factor;
51  unsigned lo;
52  unsigned hi;
53 
55  DECLARE_ALIGNED(32, int16_t, block)[6][64];
56 } IMM4Context;
57 
58 static const uint8_t intra_cb[] = {
59  24, 18, 12
60 };
61 
62 static const uint8_t inter_cb[] = {
63  30, 20, 15
64 };
65 
66 static const uint8_t cbplo[][2] = {
67  { 0,-6 }, { 0x01, 6 }, { 0x02, 6 }, { 0x03, 6 }, { 0x00, 4 },
68  { 0x01, 3 }, { 0x02, 3 }, { 0x03, 3 }, { 0x00, 1 },
69 };
70 
71 static const uint8_t cbphi_bits[] = {
72  4, 5, 5, 4, 5, 4, 6, 4, 5, 6, 4, 4, 4, 4, 4, 2
73 };
74 
75 static const uint8_t cbphi_codes[] = {
76  3, 5, 4, 9, 3, 7, 2, 11, 2, 3, 5, 10, 4, 8, 6, 3
77 };
78 
79 static const uint8_t blktype[][2] = {
80  { 0,-8 }, { 0x34, 9 }, { 0,-9 }, { 0x14, 9 }, { 0,-9 },
81  { 0x23, 8 }, { 0x13, 8 }, { 0x32, 8 }, { 0x33, 7 }, { 0x22, 7 },
82  { 0x12, 7 }, { 0x21, 7 }, { 0x11, 7 }, { 0x04, 6 }, { 0x30, 6 },
83  { 0x03, 5 }, { 0x20, 4 }, { 0x10, 4 }, { 0x02, 3 }, { 0x01, 3 },
84  { 0x00, 1 },
85 };
86 
87 static const uint16_t block_symbols[] = {
88  0, 0x4082, 0x4003, 0x000B, 0x000A, 0x4E01, 0x4D81, 0x4D01, 0x4C81,
89  0x0482, 0x0402, 0x0382, 0x0302, 0x0282, 0x0183, 0x0103, 0x0084, 0x000C,
90  0x0085, 0x0B81, 0x0C01, 0x4E81, 0x4F01, 0x4F81, 0x5001, 0x0086, 0x0104,
91  0x0203, 0x0283, 0x0303, 0x0502, 0x0C81, 0x0D01, 0x5081, 0x5101, 0x5181,
92  0x5201, 0x5281, 0x5301, 0x5381, 0x5401, 0x0000, 0x0009, 0x0008, 0x4C01,
93  0x4B81, 0x4B01, 0x4A81, 0x4A01, 0x4981, 0x4901, 0x4881, 0x4002, 0x0B01,
94  0x0A81, 0x0A01, 0x0981, 0x0901, 0x0881, 0x0801, 0x0781, 0x0202, 0x0182,
95  0x0007, 0x0006, 0x4801, 0x4781, 0x4701, 0x4681, 0x4601, 0x4581, 0x4501,
96  0x4481, 0x0701, 0x0681, 0x0102, 0x0083, 0x0005, 0x4401, 0x4381, 0x4301,
97  0x4281, 0x0601, 0x0581, 0x0501, 0x0004, 0x4201, 0x4181, 0x4101, 0x4081,
98  0x0481, 0x0401, 0x0381, 0x0301, 0x0082, 0x0003, 0x0281, 0x0201, 0x0181,
99  0x4001, 0x0001, 0x0081, 0x0101, 0x0002,
100 };
101 
102 static const uint8_t block_bits[] = {
103  -9, 11, 11, 11, 11, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11,
104  11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
105  12, 12, 12, 7, 10, 10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
106  9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
107  8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6,
108  6, 5, 5, 5, 4, 2, 3, 4, 4,
109 };
110 
115 
116 static int get_cbphi(GetBitContext *gb, int x)
117 {
118  int value;
119 
121  if (value < 0)
122  return AVERROR_INVALIDDATA;
123 
124  return x ? value : 15 - value;
125 }
126 
128  int block, int factor, int flag, int offset, int flag2)
129 {
130  IMM4Context *s = avctx->priv_data;
131  const uint8_t *idct_permutation = s->idsp.idct_permutation;
132  int i, last, len, factor2;
133 
134  for (i = !flag; i < 64; i++) {
135  int value;
136 
138  if (value < 0)
139  return AVERROR_INVALIDDATA;
140  if (value == 0) {
141  last = get_bits1(gb);
142  len = get_bits(gb, 6);
143  factor2 = get_sbits(gb, 8);
144  } else {
145  factor2 = value & 0x7F;
146  last = (value >> 14) & 1;
147  len = (value >> 7) & 0x3F;
148  if (get_bits1(gb))
149  factor2 = -factor2;
150  }
151  i += len;
152  if (i >= 64)
153  break;
154  s->block[block][idct_permutation[i]] = offset * (factor2 < 0 ? -1 : 1) + factor * factor2;
155  if (last)
156  break;
157  }
158 
159  if (s->hi == 2 && flag2 && block < 4) {
160  if (flag)
161  s->block[block][idct_permutation[0]] *= 2;
162  s->block[block][idct_permutation[1]] *= 2;
163  s->block[block][idct_permutation[8]] *= 2;
164  s->block[block][idct_permutation[16]] *= 2;
165  }
166 
167  return 0;
168 }
169 
171  unsigned cbp, int flag, int offset, unsigned flag2)
172 {
173  IMM4Context *s = avctx->priv_data;
174  const uint8_t *idct_permutation = s->idsp.idct_permutation;
175  int ret, i;
176 
177  memset(s->block, 0, sizeof(s->block));
178 
179  for (i = 0; i < 6; i++) {
180  if (!flag) {
181  int x = get_bits(gb, 8);
182 
183  if (x == 255)
184  x = 128;
185  x *= 8;
186 
187  s->block[i][idct_permutation[0]] = x;
188  }
189 
190  if (cbp & (1 << (5 - i))) {
191  ret = decode_block(avctx, gb, i, s->factor, flag, offset, flag2);
192  if (ret < 0)
193  return ret;
194  }
195  }
196 
197  return 0;
198 }
199 
201 {
202  IMM4Context *s = avctx->priv_data;
203  int ret, x, y, offset = 0;
204 
205  if (s->hi == 0) {
206  if (s->lo > 2)
207  return AVERROR_INVALIDDATA;
208  s->factor = intra_cb[s->lo];
209  } else {
210  s->factor = s->lo * 2;
211  }
212 
213  if (s->hi) {
214  offset = s->factor;
215  offset >>= 1;
216  if (!(offset & 1))
217  offset--;
218  }
219 
220  for (y = 0; y < avctx->height; y += 16) {
221  for (x = 0; x < avctx->width; x += 16) {
222  unsigned flag, cbplo;
223  int cbphi;
224 
226  flag = get_bits1(gb);
227 
228  cbphi = get_cbphi(gb, 1);
229  if (cbphi < 0)
230  return cbphi;
231 
232  ret = decode_blocks(avctx, gb, cbplo | (cbphi << 2), 0, offset, flag);
233  if (ret < 0)
234  return ret;
235 
236  s->idsp.idct_put(frame->data[0] + y * frame->linesize[0] + x,
237  frame->linesize[0], s->block[0]);
238  s->idsp.idct_put(frame->data[0] + y * frame->linesize[0] + x + 8,
239  frame->linesize[0], s->block[1]);
240  s->idsp.idct_put(frame->data[0] + (y + 8) * frame->linesize[0] + x,
241  frame->linesize[0], s->block[2]);
242  s->idsp.idct_put(frame->data[0] + (y + 8) * frame->linesize[0] + x + 8,
243  frame->linesize[0], s->block[3]);
244  s->idsp.idct_put(frame->data[1] + (y >> 1) * frame->linesize[1] + (x >> 1),
245  frame->linesize[1], s->block[4]);
246  s->idsp.idct_put(frame->data[2] + (y >> 1) * frame->linesize[2] + (x >> 1),
247  frame->linesize[2], s->block[5]);
248  }
249  }
250 
251  return 0;
252 }
253 
255  AVFrame *frame, AVFrame *prev)
256 {
257  IMM4Context *s = avctx->priv_data;
258  int ret, x, y, offset = 0;
259 
260  if (s->hi == 0) {
261  if (s->lo > 2)
262  return AVERROR_INVALIDDATA;
263  s->factor = inter_cb[s->lo];
264  } else {
265  s->factor = s->lo * 2;
266  }
267 
268  if (s->hi) {
269  offset = s->factor;
270  offset >>= 1;
271  if (!(offset & 1))
272  offset--;
273  }
274 
275  for (y = 0; y < avctx->height; y += 16) {
276  for (x = 0; x < avctx->width; x += 16) {
277  int reverse, intra_block, value;
278  unsigned cbplo, flag2 = 0;
279  int cbphi;
280 
281  if (get_bits1(gb)) {
282  copy_block16(frame->data[0] + y * frame->linesize[0] + x,
283  prev->data[0] + y * prev->linesize[0] + x,
284  frame->linesize[0], prev->linesize[0], 16);
285  copy_block8(frame->data[1] + (y >> 1) * frame->linesize[1] + (x >> 1),
286  prev->data[1] + (y >> 1) * prev->linesize[1] + (x >> 1),
287  frame->linesize[1], prev->linesize[1], 8);
288  copy_block8(frame->data[2] + (y >> 1) * frame->linesize[2] + (x >> 1),
289  prev->data[2] + (y >> 1) * prev->linesize[2] + (x >> 1),
290  frame->linesize[2], prev->linesize[2], 8);
291  continue;
292  }
293 
295  if (value < 0)
296  return AVERROR_INVALIDDATA;
297 
298  intra_block = value & 0x07;
299  reverse = intra_block == 3;
300  if (reverse)
301  flag2 = get_bits1(gb);
302 
303  cbplo = value >> 4;
304  cbphi = get_cbphi(gb, reverse);
305  if (cbphi < 0)
306  return cbphi;
307 
308  if (intra_block) {
309  ret = decode_blocks(avctx, gb, cbplo | (cbphi << 2), 0, offset, flag2);
310  if (ret < 0)
311  return ret;
312 
313  s->idsp.idct_put(frame->data[0] + y * frame->linesize[0] + x,
314  frame->linesize[0], s->block[0]);
315  s->idsp.idct_put(frame->data[0] + y * frame->linesize[0] + x + 8,
316  frame->linesize[0], s->block[1]);
317  s->idsp.idct_put(frame->data[0] + (y + 8) * frame->linesize[0] + x,
318  frame->linesize[0], s->block[2]);
319  s->idsp.idct_put(frame->data[0] + (y + 8) * frame->linesize[0] + x + 8,
320  frame->linesize[0], s->block[3]);
321  s->idsp.idct_put(frame->data[1] + (y >> 1) * frame->linesize[1] + (x >> 1),
322  frame->linesize[1], s->block[4]);
323  s->idsp.idct_put(frame->data[2] + (y >> 1) * frame->linesize[2] + (x >> 1),
324  frame->linesize[2], s->block[5]);
325  } else {
326  flag2 = get_bits1(gb);
327  skip_bits1(gb);
328  ret = decode_blocks(avctx, gb, cbplo | (cbphi << 2), 1, offset, flag2);
329  if (ret < 0)
330  return ret;
331 
332  copy_block16(frame->data[0] + y * frame->linesize[0] + x,
333  prev->data[0] + y * prev->linesize[0] + x,
334  frame->linesize[0], prev->linesize[0], 16);
335  copy_block8(frame->data[1] + (y >> 1) * frame->linesize[1] + (x >> 1),
336  prev->data[1] + (y >> 1) * prev->linesize[1] + (x >> 1),
337  frame->linesize[1], prev->linesize[1], 8);
338  copy_block8(frame->data[2] + (y >> 1) * frame->linesize[2] + (x >> 1),
339  prev->data[2] + (y >> 1) * prev->linesize[2] + (x >> 1),
340  frame->linesize[2], prev->linesize[2], 8);
341 
342  s->idsp.idct_add(frame->data[0] + y * frame->linesize[0] + x,
343  frame->linesize[0], s->block[0]);
344  s->idsp.idct_add(frame->data[0] + y * frame->linesize[0] + x + 8,
345  frame->linesize[0], s->block[1]);
346  s->idsp.idct_add(frame->data[0] + (y + 8) * frame->linesize[0] + x,
347  frame->linesize[0], s->block[2]);
348  s->idsp.idct_add(frame->data[0] + (y + 8) * frame->linesize[0] + x + 8,
349  frame->linesize[0], s->block[3]);
350  s->idsp.idct_add(frame->data[1] + (y >> 1) * frame->linesize[1] + (x >> 1),
351  frame->linesize[1], s->block[4]);
352  s->idsp.idct_add(frame->data[2] + (y >> 1) * frame->linesize[2] + (x >> 1),
353  frame->linesize[2], s->block[5]);
354  }
355  }
356  }
357 
358  return 0;
359 }
360 
362  int *got_frame, AVPacket *avpkt)
363 {
364  IMM4Context *s = avctx->priv_data;
365  GetBitContext *gb = &s->gb;
366  int width, height;
367  unsigned type;
368  int ret, scaled;
369 
370  if (avpkt->size <= 32)
371  return AVERROR_INVALIDDATA;
372 
373  av_fast_padded_malloc(&s->bitstream, &s->bitstream_size,
374  FFALIGN(avpkt->size, 4));
375  if (!s->bitstream)
376  return AVERROR(ENOMEM);
377 
378  s->bdsp.bswap_buf((uint32_t *)s->bitstream,
379  (uint32_t *)avpkt->data,
380  (avpkt->size + 3) >> 2);
381 
382  if ((ret = init_get_bits8(gb, s->bitstream, FFALIGN(avpkt->size, 4))) < 0)
383  return ret;
384 
385  avctx->pix_fmt = AV_PIX_FMT_YUV420P;
386  avctx->color_range = AVCOL_RANGE_JPEG;
387 
388  width = avctx->width;
389  height = avctx->height;
390 
391  scaled = avpkt->data[8];
392  if (scaled < 2) {
393  int mode = avpkt->data[10];
394 
395  switch (mode) {
396  case 1:
397  width = 352;
398  height = 240;
399  break;
400  case 2:
401  width = 704;
402  height = 240;
403  break;
404  case 4:
405  width = 480;
406  height = 704;
407  break;
408  case 17:
409  width = 352;
410  height = 288;
411  break;
412  case 18:
413  width = 704;
414  height = 288;
415  break;
416  default:
417  width = 704;
418  height = 576;
419  break;
420  }
421  }
422 
423  skip_bits_long(gb, 24 * 8);
424  type = get_bits_long(gb, 32);
425  s->hi = get_bits(gb, 16);
426  s->lo = get_bits(gb, 16);
427 
428  switch (type) {
429  case 0x19781977:
432  break;
433  case 0x12250926:
436  break;
437  default:
438  avpriv_request_sample(avctx, "type %X", type);
439  return AVERROR_PATCHWELCOME;
440  }
441 
442  if (avctx->width != width ||
443  avctx->height != height) {
444  if (!(frame->flags & AV_FRAME_FLAG_KEY)) {
445  av_log(avctx, AV_LOG_ERROR, "Frame size change is unsupported.\n");
446  return AVERROR_INVALIDDATA;
447  }
448  av_frame_unref(s->prev_frame);
449  }
450 
451  ret = ff_set_dimensions(avctx, width, height);
452  if (ret < 0)
453  return ret;
454 
456  return ret;
457 
458  if (frame->flags & AV_FRAME_FLAG_KEY) {
459  ret = decode_intra(avctx, gb, frame);
460  if (ret < 0)
461  return ret;
462 
463  if ((ret = av_frame_replace(s->prev_frame, frame)) < 0)
464  return ret;
465  } else {
466  if (!s->prev_frame->data[0]) {
467  av_log(avctx, AV_LOG_ERROR, "Missing reference frame.\n");
468  return AVERROR_INVALIDDATA;
469  }
470 
471  ret = decode_inter(avctx, gb, frame, s->prev_frame);
472  if (ret < 0)
473  return ret;
474  }
475 
476  *got_frame = 1;
477 
478  return avpkt->size;
479 }
480 
482 {
484  &cbplo[0][1], 2, &cbplo[0][0], 2, 1,
485  0, 0);
486 
488  cbphi_bits, 1, 1, cbphi_codes, 1, 1, 0);
489 
491  &blktype[0][1], 2, &blktype[0][0], 2, 1,
492  0, 0);
493 
495  block_bits, 1, block_symbols, 2, 2,
496  0, 0);
497 }
498 
500 {
501  static AVOnce init_static_once = AV_ONCE_INIT;
502  IMM4Context *s = avctx->priv_data;
503 
504  ff_bswapdsp_init(&s->bdsp);
505  ff_idctdsp_init(&s->idsp, avctx);
506 
507  s->prev_frame = av_frame_alloc();
508  if (!s->prev_frame)
509  return AVERROR(ENOMEM);
510 
511  ff_thread_once(&init_static_once, imm4_init_static_data);
512 
513  return 0;
514 }
515 
516 static void decode_flush(AVCodecContext *avctx)
517 {
518  IMM4Context *s = avctx->priv_data;
519 
520  av_frame_unref(s->prev_frame);
521 }
522 
524 {
525  IMM4Context *s = avctx->priv_data;
526 
527  av_frame_free(&s->prev_frame);
528  av_freep(&s->bitstream);
529  s->bitstream_size = 0;
530 
531  return 0;
532 }
533 
535  .p.name = "imm4",
536  CODEC_LONG_NAME("Infinity IMM4"),
537  .p.type = AVMEDIA_TYPE_VIDEO,
538  .p.id = AV_CODEC_ID_IMM4,
539  .priv_data_size = sizeof(IMM4Context),
540  .init = decode_init,
541  .close = decode_close,
543  .flush = decode_flush,
544  .p.capabilities = AV_CODEC_CAP_DR1,
545  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
546 };
imm4_init_static_data
static av_cold void imm4_init_static_data(void)
Definition: imm4.c:481
bswapdsp.h
IMM4Context::factor
int factor
Definition: imm4.c:50
skip_bits_long
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
Definition: get_bits.h:278
FF_CODEC_CAP_INIT_CLEANUP
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: codec_internal.h:42
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
blktype_tab
static VLCElem blktype_tab[1<< BLKTYPE_VLC_BITS]
Definition: imm4.c:113
mem_internal.h
get_cbphi
static int get_cbphi(GetBitContext *gb, int x)
Definition: imm4.c:116
thread.h
block_bits
static const uint8_t block_bits[]
Definition: imm4.c:102
get_bits_long
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
Definition: get_bits.h:421
cbplo_tab
static VLCElem cbplo_tab[1<< CBPLO_VLC_BITS]
Definition: imm4.c:111
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:130
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:344
AVCOL_RANGE_JPEG
@ AVCOL_RANGE_JPEG
Full range content.
Definition: pixfmt.h:683
AVPacket::data
uint8_t * data
Definition: packet.h:522
FFCodec
Definition: codec_internal.h:127
copy_block8
static void copy_block8(uint8_t *dst, const uint8_t *src, ptrdiff_t dstStride, ptrdiff_t srcStride, int h)
Definition: copy_block.h:47
decode_frame
static int decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *avpkt)
Definition: imm4.c:361
AVFrame::flags
int flags
Frame flags, a combination of AV_FRAME_FLAGS.
Definition: frame.h:616
ff_set_dimensions
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Check that the provided frame dimensions are valid and set them on the codec context.
Definition: utils.c:94
intra_cb
static const uint8_t intra_cb[]
Definition: imm4.c:58
ff_idctdsp_init
av_cold void ff_idctdsp_init(IDCTDSPContext *c, AVCodecContext *avctx)
Definition: idctdsp.c:228
decode_close
static av_cold int decode_close(AVCodecContext *avctx)
Definition: imm4.c:523
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:365
get_bits
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:335
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:131
cbplo
static const uint8_t cbplo[][2]
Definition: imm4.c:66
GetBitContext
Definition: get_bits.h:108
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
decode_intra
static int decode_intra(AVCodecContext *avctx, GetBitContext *gb, AVFrame *frame)
Definition: imm4.c:200
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:118
ff_thread_once
static int ff_thread_once(char *control, void(*routine)(void))
Definition: thread.h:205
CBPHI_VLC_BITS
#define CBPHI_VLC_BITS
Definition: imm4.c:38
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
av_cold
#define av_cold
Definition: attributes.h:90
init_get_bits8
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition: get_bits.h:545
AV_FRAME_FLAG_KEY
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
Definition: frame.h:595
width
#define width
FF_CODEC_DECODE_CB
#define FF_CODEC_DECODE_CB(func)
Definition: codec_internal.h:287
decode_block
static int decode_block(AVCodecContext *avctx, GetBitContext *gb, int block, int factor, int flag, int offset, int flag2)
Definition: imm4.c:127
s
#define s(width, name)
Definition: cbs_vp9.c:198
blktype
static const uint8_t blktype[][2]
Definition: imm4.c:79
BLKTYPE_VLC_BITS
#define BLKTYPE_VLC_BITS
Definition: imm4.c:39
IMM4Context::bdsp
BswapDSPContext bdsp
Definition: imm4.c:43
AV_GET_BUFFER_FLAG_REF
#define AV_GET_BUFFER_FLAG_REF
The decoder will keep a reference to the frame and may reuse it later.
Definition: avcodec.h:425
get_sbits
static int get_sbits(GetBitContext *s, int n)
Definition: get_bits.h:320
decode_init
static av_cold int decode_init(AVCodecContext *avctx)
Definition: imm4.c:499
decode.h
cbphi_codes
static const uint8_t cbphi_codes[]
Definition: imm4.c:75
get_bits.h
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:73
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:272
frame
static AVFrame * frame
Definition: demux_decode.c:54
IMM4Context::hi
unsigned hi
Definition: imm4.c:52
AV_ONCE_INIT
#define AV_ONCE_INIT
Definition: thread.h:203
copy_block16
static void copy_block16(uint8_t *dst, const uint8_t *src, ptrdiff_t dstStride, ptrdiff_t srcStride, int h)
Definition: copy_block.h:68
ff_bswapdsp_init
av_cold void ff_bswapdsp_init(BswapDSPContext *c)
Definition: bswapdsp.c:49
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:64
AVCodecContext::color_range
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:695
AV_PICTURE_TYPE_I
@ AV_PICTURE_TYPE_I
Intra.
Definition: avutil.h:279
get_bits1
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:388
cbphi_bits
static const uint8_t cbphi_bits[]
Definition: imm4.c:71
CBPLO_VLC_BITS
#define CBPLO_VLC_BITS
Definition: imm4.c:37
get_vlc2
static av_always_inline int get_vlc2(GetBitContext *s, const VLCElem *table, int bits, int max_depth)
Parse a vlc code.
Definition: get_bits.h:652
AVOnce
#define AVOnce
Definition: thread.h:202
inter_cb
static const uint8_t inter_cb[]
Definition: imm4.c:62
IMM4Context::bitstream_size
int bitstream_size
Definition: imm4.c:48
ff_get_buffer
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1569
AVFrame::pict_type
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:446
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:365
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
AVPacket::size
int size
Definition: packet.h:523
codec_internal.h
DECLARE_ALIGNED
#define DECLARE_ALIGNED(n, t, v)
Definition: mem_internal.h:109
block_symbols
static const uint16_t block_symbols[]
Definition: imm4.c:87
VLCElem
Definition: vlc.h:32
decode_inter
static int decode_inter(AVCodecContext *avctx, GetBitContext *gb, AVFrame *frame, AVFrame *prev)
Definition: imm4.c:254
height
#define height
AV_CODEC_ID_IMM4
@ AV_CODEC_ID_IMM4
Definition: codec_id.h:287
offset
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
Definition: writing_filters.txt:86
skip_bits1
static void skip_bits1(GetBitContext *s)
Definition: get_bits.h:413
IMM4Context::prev_frame
AVFrame * prev_frame
Definition: imm4.c:46
flag
#define flag(name)
Definition: cbs_av1.c:474
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
copy_block.h
av_fast_padded_malloc
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:52
value
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default value
Definition: writing_filters.txt:86
av_frame_unref
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:576
cbphi_tab
static VLCElem cbphi_tab[1<< CBPHI_VLC_BITS]
Definition: imm4.c:112
IMM4Context::bitstream
uint8_t * bitstream
Definition: imm4.c:47
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:194
len
int len
Definition: vorbis_enc_data.h:426
AVCodecContext::height
int height
Definition: avcodec.h:618
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:657
IMM4Context::block
int16_t block[6][64]
Definition: imm4.c:55
idctdsp.h
avcodec.h
ret
ret
Definition: filter_design.txt:187
IDCTDSPContext
Definition: idctdsp.h:43
ff_imm4_decoder
const FFCodec ff_imm4_decoder
Definition: imm4.c:534
av_frame_replace
int av_frame_replace(AVFrame *dst, const AVFrame *src)
Ensure the destination frame refers to the same data described by the source frame,...
Definition: frame.c:453
AVCodecContext
main external API structure.
Definition: avcodec.h:445
IMM4Context::gb
GetBitContext gb
Definition: imm4.c:44
mode
mode
Definition: ebur128.h:83
VLC_INIT_STATIC_TABLE
#define VLC_INIT_STATIC_TABLE(vlc_table, nb_bits, nb_codes, bits, bits_wrap, bits_size, codes, codes_wrap, codes_size, flags)
Definition: vlc.h:267
factor
static const int factor[16]
Definition: vf_pp7.c:78
AV_PICTURE_TYPE_P
@ AV_PICTURE_TYPE_P
Predicted.
Definition: avutil.h:280
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
BLOCK_VLC_BITS
#define BLOCK_VLC_BITS
Definition: imm4.c:40
avpriv_request_sample
#define avpriv_request_sample(...)
Definition: tableprint_vlc.h:36
VLC_INIT_STATIC_TABLE_FROM_LENGTHS
#define VLC_INIT_STATIC_TABLE_FROM_LENGTHS(vlc_table, nb_bits, nb_codes, lens, lens_wrap, syms, syms_wrap, syms_size, offset, flags)
Definition: vlc.h:277
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
AVPacket
This structure stores compressed data.
Definition: packet.h:499
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:472
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
IMM4Context
Definition: imm4.c:42
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:618
block_tab
static VLCElem block_tab[1<< BLOCK_VLC_BITS]
Definition: imm4.c:114
AVFrame::linesize
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
Definition: frame.h:389
block
The exact code depends on how similar the blocks are and how related they are to the block
Definition: filter_design.txt:207
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
BswapDSPContext
Definition: bswapdsp.h:24
decode_flush
static void decode_flush(AVCodecContext *avctx)
Definition: imm4.c:516
decode_blocks
static int decode_blocks(AVCodecContext *avctx, GetBitContext *gb, unsigned cbp, int flag, int offset, unsigned flag2)
Definition: imm4.c:170
IMM4Context::idsp
IDCTDSPContext idsp
Definition: imm4.c:54
IMM4Context::lo
unsigned lo
Definition: imm4.c:51