Merge commit 'b0017579b6e8de3d0d13dcfe0a4dd848dc6baa37'
authorMichael Niedermayer <michael@niedermayer.cc>
Fri, 17 Jul 2015 11:48:40 +0000 (13:48 +0200)
committerMichael Niedermayer <michael@niedermayer.cc>
Fri, 17 Jul 2015 12:13:19 +0000 (14:13 +0200)
* commit 'b0017579b6e8de3d0d13dcfe0a4dd848dc6baa37':
  h264: Add support for Closed Caption export

Conflicts:
libavcodec/h264.c
libavcodec/h264_sei.c

See: 8234f0e3b485811d60c228c40a94a141c46e61ca
Merged-by: Michael Niedermayer <michael@niedermayer.cc>
1  2 
libavcodec/h264.c
libavcodec/h264.h
libavcodec/h264_sei.c

@@@ -880,18 -833,17 +880,19 @@@ static void decode_postinit(H264Contex
      }
  
      if (h->a53_caption) {
-         AVFrameSideData *sd =
-             av_frame_new_side_data(cur->f, AV_FRAME_DATA_A53_CC, h->a53_caption_size);
+         AVFrameSideData *sd = av_frame_new_side_data(cur->f,
+                                                      AV_FRAME_DATA_A53_CC,
+                                                      h->a53_caption_size);
 -        if (!sd)
 -            return;
 -
 -        memcpy(sd->data, h->a53_caption, h->a53_caption_size);
 +        if (sd)
 +            memcpy(sd->data, h->a53_caption, h->a53_caption_size);
          av_freep(&h->a53_caption);
          h->a53_caption_size = 0;
 +        h->avctx->properties |= FF_CODEC_PROPERTY_CLOSED_CAPTIONS;
      }
  
 +    cur->mmco_reset = h->mmco_reset;
 +    h->mmco_reset = 0;
 +
      // FIXME do something with unavailable reference frames
  
      /* Sort B-frames into display order */
@@@ -801,14 -730,7 +803,11 @@@ typedef struct H264Context 
  
      int frame_recovered;    ///< Initial frame has been completely recovered
  
 -    /* for frame threading, this is set to 1
 +    int has_recovery_point;
 +
 +    int missing_fields;
 +
-     int a53_caption_size;
-     uint8_t *a53_caption;
 +/* for frame threading, this is set to 1
       * after finish_setup() has been called, so we cannot modify
       * some context properties (which are supposed to stay constant between
       * slices) anymore */
@@@ -147,35 -141,37 +147,39 @@@ static int decode_registered_user_data(
                  skip_bits(&h->gb, 4);           // reserved
                  h->active_format_description   = get_bits(&h->gb, 4);
                  h->sei_reguserdata_afd_present = 1;
 +#if FF_API_AFD
 +FF_DISABLE_DEPRECATION_WARNINGS
 +                h->avctx->dtg_active_format = h->active_format_description;
 +FF_ENABLE_DEPRECATION_WARNINGS
 +#endif /* FF_API_AFD */
              }
              break;
 -        case MKBETAG('G', 'A', '9', '4'):       // closed captions
 +        case MKBETAG('G', 'A', '9', '4'): // "GA94" closed captions
              if (size < 3)
                  return AVERROR(EINVAL);
 -
              user_data_type_code = get_bits(&h->gb, 8);
              if (user_data_type_code == 0x3) {
-                 skip_bits(&h->gb, 1);
-                 if (get_bits(&h->gb, 1)) {
-                     skip_bits(&h->gb, 1);
+                 skip_bits(&h->gb, 1);           // reserved
+                 flag = get_bits(&h->gb, 1);     // process_cc_data_flag
+                 if (flag) {
+                     skip_bits(&h->gb, 1);       // zero bit
                      cc_count = get_bits(&h->gb, 5);
-                     skip_bits(&h->gb, 8);
+                     skip_bits(&h->gb, 8);       // reserved
                      size -= 2;
-                     if (cc_count && size >= cc_count*3) {
+                     if (cc_count && size >= cc_count * 3) {
 -                        int i, ret;
 -                        int new_size = (int64_t) h->a53_caption_size +
 -                                       (int64_t) cc_count * 3;
 -
 -                        if (new_size > INT_MAX)
 +                        int i;
 +                        uint8_t *tmp;
 +                        if ((int64_t)h->a53_caption_size + (int64_t)cc_count*3 > INT_MAX)
                              return AVERROR(EINVAL);
  
 -                        /* Allow merging of the cc data from two fields. */
 -                        ret = av_reallocp(&h->a53_caption,
 -                                          h->a53_caption_size + cc_count * 3);
 -                        if (ret < 0)
 -                            return ret;
 +                        // Allow merging of the cc data from two fields
 +                        tmp = av_realloc(h->a53_caption, h->a53_caption_size + cc_count*3);
 +                        if (!tmp)
 +                            return AVERROR(ENOMEM);
 +                        h->a53_caption = tmp;
                          for (i = 0; i < cc_count; i++) {
                              h->a53_caption[h->a53_caption_size++] = get_bits(&h->gb, 8);
                              h->a53_caption[h->a53_caption_size++] = get_bits(&h->gb, 8);