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 / MPEG-4 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 "bytestream.h"
38 #include "cabac.h"
39 #include "cabac_functions.h"
40 #include "error_resilience.h"
41 #include "avcodec.h"
42 #include "h264.h"
43 #include "h2645_parse.h"
44 #include "h264data.h"
45 #include "h264chroma.h"
46 #include "h264_mvpred.h"
47 #include "golomb.h"
48 #include "mathops.h"
49 #include "me_cmp.h"
50 #include "mpegutils.h"
51 #include "profiles.h"
52 #include "rectangle.h"
53 #include "thread.h"
54 #include "vdpau_compat.h"
55 
56 static int h264_decode_end(AVCodecContext *avctx);
57 
58 const uint16_t ff_h264_mb_sizes[4] = { 256, 384, 512, 768 };
59 
61 {
62  H264Context *h = avctx->priv_data;
63  return h && h->ps.sps ? h->ps.sps->num_reorder_frames : 0;
64 }
65 
66 static void h264_er_decode_mb(void *opaque, int ref, int mv_dir, int mv_type,
67  int (*mv)[2][4][2],
68  int mb_x, int mb_y, int mb_intra, int mb_skipped)
69 {
70  H264Context *h = opaque;
71  H264SliceContext *sl = &h->slice_ctx[0];
72 
73  sl->mb_x = mb_x;
74  sl->mb_y = mb_y;
75  sl->mb_xy = mb_x + mb_y * h->mb_stride;
76  memset(sl->non_zero_count_cache, 0, sizeof(sl->non_zero_count_cache));
77  av_assert1(ref >= 0);
78  /* FIXME: It is possible albeit uncommon that slice references
79  * differ between slices. We take the easy approach and ignore
80  * it for now. If this turns out to have any relevance in
81  * practice then correct remapping should be added. */
82  if (ref >= sl->ref_count[0])
83  ref = 0;
84  if (!sl->ref_list[0][ref].data[0]) {
85  av_log(h->avctx, AV_LOG_DEBUG, "Reference not available for error concealing\n");
86  ref = 0;
87  }
88  if ((sl->ref_list[0][ref].reference&3) != 3) {
89  av_log(h->avctx, AV_LOG_DEBUG, "Reference invalid\n");
90  return;
91  }
92  fill_rectangle(&h->cur_pic.ref_index[0][4 * sl->mb_xy],
93  2, 2, 2, ref, 1);
94  fill_rectangle(&sl->ref_cache[0][scan8[0]], 4, 4, 8, ref, 1);
95  fill_rectangle(sl->mv_cache[0][scan8[0]], 4, 4, 8,
96  pack16to32((*mv)[0][0][0], (*mv)[0][0][1]), 4);
97  sl->mb_mbaff =
98  sl->mb_field_decoding_flag = 0;
100 }
101 
103  int y, int height)
104 {
105  AVCodecContext *avctx = h->avctx;
106  const AVFrame *src = h->cur_pic.f;
108  int vshift = desc->log2_chroma_h;
109  const int field_pic = h->picture_structure != PICT_FRAME;
110  if (field_pic) {
111  height <<= 1;
112  y <<= 1;
113  }
114 
115  height = FFMIN(height, avctx->height - y);
116 
117  if (field_pic && h->first_field && !(avctx->slice_flags & SLICE_FLAG_ALLOW_FIELD))
118  return;
119 
120  if (avctx->draw_horiz_band) {
122  int i;
123 
124  offset[0] = y * src->linesize[0];
125  offset[1] =
126  offset[2] = (y >> vshift) * src->linesize[1];
127  for (i = 3; i < AV_NUM_DATA_POINTERS; i++)
128  offset[i] = 0;
129 
130  emms_c();
131 
132  avctx->draw_horiz_band(avctx, src, offset,
133  y, h->picture_structure, height);
134  }
135 }
136 
138 {
139  int i;
140 
143  av_freep(&h->cbp_table);
144  av_freep(&h->mvd_table[0]);
145  av_freep(&h->mvd_table[1]);
146  av_freep(&h->direct_table);
149  h->slice_table = NULL;
150  av_freep(&h->list_counts);
151 
152  av_freep(&h->mb2b_xy);
153  av_freep(&h->mb2br_xy);
154 
159 
160  for (i = 0; i < h->nb_slice_ctx; i++) {
161  H264SliceContext *sl = &h->slice_ctx[i];
162 
163  av_freep(&sl->dc_val_base);
164  av_freep(&sl->er.mb_index2xy);
166  av_freep(&sl->er.er_temp_buffer);
167 
170  av_freep(&sl->top_borders[0]);
171  av_freep(&sl->top_borders[1]);
172 
175  sl->top_borders_allocated[0] = 0;
176  sl->top_borders_allocated[1] = 0;
177  }
178 }
179 
181 {
182  const int big_mb_num = h->mb_stride * (h->mb_height + 1);
183  const int row_mb_num = 2*h->mb_stride*FFMAX(h->nb_slice_ctx, 1);
184  int x, y;
185 
187  row_mb_num, 8 * sizeof(uint8_t), fail)
189 
191  big_mb_num * 48 * sizeof(uint8_t), fail)
193  (big_mb_num + h->mb_stride) * sizeof(*h->slice_table_base), fail)
195  big_mb_num * sizeof(uint16_t), fail)
197  big_mb_num * sizeof(uint8_t), fail)
199  row_mb_num, 16 * sizeof(uint8_t), fail);
201  row_mb_num, 16 * sizeof(uint8_t), fail);
202  h->slice_ctx[0].mvd_table[0] = h->mvd_table[0];
203  h->slice_ctx[0].mvd_table[1] = h->mvd_table[1];
204 
206  4 * big_mb_num * sizeof(uint8_t), fail);
208  big_mb_num * sizeof(uint8_t), fail)
209 
210  memset(h->slice_table_base, -1,
211  (big_mb_num + h->mb_stride) * sizeof(*h->slice_table_base));
212  h->slice_table = h->slice_table_base + h->mb_stride * 2 + 1;
213 
215  big_mb_num * sizeof(uint32_t), fail);
217  big_mb_num * sizeof(uint32_t), fail);
218  for (y = 0; y < h->mb_height; y++)
219  for (x = 0; x < h->mb_width; x++) {
220  const int mb_xy = x + y * h->mb_stride;
221  const int b_xy = 4 * x + 4 * y * h->b_stride;
222 
223  h->mb2b_xy[mb_xy] = b_xy;
224  h->mb2br_xy[mb_xy] = 8 * (FMO ? mb_xy : (mb_xy % (2 * h->mb_stride)));
225  }
226 
227  return 0;
228 
229 fail:
231  return AVERROR(ENOMEM);
232 }
233 
234 /**
235  * Init context
236  * Allocate buffers which are not shared amongst multiple threads.
237  */
239 {
240  ERContext *er = &sl->er;
241  int mb_array_size = h->mb_height * h->mb_stride;
242  int y_size = (2 * h->mb_width + 1) * (2 * h->mb_height + 1);
243  int c_size = h->mb_stride * (h->mb_height + 1);
244  int yc_size = y_size + 2 * c_size;
245  int x, y, i;
246 
247  sl->ref_cache[0][scan8[5] + 1] =
248  sl->ref_cache[0][scan8[7] + 1] =
249  sl->ref_cache[0][scan8[13] + 1] =
250  sl->ref_cache[1][scan8[5] + 1] =
251  sl->ref_cache[1][scan8[7] + 1] =
252  sl->ref_cache[1][scan8[13] + 1] = PART_NOT_AVAILABLE;
253 
254  if (sl != h->slice_ctx) {
255  memset(er, 0, sizeof(*er));
256  } else
257  if (CONFIG_ERROR_RESILIENCE) {
258 
259  /* init ER */
260  er->avctx = h->avctx;
262  er->opaque = h;
263  er->quarter_sample = 1;
264 
265  er->mb_num = h->mb_num;
266  er->mb_width = h->mb_width;
267  er->mb_height = h->mb_height;
268  er->mb_stride = h->mb_stride;
269  er->b8_stride = h->mb_width * 2 + 1;
270 
271  // error resilience code looks cleaner with this
273  (h->mb_num + 1) * sizeof(int), fail);
274 
275  for (y = 0; y < h->mb_height; y++)
276  for (x = 0; x < h->mb_width; x++)
277  er->mb_index2xy[x + y * h->mb_width] = x + y * h->mb_stride;
278 
279  er->mb_index2xy[h->mb_height * h->mb_width] = (h->mb_height - 1) *
280  h->mb_stride + h->mb_width;
281 
283  mb_array_size * sizeof(uint8_t), fail);
284 
286  h->mb_height * h->mb_stride, fail);
287 
289  yc_size * sizeof(int16_t), fail);
290  er->dc_val[0] = sl->dc_val_base + h->mb_width * 2 + 2;
291  er->dc_val[1] = sl->dc_val_base + y_size + h->mb_stride + 1;
292  er->dc_val[2] = er->dc_val[1] + c_size;
293  for (i = 0; i < yc_size; i++)
294  sl->dc_val_base[i] = 1024;
295  }
296 
297  return 0;
298 
299 fail:
300  return AVERROR(ENOMEM); // ff_h264_free_tables will clean up for us
301 }
302 
304 {
305  int i;
306 
307  h->avctx = avctx;
308  h->backup_width = -1;
309  h->backup_height = -1;
311  h->cur_chroma_format_idc = -1;
312 
314  h->workaround_bugs = avctx->workaround_bugs;
315  h->flags = avctx->flags;
316  h->poc.prev_poc_msb = 1 << 16;
317  h->recovery_frame = -1;
318  h->frame_recovered = 0;
319  h->poc.prev_frame_num = -1;
321  h->sei.unregistered.x264_build = -1;
322 
323  h->next_outputed_poc = INT_MIN;
324  for (i = 0; i < MAX_DELAYED_PIC_COUNT; i++)
325  h->last_pocs[i] = INT_MIN;
326 
327  ff_h264_sei_uninit(&h->sei);
328 
330 
331  h->nb_slice_ctx = (avctx->active_thread_type & FF_THREAD_SLICE) ? avctx->thread_count : 1;
332  h->slice_ctx = av_mallocz_array(h->nb_slice_ctx, sizeof(*h->slice_ctx));
333  if (!h->slice_ctx) {
334  h->nb_slice_ctx = 0;
335  return AVERROR(ENOMEM);
336  }
337 
338  for (i = 0; i < H264_MAX_PICTURE_COUNT; i++) {
339  h->DPB[i].f = av_frame_alloc();
340  if (!h->DPB[i].f)
341  return AVERROR(ENOMEM);
342  }
343 
344  h->cur_pic.f = av_frame_alloc();
345  if (!h->cur_pic.f)
346  return AVERROR(ENOMEM);
347 
349  if (!h->last_pic_for_ec.f)
350  return AVERROR(ENOMEM);
351 
352  for (i = 0; i < h->nb_slice_ctx; i++)
353  h->slice_ctx[i].h264 = h;
354 
355  return 0;
356 }
357 
359 {
360  H264Context *h = avctx->priv_data;
361  int i;
362 
365 
366  for (i = 0; i < H264_MAX_PICTURE_COUNT; i++) {
367  ff_h264_unref_picture(h, &h->DPB[i]);
368  av_frame_free(&h->DPB[i].f);
369  }
370  memset(h->delayed_pic, 0, sizeof(h->delayed_pic));
371 
372  h->cur_pic_ptr = NULL;
373 
374  av_freep(&h->slice_ctx);
375  h->nb_slice_ctx = 0;
376 
377  ff_h264_sei_uninit(&h->sei);
378  ff_h264_ps_uninit(&h->ps);
379 
381 
383  av_frame_free(&h->cur_pic.f);
386 
387  return 0;
388 }
389 
391 
393 {
394  H264Context *h = avctx->priv_data;
395  int ret;
396 
397  ret = h264_init_context(avctx, h);
398  if (ret < 0)
399  return ret;
400 
401  ret = ff_thread_once(&h264_vlc_init, ff_h264_decode_init_vlc);
402  if (ret != 0) {
403  av_log(avctx, AV_LOG_ERROR, "pthread_once has failed.");
404  return AVERROR_UNKNOWN;
405  }
406 
407  if (avctx->codec_id == AV_CODEC_ID_H264) {
408  if (avctx->ticks_per_frame == 1) {
409  if(h->avctx->time_base.den < INT_MAX/2) {
410  h->avctx->time_base.den *= 2;
411  } else
412  h->avctx->time_base.num /= 2;
413  }
414  avctx->ticks_per_frame = 2;
415  }
416 
417  if (avctx->extradata_size > 0 && avctx->extradata) {
419  &h->ps, &h->is_avc, &h->nal_length_size,
420  avctx->err_recognition, avctx);
421  if (ret < 0) {
422  h264_decode_end(avctx);
423  return ret;
424  }
425  }
426 
427  if (h->ps.sps && h->ps.sps->bitstream_restriction_flag &&
430  }
431 
432  avctx->internal->allocate_progress = 1;
433 
435 
436  if (h->enable_er < 0 && (avctx->active_thread_type & FF_THREAD_SLICE))
437  h->enable_er = 0;
438 
439  if (h->enable_er && (avctx->active_thread_type & FF_THREAD_SLICE)) {
440  av_log(avctx, AV_LOG_WARNING,
441  "Error resilience with slice threads is enabled. It is unsafe and unsupported and may crash. "
442  "Use it at your own risk\n");
443  }
444 
445  return 0;
446 }
447 
448 #if HAVE_THREADS
449 static int decode_init_thread_copy(AVCodecContext *avctx)
450 {
451  H264Context *h = avctx->priv_data;
452  int ret;
453 
454  if (!avctx->internal->is_copy)
455  return 0;
456 
457  memset(h, 0, sizeof(*h));
458 
459  ret = h264_init_context(avctx, h);
460  if (ret < 0)
461  return ret;
462 
463  h->context_initialized = 0;
464 
465  return 0;
466 }
467 #endif
468 
469 /**
470  * Run setup operations that must be run after slice header decoding.
471  * This includes finding the next displayed frame.
472  *
473  * @param h h264 master context
474  * @param setup_finished enough NALs have been read that we can call
475  * ff_thread_finish_setup()
476  */
477 static void decode_postinit(H264Context *h, int setup_finished)
478 {
479  const SPS *sps = h->ps.sps;
481  H264Picture *cur = h->cur_pic_ptr;
482  int i, pics, out_of_order, out_idx;
483 
484  if (h->next_output_pic)
485  return;
486 
487  if (cur->field_poc[0] == INT_MAX || cur->field_poc[1] == INT_MAX) {
488  /* FIXME: if we have two PAFF fields in one packet, we can't start
489  * the next thread here. If we have one field per packet, we can.
490  * The check in decode_nal_units() is not good enough to find this
491  * yet, so we assume the worst for now. */
492  // if (setup_finished)
493  // ff_thread_finish_setup(h->avctx);
494  if (cur->field_poc[0] == INT_MAX && cur->field_poc[1] == INT_MAX)
495  return;
496  if (h->avctx->hwaccel || h->missing_fields <=1)
497  return;
498  }
499 
500  cur->f->interlaced_frame = 0;
501  cur->f->repeat_pict = 0;
502 
503  /* Signal interlacing information externally. */
504  /* Prioritize picture timing SEI information over used
505  * decoding process if it exists. */
506 
507  if (sps->pic_struct_present_flag) {
509  switch (pt->pic_struct) {
511  break;
514  cur->f->interlaced_frame = 1;
515  break;
518  if (FIELD_OR_MBAFF_PICTURE(h))
519  cur->f->interlaced_frame = 1;
520  else
521  // try to flag soft telecine progressive
523  break;
526  /* Signal the possibility of telecined film externally
527  * (pic_struct 5,6). From these hints, let the applications
528  * decide if they apply deinterlacing. */
529  cur->f->repeat_pict = 1;
530  break;
532  cur->f->repeat_pict = 2;
533  break;
535  cur->f->repeat_pict = 4;
536  break;
537  }
538 
539  if ((pt->ct_type & 3) &&
541  cur->f->interlaced_frame = (pt->ct_type & (1 << 1)) != 0;
542  } else {
543  /* Derive interlacing flag from used decoding process. */
545  }
547 
548  if (cur->field_poc[0] != cur->field_poc[1]) {
549  /* Derive top_field_first from field pocs. */
550  cur->f->top_field_first = cur->field_poc[0] < cur->field_poc[1];
551  } else {
552  if (sps->pic_struct_present_flag) {
553  /* Use picture timing SEI information. Even if it is a
554  * information of a past frame, better than nothing. */
557  cur->f->top_field_first = 1;
558  else
559  cur->f->top_field_first = 0;
560  } else if (cur->f->interlaced_frame) {
561  /* Default to top field first when pic_struct_present_flag
562  * is not set but interlaced frame detected */
563  cur->f->top_field_first = 1;
564  } else {
565  /* Most likely progressive */
566  cur->f->top_field_first = 0;
567  }
568  }
569 
570  if (h->sei.frame_packing.present &&
575  AVStereo3D *stereo = av_stereo3d_create_side_data(cur->f);
576  if (stereo) {
577  switch (fp->frame_packing_arrangement_type) {
578  case 0:
579  stereo->type = AV_STEREO3D_CHECKERBOARD;
580  break;
581  case 1:
582  stereo->type = AV_STEREO3D_COLUMNS;
583  break;
584  case 2:
585  stereo->type = AV_STEREO3D_LINES;
586  break;
587  case 3:
588  if (fp->quincunx_sampling_flag)
590  else
591  stereo->type = AV_STEREO3D_SIDEBYSIDE;
592  break;
593  case 4:
594  stereo->type = AV_STEREO3D_TOPBOTTOM;
595  break;
596  case 5:
598  break;
599  case 6:
600  stereo->type = AV_STEREO3D_2D;
601  break;
602  }
603 
604  if (fp->content_interpretation_type == 2)
605  stereo->flags = AV_STEREO3D_FLAG_INVERT;
606  }
607  }
608 
614  double angle = o->anticlockwise_rotation * 360 / (double) (1 << 16);
615  AVFrameSideData *rotation = av_frame_new_side_data(cur->f,
617  sizeof(int32_t) * 9);
618  if (rotation) {
619  av_display_rotation_set((int32_t *)rotation->data, angle);
620  av_display_matrix_flip((int32_t *)rotation->data,
621  o->hflip, o->vflip);
622  }
623  }
624 
625  if (h->sei.afd.present) {
627  sizeof(uint8_t));
628 
629  if (sd) {
631  h->sei.afd.present = 0;
632  }
633  }
634 
635  if (h->sei.a53_caption.a53_caption) {
636  H264SEIA53Caption *a53 = &h->sei.a53_caption;
639  a53->a53_caption_size);
640  if (sd)
641  memcpy(sd->data, a53->a53_caption, a53->a53_caption_size);
642  av_freep(&a53->a53_caption);
643  a53->a53_caption_size = 0;
645  }
646 
647  cur->mmco_reset = h->mmco_reset;
648  h->mmco_reset = 0;
649 
650  // FIXME do something with unavailable reference frames
651 
652  /* Sort B-frames into display order */
653  if (sps->bitstream_restriction_flag ||
656  }
657 
658  for (i = 0; 1; i++) {
659  if(i == MAX_DELAYED_PIC_COUNT || cur->poc < h->last_pocs[i]){
660  if(i)
661  h->last_pocs[i-1] = cur->poc;
662  break;
663  } else if(i) {
664  h->last_pocs[i-1]= h->last_pocs[i];
665  }
666  }
667  out_of_order = MAX_DELAYED_PIC_COUNT - i;
668  if( cur->f->pict_type == AV_PICTURE_TYPE_B
670  out_of_order = FFMAX(out_of_order, 1);
671  if (out_of_order == MAX_DELAYED_PIC_COUNT) {
672  av_log(h->avctx, AV_LOG_VERBOSE, "Invalid POC %d<%d\n", cur->poc, h->last_pocs[0]);
673  for (i = 1; i < MAX_DELAYED_PIC_COUNT; i++)
674  h->last_pocs[i] = INT_MIN;
675  h->last_pocs[0] = cur->poc;
676  cur->mmco_reset = 1;
677  } else if(h->avctx->has_b_frames < out_of_order && !sps->bitstream_restriction_flag){
678  av_log(h->avctx, AV_LOG_INFO, "Increasing reorder buffer to %d\n", out_of_order);
679  h->avctx->has_b_frames = out_of_order;
680  }
681 
682  pics = 0;
683  while (h->delayed_pic[pics])
684  pics++;
685 
687 
688  h->delayed_pic[pics++] = cur;
689  if (cur->reference == 0)
690  cur->reference = DELAYED_PIC_REF;
691 
692  out = h->delayed_pic[0];
693  out_idx = 0;
694  for (i = 1; h->delayed_pic[i] &&
695  !h->delayed_pic[i]->f->key_frame &&
696  !h->delayed_pic[i]->mmco_reset;
697  i++)
698  if (h->delayed_pic[i]->poc < out->poc) {
699  out = h->delayed_pic[i];
700  out_idx = i;
701  }
702  if (h->avctx->has_b_frames == 0 &&
703  (h->delayed_pic[0]->f->key_frame || h->delayed_pic[0]->mmco_reset))
704  h->next_outputed_poc = INT_MIN;
705  out_of_order = out->poc < h->next_outputed_poc;
706 
707  if (out_of_order || pics > h->avctx->has_b_frames) {
708  out->reference &= ~DELAYED_PIC_REF;
709  for (i = out_idx; h->delayed_pic[i]; i++)
710  h->delayed_pic[i] = h->delayed_pic[i + 1];
711  }
712  if (!out_of_order && pics > h->avctx->has_b_frames) {
713  h->next_output_pic = out;
714  if (out_idx == 0 && h->delayed_pic[0] && (h->delayed_pic[0]->f->key_frame || h->delayed_pic[0]->mmco_reset)) {
715  h->next_outputed_poc = INT_MIN;
716  } else
717  h->next_outputed_poc = out->poc;
718  } else {
719  av_log(h->avctx, AV_LOG_DEBUG, "no picture %s\n", out_of_order ? "ooo" : "");
720  }
721 
722  if (h->next_output_pic) {
723  if (h->next_output_pic->recovered) {
724  // We have reached an recovery point and all frames after it in
725  // display order are "recovered".
727  }
729  }
730 
731  if (setup_finished && !h->avctx->hwaccel) {
733 
735  h->setup_finished = 1;
736  }
737 }
738 
739 /**
740  * instantaneous decoder refresh.
741  */
742 static void idr(H264Context *h)
743 {
744  int i;
746  h->poc.prev_frame_num =
747  h->poc.prev_frame_num_offset = 0;
748  h->poc.prev_poc_msb = 1<<16;
749  h->poc.prev_poc_lsb = 0;
750  for (i = 0; i < MAX_DELAYED_PIC_COUNT; i++)
751  h->last_pocs[i] = INT_MIN;
752 }
753 
754 /* forget old pics after a seek */
756 {
757  int i, j;
758 
759  h->next_outputed_poc = INT_MIN;
760  h->prev_interlaced_frame = 1;
761  idr(h);
762 
763  h->poc.prev_frame_num = -1;
764  if (h->cur_pic_ptr) {
765  h->cur_pic_ptr->reference = 0;
766  for (j=i=0; h->delayed_pic[i]; i++)
767  if (h->delayed_pic[i] != h->cur_pic_ptr)
768  h->delayed_pic[j++] = h->delayed_pic[i];
769  h->delayed_pic[j] = NULL;
770  }
772 
773  h->first_field = 0;
774  ff_h264_sei_uninit(&h->sei);
775  h->recovery_frame = -1;
776  h->frame_recovered = 0;
777  h->current_slice = 0;
778  h->mmco_reset = 1;
779 }
780 
781 /* forget old pics after a seek */
782 static void flush_dpb(AVCodecContext *avctx)
783 {
784  H264Context *h = avctx->priv_data;
785  int i;
786 
787  memset(h->delayed_pic, 0, sizeof(h->delayed_pic));
788 
790 
791  for (i = 0; i < H264_MAX_PICTURE_COUNT; i++)
792  ff_h264_unref_picture(h, &h->DPB[i]);
793  h->cur_pic_ptr = NULL;
795 
796  h->mb_y = 0;
797 
799  h->context_initialized = 0;
800 }
801 
802 #if FF_API_CAP_VDPAU
803 static const uint8_t start_code[] = { 0x00, 0x00, 0x01 };
804 #endif
805 
807 {
808  int nals_needed = 0;
809  int first_slice = 0;
810  int i;
811  int ret;
812 
813  for (i = 0; i < h->pkt.nb_nals; i++) {
814  H2645NAL *nal = &h->pkt.nals[i];
815  GetBitContext gb;
816 
817  /* packets can sometimes contain multiple PPS/SPS,
818  * e.g. two PAFF field pictures in one packet, or a demuxer
819  * which splits NALs strangely if so, when frame threading we
820  * can't start the next thread until we've read all of them */
821  switch (nal->type) {
822  case NAL_SPS:
823  case NAL_PPS:
824  nals_needed = i;
825  break;
826  case NAL_DPA:
827  case NAL_IDR_SLICE:
828  case NAL_SLICE:
829  ret = init_get_bits8(&gb, nal->data + 1, (nal->size - 1));
830  if (ret < 0)
831  return ret;
832  if (!get_ue_golomb_long(&gb) || // first_mb_in_slice
833  !first_slice ||
834  first_slice != nal->type)
835  nals_needed = i;
836  if (!first_slice)
837  first_slice = nal->type;
838  }
839  }
840 
841  return nals_needed;
842 }
843 
844 static void debug_green_metadata(const H264SEIGreenMetaData *gm, void *logctx)
845 {
846  av_log(logctx, AV_LOG_DEBUG, "Green Metadata Info SEI message\n");
847  av_log(logctx, AV_LOG_DEBUG, " green_metadata_type: %d\n", gm->green_metadata_type);
848 
849  if (gm->green_metadata_type == 0) {
850  av_log(logctx, AV_LOG_DEBUG, " green_metadata_period_type: %d\n", gm->period_type);
851 
852  if (gm->period_type == 2)
853  av_log(logctx, AV_LOG_DEBUG, " green_metadata_num_seconds: %d\n", gm->num_seconds);
854  else if (gm->period_type == 3)
855  av_log(logctx, AV_LOG_DEBUG, " green_metadata_num_pictures: %d\n", gm->num_pictures);
856 
857  av_log(logctx, AV_LOG_DEBUG, " SEI GREEN Complexity Metrics: %f %f %f %f\n",
858  (float)gm->percent_non_zero_macroblocks/255,
859  (float)gm->percent_intra_coded_macroblocks/255,
860  (float)gm->percent_six_tap_filtering/255,
862 
863  } else if (gm->green_metadata_type == 1) {
864  av_log(logctx, AV_LOG_DEBUG, " xsd_metric_type: %d\n", gm->xsd_metric_type);
865 
866  if (gm->xsd_metric_type == 0)
867  av_log(logctx, AV_LOG_DEBUG, " xsd_metric_value: %f\n",
868  (float)gm->xsd_metric_value/100);
869  }
870 }
871 
872 static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size)
873 {
874  AVCodecContext *const avctx = h->avctx;
875  unsigned context_count = 0;
876  int nals_needed = 0; ///< number of NALs that need decoding before the next frame thread starts
877  int idr_cleared=0;
878  int i, ret = 0;
879 
880  h->nal_unit_type= 0;
881 
882  h->max_contexts = h->nb_slice_ctx;
883  if (!(avctx->flags2 & AV_CODEC_FLAG2_CHUNKS)) {
884  h->current_slice = 0;
885  if (!h->first_field)
886  h->cur_pic_ptr = NULL;
887  ff_h264_sei_uninit(&h->sei);
888  }
889 
890  if (h->nal_length_size == 4) {
891  if (buf_size > 8 && AV_RB32(buf) == 1 && AV_RB32(buf+5) > (unsigned)buf_size) {
892  h->is_avc = 0;
893  }else if(buf_size > 3 && AV_RB32(buf) > 1 && AV_RB32(buf) <= (unsigned)buf_size)
894  h->is_avc = 1;
895  }
896 
897  ret = ff_h2645_packet_split(&h->pkt, buf, buf_size, avctx, h->is_avc,
898  h->nal_length_size, avctx->codec_id);
899  if (ret < 0) {
900  av_log(avctx, AV_LOG_ERROR,
901  "Error splitting the input into NAL units.\n");
902  return ret;
903  }
904 
905  if (avctx->active_thread_type & FF_THREAD_FRAME)
906  nals_needed = get_last_needed_nal(h);
907  if (nals_needed < 0)
908  return nals_needed;
909 
910  for (i = 0; i < h->pkt.nb_nals; i++) {
911  H2645NAL *nal = &h->pkt.nals[i];
912  H264SliceContext *sl = &h->slice_ctx[context_count];
913  int err;
914 
915  if (avctx->skip_frame >= AVDISCARD_NONREF &&
916  nal->ref_idc == 0 && nal->type != NAL_SEI)
917  continue;
918 
919 again:
920  // FIXME these should stop being context-global variables
921  h->nal_ref_idc = nal->ref_idc;
922  h->nal_unit_type = nal->type;
923 
924  err = 0;
925  switch (nal->type) {
926  case NAL_IDR_SLICE:
927  if ((nal->data[1] & 0xFC) == 0x98) {
928  av_log(h->avctx, AV_LOG_ERROR, "Invalid inter IDR frame\n");
929  h->next_outputed_poc = INT_MIN;
930  ret = -1;
931  goto end;
932  }
933  if (nal->type != NAL_IDR_SLICE) {
935  "Invalid mix of idr and non-idr slices\n");
936  ret = -1;
937  goto end;
938  }
939  if(!idr_cleared) {
940  if (h->current_slice && (avctx->active_thread_type & FF_THREAD_SLICE)) {
941  av_log(h, AV_LOG_ERROR, "invalid mixed IDR / non IDR frames cannot be decoded in slice multithreading mode\n");
942  ret = AVERROR_INVALIDDATA;
943  goto end;
944  }
945  idr(h); // FIXME ensure we don't lose some frames if there is reordering
946  }
947  idr_cleared = 1;
948  h->has_recovery_point = 1;
949  case NAL_SLICE:
950  sl->gb = nal->gb;
951 
952  if ((err = ff_h264_decode_slice_header(h, sl, nal)))
953  break;
954 
955  if (h->sei.recovery_point.recovery_frame_cnt >= 0) {
956  const int sei_recovery_frame_cnt = h->sei.recovery_point.recovery_frame_cnt;
957 
958  if (h->poc.frame_num != sei_recovery_frame_cnt || sl->slice_type_nos != AV_PICTURE_TYPE_I)
959  h->valid_recovery_point = 1;
960 
961  if ( h->recovery_frame < 0
962  || av_mod_uintp2(h->recovery_frame - h->poc.frame_num, h->ps.sps->log2_max_frame_num) > sei_recovery_frame_cnt) {
963  h->recovery_frame = av_mod_uintp2(h->poc.frame_num + sei_recovery_frame_cnt, h->ps.sps->log2_max_frame_num);
964 
965  if (!h->valid_recovery_point)
966  h->recovery_frame = h->poc.frame_num;
967  }
968  }
969 
970  h->cur_pic_ptr->f->key_frame |= (nal->type == NAL_IDR_SLICE);
971 
972  if (nal->type == NAL_IDR_SLICE ||
973  (h->recovery_frame == h->poc.frame_num && nal->ref_idc)) {
974  h->recovery_frame = -1;
975  h->cur_pic_ptr->recovered = 1;
976  }
977  // If we have an IDR, all frames after it in decoded order are
978  // "recovered".
979  if (nal->type == NAL_IDR_SLICE)
981 #if 1
983 #else
985 #endif
986 
987  if (h->current_slice == 1) {
988  if (!(avctx->flags2 & AV_CODEC_FLAG2_CHUNKS))
989  decode_postinit(h, i >= nals_needed);
990 
991  if (h->avctx->hwaccel &&
992  (ret = h->avctx->hwaccel->start_frame(h->avctx, buf, buf_size)) < 0)
993  goto end;
994 #if FF_API_CAP_VDPAU
995  if (CONFIG_H264_VDPAU_DECODER &&
998 #endif
999  }
1000 
1001  if (sl->redundant_pic_count == 0) {
1002  if (avctx->hwaccel) {
1003  ret = avctx->hwaccel->decode_slice(avctx,
1004  nal->raw_data,
1005  nal->raw_size);
1006  if (ret < 0)
1007  goto end;
1008 #if FF_API_CAP_VDPAU
1009  } else if (CONFIG_H264_VDPAU_DECODER &&
1012  start_code,
1013  sizeof(start_code));
1015  nal->raw_data,
1016  nal->raw_size);
1017 #endif
1018  } else
1019  context_count++;
1020  }
1021  break;
1022  case NAL_DPA:
1023  case NAL_DPB:
1024  case NAL_DPC:
1025  avpriv_request_sample(avctx, "data partitioning");
1026  break;
1027  case NAL_SEI:
1028  ret = ff_h264_sei_decode(&h->sei, &nal->gb, &h->ps, avctx);
1030  if (avctx->debug & FF_DEBUG_GREEN_MD)
1032 #if FF_API_AFD
1036 #endif /* FF_API_AFD */
1037  if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))
1038  goto end;
1039  break;
1040  case NAL_SPS: {
1041  GetBitContext tmp_gb = nal->gb;
1042  if (ff_h264_decode_seq_parameter_set(&tmp_gb, avctx, &h->ps, 0) >= 0)
1043  break;
1045  "SPS decoding failure, trying again with the complete NAL\n");
1046  init_get_bits8(&tmp_gb, nal->raw_data + 1, nal->raw_size - 1);
1047  if (ff_h264_decode_seq_parameter_set(&tmp_gb, avctx, &h->ps, 0) >= 0)
1048  break;
1049  ff_h264_decode_seq_parameter_set(&nal->gb, avctx, &h->ps, 1);
1050  break;
1051  }
1052  case NAL_PPS:
1053  ret = ff_h264_decode_picture_parameter_set(&nal->gb, avctx, &h->ps,
1054  nal->size_bits);
1055  if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))
1056  goto end;
1057  break;
1058  case NAL_AUD:
1059  case NAL_END_SEQUENCE:
1060  case NAL_END_STREAM:
1061  case NAL_FILLER_DATA:
1062  case NAL_SPS_EXT:
1063  case NAL_AUXILIARY_SLICE:
1064  break;
1065  case NAL_FF_IGNORE:
1066  break;
1067  default:
1068  av_log(avctx, AV_LOG_DEBUG, "Unknown NAL code: %d (%d bits)\n",
1069  nal->type, nal->size_bits);
1070  }
1071 
1072  if (context_count == h->max_contexts) {
1073  ret = ff_h264_execute_decode_slices(h, context_count);
1074  if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))
1075  goto end;
1076  context_count = 0;
1077  }
1078 
1079  if (err < 0 || err == SLICE_SKIPED) {
1080  if (err < 0)
1081  av_log(h->avctx, AV_LOG_ERROR, "decode_slice_header error\n");
1082  sl->ref_count[0] = sl->ref_count[1] = sl->list_count = 0;
1083  } else if (err == SLICE_SINGLETHREAD) {
1084  if (context_count > 0) {
1085  ret = ff_h264_execute_decode_slices(h, context_count);
1086  if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))
1087  goto end;
1088  context_count = 0;
1089  }
1090  /* Slice could not be decoded in parallel mode, restart. */
1091  sl = &h->slice_ctx[0];
1092  goto again;
1093  }
1094  }
1095  if (context_count) {
1096  ret = ff_h264_execute_decode_slices(h, context_count);
1097  if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))
1098  goto end;
1099  }
1100 
1101  ret = 0;
1102 end:
1103 
1104 #if CONFIG_ERROR_RESILIENCE
1105  /*
1106  * FIXME: Error handling code does not seem to support interlaced
1107  * when slices span multiple rows
1108  * The ff_er_add_slice calls don't work right for bottom
1109  * fields; they cause massive erroneous error concealing
1110  * Error marking covers both fields (top and bottom).
1111  * This causes a mismatched s->error_count
1112  * and a bad error table. Further, the error count goes to
1113  * INT_MAX when called for bottom field, because mb_y is
1114  * past end by one (callers fault) and resync_mb_y != 0
1115  * causes problems for the first MB line, too.
1116  */
1117  if (!FIELD_PICTURE(h) && h->current_slice &&
1118  h->ps.sps == (const SPS*)h->ps.sps_list[h->ps.pps->sps_id]->data &&
1119  h->enable_er) {
1120 
1121  H264SliceContext *sl = h->slice_ctx;
1122  int use_last_pic = h->last_pic_for_ec.f->buf[0] && !sl->ref_count[0];
1123 
1125 
1126  if (use_last_pic) {
1128  sl->ref_list[0][0].parent = &h->last_pic_for_ec;
1129  memcpy(sl->ref_list[0][0].data, h->last_pic_for_ec.f->data, sizeof(sl->ref_list[0][0].data));
1130  memcpy(sl->ref_list[0][0].linesize, h->last_pic_for_ec.f->linesize, sizeof(sl->ref_list[0][0].linesize));
1132  } else if (sl->ref_count[0]) {
1133  ff_h264_set_erpic(&sl->er.last_pic, sl->ref_list[0][0].parent);
1134  } else
1136 
1137  if (sl->ref_count[1])
1138  ff_h264_set_erpic(&sl->er.next_pic, sl->ref_list[1][0].parent);
1139 
1140  sl->er.ref_count = sl->ref_count[0];
1141 
1142  ff_er_frame_end(&sl->er);
1143  if (use_last_pic)
1144  memset(&sl->ref_list[0][0], 0, sizeof(sl->ref_list[0][0]));
1145  }
1146 #endif /* CONFIG_ERROR_RESILIENCE */
1147  /* clean up */
1148  if (h->cur_pic_ptr && !h->droppable) {
1151  }
1152 
1153  return (ret < 0) ? ret : buf_size;
1154 }
1155 
1156 /**
1157  * Return the number of bytes consumed for building the current frame.
1158  */
1159 static int get_consumed_bytes(int pos, int buf_size)
1160 {
1161  if (pos == 0)
1162  pos = 1; // avoid infinite loops (I doubt that is needed but...)
1163  if (pos + 10 > buf_size)
1164  pos = buf_size; // oops ;)
1165 
1166  return pos;
1167 }
1168 
1170 {
1171  AVFrame *src = srcp->f;
1173  int i;
1174  int ret = av_frame_ref(dst, src);
1175  if (ret < 0)
1176  return ret;
1177 
1178  av_dict_set(&dst->metadata, "stereo_mode", ff_h264_sei_stereo_mode(&h->sei.frame_packing), 0);
1179 
1180  h->backup_width = h->avctx->width;
1181  h->backup_height = h->avctx->height;
1182  h->backup_pix_fmt = h->avctx->pix_fmt;
1183 
1184  h->avctx->width = dst->width;
1185  h->avctx->height = dst->height;
1186  h->avctx->pix_fmt = dst->format;
1187 
1188  if (srcp->sei_recovery_frame_cnt == 0)
1189  dst->key_frame = 1;
1190  if (!srcp->crop)
1191  return 0;
1192 
1193  for (i = 0; i < desc->nb_components; i++) {
1194  int hshift = (i > 0) ? desc->log2_chroma_w : 0;
1195  int vshift = (i > 0) ? desc->log2_chroma_h : 0;
1196  int off = ((srcp->crop_left >> hshift) << h->pixel_shift) +
1197  (srcp->crop_top >> vshift) * dst->linesize[i];
1198  dst->data[i] += off;
1199  }
1200  return 0;
1201 }
1202 
1203 static int is_extra(const uint8_t *buf, int buf_size)
1204 {
1205  int cnt= buf[5]&0x1f;
1206  const uint8_t *p= buf+6;
1207  while(cnt--){
1208  int nalsize= AV_RB16(p) + 2;
1209  if(nalsize > buf_size - (p-buf) || (p[2] & 0x9F) != 7)
1210  return 0;
1211  p += nalsize;
1212  }
1213  cnt = *(p++);
1214  if(!cnt)
1215  return 0;
1216  while(cnt--){
1217  int nalsize= AV_RB16(p) + 2;
1218  if(nalsize > buf_size - (p-buf) || (p[2] & 0x9F) != 8)
1219  return 0;
1220  p += nalsize;
1221  }
1222  return 1;
1223 }
1224 
1225 static int h264_decode_frame(AVCodecContext *avctx, void *data,
1226  int *got_frame, AVPacket *avpkt)
1227 {
1228  const uint8_t *buf = avpkt->data;
1229  int buf_size = avpkt->size;
1230  H264Context *h = avctx->priv_data;
1231  AVFrame *pict = data;
1232  int buf_index = 0;
1233  H264Picture *out;
1234  int i, out_idx;
1235  int ret;
1236 
1237  h->flags = avctx->flags;
1238  h->setup_finished = 0;
1239 
1240  if (h->backup_width != -1) {
1241  avctx->width = h->backup_width;
1242  h->backup_width = -1;
1243  }
1244  if (h->backup_height != -1) {
1245  avctx->height = h->backup_height;
1246  h->backup_height = -1;
1247  }
1248  if (h->backup_pix_fmt != AV_PIX_FMT_NONE) {
1249  avctx->pix_fmt = h->backup_pix_fmt;
1251  }
1252 
1254 
1255  /* end of stream, output what is still in the buffers */
1256  if (buf_size == 0) {
1257  out:
1258 
1259  h->cur_pic_ptr = NULL;
1260  h->first_field = 0;
1261 
1262  // FIXME factorize this with the output code below
1263  out = h->delayed_pic[0];
1264  out_idx = 0;
1265  for (i = 1;
1266  h->delayed_pic[i] &&
1267  !h->delayed_pic[i]->f->key_frame &&
1268  !h->delayed_pic[i]->mmco_reset;
1269  i++)
1270  if (h->delayed_pic[i]->poc < out->poc) {
1271  out = h->delayed_pic[i];
1272  out_idx = i;
1273  }
1274 
1275  for (i = out_idx; h->delayed_pic[i]; i++)
1276  h->delayed_pic[i] = h->delayed_pic[i + 1];
1277 
1278  if (out) {
1279  out->reference &= ~DELAYED_PIC_REF;
1280  ret = output_frame(h, pict, out);
1281  if (ret < 0)
1282  return ret;
1283  *got_frame = 1;
1284  }
1285 
1286  return buf_index;
1287  }
1289  int side_size;
1290  uint8_t *side = av_packet_get_side_data(avpkt, AV_PKT_DATA_NEW_EXTRADATA, &side_size);
1291  if (is_extra(side, side_size))
1292  ff_h264_decode_extradata(side, side_size,
1293  &h->ps, &h->is_avc, &h->nal_length_size,
1294  avctx->err_recognition, avctx);
1295  }
1296  if(h->is_avc && buf_size >= 9 && buf[0]==1 && buf[2]==0 && (buf[4]&0xFC)==0xFC && (buf[5]&0x1F) && buf[8]==0x67){
1297  if (is_extra(buf, buf_size))
1298  return ff_h264_decode_extradata(buf, buf_size,
1299  &h->ps, &h->is_avc, &h->nal_length_size,
1300  avctx->err_recognition, avctx);
1301  }
1302 
1303  buf_index = decode_nal_units(h, buf, buf_size);
1304  if (buf_index < 0)
1305  return AVERROR_INVALIDDATA;
1306 
1307  if (!h->cur_pic_ptr && h->nal_unit_type == NAL_END_SEQUENCE) {
1308  av_assert0(buf_index <= buf_size);
1309  goto out;
1310  }
1311 
1312  if (!(avctx->flags2 & AV_CODEC_FLAG2_CHUNKS) && !h->cur_pic_ptr) {
1313  if (avctx->skip_frame >= AVDISCARD_NONREF ||
1314  buf_size >= 4 && !memcmp("Q264", buf, 4))
1315  return buf_size;
1316  av_log(avctx, AV_LOG_ERROR, "no frame!\n");
1317  return AVERROR_INVALIDDATA;
1318  }
1319 
1320  if (!(avctx->flags2 & AV_CODEC_FLAG2_CHUNKS) ||
1321  (h->mb_y >= h->mb_height && h->mb_height)) {
1322  if (avctx->flags2 & AV_CODEC_FLAG2_CHUNKS)
1323  decode_postinit(h, 1);
1324 
1325  if ((ret = ff_h264_field_end(h, &h->slice_ctx[0], 0)) < 0)
1326  return ret;
1327 
1328  /* Wait for second field. */
1329  *got_frame = 0;
1330  if (h->next_output_pic && ((avctx->flags & AV_CODEC_FLAG_OUTPUT_CORRUPT) ||
1331  (avctx->flags2 & AV_CODEC_FLAG2_SHOW_ALL) ||
1332  h->next_output_pic->recovered)) {
1333  if (!h->next_output_pic->recovered)
1335 
1336  if (!h->avctx->hwaccel &&
1337  (h->next_output_pic->field_poc[0] == INT_MAX ||
1338  h->next_output_pic->field_poc[1] == INT_MAX)
1339  ) {
1340  int p;
1341  AVFrame *f = h->next_output_pic->f;
1342  int field = h->next_output_pic->field_poc[0] == INT_MAX;
1343  uint8_t *dst_data[4];
1344  int linesizes[4];
1345  const uint8_t *src_data[4];
1346 
1347  av_log(h->avctx, AV_LOG_DEBUG, "Duplicating field %d to fill missing\n", field);
1348 
1349  for (p = 0; p<4; p++) {
1350  dst_data[p] = f->data[p] + (field^1)*f->linesize[p];
1351  src_data[p] = f->data[p] + field *f->linesize[p];
1352  linesizes[p] = 2*f->linesize[p];
1353  }
1354 
1355  av_image_copy(dst_data, linesizes, src_data, linesizes,
1356  f->format, f->width, f->height>>1);
1357  }
1358 
1359  ret = output_frame(h, pict, h->next_output_pic);
1360  if (ret < 0)
1361  return ret;
1362  *got_frame = 1;
1363  if (CONFIG_MPEGVIDEO) {
1364  ff_print_debug_info2(h->avctx, pict, NULL,
1368  NULL,
1369  h->mb_width, h->mb_height, h->mb_stride, 1);
1370  }
1371  }
1372  }
1373 
1374  av_assert0(pict->buf[0] || !*got_frame);
1375 
1377 
1378  return get_consumed_bytes(buf_index, buf_size);
1379 }
1380 
1381 #define OFFSET(x) offsetof(H264Context, x)
1382 #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
1383 static const AVOption h264_options[] = {
1384  {"is_avc", "is avc", offsetof(H264Context, is_avc), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, 0},
1385  {"nal_length_size", "nal_length_size", offsetof(H264Context, nal_length_size), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 4, 0},
1386  { "enable_er", "Enable error resilience on damaged frames (unsafe)", OFFSET(enable_er), AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, VD },
1387  { NULL },
1388 };
1389 
1390 static const AVClass h264_class = {
1391  .class_name = "H264 Decoder",
1392  .item_name = av_default_item_name,
1393  .option = h264_options,
1394  .version = LIBAVUTIL_VERSION_INT,
1395 };
1396 
1398  .name = "h264",
1399  .long_name = NULL_IF_CONFIG_SMALL("H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10"),
1400  .type = AVMEDIA_TYPE_VIDEO,
1401  .id = AV_CODEC_ID_H264,
1402  .priv_data_size = sizeof(H264Context),
1404  .close = h264_decode_end,
1406  .capabilities = /*AV_CODEC_CAP_DRAW_HORIZ_BAND |*/ AV_CODEC_CAP_DR1 |
1409  .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
1410  .flush = flush_dpb,
1411  .init_thread_copy = ONLY_IF_THREADS_ENABLED(decode_init_thread_copy),
1412  .update_thread_context = ONLY_IF_THREADS_ENABLED(ff_h264_update_thread_context),
1414  .priv_class = &h264_class,
1415 };
1416 
1417 #if CONFIG_H264_VDPAU_DECODER && FF_API_VDPAU
1418 static const AVClass h264_vdpau_class = {
1419  .class_name = "H264 VDPAU Decoder",
1420  .item_name = av_default_item_name,
1421  .option = h264_options,
1422  .version = LIBAVUTIL_VERSION_INT,
1423 };
1424 
1425 AVCodec ff_h264_vdpau_decoder = {
1426  .name = "h264_vdpau",
1427  .long_name = NULL_IF_CONFIG_SMALL("H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (VDPAU acceleration)"),
1428  .type = AVMEDIA_TYPE_VIDEO,
1429  .id = AV_CODEC_ID_H264,
1430  .priv_data_size = sizeof(H264Context),
1432  .close = h264_decode_end,
1435  .flush = flush_dpb,
1436  .pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_VDPAU_H264,
1437  AV_PIX_FMT_NONE},
1439  .priv_class = &h264_vdpau_class,
1440 };
1441 #endif
struct H264Context * h264
Definition: h264.h:316
void ff_h264_unref_picture(H264Context *h, H264Picture *pic)
Definition: h264_picture.c:46
#define NULL
Definition: coverity.c:32
const struct AVCodec * codec
Definition: avcodec.h:1666
void ff_h264_flush_change(H264Context *h)
Definition: h264.c:755
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:3742
int workaround_bugs
Definition: h264.h:505
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
int sei_recovery_frame_cnt
Definition: h264.h:297
#define AV_NUM_DATA_POINTERS
Definition: frame.h:185
#define SLICE_FLAG_ALLOW_FIELD
allow draw_horiz_band() with field slices (MPEG-2 field pics)
Definition: avcodec.h:2201
enum AVPixelFormat backup_pix_fmt
Definition: h264.h:498
int ff_h264_execute_decode_slices(H264Context *h, unsigned context_count)
Call decode_slice() for each context.
Definition: h264_slice.c:2397
H264POCContext poc
Definition: h264.h:584
int mb_num
Definition: h264.h:563
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2263
MPEG-2/4 4:2:0, H.264 default for 4:2:0.
Definition: pixfmt.h:480
This structure describes decoded (raw) audio or video data.
Definition: frame.h:184
#define FF_ALLOCZ_ARRAY_OR_GOTO(ctx, p, nelem, elsize, label)
Definition: internal.h:157
static int get_last_needed_nal(H264Context *h)
Definition: h264.c:806
int recovery_frame_cnt
recovery_frame_cnt
Definition: h264_sei.h:109
int16_t mv_cache[2][5 *8][2]
Motion vector cache.
Definition: h264.h:437
AVOption.
Definition: opt.h:245
static const AVClass h264_class
Definition: h264.c:1390
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
static void flush(AVCodecContext *avctx)
int size
Definition: h2645_parse.h:33
int edge_emu_buffer_allocated
Definition: h264.h:425
uint16_t num_pictures
Definition: h264_sei.h:137
#define H264_MAX_PICTURE_COUNT
Definition: h264.h:51
int first_field
Definition: h264.h:535
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:392
#define LIBAVUTIL_VERSION_INT
Definition: version.h:70
AVBufferRef * sps_list[MAX_SPS_COUNT]
Definition: h264.h:230
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
Definition: frame.h:363
const char * desc
Definition: nvenc.c:89
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
uint16_t * cbp_table
Definition: h264.h:540
av_cold int ff_h264_decode_init(AVCodecContext *avctx)
Definition: h264.c:392
int frame_packing_arrangement_cancel_flag
is previous arrangement canceled, -1 if never received
Definition: h264_sei.h:120
void ff_er_frame_end(ERContext *s)
Sequence parameter set.
Definition: h264.h:136
int mb_y
Definition: h264.h:560
int bitstream_restriction_flag
Definition: h264.h:176
#define FMO
Definition: h264.h:66
int num
numerator
Definition: rational.h:44
int repeat_pict
When decoding, this signals how much the picture must be delayed.
Definition: frame.h:313
int bipred_scratchpad_allocated
Definition: h264.h:424
int size
Definition: avcodec.h:1589
#define DELAYED_PIC_REF
Value of Picture.reference when Picture is not a reference picture, but is held for delayed output...
Definition: diracdec.c:65
AVBufferPool * mb_type_pool
Definition: h264.h:693
int ff_h2645_packet_split(H2645Packet *pkt, const uint8_t *buf, int length, void *logctx, int is_nalff, int nal_length_size, enum AVCodecID codec_id)
Split an input packet into NAL units.
Definition: h2645_parse.c:248
int crop
Definition: h264.h:299
void ff_h264_draw_horiz_band(const H264Context *h, H264SliceContext *sl, int y, int height)
Definition: h264.c:102
int16_t(*[2] motion_val)[2]
Definition: h264.h:270
int flags
Definition: h264.h:504
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1885
int mb_height
Definition: h264.h:561
H264Picture * delayed_pic[MAX_DELAYED_PIC_COUNT+2]
Definition: h264.h:599
int is_avc
Used to parse AVC variant of H.264.
Definition: h264.h:574
3: top field, bottom field, in that order
Definition: h264_sei.h:45
AVBufferPool * ref_index_pool
Definition: h264.h:695
void ff_h264_free_tables(H264Context *h)
Definition: h264.c:137
void ff_h264_sei_uninit(H264SEIContext *h)
Reset SEI values at the beginning of the frame.
Definition: h264_sei.c:41
ERPicture last_pic
H264SEIDisplayOrientation display_orientation
Definition: h264_sei.h:154
void ff_h264_decode_init_vlc(void)
Definition: h264_cavlc.c:327
H264Context.
Definition: h264.h:468
AVFrame * f
Definition: h264.h:263
#define AV_CODEC_FLAG2_CHUNKS
Input bitstream might be truncated at a packet boundaries instead of only at frame boundaries...
Definition: avcodec.h:917
int ff_h264_decode_slice_header(H264Context *h, H264SliceContext *sl, const H2645NAL *nal)
Decode a slice header.
Definition: h264_slice.c:1659
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
#define FRAME_RECOVERED_IDR
We have seen an IDR, so all the following frames in coded order are correctly decodable.
Definition: h264.h:665
8: frame tripling
Definition: h264_sei.h:50
Views are next to each other.
Definition: stereo3d.h:45
AVCodec.
Definition: avcodec.h:3559
int picture_structure
Definition: h264.h:534
static void debug_green_metadata(const H264SEIGreenMetaData *gm, void *logctx)
Definition: h264.c:844
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:92
unsigned int ref_count[2]
num_ref_idx_l0/1_active_minus1 + 1
Definition: h264.h:405
int avpriv_h264_has_num_reorder_frames(AVCodecContext *avctx)
Definition: h264.c:60
int size_bits
Size, in bits, of just the data, excluding the stop bit and any trailing padding. ...
Definition: h2645_parse.h:40
H264SEIGreenMetaData green_metadata
Definition: h264_sei.h:155
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avcodec.h:1794
uint8_t * chroma_pred_mode_table
Definition: h264.h:543
int setup_finished
Definition: h264.h:682
enum AVDiscard skip_frame
Skip decoding for selected frames.
Definition: avcodec.h:3281
H264SEIContext sei
Definition: h264.h:690
const char * ff_h264_sei_stereo_mode(const H264SEIFramePacking *h)
Get stereo_mode string from the h264 frame_packing_arrangement.
Definition: h264_sei.c:454
BYTE int const BYTE * srcp
Definition: avisynth_c.h:676
struct AVHWAccel * hwaccel
Hardware accelerator in use.
Definition: avcodec.h:2976
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:981
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
const PPS * pps
Definition: h264.h:236
#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
#define av_cold
Definition: attributes.h:82
uint8_t green_metadata_type
Definition: h264_sei.h:134
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:140
AVOptions.
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:303
int poc
frame POC
Definition: h264.h:282
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:90
AVCodec ff_h264_decoder
Definition: h264.c:1397
Multithreading support functions.
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:374
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:1772
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:423
void ff_h2645_packet_uninit(H2645Packet *pkt)
Free all the allocated memory in the packet.
Definition: h2645_parse.c:370
ERPicture cur_pic
int frame_recovered
Initial frame has been completely recovered.
Definition: h264.h:672
Structure to hold side data for an AVFrame.
Definition: frame.h:143
int ff_h264_decode_extradata(const uint8_t *data, int size, H264ParamSets *ps, int *is_avc, int *nal_length_size, int err_recognition, void *logctx)
Definition: h264_parse.c:420
#define PICT_BOTTOM_FIELD
Definition: mpegutils.h:38
#define height
int pt
Definition: rtp.c:35
uint8_t * data
Definition: avcodec.h:1588
#define AV_CODEC_CAP_HWACCEL_VDPAU
Codec can export data for HW decoding (VDPAU).
Definition: avcodec.h:992
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:192
AVDictionary * metadata
metadata.
Definition: frame.h:465
int interlaced_frame
The content of the picture is interlaced.
Definition: frame.h:318
#define MAX_DELAYED_PIC_COUNT
Definition: h264.h:58
static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size)
Definition: h264.c:872
static void fill_rectangle(SDL_Surface *screen, int x, int y, int w, int h, int color, int update)
Definition: ffplay.c:801
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...
H264Picture * parent
Definition: h264.h:312
H264SEIAFD afd
Definition: h264_sei.h:148
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:295
Active Format Description data consisting of a single byte as specified in ETSI TS 101 154 using AVAc...
Definition: frame.h:88
#define AVOnce
Definition: thread.h:158
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
Definition: avcodec.h:2400
7: frame doubling
Definition: h264_sei.h:49
#define av_log(a,...)
Definition: h264.h:123
int last_pocs[MAX_DELAYED_PIC_COUNT]
Definition: h264.h:600
uint16_t num_seconds
Definition: h264_sei.h:136
uint8_t percent_six_tap_filtering
Definition: h264_sei.h:140
SEI_FpaType frame_packing_arrangement_type
Definition: h264_sei.h:121
int a53_caption_size
Definition: h264_sei.h:93
H.264 / AVC / MPEG-4 part10 codec.
void ff_h264_hl_decode_mb(const H264Context *h, H264SliceContext *sl)
Definition: h264_mb.c:798
H264Picture DPB[H264_MAX_PICTURE_COUNT]
Definition: h264.h:476
int width
width and height of the video frame
Definition: frame.h:236
#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:1979
int flags
Additional information about the frame packing.
Definition: stereo3d.h:132
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:1159
int16_t * dc_val_base
Definition: h264.h:419
int context_initialized
Definition: h264.h:503
ERContext er
Definition: h264.h:318
int nal_unit_type
Definition: h264.h:569
av_default_item_name
int num_reorder_frames
Definition: h264.h:177
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:153
int backup_height
Definition: h264.h:497
#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:3106
int backup_width
Backup frame properties: needed, because they can be different between returned frame and last decode...
Definition: h264.h:496
H2645Packet pkt
Definition: h264.h:484
static void flush_dpb(AVCodecContext *avctx)
Definition: h264.c:782
int capabilities
Codec capabilities.
Definition: avcodec.h:3578
#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:57
static const AVOption h264_options[]
Definition: h264.c:1383
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)
uint8_t(*[2] mvd_table)[2]
Definition: h264.h:544
int prev_interlaced_frame
Complement sei_pic_struct SEI_PIC_STRUCT_TOP_BOTTOM and SEI_PIC_STRUCT_BOTTOM_TOP indicate interlaced...
Definition: h264.h:646
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:1752
ThreadFrame tf
Definition: h264.h:264
simple assert() macros that are a bit more flexible than ISO C assert().
const char * name
Name of the codec implementation.
Definition: avcodec.h:3566
H264SEIUnregistered unregistered
Definition: h264_sei.h:150
static AVOnce h264_vlc_init
Definition: h264.c:390
static av_always_inline uint32_t pack16to32(unsigned a, unsigned b)
Definition: h264.h:822
int valid_recovery_point
Are the SEI recovery points looking valid.
Definition: h264.h:651
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:537
#define FFMAX(a, b)
Definition: common.h:94
#define fail()
Definition: checkasm.h:82
uint8_t active_format_description
Definition: h264_sei.h:89
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition: avcodec.h:1019
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 raw_size
Definition: h2645_parse.h:42
#define FIELD_OR_MBAFF_PICTURE(h)
Definition: h264.h:95
uint8_t percent_non_zero_macroblocks
Definition: h264_sei.h:138
int slice_type_nos
S free slice type (SI/SP are remapped to I/P)
Definition: h264.h:322
static const uint8_t scan8[16 *3+3]
Definition: h264.h:806
#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:300
uint8_t * error_status_table
uint8_t * direct_table
Definition: h264.h:545
int nal_length_size
Number of bytes used for nal length (1, 2 or 4)
Definition: h264.h:575
useful rectangle filling function
uint8_t * data[3]
Definition: h264.h:305
int prev_poc_msb
poc_msb of the last reference pic for POC type 0
Definition: h264_parse.h:48
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:66
Views are packed per line, as if interlaced.
Definition: stereo3d.h:97
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:1918
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:258
int flags
Frame flags, a combination of AV_FRAME_FLAGS.
Definition: frame.h:404
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
Definition: avcodec.h:2944
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:53
#define FF_THREAD_FRAME
Decode more than one frame at once.
Definition: avcodec.h:3098
int ct_type
Bit set of clock types for fields/frames in picture timing SEI message.
Definition: h264_sei.h:74
uint32_t * mb2br_xy
Definition: h264.h:527
uint8_t * er_temp_buffer
#define OFFSET(x)
Definition: h264.c:1381
#define FFMIN(a, b)
Definition: common.h:96
uint16_t * slice_table
slice_table_base + 2*mb_stride + 1
Definition: h264.h:530
int reference
Definition: h264.h:294
#define FIELD_PICTURE(h)
Definition: h264.h:78
int width
picture width / height.
Definition: avcodec.h:1844
int redundant_pic_count
Definition: h264.h:382
int nb_slice_ctx
Definition: h264.h:482
uint32_t * mb_type
Definition: h264.h:273
#define AV_FRAME_FLAG_CORRUPT
The frame data may be corrupted, e.g.
Definition: frame.h:396
void ff_thread_report_progress(ThreadFrame *f, int n, int field)
Notify later decoding threads when part of their reference picture is ready.
int32_t
Definition: h264.h:124
#define FF_THREAD_SLICE
Decode more than one part of a single frame at once.
Definition: avcodec.h:3099
Context Adaptive Binary Arithmetic Coder inline functions.
int mmco_reset
Definition: h264.h:609
H264SliceContext * slice_ctx
Definition: h264.h:481
#define AV_EF_EXPLODE
abort decoding on minor error detection
Definition: avcodec.h:2955
int reference
Definition: h264.h:308
static int h264_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: h264.c:1225
int ticks_per_frame
For some codecs, the time base is closer to the field rate than the frame rate.
Definition: avcodec.h:1803
int top_borders_allocated[2]
Definition: h264.h:426
uint8_t * a53_caption
Definition: h264_sei.h:94
int ref_idc
H.264 only, nal_ref_idc.
Definition: h2645_parse.h:63
#define src
Definition: vp9dsp.c:530
static int output_frame(H264Context *h, AVFrame *dst, H264Picture *srcp)
Definition: h264.c:1169
int quincunx_sampling_flag
Definition: h264_sei.h:124
#define AV_STEREO3D_FLAG_INVERT
Inverted views, Right/Bottom represents the left view.
Definition: stereo3d.h:114
int type
NAL unit type.
Definition: h2645_parse.h:50
2: bottom field
Definition: h264_sei.h:44
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:518
int thread_count
thread count is used to decide how many independent tasks should be passed to execute() ...
Definition: avcodec.h:3087
uint8_t * edge_emu_buffer
Definition: h264.h:422
Views are packed per column.
Definition: stereo3d.h:107
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:1023
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:248
Definition: h264.h:121
The AV_PKT_DATA_NEW_EXTRADATA is used to notify the codec or the format that the extradata buffer was...
Definition: avcodec.h:1359
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:238
int mb_stride
Definition: h264.h:562
#define AV_LOG_INFO
Standard information.
Definition: log.h:187
AVCodecContext * avctx
Definition: h264.h:470
#define AV_ONCE_INIT
Definition: thread.h:159
Libavcodec external API header.
This side data contains a 3x3 transformation matrix describing an affine transformation that needs to...
Definition: frame.h:83
enum AVCodecID codec_id
Definition: avcodec.h:1674
void ff_h264_remove_all_refs(H264Context *h)
Definition: h264_refs.c:562
ERPicture next_pic
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:215
int next_outputed_poc
Definition: h264.h:602
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition: get_bits.h:437
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:281
SEI_PicStructType pic_struct
Definition: h264_sei.h:67
int debug
debug
Definition: avcodec.h:2896
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:630
int recovery_frame
recovery_frame is the frame_num at which the next frame should be fully constructed.
Definition: h264.h:659
main external API structure.
Definition: avcodec.h:1657
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
Definition: h264.h:119
uint8_t * data
The data buffer.
Definition: buffer.h:89
static void decode_postinit(H264Context *h, int setup_finished)
Run setup operations that must be run after slice header decoding.
Definition: h264.c:477
int ff_h264_alloc_tables(H264Context *h)
Allocate tables.
Definition: h264.c:180
const uint8_t * data
Definition: h2645_parse.h:34
#define fp
Definition: regdef.h:44
uint8_t * data
Definition: frame.h:145
H264SEIA53Caption a53_caption
Definition: h264_sei.h:149
void * buf
Definition: avisynth_c.h:553
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:1579
int8_t * qscale_table
Definition: h264.h:267
int extradata_size
Definition: avcodec.h:1773
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:104
int ff_h264_update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
Definition: h264_slice.c:297
int slice_flags
slice flags
Definition: avcodec.h:2199
Describe the class of an AVClass context structure.
Definition: log.h:67
int prev_frame_num
frame_num of the last pic for POC type 1/2
Definition: h264_parse.h:52
#define FF_CODEC_PROPERTY_CLOSED_CAPTIONS
Definition: avcodec.h:3490
AVFrameSideData * av_frame_new_side_data(AVFrame *frame, enum AVFrameSideDataType type, int size)
Add a new side data to a frame.
Definition: frame.c:616
uint8_t non_zero_count_cache[15 *8]
non zero coeff count cache.
Definition: h264.h:432
5: top field, bottom field, top field repeated, in that order
Definition: h264_sei.h:47
static int h264_decode_end(AVCodecContext *avctx)
Definition: h264.c:358
void av_buffer_pool_uninit(AVBufferPool **ppool)
Mark the pool as being available for freeing.
Definition: buffer.c:274
Definition: h264.h:117
int8_t * ref_index[2]
Definition: h264.h:279
int pixel_shift
0 for 8-bit H.264, 1 for high-bit-depth H.264
Definition: h264.h:486
int mmco_reset
MMCO_RESET set this 1.
Definition: h264.h:284
int content_interpretation_type
Definition: h264_sei.h:123
H264Picture * cur_pic_ptr
Definition: h264.h:477
int mb_mbaff
mb_aff_frame && mb_field_decoding_flag
Definition: h264.h:380
#define FF_DEBUG_GREEN_MD
Definition: avcodec.h:2923
int enable_er
Definition: h264.h:688
uint8_t percent_intra_coded_macroblocks
Definition: h264_sei.h:139
#define FF_COMPLIANCE_STRICT
Strictly conform to all the things in the spec no matter what consequences.
Definition: avcodec.h:2876
const SPS * sps
Definition: h264.h:237
unsigned int sps_id
Definition: h264.h:201
attribute_deprecated int dtg_active_format
DTG active format information (additional aspect ratio information only used in DVB MPEG-2 transport ...
Definition: avcodec.h:2162
H264SEIPictureTiming picture_timing
Definition: h264_sei.h:147
int allocate_progress
Whether to allocate progress for frame threading.
Definition: internal.h:126
H264SEIRecoveryPoint recovery_point
Definition: h264_sei.h:151
static int is_extra(const uint8_t *buf, int buf_size)
Definition: h264.c:1203
AVCodecContext * avctx
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:262
static const uint8_t start_code[]
Definition: h264.c:803
int linesize[3]
Definition: h264.h:306
int pic_struct_present_flag
Definition: h264.h:183
AVStereo3D * av_stereo3d_create_side_data(AVFrame *frame)
Allocate a complete AVFrameSideData and add it to the frame.
Definition: stereo3d.c:33
unsigned int list_count
Definition: h264.h:406
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:198
int prev_poc_lsb
poc_lsb of the last reference pic for POC type 0
Definition: h264_parse.h:49
uint8_t xsd_metric_type
Definition: h264_sei.h:142
int has_recovery_point
Definition: h264.h:674
int ff_h264_decode_picture_parameter_set(GetBitContext *gb, AVCodecContext *avctx, H264ParamSets *ps, int bit_length)
Decode PPS.
Definition: h264_ps.c:712
uint16_t xsd_metric_value
Definition: h264_sei.h:143
static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket *avpkt)
Definition: ccaption_dec.c:752
static void idr(H264Context *h)
instantaneous decoder refresh.
Definition: h264.c:742
discard all non reference
Definition: avcodec.h:780
AVBufferPool * qscale_table_pool
Definition: h264.h:692
H264Picture * next_output_pic
Definition: h264.h:601
AVBufferPool * motion_val_pool
Definition: h264.h:694
#define SLICE_SINGLETHREAD
Definition: h264.h:999
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:80
common internal api header.
if(ret< 0)
Definition: vf_mcdeint.c:282
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:107
#define FRAME_RECOVERED_SEI
Sufficient number of frames have been decoded since a SEI recovery point, so all the following frames...
Definition: h264.h:670
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:582
int log2_max_frame_num
log2_max_frame_num_minus4 + 4
Definition: h264.h:142
int missing_fields
Definition: h264.h:676
Views are packed in a checkerboard-like structure per pixel.
Definition: stereo3d.h:76
H264ParamSets ps
Definition: h264.h:580
int16_t * dc_val[3]
H264SEIFramePacking frame_packing
Definition: h264_sei.h:153
H.264 / AVC / MPEG-4 part10 motion vector prediction.
Bi-dir predicted.
Definition: avutil.h:268
int workaround_bugs
Work around bugs in encoders which sometimes cannot be detected automatically.
Definition: avcodec.h:2840
const AVProfile ff_h264_profiles[]
Definition: profiles.c:59
int cur_chroma_format_idc
Definition: h264.h:684
int8_t * intra4x4_pred_mode
Definition: h264.h:344
unsigned properties
Definition: avcodec.h:3488
int den
denominator
Definition: rational.h:45
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
Definition: error.h:71
GetBitContext gb
Definition: h2645_parse.h:45
int ff_h264_decode_seq_parameter_set(GetBitContext *gb, AVCodecContext *avctx, H264ParamSets *ps, int ignore_truncation)
Decode SPS.
Definition: h264_ps.c:322
int present
Definition: h264_sei.h:88
void * priv_data
Definition: avcodec.h:1699
int ff_h264_field_end(H264Context *h, H264SliceContext *sl, int in_setup)
Definition: h264_picture.c:153
const uint8_t * raw_data
Definition: h2645_parse.h:43
#define PICT_FRAME
Definition: mpegutils.h:39
4: bottom field, top field, in that order
Definition: h264_sei.h:46
void ff_h264_set_erpic(ERPicture *dst, H264Picture *src)
Definition: h264_picture.c:130
int8_t ref_cache[2][5 *8]
Definition: h264.h:438
#define AV_CODEC_FLAG_OUTPUT_CORRUPT
Output even those frames that might be corrupted.
Definition: avcodec.h:838
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:81
#define SLICE_SKIPED
Definition: h264.h:1000
#define VD
Definition: h264.c:1382
int top_field_first
If the content is interlaced, is top field displayed first.
Definition: frame.h:323
const uint16_t ff_h264_mb_sizes[4]
Definition: h264.c:58
struct AVCodecInternal * internal
Private context used for internal data.
Definition: avcodec.h:1707
static int ff_thread_once(char *control, void(*routine)(void))
Definition: thread.h:161
H2645NAL * nals
Definition: h2645_parse.h:68
H264Picture cur_pic
Definition: h264.h:478
Views are on top of each other.
Definition: stereo3d.h:55
int key_frame
1 -> keyframe, 0-> not
Definition: frame.h:253
int mb_width
Definition: h264.h:561
int current_slice
current slice number, used to initialize slice_num of each thread/context
Definition: h264.h:622
int flags2
AV_CODEC_FLAG2_*.
Definition: avcodec.h:1759
uint32_t * mb2b_xy
Definition: h264.h:526
H264Ref ref_list[2][48]
0..15: frame refs, 16..47: mbaff field refs.
Definition: h264.h:407
H264Picture last_pic_for_ec
Definition: h264.h:479
static void * av_mallocz_array(size_t nmemb, size_t size)
Definition: mem.h:229
int height
Definition: frame.h:236
int crop_top
Definition: h264.h:301
#define AV_CODEC_FLAG2_SHOW_ALL
Show all frames before the first keyframe.
Definition: avcodec.h:926
1: top field
Definition: h264_sei.h:43
FILE * out
Definition: movenc.c:54
uint8_t(*[2] mvd_table)[2]
Definition: h264.h:451
#define av_freep(p)
Definition: h264.h:118
void ff_h264_ps_uninit(H264ParamSets *ps)
Uninit H264 param sets structure.
Definition: h264_ps.c:305
int ff_h264_sei_decode(H264SEIContext *h, GetBitContext *gb, const H264ParamSets *ps, void *logctx)
Definition: h264_sei.c:382
uint8_t * av_packet_get_side_data(AVPacket *pkt, enum AVPacketSideDataType type, int *size)
Get side information from packet.
Definition: avpacket.c:334
int prev_frame_num_offset
for POC type 2
Definition: h264_parse.h:51
void ff_vdpau_add_data_chunk(uint8_t *data, const uint8_t *buf, int buf_size)
int8_t * intra4x4_pred_mode
Definition: h264.h:512
int(* decode_slice)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size)
Callback for each slice.
Definition: avcodec.h:3756
int mb_field_decoding_flag
Definition: h264.h:379
uint8_t(* non_zero_count)[48]
Definition: h264.h:515
exp golomb vlc stuff
uint8_t * bipred_scratchpad
Definition: h264.h:421
Definition: h264.h:122
AVPixelFormat
Pixel format.
Definition: pixfmt.h:60
This structure stores compressed data.
Definition: avcodec.h:1565
int droppable
Definition: h264.h:500
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:956
int strict_std_compliance
strictly follow the standard (MPEG-4, ...).
Definition: avcodec.h:2874
int nal_ref_idc
Definition: h264.h:568
GetBitContext gb
Definition: h264.h:317
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:528
6: bottom field, top field, bottom field repeated, in that order
Definition: h264_sei.h:48
Context Adaptive Binary Arithmetic Coder.
uint8_t percent_alpha_point_deblocking_instance
Definition: h264_sei.h:141