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