FFmpeg
dvenc.c
Go to the documentation of this file.
1 /*
2  * DV encoder
3  * Copyright (c) 2003 Roman Shaposhnik
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  *
21  * quant_deadzone code and fixes sponsored by NOA GmbH
22  */
23 
24 /**
25  * @file
26  * DV encoder
27  */
28 
29 #include "config.h"
30 
31 #include "libavutil/attributes.h"
32 #include "libavutil/internal.h"
33 #include "libavutil/mem_internal.h"
34 #include "libavutil/opt.h"
35 #include "libavutil/pixdesc.h"
36 #include "libavutil/thread.h"
37 
38 #include "avcodec.h"
39 #include "dv.h"
40 #include "dv_profile_internal.h"
41 #include "dv_tablegen.h"
42 #include "fdctdsp.h"
43 #include "internal.h"
44 #include "mathops.h"
45 #include "me_cmp.h"
46 #include "pixblockdsp.h"
47 #include "put_bits.h"
48 
50 {
51  DVVideoContext *s = avctx->priv_data;
52  FDCTDSPContext fdsp;
53  MECmpContext mecc;
54  PixblockDSPContext pdsp;
55  int ret;
56 
57  s->sys = av_dv_codec_profile2(avctx->width, avctx->height, avctx->pix_fmt, avctx->time_base);
58  if (!s->sys) {
59  av_log(avctx, AV_LOG_ERROR, "Found no DV profile for %ix%i %s video. "
60  "Valid DV profiles are:\n",
61  avctx->width, avctx->height, av_get_pix_fmt_name(avctx->pix_fmt));
63  return AVERROR(EINVAL);
64  }
65 
67  if (ret < 0) {
68  av_log(avctx, AV_LOG_ERROR, "Error initializing work tables.\n");
69  return ret;
70  }
71 
72  memset(&fdsp,0, sizeof(fdsp));
73  memset(&mecc,0, sizeof(mecc));
74  memset(&pdsp,0, sizeof(pdsp));
75  ff_fdctdsp_init(&fdsp, avctx);
76  ff_me_cmp_init(&mecc, avctx);
77  ff_pixblockdsp_init(&pdsp, avctx);
78  ff_set_cmp(&mecc, mecc.ildct_cmp, avctx->ildct_cmp);
79 
80  s->get_pixels = pdsp.get_pixels;
81  s->ildct_cmp = mecc.ildct_cmp[5];
82 
83  s->fdct[0] = fdsp.fdct;
84  s->fdct[1] = fdsp.fdct248;
85 
86 #if !CONFIG_HARDCODED_TABLES
87  {
88  static AVOnce init_static_once = AV_ONCE_INIT;
89  ff_thread_once(&init_static_once, dv_vlc_map_tableinit);
90  }
91 #endif
92 
93  return ff_dvvideo_init(avctx);
94 }
95 
96 /* bit budget for AC only in 5 MBs */
97 static const int vs_total_ac_bits_hd = (68 * 6 + 52*2) * 5;
98 static const int vs_total_ac_bits = (100 * 4 + 68 * 2) * 5;
99 static const int mb_area_start[5] = { 1, 6, 21, 43, 64 };
100 
101 #if CONFIG_SMALL
102 /* Convert run and level (where level != 0) pair into VLC, returning bit size */
103 static av_always_inline int dv_rl2vlc(int run, int level, int sign,
104  uint32_t *vlc)
105 {
106  int size;
108  *vlc = dv_vlc_map[run][level].vlc | sign;
110  } else {
111  if (level < DV_VLC_MAP_LEV_SIZE) {
112  *vlc = dv_vlc_map[0][level].vlc | sign;
113  size = dv_vlc_map[0][level].size;
114  } else {
115  *vlc = 0xfe00 | (level << 1) | sign;
116  size = 16;
117  }
118  if (run) {
119  *vlc |= ((run < 16) ? dv_vlc_map[run - 1][0].vlc :
120  (0x1f80 | (run - 1))) << size;
121  size += (run < 16) ? dv_vlc_map[run - 1][0].size : 13;
122  }
123  }
124 
125  return size;
126 }
127 
128 static av_always_inline int dv_rl2vlc_size(int run, int level)
129 {
130  int size;
131 
134  } else {
136  if (run)
137  size += (run < 16) ? dv_vlc_map[run - 1][0].size : 13;
138  }
139  return size;
140 }
141 #else
142 static av_always_inline int dv_rl2vlc(int run, int l, int sign, uint32_t *vlc)
143 {
144  *vlc = dv_vlc_map[run][l].vlc | sign;
145  return dv_vlc_map[run][l].size;
146 }
147 
148 static av_always_inline int dv_rl2vlc_size(int run, int l)
149 {
150  return dv_vlc_map[run][l].size;
151 }
152 #endif
153 
154 typedef struct EncBlockInfo {
155  int area_q[4];
156  int bit_size[4];
157  int prev[5];
158  int cur_ac;
159  int cno;
160  int dct_mode;
161  int16_t mb[64];
162  uint8_t next[64];
163  uint8_t sign[64];
165  uint32_t partial_bit_buffer; /* we can't use uint16_t here */
166  /* used by DV100 only: a copy of the weighted and classified but
167  not-yet-quantized AC coefficients. This is necessary for
168  re-quantizing at different steps. */
169  int16_t save[64];
170  int min_qlevel; /* DV100 only: minimum qlevel (for AC coefficients >255) */
171 } EncBlockInfo;
172 
174  PutBitContext *pb_pool,
175  PutBitContext *pb_end)
176 {
177  int prev, bits_left;
178  PutBitContext *pb = pb_pool;
179  int size = bi->partial_bit_count;
180  uint32_t vlc = bi->partial_bit_buffer;
181 
182  bi->partial_bit_count =
183  bi->partial_bit_buffer = 0;
184  for (;;) {
185  /* Find suitable storage space */
186  for (; size > (bits_left = put_bits_left(pb)); pb++) {
187  if (bits_left) {
188  size -= bits_left;
189  put_bits(pb, bits_left, vlc >> size);
190  vlc = av_mod_uintp2(vlc, size);
191  }
192  if (pb + 1 >= pb_end) {
193  bi->partial_bit_count = size;
194  bi->partial_bit_buffer = vlc;
195  return pb;
196  }
197  }
198 
199  /* Store VLC */
200  put_bits(pb, size, vlc);
201 
202  if (bi->cur_ac >= 64)
203  break;
204 
205  /* Construct the next VLC */
206  prev = bi->cur_ac;
207  bi->cur_ac = bi->next[prev];
208  if (bi->cur_ac < 64) {
209  size = dv_rl2vlc(bi->cur_ac - prev - 1, bi->mb[bi->cur_ac],
210  bi->sign[bi->cur_ac], &vlc);
211  } else {
212  size = 4;
213  vlc = 6; /* End Of Block stamp */
214  }
215  }
216  return pb;
217 }
218 
220  ptrdiff_t linesize)
221 {
222  if (s->avctx->flags & AV_CODEC_FLAG_INTERLACED_DCT) {
223  int ps = s->ildct_cmp(NULL, data, NULL, linesize, 8) - 400;
224  if (ps > 0) {
225  int is = s->ildct_cmp(NULL, data, NULL, linesize * 2, 4) +
226  s->ildct_cmp(NULL, data + linesize, NULL, linesize * 2, 4);
227  return ps > is;
228  }
229  }
230 
231  return 0;
232 }
233 
234 static const int dv_weight_bits = 18;
235 static const int dv_weight_88[64] = {
236  131072, 257107, 257107, 242189, 252167, 242189, 235923, 237536,
237  237536, 235923, 229376, 231390, 223754, 231390, 229376, 222935,
238  224969, 217965, 217965, 224969, 222935, 200636, 218652, 211916,
239  212325, 211916, 218652, 200636, 188995, 196781, 205965, 206433,
240  206433, 205965, 196781, 188995, 185364, 185364, 200636, 200704,
241  200636, 185364, 185364, 174609, 180568, 195068, 195068, 180568,
242  174609, 170091, 175557, 189591, 175557, 170091, 165371, 170627,
243  170627, 165371, 160727, 153560, 160727, 144651, 144651, 136258,
244 };
245 static const int dv_weight_248[64] = {
246  131072, 262144, 257107, 257107, 242189, 242189, 242189, 242189,
247  237536, 237536, 229376, 229376, 200636, 200636, 224973, 224973,
248  223754, 223754, 235923, 235923, 229376, 229376, 217965, 217965,
249  211916, 211916, 196781, 196781, 185364, 185364, 206433, 206433,
250  211916, 211916, 222935, 222935, 200636, 200636, 205964, 205964,
251  200704, 200704, 180568, 180568, 175557, 175557, 195068, 195068,
252  185364, 185364, 188995, 188995, 174606, 174606, 175557, 175557,
253  170627, 170627, 153560, 153560, 165371, 165371, 144651, 144651,
254 };
255 
256 /* setting this to 1 results in a faster codec but
257  * somewhat lower image quality */
258 #define DV100_SACRIFICE_QUALITY_FOR_SPEED 1
259 #define DV100_ENABLE_FINER 1
260 
261 /* pack combination of QNO and CNO into a single 8-bit value */
262 #define DV100_MAKE_QLEVEL(qno,cno) ((qno<<2) | (cno))
263 #define DV100_QLEVEL_QNO(qlevel) (qlevel>>2)
264 #define DV100_QLEVEL_CNO(qlevel) (qlevel&0x3)
265 
266 #define DV100_NUM_QLEVELS 31
267 
268 /* The quantization step is determined by a combination of QNO and
269  CNO. We refer to these combinations as "qlevels" (this term is our
270  own, it's not mentioned in the spec). We use CNO, a multiplier on
271  the quantization step, to "fill in the gaps" between quantization
272  steps associated with successive values of QNO. e.g. there is no
273  QNO for a quantization step of 10, but we can use QNO=5 CNO=1 to
274  get the same result. The table below encodes combinations of QNO
275  and CNO in order of increasing quantization coarseness. */
276 static const uint8_t dv100_qlevels[DV100_NUM_QLEVELS] = {
277  DV100_MAKE_QLEVEL( 1,0), // 1*1= 1
278  DV100_MAKE_QLEVEL( 1,0), // 1*1= 1
279  DV100_MAKE_QLEVEL( 2,0), // 2*1= 2
280  DV100_MAKE_QLEVEL( 3,0), // 3*1= 3
281  DV100_MAKE_QLEVEL( 4,0), // 4*1= 4
282  DV100_MAKE_QLEVEL( 5,0), // 5*1= 5
283  DV100_MAKE_QLEVEL( 6,0), // 6*1= 6
284  DV100_MAKE_QLEVEL( 7,0), // 7*1= 7
285  DV100_MAKE_QLEVEL( 8,0), // 8*1= 8
286  DV100_MAKE_QLEVEL( 5,1), // 5*2=10
287  DV100_MAKE_QLEVEL( 6,1), // 6*2=12
288  DV100_MAKE_QLEVEL( 7,1), // 7*2=14
289  DV100_MAKE_QLEVEL( 9,0), // 16*1=16
290  DV100_MAKE_QLEVEL(10,0), // 18*1=18
291  DV100_MAKE_QLEVEL(11,0), // 20*1=20
292  DV100_MAKE_QLEVEL(12,0), // 22*1=22
293  DV100_MAKE_QLEVEL(13,0), // 24*1=24
294  DV100_MAKE_QLEVEL(14,0), // 28*1=28
295  DV100_MAKE_QLEVEL( 9,1), // 16*2=32
296  DV100_MAKE_QLEVEL(10,1), // 18*2=36
297  DV100_MAKE_QLEVEL(11,1), // 20*2=40
298  DV100_MAKE_QLEVEL(12,1), // 22*2=44
299  DV100_MAKE_QLEVEL(13,1), // 24*2=48
300  DV100_MAKE_QLEVEL(15,0), // 52*1=52
301  DV100_MAKE_QLEVEL(14,1), // 28*2=56
302  DV100_MAKE_QLEVEL( 9,2), // 16*4=64
303  DV100_MAKE_QLEVEL(10,2), // 18*4=72
304  DV100_MAKE_QLEVEL(11,2), // 20*4=80
305  DV100_MAKE_QLEVEL(12,2), // 22*4=88
306  DV100_MAKE_QLEVEL(13,2), // 24*4=96
307  // ...
308  DV100_MAKE_QLEVEL(15,3), // 52*8=416
309 };
310 
311 static const int dv100_min_bias = 0;
312 static const int dv100_chroma_bias = 0;
313 static const int dv100_starting_qno = 1;
314 
315 #if DV100_SACRIFICE_QUALITY_FOR_SPEED
316 static const int dv100_qlevel_inc = 4;
317 #else
318 static const int dv100_qlevel_inc = 1;
319 #endif
320 
321 // 1/qstep, shifted up by 16 bits
322 static const int dv100_qstep_bits = 16;
323 static const int dv100_qstep_inv[16] = {
324  65536, 65536, 32768, 21845, 16384, 13107, 10923, 9362, 8192, 4096, 3641, 3277, 2979, 2731, 2341, 1260,
325 };
326 
327 /* DV100 weights are pre-zigzagged, inverted and multiplied by 2^16
328  (in DV100 the AC components are divided by the spec weights) */
329 static const int dv_weight_1080[2][64] = {
330  { 8192, 65536, 65536, 61681, 61681, 61681, 58254, 58254,
331  58254, 58254, 58254, 58254, 55188, 58254, 58254, 55188,
332  55188, 55188, 55188, 55188, 55188, 24966, 27594, 26214,
333  26214, 26214, 27594, 24966, 23831, 24385, 25575, 25575,
334  25575, 25575, 24385, 23831, 23302, 23302, 24966, 24966,
335  24966, 23302, 23302, 21845, 22795, 24385, 24385, 22795,
336  21845, 21400, 21845, 23831, 21845, 21400, 10382, 10700,
337  10700, 10382, 10082, 9620, 10082, 9039, 9039, 8525, },
338  { 8192, 65536, 65536, 61681, 61681, 61681, 41943, 41943,
339  41943, 41943, 40330, 41943, 40330, 41943, 40330, 40330,
340  40330, 38836, 38836, 40330, 40330, 24966, 27594, 26214,
341  26214, 26214, 27594, 24966, 23831, 24385, 25575, 25575,
342  25575, 25575, 24385, 23831, 11523, 11523, 12483, 12483,
343  12483, 11523, 11523, 10923, 11275, 12193, 12193, 11275,
344  10923, 5323, 5490, 5924, 5490, 5323, 5165, 5323,
345  5323, 5165, 5017, 4788, 5017, 4520, 4520, 4263, }
346 };
347 
348 static const int dv_weight_720[2][64] = {
349  { 8192, 65536, 65536, 61681, 61681, 61681, 58254, 58254,
350  58254, 58254, 58254, 58254, 55188, 58254, 58254, 55188,
351  55188, 55188, 55188, 55188, 55188, 24966, 27594, 26214,
352  26214, 26214, 27594, 24966, 23831, 24385, 25575, 25575,
353  25575, 25575, 24385, 23831, 15420, 15420, 16644, 16644,
354  16644, 15420, 15420, 10923, 11398, 12193, 12193, 11398,
355  10923, 10700, 10923, 11916, 10923, 10700, 5191, 5350,
356  5350, 5191, 5041, 4810, 5041, 4520, 4520, 4263, },
357  { 8192, 43691, 43691, 40330, 40330, 40330, 29127, 29127,
358  29127, 29127, 29127, 29127, 27594, 29127, 29127, 27594,
359  27594, 27594, 27594, 27594, 27594, 12483, 13797, 13107,
360  13107, 13107, 13797, 12483, 11916, 12193, 12788, 12788,
361  12788, 12788, 12193, 11916, 5761, 5761, 6242, 6242,
362  6242, 5761, 5761, 5461, 5638, 5461, 6096, 5638,
363  5461, 2661, 2745, 2962, 2745, 2661, 2583, 2661,
364  2661, 2583, 2509, 2394, 2509, 2260, 2260, 2131, }
365 };
366 
368  int16_t *blk, EncBlockInfo *bi,
369  const uint8_t *zigzag_scan,
370  const int *weight, int bias)
371 {
372  int i, area;
373  /* We offer two different methods for class number assignment: the
374  * method suggested in SMPTE 314M Table 22, and an improved
375  * method. The SMPTE method is very conservative; it assigns class
376  * 3 (i.e. severe quantization) to any block where the largest AC
377  * component is greater than 36. FFmpeg's DV encoder tracks AC bit
378  * consumption precisely, so there is no need to bias most blocks
379  * towards strongly lossy compression. Instead, we assign class 2
380  * to most blocks, and use class 3 only when strictly necessary
381  * (for blocks whose largest AC component exceeds 255). */
382 
383 #if 0 /* SMPTE spec method */
384  static const int classes[] = { 12, 24, 36, 0xffff };
385 #else /* improved FFmpeg method */
386  static const int classes[] = { -1, -1, 255, 0xffff };
387 #endif
388  int max = classes[0];
389  int prev = 0;
390  const unsigned deadzone = s->quant_deadzone;
391  const unsigned threshold = 2 * deadzone;
392 
393  bi->mb[0] = blk[0];
394 
395  for (area = 0; area < 4; area++) {
396  bi->prev[area] = prev;
397  bi->bit_size[area] = 1; // 4 areas 4 bits for EOB :)
398  for (i = mb_area_start[area]; i < mb_area_start[area + 1]; i++) {
399  int level = blk[zigzag_scan[i]];
400 
401  if (level + deadzone > threshold) {
402  bi->sign[i] = (level >> 31) & 1;
403  /* Weight it and shift down into range, adding for rounding.
404  * The extra division by a factor of 2^4 reverses the 8x
405  * expansion of the DCT AND the 2x doubling of the weights. */
406  level = (FFABS(level) * weight[i] + (1 << (dv_weight_bits + 3))) >>
407  (dv_weight_bits + 4);
408  if (!level)
409  continue;
410  bi->mb[i] = level;
411  if (level > max)
412  max = level;
413  bi->bit_size[area] += dv_rl2vlc_size(i - prev - 1, level);
414  bi->next[prev] = i;
415  prev = i;
416  }
417  }
418  }
419  bi->next[prev] = i;
420  for (bi->cno = 0; max > classes[bi->cno]; bi->cno++)
421  ;
422 
423  bi->cno += bias;
424 
425  if (bi->cno >= 3) {
426  bi->cno = 3;
427  prev = 0;
428  i = bi->next[prev];
429  for (area = 0; area < 4; area++) {
430  bi->prev[area] = prev;
431  bi->bit_size[area] = 1; // 4 areas 4 bits for EOB :)
432  for (; i < mb_area_start[area + 1]; i = bi->next[i]) {
433  bi->mb[i] >>= 1;
434 
435  if (bi->mb[i]) {
436  bi->bit_size[area] += dv_rl2vlc_size(i - prev - 1, bi->mb[i]);
437  bi->next[prev] = i;
438  prev = i;
439  }
440  }
441  }
442  bi->next[prev] = i;
443  }
444 
445  return bi->bit_size[0] + bi->bit_size[1] +
446  bi->bit_size[2] + bi->bit_size[3];
447 }
448 
449 /* this function just copies the DCT coefficients and performs
450  the initial (non-)quantization. */
452  int16_t *blk, EncBlockInfo *bi,
453  const uint8_t *zigzag_scan,
454  const int *weight, int bias)
455 {
456  int i, max = 0;
457 
458  /* the first quantization (none at all) */
459  bi->area_q[0] = 1;
460 
461  /* weigh AC components and store to save[] */
462  /* (i=0 is the DC component; we only include it to make the
463  number of loop iterations even, for future possible SIMD optimization) */
464  for (i = 0; i < 64; i += 2) {
465  int level0, level1;
466 
467  /* get the AC component (in zig-zag order) */
468  level0 = blk[zigzag_scan[i+0]];
469  level1 = blk[zigzag_scan[i+1]];
470 
471  /* extract sign and make it the lowest bit */
472  bi->sign[i+0] = (level0>>31)&1;
473  bi->sign[i+1] = (level1>>31)&1;
474 
475  /* take absolute value of the level */
476  level0 = FFABS(level0);
477  level1 = FFABS(level1);
478 
479  /* weigh it */
480  level0 = (level0*weight[i+0] + 4096 + (1<<17)) >> 18;
481  level1 = (level1*weight[i+1] + 4096 + (1<<17)) >> 18;
482 
483  /* save unquantized value */
484  bi->save[i+0] = level0;
485  bi->save[i+1] = level1;
486 
487  /* find max component */
488  if (bi->save[i+0] > max)
489  max = bi->save[i+0];
490  if (bi->save[i+1] > max)
491  max = bi->save[i+1];
492  }
493 
494  /* copy DC component */
495  bi->mb[0] = blk[0];
496 
497  /* the EOB code is 4 bits */
498  bi->bit_size[0] = 4;
499  bi->bit_size[1] = bi->bit_size[2] = bi->bit_size[3] = 0;
500 
501  /* ensure that no AC coefficients are cut off */
502  bi->min_qlevel = ((max+256) >> 8);
503 
504  bi->area_q[0] = 25; /* set to an "impossible" value */
505  bi->cno = 0;
506 }
507 
508 static av_always_inline int dv_init_enc_block(EncBlockInfo* bi, uint8_t *data, int linesize,
509  DVVideoContext *s, int chroma)
510 {
511  LOCAL_ALIGNED_16(int16_t, blk, [64]);
512 
513  bi->area_q[0] = bi->area_q[1] = bi->area_q[2] = bi->area_q[3] = 0;
514  bi->partial_bit_count = 0;
515  bi->partial_bit_buffer = 0;
516  bi->cur_ac = 0;
517 
518  if (data) {
519  if (DV_PROFILE_IS_HD(s->sys)) {
520  s->get_pixels(blk, data, linesize * (1 << bi->dct_mode));
521  s->fdct[0](blk);
522  } else {
523  bi->dct_mode = dv_guess_dct_mode(s, data, linesize);
524  s->get_pixels(blk, data, linesize);
525  s->fdct[bi->dct_mode](blk);
526  }
527  } else {
528  /* We rely on the fact that encoding all zeros leads to an immediate EOB,
529  which is precisely what the spec calls for in the "dummy" blocks. */
530  memset(blk, 0, 64*sizeof(*blk));
531  bi->dct_mode = 0;
532  }
533 
534  if (DV_PROFILE_IS_HD(s->sys)) {
535  const int *weights;
536  if (s->sys->height == 1080) {
538  } else { /* 720p */
540  }
543  weights,
545  } else {
549  chroma);
550  }
551 
552  return bi->bit_size[0] + bi->bit_size[1] + bi->bit_size[2] + bi->bit_size[3];
553 }
554 
555 /* DV100 quantize
556  Perform quantization by divinding the AC component by the qstep.
557  As an optimization we use a fixed-point integer multiply instead
558  of a divide. */
559 static av_always_inline int dv100_quantize(int level, int qsinv)
560 {
561  /* this code is equivalent to */
562  /* return (level + qs/2) / qs; */
563 
564  return (level * qsinv + 1024 + (1<<(dv100_qstep_bits-1))) >> dv100_qstep_bits;
565 
566  /* the extra +1024 is needed to make the rounding come out right. */
567 
568  /* I (DJM) have verified that the results are exactly the same as
569  division for level 0-2048 at all QNOs. */
570 }
571 
572 static int dv100_actual_quantize(EncBlockInfo *b, int qlevel)
573 {
574  int prev, k, qsinv;
575 
576  int qno = DV100_QLEVEL_QNO(dv100_qlevels[qlevel]);
577  int cno = DV100_QLEVEL_CNO(dv100_qlevels[qlevel]);
578 
579  if (b->area_q[0] == qno && b->cno == cno)
580  return b->bit_size[0];
581 
582  qsinv = dv100_qstep_inv[qno];
583 
584  /* record the new qstep */
585  b->area_q[0] = qno;
586  b->cno = cno;
587 
588  /* reset encoded size (EOB = 4 bits) */
589  b->bit_size[0] = 4;
590 
591  /* visit nonzero components and quantize */
592  prev = 0;
593  for (k = 1; k < 64; k++) {
594  /* quantize */
595  int ac = dv100_quantize(b->save[k], qsinv) >> cno;
596  if (ac) {
597  if (ac > 255)
598  ac = 255;
599  b->mb[k] = ac;
600  b->bit_size[0] += dv_rl2vlc_size(k - prev - 1, ac);
601  b->next[prev] = k;
602  prev = k;
603  }
604  }
605  b->next[prev] = k;
606 
607  return b->bit_size[0];
608 }
609 
610 static inline void dv_guess_qnos_hd(EncBlockInfo *blks, int *qnos)
611 {
612  EncBlockInfo *b;
613  int min_qlevel[5];
614  int qlevels[5];
615  int size[5];
616  int i, j;
617  /* cache block sizes at hypothetical qlevels */
618  uint16_t size_cache[5*8][DV100_NUM_QLEVELS] = {{0}};
619 
620  /* get minimum qlevels */
621  for (i = 0; i < 5; i++) {
622  min_qlevel[i] = 1;
623  for (j = 0; j < 8; j++) {
624  if (blks[8*i+j].min_qlevel > min_qlevel[i])
625  min_qlevel[i] = blks[8*i+j].min_qlevel;
626  }
627  }
628 
629  /* initialize sizes */
630  for (i = 0; i < 5; i++) {
631  qlevels[i] = dv100_starting_qno;
632  if (qlevels[i] < min_qlevel[i])
633  qlevels[i] = min_qlevel[i];
634 
635  qnos[i] = DV100_QLEVEL_QNO(dv100_qlevels[qlevels[i]]);
636  size[i] = 0;
637  for (j = 0; j < 8; j++) {
638  size_cache[8*i+j][qlevels[i]] = dv100_actual_quantize(&blks[8*i+j], qlevels[i]);
639  size[i] += size_cache[8*i+j][qlevels[i]];
640  }
641  }
642 
643  /* must we go coarser? */
644  if (size[0]+size[1]+size[2]+size[3]+size[4] > vs_total_ac_bits_hd) {
645  int largest = size[0] % 5; /* 'random' number */
646  int qlevels_done = 0;
647 
648  do {
649  /* find the macroblock with the lowest qlevel */
650  for (i = 0; i < 5; i++) {
651  if (qlevels[i] < qlevels[largest])
652  largest = i;
653  }
654 
655  i = largest;
656  /* ensure that we don't enter infinite loop */
657  largest = (largest+1) % 5;
658 
659  /* quantize a little bit more */
660  qlevels[i] += dv100_qlevel_inc;
661  if (qlevels[i] > DV100_NUM_QLEVELS-1) {
662  qlevels[i] = DV100_NUM_QLEVELS-1;
663  qlevels_done++;
664  }
665 
666  qnos[i] = DV100_QLEVEL_QNO(dv100_qlevels[qlevels[i]]);
667  size[i] = 0;
668 
669  /* for each block */
670  b = &blks[8*i];
671  for (j = 0; j < 8; j++, b++) {
672  /* accumulate block size into macroblock */
673  if(size_cache[8*i+j][qlevels[i]] == 0) {
674  /* it is safe to use actual_quantize() here because we only go from finer to coarser,
675  and it saves the final actual_quantize() down below */
676  size_cache[8*i+j][qlevels[i]] = dv100_actual_quantize(b, qlevels[i]);
677  }
678  size[i] += size_cache[8*i+j][qlevels[i]];
679  } /* for each block */
680 
681  } while (vs_total_ac_bits_hd < size[0] + size[1] + size[2] + size[3] + size[4] && qlevels_done < 5);
682 
683  // can we go finer?
684  } else if (DV100_ENABLE_FINER &&
685  size[0]+size[1]+size[2]+size[3]+size[4] < vs_total_ac_bits_hd) {
686  int save_qlevel;
687  int largest = size[0] % 5; /* 'random' number */
688 
689  while (qlevels[0] > min_qlevel[0] ||
690  qlevels[1] > min_qlevel[1] ||
691  qlevels[2] > min_qlevel[2] ||
692  qlevels[3] > min_qlevel[3] ||
693  qlevels[4] > min_qlevel[4]) {
694 
695  /* find the macroblock with the highest qlevel */
696  for (i = 0; i < 5; i++) {
697  if (qlevels[i] > min_qlevel[i] && qlevels[i] > qlevels[largest])
698  largest = i;
699  }
700 
701  i = largest;
702 
703  /* ensure that we don't enter infinite loop */
704  largest = (largest+1) % 5;
705 
706  if (qlevels[i] <= min_qlevel[i]) {
707  /* can't unquantize any more */
708  continue;
709  }
710  /* quantize a little bit less */
711  save_qlevel = qlevels[i];
712  qlevels[i] -= dv100_qlevel_inc;
713  if (qlevels[i] < min_qlevel[i])
714  qlevels[i] = min_qlevel[i];
715 
716  qnos[i] = DV100_QLEVEL_QNO(dv100_qlevels[qlevels[i]]);
717 
718  size[i] = 0;
719 
720  /* for each block */
721  b = &blks[8*i];
722  for (j = 0; j < 8; j++, b++) {
723  /* accumulate block size into macroblock */
724  if(size_cache[8*i+j][qlevels[i]] == 0) {
725  size_cache[8*i+j][qlevels[i]] = dv100_actual_quantize(b, qlevels[i]);
726  }
727  size[i] += size_cache[8*i+j][qlevels[i]];
728  } /* for each block */
729 
730  /* did we bust the limit? */
731  if (vs_total_ac_bits_hd < size[0] + size[1] + size[2] + size[3] + size[4]) {
732  /* go back down and exit */
733  qlevels[i] = save_qlevel;
734  qnos[i] = DV100_QLEVEL_QNO(dv100_qlevels[qlevels[i]]);
735  break;
736  }
737  }
738  }
739 
740  /* now do the actual quantization */
741  for (i = 0; i < 5; i++) {
742  /* for each block */
743  b = &blks[8*i];
744  size[i] = 0;
745  for (j = 0; j < 8; j++, b++) {
746  /* accumulate block size into macroblock */
747  size[i] += dv100_actual_quantize(b, qlevels[i]);
748  } /* for each block */
749  }
750 }
751 
752 static inline void dv_guess_qnos(EncBlockInfo *blks, int *qnos)
753 {
754  int size[5];
755  int i, j, k, a, prev, a2;
756  EncBlockInfo *b;
757 
758  size[0] =
759  size[1] =
760  size[2] =
761  size[3] =
762  size[4] = 1 << 24;
763  do {
764  b = blks;
765  for (i = 0; i < 5; i++) {
766  if (!qnos[i])
767  continue;
768 
769  qnos[i]--;
770  size[i] = 0;
771  for (j = 0; j < 6; j++, b++) {
772  for (a = 0; a < 4; a++) {
773  if (b->area_q[a] != ff_dv_quant_shifts[qnos[i] + ff_dv_quant_offset[b->cno]][a]) {
774  b->bit_size[a] = 1; // 4 areas 4 bits for EOB :)
775  b->area_q[a]++;
776  prev = b->prev[a];
777  av_assert2(b->next[prev] >= mb_area_start[a + 1] || b->mb[prev]);
778  for (k = b->next[prev]; k < mb_area_start[a + 1]; k = b->next[k]) {
779  b->mb[k] >>= 1;
780  if (b->mb[k]) {
781  b->bit_size[a] += dv_rl2vlc_size(k - prev - 1, b->mb[k]);
782  prev = k;
783  } else {
784  if (b->next[k] >= mb_area_start[a + 1] && b->next[k] < 64) {
785  for (a2 = a + 1; b->next[k] >= mb_area_start[a2 + 1]; a2++)
786  b->prev[a2] = prev;
787  av_assert2(a2 < 4);
788  av_assert2(b->mb[b->next[k]]);
789  b->bit_size[a2] += dv_rl2vlc_size(b->next[k] - prev - 1, b->mb[b->next[k]]) -
790  dv_rl2vlc_size(b->next[k] - k - 1, b->mb[b->next[k]]);
791  av_assert2(b->prev[a2] == k && (a2 + 1 >= 4 || b->prev[a2 + 1] != k));
792  b->prev[a2] = prev;
793  }
794  b->next[prev] = b->next[k];
795  }
796  }
797  b->prev[a + 1] = prev;
798  }
799  size[i] += b->bit_size[a];
800  }
801  }
802  if (vs_total_ac_bits >= size[0] + size[1] + size[2] + size[3] + size[4])
803  return;
804  }
805  } while (qnos[0] | qnos[1] | qnos[2] | qnos[3] | qnos[4]);
806 
807  for (a = 2; a == 2 || vs_total_ac_bits < size[0]; a += a) {
808  b = blks;
809  size[0] = 5 * 6 * 4; // EOB
810  for (j = 0; j < 6 * 5; j++, b++) {
811  prev = b->prev[0];
812  for (k = b->next[prev]; k < 64; k = b->next[k]) {
813  if (b->mb[k] < a && b->mb[k] > -a) {
814  b->next[prev] = b->next[k];
815  } else {
816  size[0] += dv_rl2vlc_size(k - prev - 1, b->mb[k]);
817  prev = k;
818  }
819  }
820  }
821  }
822 }
823 
824 /* update all cno values into the blocks, over-writing the old values without
825  touching anything else. (only used for DV100) */
826 static inline void dv_revise_cnos(uint8_t *dif, EncBlockInfo *blk, const AVDVProfile *profile)
827 {
828  uint8_t *data;
829  int mb_index, i;
830 
831  for (mb_index = 0; mb_index < 5; mb_index++) {
832  data = dif + mb_index*80 + 4;
833  for (i = 0; i < profile->bpm; i++) {
834  /* zero out the class number */
835  data[1] &= 0xCF;
836  /* add the new one */
837  data[1] |= blk[profile->bpm*mb_index+i].cno << 4;
838 
839  data += profile->block_sizes[i] >> 3;
840  }
841  }
842 }
843 
844 static int dv_encode_video_segment(AVCodecContext *avctx, void *arg)
845 {
846  DVVideoContext *s = avctx->priv_data;
847  DVwork_chunk *work_chunk = arg;
848  int mb_index, i, j;
849  int mb_x, mb_y, c_offset;
850  ptrdiff_t linesize, y_stride;
851  uint8_t *y_ptr;
852  uint8_t *dif, *p;
853  LOCAL_ALIGNED_8(uint8_t, scratch, [128]);
854  EncBlockInfo enc_blks[5 * DV_MAX_BPM];
855  PutBitContext pbs[5 * DV_MAX_BPM];
856  PutBitContext *pb;
857  EncBlockInfo *enc_blk;
858  int vs_bit_size = 0;
859  int qnos[5];
860  int *qnosp = &qnos[0];
861 
862  p = dif = &s->buf[work_chunk->buf_offset * 80];
863  enc_blk = &enc_blks[0];
864  for (mb_index = 0; mb_index < 5; mb_index++) {
865  dv_calculate_mb_xy(s, work_chunk, mb_index, &mb_x, &mb_y);
866 
867  qnos[mb_index] = DV_PROFILE_IS_HD(s->sys) ? 1 : 15;
868 
869  y_ptr = s->frame->data[0] + (mb_y * s->frame->linesize[0] + mb_x) * 8;
870  linesize = s->frame->linesize[0];
871 
872  if (s->sys->height == 1080 && mb_y < 134)
873  enc_blk->dct_mode = dv_guess_dct_mode(s, y_ptr, linesize);
874  else
875  enc_blk->dct_mode = 0;
876  for (i = 1; i < 8; i++)
877  enc_blk[i].dct_mode = enc_blk->dct_mode;
878 
879  /* initializing luminance blocks */
880  if ((s->sys->pix_fmt == AV_PIX_FMT_YUV420P) ||
881  (s->sys->pix_fmt == AV_PIX_FMT_YUV411P && mb_x >= (704 / 8)) ||
882  (s->sys->height >= 720 && mb_y != 134)) {
883  y_stride = s->frame->linesize[0] * (1 << (3*!enc_blk->dct_mode));
884  } else {
885  y_stride = 16;
886  }
887  y_ptr = s->frame->data[0] +
888  (mb_y * s->frame->linesize[0] + mb_x) * 8;
889  linesize = s->frame->linesize[0];
890 
891  if (s->sys->video_stype == 4) { /* SD 422 */
892  vs_bit_size +=
893  dv_init_enc_block(enc_blk + 0, y_ptr, linesize, s, 0) +
894  dv_init_enc_block(enc_blk + 1, NULL, linesize, s, 0) +
895  dv_init_enc_block(enc_blk + 2, y_ptr + 8, linesize, s, 0) +
896  dv_init_enc_block(enc_blk + 3, NULL, linesize, s, 0);
897  } else {
898  vs_bit_size +=
899  dv_init_enc_block(enc_blk + 0, y_ptr, linesize, s, 0) +
900  dv_init_enc_block(enc_blk + 1, y_ptr + 8, linesize, s, 0) +
901  dv_init_enc_block(enc_blk + 2, y_ptr + y_stride, linesize, s, 0) +
902  dv_init_enc_block(enc_blk + 3, y_ptr + 8 + y_stride, linesize, s, 0);
903  }
904  enc_blk += 4;
905 
906  /* initializing chrominance blocks */
907  c_offset = ((mb_y >> (s->sys->pix_fmt == AV_PIX_FMT_YUV420P)) * s->frame->linesize[1] +
908  (mb_x >> ((s->sys->pix_fmt == AV_PIX_FMT_YUV411P) ? 2 : 1))) * 8;
909  for (j = 2; j; j--) {
910  uint8_t *c_ptr = s->frame->data[j] + c_offset;
911  linesize = s->frame->linesize[j];
912  y_stride = (mb_y == 134) ? 8 : (s->frame->linesize[j] * (1 << (3*!enc_blk->dct_mode)));
913  if (s->sys->pix_fmt == AV_PIX_FMT_YUV411P && mb_x >= (704 / 8)) {
914  uint8_t *d;
915  uint8_t *b = scratch;
916  for (i = 0; i < 8; i++) {
917  d = c_ptr + linesize * 8;
918  b[0] = c_ptr[0];
919  b[1] = c_ptr[1];
920  b[2] = c_ptr[2];
921  b[3] = c_ptr[3];
922  b[4] = d[0];
923  b[5] = d[1];
924  b[6] = d[2];
925  b[7] = d[3];
926  c_ptr += linesize;
927  b += 16;
928  }
929  c_ptr = scratch;
930  linesize = 16;
931  }
932 
933  vs_bit_size += dv_init_enc_block(enc_blk++, c_ptr, linesize, s, 1);
934  if (s->sys->bpm == 8)
935  vs_bit_size += dv_init_enc_block(enc_blk++, c_ptr + y_stride,
936  linesize, s, 1);
937  }
938  }
939 
940  if (DV_PROFILE_IS_HD(s->sys)) {
941  /* unconditional */
942  dv_guess_qnos_hd(&enc_blks[0], qnosp);
943  } else if (vs_total_ac_bits < vs_bit_size) {
944  dv_guess_qnos(&enc_blks[0], qnosp);
945  }
946 
947  /* DIF encoding process */
948  for (j = 0; j < 5 * s->sys->bpm;) {
949  int start_mb = j;
950 
951  p[3] = *qnosp++;
952  p += 4;
953 
954  /* First pass over individual cells only */
955  for (i = 0; i < s->sys->bpm; i++, j++) {
956  int sz = s->sys->block_sizes[i] >> 3;
957 
958  init_put_bits(&pbs[j], p, sz);
959  put_sbits(&pbs[j], 9, ((enc_blks[j].mb[0] >> 3) - 1024 + 2) >> 2);
960  put_bits(&pbs[j], 1, DV_PROFILE_IS_HD(s->sys) && i ? 1 : enc_blks[j].dct_mode);
961  put_bits(&pbs[j], 2, enc_blks[j].cno);
962 
963  dv_encode_ac(&enc_blks[j], &pbs[j], &pbs[j + 1]);
964  p += sz;
965  }
966 
967  /* Second pass over each MB space */
968  pb = &pbs[start_mb];
969  for (i = 0; i < s->sys->bpm; i++)
970  if (enc_blks[start_mb + i].partial_bit_count)
971  pb = dv_encode_ac(&enc_blks[start_mb + i], pb,
972  &pbs[start_mb + s->sys->bpm]);
973  }
974 
975  /* Third and final pass over the whole video segment space */
976  pb = &pbs[0];
977  for (j = 0; j < 5 * s->sys->bpm; j++) {
978  if (enc_blks[j].partial_bit_count)
979  pb = dv_encode_ac(&enc_blks[j], pb, &pbs[s->sys->bpm * 5]);
980  if (enc_blks[j].partial_bit_count)
981  av_log(avctx, AV_LOG_ERROR, "ac bitstream overflow\n");
982  }
983 
984  for (j = 0; j < 5 * s->sys->bpm; j++) {
985  flush_put_bits(&pbs[j]);
986  memset(put_bits_ptr(&pbs[j]), 0xff, put_bytes_left(&pbs[j], 0));
987  }
988 
989  if (DV_PROFILE_IS_HD(s->sys))
990  dv_revise_cnos(dif, enc_blks, s->sys);
991 
992  return 0;
993 }
994 
995 static inline int dv_write_pack(enum dv_pack_type pack_id, DVVideoContext *c,
996  uint8_t *buf)
997 {
998  /*
999  * Here's what SMPTE314M says about these two:
1000  * (page 6) APTn, AP1n, AP2n, AP3n: These data shall be identical
1001  * as track application IDs (APTn = 001, AP1n =
1002  * 001, AP2n = 001, AP3n = 001), if the source signal
1003  * comes from a digital VCR. If the signal source is
1004  * unknown, all bits for these data shall be set to 1.
1005  * (page 12) STYPE: STYPE defines a signal type of video signal
1006  * 00000b = 4:1:1 compression
1007  * 00100b = 4:2:2 compression
1008  * XXXXXX = Reserved
1009  * Now, I've got two problems with these statements:
1010  * 1. it looks like APT == 111b should be a safe bet, but it isn't.
1011  * It seems that for PAL as defined in IEC 61834 we have to set
1012  * APT to 000 and for SMPTE314M to 001.
1013  * 2. It is not at all clear what STYPE is used for 4:2:0 PAL
1014  * compression scheme (if any).
1015  */
1016  uint8_t aspect = 0;
1017  int apt = (c->sys->pix_fmt == AV_PIX_FMT_YUV420P ? 0 : 1);
1018  int fs;
1019 
1020  if (c->avctx->height >= 720)
1021  fs = c->avctx->height == 720 || c->frame->top_field_first ? 0x40 : 0x00;
1022  else
1023  fs = c->frame->top_field_first ? 0x00 : 0x40;
1024 
1025  if (DV_PROFILE_IS_HD(c->sys) ||
1026  (int)(av_q2d(c->avctx->sample_aspect_ratio) *
1027  c->avctx->width / c->avctx->height * 10) >= 17)
1028  /* HD formats are always 16:9 */
1029  aspect = 0x02;
1030 
1031  buf[0] = (uint8_t) pack_id;
1032  switch (pack_id) {
1033  case dv_header525: /* I can't imagine why these two weren't defined as real */
1034  case dv_header625: /* packs in SMPTE314M -- they definitely look like ones */
1035  buf[1] = 0xf8 | /* reserved -- always 1 */
1036  (apt & 0x07); /* APT: Track application ID */
1037  buf[2] = (0 << 7) | /* TF1: audio data is 0 - valid; 1 - invalid */
1038  (0x0f << 3) | /* reserved -- always 1 */
1039  (apt & 0x07); /* AP1: Audio application ID */
1040  buf[3] = (0 << 7) | /* TF2: video data is 0 - valid; 1 - invalid */
1041  (0x0f << 3) | /* reserved -- always 1 */
1042  (apt & 0x07); /* AP2: Video application ID */
1043  buf[4] = (0 << 7) | /* TF3: subcode(SSYB) is 0 - valid; 1 - invalid */
1044  (0x0f << 3) | /* reserved -- always 1 */
1045  (apt & 0x07); /* AP3: Subcode application ID */
1046  break;
1047  case dv_video_source:
1048  buf[1] = 0xff; /* reserved -- always 1 */
1049  buf[2] = (1 << 7) | /* B/W: 0 - b/w, 1 - color */
1050  (1 << 6) | /* following CLF is valid - 0, invalid - 1 */
1051  (3 << 4) | /* CLF: color frames ID (see ITU-R BT.470-4) */
1052  0xf; /* reserved -- always 1 */
1053  buf[3] = (3 << 6) | /* reserved -- always 1 */
1054  (c->sys->dsf << 5) | /* system: 60fields/50fields */
1055  c->sys->video_stype; /* signal type video compression */
1056  buf[4] = 0xff; /* VISC: 0xff -- no information */
1057  break;
1058  case dv_video_control:
1059  buf[1] = (0 << 6) | /* Copy generation management (CGMS) 0 -- free */
1060  0x3f; /* reserved -- always 1 */
1061  buf[2] = 0xc8 | /* reserved -- always b11001xxx */
1062  aspect;
1063  buf[3] = (1 << 7) | /* frame/field flag 1 -- frame, 0 -- field */
1064  fs | /* first/second field flag 0 -- field 2, 1 -- field 1 */
1065  (1 << 5) | /* frame change flag 0 -- same picture as before, 1 -- different */
1066  (1 << 4) | /* 1 - interlaced, 0 - noninterlaced */
1067  0xc; /* reserved -- always b1100 */
1068  buf[4] = 0xff; /* reserved -- always 1 */
1069  break;
1070  default:
1071  buf[1] =
1072  buf[2] =
1073  buf[3] =
1074  buf[4] = 0xff;
1075  }
1076  return 5;
1077 }
1078 
1079 static inline int dv_write_dif_id(enum dv_section_type t, uint8_t chan_num,
1080  uint8_t seq_num, uint8_t dif_num,
1081  uint8_t *buf)
1082 {
1083  int fsc = chan_num & 1;
1084  int fsp = 1 - (chan_num >> 1);
1085 
1086  buf[0] = (uint8_t) t; /* Section type */
1087  buf[1] = (seq_num << 4) | /* DIF seq number 0-9 for 525/60; 0-11 for 625/50 */
1088  (fsc << 3) | /* FSC: for 50 and 100Mb/s 0 - first channel; 1 - second */
1089  (fsp << 2) | /* FSP: for 100Mb/s 1 - channels 0-1; 0 - channels 2-3 */
1090  3; /* reserved -- always 1 */
1091  buf[2] = dif_num; /* DIF block number Video: 0-134, Audio: 0-8 */
1092  return 3;
1093 }
1094 
1095 static inline int dv_write_ssyb_id(uint8_t syb_num, uint8_t fr, uint8_t *buf)
1096 {
1097  if (syb_num == 0 || syb_num == 6) {
1098  buf[0] = (fr << 7) | /* FR ID 1 - first half of each channel; 0 - second */
1099  (0 << 4) | /* AP3 (Subcode application ID) */
1100  0x0f; /* reserved -- always 1 */
1101  } else if (syb_num == 11) {
1102  buf[0] = (fr << 7) | /* FR ID 1 - first half of each channel; 0 - second */
1103  0x7f; /* reserved -- always 1 */
1104  } else {
1105  buf[0] = (fr << 7) | /* FR ID 1 - first half of each channel; 0 - second */
1106  (0 << 4) | /* APT (Track application ID) */
1107  0x0f; /* reserved -- always 1 */
1108  }
1109  buf[1] = 0xf0 | /* reserved -- always 1 */
1110  (syb_num & 0x0f); /* SSYB number 0 - 11 */
1111  buf[2] = 0xff; /* reserved -- always 1 */
1112  return 3;
1113 }
1114 
1115 static void dv_format_frame(DVVideoContext *c, uint8_t *buf)
1116 {
1117  int chan, i, j, k;
1118  /* We work with 720p frames split in half. The odd half-frame is chan 2,3 */
1119  int chan_offset = 2*(c->sys->height == 720 && c->avctx->frame_number & 1);
1120 
1121  for (chan = 0; chan < c->sys->n_difchan; chan++) {
1122  for (i = 0; i < c->sys->difseg_size; i++) {
1123  memset(buf, 0xff, 80 * 6); /* first 6 DIF blocks are for control data */
1124 
1125  /* DV header: 1DIF */
1126  buf += dv_write_dif_id(dv_sect_header, chan+chan_offset, i, 0, buf);
1127  buf += dv_write_pack((c->sys->dsf ? dv_header625 : dv_header525),
1128  c, buf);
1129  buf += 72; /* unused bytes */
1130 
1131  /* DV subcode: 2DIFs */
1132  for (j = 0; j < 2; j++) {
1133  buf += dv_write_dif_id(dv_sect_subcode, chan+chan_offset, i, j, buf);
1134  for (k = 0; k < 6; k++)
1135  buf += dv_write_ssyb_id(k, (i < c->sys->difseg_size / 2), buf) + 5;
1136  buf += 29; /* unused bytes */
1137  }
1138 
1139  /* DV VAUX: 3DIFS */
1140  for (j = 0; j < 3; j++) {
1141  buf += dv_write_dif_id(dv_sect_vaux, chan+chan_offset, i, j, buf);
1142  buf += dv_write_pack(dv_video_source, c, buf);
1143  buf += dv_write_pack(dv_video_control, c, buf);
1144  buf += 7 * 5;
1145  buf += dv_write_pack(dv_video_source, c, buf);
1146  buf += dv_write_pack(dv_video_control, c, buf);
1147  buf += 4 * 5 + 2; /* unused bytes */
1148  }
1149 
1150  /* DV Audio/Video: 135 Video DIFs + 9 Audio DIFs */
1151  for (j = 0; j < 135; j++) {
1152  if (j % 15 == 0) {
1153  memset(buf, 0xff, 80);
1154  buf += dv_write_dif_id(dv_sect_audio, chan+chan_offset, i, j/15, buf);
1155  buf += 77; /* audio control & shuffled PCM audio */
1156  }
1157  buf += dv_write_dif_id(dv_sect_video, chan+chan_offset, i, j, buf);
1158  buf += 77; /* 1 video macroblock: 1 bytes control
1159  * 4 * 14 bytes Y 8x8 data
1160  * 10 bytes Cr 8x8 data
1161  * 10 bytes Cb 8x8 data */
1162  }
1163  }
1164  }
1165 }
1166 
1168  const AVFrame *frame, int *got_packet)
1169 {
1170  DVVideoContext *s = c->priv_data;
1171  int ret;
1172 
1173  if ((ret = ff_alloc_packet2(c, pkt, s->sys->frame_size, 0)) < 0)
1174  return ret;
1175 
1176  c->pix_fmt = s->sys->pix_fmt;
1177  s->frame = frame;
1178  s->buf = pkt->data;
1179 
1181 
1182  c->execute(c, dv_encode_video_segment, s->work_chunks, NULL,
1183  dv_work_pool_size(s->sys), sizeof(DVwork_chunk));
1184 
1185  emms_c();
1186 
1188  *got_packet = 1;
1189 
1190  return 0;
1191 }
1192 
1193 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
1194 #define OFFSET(x) offsetof(DVVideoContext, x)
1195 static const AVOption dv_options[] = {
1196  { "quant_deadzone", "Quantizer dead zone", OFFSET(quant_deadzone), AV_OPT_TYPE_INT, { .i64 = 7 }, 0, 1024, VE },
1197  { NULL },
1198 };
1199 
1201  .class_name = "dvvideo encoder",
1202  .item_name = av_default_item_name,
1203  .option = dv_options,
1204  .version = LIBAVUTIL_VERSION_INT,
1205 };
1206 
1208  .name = "dvvideo",
1209  .long_name = NULL_IF_CONFIG_SMALL("DV (Digital Video)"),
1210  .type = AVMEDIA_TYPE_VIDEO,
1211  .id = AV_CODEC_ID_DVVIDEO,
1212  .priv_data_size = sizeof(DVVideoContext),
1214  .encode2 = dvvideo_encode_frame,
1216  .pix_fmts = (const enum AVPixelFormat[]) {
1219  },
1220  .priv_class = &dvvideo_encode_class,
1221  .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
1222 };
AVCodec
AVCodec.
Definition: codec.h:197
EncBlockInfo::mb
int16_t mb[64]
Definition: dvenc.c:161
dv_guess_qnos
static void dv_guess_qnos(EncBlockInfo *blks, int *qnos)
Definition: dvenc.c:752
FF_CODEC_CAP_INIT_THREADSAFE
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
Definition: internal.h:41
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
level
uint8_t level
Definition: svq3.c:204
dv100_qstep_inv
static const int dv100_qstep_inv[16]
Definition: dvenc.c:323
DV_MAX_BPM
#define DV_MAX_BPM
maximum number of blocks per macroblock in any DV format
Definition: dv.h:97
dv_vlc_map_tableinit
static av_cold void dv_vlc_map_tableinit(void)
Definition: dv_tablegen.h:51
init
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:31
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
opt.h
DV100_ENABLE_FINER
#define DV100_ENABLE_FINER
Definition: dvenc.c:259
DVwork_chunk::buf_offset
uint16_t buf_offset
Definition: dv.h:37
FDCTDSPContext::fdct248
void(* fdct248)(int16_t *block)
Definition: fdctdsp.h:28
mem_internal.h
EncBlockInfo::prev
int prev[5]
Definition: dvenc.c:157
is
The official guide to swscale for confused that is
Definition: swscale.txt:28
dv_profile_internal.h
dv_weight_1080
static const int dv_weight_1080[2][64]
Definition: dvenc.c:329
dv_rl2vlc
static av_always_inline int dv_rl2vlc(int run, int l, int sign, uint32_t *vlc)
Definition: dvenc.c:142
thread.h
dv_weight_720
static const int dv_weight_720[2][64]
Definition: dvenc.c:348
dv_tablegen.h
put_sbits
static void put_sbits(PutBitContext *pb, int n, int32_t value)
Definition: put_bits.h:280
init_put_bits
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
Definition: put_bits.h:61
av_mod_uintp2
#define av_mod_uintp2
Definition: common.h:149
profile
mfxU16 profile
Definition: qsvenc.c:45
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:303
put_bits
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
Definition: j2kenc.c:218
pixdesc.h
dv_sect_vaux
@ dv_sect_vaux
Definition: dv.h:64
DVwork_chunk
Definition: dv.h:36
EncBlockInfo::partial_bit_count
uint8_t partial_bit_count
Definition: dvenc.c:164
dv_vlc_pair::vlc
uint32_t vlc
Definition: dv_tablegen.h:41
internal.h
AVPacket::data
uint8_t * data
Definition: packet.h:365
AVOption
AVOption.
Definition: opt.h:248
dv_header625
@ dv_header625
Definition: dv.h:71
b
#define b
Definition: input.c:41
chroma
static av_always_inline void chroma(WaveformContext *s, AVFrame *in, AVFrame *out, int component, int intensity, int offset_y, int offset_x, int column, int mirror, int jobnr, int nb_jobs)
Definition: vf_waveform.c:1624
data
const char data[16]
Definition: mxf.c:142
mb_area_start
static const int mb_area_start[5]
Definition: dvenc.c:99
dv_encode_video_segment
static int dv_encode_video_segment(AVCodecContext *avctx, void *arg)
Definition: dvenc.c:844
ff_pixblockdsp_init
av_cold void ff_pixblockdsp_init(PixblockDSPContext *c, AVCodecContext *avctx)
Definition: pixblockdsp.c:81
max
#define max(a, b)
Definition: cuda_runtime.h:33
DV_VLC_MAP_RUN_SIZE
#define DV_VLC_MAP_RUN_SIZE
Definition: dv_tablegen.h:35
ff_set_cmp
void ff_set_cmp(MECmpContext *c, me_cmp_func *cmp, int type)
Definition: me_cmp.c:475
ff_dv_print_profiles
void ff_dv_print_profiles(void *logctx, int loglevel)
Print all allowed DV profiles into logctx at specified logging level.
AV_PKT_FLAG_KEY
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: packet.h:396
EncBlockInfo::next
uint8_t next[64]
Definition: dvenc.c:162
dv_weight_88
static const int dv_weight_88[64]
Definition: dvenc.c:235
FDCTDSPContext
Definition: fdctdsp.h:26
dv100_qlevel_inc
static const int dv100_qlevel_inc
Definition: dvenc.c:316
EncBlockInfo::bit_size
int bit_size[4]
Definition: dvenc.c:156
dv_sect_subcode
@ dv_sect_subcode
Definition: dv.h:63
PixblockDSPContext::get_pixels
void(* get_pixels)(int16_t *av_restrict block, const uint8_t *pixels, ptrdiff_t stride)
Definition: pixblockdsp.h:29
put_bits_left
static int put_bits_left(PutBitContext *s)
Definition: put_bits.h:124
ff_me_cmp_init
av_cold void ff_me_cmp_init(MECmpContext *c, AVCodecContext *avctx)
Definition: me_cmp.c:1015
dv_sect_audio
@ dv_sect_audio
Definition: dv.h:65
MECmpContext::ildct_cmp
me_cmp_func ildct_cmp[6]
Definition: me_cmp.h:75
put_bytes_left
static int put_bytes_left(const PutBitContext *s, int round_up)
Definition: put_bits.h:134
dvvideo_encode_class
static const AVClass dvvideo_encode_class
Definition: dvenc.c:1200
AV_CODEC_FLAG_INTERLACED_DCT
#define AV_CODEC_FLAG_INTERLACED_DCT
Use interlaced DCT.
Definition: avcodec.h:298
ff_thread_once
static int ff_thread_once(char *control, void(*routine)(void))
Definition: thread.h:175
pkt
AVPacket * pkt
Definition: movenc.c:59
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:181
ff_dv_init_dynamic_tables
int ff_dv_init_dynamic_tables(DVVideoContext *ctx, const AVDVProfile *d)
Definition: dv.c:172
dv_weight_bits
static const int dv_weight_bits
Definition: dvenc.c:234
av_cold
#define av_cold
Definition: attributes.h:90
ff_fdctdsp_init
av_cold void ff_fdctdsp_init(FDCTDSPContext *c, AVCodecContext *avctx)
Definition: fdctdsp.c:26
dv100_starting_qno
static const int dv100_starting_qno
Definition: dvenc.c:313
dv_pack_type
dv_pack_type
Definition: dv.h:69
s
#define s(width, name)
Definition: cbs_vp9.c:257
EncBlockInfo::sign
uint8_t sign[64]
Definition: dvenc.c:163
dv100_min_bias
static const int dv100_min_bias
Definition: dvenc.c:311
av_q2d
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition: rational.h:104
LOCAL_ALIGNED_16
#define LOCAL_ALIGNED_16(t, v,...)
Definition: mem_internal.h:130
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:289
dv_revise_cnos
static void dv_revise_cnos(uint8_t *dif, EncBlockInfo *blk, const AVDVProfile *profile)
Definition: dvenc.c:826
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:66
blk
#define blk(i)
Definition: sha.c:185
dv_guess_qnos_hd
static void dv_guess_qnos_hd(EncBlockInfo *blks, int *qnos)
Definition: dvenc.c:610
PutBitContext
Definition: put_bits.h:49
LOCAL_ALIGNED_8
#define LOCAL_ALIGNED_8(t, v,...)
Definition: mem_internal.h:124
arg
const char * arg
Definition: jacosubdec.c:67
dv_init_enc_block
static av_always_inline int dv_init_enc_block(EncBlockInfo *bi, uint8_t *data, int linesize, DVVideoContext *s, int chroma)
Definition: dvenc.c:508
FFABS
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:72
if
if(ret)
Definition: filter_design.txt:179
PixblockDSPContext
Definition: pixblockdsp.h:28
AV_CODEC_CAP_FRAME_THREADS
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition: codec.h:108
MECmpContext
Definition: me_cmp.h:53
OFFSET
#define OFFSET(x)
Definition: dvenc.c:1194
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
dv_video_source
@ dv_video_source
Definition: dv.h:77
ff_dv_quant_shifts
const uint8_t ff_dv_quant_shifts[22][4]
Definition: dvdata.c:45
EncBlockInfo::dct_mode
int dct_mode
Definition: dvenc.c:160
AV_ONCE_INIT
#define AV_ONCE_INIT
Definition: thread.h:173
DV100_QLEVEL_CNO
#define DV100_QLEVEL_CNO(qlevel)
Definition: dvenc.c:264
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:67
NULL
#define NULL
Definition: coverity.c:32
run
uint8_t run
Definition: svq3.c:203
fs
#define fs(width, name, subs,...)
Definition: cbs_vp9.c:259
DVVideoContext
Definition: dv.h:41
dv_set_class_number_sd
static av_always_inline int dv_set_class_number_sd(DVVideoContext *s, int16_t *blk, EncBlockInfo *bi, const uint8_t *zigzag_scan, const int *weight, int bias)
Definition: dvenc.c:367
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:235
mathops.h
AVCodecContext::ildct_cmp
int ildct_cmp
interlaced DCT comparison function
Definition: avcodec.h:884
dv_encode_ac
static av_always_inline PutBitContext * dv_encode_ac(EncBlockInfo *bi, PutBitContext *pb_pool, PutBitContext *pb_end)
Definition: dvenc.c:173
dv100_chroma_bias
static const int dv100_chroma_bias
Definition: dvenc.c:312
AVOnce
#define AVOnce
Definition: thread.h:172
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
dv_sect_header
@ dv_sect_header
Definition: dv.h:62
dv100_qstep_bits
static const int dv100_qstep_bits
Definition: dvenc.c:322
weight
static int weight(int i, int blen, int offset)
Definition: diracdec.c:1561
dv_format_frame
static void dv_format_frame(DVVideoContext *c, uint8_t *buf)
Definition: dvenc.c:1115
AVCodecContext::time_base
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
Definition: avcodec.h:624
dv.h
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
dvvideo_encode_init
static av_cold int dvvideo_encode_init(AVCodecContext *avctx)
Definition: dvenc.c:49
size
int size
Definition: twinvq_data.h:10344
dv100_quantize
static av_always_inline int dv100_quantize(int level, int qsinv)
Definition: dvenc.c:559
ff_dv_zigzag248_direct
const uint8_t ff_dv_zigzag248_direct[64]
Definition: dvdata.c:33
EncBlockInfo::partial_bit_buffer
uint32_t partial_bit_buffer
Definition: dvenc.c:165
dvvideo_encode_frame
static int dvvideo_encode_frame(AVCodecContext *c, AVPacket *pkt, const AVFrame *frame, int *got_packet)
Definition: dvenc.c:1167
dv_header525
@ dv_header525
Definition: dv.h:70
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
AV_CODEC_CAP_SLICE_THREADS
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
Definition: codec.h:112
attributes.h
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:371
vs_total_ac_bits_hd
static const int vs_total_ac_bits_hd
Definition: dvenc.c:97
vs_total_ac_bits
static const int vs_total_ac_bits
Definition: dvenc.c:98
dv100_actual_quantize
static int dv100_actual_quantize(EncBlockInfo *b, int qlevel)
Definition: dvenc.c:572
DV_PROFILE_IS_HD
#define DV_PROFILE_IS_HD(p)
Definition: dv.h:84
mb
#define mb
Definition: vf_colormatrix.c:101
VE
#define VE
Definition: dvenc.c:1193
dv_write_pack
static int dv_write_pack(enum dv_pack_type pack_id, DVVideoContext *c, uint8_t *buf)
Definition: dvenc.c:995
dv_options
static const AVOption dv_options[]
Definition: dvenc.c:1195
av_assert2
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition: avassert.h:64
i
int i
Definition: input.c:407
dv_vlc_map
static struct dv_vlc_pair dv_vlc_map[DV_VLC_MAP_RUN_SIZE][DV_VLC_MAP_LEV_SIZE]
Definition: dv_tablegen.h:49
ff_dvvideo_encoder
const AVCodec ff_dvvideo_encoder
Definition: dvenc.c:1207
internal.h
dv_write_ssyb_id
static int dv_write_ssyb_id(uint8_t syb_num, uint8_t fr, uint8_t *buf)
Definition: dvenc.c:1095
weights
static const int weights[]
Definition: hevc_pel.c:32
a2
#define a2
Definition: regdef.h:48
EncBlockInfo::area_q
int area_q[4]
Definition: dvenc.c:155
xf
#define xf(width, name, var, range_min, range_max, subs,...)
Definition: cbs_av1.c:664
av_always_inline
#define av_always_inline
Definition: attributes.h:49
AV_CODEC_ID_DVVIDEO
@ AV_CODEC_ID_DVVIDEO
Definition: codec_id.h:73
dv_work_pool_size
static int dv_work_pool_size(const AVDVProfile *d)
Definition: dv.h:103
dv_video_control
@ dv_video_control
Definition: dv.h:78
fdctdsp.h
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:204
dv100_qlevels
static const uint8_t dv100_qlevels[DV100_NUM_QLEVELS]
Definition: dvenc.c:276
DV100_NUM_QLEVELS
#define DV100_NUM_QLEVELS
Definition: dvenc.c:266
AVCodecContext::height
int height
Definition: avcodec.h:674
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:711
dv_section_type
dv_section_type
Definition: dv.h:61
avcodec.h
ff_zigzag_direct
const uint8_t ff_zigzag_direct[64]
Definition: mathtables.c:98
EncBlockInfo::cur_ac
int cur_ac
Definition: dvenc.c:158
ret
ret
Definition: filter_design.txt:187
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:72
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
EncBlockInfo::min_qlevel
int min_qlevel
Definition: dvenc.c:170
dv_calculate_mb_xy
static void dv_calculate_mb_xy(DVVideoContext *s, DVwork_chunk *work_chunk, int m, int *mb_x, int *mb_y)
Definition: dv.h:113
me_cmp.h
dv_guess_dct_mode
static av_always_inline int dv_guess_dct_mode(DVVideoContext *s, uint8_t *data, ptrdiff_t linesize)
Definition: dvenc.c:219
AVCodecContext
main external API structure.
Definition: avcodec.h:501
ff_dv_quant_offset
const uint8_t ff_dv_quant_offset[4]
Definition: dvdata.c:70
put_bits_ptr
static uint8_t * put_bits_ptr(PutBitContext *s)
Return the pointer to the byte where the bitstream writer will put the next bit.
Definition: put_bits.h:369
dv_sect_video
@ dv_sect_video
Definition: dv.h:66
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
EncBlockInfo
Definition: dvenc.c:154
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
DV100_QLEVEL_QNO
#define DV100_QLEVEL_QNO(qlevel)
Definition: dvenc.c:263
AVDVProfile
Definition: dv_profile.h:39
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AV_PIX_FMT_YUV422P
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:70
FDCTDSPContext::fdct
void(* fdct)(int16_t *block)
Definition: fdctdsp.h:27
dv_write_dif_id
static int dv_write_dif_id(enum dv_section_type t, uint8_t chan_num, uint8_t seq_num, uint8_t dif_num, uint8_t *buf)
Definition: dvenc.c:1079
flush_put_bits
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
Definition: put_bits.h:142
ff_dvvideo_init
av_cold int ff_dvvideo_init(AVCodecContext *avctx)
Definition: dv.c:195
EncBlockInfo::save
int16_t save[64]
Definition: dvenc.c:169
AVPacket
This structure stores compressed data.
Definition: packet.h:342
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:528
dv_vlc_pair::size
uint32_t size
Definition: dv_tablegen.h:42
AV_PIX_FMT_YUV411P
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:73
d
d
Definition: ffmpeg_filter.c:156
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:674
DV100_MAKE_QLEVEL
#define DV100_MAKE_QLEVEL(qno, cno)
Definition: dvenc.c:262
DV_VLC_MAP_LEV_SIZE
#define DV_VLC_MAP_LEV_SIZE
Definition: dv_tablegen.h:36
dv_rl2vlc_size
static av_always_inline int dv_rl2vlc_size(int run, int l)
Definition: dvenc.c:148
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
dv_weight_248
static const int dv_weight_248[64]
Definition: dvenc.c:245
av_dv_codec_profile2
const AVDVProfile * av_dv_codec_profile2(int width, int height, enum AVPixelFormat pix_fmt, AVRational frame_rate)
Get a DV profile for the provided stream parameters.
Definition: dv_profile.c:314
ff_alloc_packet2
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
Definition: encode.c:33
int
int
Definition: ffmpeg_filter.c:156
put_bits.h
EncBlockInfo::cno
int cno
Definition: dvenc.c:159
dv_set_class_number_hd
static void dv_set_class_number_hd(DVVideoContext *s, int16_t *blk, EncBlockInfo *bi, const uint8_t *zigzag_scan, const int *weight, int bias)
Definition: dvenc.c:451
pixblockdsp.h
av_get_pix_fmt_name
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
Definition: pixdesc.c:2461