Merge remote-tracking branch 'qatar/master'
authorMichael Niedermayer <michaelni@gmx.at>
Mon, 9 Dec 2013 21:25:38 +0000 (22:25 +0100)
committerMichael Niedermayer <michaelni@gmx.at>
Mon, 9 Dec 2013 21:25:38 +0000 (22:25 +0100)
* qatar/master:
  hevc: parse frame packing arrangement SEI messages and save relevant stereo3d information

Conflicts:
libavcodec/hevc.h
libavcodec/hevc_sei.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
1  2 
libavcodec/hevc.c
libavcodec/hevc.h
libavcodec/hevc_sei.c

@@@ -2072,9 -2348,44 +2073,44 @@@ static void restore_tqb_pixels(HEVCCont
      }
  }
  
+ static int set_side_data(HEVCContext *s)
+ {
+     AVFrame *out = s->ref->frame;
+     if (s->sei_frame_packing_present &&
+         s->frame_packing_arrangement_type >= 3 &&
+         s->frame_packing_arrangement_type <= 5 &&
+         s->content_interpretation_type > 0 &&
+         s->content_interpretation_type < 3) {
+         AVStereo3D *stereo = av_stereo3d_create_side_data(out);
+         if (!stereo)
+             return AVERROR(ENOMEM);
+         switch (s->frame_packing_arrangement_type) {
+         case 3:
+             if (s->quincunx_subsampling)
+                 stereo->type = AV_STEREO3D_SIDEBYSIDE_QUINCUNX;
+             else
+                 stereo->type = AV_STEREO3D_SIDEBYSIDE;
+             break;
+         case 4:
+             stereo->type = AV_STEREO3D_TOPBOTTOM;
+             break;
+         case 5:
+             stereo->type = AV_STEREO3D_FRAMESEQUENCE;
+             break;
+         }
+         if (s->content_interpretation_type == 2)
+             stereo->flags = AV_STEREO3D_FLAG_INVERT;
+     }
+     return 0;
+ }
  static int hevc_frame_start(HEVCContext *s)
  {
 -    HEVCLocalContext *lc = &s->HEVClc;
 +    HEVCLocalContext *lc = s->HEVClc;
      int ret;
  
      memset(s->horizontal_bs, 0, 2 * s->bs_width * (s->bs_height + 1));
@@@ -886,7 -921,11 +886,13 @@@ typedef struct HEVCContext 
      int nal_length_size;    ///< Number of bytes used for nal length (1, 2 or 4)
      int nuh_layer_id;
  
+     /** frame packing arrangement variables */
+     int sei_frame_packing_present;
+     int frame_packing_arrangement_type;
+     int content_interpretation_type;
+     int quincunx_subsampling;
++
 +    int picture_struct;
  } HEVCContext;
  
  int ff_hevc_decode_short_term_rps(HEVCContext *s, ShortTermRPS *rps,
@@@ -51,8 -48,8 +51,8 @@@ static void decode_nal_sei_decoded_pict
  
  static void decode_nal_sei_frame_packing_arrangement(HEVCContext *s)
  {
 -    GetBitContext *gb = &s->HEVClc.gb;
 +    GetBitContext *gb = &s->HEVClc->gb;
-     int cancel, type, quincunx;
+     int cancel, type, quincunx, content;
  
      get_ue_golomb(gb);                  // frame_packing_arrangement_id
      cancel = get_bits1(gb);             // frame_packing_cancel_flag
          skip_bits1(gb);         // frame_packing_arrangement_persistance_flag
      }
      skip_bits1(gb);             // upsampled_aspect_ratio_flag
+     s->sei_frame_packing_present      = (cancel == 0);
+     s->frame_packing_arrangement_type = type;
+     s->content_interpretation_type    = content;
+     s->quincunx_subsampling           = quincunx;
  }
  
 +static int decode_pic_timing(HEVCContext *s)
 +{
 +    GetBitContext *gb = &s->HEVClc->gb;
 +    HEVCSPS *sps;
 +
 +    if (!s->sps_list[s->active_seq_parameter_set_id])
 +        return(AVERROR(ENOMEM));
 +    sps = (HEVCSPS*)s->sps_list[s->active_seq_parameter_set_id]->data;
 +
 +    if (sps->vui.frame_field_info_present_flag) {
 +        int pic_struct = get_bits(gb, 4);
 +        s->picture_struct = AV_PICTURE_STRUCTURE_UNKNOWN;
 +        if (pic_struct == 2) {
 +            av_log(s->avctx, AV_LOG_DEBUG, "BOTTOM Field\n");
 +            s->picture_struct = AV_PICTURE_STRUCTURE_BOTTOM_FIELD;
 +        } else if (pic_struct == 1) {
 +            av_log(s->avctx, AV_LOG_DEBUG, "TOP Field\n");
 +            s->picture_struct = AV_PICTURE_STRUCTURE_TOP_FIELD;
 +        }
 +        get_bits(gb, 2);                   // source_scan_type
 +        get_bits(gb, 1);                   // duplicate_flag
 +    }
 +    return 1;
 +}
 +
 +static int active_parameter_sets(HEVCContext *s)
 +{
 +    GetBitContext *gb = &s->HEVClc->gb;
 +    int num_sps_ids_minus1;
 +    int i;
 +    unsigned active_seq_parameter_set_id;
 +
 +    get_bits(gb, 4); // active_video_parameter_set_id
 +    get_bits(gb, 1); // self_contained_cvs_flag
 +    get_bits(gb, 1); // num_sps_ids_minus1
 +    num_sps_ids_minus1 = get_ue_golomb_long(gb); // num_sps_ids_minus1
 +
 +    active_seq_parameter_set_id = get_ue_golomb_long(gb);
 +    if (active_seq_parameter_set_id >= MAX_SPS_COUNT) {
 +        av_log(s->avctx, AV_LOG_ERROR, "active_parameter_set_id %d invalid\n", active_seq_parameter_set_id);
 +        return AVERROR_INVALIDDATA;
 +    }
 +    s->active_seq_parameter_set_id = active_seq_parameter_set_id;
 +
 +    for (i = 1; i <= num_sps_ids_minus1; i++)
 +        get_ue_golomb_long(gb); // active_seq_parameter_set_id[i]
 +
 +    return 0;
 +}
 +
  static int decode_nal_sei_message(HEVCContext *s)
  {
 -    GetBitContext *gb = &s->HEVClc.gb;
 +    GetBitContext *gb = &s->HEVClc->gb;
  
      int payload_type = 0;
      int payload_size = 0;