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