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 "golomb.h"
26 #include "hevc.h"
27 
54 };
55 
57 {
58  int cIdx, i;
59  uint8_t hash_type;
60  //uint16_t picture_crc;
61  //uint32_t picture_checksum;
62  GetBitContext *gb = &s->HEVClc->gb;
63  hash_type = get_bits(gb, 8);
64 
65  for (cIdx = 0; cIdx < 3/*((s->sps->chroma_format_idc == 0) ? 1 : 3)*/; cIdx++) {
66  if (hash_type == 0) {
67  s->is_md5 = 1;
68  for (i = 0; i < 16; i++)
69  s->md5[cIdx][i] = get_bits(gb, 8);
70  } else if (hash_type == 1) {
71  // picture_crc = get_bits(gb, 16);
72  skip_bits(gb, 16);
73  } else if (hash_type == 2) {
74  // picture_checksum = get_bits_long(gb, 32);
75  skip_bits(gb, 32);
76  }
77  }
78  return 0;
79 }
80 
82 {
83  GetBitContext *gb = &s->HEVClc->gb;
84 
85  get_ue_golomb(gb); // frame_packing_arrangement_id
87 
92 
93  // the following skips spatial_flipping_flag frame0_flipped_flag
94  // field_views_flag current_frame_is_frame0_flag
95  // frame0_self_contained_flag frame1_self_contained_flag
96  skip_bits(gb, 6);
97 
99  skip_bits(gb, 16); // frame[01]_grid_position_[xy]
100  skip_bits(gb, 8); // frame_packing_arrangement_reserved_byte
101  skip_bits1(gb); // frame_packing_arrangement_persistance_flag
102  }
103  skip_bits1(gb); // upsampled_aspect_ratio_flag
104  return 0;
105 }
106 
108 {
109  GetBitContext *gb = &s->HEVClc->gb;
110 
112 
114  s->sei_hflip = get_bits1(gb); // hor_flip
115  s->sei_vflip = get_bits1(gb); // ver_flip
116 
118  skip_bits1(gb); // display_orientation_persistence_flag
119  }
120 
121  return 0;
122 }
123 
125 {
126  GetBitContext *gb = &s->HEVClc->gb;
127  HEVCSPS *sps;
128 
130  return(AVERROR(ENOMEM));
132 
134  int pic_struct = get_bits(gb, 4);
136  if (pic_struct == 2) {
137  av_log(s->avctx, AV_LOG_DEBUG, "BOTTOM Field\n");
139  } else if (pic_struct == 1) {
140  av_log(s->avctx, AV_LOG_DEBUG, "TOP Field\n");
142  }
143  get_bits(gb, 2); // source_scan_type
144  get_bits(gb, 1); // duplicate_flag
145  }
146  return 1;
147 }
148 
150 {
151  GetBitContext *gb = &s->HEVClc->gb;
152  int num_sps_ids_minus1;
153  int i;
154  unsigned active_seq_parameter_set_id;
155 
156  get_bits(gb, 4); // active_video_parameter_set_id
157  get_bits(gb, 1); // self_contained_cvs_flag
158  get_bits(gb, 1); // num_sps_ids_minus1
159  num_sps_ids_minus1 = get_ue_golomb_long(gb); // num_sps_ids_minus1
160 
161  if (num_sps_ids_minus1 < 0 || num_sps_ids_minus1 > 15) {
162  av_log(s->avctx, AV_LOG_ERROR, "num_sps_ids_minus1 %d invalid\n", num_sps_ids_minus1);
163  return AVERROR_INVALIDDATA;
164  }
165 
166  active_seq_parameter_set_id = get_ue_golomb_long(gb);
167  if (active_seq_parameter_set_id >= MAX_SPS_COUNT) {
168  av_log(s->avctx, AV_LOG_ERROR, "active_parameter_set_id %d invalid\n", active_seq_parameter_set_id);
169  return AVERROR_INVALIDDATA;
170  }
171  s->active_seq_parameter_set_id = active_seq_parameter_set_id;
172 
173  for (i = 1; i <= num_sps_ids_minus1; i++)
174  get_ue_golomb_long(gb); // active_seq_parameter_set_id[i]
175 
176  return 0;
177 }
178 
180 {
181  GetBitContext *gb = &s->HEVClc->gb;
182 
183  switch (type) {
184  case 256: // Mismatched value from HM 8.1
191  {
192  int ret = decode_pic_timing(s);
193  av_log(s->avctx, AV_LOG_DEBUG, "Skipped PREFIX SEI %d\n", type);
194  skip_bits(gb, 8 * size);
195  return ret;
196  }
199  av_log(s->avctx, AV_LOG_DEBUG, "Skipped PREFIX SEI %d\n", type);
200  return 0;
201  default:
202  av_log(s->avctx, AV_LOG_DEBUG, "Skipped PREFIX SEI %d\n", type);
203  skip_bits_long(gb, 8 * size);
204  return 0;
205  }
206 }
207 
209 {
210  GetBitContext *gb = &s->HEVClc->gb;
211 
212  switch (type) {
215  default:
216  av_log(s->avctx, AV_LOG_DEBUG, "Skipped SUFFIX SEI %d\n", type);
217  skip_bits_long(gb, 8 * size);
218  return 0;
219  }
220 }
221 
223 {
224  GetBitContext *gb = &s->HEVClc->gb;
225 
226  int payload_type = 0;
227  int payload_size = 0;
228  int byte = 0xFF;
229  av_log(s->avctx, AV_LOG_DEBUG, "Decoding SEI\n");
230 
231  while (byte == 0xFF) {
232  byte = get_bits(gb, 8);
233  payload_type += byte;
234  }
235  byte = 0xFF;
236  while (byte == 0xFF) {
237  byte = get_bits(gb, 8);
238  payload_size += byte;
239  }
240  if (s->nal_unit_type == NAL_SEI_PREFIX) {
241  return decode_nal_sei_prefix(s, payload_type, payload_size);
242  } else { /* nal_unit_type == NAL_SEI_SUFFIX */
243  return decode_nal_sei_suffix(s, payload_type, payload_size);
244  }
245  return 1;
246 }
247 
249 {
250  return get_bits_left(gb) > 0 && show_bits(gb, 8) != 0x80;
251 }
252 
254 {
255  int ret;
256 
257  do {
258  ret = decode_nal_sei_message(s);
259  if (ret < 0)
260  return(AVERROR(ENOMEM));
261  } while (more_rbsp_data(&s->HEVClc->gb));
262  return 1;
263 }
int frame_packing_arrangement_type
Definition: hevc.h:929
int sei_frame_packing_present
frame packing arrangement variables
Definition: hevc.h:928
const char * s
Definition: avisynth_c.h:631
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
int quincunx_subsampling
Definition: hevc.h:931
int active_seq_parameter_set_id
Definition: hevc.h:922
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:260
int content_interpretation_type
Definition: hevc.h:930
static void skip_bits_long(GetBitContext *s, int n)
Definition: get_bits.h:217
int sei_hflip
Definition: hevc.h:936
VUI vui
Definition: hevc.h:423
HEVCParamSets ps
Definition: hevc.h:844
HEVC_SEI_TYPE
Definition: hevc_sei.c:28
static int more_rbsp_data(GetBitContext *gb)
Definition: hevc_sei.c:248
uint8_t
AVCodecContext * avctx
Definition: hevc.h:821
int frame_field_info_present_flag
Definition: hevc.h:328
int sei_anticlockwise_rotation
Definition: hevc.h:935
ptrdiff_t size
Definition: opengl_enc.c:101
#define av_log(a,...)
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:588
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
static int get_ue_golomb(GetBitContext *gb)
read unsigned exp golomb code.
Definition: golomb.h:53
static int decode_nal_sei_decoded_picture_hash(HEVCContext *s)
Definition: hevc_sei.c:56
#define AVERROR(e)
Definition: error.h:43
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
int picture_struct
Definition: hevc.h:938
static int decode_nal_sei_prefix(HEVCContext *s, int type, int size)
Definition: hevc_sei.c:179
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
Definition: get_bits.h:287
#define MAX_SPS_COUNT
Definition: h264.h:49
static int decode_nal_sei_suffix(HEVCContext *s, int type, int size)
Definition: hevc_sei.c:208
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
Definition: hevc.h:398
int sei_display_orientation_present
display orientation
Definition: hevc.h:934
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_WB16 unsigned int_TMPL byte
Definition: bytestream.h:87
int ff_hevc_decode_nal_sei(HEVCContext *s)
Definition: hevc_sei.c:253
uint8_t md5[3][16]
Definition: hevc.h:914
uint8_t is_md5
Definition: hevc.h:915
uint8_t * data
The data buffer.
Definition: buffer.h:89
static int decode_nal_sei_display_orientation(HEVCContext *s)
Definition: hevc_sei.c:107
GLint GLenum type
Definition: opengl_enc.c:105
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:304
static void skip_bits1(GetBitContext *s)
Definition: get_bits.h:329
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:297
GetBitContext gb
Definition: hevc.h:783
enum NALUnitType nal_unit_type
Definition: hevc.h:855
HEVCLocalContext * HEVClc
Definition: hevc.h:826
static int decode_nal_sei_frame_packing_arrangement(HEVCContext *s)
Definition: hevc_sei.c:81
int sei_vflip
Definition: hevc.h:936
if(ret< 0)
Definition: vf_mcdeint.c:280
static int active_parameter_sets(HEVCContext *s)
Definition: hevc_sei.c:149
static int decode_nal_sei_message(HEVCContext *s)
Definition: hevc_sei.c:222
static int decode_pic_timing(HEVCContext *s)
Definition: hevc_sei.c:124
exp golomb vlc stuff
AVBufferRef * sps_list[MAX_SPS_COUNT]
Definition: hevc.h:563