FFmpeg
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
svq3.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2003 The FFmpeg Project
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 /*
22  * How to use this decoder:
23  * SVQ3 data is transported within Apple Quicktime files. Quicktime files
24  * have stsd atoms to describe media trak properties. A stsd atom for a
25  * video trak contains 1 or more ImageDescription atoms. These atoms begin
26  * with the 4-byte length of the atom followed by the codec fourcc. Some
27  * decoders need information in this atom to operate correctly. Such
28  * is the case with SVQ3. In order to get the best use out of this decoder,
29  * the calling app must make the SVQ3 ImageDescription atom available
30  * via the AVCodecContext's extradata[_size] field:
31  *
32  * AVCodecContext.extradata = pointer to ImageDescription, first characters
33  * are expected to be 'S', 'V', 'Q', and '3', NOT the 4-byte atom length
34  * AVCodecContext.extradata_size = size of ImageDescription atom memory
35  * buffer (which will be the same as the ImageDescription atom size field
36  * from the QT file, minus 4 bytes since the length is missing)
37  *
38  * You will know you have these parameters passed correctly when the decoder
39  * correctly decodes this file:
40  * http://samples.mplayerhq.hu/V-codecs/SVQ3/Vertical400kbit.sorenson3.mov
41  */
42 
43 #include <inttypes.h>
44 
45 #include "libavutil/attributes.h"
46 #include "libavutil/crc.h"
47 #include "libavutil/mem.h"
48 #include "libavutil/mem_internal.h"
49 
50 #include "codec_internal.h"
51 #include "decode.h"
52 #include "avcodec.h"
53 #include "mpegutils.h"
54 #include "h264data.h"
55 #include "h264dsp.h"
56 #include "h264pred.h"
57 #include "h264_parse.h"
58 #include "golomb.h"
59 #include "hpeldsp.h"
60 #include "mathops.h"
61 #include "rectangle.h"
62 #include "tpeldsp.h"
63 #include "videodsp.h"
64 
65 #if CONFIG_ZLIB
66 #include <zlib.h>
67 #endif
68 
69 /**
70  * @file
71  * svq3 decoder.
72  */
73 
74 #define NUM_PICS 3
75 
76 typedef struct SVQ3Frame {
78 
79  int16_t (*motion_val[2])[2];
80 
81  uint32_t *mb_type;
82 } SVQ3Frame;
83 
84 typedef struct SVQ3Context {
86 
92 
98  uint8_t *slice_buf;
99  unsigned slice_buf_size;
103  uint32_t watermark_key;
108  int qscale;
109  int cbp;
114 
118 
119  int mb_x, mb_y;
120  int mb_xy;
123  int b_stride;
124 
125  uint32_t *mb2br_xy;
126 
129 
132 
133  unsigned int top_samples_available;
135 
136  uint8_t *edge_emu_buffer;
137 
138  DECLARE_ALIGNED(16, int16_t, mv_cache)[2][5 * 8][2];
139  DECLARE_ALIGNED(8, int8_t, ref_cache)[2][5 * 8];
140  DECLARE_ALIGNED(16, int16_t, mb)[16 * 48 * 2];
141  DECLARE_ALIGNED(16, int16_t, mb_luma_dc)[3][16 * 2];
142  DECLARE_ALIGNED(8, uint8_t, non_zero_count_cache)[15 * 8];
143  uint32_t dequant4_coeff[QP_MAX_NUM + 1][16];
144  int block_offset[2 * (16 * 3)];
146 
147  uint32_t *mb_type_buf;
148  int16_t (*motion_val_buf)[2];
149 } SVQ3Context;
150 
151 #define FULLPEL_MODE 1
152 #define HALFPEL_MODE 2
153 #define THIRDPEL_MODE 3
154 #define PREDICT_MODE 4
155 
156 /* dual scan (from some older H.264 draft)
157  * o-->o-->o o
158  * | /|
159  * o o o / o
160  * | / | |/ |
161  * o o o o
162  * /
163  * o-->o-->o-->o
164  */
165 static const uint8_t svq3_scan[16] = {
166  0 + 0 * 4, 1 + 0 * 4, 2 + 0 * 4, 2 + 1 * 4,
167  2 + 2 * 4, 3 + 0 * 4, 3 + 1 * 4, 3 + 2 * 4,
168  0 + 1 * 4, 0 + 2 * 4, 1 + 1 * 4, 1 + 2 * 4,
169  0 + 3 * 4, 1 + 3 * 4, 2 + 3 * 4, 3 + 3 * 4,
170 };
171 
172 static const uint8_t luma_dc_zigzag_scan[16] = {
173  0 * 16 + 0 * 64, 1 * 16 + 0 * 64, 2 * 16 + 0 * 64, 0 * 16 + 2 * 64,
174  3 * 16 + 0 * 64, 0 * 16 + 1 * 64, 1 * 16 + 1 * 64, 2 * 16 + 1 * 64,
175  1 * 16 + 2 * 64, 2 * 16 + 2 * 64, 3 * 16 + 2 * 64, 0 * 16 + 3 * 64,
176  3 * 16 + 1 * 64, 1 * 16 + 3 * 64, 2 * 16 + 3 * 64, 3 * 16 + 3 * 64,
177 };
178 
179 static const uint8_t svq3_pred_0[25][2] = {
180  { 0, 0 },
181  { 1, 0 }, { 0, 1 },
182  { 0, 2 }, { 1, 1 }, { 2, 0 },
183  { 3, 0 }, { 2, 1 }, { 1, 2 }, { 0, 3 },
184  { 0, 4 }, { 1, 3 }, { 2, 2 }, { 3, 1 }, { 4, 0 },
185  { 4, 1 }, { 3, 2 }, { 2, 3 }, { 1, 4 },
186  { 2, 4 }, { 3, 3 }, { 4, 2 },
187  { 4, 3 }, { 3, 4 },
188  { 4, 4 }
189 };
190 
191 static const int8_t svq3_pred_1[6][6][5] = {
192  { { 2, -1, -1, -1, -1 }, { 2, 1, -1, -1, -1 }, { 1, 2, -1, -1, -1 },
193  { 2, 1, -1, -1, -1 }, { 1, 2, -1, -1, -1 }, { 1, 2, -1, -1, -1 } },
194  { { 0, 2, -1, -1, -1 }, { 0, 2, 1, 4, 3 }, { 0, 1, 2, 4, 3 },
195  { 0, 2, 1, 4, 3 }, { 2, 0, 1, 3, 4 }, { 0, 4, 2, 1, 3 } },
196  { { 2, 0, -1, -1, -1 }, { 2, 1, 0, 4, 3 }, { 1, 2, 4, 0, 3 },
197  { 2, 1, 0, 4, 3 }, { 2, 1, 4, 3, 0 }, { 1, 2, 4, 0, 3 } },
198  { { 2, 0, -1, -1, -1 }, { 2, 0, 1, 4, 3 }, { 1, 2, 0, 4, 3 },
199  { 2, 1, 0, 4, 3 }, { 2, 1, 3, 4, 0 }, { 2, 4, 1, 0, 3 } },
200  { { 0, 2, -1, -1, -1 }, { 0, 2, 1, 3, 4 }, { 1, 2, 3, 0, 4 },
201  { 2, 0, 1, 3, 4 }, { 2, 1, 3, 0, 4 }, { 2, 0, 4, 3, 1 } },
202  { { 0, 2, -1, -1, -1 }, { 0, 2, 4, 1, 3 }, { 1, 4, 2, 0, 3 },
203  { 4, 2, 0, 1, 3 }, { 2, 0, 1, 4, 3 }, { 4, 2, 1, 0, 3 } },
204 };
205 
206 static const struct {
207  uint8_t run;
208  uint8_t level;
209 } svq3_dct_tables[2][16] = {
210  { { 0, 0 }, { 0, 1 }, { 1, 1 }, { 2, 1 }, { 0, 2 }, { 3, 1 }, { 4, 1 }, { 5, 1 },
211  { 0, 3 }, { 1, 2 }, { 2, 2 }, { 6, 1 }, { 7, 1 }, { 8, 1 }, { 9, 1 }, { 0, 4 } },
212  { { 0, 0 }, { 0, 1 }, { 1, 1 }, { 0, 2 }, { 2, 1 }, { 0, 3 }, { 0, 4 }, { 0, 5 },
213  { 3, 1 }, { 4, 1 }, { 1, 2 }, { 1, 3 }, { 0, 6 }, { 0, 7 }, { 0, 8 }, { 0, 9 } }
214 };
215 
216 static const uint32_t svq3_dequant_coeff[32] = {
217  3881, 4351, 4890, 5481, 6154, 6914, 7761, 8718,
218  9781, 10987, 12339, 13828, 15523, 17435, 19561, 21873,
219  24552, 27656, 30847, 34870, 38807, 43747, 49103, 54683,
220  61694, 68745, 77615, 89113, 100253, 109366, 126635, 141533
221 };
222 
223 static void svq3_luma_dc_dequant_idct_c(int16_t *output, int16_t *input, int qp)
224 {
225  const unsigned qmul = svq3_dequant_coeff[qp];
226 #define stride 16
227  int i;
228  int temp[16];
229  static const uint8_t x_offset[4] = { 0, 1 * stride, 4 * stride, 5 * stride };
230 
231  for (i = 0; i < 4; i++) {
232  const int z0 = 13 * (input[4 * i + 0] + input[4 * i + 2]);
233  const int z1 = 13 * (input[4 * i + 0] - input[4 * i + 2]);
234  const int z2 = 7 * input[4 * i + 1] - 17 * input[4 * i + 3];
235  const int z3 = 17 * input[4 * i + 1] + 7 * input[4 * i + 3];
236 
237  temp[4 * i + 0] = z0 + z3;
238  temp[4 * i + 1] = z1 + z2;
239  temp[4 * i + 2] = z1 - z2;
240  temp[4 * i + 3] = z0 - z3;
241  }
242 
243  for (i = 0; i < 4; i++) {
244  const int offset = x_offset[i];
245  const int z0 = 13 * (temp[4 * 0 + i] + temp[4 * 2 + i]);
246  const int z1 = 13 * (temp[4 * 0 + i] - temp[4 * 2 + i]);
247  const int z2 = 7 * temp[4 * 1 + i] - 17 * temp[4 * 3 + i];
248  const int z3 = 17 * temp[4 * 1 + i] + 7 * temp[4 * 3 + i];
249 
250  output[stride * 0 + offset] = (int)((z0 + z3) * qmul + 0x80000) >> 20;
251  output[stride * 2 + offset] = (int)((z1 + z2) * qmul + 0x80000) >> 20;
252  output[stride * 8 + offset] = (int)((z1 - z2) * qmul + 0x80000) >> 20;
253  output[stride * 10 + offset] = (int)((z0 - z3) * qmul + 0x80000) >> 20;
254  }
255 }
256 #undef stride
257 
258 static void svq3_add_idct_c(uint8_t *dst, int16_t *block,
259  int stride, int qp, int dc)
260 {
261  const int qmul = svq3_dequant_coeff[qp];
262  int i;
263 
264  if (dc) {
265  dc = 13 * 13 * (dc == 1 ? 1538U* block[0]
266  : qmul * (block[0] >> 3) / 2);
267  block[0] = 0;
268  }
269 
270  for (i = 0; i < 4; i++) {
271  const int z0 = 13 * (block[0 + 4 * i] + block[2 + 4 * i]);
272  const int z1 = 13 * (block[0 + 4 * i] - block[2 + 4 * i]);
273  const int z2 = 7 * block[1 + 4 * i] - 17 * block[3 + 4 * i];
274  const int z3 = 17 * block[1 + 4 * i] + 7 * block[3 + 4 * i];
275 
276  block[0 + 4 * i] = z0 + z3;
277  block[1 + 4 * i] = z1 + z2;
278  block[2 + 4 * i] = z1 - z2;
279  block[3 + 4 * i] = z0 - z3;
280  }
281 
282  for (i = 0; i < 4; i++) {
283  const unsigned z0 = 13 * (block[i + 4 * 0] + block[i + 4 * 2]);
284  const unsigned z1 = 13 * (block[i + 4 * 0] - block[i + 4 * 2]);
285  const unsigned z2 = 7 * block[i + 4 * 1] - 17 * block[i + 4 * 3];
286  const unsigned z3 = 17 * block[i + 4 * 1] + 7 * block[i + 4 * 3];
287  const int rr = (dc + 0x80000u);
288 
289  dst[i + stride * 0] = av_clip_uint8(dst[i + stride * 0] + ((int)((z0 + z3) * qmul + rr) >> 20));
290  dst[i + stride * 1] = av_clip_uint8(dst[i + stride * 1] + ((int)((z1 + z2) * qmul + rr) >> 20));
291  dst[i + stride * 2] = av_clip_uint8(dst[i + stride * 2] + ((int)((z1 - z2) * qmul + rr) >> 20));
292  dst[i + stride * 3] = av_clip_uint8(dst[i + stride * 3] + ((int)((z0 - z3) * qmul + rr) >> 20));
293  }
294 
295  memset(block, 0, 16 * sizeof(int16_t));
296 }
297 
298 static inline int svq3_decode_block(GetBitContext *gb, int16_t *block,
299  int index, const int type)
300 {
301  static const uint8_t *const scan_patterns[4] = {
303  };
304 
305  int run, level, sign, limit;
306  unsigned vlc;
307  const int intra = 3 * type >> 2;
308  const uint8_t *const scan = scan_patterns[type];
309 
310  for (limit = (16 >> intra); index < 16; index = limit, limit += 8) {
311  for (; (vlc = get_interleaved_ue_golomb(gb)) != 0; index++) {
312  if ((int32_t)vlc < 0)
313  return -1;
314 
315  sign = (vlc & 1) ? 0 : -1;
316  vlc = vlc + 1 >> 1;
317 
318  if (type == 3) {
319  if (vlc < 3) {
320  run = 0;
321  level = vlc;
322  } else if (vlc < 4) {
323  run = 1;
324  level = 1;
325  } else {
326  run = vlc & 0x3;
327  level = (vlc + 9 >> 2) - run;
328  }
329  } else {
330  if (vlc < 16U) {
331  run = svq3_dct_tables[intra][vlc].run;
332  level = svq3_dct_tables[intra][vlc].level;
333  } else if (intra) {
334  run = vlc & 0x7;
335  level = (vlc >> 3) + ((run == 0) ? 8 : ((run < 2) ? 2 : ((run < 5) ? 0 : -1)));
336  } else {
337  run = vlc & 0xF;
338  level = (vlc >> 4) + ((run == 0) ? 4 : ((run < 3) ? 2 : ((run < 10) ? 1 : 0)));
339  }
340  }
341 
342 
343  if ((index += run) >= limit)
344  return -1;
345 
346  block[scan[index]] = (level ^ sign) - sign;
347  }
348 
349  if (type != 2) {
350  break;
351  }
352  }
353 
354  return 0;
355 }
356 
357 static av_always_inline int
358 svq3_fetch_diagonal_mv(const SVQ3Context *s, const int16_t **C,
359  int i, int list, int part_width)
360 {
361  const int topright_ref = s->ref_cache[list][i - 8 + part_width];
362 
363  if (topright_ref != PART_NOT_AVAILABLE) {
364  *C = s->mv_cache[list][i - 8 + part_width];
365  return topright_ref;
366  } else {
367  *C = s->mv_cache[list][i - 8 - 1];
368  return s->ref_cache[list][i - 8 - 1];
369  }
370 }
371 
372 /**
373  * Get the predicted MV.
374  * @param n the block index
375  * @param part_width the width of the partition (4, 8,16) -> (1, 2, 4)
376  * @param mx the x component of the predicted motion vector
377  * @param my the y component of the predicted motion vector
378  */
379 static av_always_inline void svq3_pred_motion(const SVQ3Context *s, int n,
380  int part_width, int list,
381  int ref, int *const mx, int *const my)
382 {
383  const int index8 = scan8[n];
384  const int top_ref = s->ref_cache[list][index8 - 8];
385  const int left_ref = s->ref_cache[list][index8 - 1];
386  const int16_t *const A = s->mv_cache[list][index8 - 1];
387  const int16_t *const B = s->mv_cache[list][index8 - 8];
388  const int16_t *C;
389  int diagonal_ref, match_count;
390 
391 /* mv_cache
392  * B . . A T T T T
393  * U . . L . . , .
394  * U . . L . . . .
395  * U . . L . . , .
396  * . . . L . . . .
397  */
398 
399  diagonal_ref = svq3_fetch_diagonal_mv(s, &C, index8, list, part_width);
400  match_count = (diagonal_ref == ref) + (top_ref == ref) + (left_ref == ref);
401  if (match_count > 1) { //most common
402  *mx = mid_pred(A[0], B[0], C[0]);
403  *my = mid_pred(A[1], B[1], C[1]);
404  } else if (match_count == 1) {
405  if (left_ref == ref) {
406  *mx = A[0];
407  *my = A[1];
408  } else if (top_ref == ref) {
409  *mx = B[0];
410  *my = B[1];
411  } else {
412  *mx = C[0];
413  *my = C[1];
414  }
415  } else {
416  if (top_ref == PART_NOT_AVAILABLE &&
417  diagonal_ref == PART_NOT_AVAILABLE &&
418  left_ref != PART_NOT_AVAILABLE) {
419  *mx = A[0];
420  *my = A[1];
421  } else {
422  *mx = mid_pred(A[0], B[0], C[0]);
423  *my = mid_pred(A[1], B[1], C[1]);
424  }
425  }
426 }
427 
428 static inline void svq3_mc_dir_part(SVQ3Context *s,
429  int x, int y, int width, int height,
430  int mx, int my, int dxy,
431  int thirdpel, int dir, int avg)
432 {
433  const SVQ3Frame *pic = (dir == 0) ? s->last_pic : s->next_pic;
434  uint8_t *src, *dest;
435  int i, emu = 0;
436  int blocksize = 2 - (width >> 3); // 16->0, 8->1, 4->2
437  int linesize = s->cur_pic->f->linesize[0];
438  int uvlinesize = s->cur_pic->f->linesize[1];
439 
440  mx += x;
441  my += y;
442 
443  if (mx < 0 || mx >= s->h_edge_pos - width - 1 ||
444  my < 0 || my >= s->v_edge_pos - height - 1) {
445  emu = 1;
446  mx = av_clip(mx, -16, s->h_edge_pos - width + 15);
447  my = av_clip(my, -16, s->v_edge_pos - height + 15);
448  }
449 
450  /* form component predictions */
451  dest = s->cur_pic->f->data[0] + x + y * linesize;
452  src = pic->f->data[0] + mx + my * linesize;
453 
454  if (emu) {
455  s->vdsp.emulated_edge_mc(s->edge_emu_buffer, src,
456  linesize, linesize,
457  width + 1, height + 1,
458  mx, my, s->h_edge_pos, s->v_edge_pos);
459  src = s->edge_emu_buffer;
460  }
461  if (thirdpel)
462  (avg ? s->tdsp.avg_tpel_pixels_tab
463  : s->tdsp.put_tpel_pixels_tab)[dxy](dest, src, linesize,
464  width, height);
465  else
466  (avg ? s->hdsp.avg_pixels_tab
467  : s->hdsp.put_pixels_tab)[blocksize][dxy](dest, src, linesize,
468  height);
469 
470  if (!(s->avctx->flags & AV_CODEC_FLAG_GRAY)) {
471  mx = mx + (mx < (int) x) >> 1;
472  my = my + (my < (int) y) >> 1;
473  width = width >> 1;
474  height = height >> 1;
475  blocksize++;
476 
477  for (i = 1; i < 3; i++) {
478  dest = s->cur_pic->f->data[i] + (x >> 1) + (y >> 1) * uvlinesize;
479  src = pic->f->data[i] + mx + my * uvlinesize;
480 
481  if (emu) {
482  s->vdsp.emulated_edge_mc(s->edge_emu_buffer, src,
483  uvlinesize, uvlinesize,
484  width + 1, height + 1,
485  mx, my, (s->h_edge_pos >> 1),
486  s->v_edge_pos >> 1);
487  src = s->edge_emu_buffer;
488  }
489  if (thirdpel)
490  (avg ? s->tdsp.avg_tpel_pixels_tab
491  : s->tdsp.put_tpel_pixels_tab)[dxy](dest, src,
492  uvlinesize,
493  width, height);
494  else
495  (avg ? s->hdsp.avg_pixels_tab
496  : s->hdsp.put_pixels_tab)[blocksize][dxy](dest, src,
497  uvlinesize,
498  height);
499  }
500  }
501 }
502 
503 static inline int svq3_mc_dir(SVQ3Context *s, int size, int mode,
504  int dir, int avg)
505 {
506  int i, j, k, mx, my, dx, dy, x, y;
507  const int part_width = ((size & 5) == 4) ? 4 : 16 >> (size & 1);
508  const int part_height = 16 >> ((unsigned)(size + 1) / 3);
509  const int extra_width = (mode == PREDICT_MODE) ? -16 * 6 : 0;
510  const int h_edge_pos = 6 * (s->h_edge_pos - part_width) - extra_width;
511  const int v_edge_pos = 6 * (s->v_edge_pos - part_height) - extra_width;
512 
513  for (i = 0; i < 16; i += part_height)
514  for (j = 0; j < 16; j += part_width) {
515  const int b_xy = (4 * s->mb_x + (j >> 2)) +
516  (4 * s->mb_y + (i >> 2)) * s->b_stride;
517  int dxy;
518  x = 16 * s->mb_x + j;
519  y = 16 * s->mb_y + i;
520  k = (j >> 2 & 1) + (i >> 1 & 2) +
521  (j >> 1 & 4) + (i & 8);
522 
523  if (mode != PREDICT_MODE) {
524  svq3_pred_motion(s, k, part_width >> 2, dir, 1, &mx, &my);
525  } else {
526  mx = s->next_pic->motion_val[0][b_xy][0] * 2;
527  my = s->next_pic->motion_val[0][b_xy][1] * 2;
528 
529  if (dir == 0) {
530  mx = mx * s->frame_num_offset /
531  s->prev_frame_num_offset + 1 >> 1;
532  my = my * s->frame_num_offset /
533  s->prev_frame_num_offset + 1 >> 1;
534  } else {
535  mx = mx * (s->frame_num_offset - s->prev_frame_num_offset) /
536  s->prev_frame_num_offset + 1 >> 1;
537  my = my * (s->frame_num_offset - s->prev_frame_num_offset) /
538  s->prev_frame_num_offset + 1 >> 1;
539  }
540  }
541 
542  /* clip motion vector prediction to frame border */
543  mx = av_clip(mx, extra_width - 6 * x, h_edge_pos - 6 * x);
544  my = av_clip(my, extra_width - 6 * y, v_edge_pos - 6 * y);
545 
546  /* get (optional) motion vector differential */
547  if (mode == PREDICT_MODE) {
548  dx = dy = 0;
549  } else {
550  dy = get_interleaved_se_golomb(&s->gb_slice);
551  dx = get_interleaved_se_golomb(&s->gb_slice);
552 
553  if (dx != (int16_t)dx || dy != (int16_t)dy) {
554  av_log(s->avctx, AV_LOG_ERROR, "invalid MV vlc\n");
555  return -1;
556  }
557  }
558 
559  /* compute motion vector */
560  if (mode == THIRDPEL_MODE) {
561  int fx, fy;
562  mx = (mx + 1 >> 1) + dx;
563  my = (my + 1 >> 1) + dy;
564  fx = (unsigned)(mx + 0x30000) / 3 - 0x10000;
565  fy = (unsigned)(my + 0x30000) / 3 - 0x10000;
566  dxy = (mx - 3 * fx) + 4 * (my - 3 * fy);
567 
568  svq3_mc_dir_part(s, x, y, part_width, part_height,
569  fx, fy, dxy, 1, dir, avg);
570  mx += mx;
571  my += my;
572  } else if (mode == HALFPEL_MODE || mode == PREDICT_MODE) {
573  mx = (unsigned)(mx + 1 + 0x30000) / 3 + dx - 0x10000;
574  my = (unsigned)(my + 1 + 0x30000) / 3 + dy - 0x10000;
575  dxy = (mx & 1) + 2 * (my & 1);
576 
577  svq3_mc_dir_part(s, x, y, part_width, part_height,
578  mx >> 1, my >> 1, dxy, 0, dir, avg);
579  mx *= 3;
580  my *= 3;
581  } else {
582  mx = (unsigned)(mx + 3 + 0x60000) / 6 + dx - 0x10000;
583  my = (unsigned)(my + 3 + 0x60000) / 6 + dy - 0x10000;
584 
585  svq3_mc_dir_part(s, x, y, part_width, part_height,
586  mx, my, 0, 0, dir, avg);
587  mx *= 6;
588  my *= 6;
589  }
590 
591  /* update mv_cache */
592  if (mode != PREDICT_MODE) {
593  int32_t mv = pack16to32(mx, my);
594 
595  if (part_height == 8 && i < 8) {
596  AV_WN32A(s->mv_cache[dir][scan8[k] + 1 * 8], mv);
597 
598  if (part_width == 8 && j < 8)
599  AV_WN32A(s->mv_cache[dir][scan8[k] + 1 + 1 * 8], mv);
600  }
601  if (part_width == 8 && j < 8)
602  AV_WN32A(s->mv_cache[dir][scan8[k] + 1], mv);
603  if (part_width == 4 || part_height == 4)
604  AV_WN32A(s->mv_cache[dir][scan8[k]], mv);
605  }
606 
607  /* write back motion vectors */
608  fill_rectangle(s->cur_pic->motion_val[dir][b_xy],
609  part_width >> 2, part_height >> 2, s->b_stride,
610  pack16to32(mx, my), 4);
611  }
612 
613  return 0;
614 }
615 
617  int mb_type, const int *block_offset,
618  int linesize, uint8_t *dest_y)
619 {
620  int i;
621  if (!IS_INTRA4x4(mb_type)) {
622  for (i = 0; i < 16; i++)
623  if (s->non_zero_count_cache[scan8[i]] || s->mb[i * 16]) {
624  uint8_t *const ptr = dest_y + block_offset[i];
625  svq3_add_idct_c(ptr, s->mb + i * 16, linesize,
626  s->qscale, IS_INTRA(mb_type) ? 1 : 0);
627  }
628  }
629 }
630 
632  int mb_type,
633  const int *block_offset,
634  int linesize,
635  uint8_t *dest_y)
636 {
637  int i;
638  int qscale = s->qscale;
639 
640  if (IS_INTRA4x4(mb_type)) {
641  for (i = 0; i < 16; i++) {
642  uint8_t *const ptr = dest_y + block_offset[i];
643  const int dir = s->intra4x4_pred_mode_cache[scan8[i]];
644 
645  uint8_t *topright;
646  int nnz;
647  if (dir == DIAG_DOWN_LEFT_PRED || dir == VERT_LEFT_PRED) {
648  av_assert2(s->mb_y || linesize <= block_offset[i]);
649  topright = ptr + 4 - linesize;
650  } else
651  topright = NULL;
652 
653  s->hpc.pred4x4[dir](ptr, topright, linesize);
654  nnz = s->non_zero_count_cache[scan8[i]];
655  if (nnz) {
656  svq3_add_idct_c(ptr, s->mb + i * 16, linesize, qscale, 0);
657  }
658  }
659  } else {
660  s->hpc.pred16x16[s->intra16x16_pred_mode](dest_y, linesize);
661  svq3_luma_dc_dequant_idct_c(s->mb, s->mb_luma_dc[0], qscale);
662  }
663 }
664 
666 {
667  const int mb_x = s->mb_x;
668  const int mb_y = s->mb_y;
669  const int mb_xy = s->mb_xy;
670  const int mb_type = s->cur_pic->mb_type[mb_xy];
671  uint8_t *dest_y, *dest_cb, *dest_cr;
672  int linesize, uvlinesize;
673  int i, j;
674  const int *block_offset = &s->block_offset[0];
675  const int block_h = 16 >> 1;
676 
677  linesize = s->cur_pic->f->linesize[0];
678  uvlinesize = s->cur_pic->f->linesize[1];
679 
680  dest_y = s->cur_pic->f->data[0] + (mb_x + mb_y * linesize) * 16;
681  dest_cb = s->cur_pic->f->data[1] + mb_x * 8 + mb_y * uvlinesize * block_h;
682  dest_cr = s->cur_pic->f->data[2] + mb_x * 8 + mb_y * uvlinesize * block_h;
683 
684  s->vdsp.prefetch(dest_y + (s->mb_x & 3) * 4 * linesize + 64, linesize, 4);
685  s->vdsp.prefetch(dest_cb + (s->mb_x & 7) * uvlinesize + 64, dest_cr - dest_cb, 2);
686 
687  if (IS_INTRA(mb_type)) {
688  s->hpc.pred8x8[s->chroma_pred_mode](dest_cb, uvlinesize);
689  s->hpc.pred8x8[s->chroma_pred_mode](dest_cr, uvlinesize);
690 
691  hl_decode_mb_predict_luma(s, mb_type, block_offset, linesize, dest_y);
692  }
693 
694  hl_decode_mb_idct_luma(s, mb_type, block_offset, linesize, dest_y);
695 
696  if (s->cbp & 0x30) {
697  uint8_t *dest[2] = { dest_cb, dest_cr };
698  s->h264dsp.h264_chroma_dc_dequant_idct(s->mb + 16 * 16 * 1,
699  s->dequant4_coeff[4][0]);
700  s->h264dsp.h264_chroma_dc_dequant_idct(s->mb + 16 * 16 * 2,
701  s->dequant4_coeff[4][0]);
702  for (j = 1; j < 3; j++) {
703  for (i = j * 16; i < j * 16 + 4; i++)
704  if (s->non_zero_count_cache[scan8[i]] || s->mb[i * 16]) {
705  uint8_t *const ptr = dest[j - 1] + block_offset[i];
706  svq3_add_idct_c(ptr, s->mb + i * 16,
707  uvlinesize, ff_h264_chroma_qp[0][s->qscale + 12] - 12, 2);
708  }
709  }
710  }
711 }
712 
713 static int svq3_decode_mb(SVQ3Context *s, unsigned int mb_type)
714 {
715  int i, j, k, m, dir, mode;
716  int cbp = 0;
717  uint32_t vlc;
718  int8_t *top, *left;
719  const int mb_xy = s->mb_xy;
720  const int b_xy = 4 * s->mb_x + 4 * s->mb_y * s->b_stride;
721 
722  s->top_samples_available = (s->mb_y == 0) ? 0x33FF : 0xFFFF;
723  s->left_samples_available = (s->mb_x == 0) ? 0x5F5F : 0xFFFF;
724 
725  if (mb_type == 0) { /* SKIP */
726  if (s->pict_type == AV_PICTURE_TYPE_P ||
727  s->next_pic->mb_type[mb_xy] == -1) {
728  svq3_mc_dir_part(s, 16 * s->mb_x, 16 * s->mb_y, 16, 16,
729  0, 0, 0, 0, 0, 0);
730 
731  if (s->pict_type == AV_PICTURE_TYPE_B)
732  svq3_mc_dir_part(s, 16 * s->mb_x, 16 * s->mb_y, 16, 16,
733  0, 0, 0, 0, 1, 1);
734 
735  mb_type = MB_TYPE_SKIP;
736  } else {
737  mb_type = FFMIN(s->next_pic->mb_type[mb_xy], 6);
738  if (svq3_mc_dir(s, mb_type, PREDICT_MODE, 0, 0) < 0)
739  return -1;
740  if (svq3_mc_dir(s, mb_type, PREDICT_MODE, 1, 1) < 0)
741  return -1;
742 
743  mb_type = MB_TYPE_16x16;
744  }
745  } else if (mb_type < 8) { /* INTER */
746  if (s->thirdpel_flag && s->halfpel_flag == !get_bits1(&s->gb_slice))
748  else if (s->halfpel_flag &&
749  s->thirdpel_flag == !get_bits1(&s->gb_slice))
750  mode = HALFPEL_MODE;
751  else
752  mode = FULLPEL_MODE;
753 
754  /* fill caches */
755  /* note ref_cache should contain here:
756  * ????????
757  * ???11111
758  * N??11111
759  * N??11111
760  * N??11111
761  */
762 
763  for (m = 0; m < 2; m++) {
764  if (s->mb_x > 0 && s->intra4x4_pred_mode[s->mb2br_xy[mb_xy - 1] + 6] != -1) {
765  for (i = 0; i < 4; i++)
766  AV_COPY32(s->mv_cache[m][scan8[0] - 1 + i * 8],
767  s->cur_pic->motion_val[m][b_xy - 1 + i * s->b_stride]);
768  } else {
769  for (i = 0; i < 4; i++)
770  AV_ZERO32(s->mv_cache[m][scan8[0] - 1 + i * 8]);
771  }
772  if (s->mb_y > 0) {
773  memcpy(s->mv_cache[m][scan8[0] - 1 * 8],
774  s->cur_pic->motion_val[m][b_xy - s->b_stride],
775  4 * 2 * sizeof(int16_t));
776  memset(&s->ref_cache[m][scan8[0] - 1 * 8],
777  (s->intra4x4_pred_mode[s->mb2br_xy[mb_xy - s->mb_stride]] == -1) ? PART_NOT_AVAILABLE : 1, 4);
778 
779  if (s->mb_x < s->mb_width - 1) {
780  AV_COPY32(s->mv_cache[m][scan8[0] + 4 - 1 * 8],
781  s->cur_pic->motion_val[m][b_xy - s->b_stride + 4]);
782  s->ref_cache[m][scan8[0] + 4 - 1 * 8] =
783  (s->intra4x4_pred_mode[s->mb2br_xy[mb_xy - s->mb_stride + 1] + 6] == -1 ||
784  s->intra4x4_pred_mode[s->mb2br_xy[mb_xy - s->mb_stride]] == -1) ? PART_NOT_AVAILABLE : 1;
785  } else
786  s->ref_cache[m][scan8[0] + 4 - 1 * 8] = PART_NOT_AVAILABLE;
787  if (s->mb_x > 0) {
788  AV_COPY32(s->mv_cache[m][scan8[0] - 1 - 1 * 8],
789  s->cur_pic->motion_val[m][b_xy - s->b_stride - 1]);
790  s->ref_cache[m][scan8[0] - 1 - 1 * 8] =
791  (s->intra4x4_pred_mode[s->mb2br_xy[mb_xy - s->mb_stride - 1] + 3] == -1) ? PART_NOT_AVAILABLE : 1;
792  } else
793  s->ref_cache[m][scan8[0] - 1 - 1 * 8] = PART_NOT_AVAILABLE;
794  } else
795  memset(&s->ref_cache[m][scan8[0] - 1 * 8 - 1],
796  PART_NOT_AVAILABLE, 8);
797 
798  if (s->pict_type != AV_PICTURE_TYPE_B)
799  break;
800  }
801 
802  /* decode motion vector(s) and form prediction(s) */
803  if (s->pict_type == AV_PICTURE_TYPE_P) {
804  if (svq3_mc_dir(s, mb_type - 1, mode, 0, 0) < 0)
805  return -1;
806  } else { /* AV_PICTURE_TYPE_B */
807  if (mb_type != 2) {
808  if (svq3_mc_dir(s, 0, mode, 0, 0) < 0)
809  return -1;
810  } else {
811  for (i = 0; i < 4; i++)
812  memset(s->cur_pic->motion_val[0][b_xy + i * s->b_stride],
813  0, 4 * 2 * sizeof(int16_t));
814  }
815  if (mb_type != 1) {
816  if (svq3_mc_dir(s, 0, mode, 1, mb_type == 3) < 0)
817  return -1;
818  } else {
819  for (i = 0; i < 4; i++)
820  memset(s->cur_pic->motion_val[1][b_xy + i * s->b_stride],
821  0, 4 * 2 * sizeof(int16_t));
822  }
823  }
824 
825  mb_type = MB_TYPE_16x16;
826  } else if (mb_type == 8 || mb_type == 33) { /* INTRA4x4 */
827  int8_t *i4x4 = s->intra4x4_pred_mode + s->mb2br_xy[s->mb_xy];
828  int8_t *i4x4_cache = s->intra4x4_pred_mode_cache;
829 
830  memset(s->intra4x4_pred_mode_cache, -1, 8 * 5 * sizeof(int8_t));
831 
832  if (mb_type == 8) {
833  if (s->mb_x > 0) {
834  for (i = 0; i < 4; i++)
835  s->intra4x4_pred_mode_cache[scan8[0] - 1 + i * 8] = s->intra4x4_pred_mode[s->mb2br_xy[mb_xy - 1] + 6 - i];
836  if (s->intra4x4_pred_mode_cache[scan8[0] - 1] == -1)
837  s->left_samples_available = 0x5F5F;
838  }
839  if (s->mb_y > 0) {
840  s->intra4x4_pred_mode_cache[4 + 8 * 0] = s->intra4x4_pred_mode[s->mb2br_xy[mb_xy - s->mb_stride] + 0];
841  s->intra4x4_pred_mode_cache[5 + 8 * 0] = s->intra4x4_pred_mode[s->mb2br_xy[mb_xy - s->mb_stride] + 1];
842  s->intra4x4_pred_mode_cache[6 + 8 * 0] = s->intra4x4_pred_mode[s->mb2br_xy[mb_xy - s->mb_stride] + 2];
843  s->intra4x4_pred_mode_cache[7 + 8 * 0] = s->intra4x4_pred_mode[s->mb2br_xy[mb_xy - s->mb_stride] + 3];
844 
845  if (s->intra4x4_pred_mode_cache[4 + 8 * 0] == -1)
846  s->top_samples_available = 0x33FF;
847  }
848 
849  /* decode prediction codes for luma blocks */
850  for (i = 0; i < 16; i += 2) {
851  vlc = get_interleaved_ue_golomb(&s->gb_slice);
852 
853  if (vlc >= 25U) {
854  av_log(s->avctx, AV_LOG_ERROR,
855  "luma prediction:%"PRIu32"\n", vlc);
856  return -1;
857  }
858 
859  left = &s->intra4x4_pred_mode_cache[scan8[i] - 1];
860  top = &s->intra4x4_pred_mode_cache[scan8[i] - 8];
861 
862  left[1] = svq3_pred_1[top[0] + 1][left[0] + 1][svq3_pred_0[vlc][0]];
863  left[2] = svq3_pred_1[top[1] + 1][left[1] + 1][svq3_pred_0[vlc][1]];
864 
865  if (left[1] == -1 || left[2] == -1) {
866  av_log(s->avctx, AV_LOG_ERROR, "weird prediction\n");
867  return -1;
868  }
869  }
870  } else { /* mb_type == 33, DC_128_PRED block type */
871  for (i = 0; i < 4; i++)
872  memset(&s->intra4x4_pred_mode_cache[scan8[0] + 8 * i], DC_PRED, 4);
873  }
874 
875  AV_COPY32(i4x4, i4x4_cache + 4 + 8 * 4);
876  i4x4[4] = i4x4_cache[7 + 8 * 3];
877  i4x4[5] = i4x4_cache[7 + 8 * 2];
878  i4x4[6] = i4x4_cache[7 + 8 * 1];
879 
880  if (mb_type == 8) {
881  ff_h264_check_intra4x4_pred_mode(s->intra4x4_pred_mode_cache,
882  s->avctx, s->top_samples_available,
883  s->left_samples_available);
884 
885  s->top_samples_available = (s->mb_y == 0) ? 0x33FF : 0xFFFF;
886  s->left_samples_available = (s->mb_x == 0) ? 0x5F5F : 0xFFFF;
887  } else {
888  for (i = 0; i < 4; i++)
889  memset(&s->intra4x4_pred_mode_cache[scan8[0] + 8 * i], DC_128_PRED, 4);
890 
891  s->top_samples_available = 0x33FF;
892  s->left_samples_available = 0x5F5F;
893  }
894 
895  mb_type = MB_TYPE_INTRA4x4;
896  } else { /* INTRA16x16 */
897  dir = ff_h264_i_mb_type_info[mb_type - 8].pred_mode;
898  dir = (dir >> 1) ^ 3 * (dir & 1) ^ 1;
899 
900  if ((s->intra16x16_pred_mode = ff_h264_check_intra_pred_mode(s->avctx, s->top_samples_available,
901  s->left_samples_available, dir, 0)) < 0) {
902  av_log(s->avctx, AV_LOG_ERROR, "ff_h264_check_intra_pred_mode < 0\n");
903  return s->intra16x16_pred_mode;
904  }
905 
906  cbp = ff_h264_i_mb_type_info[mb_type - 8].cbp;
907  mb_type = MB_TYPE_INTRA16x16;
908  }
909 
910  if (!IS_INTER(mb_type) && s->pict_type != AV_PICTURE_TYPE_I) {
911  for (i = 0; i < 4; i++)
912  memset(s->cur_pic->motion_val[0][b_xy + i * s->b_stride],
913  0, 4 * 2 * sizeof(int16_t));
914  if (s->pict_type == AV_PICTURE_TYPE_B) {
915  for (i = 0; i < 4; i++)
916  memset(s->cur_pic->motion_val[1][b_xy + i * s->b_stride],
917  0, 4 * 2 * sizeof(int16_t));
918  }
919  }
920  if (!IS_INTRA4x4(mb_type)) {
921  memset(s->intra4x4_pred_mode + s->mb2br_xy[mb_xy], DC_PRED, 8);
922  }
923  if (!IS_SKIP(mb_type) || s->pict_type == AV_PICTURE_TYPE_B) {
924  memset(s->non_zero_count_cache + 8, 0, 14 * 8 * sizeof(uint8_t));
925  }
926 
927  if (!IS_INTRA16x16(mb_type) &&
928  (!IS_SKIP(mb_type) || s->pict_type == AV_PICTURE_TYPE_B)) {
929  if ((vlc = get_interleaved_ue_golomb(&s->gb_slice)) >= 48U){
930  av_log(s->avctx, AV_LOG_ERROR, "cbp_vlc=%"PRIu32"\n", vlc);
931  return -1;
932  }
933 
934  cbp = IS_INTRA(mb_type) ? ff_h264_golomb_to_intra4x4_cbp[vlc]
936  }
937  if (IS_INTRA16x16(mb_type) ||
938  (s->pict_type != AV_PICTURE_TYPE_I && s->adaptive_quant && cbp)) {
939  s->qscale += get_interleaved_se_golomb(&s->gb_slice);
940 
941  if (s->qscale > 31u) {
942  av_log(s->avctx, AV_LOG_ERROR, "qscale:%d\n", s->qscale);
943  return -1;
944  }
945  }
946  if (IS_INTRA16x16(mb_type)) {
947  AV_ZERO128(s->mb_luma_dc[0] + 0);
948  AV_ZERO128(s->mb_luma_dc[0] + 8);
949  if (svq3_decode_block(&s->gb_slice, s->mb_luma_dc[0], 0, 1)) {
950  av_log(s->avctx, AV_LOG_ERROR,
951  "error while decoding intra luma dc\n");
952  return -1;
953  }
954  }
955 
956  if (cbp) {
957  const int index = IS_INTRA16x16(mb_type) ? 1 : 0;
958  const int type = ((s->qscale < 24 && IS_INTRA4x4(mb_type)) ? 2 : 1);
959 
960  for (i = 0; i < 4; i++)
961  if ((cbp & (1 << i))) {
962  for (j = 0; j < 4; j++) {
963  k = index ? (1 * (j & 1) + 2 * (i & 1) +
964  2 * (j & 2) + 4 * (i & 2))
965  : (4 * i + j);
966  s->non_zero_count_cache[scan8[k]] = 1;
967 
968  if (svq3_decode_block(&s->gb_slice, &s->mb[16 * k], index, type)) {
969  av_log(s->avctx, AV_LOG_ERROR,
970  "error while decoding block\n");
971  return -1;
972  }
973  }
974  }
975 
976  if ((cbp & 0x30)) {
977  for (i = 1; i < 3; ++i)
978  if (svq3_decode_block(&s->gb_slice, &s->mb[16 * 16 * i], 0, 3)) {
979  av_log(s->avctx, AV_LOG_ERROR,
980  "error while decoding chroma dc block\n");
981  return -1;
982  }
983 
984  if ((cbp & 0x20)) {
985  for (i = 1; i < 3; i++) {
986  for (j = 0; j < 4; j++) {
987  k = 16 * i + j;
988  s->non_zero_count_cache[scan8[k]] = 1;
989 
990  if (svq3_decode_block(&s->gb_slice, &s->mb[16 * k], 1, 1)) {
991  av_log(s->avctx, AV_LOG_ERROR,
992  "error while decoding chroma ac block\n");
993  return -1;
994  }
995  }
996  }
997  }
998  }
999  }
1000 
1001  s->cbp = cbp;
1002  s->cur_pic->mb_type[mb_xy] = mb_type;
1003 
1004  if (IS_INTRA(mb_type))
1005  s->chroma_pred_mode = ff_h264_check_intra_pred_mode(s->avctx, s->top_samples_available,
1006  s->left_samples_available, DC_PRED8x8, 1);
1007 
1008  return 0;
1009 }
1010 
1012 {
1013  SVQ3Context *s = avctx->priv_data;
1014  const int mb_xy = s->mb_xy;
1015  int i, header;
1016  unsigned slice_id;
1017 
1018  header = get_bits(&s->gb, 8);
1019 
1020  if (((header & 0x9F) != 1 && (header & 0x9F) != 2) || (header & 0x60) == 0) {
1021  /* TODO: what? */
1022  av_log(avctx, AV_LOG_ERROR, "unsupported slice header (%02X)\n", header);
1023  return -1;
1024  } else {
1025  int slice_bits, slice_bytes, slice_length;
1026  int length = header >> 5 & 3;
1027 
1028  slice_length = show_bits(&s->gb, 8 * length);
1029  slice_bits = slice_length * 8;
1030  slice_bytes = slice_length + length - 1;
1031 
1032  skip_bits(&s->gb, 8);
1033 
1034  av_fast_padded_malloc(&s->slice_buf, &s->slice_buf_size, slice_bytes);
1035  if (!s->slice_buf)
1036  return AVERROR(ENOMEM);
1037 
1038  if (slice_bytes * 8LL > get_bits_left(&s->gb)) {
1039  av_log(avctx, AV_LOG_ERROR, "slice after bitstream end\n");
1040  return AVERROR_INVALIDDATA;
1041  }
1042  memcpy(s->slice_buf, s->gb.buffer + s->gb.index / 8, slice_bytes);
1043 
1044  if (length > 0) {
1045  memmove(s->slice_buf, &s->slice_buf[slice_length], length - 1);
1046  }
1047 
1048  if (s->watermark_key) {
1049  uint32_t header = AV_RL32(&s->slice_buf[1]);
1050  AV_WL32(&s->slice_buf[1], header ^ s->watermark_key);
1051  }
1052  init_get_bits(&s->gb_slice, s->slice_buf, slice_bits);
1053 
1054  skip_bits_long(&s->gb, slice_bytes * 8);
1055  }
1056 
1057  if ((slice_id = get_interleaved_ue_golomb(&s->gb_slice)) >= 3) {
1058  av_log(s->avctx, AV_LOG_ERROR, "illegal slice type %u \n", slice_id);
1059  return -1;
1060  }
1061 
1062  s->slice_type = ff_h264_golomb_to_pict_type[slice_id];
1063 
1064  if ((header & 0x9F) == 2) {
1065  i = (s->mb_num < 64) ? 6 : (1 + av_log2(s->mb_num - 1));
1066  get_bits(&s->gb_slice, i);
1067  } else if (get_bits1(&s->gb_slice)) {
1068  avpriv_report_missing_feature(s->avctx, "Media key encryption");
1069  return AVERROR_PATCHWELCOME;
1070  }
1071 
1072  s->slice_num = get_bits(&s->gb_slice, 8);
1073  s->qscale = get_bits(&s->gb_slice, 5);
1074  s->adaptive_quant = get_bits1(&s->gb_slice);
1075 
1076  /* unknown fields */
1077  skip_bits1(&s->gb_slice);
1078 
1079  if (s->has_watermark)
1080  skip_bits1(&s->gb_slice);
1081 
1082  skip_bits1(&s->gb_slice);
1083  skip_bits(&s->gb_slice, 2);
1084 
1085  if (skip_1stop_8data_bits(&s->gb_slice) < 0)
1086  return AVERROR_INVALIDDATA;
1087 
1088  /* reset intra predictors and invalidate motion vector references */
1089  if (s->mb_x > 0) {
1090  memset(s->intra4x4_pred_mode + s->mb2br_xy[mb_xy - 1] + 3,
1091  -1, 4 * sizeof(int8_t));
1092  memset(s->intra4x4_pred_mode + s->mb2br_xy[mb_xy - s->mb_x],
1093  -1, 8 * sizeof(int8_t) * s->mb_x);
1094  }
1095  if (s->mb_y > 0) {
1096  memset(s->intra4x4_pred_mode + s->mb2br_xy[mb_xy - s->mb_stride],
1097  -1, 8 * sizeof(int8_t) * (s->mb_width - s->mb_x));
1098 
1099  if (s->mb_x > 0)
1100  s->intra4x4_pred_mode[s->mb2br_xy[mb_xy - s->mb_stride - 1] + 3] = -1;
1101  }
1102 
1103  return 0;
1104 }
1105 
1107 {
1108  int q, x;
1109  const int max_qp = 51;
1110 
1111  for (q = 0; q < max_qp + 1; q++) {
1112  int shift = ff_h264_quant_div6[q] + 2;
1113  int idx = ff_h264_quant_rem6[q];
1114  for (x = 0; x < 16; x++)
1115  s->dequant4_coeff[q][(x >> 2) | ((x << 2) & 0xF)] =
1116  ((uint32_t)ff_h264_dequant4_coeff_init[idx][(x & 1) + ((x >> 2) & 1)] * 16) << shift;
1117  }
1118 }
1119 
1121  int seqh_offset)
1122 {
1123  const uint8_t *extradata = avctx->extradata + seqh_offset;
1124  unsigned int size = AV_RB32(extradata + 4);
1125  GetBitContext gb;
1126  int ret;
1127 
1128  if (size > avctx->extradata_size - seqh_offset - 8)
1129  return AVERROR_INVALIDDATA;
1130  extradata += 8;
1131  init_get_bits(&gb, extradata, size * 8);
1132 
1133  /* 'frame size code' and optional 'width, height' */
1134  int frame_size_code = get_bits(&gb, 3);
1135  int w, h;
1136  switch (frame_size_code) {
1137  case 0:
1138  w = 160;
1139  h = 120;
1140  break;
1141  case 1:
1142  w = 128;
1143  h = 96;
1144  break;
1145  case 2:
1146  w = 176;
1147  h = 144;
1148  break;
1149  case 3:
1150  w = 352;
1151  h = 288;
1152  break;
1153  case 4:
1154  w = 704;
1155  h = 576;
1156  break;
1157  case 5:
1158  w = 240;
1159  h = 180;
1160  break;
1161  case 6:
1162  w = 320;
1163  h = 240;
1164  break;
1165  case 7:
1166  w = get_bits(&gb, 12);
1167  h = get_bits(&gb, 12);
1168  break;
1169  }
1170  ret = ff_set_dimensions(avctx, w, h);
1171  if (ret < 0)
1172  return ret;
1173 
1174  s->halfpel_flag = get_bits1(&gb);
1175  s->thirdpel_flag = get_bits1(&gb);
1176 
1177  /* unknown fields */
1178  int unk0 = get_bits1(&gb);
1179  int unk1 = get_bits1(&gb);
1180  int unk2 = get_bits1(&gb);
1181  int unk3 = get_bits1(&gb);
1182 
1183  s->low_delay = get_bits1(&gb);
1184  avctx->has_b_frames = !s->low_delay;
1185 
1186  /* unknown field */
1187  int unk4 = get_bits1(&gb);
1188 
1189  av_log(avctx, AV_LOG_DEBUG, "Unknown fields %d %d %d %d %d\n",
1190  unk0, unk1, unk2, unk3, unk4);
1191 
1192  if (skip_1stop_8data_bits(&gb) < 0)
1193  return AVERROR_INVALIDDATA;
1194 
1195  s->has_watermark = get_bits1(&gb);
1196 
1197  if (!s->has_watermark)
1198  return 0;
1199 
1200 #if CONFIG_ZLIB
1201  unsigned watermark_width = get_interleaved_ue_golomb(&gb);
1202  unsigned watermark_height = get_interleaved_ue_golomb(&gb);
1203  int u1 = get_interleaved_ue_golomb(&gb);
1204  int u2 = get_bits(&gb, 8);
1205  int u3 = get_bits(&gb, 2);
1206  int u4 = get_interleaved_ue_golomb(&gb);
1207  unsigned long buf_len = watermark_width *
1208  watermark_height * 4;
1209  int offset = get_bits_count(&gb) + 7 >> 3;
1210 
1211  if (watermark_height <= 0 ||
1212  get_bits_left(&gb) <= 0 ||
1213  (uint64_t)watermark_width * 4 > UINT_MAX / watermark_height)
1214  return AVERROR_INVALIDDATA;
1215 
1216  av_log(avctx, AV_LOG_DEBUG, "watermark size: %ux%u\n",
1217  watermark_width, watermark_height);
1218  av_log(avctx, AV_LOG_DEBUG,
1219  "u1: %x u2: %x u3: %x compressed data size: %d offset: %d\n",
1220  u1, u2, u3, u4, offset);
1221 
1222  uint8_t *buf = av_malloc(buf_len);
1223  if (!buf)
1224  return AVERROR(ENOMEM);
1225 
1226  if (uncompress(buf, &buf_len, extradata + offset,
1227  size - offset) != Z_OK) {
1228  av_log(avctx, AV_LOG_ERROR,
1229  "could not uncompress watermark logo\n");
1230  av_free(buf);
1231  return AVERROR_EXTERNAL;
1232  }
1233  s->watermark_key = av_bswap16(av_crc(av_crc_get_table(AV_CRC_16_CCITT), 0, buf, buf_len));
1234 
1235  s->watermark_key = s->watermark_key << 16 | s->watermark_key;
1236  av_log(avctx, AV_LOG_DEBUG,
1237  "watermark key %#"PRIx32"\n", s->watermark_key);
1238  av_free(buf);
1239 
1240  return 0;
1241 #else
1242  av_log(avctx, AV_LOG_ERROR,
1243  "this svq3 file contains watermark which need zlib support compiled in\n");
1244  return AVERROR(ENOSYS);
1245 #endif
1246 }
1247 
1249 {
1250  SVQ3Context *s = avctx->priv_data;
1251  int m, x, y;
1252  unsigned char *extradata;
1253  int ret;
1254 
1255  s->cur_pic = &s->frames[0];
1256  s->last_pic = &s->frames[1];
1257  s->next_pic = &s->frames[2];
1258 
1259  s->cur_pic->f = av_frame_alloc();
1260  s->last_pic->f = av_frame_alloc();
1261  s->next_pic->f = av_frame_alloc();
1262  if (!s->cur_pic->f || !s->last_pic->f || !s->next_pic->f)
1263  return AVERROR(ENOMEM);
1264 
1265  ff_h264dsp_init(&s->h264dsp, 8, 1);
1266  ff_h264_pred_init(&s->hpc, AV_CODEC_ID_SVQ3, 8, 1);
1267  ff_videodsp_init(&s->vdsp, 8);
1268 
1269 
1270  avctx->bits_per_raw_sample = 8;
1271 
1272  ff_hpeldsp_init(&s->hdsp, avctx->flags);
1273  ff_tpeldsp_init(&s->tdsp);
1274 
1275  avctx->pix_fmt = AV_PIX_FMT_YUVJ420P;
1276  avctx->color_range = AVCOL_RANGE_JPEG;
1277 
1278  s->avctx = avctx;
1279  s->halfpel_flag = 1;
1280  s->thirdpel_flag = 1;
1281  s->has_watermark = 0;
1282 
1283  /* prowl for the "SEQH" marker in the extradata */
1284  extradata = (unsigned char *)avctx->extradata;
1285  if (extradata) {
1286  for (m = 0; m + 8 < avctx->extradata_size; m++) {
1287  if (!memcmp(extradata, "SEQH", 4)) {
1288  /* if a match was found, parse the extra data */
1289  ret = svq3_decode_extradata(avctx, s, m);
1290  if (ret < 0)
1291  return ret;
1292  break;
1293  }
1294  extradata++;
1295  }
1296  }
1297 
1298  s->mb_width = (avctx->width + 15) / 16;
1299  s->mb_height = (avctx->height + 15) / 16;
1300  s->mb_stride = s->mb_width + 1;
1301  s->mb_num = s->mb_width * s->mb_height;
1302  s->b_stride = 4 * s->mb_width;
1303  s->h_edge_pos = s->mb_width * 16;
1304  s->v_edge_pos = s->mb_height * 16;
1305 
1306  const unsigned big_mb_num = s->mb_stride * (s->mb_height + 2) + 1;
1307 
1308  s->mb_type_buf = av_calloc(big_mb_num, NUM_PICS * sizeof(*s->mb_type_buf));
1309  if (!s->mb_type_buf)
1310  return AVERROR(ENOMEM);
1311  uint32_t *mb_type_buf = s->mb_type_buf + 2 * s->mb_stride + 1;
1312 
1313  const unsigned b4_stride = s->mb_width * 4 + 1;
1314  const unsigned b4_array_size = b4_stride * s->mb_height * 4;
1315  const unsigned motion_val_buf_size = b4_array_size + 4;
1316 
1317  s->motion_val_buf = av_calloc(motion_val_buf_size,
1318  NUM_PICS * 2 * sizeof(*s->motion_val_buf));
1319  if (!s->motion_val_buf)
1320  return AVERROR(ENOMEM);
1321  int16_t (*motion_val_buf)[2] = s->motion_val_buf + 4;
1322 
1323  for (size_t i = 0; i < NUM_PICS; ++i) {
1324  SVQ3Frame *const pic = &s->frames[i];
1325 
1326  pic->mb_type = mb_type_buf;
1327  mb_type_buf += big_mb_num;
1328  for (size_t j = 0; j < FF_ARRAY_ELEMS(pic->motion_val); ++j) {
1329  pic->motion_val[j] = motion_val_buf;
1330  motion_val_buf += motion_val_buf_size;
1331  }
1332  }
1333 
1334  s->intra4x4_pred_mode = av_mallocz(s->mb_stride * 2 * 8);
1335  if (!s->intra4x4_pred_mode)
1336  return AVERROR(ENOMEM);
1337 
1338  s->mb2br_xy = av_mallocz(s->mb_stride * (s->mb_height + 1) *
1339  sizeof(*s->mb2br_xy));
1340  if (!s->mb2br_xy)
1341  return AVERROR(ENOMEM);
1342 
1343  for (y = 0; y < s->mb_height; y++)
1344  for (x = 0; x < s->mb_width; x++) {
1345  const int mb_xy = x + y * s->mb_stride;
1346 
1347  s->mb2br_xy[mb_xy] = 8 * (mb_xy % (2 * s->mb_stride));
1348  }
1349 
1351 
1352  return 0;
1353 }
1354 
1355 static int get_buffer(AVCodecContext *avctx, SVQ3Frame *pic)
1356 {
1357  SVQ3Context *s = avctx->priv_data;
1358  int ret = ff_get_buffer(avctx, pic->f,
1359  (s->pict_type != AV_PICTURE_TYPE_B) ?
1361  if (ret < 0)
1362  return ret;
1363 
1364  if (!s->edge_emu_buffer) {
1365  s->edge_emu_buffer = av_calloc(pic->f->linesize[0], 17);
1366  if (!s->edge_emu_buffer)
1367  return AVERROR(ENOMEM);
1368  }
1369 
1370  return 0;
1371 }
1372 
1374 {
1375  av_log(avctx, AV_LOG_ERROR, "Missing reference frame.\n");
1376  av_frame_unref(pic->f);
1377  int ret = get_buffer(avctx, pic);
1378  if (ret < 0)
1379  return ret;
1380 
1381  memset(pic->f->data[0], 0, avctx->height * pic->f->linesize[0]);
1382  memset(pic->f->data[1], 0x80, (avctx->height / 2) *
1383  pic->f->linesize[1]);
1384  memset(pic->f->data[2], 0x80, (avctx->height / 2) *
1385  pic->f->linesize[2]);
1386 
1387  return 0;
1388 }
1389 
1390 static int svq3_decode_frame(AVCodecContext *avctx, AVFrame *rframe,
1391  int *got_frame, AVPacket *avpkt)
1392 {
1393  SVQ3Context *s = avctx->priv_data;
1394  int buf_size = avpkt->size;
1395  int left;
1396  int ret, m, i;
1397 
1398  /* special case for last picture */
1399  if (buf_size == 0) {
1400  if (s->next_pic->f->data[0] && !s->low_delay) {
1401  av_frame_move_ref(rframe, s->next_pic->f);
1402  *got_frame = 1;
1403  }
1404  return 0;
1405  }
1406 
1407  s->mb_x = s->mb_y = s->mb_xy = 0;
1408 
1409  ret = init_get_bits8(&s->gb, avpkt->data, avpkt->size);
1410  if (ret < 0)
1411  return ret;
1412 
1413  ret = svq3_decode_slice_header(avctx);
1414  if (ret < 0)
1415  return ret;
1416 
1417  if (avpkt->size < s->mb_width * s->mb_height / 8)
1418  return AVERROR_INVALIDDATA;
1419 
1420  s->pict_type = s->slice_type;
1421 
1422  if (s->pict_type != AV_PICTURE_TYPE_B)
1423  FFSWAP(SVQ3Frame*, s->next_pic, s->last_pic);
1424 
1425  av_frame_unref(s->cur_pic->f);
1426 
1427  /* for skipping the frame */
1428  s->cur_pic->f->pict_type = s->pict_type;
1429  if (s->pict_type == AV_PICTURE_TYPE_I)
1430  s->cur_pic->f->flags |= AV_FRAME_FLAG_KEY;
1431  else
1432  s->cur_pic->f->flags &= ~AV_FRAME_FLAG_KEY;
1433 
1434  ret = get_buffer(avctx, s->cur_pic);
1435  if (ret < 0)
1436  return ret;
1437 
1438  for (i = 0; i < 16; i++) {
1439  s->block_offset[i] = (4 * ((scan8[i] - scan8[0]) & 7)) + 4 * s->cur_pic->f->linesize[0] * ((scan8[i] - scan8[0]) >> 3);
1440  s->block_offset[48 + i] = (4 * ((scan8[i] - scan8[0]) & 7)) + 8 * s->cur_pic->f->linesize[0] * ((scan8[i] - scan8[0]) >> 3);
1441  }
1442  for (i = 0; i < 16; i++) {
1443  s->block_offset[16 + i] =
1444  s->block_offset[32 + i] = (4 * ((scan8[i] - scan8[0]) & 7)) + 4 * s->cur_pic->f->linesize[1] * ((scan8[i] - scan8[0]) >> 3);
1445  s->block_offset[48 + 16 + i] =
1446  s->block_offset[48 + 32 + i] = (4 * ((scan8[i] - scan8[0]) & 7)) + 8 * s->cur_pic->f->linesize[1] * ((scan8[i] - scan8[0]) >> 3);
1447  }
1448 
1449  if (s->pict_type != AV_PICTURE_TYPE_I) {
1450  if (!s->last_pic->f->data[0]) {
1451  ret = alloc_dummy_frame(avctx, s->last_pic);
1452  if (ret < 0)
1453  return ret;
1454  }
1455 
1456  if (s->pict_type == AV_PICTURE_TYPE_B && !s->next_pic->f->data[0]) {
1457  ret = alloc_dummy_frame(avctx, s->next_pic);
1458  if (ret < 0)
1459  return ret;
1460  }
1461  }
1462 
1463  if (avctx->debug & FF_DEBUG_PICT_INFO)
1464  av_log(s->avctx, AV_LOG_DEBUG,
1465  "%c hpel:%d, tpel:%d aqp:%d qp:%d, slice_num:%02X\n",
1466  av_get_picture_type_char(s->pict_type),
1467  s->halfpel_flag, s->thirdpel_flag,
1468  s->adaptive_quant, s->qscale, s->slice_num);
1469 
1470  if (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type == AV_PICTURE_TYPE_B ||
1471  avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type != AV_PICTURE_TYPE_I ||
1472  avctx->skip_frame >= AVDISCARD_ALL)
1473  return 0;
1474 
1475  if (s->pict_type == AV_PICTURE_TYPE_B) {
1476  s->frame_num_offset = s->slice_num - s->prev_frame_num;
1477 
1478  if (s->frame_num_offset < 0)
1479  s->frame_num_offset += 256;
1480  if (s->frame_num_offset == 0 ||
1481  s->frame_num_offset >= s->prev_frame_num_offset) {
1482  av_log(s->avctx, AV_LOG_ERROR, "error in B-frame picture id\n");
1483  return -1;
1484  }
1485  } else {
1486  s->prev_frame_num = s->frame_num;
1487  s->frame_num = s->slice_num;
1488  s->prev_frame_num_offset = s->frame_num - s->prev_frame_num;
1489 
1490  if (s->prev_frame_num_offset < 0)
1491  s->prev_frame_num_offset += 256;
1492  }
1493 
1494  for (m = 0; m < 2; m++) {
1495  int i;
1496  for (i = 0; i < 4; i++) {
1497  int j;
1498  for (j = -1; j < 4; j++)
1499  s->ref_cache[m][scan8[0] + 8 * i + j] = 1;
1500  if (i < 3)
1501  s->ref_cache[m][scan8[0] + 8 * i + j] = PART_NOT_AVAILABLE;
1502  }
1503  }
1504 
1505  for (s->mb_y = 0; s->mb_y < s->mb_height; s->mb_y++) {
1506  for (s->mb_x = 0; s->mb_x < s->mb_width; s->mb_x++) {
1507  unsigned mb_type;
1508  s->mb_xy = s->mb_x + s->mb_y * s->mb_stride;
1509 
1510  if ((get_bits_left(&s->gb_slice)) <= 7) {
1511  if (((get_bits_count(&s->gb_slice) & 7) == 0 ||
1512  show_bits(&s->gb_slice, get_bits_left(&s->gb_slice) & 7) == 0)) {
1513 
1514  ret = svq3_decode_slice_header(avctx);
1515  if (ret < 0)
1516  return ret;
1517  }
1518  if (s->slice_type != s->pict_type) {
1519  avpriv_request_sample(avctx, "non constant slice type");
1520  }
1521  /* TODO: support s->mb_skip_run */
1522  }
1523 
1524  mb_type = get_interleaved_ue_golomb(&s->gb_slice);
1525 
1526  if (s->pict_type == AV_PICTURE_TYPE_I)
1527  mb_type += 8;
1528  else if (s->pict_type == AV_PICTURE_TYPE_B && mb_type >= 4)
1529  mb_type += 4;
1530  if (mb_type > 33 || svq3_decode_mb(s, mb_type)) {
1531  av_log(s->avctx, AV_LOG_ERROR,
1532  "error while decoding MB %d %d\n", s->mb_x, s->mb_y);
1533  return -1;
1534  }
1535 
1536  if (mb_type != 0 || s->cbp)
1537  hl_decode_mb(s);
1538 
1539  if (s->pict_type != AV_PICTURE_TYPE_B && !s->low_delay)
1540  s->cur_pic->mb_type[s->mb_x + s->mb_y * s->mb_stride] =
1541  (s->pict_type == AV_PICTURE_TYPE_P && mb_type < 8) ? (mb_type - 1) : -1;
1542  }
1543 
1544  ff_draw_horiz_band(avctx, s->cur_pic->f,
1545  s->last_pic->f->data[0] ? s->last_pic->f : NULL,
1546  16 * s->mb_y, 16, PICT_FRAME, 0,
1547  s->low_delay);
1548  }
1549 
1550  left = buf_size*8 - get_bits_count(&s->gb_slice);
1551 
1552  if (s->mb_y != s->mb_height || s->mb_x != s->mb_width) {
1553  av_log(avctx, AV_LOG_INFO, "frame num %"PRId64" incomplete pic x %d y %d left %d\n", avctx->frame_num, s->mb_y, s->mb_x, left);
1554  //av_hex_dump(stderr, buf+buf_size-8, 8);
1555  }
1556 
1557  if (left < 0) {
1558  av_log(avctx, AV_LOG_ERROR, "frame num %"PRId64" left %d\n", avctx->frame_num, left);
1559  return -1;
1560  }
1561 
1562  if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay)
1563  ret = av_frame_ref(rframe, s->cur_pic->f);
1564  else if (s->last_pic->f->data[0])
1565  ret = av_frame_ref(rframe, s->last_pic->f);
1566  if (ret < 0)
1567  return ret;
1568 
1569  /* Do not output the last pic after seeking. */
1570  if (s->last_pic->f->data[0] || s->low_delay)
1571  *got_frame = 1;
1572 
1573  if (s->pict_type != AV_PICTURE_TYPE_B) {
1574  FFSWAP(SVQ3Frame*, s->cur_pic, s->next_pic);
1575  } else {
1576  av_frame_unref(s->cur_pic->f);
1577  }
1578 
1579  return buf_size;
1580 }
1581 
1583 {
1584  SVQ3Context *s = avctx->priv_data;
1585 
1586  for (int i = 0; i < NUM_PICS; i++)
1587  av_frame_free(&s->frames[i].f);
1588  av_freep(&s->motion_val_buf);
1589  av_freep(&s->mb_type_buf);
1590  av_freep(&s->slice_buf);
1591  av_freep(&s->intra4x4_pred_mode);
1592  av_freep(&s->edge_emu_buffer);
1593  av_freep(&s->mb2br_xy);
1594 
1595  return 0;
1596 }
1597 
1599  .p.name = "svq3",
1600  CODEC_LONG_NAME("Sorenson Vector Quantizer 3 / Sorenson Video 3 / SVQ3"),
1601  .p.type = AVMEDIA_TYPE_VIDEO,
1602  .p.id = AV_CODEC_ID_SVQ3,
1603  .priv_data_size = sizeof(SVQ3Context),
1607  .p.capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND |
1610  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
1611 };
PICT_FRAME
#define PICT_FRAME
Definition: mpegutils.h:33
SVQ3Context::frame_num
int frame_num
Definition: svq3.c:110
SVQ3Context::edge_emu_buffer
uint8_t * edge_emu_buffer
Definition: svq3.c:136
IS_INTRA4x4
#define IS_INTRA4x4(a)
Definition: mpegutils.h:69
A
#define A(x)
Definition: vpx_arith.h:28
ff_draw_horiz_band
void ff_draw_horiz_band(AVCodecContext *avctx, const AVFrame *cur, const AVFrame *last, int y, int h, int picture_structure, int first_field, int low_delay)
Draw a horizontal band if supported.
Definition: mpegutils.c:54
svq3_dequant_coeff
static const uint32_t svq3_dequant_coeff[32]
Definition: svq3.c:216
SVQ3Context::next_pic
SVQ3Frame * next_pic
Definition: svq3.c:94
skip_bits_long
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
Definition: get_bits.h:261
SVQ3Context::slice_type
enum AVPictureType slice_type
Definition: svq3.c:116
SVQ3Context::gb_slice
GetBitContext gb_slice
Definition: svq3.c:97
SVQ3Context::vdsp
VideoDSPContext vdsp
Definition: svq3.c:91
SVQ3Context::slice_num
int slice_num
Definition: svq3.c:107
level
uint8_t level
Definition: svq3.c:208
av_clip
#define av_clip
Definition: common.h:100
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
get_bits_left
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:678
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
DC_PRED8x8
#define DC_PRED8x8
Definition: h264pred.h:68
svq3_decode_slice_header
static int svq3_decode_slice_header(AVCodecContext *avctx)
Definition: svq3.c:1011
SVQ3Context::frames
SVQ3Frame frames[NUM_PICS]
Definition: svq3.c:145
AV_WL32
#define AV_WL32(p, v)
Definition: intreadwrite.h:422
mem_internal.h
SVQ3Context::avctx
AVCodecContext * avctx
Definition: svq3.c:85
DC_128_PRED
@ DC_128_PRED
Definition: vp9.h:58
SVQ3Context::mb_num
int mb_num
Definition: svq3.c:122
SVQ3Context::v_edge_pos
int v_edge_pos
Definition: svq3.c:106
AVPictureType
AVPictureType
Definition: avutil.h:276
ff_h264_chroma_qp
const uint8_t ff_h264_chroma_qp[7][QP_MAX_NUM+1]
Definition: h264data.c:203
mv
static const int8_t mv[256][2]
Definition: 4xm.c:81
output
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce output
Definition: filter_design.txt:225
SVQ3Context::left_samples_available
unsigned int left_samples_available
Definition: svq3.c:134
get_bits_count
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:249
get_interleaved_ue_golomb
static unsigned get_interleaved_ue_golomb(GetBitContext *gb)
Definition: golomb.h:143
ff_h264_golomb_to_inter_cbp
const uint8_t ff_h264_golomb_to_inter_cbp[48]
Definition: h264data.c:48
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:63
h264_parse.h
mode
Definition: swscale.c:56
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:410
SVQ3Context::h_edge_pos
int h_edge_pos
Definition: svq3.c:105
w
uint8_t w
Definition: llviddspenc.c:38
AVCOL_RANGE_JPEG
@ AVCOL_RANGE_JPEG
Full range content.
Definition: pixfmt.h:750
IMbInfo::cbp
uint8_t cbp
Definition: h264data.h:37
AVPacket::data
uint8_t * data
Definition: packet.h:535
DC_PRED
@ DC_PRED
Definition: vp9.h:48
MB_TYPE_INTRA4x4
#define MB_TYPE_INTRA4x4
Definition: mpegutils.h:38
SVQ3Context::slice_buf
uint8_t * slice_buf
Definition: svq3.c:98
VERT_LEFT_PRED
@ VERT_LEFT_PRED
Definition: vp9.h:53
MB_TYPE_16x16
#define MB_TYPE_16x16
Definition: mpegutils.h:41
SVQ3Context::mb
int16_t mb[16 *48 *2]
Definition: svq3.c:140
PREDICT_MODE
#define PREDICT_MODE
Definition: svq3.c:154
FFCodec
Definition: codec_internal.h:127
svq3_dct_tables
static const struct @248 svq3_dct_tables[2][16]
AV_WN32A
#define AV_WN32A(p, v)
Definition: intreadwrite.h:534
ff_h264_golomb_to_intra4x4_cbp
const uint8_t ff_h264_golomb_to_intra4x4_cbp[48]
Definition: h264data.c:42
SVQ3Context::frame_num_offset
int frame_num_offset
Definition: svq3.c:111
mpegutils.h
MB_TYPE_INTRA16x16
#define MB_TYPE_INTRA16x16
Definition: mpegutils.h:39
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:91
init_get_bits
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:497
SVQ3Context::slice_buf_size
unsigned slice_buf_size
Definition: svq3.c:99
FF_DEBUG_PICT_INFO
#define FF_DEBUG_PICT_INFO
Definition: avcodec.h:1375
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:431
get_buffer
static int get_buffer(AVCodecContext *avctx, SVQ3Frame *pic)
Definition: svq3.c:1355
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:31
NUM_PICS
#define NUM_PICS
Definition: svq3.c:74
crc.h
skip_bits
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:364
golomb.h
exp golomb vlc stuff
close
static av_cold void close(AVCodecParserContext *s)
Definition: apv_parser.c:135
get_bits
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:318
mx
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t mx
Definition: dsp.h:57
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:131
SVQ3Context::last_pic
SVQ3Frame * last_pic
Definition: svq3.c:95
SVQ3Context::qscale
int qscale
Definition: svq3.c:108
u
#define u(width, name, range_min, range_max)
Definition: cbs_apv.c:83
AVCodecContext::skip_frame
enum AVDiscard skip_frame
Skip decoding for selected frames.
Definition: avcodec.h:1662
GetBitContext
Definition: get_bits.h:108
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:488
SVQ3Context::tdsp
TpelDSPContext tdsp
Definition: svq3.c:90
ff_videodsp_init
av_cold void ff_videodsp_init(VideoDSPContext *ctx, int bpc)
Definition: videodsp.c:39
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
scan8
static const uint8_t scan8[16 *3+3]
Definition: h264_parse.h:40
SVQ3Context::thirdpel_flag
int thirdpel_flag
Definition: svq3.c:101
ff_h264_golomb_to_pict_type
const uint8_t ff_h264_golomb_to_pict_type[5]
Definition: h264data.c:37
pack16to32
static av_always_inline uint32_t pack16to32(unsigned a, unsigned b)
Definition: h264_parse.h:127
alloc_dummy_frame
static av_cold int alloc_dummy_frame(AVCodecContext *avctx, SVQ3Frame *pic)
Definition: svq3.c:1373
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:51
SVQ3Context::intra4x4_pred_mode_cache
int8_t intra4x4_pred_mode_cache[5 *8]
Definition: svq3.c:130
C
s EdgeDetect Foobar g libavfilter vf_edgedetect c libavfilter vf_foobar c edit libavfilter and add an entry for foobar following the pattern of the other filters edit libavfilter allfilters and add an entry for foobar following the pattern of the other filters configure make j< whatever > ffmpeg ffmpeg i you should get a foobar png with Lena edge detected That s your new playground is ready Some little details about what s going which in turn will define variables for the build system and the C
Definition: writing_filters.txt:58
SVQ3Context::gb
GetBitContext gb
Definition: svq3.c:96
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:210
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
av_cold
#define av_cold
Definition: attributes.h:90
SVQ3Context::cbp
int cbp
Definition: svq3.c:109
init_get_bits8
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition: get_bits.h:528
AV_FRAME_FLAG_KEY
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
Definition: frame.h:625
FULLPEL_MODE
#define FULLPEL_MODE
Definition: svq3.c:151
SVQ3Context::mb_y
int mb_y
Definition: svq3.c:119
SVQ3Context::mb_x
int mb_x
Definition: svq3.c:119
SVQ3Context::adaptive_quant
int adaptive_quant
Definition: svq3.c:104
AVCodecContext::extradata_size
int extradata_size
Definition: avcodec.h:515
AVCodecContext::has_b_frames
int has_b_frames
Size of the frame reordering buffer in the decoder.
Definition: avcodec.h:697
FF_CODEC_DECODE_CB
#define FF_CODEC_DECODE_CB(func)
Definition: codec_internal.h:341
s
#define s(width, name)
Definition: cbs_vp9.c:198
TpelDSPContext
thirdpel DSP context
Definition: tpeldsp.h:42
SVQ3Context::pict_type
enum AVPictureType pict_type
Definition: svq3.c:115
AV_ZERO32
#define AV_ZERO32(d)
Definition: intreadwrite.h:662
svq3_mc_dir
static int svq3_mc_dir(SVQ3Context *s, int size, int mode, int dir, int avg)
Definition: svq3.c:503
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:411
ff_tpeldsp_init
av_cold void ff_tpeldsp_init(TpelDSPContext *c)
Definition: tpeldsp.c:312
QP_MAX_NUM
#define QP_MAX_NUM
Definition: h264.h:27
h264data.h
B
#define B
Definition: huffyuv.h:42
AVCodecContext::bits_per_raw_sample
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
Definition: avcodec.h:1553
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:231
svq3_pred_motion
static av_always_inline void svq3_pred_motion(const SVQ3Context *s, int n, int part_width, int list, int ref, int *const mx, int *const my)
Get the predicted MV.
Definition: svq3.c:379
decode.h
IS_SKIP
#define IS_SKIP(a)
Definition: mpegutils.h:75
SVQ3Context::top_samples_available
unsigned int top_samples_available
Definition: svq3.c:133
AV_CODEC_ID_SVQ3
@ AV_CODEC_ID_SVQ3
Definition: codec_id.h:75
SVQ3Context::b_stride
int b_stride
Definition: svq3.c:123
SVQ3Context::prev_frame_num_offset
int prev_frame_num_offset
Definition: svq3.c:112
SVQ3Context::h264dsp
H264DSPContext h264dsp
Definition: svq3.c:87
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:326
ff_hpeldsp_init
av_cold void ff_hpeldsp_init(HpelDSPContext *c, int flags)
Definition: hpeldsp.c:337
my
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t my
Definition: dsp.h:57
IMbInfo::pred_mode
uint8_t pred_mode
Definition: h264data.h:36
if
if(ret)
Definition: filter_design.txt:179
SVQ3Frame::motion_val
int16_t(*[2] motion_val)[2]
Definition: svq3.c:79
AVDISCARD_ALL
@ AVDISCARD_ALL
discard all
Definition: defs.h:229
NULL
#define NULL
Definition: coverity.c:32
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:64
run
uint8_t run
Definition: svq3.c:207
AVCodecContext::color_range
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:669
SVQ3Context::mb_width
int mb_width
Definition: svq3.c:121
AV_PIX_FMT_YUVJ420P
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition: pixfmt.h:85
SVQ3Context::mb2br_xy
uint32_t * mb2br_xy
Definition: svq3.c:125
AV_PICTURE_TYPE_I
@ AV_PICTURE_TYPE_I
Intra.
Definition: avutil.h:278
get_bits1
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:371
h264dsp.h
mathops.h
list
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 list
Definition: filter_design.txt:25
ff_h264_chroma_dc_scan
const uint8_t ff_h264_chroma_dc_scan[4]
Definition: h264data.c:54
SVQ3Context
Definition: svq3.c:84
AV_ZERO128
#define AV_ZERO128(d)
Definition: intreadwrite.h:670
SVQ3Context::mb_luma_dc
int16_t mb_luma_dc[3][16 *2]
Definition: svq3.c:141
tpeldsp.h
index
int index
Definition: gxfenc.c:90
hl_decode_mb_idct_luma
static av_always_inline void hl_decode_mb_idct_luma(SVQ3Context *s, int mb_type, const int *block_offset, int linesize, uint8_t *dest_y)
Definition: svq3.c:616
HpelDSPContext
Half-pel DSP context.
Definition: hpeldsp.h:45
H264DSPContext
Context for storing H.264 DSP functions.
Definition: h264dsp.h:42
SVQ3Context::intra16x16_pred_mode
int intra16x16_pred_mode
Definition: svq3.c:128
IS_INTRA
#define IS_INTRA(x, y)
AVDISCARD_NONKEY
@ AVDISCARD_NONKEY
discard all frames except keyframes
Definition: defs.h:228
SVQ3Context::hpc
H264PredContext hpc
Definition: svq3.c:88
ff_get_buffer
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1635
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:368
init_dequant4_coeff_table
static void init_dequant4_coeff_table(SVQ3Context *s)
Definition: svq3.c:1106
ff_zigzag_scan
const uint8_t ff_zigzag_scan[16+1]
Definition: mathtables.c:148
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
svq3_fetch_diagonal_mv
static av_always_inline int svq3_fetch_diagonal_mv(const SVQ3Context *s, const int16_t **C, int i, int list, int part_width)
Definition: svq3.c:358
AV_CODEC_FLAG_GRAY
#define AV_CODEC_FLAG_GRAY
Only decode/encode grayscale.
Definition: avcodec.h:302
AVPacket::size
int size
Definition: packet.h:536
dc
Tag MUST be and< 10hcoeff half pel interpolation filter coefficients, hcoeff[0] are the 2 middle coefficients[1] are the next outer ones and so on, resulting in a filter like:...eff[2], hcoeff[1], hcoeff[0], hcoeff[0], hcoeff[1], hcoeff[2] ... the sign of the coefficients is not explicitly stored but alternates after each coeff and coeff[0] is positive, so ...,+,-,+,-,+,+,-,+,-,+,... hcoeff[0] is not explicitly stored but found by subtracting the sum of all stored coefficients with signs from 32 hcoeff[0]=32 - hcoeff[1] - hcoeff[2] - ... a good choice for hcoeff and htaps is htaps=6 hcoeff={40,-10, 2} an alternative which requires more computations at both encoder and decoder side and may or may not be better is htaps=8 hcoeff={42,-14, 6,-2}ref_frames minimum of the number of available reference frames and max_ref_frames for example the first frame after a key frame always has ref_frames=1spatial_decomposition_type wavelet type 0 is a 9/7 symmetric compact integer wavelet 1 is a 5/3 symmetric compact integer wavelet others are reserved stored as delta from last, last is reset to 0 if always_reset||keyframeqlog quality(logarithmic quantizer scale) stored as delta from last, last is reset to 0 if always_reset||keyframemv_scale stored as delta from last, last is reset to 0 if always_reset||keyframe FIXME check that everything works fine if this changes between framesqbias dequantization bias stored as delta from last, last is reset to 0 if always_reset||keyframeblock_max_depth maximum depth of the block tree stored as delta from last, last is reset to 0 if always_reset||keyframequant_table quantization tableHighlevel bitstream structure:==============================--------------------------------------------|Header|--------------------------------------------|------------------------------------|||Block0||||split?||||yes no||||......... intra?||||:Block01 :yes no||||:Block02 :....... ..........||||:Block03 ::y DC ::ref index:||||:Block04 ::cb DC ::motion x :||||......... :cr DC ::motion y :||||....... ..........|||------------------------------------||------------------------------------|||Block1|||...|--------------------------------------------|------------ ------------ ------------|||Y subbands||Cb subbands||Cr subbands||||--- ---||--- ---||--- ---|||||LL0||HL0||||LL0||HL0||||LL0||HL0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||LH0||HH0||||LH0||HH0||||LH0||HH0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HL1||LH1||||HL1||LH1||||HL1||LH1|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HH1||HL2||||HH1||HL2||||HH1||HL2|||||...||...||...|||------------ ------------ ------------|--------------------------------------------Decoding process:=================------------|||Subbands|------------||||------------|Intra DC||||LL0 subband prediction ------------|\ Dequantization ------------------- \||Reference frames|\ IDWT|------- -------|Motion \|||Frame 0||Frame 1||Compensation . OBMC v -------|------- -------|--------------. \------> Frame n output Frame Frame<----------------------------------/|...|------------------- Range Coder:============Binary Range Coder:------------------- The implemented range coder is an adapted version based upon "Range encoding: an algorithm for removing redundancy from a digitised message." by G. N. N. Martin. The symbols encoded by the Snow range coder are bits(0|1). The associated probabilities are not fix but change depending on the symbol mix seen so far. bit seen|new state ---------+----------------------------------------------- 0|256 - state_transition_table[256 - old_state];1|state_transition_table[old_state];state_transition_table={ 0, 0, 0, 0, 0, 0, 0, 0, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 190, 191, 192, 194, 194, 195, 196, 197, 198, 199, 200, 201, 202, 202, 204, 205, 206, 207, 208, 209, 209, 210, 211, 212, 213, 215, 215, 216, 217, 218, 219, 220, 220, 222, 223, 224, 225, 226, 227, 227, 229, 229, 230, 231, 232, 234, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 248, 0, 0, 0, 0, 0, 0, 0};FIXME Range Coding of integers:------------------------- FIXME Neighboring Blocks:===================left and top are set to the respective blocks unless they are outside of the image in which case they are set to the Null block top-left is set to the top left block unless it is outside of the image in which case it is set to the left block if this block has no larger parent block or it is at the left side of its parent block and the top right block is not outside of the image then the top right block is used for top-right else the top-left block is used Null block y, cb, cr are 128 level, ref, mx and my are 0 Motion Vector Prediction:=========================1. the motion vectors of all the neighboring blocks are scaled to compensate for the difference of reference frames scaled_mv=(mv *(256 *(current_reference+1)/(mv.reference+1))+128)> the median of the scaled top and top right vectors is used as motion vector prediction the used motion vector is the sum of the predictor and(mvx_diff, mvy_diff) *mv_scale Intra DC Prediction block[y][x] dc[1]
Definition: snow.txt:400
height
#define height
Definition: dsp.h:89
av_frame_ref
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:276
codec_internal.h
DECLARE_ALIGNED
#define DECLARE_ALIGNED(n, t, v)
Definition: mem_internal.h:104
shift
static int shift(int a, int b)
Definition: bonk.c:261
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:87
rectangle.h
hl_decode_mb
static void hl_decode_mb(SVQ3Context *s)
Definition: svq3.c:665
get_interleaved_se_golomb
static int get_interleaved_se_golomb(GetBitContext *gb)
Definition: golomb.h:301
size
int size
Definition: twinvq_data.h:10344
AV_RB32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
Definition: bytestream.h:96
avpriv_report_missing_feature
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
MB_TYPE_SKIP
#define MB_TYPE_SKIP
Definition: mpegutils.h:61
avg
#define avg(a, b, c, d)
Definition: colorspacedsp_template.c:28
header
static const uint8_t header[24]
Definition: sdr2.c:68
av_crc_get_table
const AVCRC * av_crc_get_table(AVCRCId crc_id)
Get an initialized standard CRC table.
Definition: crc.c:374
AVERROR_EXTERNAL
#define AVERROR_EXTERNAL
Generic error in an external library.
Definition: error.h:59
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
attributes.h
ff_h264_quant_rem6
const uint8_t ff_h264_quant_rem6[QP_MAX_NUM+1]
Definition: h264data.c:174
skip_bits1
static void skip_bits1(GetBitContext *s)
Definition: get_bits.h:396
IS_INTRA16x16
#define IS_INTRA16x16(a)
Definition: mpegutils.h:70
hl_decode_mb_predict_luma
static av_always_inline void hl_decode_mb_predict_luma(SVQ3Context *s, int mb_type, const int *block_offset, int linesize, uint8_t *dest_y)
Definition: svq3.c:631
input
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some input
Definition: filter_design.txt:172
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:221
SVQ3Context::prev_frame_num
int prev_frame_num
Definition: svq3.c:113
svq3_add_idct_c
static void svq3_add_idct_c(uint8_t *dst, int16_t *block, int stride, int qp, int dc)
Definition: svq3.c:258
av_get_picture_type_char
char av_get_picture_type_char(enum AVPictureType pict_type)
Return a single letter to describe the given picture type pict_type.
Definition: utils.c:40
av_assert2
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition: avassert.h:68
svq3_luma_dc_dequant_idct_c
static void svq3_luma_dc_dequant_idct_c(int16_t *output, int16_t *input, int qp)
Definition: svq3.c:223
stride
#define stride
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
AV_CRC_16_CCITT
@ AV_CRC_16_CCITT
Definition: crc.h:51
AVCodecContext::extradata
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
Definition: avcodec.h:514
show_bits
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
Definition: get_bits.h:354
SVQ3Frame
Definition: svq3.c:76
THIRDPEL_MODE
#define THIRDPEL_MODE
Definition: svq3.c:153
SVQ3Context::mv_cache
int16_t mv_cache[2][5 *8][2]
Definition: svq3.c:138
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:53
av_always_inline
#define av_always_inline
Definition: attributes.h:49
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
av_frame_move_ref
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everything contained in src to dst and reset src.
Definition: frame.c:521
av_frame_unref
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:494
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:256
AV_COPY32
#define AV_COPY32(d, s)
Definition: intreadwrite.h:634
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:179
svq3_decode_frame
static int svq3_decode_frame(AVCodecContext *avctx, AVFrame *rframe, int *got_frame, AVPacket *avpkt)
Definition: svq3.c:1390
svq3_decode_extradata
static av_cold int svq3_decode_extradata(AVCodecContext *avctx, SVQ3Context *s, int seqh_offset)
Definition: svq3.c:1120
SVQ3Context::non_zero_count_cache
uint8_t non_zero_count_cache[15 *8]
Definition: svq3.c:142
AVCodecContext::height
int height
Definition: avcodec.h:592
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:631
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:264
svq3_decode_mb
static int svq3_decode_mb(SVQ3Context *s, unsigned int mb_type)
Definition: svq3.c:713
svq3_scan
static const uint8_t svq3_scan[16]
Definition: svq3.c:165
avcodec.h
limit
static double limit(double x)
Definition: vf_pseudocolor.c:142
ff_h264dsp_init
av_cold void ff_h264dsp_init(H264DSPContext *c, const int bit_depth, const int chroma_format_idc)
Definition: h264dsp.c:66
SVQ3Context::halfpel_flag
int halfpel_flag
Definition: svq3.c:100
AVCodecContext::frame_num
int64_t frame_num
Frame counter, set by libavcodec.
Definition: avcodec.h:1878
mid_pred
#define mid_pred
Definition: mathops.h:97
svq3_pred_1
static const int8_t svq3_pred_1[6][6][5]
Definition: svq3.c:191
ret
ret
Definition: filter_design.txt:187
FFSWAP
#define FFSWAP(type, a, b)
Definition: macros.h:52
SVQ3Frame::mb_type
uint32_t * mb_type
Definition: svq3.c:81
SVQ3Context::mb_height
int mb_height
Definition: svq3.c:121
SVQ3Context::hdsp
HpelDSPContext hdsp
Definition: svq3.c:89
SVQ3Context::low_delay
int low_delay
Definition: svq3.c:117
h264pred.h
left
Tag MUST be and< 10hcoeff half pel interpolation filter coefficients, hcoeff[0] are the 2 middle coefficients[1] are the next outer ones and so on, resulting in a filter like:...eff[2], hcoeff[1], hcoeff[0], hcoeff[0], hcoeff[1], hcoeff[2] ... the sign of the coefficients is not explicitly stored but alternates after each coeff and coeff[0] is positive, so ...,+,-,+,-,+,+,-,+,-,+,... hcoeff[0] is not explicitly stored but found by subtracting the sum of all stored coefficients with signs from 32 hcoeff[0]=32 - hcoeff[1] - hcoeff[2] - ... a good choice for hcoeff and htaps is htaps=6 hcoeff={40,-10, 2} an alternative which requires more computations at both encoder and decoder side and may or may not be better is htaps=8 hcoeff={42,-14, 6,-2}ref_frames minimum of the number of available reference frames and max_ref_frames for example the first frame after a key frame always has ref_frames=1spatial_decomposition_type wavelet type 0 is a 9/7 symmetric compact integer wavelet 1 is a 5/3 symmetric compact integer wavelet others are reserved stored as delta from last, last is reset to 0 if always_reset||keyframeqlog quality(logarithmic quantizer scale) stored as delta from last, last is reset to 0 if always_reset||keyframemv_scale stored as delta from last, last is reset to 0 if always_reset||keyframe FIXME check that everything works fine if this changes between framesqbias dequantization bias stored as delta from last, last is reset to 0 if always_reset||keyframeblock_max_depth maximum depth of the block tree stored as delta from last, last is reset to 0 if always_reset||keyframequant_table quantization tableHighlevel bitstream structure:==============================--------------------------------------------|Header|--------------------------------------------|------------------------------------|||Block0||||split?||||yes no||||......... intra?||||:Block01 :yes no||||:Block02 :....... ..........||||:Block03 ::y DC ::ref index:||||:Block04 ::cb DC ::motion x :||||......... :cr DC ::motion y :||||....... ..........|||------------------------------------||------------------------------------|||Block1|||...|--------------------------------------------|------------ ------------ ------------|||Y subbands||Cb subbands||Cr subbands||||--- ---||--- ---||--- ---|||||LL0||HL0||||LL0||HL0||||LL0||HL0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||LH0||HH0||||LH0||HH0||||LH0||HH0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HL1||LH1||||HL1||LH1||||HL1||LH1|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HH1||HL2||||HH1||HL2||||HH1||HL2|||||...||...||...|||------------ ------------ ------------|--------------------------------------------Decoding process:=================------------|||Subbands|------------||||------------|Intra DC||||LL0 subband prediction ------------|\ Dequantization ------------------- \||Reference frames|\ IDWT|------- -------|Motion \|||Frame 0||Frame 1||Compensation . OBMC v -------|------- -------|--------------. \------> Frame n output Frame Frame<----------------------------------/|...|------------------- Range Coder:============Binary Range Coder:------------------- The implemented range coder is an adapted version based upon "Range encoding: an algorithm for removing redundancy from a digitised message." by G. N. N. Martin. The symbols encoded by the Snow range coder are bits(0|1). The associated probabilities are not fix but change depending on the symbol mix seen so far. bit seen|new state ---------+----------------------------------------------- 0|256 - state_transition_table[256 - old_state];1|state_transition_table[old_state];state_transition_table={ 0, 0, 0, 0, 0, 0, 0, 0, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 190, 191, 192, 194, 194, 195, 196, 197, 198, 199, 200, 201, 202, 202, 204, 205, 206, 207, 208, 209, 209, 210, 211, 212, 213, 215, 215, 216, 217, 218, 219, 220, 220, 222, 223, 224, 225, 226, 227, 227, 229, 229, 230, 231, 232, 234, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 248, 0, 0, 0, 0, 0, 0, 0};FIXME Range Coding of integers:------------------------- FIXME Neighboring Blocks:===================left and top are set to the respective blocks unless they are outside of the image in which case they are set to the Null block top-left is set to the top left block unless it is outside of the image in which case it is set to the left block if this block has no larger parent block or it is at the left side of its parent block and the top right block is not outside of the image then the top right block is used for top-right else the top-left block is used Null block y, cb, cr are 128 level, ref, mx and my are 0 Motion Vector Prediction:=========================1. the motion vectors of all the neighboring blocks are scaled to compensate for the difference of reference frames scaled_mv=(mv *(256 *(current_reference+1)/(mv.reference+1))+128)> the median of the scaled left
Definition: snow.txt:386
svq3_decode_block
static int svq3_decode_block(GetBitContext *gb, int16_t *block, int index, const int type)
Definition: svq3.c:298
AV_RL32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
Definition: bytestream.h:92
U
#define U(x)
Definition: vpx_arith.h:37
skip_1stop_8data_bits
static int skip_1stop_8data_bits(GetBitContext *gb)
Definition: get_bits.h:683
AVCodecContext
main external API structure.
Definition: avcodec.h:431
ff_h264_dequant4_coeff_init
const uint8_t ff_h264_dequant4_coeff_init[6][3]
Definition: h264data.c:152
SVQ3Frame::f
AVFrame * f
Definition: svq3.c:77
SVQ3Context::mb_type_buf
uint32_t * mb_type_buf
Definition: svq3.c:147
SVQ3Context::block_offset
int block_offset[2 *(16 *3)]
Definition: svq3.c:144
ff_h264_pred_init
av_cold void ff_h264_pred_init(H264PredContext *h, int codec_id, const int bit_depth, int chroma_format_idc)
Set the intra prediction function pointers.
Definition: h264pred.c:437
AV_PICTURE_TYPE_B
@ AV_PICTURE_TYPE_B
Bi-dir predicted.
Definition: avutil.h:280
SVQ3Context::motion_val_buf
int16_t(* motion_val_buf)[2]
Definition: svq3.c:148
av_crc
uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length)
Calculate the CRC of a block.
Definition: crc.c:392
mode
mode
Definition: ebur128.h:83
ff_h264_check_intra4x4_pred_mode
int ff_h264_check_intra4x4_pred_mode(int8_t *pred_mode_cache, void *logctx, int top_samples_available, int left_samples_available)
Check if the top & left blocks are available if needed and change the dc mode so it only uses the ava...
Definition: h264_parse.c:134
ff_h264_i_mb_type_info
const IMbInfo ff_h264_i_mb_type_info[26]
Definition: h264data.c:66
fill_rectangle
static void fill_rectangle(int x, int y, int w, int h)
Definition: ffplay.c:825
SVQ3Context::chroma_pred_mode
int chroma_pred_mode
Definition: svq3.c:127
SVQ3Context::watermark_key
uint32_t watermark_key
Definition: svq3.c:103
SVQ3Context::mb_xy
int mb_xy
Definition: svq3.c:120
ref
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:117
temp
else temp
Definition: vf_mcdeint.c:271
AV_CODEC_CAP_DELAY
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Definition: codec.h:76
luma_dc_zigzag_scan
static const uint8_t luma_dc_zigzag_scan[16]
Definition: svq3.c:172
PART_NOT_AVAILABLE
#define PART_NOT_AVAILABLE
Definition: h264pred.h:89
av_clip_uint8
#define av_clip_uint8
Definition: common.h:106
ff_h264_quant_div6
const uint8_t ff_h264_quant_div6[QP_MAX_NUM+1]
Definition: h264data.c:182
VideoDSPContext
Definition: videodsp.h:40
AVCodecContext::debug
int debug
debug
Definition: avcodec.h:1374
H264PredContext
Context for storing H.264 prediction functions.
Definition: h264pred.h:94
svq3_mc_dir_part
static void svq3_mc_dir_part(SVQ3Context *s, int x, int y, int width, int height, int mx, int my, int dxy, int thirdpel, int dir, int avg)
Definition: svq3.c:428
AV_PICTURE_TYPE_P
@ AV_PICTURE_TYPE_P
Predicted.
Definition: avutil.h:279
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:200
IS_INTER
#define IS_INTER(a)
Definition: mpegutils.h:73
mem.h
svq3_decode_end
static av_cold int svq3_decode_end(AVCodecContext *avctx)
Definition: svq3.c:1582
avpriv_request_sample
#define avpriv_request_sample(...)
Definition: tableprint_vlc.h:37
SVQ3Context::dequant4_coeff
uint32_t dequant4_coeff[QP_MAX_NUM+1][16]
Definition: svq3.c:143
SVQ3Context::ref_cache
int8_t ref_cache[2][5 *8]
Definition: svq3.c:139
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
AVPacket
This structure stores compressed data.
Definition: packet.h:512
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:458
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
videodsp.h
SVQ3Context::mb_stride
int mb_stride
Definition: svq3.c:122
DIAG_DOWN_LEFT_PRED
@ DIAG_DOWN_LEFT_PRED
Definition: vp9.h:49
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:592
int32_t
int32_t
Definition: audioconvert.c:56
hpeldsp.h
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:455
AV_CODEC_CAP_DRAW_HORIZ_BAND
#define AV_CODEC_CAP_DRAW_HORIZ_BAND
Decoder can use draw_horiz_band callback.
Definition: codec.h:44
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
svq3_decode_init
static av_cold int svq3_decode_init(AVCodecContext *avctx)
Definition: svq3.c:1248
h
h
Definition: vp9dsp_template.c:2070
width
#define width
Definition: dsp.h:89
AVDISCARD_NONREF
@ AVDISCARD_NONREF
discard all non reference
Definition: defs.h:225
av_bswap16
#define av_bswap16
Definition: bswap.h:28
ff_svq3_decoder
const FFCodec ff_svq3_decoder
Definition: svq3.c:1598
SVQ3Context::cur_pic
SVQ3Frame * cur_pic
Definition: svq3.c:93
av_log2
int av_log2(unsigned v)
Definition: intmath.c:26
SVQ3Context::has_watermark
int has_watermark
Definition: svq3.c:102
SVQ3Context::intra4x4_pred_mode
int8_t * intra4x4_pred_mode
Definition: svq3.c:131
src
#define src
Definition: vp8dsp.c:248
svq3_pred_0
static const uint8_t svq3_pred_0[25][2]
Definition: svq3.c:179
HALFPEL_MODE
#define HALFPEL_MODE
Definition: svq3.c:152
ff_h264_check_intra_pred_mode
int ff_h264_check_intra_pred_mode(void *logctx, int top_samples_available, int left_samples_available, int mode, int is_chroma)
Check if the top & left blocks are available if needed and change the dc mode so it only uses the ava...
Definition: h264_parse.c:182