Merge commit '0569a7e0bd2006d9a5248d17a1f4bf3ca654ae50'
authorMichael Niedermayer <michaelni@gmx.at>
Wed, 9 Jul 2014 22:15:34 +0000 (00:15 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Wed, 9 Jul 2014 22:19:43 +0000 (00:19 +0200)
* commit '0569a7e0bd2006d9a5248d17a1f4bf3ca654ae50':
  hevc: parse display orientation SEI message

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

   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
   */
  
 +#include "libavutil/atomic.h"
  #include "libavutil/attributes.h"
  #include "libavutil/common.h"
+ #include "libavutil/display.h"
  #include "libavutil/internal.h"
  #include "libavutil/md5.h"
  #include "libavutil/opt.h"
@@@ -885,7 -860,10 +885,12 @@@ typedef struct HEVCContext 
      int content_interpretation_type;
      int quincunx_subsampling;
  
+     /** display orientation */
+     int sei_display_orientation_present;
+     int sei_anticlockwise_rotation;
+     int sei_hflip, sei_vflip;
++
 +    int picture_struct;
  } HEVCContext;
  
  int ff_hevc_decode_short_term_rps(HEVCContext *s, ShortTermRPS *rps,
@@@ -74,59 -71,24 +74,74 @@@ static void decode_nal_sei_frame_packin
      skip_bits1(gb);             // upsampled_aspect_ratio_flag
  }
  
 -    GetBitContext *gb = &s->HEVClc.gb;
+ static void decode_nal_sei_display_orientation(HEVCContext *s)
+ {
++    GetBitContext *gb = &s->HEVClc->gb;
+     s->sei_display_orientation_present = !get_bits1(gb);
+     if (s->sei_display_orientation_present) {
+         s->sei_hflip = get_bits1(gb);     // hor_flip
+         s->sei_vflip = get_bits1(gb);     // ver_flip
+         s->sei_anticlockwise_rotation = get_bits(gb, 16);
+         skip_bits1(gb);     // display_orientation_persistence_flag
+     }
+ }
 +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;
          payload_size += byte;
      }
      if (s->nal_unit_type == NAL_SEI_PREFIX) {
 -        if (payload_type == 256)
 +        if (payload_type == 256 /*&& s->decode_checksum_sei*/) {
              decode_nal_sei_decoded_picture_hash(s);
 -        else if (payload_type == 45)
 +            return 1;
 +        } else if (payload_type == 45) {
              decode_nal_sei_frame_packing_arrangement(s);
 -        else if (payload_type == 47)
 +            return 1;
++        } else if (payload_type == 47) {
+             decode_nal_sei_display_orientation(s);
 -        else {
++            return 1;
 +        } else if (payload_type == 1){
 +            int ret = decode_pic_timing(s);
              av_log(s->avctx, AV_LOG_DEBUG, "Skipped PREFIX SEI %d\n", payload_type);
              skip_bits(gb, 8 * payload_size);
 +            return ret;
 +        } else if (payload_type == 129){
 +            active_parameter_sets(s);
 +            av_log(s->avctx, AV_LOG_DEBUG, "Skipped PREFIX SEI %d\n", payload_type);
 +            return 1;
 +        } else {
 +            av_log(s->avctx, AV_LOG_DEBUG, "Skipped PREFIX SEI %d\n", payload_type);
 +            skip_bits(gb, 8*payload_size);
 +            return 1;
          }
      } else { /* nal_unit_type == NAL_SEI_SUFFIX */
 -        if (payload_type == 132)
 +        if (payload_type == 132 /* && s->decode_checksum_sei */)
              decode_nal_sei_decoded_picture_hash(s);
          else {
              av_log(s->avctx, AV_LOG_DEBUG, "Skipped SUFFIX SEI %d\n", payload_type);