FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
hevc_sei.c
Go to the documentation of this file.
1 /*
2  * HEVC Supplementary Enhancement Information messages
3  *
4  * Copyright (C) 2012 - 2013 Guillaume Martres
5  * Copyright (C) 2012 - 2013 Gildas Cocherel
6  * Copyright (C) 2013 Vittorio Giovara
7  *
8  * This file is part of FFmpeg.
9  *
10  * FFmpeg is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 2.1 of the License, or (at your option) any later version.
14  *
15  * FFmpeg is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with FFmpeg; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23  */
24 
25 #include "hevc.h"
26 #include "golomb.h"
27 
28 static void decode_nal_sei_decoded_picture_hash(HEVCContext *s, int payload_size)
29 {
30  int cIdx, i;
31  uint8_t hash_type;
32  //uint16_t picture_crc;
33  //uint32_t picture_checksum;
34  GetBitContext *gb = &s->HEVClc->gb;
35  hash_type = get_bits(gb, 8);
36 
37 
38  for( cIdx = 0; cIdx < 3/*((s->sps->chroma_format_idc == 0) ? 1 : 3)*/; cIdx++ ) {
39  if ( hash_type == 0 ) {
40  s->is_md5 = 1;
41  for( i = 0; i < 16; i++) {
42  s->md5[cIdx][i] = get_bits(gb, 8);
43  }
44  } else if( hash_type == 1 ) {
45  // picture_crc = get_bits(gb, 16);
46  skip_bits(gb, 16);
47  } else if( hash_type == 2 ) {
48  // picture_checksum = get_bits(gb, 32);
49  skip_bits(gb, 32);
50  }
51  }
52 }
53 
55 {
56  GetBitContext *gb = &lc->gb;
57  int cancel, type, quincunx;
58 
59  get_ue_golomb(gb); // frame_packing_arrangement_id
60  cancel = get_bits1(gb); // frame_packing_cancel_flag
61  if ( cancel == 0 )
62  {
63  type = get_bits(gb, 7); // frame_packing_arrangement_type
64  quincunx = get_bits1(gb); // quincunx_sampling_flag
65  skip_bits(gb, 6); // content_interpretation_type
66 
67  // the following skips spatial_flipping_flag frame0_flipped_flag
68  // field_views_flag current_frame_is_frame0_flag
69  // frame0_self_contained_flag frame1_self_contained_flag
70  skip_bits(gb, 6);
71 
72  if ( quincunx == 0 && type != 5 )
73  skip_bits(gb, 16); // frame[01]_grid_position_[xy]
74  skip_bits(gb, 8); // frame_packing_arrangement_reserved_byte
75  skip_bits1(gb); // frame_packing_arrangement_persistance_flag
76  }
77  skip_bits1(gb); // upsampled_aspect_ratio_flag
78 }
79 
81 {
82  GetBitContext *gb = &s->HEVClc->gb;
83 
84  int payload_type = 0;
85  int payload_size = 0;
86  int byte = 0xFF;
87  av_log(s->avctx, AV_LOG_DEBUG, "Decoding SEI\n");
88 
89  while (byte == 0xFF) {
90  byte = get_bits(gb, 8);
91  payload_type += byte;
92  }
93  byte = 0xFF;
94  while (byte == 0xFF) {
95  byte = get_bits(gb, 8);
96  payload_size += byte;
97  }
98  if (s->nal_unit_type == NAL_SEI_PREFIX) {
99  if (payload_type == 256 /*&& s->decode_checksum_sei*/)
100  decode_nal_sei_decoded_picture_hash(s, payload_size);
101  else if (payload_type == 45)
103  else {
104  av_log(s->avctx, AV_LOG_DEBUG, "Skipped PREFIX SEI %d\n", payload_type);
105  skip_bits(gb, 8*payload_size);
106  }
107  } else { /* nal_unit_type == NAL_SEI_SUFFIX */
108  if (payload_type == 132 /* && s->decode_checksum_sei */)
109  decode_nal_sei_decoded_picture_hash(s, payload_size);
110  else {
111  av_log(s->avctx, AV_LOG_DEBUG, "Skipped SUFFIX SEI %d\n", payload_type);
112  skip_bits(gb, 8*payload_size);
113  }
114  }
115  return 0;
116 }
117 
119 {
120  return get_bits_left(gb) > 0 && show_bits(gb, 8) != 0x80;
121 }
122 
124 {
125  do {
127  } while (more_rbsp_data(&s->HEVClc->gb));
128  return 0;
129 }