FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
h264.c
Go to the documentation of this file.
1 /*
2  * H.26L/H.264/AVC/JVT/14496-10/... decoder
3  * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
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 
22 /**
23  * @file
24  * H.264 / AVC / MPEG4 part10 codec.
25  * @author Michael Niedermayer <michaelni@gmx.at>
26  */
27 
28 #define UNCHECKED_BITSTREAM_READER 1
29 
30 #include "libavutil/avassert.h"
31 #include "libavutil/display.h"
32 #include "libavutil/imgutils.h"
33 #include "libavutil/opt.h"
34 #include "libavutil/stereo3d.h"
35 #include "libavutil/timer.h"
36 #include "internal.h"
37 #include "cabac.h"
38 #include "cabac_functions.h"
39 #include "error_resilience.h"
40 #include "avcodec.h"
41 #include "h264.h"
42 #include "h264data.h"
43 #include "h264chroma.h"
44 #include "h264_mvpred.h"
45 #include "golomb.h"
46 #include "mathops.h"
47 #include "me_cmp.h"
48 #include "mpegutils.h"
49 #include "profiles.h"
50 #include "rectangle.h"
51 #include "svq3.h"
52 #include "thread.h"
53 #include "vdpau_compat.h"
54 
55 static int h264_decode_end(AVCodecContext *avctx);
56 
57 const uint16_t ff_h264_mb_sizes[4] = { 256, 384, 512, 768 };
58 
60 {
61  H264Context *h = avctx->priv_data;
62  return h ? h->sps.num_reorder_frames : 0;
63 }
64 
65 static void h264_er_decode_mb(void *opaque, int ref, int mv_dir, int mv_type,
66  int (*mv)[2][4][2],
67  int mb_x, int mb_y, int mb_intra, int mb_skipped)
68 {
69  H264Context *h = opaque;
70  H264SliceContext *sl = &h->slice_ctx[0];
71 
72  sl->mb_x = mb_x;
73  sl->mb_y = mb_y;
74  sl->mb_xy = mb_x + mb_y * h->mb_stride;
75  memset(sl->non_zero_count_cache, 0, sizeof(sl->non_zero_count_cache));
76  av_assert1(ref >= 0);
77  /* FIXME: It is possible albeit uncommon that slice references
78  * differ between slices. We take the easy approach and ignore
79  * it for now. If this turns out to have any relevance in
80  * practice then correct remapping should be added. */
81  if (ref >= sl->ref_count[0])
82  ref = 0;
83  if (!sl->ref_list[0][ref].data[0]) {
84  av_log(h->avctx, AV_LOG_DEBUG, "Reference not available for error concealing\n");
85  ref = 0;
86  }
87  if ((sl->ref_list[0][ref].reference&3) != 3) {
88  av_log(h->avctx, AV_LOG_DEBUG, "Reference invalid\n");
89  return;
90  }
91  fill_rectangle(&h->cur_pic.ref_index[0][4 * sl->mb_xy],
92  2, 2, 2, ref, 1);
93  fill_rectangle(&sl->ref_cache[0][scan8[0]], 4, 4, 8, ref, 1);
94  fill_rectangle(sl->mv_cache[0][scan8[0]], 4, 4, 8,
95  pack16to32((*mv)[0][0][0], (*mv)[0][0][1]), 4);
96  sl->mb_mbaff =
97  sl->mb_field_decoding_flag = 0;
99 }
100 
102  int y, int height)
103 {
104  AVCodecContext *avctx = h->avctx;
105  const AVFrame *src = h->cur_pic.f;
106  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
107  int vshift = desc->log2_chroma_h;
108  const int field_pic = h->picture_structure != PICT_FRAME;
109  if (field_pic) {
110  height <<= 1;
111  y <<= 1;
112  }
113 
114  height = FFMIN(height, avctx->height - y);
115 
116  if (field_pic && h->first_field && !(avctx->slice_flags & SLICE_FLAG_ALLOW_FIELD))
117  return;
118 
119  if (avctx->draw_horiz_band) {
121  int i;
122 
123  offset[0] = y * src->linesize[0];
124  offset[1] =
125  offset[2] = (y >> vshift) * src->linesize[1];
126  for (i = 3; i < AV_NUM_DATA_POINTERS; i++)
127  offset[i] = 0;
128 
129  emms_c();
130 
131  avctx->draw_horiz_band(avctx, src, offset,
132  y, h->picture_structure, height);
133  }
134 }
135 
136 /**
137  * Check if the top & left blocks are available if needed and
138  * change the dc mode so it only uses the available blocks.
139  */
141 {
142  static const int8_t top[12] = {
143  -1, 0, LEFT_DC_PRED, -1, -1, -1, -1, -1, 0
144  };
145  static const int8_t left[12] = {
146  0, -1, TOP_DC_PRED, 0, -1, -1, -1, 0, -1, DC_128_PRED
147  };
148  int i;
149 
150  if (!(sl->top_samples_available & 0x8000)) {
151  for (i = 0; i < 4; i++) {
152  int status = top[sl->intra4x4_pred_mode_cache[scan8[0] + i]];
153  if (status < 0) {
155  "top block unavailable for requested intra4x4 mode %d at %d %d\n",
156  status, sl->mb_x, sl->mb_y);
157  return AVERROR_INVALIDDATA;
158  } else if (status) {
159  sl->intra4x4_pred_mode_cache[scan8[0] + i] = status;
160  }
161  }
162  }
163 
164  if ((sl->left_samples_available & 0x8888) != 0x8888) {
165  static const int mask[4] = { 0x8000, 0x2000, 0x80, 0x20 };
166  for (i = 0; i < 4; i++)
167  if (!(sl->left_samples_available & mask[i])) {
168  int status = left[sl->intra4x4_pred_mode_cache[scan8[0] + 8 * i]];
169  if (status < 0) {
171  "left block unavailable for requested intra4x4 mode %d at %d %d\n",
172  status, sl->mb_x, sl->mb_y);
173  return AVERROR_INVALIDDATA;
174  } else if (status) {
175  sl->intra4x4_pred_mode_cache[scan8[0] + 8 * i] = status;
176  }
177  }
178  }
179 
180  return 0;
181 } // FIXME cleanup like ff_h264_check_intra_pred_mode
182 
183 /**
184  * Check if the top & left blocks are available if needed and
185  * change the dc mode so it only uses the available blocks.
186  */
188  int mode, int is_chroma)
189 {
190  static const int8_t top[4] = { LEFT_DC_PRED8x8, 1, -1, -1 };
191  static const int8_t left[5] = { TOP_DC_PRED8x8, -1, 2, -1, DC_128_PRED8x8 };
192 
193  if (mode > 3U) {
195  "out of range intra chroma pred mode at %d %d\n",
196  sl->mb_x, sl->mb_y);
197  return AVERROR_INVALIDDATA;
198  }
199 
200  if (!(sl->top_samples_available & 0x8000)) {
201  mode = top[mode];
202  if (mode < 0) {
204  "top block unavailable for requested intra mode at %d %d\n",
205  sl->mb_x, sl->mb_y);
206  return AVERROR_INVALIDDATA;
207  }
208  }
209 
210  if ((sl->left_samples_available & 0x8080) != 0x8080) {
211  mode = left[mode];
212  if (mode < 0) {
214  "left block unavailable for requested intra mode at %d %d\n",
215  sl->mb_x, sl->mb_y);
216  return AVERROR_INVALIDDATA;
217  }
218  if (is_chroma && (sl->left_samples_available & 0x8080)) {
219  // mad cow disease mode, aka MBAFF + constrained_intra_pred
220  mode = ALZHEIMER_DC_L0T_PRED8x8 +
221  (!(sl->left_samples_available & 0x8000)) +
222  2 * (mode == DC_128_PRED8x8);
223  }
224  }
225 
226  return mode;
227 }
228 
230  const uint8_t *src,
231  int *dst_length, int *consumed, int length)
232 {
233  int i, si, di;
234  uint8_t *dst;
235 
236  // src[0]&0x80; // forbidden bit
237  h->nal_ref_idc = src[0] >> 5;
238  h->nal_unit_type = src[0] & 0x1F;
239 
240  src++;
241  length--;
242 
243 #define STARTCODE_TEST \
244  if (i + 2 < length && src[i + 1] == 0 && src[i + 2] <= 3) { \
245  if (src[i + 2] != 3 && src[i + 2] != 0) { \
246  /* startcode, so we must be past the end */ \
247  length = i; \
248  } \
249  break; \
250  }
251 
252 #if HAVE_FAST_UNALIGNED
253 #define FIND_FIRST_ZERO \
254  if (i > 0 && !src[i]) \
255  i--; \
256  while (src[i]) \
257  i++
258 
259 #if HAVE_FAST_64BIT
260  for (i = 0; i + 1 < length; i += 9) {
261  if (!((~AV_RN64A(src + i) &
262  (AV_RN64A(src + i) - 0x0100010001000101ULL)) &
263  0x8000800080008080ULL))
264  continue;
265  FIND_FIRST_ZERO;
267  i -= 7;
268  }
269 #else
270  for (i = 0; i + 1 < length; i += 5) {
271  if (!((~AV_RN32A(src + i) &
272  (AV_RN32A(src + i) - 0x01000101U)) &
273  0x80008080U))
274  continue;
275  FIND_FIRST_ZERO;
277  i -= 3;
278  }
279 #endif
280 #else
281  for (i = 0; i + 1 < length; i += 2) {
282  if (src[i])
283  continue;
284  if (i > 0 && src[i - 1] == 0)
285  i--;
287  }
288 #endif
289 
291  dst = sl->rbsp_buffer;
292 
293  if (!dst)
294  return NULL;
295 
296  if(i>=length-1){ //no escaped 0
297  *dst_length= length;
298  *consumed= length+1; //+1 for the header
299  if(h->avctx->flags2 & AV_CODEC_FLAG2_FAST){
300  return src;
301  }else{
302  memcpy(dst, src, length);
303  return dst;
304  }
305  }
306 
307  memcpy(dst, src, i);
308  si = di = i;
309  while (si + 2 < length) {
310  // remove escapes (very rare 1:2^22)
311  if (src[si + 2] > 3) {
312  dst[di++] = src[si++];
313  dst[di++] = src[si++];
314  } else if (src[si] == 0 && src[si + 1] == 0 && src[si + 2] != 0) {
315  if (src[si + 2] == 3) { // escape
316  dst[di++] = 0;
317  dst[di++] = 0;
318  si += 3;
319  continue;
320  } else // next start code
321  goto nsc;
322  }
323 
324  dst[di++] = src[si++];
325  }
326  while (si < length)
327  dst[di++] = src[si++];
328 
329 nsc:
330  memset(dst + di, 0, AV_INPUT_BUFFER_PADDING_SIZE);
331 
332  *dst_length = di;
333  *consumed = si + 1; // +1 for the header
334  /* FIXME store exact number of bits in the getbitcontext
335  * (it is needed for decoding) */
336  return dst;
337 }
338 
339 /**
340  * Identify the exact end of the bitstream
341  * @return the length of the trailing, or 0 if damaged
342  */
344 {
345  int v = *src;
346  int r;
347 
348  ff_tlog(h->avctx, "rbsp trailing %X\n", v);
349 
350  for (r = 1; r < 9; r++) {
351  if (v & 1)
352  return r;
353  v >>= 1;
354  }
355  return 0;
356 }
357 
359 {
360  int i;
361 
364  av_freep(&h->cbp_table);
365  av_freep(&h->mvd_table[0]);
366  av_freep(&h->mvd_table[1]);
367  av_freep(&h->direct_table);
370  h->slice_table = NULL;
371  av_freep(&h->list_counts);
372 
373  av_freep(&h->mb2b_xy);
374  av_freep(&h->mb2br_xy);
375 
380 
381  for (i = 0; i < h->nb_slice_ctx; i++) {
382  H264SliceContext *sl = &h->slice_ctx[i];
383 
384  av_freep(&sl->dc_val_base);
385  av_freep(&sl->er.mb_index2xy);
387  av_freep(&sl->er.er_temp_buffer);
388 
391  av_freep(&sl->top_borders[0]);
392  av_freep(&sl->top_borders[1]);
393 
396  sl->top_borders_allocated[0] = 0;
397  sl->top_borders_allocated[1] = 0;
398  }
399 }
400 
402 {
403  const int big_mb_num = h->mb_stride * (h->mb_height + 1);
404  const int row_mb_num = 2*h->mb_stride*FFMAX(h->avctx->thread_count, 1);
405  int x, y;
406 
408  row_mb_num, 8 * sizeof(uint8_t), fail)
410 
412  big_mb_num * 48 * sizeof(uint8_t), fail)
414  (big_mb_num + h->mb_stride) * sizeof(*h->slice_table_base), fail)
416  big_mb_num * sizeof(uint16_t), fail)
418  big_mb_num * sizeof(uint8_t), fail)
420  row_mb_num, 16 * sizeof(uint8_t), fail);
422  row_mb_num, 16 * sizeof(uint8_t), fail);
423  h->slice_ctx[0].mvd_table[0] = h->mvd_table[0];
424  h->slice_ctx[0].mvd_table[1] = h->mvd_table[1];
425 
427  4 * big_mb_num * sizeof(uint8_t), fail);
429  big_mb_num * sizeof(uint8_t), fail)
430 
431  memset(h->slice_table_base, -1,
432  (big_mb_num + h->mb_stride) * sizeof(*h->slice_table_base));
433  h->slice_table = h->slice_table_base + h->mb_stride * 2 + 1;
434 
436  big_mb_num * sizeof(uint32_t), fail);
438  big_mb_num * sizeof(uint32_t), fail);
439  for (y = 0; y < h->mb_height; y++)
440  for (x = 0; x < h->mb_width; x++) {
441  const int mb_xy = x + y * h->mb_stride;
442  const int b_xy = 4 * x + 4 * y * h->b_stride;
443 
444  h->mb2b_xy[mb_xy] = b_xy;
445  h->mb2br_xy[mb_xy] = 8 * (FMO ? mb_xy : (mb_xy % (2 * h->mb_stride)));
446  }
447 
448  if (!h->dequant4_coeff[0])
450 
451  return 0;
452 
453 fail:
455  return AVERROR(ENOMEM);
456 }
457 
458 /**
459  * Init context
460  * Allocate buffers which are not shared amongst multiple threads.
461  */
463 {
464  ERContext *er = &sl->er;
465  int mb_array_size = h->mb_height * h->mb_stride;
466  int y_size = (2 * h->mb_width + 1) * (2 * h->mb_height + 1);
467  int c_size = h->mb_stride * (h->mb_height + 1);
468  int yc_size = y_size + 2 * c_size;
469  int x, y, i;
470 
471  sl->ref_cache[0][scan8[5] + 1] =
472  sl->ref_cache[0][scan8[7] + 1] =
473  sl->ref_cache[0][scan8[13] + 1] =
474  sl->ref_cache[1][scan8[5] + 1] =
475  sl->ref_cache[1][scan8[7] + 1] =
476  sl->ref_cache[1][scan8[13] + 1] = PART_NOT_AVAILABLE;
477 
478  if (sl != h->slice_ctx) {
479  memset(er, 0, sizeof(*er));
480  } else
481  if (CONFIG_ERROR_RESILIENCE) {
482 
483  /* init ER */
484  er->avctx = h->avctx;
486  er->opaque = h;
487  er->quarter_sample = 1;
488 
489  er->mb_num = h->mb_num;
490  er->mb_width = h->mb_width;
491  er->mb_height = h->mb_height;
492  er->mb_stride = h->mb_stride;
493  er->b8_stride = h->mb_width * 2 + 1;
494 
495  // error resilience code looks cleaner with this
497  (h->mb_num + 1) * sizeof(int), fail);
498 
499  for (y = 0; y < h->mb_height; y++)
500  for (x = 0; x < h->mb_width; x++)
501  er->mb_index2xy[x + y * h->mb_width] = x + y * h->mb_stride;
502 
503  er->mb_index2xy[h->mb_height * h->mb_width] = (h->mb_height - 1) *
504  h->mb_stride + h->mb_width;
505 
507  mb_array_size * sizeof(uint8_t), fail);
508 
510  h->mb_height * h->mb_stride, fail);
511 
513  yc_size * sizeof(int16_t), fail);
514  er->dc_val[0] = sl->dc_val_base + h->mb_width * 2 + 2;
515  er->dc_val[1] = sl->dc_val_base + y_size + h->mb_stride + 1;
516  er->dc_val[2] = er->dc_val[1] + c_size;
517  for (i = 0; i < yc_size; i++)
518  sl->dc_val_base[i] = 1024;
519  }
520 
521  return 0;
522 
523 fail:
524  return AVERROR(ENOMEM); // ff_h264_free_tables will clean up for us
525 }
526 
527 static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size,
528  int parse_extradata);
529 
531 {
532  AVCodecContext *avctx = h->avctx;
533  int ret;
534 
535  if (!buf || size <= 0)
536  return -1;
537 
538  if (buf[0] == 1) {
539  int i, cnt, nalsize;
540  const unsigned char *p = buf;
541 
542  h->is_avc = 1;
543 
544  if (size < 7) {
545  av_log(avctx, AV_LOG_ERROR,
546  "avcC %d too short\n", size);
547  return AVERROR_INVALIDDATA;
548  }
549  /* sps and pps in the avcC always have length coded with 2 bytes,
550  * so put a fake nal_length_size = 2 while parsing them */
551  h->nal_length_size = 2;
552  // Decode sps from avcC
553  cnt = *(p + 5) & 0x1f; // Number of sps
554  p += 6;
555  for (i = 0; i < cnt; i++) {
556  nalsize = AV_RB16(p) + 2;
557  if(nalsize > size - (p-buf))
558  return AVERROR_INVALIDDATA;
559  ret = decode_nal_units(h, p, nalsize, 1);
560  if (ret < 0) {
561  av_log(avctx, AV_LOG_ERROR,
562  "Decoding sps %d from avcC failed\n", i);
563  return ret;
564  }
565  p += nalsize;
566  }
567  // Decode pps from avcC
568  cnt = *(p++); // Number of pps
569  for (i = 0; i < cnt; i++) {
570  nalsize = AV_RB16(p) + 2;
571  if(nalsize > size - (p-buf))
572  return AVERROR_INVALIDDATA;
573  ret = decode_nal_units(h, p, nalsize, 1);
574  if (ret < 0) {
575  av_log(avctx, AV_LOG_ERROR,
576  "Decoding pps %d from avcC failed\n", i);
577  return ret;
578  }
579  p += nalsize;
580  }
581  // Store right nal length size that will be used to parse all other nals
582  h->nal_length_size = (buf[4] & 0x03) + 1;
583  } else {
584  h->is_avc = 0;
585  ret = decode_nal_units(h, buf, size, 1);
586  if (ret < 0)
587  return ret;
588  }
589  return size;
590 }
591 
593 {
594  int i;
595 
596  h->avctx = avctx;
597  h->backup_width = -1;
598  h->backup_height = -1;
600  h->dequant_coeff_pps = -1;
601  h->current_sps_id = -1;
602  h->cur_chroma_format_idc = -1;
603 
605  h->slice_context_count = 1;
606  h->workaround_bugs = avctx->workaround_bugs;
607  h->flags = avctx->flags;
608  h->prev_poc_msb = 1 << 16;
609  h->x264_build = -1;
610  h->recovery_frame = -1;
611  h->frame_recovered = 0;
612  h->prev_frame_num = -1;
614 
615  h->next_outputed_poc = INT_MIN;
616  for (i = 0; i < MAX_DELAYED_PIC_COUNT; i++)
617  h->last_pocs[i] = INT_MIN;
618 
620 
622 
624  h->slice_ctx = av_mallocz_array(h->nb_slice_ctx, sizeof(*h->slice_ctx));
625  if (!h->slice_ctx) {
626  h->nb_slice_ctx = 0;
627  return AVERROR(ENOMEM);
628  }
629 
630  for (i = 0; i < H264_MAX_PICTURE_COUNT; i++) {
631  h->DPB[i].f = av_frame_alloc();
632  if (!h->DPB[i].f)
633  return AVERROR(ENOMEM);
634  }
635 
636  h->cur_pic.f = av_frame_alloc();
637  if (!h->cur_pic.f)
638  return AVERROR(ENOMEM);
639 
641  if (!h->last_pic_for_ec.f)
642  return AVERROR(ENOMEM);
643 
644  for (i = 0; i < h->nb_slice_ctx; i++)
645  h->slice_ctx[i].h264 = h;
646 
647  return 0;
648 }
649 
651 
653 {
654  H264Context *h = avctx->priv_data;
655  int ret;
656 
657  ret = h264_init_context(avctx, h);
658  if (ret < 0)
659  return ret;
660 
661  /* set defaults */
662  if (!avctx->has_b_frames)
663  h->low_delay = 1;
664 
665  ret = ff_thread_once(&h264_vlc_init, ff_h264_decode_init_vlc);
666  if (ret != 0) {
667  av_log(avctx, AV_LOG_ERROR, "pthread_once has failed.");
668  return AVERROR_UNKNOWN;
669  }
670 
671  if (avctx->codec_id == AV_CODEC_ID_H264) {
672  if (avctx->ticks_per_frame == 1) {
673  if(h->avctx->time_base.den < INT_MAX/2) {
674  h->avctx->time_base.den *= 2;
675  } else
676  h->avctx->time_base.num /= 2;
677  }
678  avctx->ticks_per_frame = 2;
679  }
680 
681  if (avctx->extradata_size > 0 && avctx->extradata) {
682  ret = ff_h264_decode_extradata(h, avctx->extradata, avctx->extradata_size);
683  if (ret < 0) {
684  h264_decode_end(avctx);
685  return ret;
686  }
687  }
688 
692  h->low_delay = 0;
693  }
694 
695  avctx->internal->allocate_progress = 1;
696 
698 
699  if (h->enable_er < 0 && (avctx->active_thread_type & FF_THREAD_SLICE))
700  h->enable_er = 0;
701 
702  if (h->enable_er && (avctx->active_thread_type & FF_THREAD_SLICE)) {
703  av_log(avctx, AV_LOG_WARNING,
704  "Error resilience with slice threads is enabled. It is unsafe and unsupported and may crash. "
705  "Use it at your own risk\n");
706  }
707 
708  return 0;
709 }
710 
711 #if HAVE_THREADS
712 static int decode_init_thread_copy(AVCodecContext *avctx)
713 {
714  H264Context *h = avctx->priv_data;
715  int ret;
716 
717  if (!avctx->internal->is_copy)
718  return 0;
719 
720  memset(h, 0, sizeof(*h));
721 
722  ret = h264_init_context(avctx, h);
723  if (ret < 0)
724  return ret;
725 
726  h->context_initialized = 0;
727 
728  return 0;
729 }
730 #endif
731 
732 /**
733  * Run setup operations that must be run after slice header decoding.
734  * This includes finding the next displayed frame.
735  *
736  * @param h h264 master context
737  * @param setup_finished enough NALs have been read that we can call
738  * ff_thread_finish_setup()
739  */
740 static void decode_postinit(H264Context *h, int setup_finished)
741 {
743  H264Picture *cur = h->cur_pic_ptr;
744  int i, pics, out_of_order, out_idx;
745 
746  h->cur_pic_ptr->f->pict_type = h->pict_type;
747 
748  if (h->next_output_pic)
749  return;
750 
751  if (cur->field_poc[0] == INT_MAX || cur->field_poc[1] == INT_MAX) {
752  /* FIXME: if we have two PAFF fields in one packet, we can't start
753  * the next thread here. If we have one field per packet, we can.
754  * The check in decode_nal_units() is not good enough to find this
755  * yet, so we assume the worst for now. */
756  // if (setup_finished)
757  // ff_thread_finish_setup(h->avctx);
758  if (cur->field_poc[0] == INT_MAX && cur->field_poc[1] == INT_MAX)
759  return;
760  if (h->avctx->hwaccel || h->missing_fields <=1)
761  return;
762  }
763 
764  cur->f->interlaced_frame = 0;
765  cur->f->repeat_pict = 0;
766 
767  /* Signal interlacing information externally. */
768  /* Prioritize picture timing SEI information over used
769  * decoding process if it exists. */
770 
771  if (h->sps.pic_struct_present_flag) {
772  switch (h->sei_pic_struct) {
774  break;
777  cur->f->interlaced_frame = 1;
778  break;
781  if (FIELD_OR_MBAFF_PICTURE(h))
782  cur->f->interlaced_frame = 1;
783  else
784  // try to flag soft telecine progressive
786  break;
789  /* Signal the possibility of telecined film externally
790  * (pic_struct 5,6). From these hints, let the applications
791  * decide if they apply deinterlacing. */
792  cur->f->repeat_pict = 1;
793  break;
795  cur->f->repeat_pict = 2;
796  break;
798  cur->f->repeat_pict = 4;
799  break;
800  }
801 
802  if ((h->sei_ct_type & 3) &&
804  cur->f->interlaced_frame = (h->sei_ct_type & (1 << 1)) != 0;
805  } else {
806  /* Derive interlacing flag from used decoding process. */
808  }
810 
811  if (cur->field_poc[0] != cur->field_poc[1]) {
812  /* Derive top_field_first from field pocs. */
813  cur->f->top_field_first = cur->field_poc[0] < cur->field_poc[1];
814  } else {
815  if (h->sps.pic_struct_present_flag) {
816  /* Use picture timing SEI information. Even if it is a
817  * information of a past frame, better than nothing. */
820  cur->f->top_field_first = 1;
821  else
822  cur->f->top_field_first = 0;
823  } else if (cur->f->interlaced_frame) {
824  /* Default to top field first when pic_struct_present_flag
825  * is not set but interlaced frame detected */
826  cur->f->top_field_first = 1;
827  } else {
828  /* Most likely progressive */
829  cur->f->top_field_first = 0;
830  }
831  }
832 
833  if (h->sei_frame_packing_present &&
838  AVStereo3D *stereo = av_stereo3d_create_side_data(cur->f);
839  if (stereo) {
840  switch (h->frame_packing_arrangement_type) {
841  case 0:
842  stereo->type = AV_STEREO3D_CHECKERBOARD;
843  break;
844  case 1:
845  stereo->type = AV_STEREO3D_COLUMNS;
846  break;
847  case 2:
848  stereo->type = AV_STEREO3D_LINES;
849  break;
850  case 3:
851  if (h->quincunx_subsampling)
853  else
854  stereo->type = AV_STEREO3D_SIDEBYSIDE;
855  break;
856  case 4:
857  stereo->type = AV_STEREO3D_TOPBOTTOM;
858  break;
859  case 5:
861  break;
862  case 6:
863  stereo->type = AV_STEREO3D_2D;
864  break;
865  }
866 
867  if (h->content_interpretation_type == 2)
868  stereo->flags = AV_STEREO3D_FLAG_INVERT;
869  }
870  }
871 
874  double angle = h->sei_anticlockwise_rotation * 360 / (double) (1 << 16);
875  AVFrameSideData *rotation = av_frame_new_side_data(cur->f,
877  sizeof(int32_t) * 9);
878  if (rotation) {
879  av_display_rotation_set((int32_t *)rotation->data, angle);
880  av_display_matrix_flip((int32_t *)rotation->data,
881  h->sei_hflip, h->sei_vflip);
882  }
883  }
884 
887  sizeof(uint8_t));
888 
889  if (sd) {
892  }
893  }
894 
895  if (h->a53_caption) {
898  h->a53_caption_size);
899  if (sd)
900  memcpy(sd->data, h->a53_caption, h->a53_caption_size);
901  av_freep(&h->a53_caption);
902  h->a53_caption_size = 0;
904  }
905 
906  cur->mmco_reset = h->mmco_reset;
907  h->mmco_reset = 0;
908 
909  // FIXME do something with unavailable reference frames
910 
911  /* Sort B-frames into display order */
915  }
916  h->low_delay = !h->avctx->has_b_frames;
917 
918  for (i = 0; 1; i++) {
919  if(i == MAX_DELAYED_PIC_COUNT || cur->poc < h->last_pocs[i]){
920  if(i)
921  h->last_pocs[i-1] = cur->poc;
922  break;
923  } else if(i) {
924  h->last_pocs[i-1]= h->last_pocs[i];
925  }
926  }
927  out_of_order = MAX_DELAYED_PIC_COUNT - i;
928  if( cur->f->pict_type == AV_PICTURE_TYPE_B
930  out_of_order = FFMAX(out_of_order, 1);
931  if (out_of_order == MAX_DELAYED_PIC_COUNT) {
932  av_log(h->avctx, AV_LOG_VERBOSE, "Invalid POC %d<%d\n", cur->poc, h->last_pocs[0]);
933  for (i = 1; i < MAX_DELAYED_PIC_COUNT; i++)
934  h->last_pocs[i] = INT_MIN;
935  h->last_pocs[0] = cur->poc;
936  cur->mmco_reset = 1;
937  } else if(h->avctx->has_b_frames < out_of_order && !h->sps.bitstream_restriction_flag){
938  av_log(h->avctx, AV_LOG_INFO, "Increasing reorder buffer to %d\n", out_of_order);
939  h->avctx->has_b_frames = out_of_order;
940  h->low_delay = 0;
941  }
942 
943  pics = 0;
944  while (h->delayed_pic[pics])
945  pics++;
946 
948 
949  h->delayed_pic[pics++] = cur;
950  if (cur->reference == 0)
951  cur->reference = DELAYED_PIC_REF;
952 
953  out = h->delayed_pic[0];
954  out_idx = 0;
955  for (i = 1; h->delayed_pic[i] &&
956  !h->delayed_pic[i]->f->key_frame &&
957  !h->delayed_pic[i]->mmco_reset;
958  i++)
959  if (h->delayed_pic[i]->poc < out->poc) {
960  out = h->delayed_pic[i];
961  out_idx = i;
962  }
963  if (h->avctx->has_b_frames == 0 &&
964  (h->delayed_pic[0]->f->key_frame || h->delayed_pic[0]->mmco_reset))
965  h->next_outputed_poc = INT_MIN;
966  out_of_order = out->poc < h->next_outputed_poc;
967 
968  if (out_of_order || pics > h->avctx->has_b_frames) {
969  out->reference &= ~DELAYED_PIC_REF;
970  // for frame threading, the owner must be the second field's thread or
971  // else the first thread can release the picture and reuse it unsafely
972  for (i = out_idx; h->delayed_pic[i]; i++)
973  h->delayed_pic[i] = h->delayed_pic[i + 1];
974  }
975  if (!out_of_order && pics > h->avctx->has_b_frames) {
976  h->next_output_pic = out;
977  if (out_idx == 0 && h->delayed_pic[0] && (h->delayed_pic[0]->f->key_frame || h->delayed_pic[0]->mmco_reset)) {
978  h->next_outputed_poc = INT_MIN;
979  } else
980  h->next_outputed_poc = out->poc;
981  } else {
982  av_log(h->avctx, AV_LOG_DEBUG, "no picture %s\n", out_of_order ? "ooo" : "");
983  }
984 
985  if (h->next_output_pic) {
986  if (h->next_output_pic->recovered) {
987  // We have reached an recovery point and all frames after it in
988  // display order are "recovered".
990  }
992  }
993 
994  if (setup_finished && !h->avctx->hwaccel) {
996 
998  h->setup_finished = 1;
999  }
1000 }
1001 
1003 {
1004  int list, i;
1005  int luma_def, chroma_def;
1006 
1007  sl->use_weight = 0;
1008  sl->use_weight_chroma = 0;
1010  if (h->sps.chroma_format_idc)
1012 
1013  if (sl->luma_log2_weight_denom > 7U) {
1014  av_log(h->avctx, AV_LOG_ERROR, "luma_log2_weight_denom %d is out of range\n", sl->luma_log2_weight_denom);
1015  sl->luma_log2_weight_denom = 0;
1016  }
1017  if (sl->chroma_log2_weight_denom > 7U) {
1018  av_log(h->avctx, AV_LOG_ERROR, "chroma_log2_weight_denom %d is out of range\n", sl->chroma_log2_weight_denom);
1019  sl->chroma_log2_weight_denom = 0;
1020  }
1021 
1022  luma_def = 1 << sl->luma_log2_weight_denom;
1023  chroma_def = 1 << sl->chroma_log2_weight_denom;
1024 
1025  for (list = 0; list < 2; list++) {
1026  sl->luma_weight_flag[list] = 0;
1027  sl->chroma_weight_flag[list] = 0;
1028  for (i = 0; i < sl->ref_count[list]; i++) {
1029  int luma_weight_flag, chroma_weight_flag;
1030 
1031  luma_weight_flag = get_bits1(&sl->gb);
1032  if (luma_weight_flag) {
1033  sl->luma_weight[i][list][0] = get_se_golomb(&sl->gb);
1034  sl->luma_weight[i][list][1] = get_se_golomb(&sl->gb);
1035  if (sl->luma_weight[i][list][0] != luma_def ||
1036  sl->luma_weight[i][list][1] != 0) {
1037  sl->use_weight = 1;
1038  sl->luma_weight_flag[list] = 1;
1039  }
1040  } else {
1041  sl->luma_weight[i][list][0] = luma_def;
1042  sl->luma_weight[i][list][1] = 0;
1043  }
1044 
1045  if (h->sps.chroma_format_idc) {
1046  chroma_weight_flag = get_bits1(&sl->gb);
1047  if (chroma_weight_flag) {
1048  int j;
1049  for (j = 0; j < 2; j++) {
1050  sl->chroma_weight[i][list][j][0] = get_se_golomb(&sl->gb);
1051  sl->chroma_weight[i][list][j][1] = get_se_golomb(&sl->gb);
1052  if (sl->chroma_weight[i][list][j][0] != chroma_def ||
1053  sl->chroma_weight[i][list][j][1] != 0) {
1054  sl->use_weight_chroma = 1;
1055  sl->chroma_weight_flag[list] = 1;
1056  }
1057  }
1058  } else {
1059  int j;
1060  for (j = 0; j < 2; j++) {
1061  sl->chroma_weight[i][list][j][0] = chroma_def;
1062  sl->chroma_weight[i][list][j][1] = 0;
1063  }
1064  }
1065  }
1066  }
1067  if (sl->slice_type_nos != AV_PICTURE_TYPE_B)
1068  break;
1069  }
1070  sl->use_weight = sl->use_weight || sl->use_weight_chroma;
1071  return 0;
1072 }
1073 
1074 /**
1075  * instantaneous decoder refresh.
1076  */
1077 static void idr(H264Context *h)
1078 {
1079  int i;
1081  h->prev_frame_num =
1082  h->prev_frame_num_offset = 0;
1083  h->prev_poc_msb = 1<<16;
1084  h->prev_poc_lsb = 0;
1085  for (i = 0; i < MAX_DELAYED_PIC_COUNT; i++)
1086  h->last_pocs[i] = INT_MIN;
1087 }
1088 
1089 /* forget old pics after a seek */
1091 {
1092  int i, j;
1093 
1094  h->next_outputed_poc = INT_MIN;
1095  h->prev_interlaced_frame = 1;
1096  idr(h);
1097 
1098  h->prev_frame_num = -1;
1099  if (h->cur_pic_ptr) {
1100  h->cur_pic_ptr->reference = 0;
1101  for (j=i=0; h->delayed_pic[i]; i++)
1102  if (h->delayed_pic[i] != h->cur_pic_ptr)
1103  h->delayed_pic[j++] = h->delayed_pic[i];
1104  h->delayed_pic[j] = NULL;
1105  }
1107 
1108  h->first_field = 0;
1109  ff_h264_reset_sei(h);
1110  h->recovery_frame = -1;
1111  h->frame_recovered = 0;
1112  h->current_slice = 0;
1113  h->mmco_reset = 1;
1114  for (i = 0; i < h->nb_slice_ctx; i++)
1115  h->slice_ctx[i].list_count = 0;
1116 }
1117 
1118 /* forget old pics after a seek */
1119 static void flush_dpb(AVCodecContext *avctx)
1120 {
1121  H264Context *h = avctx->priv_data;
1122  int i;
1123 
1124  memset(h->delayed_pic, 0, sizeof(h->delayed_pic));
1125 
1127 
1128  for (i = 0; i < H264_MAX_PICTURE_COUNT; i++)
1129  ff_h264_unref_picture(h, &h->DPB[i]);
1130  h->cur_pic_ptr = NULL;
1132 
1133  h->mb_y = 0;
1134 
1136  h->context_initialized = 0;
1137 }
1138 
1139 int ff_init_poc(H264Context *h, int pic_field_poc[2], int *pic_poc)
1140 {
1141  const int max_frame_num = 1 << h->sps.log2_max_frame_num;
1142  int field_poc[2];
1143 
1145  if (h->frame_num < h->prev_frame_num)
1146  h->frame_num_offset += max_frame_num;
1147 
1148  if (h->sps.poc_type == 0) {
1149  const int max_poc_lsb = 1 << h->sps.log2_max_poc_lsb;
1150 
1151  if (h->poc_lsb < h->prev_poc_lsb &&
1152  h->prev_poc_lsb - h->poc_lsb >= max_poc_lsb / 2)
1153  h->poc_msb = h->prev_poc_msb + max_poc_lsb;
1154  else if (h->poc_lsb > h->prev_poc_lsb &&
1155  h->prev_poc_lsb - h->poc_lsb < -max_poc_lsb / 2)
1156  h->poc_msb = h->prev_poc_msb - max_poc_lsb;
1157  else
1158  h->poc_msb = h->prev_poc_msb;
1159  field_poc[0] =
1160  field_poc[1] = h->poc_msb + h->poc_lsb;
1161  if (h->picture_structure == PICT_FRAME)
1162  field_poc[1] += h->delta_poc_bottom;
1163  } else if (h->sps.poc_type == 1) {
1164  int abs_frame_num, expected_delta_per_poc_cycle, expectedpoc;
1165  int i;
1166 
1167  if (h->sps.poc_cycle_length != 0)
1168  abs_frame_num = h->frame_num_offset + h->frame_num;
1169  else
1170  abs_frame_num = 0;
1171 
1172  if (h->nal_ref_idc == 0 && abs_frame_num > 0)
1173  abs_frame_num--;
1174 
1175  expected_delta_per_poc_cycle = 0;
1176  for (i = 0; i < h->sps.poc_cycle_length; i++)
1177  // FIXME integrate during sps parse
1178  expected_delta_per_poc_cycle += h->sps.offset_for_ref_frame[i];
1179 
1180  if (abs_frame_num > 0) {
1181  int poc_cycle_cnt = (abs_frame_num - 1) / h->sps.poc_cycle_length;
1182  int frame_num_in_poc_cycle = (abs_frame_num - 1) % h->sps.poc_cycle_length;
1183 
1184  expectedpoc = poc_cycle_cnt * expected_delta_per_poc_cycle;
1185  for (i = 0; i <= frame_num_in_poc_cycle; i++)
1186  expectedpoc = expectedpoc + h->sps.offset_for_ref_frame[i];
1187  } else
1188  expectedpoc = 0;
1189 
1190  if (h->nal_ref_idc == 0)
1191  expectedpoc = expectedpoc + h->sps.offset_for_non_ref_pic;
1192 
1193  field_poc[0] = expectedpoc + h->delta_poc[0];
1194  field_poc[1] = field_poc[0] + h->sps.offset_for_top_to_bottom_field;
1195 
1196  if (h->picture_structure == PICT_FRAME)
1197  field_poc[1] += h->delta_poc[1];
1198  } else {
1199  int poc = 2 * (h->frame_num_offset + h->frame_num);
1200 
1201  if (!h->nal_ref_idc)
1202  poc--;
1203 
1204  field_poc[0] = poc;
1205  field_poc[1] = poc;
1206  }
1207 
1209  pic_field_poc[0] = field_poc[0];
1211  pic_field_poc[1] = field_poc[1];
1212  *pic_poc = FFMIN(pic_field_poc[0], pic_field_poc[1]);
1213 
1214  return 0;
1215 }
1216 
1217 /**
1218  * Compute profile from profile_idc and constraint_set?_flags.
1219  *
1220  * @param sps SPS
1221  *
1222  * @return profile as defined by FF_PROFILE_H264_*
1223  */
1225 {
1226  int profile = sps->profile_idc;
1227 
1228  switch (sps->profile_idc) {
1230  // constraint_set1_flag set to 1
1231  profile |= (sps->constraint_set_flags & 1 << 1) ? FF_PROFILE_H264_CONSTRAINED : 0;
1232  break;
1236  // constraint_set3_flag set to 1
1237  profile |= (sps->constraint_set_flags & 1 << 3) ? FF_PROFILE_H264_INTRA : 0;
1238  break;
1239  }
1240 
1241  return profile;
1242 }
1243 
1245 {
1246  int ref_count[2], list_count;
1247  int num_ref_idx_active_override_flag;
1248 
1249  // set defaults, might be overridden a few lines later
1250  ref_count[0] = h->pps.ref_count[0];
1251  ref_count[1] = h->pps.ref_count[1];
1252 
1253  if (sl->slice_type_nos != AV_PICTURE_TYPE_I) {
1254  unsigned max[2];
1255  max[0] = max[1] = h->picture_structure == PICT_FRAME ? 15 : 31;
1256 
1257  if (sl->slice_type_nos == AV_PICTURE_TYPE_B)
1258  sl->direct_spatial_mv_pred = get_bits1(&sl->gb);
1259  num_ref_idx_active_override_flag = get_bits1(&sl->gb);
1260 
1261  if (num_ref_idx_active_override_flag) {
1262  ref_count[0] = get_ue_golomb(&sl->gb) + 1;
1263  if (sl->slice_type_nos == AV_PICTURE_TYPE_B) {
1264  ref_count[1] = get_ue_golomb(&sl->gb) + 1;
1265  } else
1266  // full range is spec-ok in this case, even for frames
1267  ref_count[1] = 1;
1268  }
1269 
1270  if (ref_count[0]-1 > max[0] || ref_count[1]-1 > max[1]){
1271  av_log(h->avctx, AV_LOG_ERROR, "reference overflow %u > %u or %u > %u\n", ref_count[0]-1, max[0], ref_count[1]-1, max[1]);
1272  sl->ref_count[0] = sl->ref_count[1] = 0;
1273  sl->list_count = 0;
1274  return AVERROR_INVALIDDATA;
1275  }
1276 
1277  if (sl->slice_type_nos == AV_PICTURE_TYPE_B)
1278  list_count = 2;
1279  else
1280  list_count = 1;
1281  } else {
1282  list_count = 0;
1283  ref_count[0] = ref_count[1] = 0;
1284  }
1285 
1286  if (list_count != sl->list_count ||
1287  ref_count[0] != sl->ref_count[0] ||
1288  ref_count[1] != sl->ref_count[1]) {
1289  sl->ref_count[0] = ref_count[0];
1290  sl->ref_count[1] = ref_count[1];
1291  sl->list_count = list_count;
1292  return 1;
1293  }
1294 
1295  return 0;
1296 }
1297 
1298 static const uint8_t start_code[] = { 0x00, 0x00, 0x01 };
1299 
1300 static int get_bit_length(H264Context *h, const uint8_t *buf,
1301  const uint8_t *ptr, int dst_length,
1302  int i, int next_avc)
1303 {
1304  if ((h->workaround_bugs & FF_BUG_AUTODETECT) && i + 3 < next_avc &&
1305  buf[i] == 0x00 && buf[i + 1] == 0x00 &&
1306  buf[i + 2] == 0x01 && buf[i + 3] == 0xE0)
1308 
1309  if (!(h->workaround_bugs & FF_BUG_TRUNCATED))
1310  while (dst_length > 0 && ptr[dst_length - 1] == 0)
1311  dst_length--;
1312 
1313  if (!dst_length)
1314  return 0;
1315 
1316  return 8 * dst_length - decode_rbsp_trailing(h, ptr + dst_length - 1);
1317 }
1318 
1319 static int get_last_needed_nal(H264Context *h, const uint8_t *buf, int buf_size)
1320 {
1321  int next_avc = h->is_avc ? 0 : buf_size;
1322  int nal_index = 0;
1323  int buf_index = 0;
1324  int nals_needed = 0;
1325  int first_slice = 0;
1326 
1327  while(1) {
1328  GetBitContext gb;
1329  int nalsize = 0;
1330  int dst_length, bit_length, consumed;
1331  const uint8_t *ptr;
1332 
1333  if (buf_index >= next_avc) {
1334  nalsize = get_avc_nalsize(h, buf, buf_size, &buf_index);
1335  if (nalsize < 0)
1336  break;
1337  next_avc = buf_index + nalsize;
1338  } else {
1339  buf_index = find_start_code(buf, buf_size, buf_index, next_avc);
1340  if (buf_index >= buf_size)
1341  break;
1342  if (buf_index >= next_avc)
1343  continue;
1344  }
1345 
1346  ptr = ff_h264_decode_nal(h, &h->slice_ctx[0], buf + buf_index, &dst_length, &consumed,
1347  next_avc - buf_index);
1348 
1349  if (!ptr || dst_length < 0)
1350  return AVERROR_INVALIDDATA;
1351 
1352  buf_index += consumed;
1353 
1354  bit_length = get_bit_length(h, buf, ptr, dst_length,
1355  buf_index, next_avc);
1356  nal_index++;
1357 
1358  /* packets can sometimes contain multiple PPS/SPS,
1359  * e.g. two PAFF field pictures in one packet, or a demuxer
1360  * which splits NALs strangely if so, when frame threading we
1361  * can't start the next thread until we've read all of them */
1362  switch (h->nal_unit_type) {
1363  case NAL_SPS:
1364  case NAL_PPS:
1365  nals_needed = nal_index;
1366  break;
1367  case NAL_DPA:
1368  case NAL_IDR_SLICE:
1369  case NAL_SLICE:
1370  init_get_bits(&gb, ptr, bit_length);
1371  if (!get_ue_golomb_long(&gb) || // first_mb_in_slice
1372  !first_slice ||
1373  first_slice != h->nal_unit_type)
1374  nals_needed = nal_index;
1375  if (!first_slice)
1376  first_slice = h->nal_unit_type;
1377  }
1378  }
1379 
1380  return nals_needed;
1381 }
1382 
1383 static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size,
1384  int parse_extradata)
1385 {
1386  AVCodecContext *const avctx = h->avctx;
1387  H264SliceContext *sl;
1388  int buf_index;
1389  unsigned context_count;
1390  int next_avc;
1391  int nals_needed = 0; ///< number of NALs that need decoding before the next frame thread starts
1392  int nal_index;
1393  int idr_cleared=0;
1394  int ret = 0;
1395 
1396  h->nal_unit_type= 0;
1397 
1398  if(!h->slice_context_count)
1399  h->slice_context_count= 1;
1401  if (!(avctx->flags2 & AV_CODEC_FLAG2_CHUNKS)) {
1402  h->current_slice = 0;
1403  if (!h->first_field)
1404  h->cur_pic_ptr = NULL;
1405  ff_h264_reset_sei(h);
1406  }
1407 
1408  if (h->nal_length_size == 4) {
1409  if (buf_size > 8 && AV_RB32(buf) == 1 && AV_RB32(buf+5) > (unsigned)buf_size) {
1410  h->is_avc = 0;
1411  }else if(buf_size > 3 && AV_RB32(buf) > 1 && AV_RB32(buf) <= (unsigned)buf_size)
1412  h->is_avc = 1;
1413  }
1414 
1415  if (avctx->active_thread_type & FF_THREAD_FRAME)
1416  nals_needed = get_last_needed_nal(h, buf, buf_size);
1417 
1418  {
1419  buf_index = 0;
1420  context_count = 0;
1421  next_avc = h->is_avc ? 0 : buf_size;
1422  nal_index = 0;
1423  for (;;) {
1424  int consumed;
1425  int dst_length;
1426  int bit_length;
1427  const uint8_t *ptr;
1428  int nalsize = 0;
1429  int err;
1430 
1431  if (buf_index >= next_avc) {
1432  nalsize = get_avc_nalsize(h, buf, buf_size, &buf_index);
1433  if (nalsize < 0)
1434  break;
1435  next_avc = buf_index + nalsize;
1436  } else {
1437  buf_index = find_start_code(buf, buf_size, buf_index, next_avc);
1438  if (buf_index >= buf_size)
1439  break;
1440  if (buf_index >= next_avc)
1441  continue;
1442  }
1443 
1444  sl = &h->slice_ctx[context_count];
1445 
1446  ptr = ff_h264_decode_nal(h, sl, buf + buf_index, &dst_length,
1447  &consumed, next_avc - buf_index);
1448  if (!ptr || dst_length < 0) {
1449  ret = -1;
1450  goto end;
1451  }
1452 
1453  bit_length = get_bit_length(h, buf, ptr, dst_length,
1454  buf_index + consumed, next_avc);
1455 
1456  if (h->avctx->debug & FF_DEBUG_STARTCODE)
1458  "NAL %d/%d at %d/%d length %d\n",
1459  h->nal_unit_type, h->nal_ref_idc, buf_index, buf_size, dst_length);
1460 
1461  if (h->is_avc && (nalsize != consumed) && nalsize)
1463  "AVC: Consumed only %d bytes instead of %d\n",
1464  consumed, nalsize);
1465 
1466  buf_index += consumed;
1467  nal_index++;
1468 
1469  if (avctx->skip_frame >= AVDISCARD_NONREF &&
1470  h->nal_ref_idc == 0 &&
1471  h->nal_unit_type != NAL_SEI)
1472  continue;
1473 
1474 again:
1475  /* Ignore per frame NAL unit type during extradata
1476  * parsing. Decoding slices is not possible in codec init
1477  * with frame-mt */
1478  if (parse_extradata) {
1479  switch (h->nal_unit_type) {
1480  case NAL_IDR_SLICE:
1481  case NAL_SLICE:
1482  case NAL_DPA:
1483  case NAL_DPB:
1484  case NAL_DPC:
1486  "Ignoring NAL %d in global header/extradata\n",
1487  h->nal_unit_type);
1488  // fall through to next case
1489  case NAL_AUXILIARY_SLICE:
1491  }
1492  }
1493 
1494  err = 0;
1495 
1496  switch (h->nal_unit_type) {
1497  case NAL_IDR_SLICE:
1498  if ((ptr[0] & 0xFC) == 0x98) {
1499  av_log(h->avctx, AV_LOG_ERROR, "Invalid inter IDR frame\n");
1500  h->next_outputed_poc = INT_MIN;
1501  ret = -1;
1502  goto end;
1503  }
1504  if (h->nal_unit_type != NAL_IDR_SLICE) {
1506  "Invalid mix of idr and non-idr slices\n");
1507  ret = -1;
1508  goto end;
1509  }
1510  if(!idr_cleared) {
1511  if (h->current_slice && (avctx->active_thread_type & FF_THREAD_SLICE)) {
1512  av_log(h, AV_LOG_ERROR, "invalid mixed IDR / non IDR frames cannot be decoded in slice multithreading mode\n");
1513  ret = AVERROR_INVALIDDATA;
1514  goto end;
1515  }
1516  idr(h); // FIXME ensure we don't lose some frames if there is reordering
1517  }
1518  idr_cleared = 1;
1519  h->has_recovery_point = 1;
1520  case NAL_SLICE:
1521  init_get_bits(&sl->gb, ptr, bit_length);
1522 
1523  if ( nals_needed >= nal_index
1524  || (!(avctx->active_thread_type & FF_THREAD_FRAME) && !context_count))
1525  h->au_pps_id = -1;
1526 
1527  if ((err = ff_h264_decode_slice_header(h, sl)))
1528  break;
1529 
1530  if (h->sei_recovery_frame_cnt >= 0) {
1532  h->valid_recovery_point = 1;
1533 
1534  if ( h->recovery_frame < 0
1535  || av_mod_uintp2(h->recovery_frame - h->frame_num, h->sps.log2_max_frame_num) > h->sei_recovery_frame_cnt) {
1536  h->recovery_frame = av_mod_uintp2(h->frame_num + h->sei_recovery_frame_cnt, h->sps.log2_max_frame_num);
1537 
1538  if (!h->valid_recovery_point)
1539  h->recovery_frame = h->frame_num;
1540  }
1541  }
1542 
1543  h->cur_pic_ptr->f->key_frame |=
1544  (h->nal_unit_type == NAL_IDR_SLICE);
1545 
1546  if (h->nal_unit_type == NAL_IDR_SLICE ||
1547  h->recovery_frame == h->frame_num) {
1548  h->recovery_frame = -1;
1549  h->cur_pic_ptr->recovered = 1;
1550  }
1551  // If we have an IDR, all frames after it in decoded order are
1552  // "recovered".
1553  if (h->nal_unit_type == NAL_IDR_SLICE)
1555 #if 1
1557 #else
1559 #endif
1560 
1561  if (h->current_slice == 1) {
1562  if (!(avctx->flags2 & AV_CODEC_FLAG2_CHUNKS))
1563  decode_postinit(h, nal_index >= nals_needed);
1564 
1565  if (h->avctx->hwaccel &&
1566  (ret = h->avctx->hwaccel->start_frame(h->avctx, buf, buf_size)) < 0)
1567  goto end;
1568 #if FF_API_CAP_VDPAU
1569  if (CONFIG_H264_VDPAU_DECODER &&
1572 #endif
1573  }
1574 
1575  if (sl->redundant_pic_count == 0) {
1576  if (avctx->hwaccel) {
1577  ret = avctx->hwaccel->decode_slice(avctx,
1578  &buf[buf_index - consumed],
1579  consumed);
1580  if (ret < 0)
1581  goto end;
1582 #if FF_API_CAP_VDPAU
1583  } else if (CONFIG_H264_VDPAU_DECODER &&
1586  start_code,
1587  sizeof(start_code));
1589  &buf[buf_index - consumed],
1590  consumed);
1591 #endif
1592  } else
1593  context_count++;
1594  }
1595  break;
1596  case NAL_DPA:
1597  case NAL_DPB:
1598  case NAL_DPC:
1599  avpriv_request_sample(avctx, "data partitioning");
1600  break;
1601  case NAL_SEI:
1602  init_get_bits(&h->gb, ptr, bit_length);
1603  ret = ff_h264_decode_sei(h);
1604  if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))
1605  goto end;
1606  break;
1607  case NAL_SPS:
1608  init_get_bits(&h->gb, ptr, bit_length);
1609  if (ff_h264_decode_seq_parameter_set(h, 0) >= 0)
1610  break;
1611  if (h->is_avc ? nalsize : 1) {
1613  "SPS decoding failure, trying again with the complete NAL\n");
1614  if (h->is_avc)
1615  av_assert0(next_avc - buf_index + consumed == nalsize);
1616  if ((next_avc - buf_index + consumed - 1) >= INT_MAX/8)
1617  break;
1618  init_get_bits(&h->gb, &buf[buf_index + 1 - consumed],
1619  8*(next_avc - buf_index + consumed - 1));
1620  if (ff_h264_decode_seq_parameter_set(h, 0) >= 0)
1621  break;
1622  }
1623  init_get_bits(&h->gb, ptr, bit_length);
1625 
1626  break;
1627  case NAL_PPS:
1628  init_get_bits(&h->gb, ptr, bit_length);
1629  ret = ff_h264_decode_picture_parameter_set(h, bit_length);
1630  if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))
1631  goto end;
1632  break;
1633  case NAL_AUD:
1634  case NAL_END_SEQUENCE:
1635  case NAL_END_STREAM:
1636  case NAL_FILLER_DATA:
1637  case NAL_SPS_EXT:
1638  case NAL_AUXILIARY_SLICE:
1639  break;
1640  case NAL_FF_IGNORE:
1641  break;
1642  default:
1643  av_log(avctx, AV_LOG_DEBUG, "Unknown NAL code: %d (%d bits)\n",
1644  h->nal_unit_type, bit_length);
1645  }
1646 
1647  if (context_count == h->max_contexts) {
1648  ret = ff_h264_execute_decode_slices(h, context_count);
1649  if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))
1650  goto end;
1651  context_count = 0;
1652  }
1653 
1654  if (err < 0 || err == SLICE_SKIPED) {
1655  if (err < 0)
1656  av_log(h->avctx, AV_LOG_ERROR, "decode_slice_header error\n");
1657  sl->ref_count[0] = sl->ref_count[1] = sl->list_count = 0;
1658  } else if (err == SLICE_SINGLETHREAD) {
1659  if (context_count > 1) {
1660  ret = ff_h264_execute_decode_slices(h, context_count - 1);
1661  if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))
1662  goto end;
1663  context_count = 0;
1664  }
1665  /* Slice could not be decoded in parallel mode, restart. Note
1666  * that rbsp_buffer is not transferred, but since we no longer
1667  * run in parallel mode this should not be an issue. */
1668  sl = &h->slice_ctx[0];
1669  goto again;
1670  }
1671  }
1672  }
1673  if (context_count) {
1674  ret = ff_h264_execute_decode_slices(h, context_count);
1675  if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))
1676  goto end;
1677  }
1678 
1679  ret = 0;
1680 end:
1681  /* clean up */
1682  if (h->cur_pic_ptr && !h->droppable) {
1685  }
1686 
1687  return (ret < 0) ? ret : buf_index;
1688 }
1689 
1690 /**
1691  * Return the number of bytes consumed for building the current frame.
1692  */
1693 static int get_consumed_bytes(int pos, int buf_size)
1694 {
1695  if (pos == 0)
1696  pos = 1; // avoid infinite loops (I doubt that is needed but...)
1697  if (pos + 10 > buf_size)
1698  pos = buf_size; // oops ;)
1699 
1700  return pos;
1701 }
1702 
1704 {
1705  AVFrame *src = srcp->f;
1706  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(src->format);
1707  int i;
1708  int ret = av_frame_ref(dst, src);
1709  if (ret < 0)
1710  return ret;
1711 
1712  av_dict_set(&dst->metadata, "stereo_mode", ff_h264_sei_stereo_mode(h), 0);
1713 
1714  h->backup_width = h->avctx->width;
1715  h->backup_height = h->avctx->height;
1716  h->backup_pix_fmt = h->avctx->pix_fmt;
1717 
1718  h->avctx->width = dst->width;
1719  h->avctx->height = dst->height;
1720  h->avctx->pix_fmt = dst->format;
1721 
1722  if (srcp->sei_recovery_frame_cnt == 0)
1723  dst->key_frame = 1;
1724  if (!srcp->crop)
1725  return 0;
1726 
1727  for (i = 0; i < desc->nb_components; i++) {
1728  int hshift = (i > 0) ? desc->log2_chroma_w : 0;
1729  int vshift = (i > 0) ? desc->log2_chroma_h : 0;
1730  int off = ((srcp->crop_left >> hshift) << h->pixel_shift) +
1731  (srcp->crop_top >> vshift) * dst->linesize[i];
1732  dst->data[i] += off;
1733  }
1734  return 0;
1735 }
1736 
1737 static int is_extra(const uint8_t *buf, int buf_size)
1738 {
1739  int cnt= buf[5]&0x1f;
1740  const uint8_t *p= buf+6;
1741  while(cnt--){
1742  int nalsize= AV_RB16(p) + 2;
1743  if(nalsize > buf_size - (p-buf) || p[2]!=0x67)
1744  return 0;
1745  p += nalsize;
1746  }
1747  cnt = *(p++);
1748  if(!cnt)
1749  return 0;
1750  while(cnt--){
1751  int nalsize= AV_RB16(p) + 2;
1752  if(nalsize > buf_size - (p-buf) || p[2]!=0x68)
1753  return 0;
1754  p += nalsize;
1755  }
1756  return 1;
1757 }
1758 
1759 static int h264_decode_frame(AVCodecContext *avctx, void *data,
1760  int *got_frame, AVPacket *avpkt)
1761 {
1762  const uint8_t *buf = avpkt->data;
1763  int buf_size = avpkt->size;
1764  H264Context *h = avctx->priv_data;
1765  AVFrame *pict = data;
1766  int buf_index = 0;
1767  H264Picture *out;
1768  int i, out_idx;
1769  int ret;
1770 
1771  h->flags = avctx->flags;
1772  h->setup_finished = 0;
1773 
1774  if (h->backup_width != -1) {
1775  avctx->width = h->backup_width;
1776  h->backup_width = -1;
1777  }
1778  if (h->backup_height != -1) {
1779  avctx->height = h->backup_height;
1780  h->backup_height = -1;
1781  }
1782  if (h->backup_pix_fmt != AV_PIX_FMT_NONE) {
1783  avctx->pix_fmt = h->backup_pix_fmt;
1785  }
1786 
1788 
1789  /* end of stream, output what is still in the buffers */
1790  if (buf_size == 0) {
1791  out:
1792 
1793  h->cur_pic_ptr = NULL;
1794  h->first_field = 0;
1795 
1796  // FIXME factorize this with the output code below
1797  out = h->delayed_pic[0];
1798  out_idx = 0;
1799  for (i = 1;
1800  h->delayed_pic[i] &&
1801  !h->delayed_pic[i]->f->key_frame &&
1802  !h->delayed_pic[i]->mmco_reset;
1803  i++)
1804  if (h->delayed_pic[i]->poc < out->poc) {
1805  out = h->delayed_pic[i];
1806  out_idx = i;
1807  }
1808 
1809  for (i = out_idx; h->delayed_pic[i]; i++)
1810  h->delayed_pic[i] = h->delayed_pic[i + 1];
1811 
1812  if (out) {
1813  out->reference &= ~DELAYED_PIC_REF;
1814  ret = output_frame(h, pict, out);
1815  if (ret < 0)
1816  return ret;
1817  *got_frame = 1;
1818  }
1819 
1820  return buf_index;
1821  }
1823  int side_size;
1824  uint8_t *side = av_packet_get_side_data(avpkt, AV_PKT_DATA_NEW_EXTRADATA, &side_size);
1825  if (is_extra(side, side_size))
1826  ff_h264_decode_extradata(h, side, side_size);
1827  }
1828  if(h->is_avc && buf_size >= 9 && buf[0]==1 && buf[2]==0 && (buf[4]&0xFC)==0xFC && (buf[5]&0x1F) && buf[8]==0x67){
1829  if (is_extra(buf, buf_size))
1830  return ff_h264_decode_extradata(h, buf, buf_size);
1831  }
1832 
1833  buf_index = decode_nal_units(h, buf, buf_size, 0);
1834  if (buf_index < 0)
1835  return AVERROR_INVALIDDATA;
1836 
1837  if (!h->cur_pic_ptr && h->nal_unit_type == NAL_END_SEQUENCE) {
1838  av_assert0(buf_index <= buf_size);
1839  goto out;
1840  }
1841 
1842  if (!(avctx->flags2 & AV_CODEC_FLAG2_CHUNKS) && !h->cur_pic_ptr) {
1843  if (avctx->skip_frame >= AVDISCARD_NONREF ||
1844  buf_size >= 4 && !memcmp("Q264", buf, 4))
1845  return buf_size;
1846  av_log(avctx, AV_LOG_ERROR, "no frame!\n");
1847  return AVERROR_INVALIDDATA;
1848  }
1849 
1850  if (!(avctx->flags2 & AV_CODEC_FLAG2_CHUNKS) ||
1851  (h->mb_y >= h->mb_height && h->mb_height)) {
1852  if (avctx->flags2 & AV_CODEC_FLAG2_CHUNKS)
1853  decode_postinit(h, 1);
1854 
1855  if ((ret = ff_h264_field_end(h, &h->slice_ctx[0], 0)) < 0)
1856  return ret;
1857 
1858  /* Wait for second field. */
1859  *got_frame = 0;
1860  if (h->next_output_pic && ((avctx->flags & AV_CODEC_FLAG_OUTPUT_CORRUPT) ||
1861  (avctx->flags2 & AV_CODEC_FLAG2_SHOW_ALL) ||
1862  h->next_output_pic->recovered)) {
1863  if (!h->next_output_pic->recovered)
1865 
1866  if (!h->avctx->hwaccel &&
1867  (h->next_output_pic->field_poc[0] == INT_MAX ||
1868  h->next_output_pic->field_poc[1] == INT_MAX)
1869  ) {
1870  int p;
1871  AVFrame *f = h->next_output_pic->f;
1872  int field = h->next_output_pic->field_poc[0] == INT_MAX;
1873  uint8_t *dst_data[4];
1874  int linesizes[4];
1875  const uint8_t *src_data[4];
1876 
1877  av_log(h->avctx, AV_LOG_DEBUG, "Duplicating field %d to fill missing\n", field);
1878 
1879  for (p = 0; p<4; p++) {
1880  dst_data[p] = f->data[p] + (field^1)*f->linesize[p];
1881  src_data[p] = f->data[p] + field *f->linesize[p];
1882  linesizes[p] = 2*f->linesize[p];
1883  }
1884 
1885  av_image_copy(dst_data, linesizes, src_data, linesizes,
1886  f->format, f->width, f->height>>1);
1887  }
1888 
1889  ret = output_frame(h, pict, h->next_output_pic);
1890  if (ret < 0)
1891  return ret;
1892  *got_frame = 1;
1893  if (CONFIG_MPEGVIDEO) {
1894  ff_print_debug_info2(h->avctx, pict, NULL,
1898  &h->low_delay,
1899  h->mb_width, h->mb_height, h->mb_stride, 1);
1900  }
1901  }
1902  }
1903 
1904  av_assert0(pict->buf[0] || !*got_frame);
1905 
1907 
1908  return get_consumed_bytes(buf_index, buf_size);
1909 }
1910 
1912 {
1913  int i;
1914 
1916 
1917  for (i = 0; i < H264_MAX_PICTURE_COUNT; i++) {
1918  ff_h264_unref_picture(h, &h->DPB[i]);
1919  av_frame_free(&h->DPB[i].f);
1920  }
1921  memset(h->delayed_pic, 0, sizeof(h->delayed_pic));
1922 
1923  h->cur_pic_ptr = NULL;
1924 
1925  for (i = 0; i < h->nb_slice_ctx; i++)
1926  av_freep(&h->slice_ctx[i].rbsp_buffer);
1927  av_freep(&h->slice_ctx);
1928  h->nb_slice_ctx = 0;
1929 
1930  h->a53_caption_size = 0;
1931  av_freep(&h->a53_caption);
1932 
1933  for (i = 0; i < MAX_SPS_COUNT; i++)
1934  av_freep(h->sps_buffers + i);
1935 
1936  for (i = 0; i < MAX_PPS_COUNT; i++)
1937  av_freep(h->pps_buffers + i);
1938 }
1939 
1941 {
1942  H264Context *h = avctx->priv_data;
1943 
1946 
1948  av_frame_free(&h->cur_pic.f);
1951 
1952  return 0;
1953 }
1954 
1955 #define OFFSET(x) offsetof(H264Context, x)
1956 #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
1957 static const AVOption h264_options[] = {
1958  {"is_avc", "is avc", offsetof(H264Context, is_avc), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, 0},
1959  {"nal_length_size", "nal_length_size", offsetof(H264Context, nal_length_size), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 4, 0},
1960  { "enable_er", "Enable error resilience on damaged frames (unsafe)", OFFSET(enable_er), AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, VD },
1961  { NULL },
1962 };
1963 
1964 static const AVClass h264_class = {
1965  .class_name = "H264 Decoder",
1966  .item_name = av_default_item_name,
1967  .option = h264_options,
1968  .version = LIBAVUTIL_VERSION_INT,
1969 };
1970 
1972  .name = "h264",
1973  .long_name = NULL_IF_CONFIG_SMALL("H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10"),
1974  .type = AVMEDIA_TYPE_VIDEO,
1975  .id = AV_CODEC_ID_H264,
1976  .priv_data_size = sizeof(H264Context),
1978  .close = h264_decode_end,
1980  .capabilities = /*AV_CODEC_CAP_DRAW_HORIZ_BAND |*/ AV_CODEC_CAP_DR1 |
1983  .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
1984  .flush = flush_dpb,
1985  .init_thread_copy = ONLY_IF_THREADS_ENABLED(decode_init_thread_copy),
1986  .update_thread_context = ONLY_IF_THREADS_ENABLED(ff_h264_update_thread_context),
1988  .priv_class = &h264_class,
1989 };
1990 
1991 #if CONFIG_H264_VDPAU_DECODER && FF_API_VDPAU
1992 static const AVClass h264_vdpau_class = {
1993  .class_name = "H264 VDPAU Decoder",
1994  .item_name = av_default_item_name,
1995  .option = h264_options,
1996  .version = LIBAVUTIL_VERSION_INT,
1997 };
1998 
1999 AVCodec ff_h264_vdpau_decoder = {
2000  .name = "h264_vdpau",
2001  .long_name = NULL_IF_CONFIG_SMALL("H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (VDPAU acceleration)"),
2002  .type = AVMEDIA_TYPE_VIDEO,
2003  .id = AV_CODEC_ID_H264,
2004  .priv_data_size = sizeof(H264Context),
2006  .close = h264_decode_end,
2009  .flush = flush_dpb,
2010  .pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_VDPAU_H264,
2011  AV_PIX_FMT_NONE},
2013  .priv_class = &h264_vdpau_class,
2014 };
2015 #endif
int chroma_format_idc
Definition: h264.h:179
struct H264Context * h264
Definition: h264.h:368
#define ff_tlog(ctx,...)
Definition: internal.h:65
void ff_h264_unref_picture(H264Context *h, H264Picture *pic)
Definition: h264_picture.c:47
#define NULL
Definition: coverity.c:32
const struct AVCodec * codec
Definition: avcodec.h:1541
int ff_h264_check_intra_pred_mode(const H264Context *h, H264SliceContext *sl, int mode, int is_chroma)
Check if the top & left blocks are available if needed and change the dc mode so it only uses the ava...
Definition: h264.c:187
void ff_h264_flush_change(H264Context *h)
Definition: h264.c:1090
int(* start_frame)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size)
Called at the beginning of each frame or field picture.
Definition: avcodec.h:3560
int workaround_bugs
Definition: h264.h:559
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size, int parse_extradata)
Definition: h264.c:1383
#define DC_128_PRED8x8
Definition: h264pred.h:76
GetBitContext gb
Definition: h264.h:529
int sei_recovery_frame_cnt
Definition: h264.h:349
#define AV_NUM_DATA_POINTERS
Definition: frame.h:182
#define SLICE_FLAG_ALLOW_FIELD
allow draw_horiz_band() with field slices (MPEG2 field pics)
Definition: avcodec.h:2068
enum AVPixelFormat backup_pix_fmt
Definition: h264.h:551
int ff_h264_execute_decode_slices(H264Context *h, unsigned context_count)
Call decode_slice() for each context.
Definition: h264_slice.c:2531
5: top field, bottom field, top field repeated, in that order
Definition: h264.h:153
int low_delay
Definition: h264.h:555
int mb_num
Definition: h264.h:626
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2157
mpeg2/4 4:2:0, h264 default for 4:2:0
Definition: pixfmt.h:464
This structure describes decoded (raw) audio or video data.
Definition: frame.h:181
#define FF_ALLOCZ_ARRAY_OR_GOTO(ctx, p, nelem, elsize, label)
Definition: internal.h:157
int16_t mv_cache[2][5 *8][2]
Motion vector cache.
Definition: h264.h:491
AVOption.
Definition: opt.h:245
static const AVClass h264_class
Definition: h264.c:1964
int delta_poc[2]
Definition: h264.h:654
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
static void flush(AVCodecContext *avctx)
static int get_se_golomb(GetBitContext *gb)
read signed exp golomb code.
Definition: golomb.h:183
int luma_weight[48][2][2]
Definition: h264.h:395
int quincunx_subsampling
Definition: h264.h:738
int edge_emu_buffer_allocated
Definition: h264.h:479
Definition: h264.h:120
int a53_caption_size
Definition: h264.h:752
3: top field, bottom field, in that order
Definition: h264.h:151
#define H264_MAX_PICTURE_COUNT
Definition: h264.h:47
int first_field
Definition: h264.h:596
misc image utilities
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
static int init_thread_copy(AVCodecContext *avctx)
Definition: tta.c:390
#define LIBAVUTIL_VERSION_INT
Definition: version.h:70
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
Definition: frame.h:357
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
uint16_t * cbp_table
Definition: h264.h:601
av_cold int ff_h264_decode_init(AVCodecContext *avctx)
Definition: h264.c:652
const uint8_t * ff_h264_decode_nal(H264Context *h, H264SliceContext *sl, const uint8_t *src, int *dst_length, int *consumed, int length)
Decode a network abstraction layer unit.
Definition: h264.c:229
7: frame doubling
Definition: h264.h:155
#define MAX_PPS_COUNT
Definition: h264.h:51
Sequence parameter set.
Definition: h264.h:175
int mb_y
Definition: h264.h:623
int bitstream_restriction_flag
Definition: h264.h:215
#define FF_PROFILE_H264_INTRA
Definition: avcodec.h:3058
unsigned int ref_count[2]
num_ref_idx_l0/1_active_minus1 + 1
Definition: h264.h:246
#define FMO
Definition: h264.h:63
int num
numerator
Definition: rational.h:44
int repeat_pict
When decoding, this signals how much the picture must be delayed.
Definition: frame.h:307
int bipred_scratchpad_allocated
Definition: h264.h:478
static int get_last_needed_nal(H264Context *h, const uint8_t *buf, int buf_size)
Definition: h264.c:1319
int size
Definition: avcodec.h:1468
#define DELAYED_PIC_REF
Value of Picture.reference when Picture is not a reference picture, but is held for delayed output...
Definition: diracdec.c:64
AVBufferPool * mb_type_pool
Definition: h264.h:834
int crop
Definition: h264.h:351
void ff_h264_draw_horiz_band(const H264Context *h, H264SliceContext *sl, int y, int height)
Definition: h264.c:101
int16_t(*[2] motion_val)[2]
Definition: h264.h:322
int flags
Definition: h264.h:558
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1752
int mb_height
Definition: h264.h:624
H264Picture * delayed_pic[MAX_DELAYED_PIC_COUNT+2]
Definition: h264.h:675
int is_avc
Used to parse AVC variant of h264.
Definition: h264.h:637
AVBufferPool * ref_index_pool
Definition: h264.h:836
void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
Same behaviour av_fast_malloc but the buffer has additional AV_INPUT_BUFFER_PADDING_SIZE at the end w...
Definition: utils.c:119
void ff_h264_free_tables(H264Context *h)
Definition: h264.c:358
int ff_h264_get_profile(SPS *sps)
Compute profile from profile_idc and constraint_set?_flags.
Definition: h264.c:1224
int sei_reguserdata_afd_present
User data registered by Rec.
Definition: h264.h:750
void ff_h264_decode_init_vlc(void)
Definition: h264_cavlc.c:327
H264Context.
Definition: h264.h:522
AVFrame * f
Definition: h264.h:315
#define AV_CODEC_FLAG2_CHUNKS
Input bitstream might be truncated at a packet boundaries instead of only at frame boundaries...
Definition: avcodec.h:821
int prev_poc_msb
poc_msb of the last reference pic for POC type 0
Definition: h264.h:656
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_WB24 unsigned int_TMPL AV_RB16
Definition: bytestream.h:87
4: bottom field, top field, in that order
Definition: h264.h:152
#define FRAME_RECOVERED_IDR
We have seen an IDR, so all the following frames in coded order are correctly decodable.
Definition: h264.h:800
Views are next to each other.
Definition: stereo3d.h:45
AVCodec.
Definition: avcodec.h:3392
int picture_structure
Definition: h264.h:595
int luma_weight_flag[2]
7.4.3.2 luma_weight_lX_flag
Definition: h264.h:392
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:92
int profile_idc
Definition: h264.h:177
unsigned current_sps_id
id of the current SPS
Definition: h264.h:580
unsigned int ref_count[2]
num_ref_idx_l0/1_active_minus1 + 1
Definition: h264.h:465
int avpriv_h264_has_num_reorder_frames(AVCodecContext *avctx)
Definition: h264.c:59
int ff_set_ref_count(H264Context *h, H264SliceContext *sl)
Definition: h264.c:1244
#define FF_PROFILE_H264_HIGH_444_PREDICTIVE
Definition: avcodec.h:3070
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avcodec.h:1661
uint8_t * chroma_pred_mode_table
Definition: h264.h:604
int setup_finished
Definition: h264.h:817
enum AVDiscard skip_frame
Skip decoding for selected frames.
Definition: avcodec.h:3139
#define AV_RN32A(p)
Definition: intreadwrite.h:526
BYTE int const BYTE * srcp
Definition: avisynth_c.h:676
struct AVHWAccel * hwaccel
Hardware accelerator in use.
Definition: avcodec.h:2843
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:72
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Definition: avcodec.h:881
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
#define FF_PROFILE_H264_BASELINE
Definition: avcodec.h:3060
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
uint32_t(*[6] dequant4_coeff)[16]
Definition: h264.h:588
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
Definition: internal.h:40
uint8_t * a53_caption
Definition: h264.h:753
uint8_t
#define av_cold
Definition: attributes.h:82
int prev_frame_num_offset
for POC type 2
Definition: h264.h:659
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:141
int offset_for_non_ref_pic
Definition: h264.h:185
mode
Definition: f_perms.c:27
AVOptions.
void ff_h264_reset_sei(H264Context *h)
Reset SEI values at the beginning of the frame.
Definition: h264_sei.c:37
Stereo 3D type: this structure describes how two videos are packed within a single video surface...
Definition: stereo3d.h:123
static int h264_init_context(AVCodecContext *avctx, H264Context *h)
Definition: h264.c:592
int poc
frame POC
Definition: h264.h:334
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:90
AVCodec ff_h264_decoder
Definition: h264.c:1971
Multithreading support functions.
#define TOP_DC_PRED8x8
Definition: h264pred.h:75
static int find_start_code(const uint8_t *buf, int buf_size, int buf_index, int next_avc)
Definition: h264.h:1177
Definition: h264.h:114
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
Definition: frame.c:375
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:1647
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
Definition: bytestream.h:87
uint8_t(*[2] top_borders)[(16 *3)*2]
Definition: h264.h:477
int frame_recovered
Initial frame has been completely recovered.
Definition: h264.h:807
Structure to hold side data for an AVFrame.
Definition: frame.h:144
#define PICT_BOTTOM_FIELD
Definition: mpegutils.h:38
uint8_t * data
Definition: avcodec.h:1467
static int decode_rbsp_trailing(H264Context *h, const uint8_t *src)
Identify the exact end of the bitstream.
Definition: h264.c:343
#define AV_CODEC_CAP_HWACCEL_VDPAU
Codec can export data for HW decoding (VDPAU).
Definition: avcodec.h:892
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:192
AVDictionary * metadata
metadata.
Definition: frame.h:459
int interlaced_frame
The content of the picture is interlaced.
Definition: frame.h:312
#define MAX_DELAYED_PIC_COUNT
Definition: h264.h:55
static void fill_rectangle(SDL_Surface *screen, int x, int y, int w, int h, int color, int update)
Definition: ffplay.c:805
ptrdiff_t size
Definition: opengl_enc.c:101
void ff_thread_finish_setup(AVCodecContext *avctx)
If the codec defines update_thread_context(), call this when they are ready for the next thread to st...
high precision timer, useful to profile code
Views are alternated temporally.
Definition: stereo3d.h:66
int recovered
picture at IDR or recovery point + recovery count
Definition: h264.h:347
Active Format Description data consisting of a single byte as specified in ETSI TS 101 154 using AVAc...
Definition: frame.h:89
#define AVOnce
Definition: thread.h:158
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
Definition: avcodec.h:2269
#define av_log(a,...)
int sei_vflip
Definition: h264.h:745
unsigned int rbsp_buffer_size
Definition: h264.h:516
int last_pocs[MAX_DELAYED_PIC_COUNT]
Definition: h264.h:676
H.264 / AVC / MPEG4 part10 codec.
Definition: h264.h:121
#define U(x)
Definition: vp56_arith.h:37
int frame_num
Definition: h264.h:655
void ff_h264_hl_decode_mb(const H264Context *h, H264SliceContext *sl)
Definition: h264_mb.c:818
H264Picture DPB[H264_MAX_PICTURE_COUNT]
Definition: h264.h:531
int width
width and height of the video frame
Definition: frame.h:230
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
int has_b_frames
Size of the frame reordering buffer in the decoder.
Definition: avcodec.h:1846
int flags
Additional information about the frame packing.
Definition: stereo3d.h:132
static int get_ue_golomb(GetBitContext *gb)
Read an unsigned Exp-Golomb code in the range 0 to 8190.
Definition: golomb.h:53
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:101
static int get_consumed_bytes(int pos, int buf_size)
Return the number of bytes consumed for building the current frame.
Definition: h264.c:1693
int16_t * dc_val_base
Definition: h264.h:473
int poc_type
pic_order_cnt_type
Definition: h264.h:182
int context_initialized
Definition: h264.h:557
static const uint16_t mask[17]
Definition: lzw.c:38
ERContext er
Definition: h264.h:370
int nal_unit_type
Definition: h264.h:632
av_default_item_name
int num_reorder_frames
Definition: h264.h:216
int is_copy
Whether the parent AVCodecContext is a copy of the context which had init() called on it...
Definition: internal.h:111
#define AVERROR(e)
Definition: error.h:43
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:154
int backup_height
Definition: h264.h:550
#define ALZHEIMER_DC_L0T_PRED8x8
Definition: h264pred.h:79
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:176
int active_thread_type
Which multithreading methods are in use by the codec.
Definition: avcodec.h:2973
int8_t intra4x4_pred_mode_cache[5 *8]
Definition: h264.h:405
int ff_init_poc(H264Context *h, int pic_field_poc[2], int *pic_poc)
Definition: h264.c:1139
const char * r
Definition: vf_curves.c:107
int backup_width
Backup frame properties: needed, because they can be different between returned frame and last decode...
Definition: h264.h:549
static void flush_dpb(AVCodecContext *avctx)
Definition: h264.c:1119
int capabilities
Codec capabilities.
Definition: avcodec.h:3411
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
ATSC A53 Part 4 Closed Captions.
Definition: frame.h:58
static const AVOption h264_options[]
Definition: h264.c:1957
int ff_pred_weight_table(H264Context *h, H264SliceContext *sl)
Definition: h264.c:1002
void(* decode_mb)(void *opaque, int ref, int mv_dir, int mv_type, int(*mv)[2][4][2], int mb_x, int mb_y, int mb_intra, int mb_skipped)
PPS pps
current pps
Definition: h264.h:582
uint8_t(*[2] mvd_table)[2]
Definition: h264.h:605
#define FF_PROFILE_H264_HIGH_422
Definition: avcodec.h:3067
int prev_interlaced_frame
Complement sei_pic_struct SEI_PIC_STRUCT_TOP_BOTTOM and SEI_PIC_STRUCT_BOTTOM_TOP indicate interlaced...
Definition: h264.h:730
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:1627
ThreadFrame tf
Definition: h264.h:316
0: frame
Definition: h264.h:148
simple assert() macros that are a bit more flexible than ISO C assert().
#define PICT_TOP_FIELD
Definition: mpegutils.h:37
GLsizei GLsizei * length
Definition: opengl_enc.c:115
const char * name
Name of the codec implementation.
Definition: avcodec.h:3399
int direct_spatial_mv_pred
Definition: h264.h:449
unsigned int top_samples_available
Definition: h264.h:422
static AVOnce h264_vlc_init
Definition: h264.c:650
static av_always_inline uint32_t pack16to32(unsigned a, unsigned b)
Definition: h264.h:1021
int valid_recovery_point
Are the SEI recovery points looking valid.
Definition: h264.h:784
static const uint8_t offset[127][2]
Definition: vf_spp.c:92
uint8_t * list_counts
Array of list_count per MB specifying the slice type.
Definition: h264.h:598
#define FFMAX(a, b)
Definition: common.h:94
#define fail()
Definition: checkasm.h:80
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition: avcodec.h:919
void av_image_copy(uint8_t *dst_data[4], int dst_linesizes[4], const uint8_t *src_data[4], const int src_linesizes[4], enum AVPixelFormat pix_fmt, int width, int height)
Copy image in src_data to dst_data.
Definition: imgutils.c:302
int * mb_index2xy
int offset_for_top_to_bottom_field
Definition: h264.h:186
#define FIELD_OR_MBAFF_PICTURE(h)
Definition: h264.h:92
int slice_type_nos
S free slice type (SI/SP are remapped to I/P)
Definition: h264.h:374
int ff_h264_decode_slice_header(H264Context *h, H264SliceContext *sl)
Decode a slice header.
Definition: h264_slice.c:1150
static const uint8_t scan8[16 *3+3]
Definition: h264.h:1005
#define ONLY_IF_THREADS_ENABLED(x)
Define a function with only the non-default version specified.
Definition: internal.h:215
int crop_left
Definition: h264.h:352
uint8_t * error_status_table
int use_weight
Definition: h264.h:388
uint8_t * direct_table
Definition: h264.h:606
int nal_length_size
Number of bytes used for nal length (1, 2 or 4)
Definition: h264.h:638
useful rectangle filling function
uint8_t * data[3]
Definition: h264.h:357
void ff_vdpau_h264_picture_start(H264Context *h)
uint8_t nb_components
The number of components each pixel has, (1-4)
Definition: pixdesc.h:83
static void h264_er_decode_mb(void *opaque, int ref, int mv_dir, int mv_type, int(*mv)[2][4][2], int mb_x, int mb_y, int mb_intra, int mb_skipped)
Definition: h264.c:65
Views are packed per line, as if interlaced.
Definition: stereo3d.h:97
int sei_anticlockwise_rotation
Definition: h264.h:744
void(* draw_horiz_band)(struct AVCodecContext *s, const AVFrame *src, int offset[AV_NUM_DATA_POINTERS], int y, int type, int height)
If non NULL, 'draw_horiz_band' is called by the libavcodec decoder to draw a horizontal band...
Definition: avcodec.h:1785
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:252
int frame_num_offset
for POC type 2
Definition: h264.h:658
int flags
Frame flags, a combination of AV_FRAME_FLAGS.
Definition: frame.h:398
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
Definition: avcodec.h:2811
FPA sei_fpa
Definition: h264.h:786
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:53
int x264_build
Definition: h264.h:621
#define FF_THREAD_FRAME
Decode more than one frame at once.
Definition: avcodec.h:2965
uint32_t * mb2br_xy
Definition: h264.h:576
uint8_t * er_temp_buffer
#define OFFSET(x)
Definition: h264.c:1955
#define FFMIN(a, b)
Definition: common.h:96
uint16_t * slice_table
slice_table_base + 2*mb_stride + 1
Definition: h264.h:591
#define H264_MAX_THREADS
Definition: h264.h:48
int poc_cycle_length
num_ref_frames_in_pic_order_cnt_cycle
Definition: h264.h:187
int reference
Definition: h264.h:346
int sei_frame_packing_present
frame_packing_arrangment SEI message
Definition: h264.h:735
int width
picture width / height.
Definition: avcodec.h:1711
int redundant_pic_count
Definition: h264.h:442
int nb_slice_ctx
Definition: h264.h:537
uint32_t * mb_type
Definition: h264.h:325
#define AV_FRAME_FLAG_CORRUPT
The frame data may be corrupted, e.g.
Definition: frame.h:390
void ff_thread_report_progress(ThreadFrame *f, int n, int field)
Notify later decoding threads when part of their reference picture is ready.
SPS sps
current sps
Definition: h264.h:581
int32_t
PPS * pps_buffers[MAX_PPS_COUNT]
Definition: h264.h:644
int sei_hflip
Definition: h264.h:745
#define MAX_SPS_COUNT
Definition: h264.h:50
int ff_h264_decode_picture_parameter_set(H264Context *h, int bit_length)
Decode PPS.
Definition: h264_ps.c:630
#define FF_THREAD_SLICE
Decode more than one part of a single frame at once.
Definition: avcodec.h:2966
Context Adaptive Binary Arithmetic Coder inline functions.
int mmco_reset
Definition: h264.h:685
H264SliceContext * slice_ctx
Definition: h264.h:536
#define AV_EF_EXPLODE
abort decoding on minor error detection
Definition: avcodec.h:2822
int poc_lsb
Definition: h264.h:651
int reference
Definition: h264.h:360
static int h264_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: h264.c:1759
int ticks_per_frame
For some codecs, the time base is closer to the field rate than the frame rate.
Definition: avcodec.h:1670
int top_borders_allocated[2]
Definition: h264.h:480
uint8_t active_format_description
Definition: h264.h:751
int chroma_log2_weight_denom
Definition: h264.h:391
#define src
Definition: vp9dsp.c:530
static int output_frame(H264Context *h, AVFrame *dst, H264Picture *srcp)
Definition: h264.c:1703
Definition: h264.h:119
#define AV_STEREO3D_FLAG_INVERT
Inverted views, Right/Bottom represents the left view.
Definition: stereo3d.h:114
#define LEFT_DC_PRED8x8
Definition: h264pred.h:74
void av_display_rotation_set(int32_t matrix[9], double angle)
Initialize a transformation matrix describing a pure counterclockwise rotation by the specified angle...
Definition: display.c:50
#define PART_NOT_AVAILABLE
Definition: h264.h:567
int thread_count
thread count is used to decide how many independent tasks should be passed to execute() ...
Definition: avcodec.h:2954
uint8_t * edge_emu_buffer
Definition: h264.h:476
Views are packed per column.
Definition: stereo3d.h:107
FILE * out
Definition: movenc-test.c:54
int dequant_coeff_pps
reinit tables when pps changes
Definition: h264.h:646
static unsigned get_ue_golomb_long(GetBitContext *gb)
Read an unsigned Exp-Golomb code in the range 0 to UINT32_MAX-1.
Definition: golomb.h:85
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
Definition: avcodec.h:923
SPS * sps_buffers[MAX_SPS_COUNT]
Definition: h264.h:643
static const int8_t mv[256][2]
Definition: 4xm.c:77
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
Definition: frame.h:242
short offset_for_ref_frame[256]
Definition: h264.h:214
enum AVStereo3DType type
How views are packed within the video.
Definition: stereo3d.h:127
int ff_h264_slice_context_init(H264Context *h, H264SliceContext *sl)
Init context Allocate buffers which are not shared amongst multiple threads.
Definition: h264.c:462
int mb_stride
Definition: h264.h:625
#define AV_LOG_INFO
Standard information.
Definition: log.h:187
AVCodecContext * avctx
Definition: h264.h:524
#define AV_ONCE_INIT
Definition: thread.h:159
Libavcodec external API header.
H264 / AVC / MPEG4 part10 codec data table
This side data contains a 3x3 transformation matrix describing an affine transformation that needs to...
Definition: frame.h:84
static int get_bit_length(H264Context *h, const uint8_t *buf, const uint8_t *ptr, int dst_length, int i, int next_avc)
Definition: h264.c:1300
1: top field
Definition: h264.h:149
enum AVCodecID codec_id
Definition: avcodec.h:1549
void ff_h264_remove_all_refs(H264Context *h)
Definition: h264_refs.c:512
int prev_frame_num
frame_num of the last pic for POC type 1/2
Definition: h264.h:660
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:209
int next_outputed_poc
Definition: h264.h:678
int ff_h264_decode_sei(H264Context *h)
Decode SEI.
Definition: h264_sei.c:421
int poc_msb
Definition: h264.h:652
Views are next to each other, but when upscaling apply a checkerboard pattern.
Definition: stereo3d.h:87
int field_poc[2]
top/bottom POC
Definition: h264.h:333
#define AV_CODEC_FLAG2_FAST
Allow non spec compliant speedup tricks.
Definition: avcodec.h:802
int debug
debug
Definition: avcodec.h:2763
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
int max_contexts
Max number of threads / contexts.
Definition: h264.h:705
int recovery_frame
recovery_frame is the frame_num at which the next frame should be fully constructed.
Definition: h264.h:794
main external API structure.
Definition: avcodec.h:1532
void av_display_matrix_flip(int32_t matrix[9], int hflip, int vflip)
Flip the input matrix horizontally and/or vertically.
Definition: display.c:65
static void decode_postinit(H264Context *h, int setup_finished)
Run setup operations that must be run after slice header decoding.
Definition: h264.c:740
int ff_h264_alloc_tables(H264Context *h)
Allocate tables.
Definition: h264.c:401
2: bottom field
Definition: h264.h:150
uint8_t * data
Definition: frame.h:146
int ff_h264_check_intra4x4_pred_mode(const H264Context *h, H264SliceContext *sl)
Check if the top & left blocks are available if needed and change the dc mode so it only uses the ava...
Definition: h264.c:140
void * buf
Definition: avisynth_c.h:553
int frame_packing_arrangement_type
Definition: h264.h:736
void ff_print_debug_info2(AVCodecContext *avctx, AVFrame *pict, uint8_t *mbskip_table, uint32_t *mbtype_table, int8_t *qscale_table, int16_t(*motion_val[2])[2], int *low_delay, int mb_width, int mb_height, int mb_stride, int quarter_sample)
Print debugging info for the given picture.
Definition: mpegvideo.c:1580
int8_t * qscale_table
Definition: h264.h:319
int extradata_size
Definition: avcodec.h:1648
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition: dict.c:69
H.264 HW decoding with VDPAU, data[0] contains a vdpau_render_state struct which contains the bitstre...
Definition: pixfmt.h:105
int constraint_set_flags
constraint_set[0-3]_flag
Definition: h264.h:231
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:312
SEI_PicStructType sei_pic_struct
pic_struct in picture timing SEI message
Definition: h264.h:722
BYTE int const BYTE int int int height
Definition: avisynth_c.h:676
int ff_h264_update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
Definition: h264_slice.c:433
int slice_flags
slice flags
Definition: avcodec.h:2066
static int get_avc_nalsize(H264Context *h, const uint8_t *buf, int buf_size, int *buf_index)
Definition: h264.h:1187
Describe the class of an AVClass context structure.
Definition: log.h:67
#define FF_CODEC_PROPERTY_CLOSED_CAPTIONS
Definition: avcodec.h:3347
AVFrameSideData * av_frame_new_side_data(AVFrame *frame, enum AVFrameSideDataType type, int size)
Add a new side data to a frame.
Definition: frame.c:601
uint8_t non_zero_count_cache[15 *8]
non zero coeff count cache.
Definition: h264.h:486
Definition: h264.h:116
static int h264_decode_end(AVCodecContext *avctx)
Definition: h264.c:1940
void av_buffer_pool_uninit(AVBufferPool **ppool)
Mark the pool as being available for freeing.
Definition: buffer.c:250
int8_t * ref_index[2]
Definition: h264.h:331
int use_weight_chroma
Definition: h264.h:389
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:418
int pixel_shift
0 for 8-bit H264, 1 for high-bit-depth H264
Definition: h264.h:539
int mmco_reset
MMCO_RESET set this 1.
Definition: h264.h:336
H264Picture * cur_pic_ptr
Definition: h264.h:532
int mb_mbaff
mb_aff_frame && mb_field_decoding_flag
Definition: h264.h:440
int enable_er
Definition: h264.h:831
#define FF_COMPLIANCE_STRICT
Strictly conform to all the things in the spec no matter what consequences.
Definition: avcodec.h:2743
int frame_packing_arrangement_cancel_flag
is previous arrangement canceled, -1 if never received
Definition: h264.h:269
int allocate_progress
Whether to allocate progress for frame threading.
Definition: internal.h:126
int log2_max_poc_lsb
log2_max_pic_order_cnt_lsb_minus4
Definition: h264.h:183
6: bottom field, top field, bottom field repeated, in that order
Definition: h264.h:154
static int is_extra(const uint8_t *buf, int buf_size)
Definition: h264.c:1737
AVCodecContext * avctx
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:262
static const uint8_t start_code[]
Definition: h264.c:1298
mfxU16 profile
Definition: qsvenc.c:42
#define FF_BUG_AUTODETECT
autodetection
Definition: avcodec.h:2708
int pic_struct_present_flag
Definition: h264.h:222
AVStereo3D * av_stereo3d_create_side_data(AVFrame *frame)
Allocate a complete AVFrameSideData and add it to the frame.
Definition: stereo3d.c:32
unsigned int list_count
Definition: h264.h:466
av_cold void ff_h264_free_context(H264Context *h)
Free any data that may have been allocated in the H264 context like SPS, PPS etc. ...
Definition: h264.c:1911
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:192
int has_recovery_point
Definition: h264.h:809
#define MAX_MBPAIR_SIZE
Definition: h264.h:57
static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket *avpkt)
Definition: ccaption_dec.c:572
static void idr(H264Context *h)
instantaneous decoder refresh.
Definition: h264.c:1077
int ff_h264_decode_seq_parameter_set(H264Context *h, int ignore_truncation)
Decode SPS.
Definition: h264_ps.c:323
discard all non reference
Definition: avcodec.h:684
AVBufferPool * qscale_table_pool
Definition: h264.h:833
H264Picture * next_output_pic
Definition: h264.h:677
int slice_context_count
Definition: h264.h:707
AVBufferPool * motion_val_pool
Definition: h264.h:835
#define SLICE_SINGLETHREAD
Definition: h264.h:1220
common internal api header.
if(ret< 0)
Definition: vf_mcdeint.c:282
int ff_h264_decode_extradata(H264Context *h, const uint8_t *buf, int size)
Definition: h264.c:530
#define FRAME_RECOVERED_SEI
Sufficient number of frames have been decoded since a SEI recovery point, so all the following frames...
Definition: h264.h:805
Video is not stereoscopic (and metadata has to be there).
Definition: stereo3d.h:35
#define FF_ALLOC_OR_GOTO(ctx, p, size, label)
Definition: internal.h:130
uint16_t * slice_table_base
Definition: h264.h:648
int log2_max_frame_num
log2_max_frame_num_minus4 + 4
Definition: h264.h:181
int missing_fields
Definition: h264.h:811
Views are packed in a checkerboard-like structure per pixel.
Definition: stereo3d.h:76
int16_t * dc_val[3]
H.264 / AVC / MPEG4 part10 motion vector predicion.
Bi-dir predicted.
Definition: avutil.h:268
const char * ff_h264_sei_stereo_mode(H264Context *h)
Get stereo_mode string from the h264 frame_packing_arrangement.
Definition: h264_sei.c:491
int workaround_bugs
Work around bugs in encoders which sometimes cannot be detected automatically.
Definition: avcodec.h:2707
const AVProfile ff_h264_profiles[]
Definition: profiles.c:50
int cur_chroma_format_idc
Definition: h264.h:823
int8_t * intra4x4_pred_mode
Definition: h264.h:406
unsigned properties
Definition: avcodec.h:3345
int den
denominator
Definition: rational.h:45
uint8_t * rbsp_buffer
Definition: h264.h:515
int sei_ct_type
Bit set of clock types for fields/frames in picture timing SEI message.
Definition: h264.h:760
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
Definition: error.h:71
Definition: h264.h:115
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
Definition: avcodec.h:635
void * priv_data
Definition: avcodec.h:1574
int ff_h264_field_end(H264Context *h, H264SliceContext *sl, int in_setup)
Definition: h264_picture.c:154
#define PICT_FRAME
Definition: mpegutils.h:39
int prev_poc_lsb
poc_lsb of the last reference pic for POC type 0
Definition: h264.h:657
#define FF_DEBUG_STARTCODE
Definition: avcodec.h:2777
int8_t ref_cache[2][5 *8]
Definition: h264.h:492
#define AV_CODEC_FLAG_OUTPUT_CORRUPT
Output even those frames that might be corrupted.
Definition: avcodec.h:742
#define SLICE_SKIPED
Definition: h264.h:1221
#define VD
Definition: h264.c:1956
int top_field_first
If the content is interlaced, is top field displayed first.
Definition: frame.h:317
const uint16_t ff_h264_mb_sizes[4]
Definition: h264.c:57
struct AVCodecInternal * internal
Private context used for internal data.
Definition: avcodec.h:1582
#define FF_BUG_TRUNCATED
Definition: avcodec.h:2727
static int ff_thread_once(char *control, void(*routine)(void))
Definition: thread.h:161
int luma_log2_weight_denom
Definition: h264.h:390
int chroma_weight[48][2][2][2]
Definition: h264.h:396
H264Picture cur_pic
Definition: h264.h:533
int sei_display_orientation_present
display orientation SEI message
Definition: h264.h:743
Views are on top of each other.
Definition: stereo3d.h:55
int content_interpretation_type
Definition: h264.h:737
int key_frame
1 -> keyframe, 0-> not
Definition: frame.h:247
int mb_width
Definition: h264.h:624
enum AVPictureType pict_type
Definition: h264.h:715
int current_slice
current slice number, used to initialize slice_num of each thread/context
Definition: h264.h:697
int flags2
AV_CODEC_FLAG2_*.
Definition: avcodec.h:1634
uint32_t * mb2b_xy
Definition: h264.h:575
H264Ref ref_list[2][48]
0..15: frame refs, 16..47: mbaff field refs.
Definition: h264.h:467
int delta_poc_bottom
Definition: h264.h:653
H264Picture last_pic_for_ec
Definition: h264.h:534
int au_pps_id
pps_id of current access unit
Definition: h264.h:584
static void * av_mallocz_array(size_t nmemb, size_t size)
Definition: mem.h:229
int height
Definition: frame.h:230
int crop_top
Definition: h264.h:353
#define AV_CODEC_FLAG2_SHOW_ALL
Show all frames before the first keyframe.
Definition: avcodec.h:830
unsigned int left_samples_available
Definition: h264.h:424
uint8_t(*[2] mvd_table)[2]
Definition: h264.h:505
Definition: h264.h:118
#define av_freep(p)
uint8_t * av_packet_get_side_data(AVPacket *pkt, enum AVPacketSideDataType type, int *size)
Get side information from packet.
Definition: avpacket.c:320
void ff_vdpau_add_data_chunk(uint8_t *data, const uint8_t *buf, int buf_size)
int8_t * intra4x4_pred_mode
Definition: h264.h:561
#define FF_PROFILE_H264_CONSTRAINED
Definition: avcodec.h:3057
int(* decode_slice)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size)
Callback for each slice.
Definition: avcodec.h:3574
8: frame tripling
Definition: h264.h:156
#define AV_RN64A(p)
Definition: intreadwrite.h:530
int mb_field_decoding_flag
Definition: h264.h:439
uint8_t(* non_zero_count)[48]
Definition: h264.h:564
#define FF_PROFILE_H264_HIGH_10
Definition: avcodec.h:3065
exp golomb vlc stuff
uint8_t * bipred_scratchpad
Definition: h264.h:475
AVPixelFormat
Pixel format.
Definition: pixfmt.h:61
This structure stores compressed data.
Definition: avcodec.h:1444
int sei_recovery_frame_cnt
recovery_frame_cnt from SEI message
Definition: h264.h:779
int droppable
Definition: h264.h:553
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:856
int strict_std_compliance
strictly follow the standard (MPEG4, ...).
Definition: avcodec.h:2741
#define STARTCODE_TEST
int nal_ref_idc
Definition: h264.h:631
GetBitContext gb
Definition: h264.h:369
for(j=16;j >0;--j)
#define FF_ALLOCZ_OR_GOTO(ctx, p, size, label)
Definition: internal.h:139
int b_stride
Definition: h264.h:577
Context Adaptive Binary Arithmetic Coder.
int chroma_weight_flag[2]
7.4.3.2 chroma_weight_lX_flag
Definition: h264.h:393
void ff_h264_init_dequant_tables(H264Context *h)
Definition: h264_slice.c:367