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 
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  for (cIdx = 0; cIdx < 3/*((s->sps->chroma_format_idc == 0) ? 1 : 3)*/; cIdx++) {
38  if (hash_type == 0) {
39  s->is_md5 = 1;
40  for (i = 0; i < 16; i++)
41  s->md5[cIdx][i] = get_bits(gb, 8);
42  } else if (hash_type == 1) {
43  // picture_crc = get_bits(gb, 16);
44  skip_bits(gb, 16);
45  } else if (hash_type == 2) {
46  // picture_checksum = get_bits_long(gb, 32);
47  skip_bits(gb, 32);
48  }
49  }
50 }
51 
53 {
54  GetBitContext *gb = &s->HEVClc->gb;
55 
56  get_ue_golomb(gb); // frame_packing_arrangement_id
58 
63 
64  // the following skips spatial_flipping_flag frame0_flipped_flag
65  // field_views_flag current_frame_is_frame0_flag
66  // frame0_self_contained_flag frame1_self_contained_flag
67  skip_bits(gb, 6);
68 
70  skip_bits(gb, 16); // frame[01]_grid_position_[xy]
71  skip_bits(gb, 8); // frame_packing_arrangement_reserved_byte
72  skip_bits1(gb); // frame_packing_arrangement_persistance_flag
73  }
74  skip_bits1(gb); // upsampled_aspect_ratio_flag
75 }
76 
78 {
79  GetBitContext *gb = &s->HEVClc->gb;
80 
82 
84  s->sei_hflip = get_bits1(gb); // hor_flip
85  s->sei_vflip = get_bits1(gb); // ver_flip
86 
88  skip_bits1(gb); // display_orientation_persistence_flag
89  }
90 }
91 
93 {
94  GetBitContext *gb = &s->HEVClc->gb;
95  HEVCSPS *sps;
96 
98  return(AVERROR(ENOMEM));
100 
102  int pic_struct = get_bits(gb, 4);
104  if (pic_struct == 2) {
105  av_log(s->avctx, AV_LOG_DEBUG, "BOTTOM Field\n");
107  } else if (pic_struct == 1) {
108  av_log(s->avctx, AV_LOG_DEBUG, "TOP Field\n");
110  }
111  get_bits(gb, 2); // source_scan_type
112  get_bits(gb, 1); // duplicate_flag
113  }
114  return 1;
115 }
116 
118 {
119  GetBitContext *gb = &s->HEVClc->gb;
120  int num_sps_ids_minus1;
121  int i;
122  unsigned active_seq_parameter_set_id;
123 
124  get_bits(gb, 4); // active_video_parameter_set_id
125  get_bits(gb, 1); // self_contained_cvs_flag
126  get_bits(gb, 1); // num_sps_ids_minus1
127  num_sps_ids_minus1 = get_ue_golomb_long(gb); // num_sps_ids_minus1
128 
129  if (num_sps_ids_minus1 < 0 || num_sps_ids_minus1 > 15) {
130  av_log(s->avctx, AV_LOG_ERROR, "num_sps_ids_minus1 %d invalid\n", num_sps_ids_minus1);
131  return AVERROR_INVALIDDATA;
132  }
133 
134  active_seq_parameter_set_id = get_ue_golomb_long(gb);
135  if (active_seq_parameter_set_id >= MAX_SPS_COUNT) {
136  av_log(s->avctx, AV_LOG_ERROR, "active_parameter_set_id %d invalid\n", active_seq_parameter_set_id);
137  return AVERROR_INVALIDDATA;
138  }
139  s->active_seq_parameter_set_id = active_seq_parameter_set_id;
140 
141  for (i = 1; i <= num_sps_ids_minus1; i++)
142  get_ue_golomb_long(gb); // active_seq_parameter_set_id[i]
143 
144  return 0;
145 }
146 
148 {
149  GetBitContext *gb = &s->HEVClc->gb;
150 
151  int payload_type = 0;
152  int payload_size = 0;
153  int byte = 0xFF;
154  av_log(s->avctx, AV_LOG_DEBUG, "Decoding SEI\n");
155 
156  while (byte == 0xFF) {
157  byte = get_bits(gb, 8);
158  payload_type += byte;
159  }
160  byte = 0xFF;
161  while (byte == 0xFF) {
162  byte = get_bits(gb, 8);
163  payload_size += byte;
164  }
165  if (s->nal_unit_type == NAL_SEI_PREFIX) {
166  if (payload_type == 256 /*&& s->decode_checksum_sei*/) {
168  } else if (payload_type == 45) {
170  } else if (payload_type == 47) {
172  } else if (payload_type == 1){
173  int ret = decode_pic_timing(s);
174  av_log(s->avctx, AV_LOG_DEBUG, "Skipped PREFIX SEI %d\n", payload_type);
175  skip_bits(gb, 8 * payload_size);
176  return ret;
177  } else if (payload_type == 129){
179  av_log(s->avctx, AV_LOG_DEBUG, "Skipped PREFIX SEI %d\n", payload_type);
180  } else {
181  av_log(s->avctx, AV_LOG_DEBUG, "Skipped PREFIX SEI %d\n", payload_type);
182  skip_bits(gb, 8*payload_size);
183  }
184  } else { /* nal_unit_type == NAL_SEI_SUFFIX */
185  if (payload_type == 132 /* && s->decode_checksum_sei */)
187  else {
188  av_log(s->avctx, AV_LOG_DEBUG, "Skipped SUFFIX SEI %d\n", payload_type);
189  skip_bits(gb, 8 * payload_size);
190  }
191  }
192  return 1;
193 }
194 
196 {
197  return get_bits_left(gb) > 0 && show_bits(gb, 8) != 0x80;
198 }
199 
201 {
202  int ret;
203 
204  do {
205  ret = decode_nal_sei_message(s);
206  if (ret < 0)
207  return(AVERROR(ENOMEM));
208  } while (more_rbsp_data(&s->HEVClc->gb));
209  return 1;
210 }
static void decode_nal_sei_decoded_picture_hash(HEVCContext *s)
Definition: hevc_sei.c:28
int frame_packing_arrangement_type
Definition: hevc.h:914
int sei_frame_packing_present
frame packing arrangement variables
Definition: hevc.h:913
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:916
int active_seq_parameter_set_id
Definition: hevc.h:907
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:915
int sei_hflip
Definition: hevc.h:921
VUI vui
Definition: hevc.h:422
static int more_rbsp_data(GetBitContext *gb)
Definition: hevc_sei.c:195
if()
Definition: avfilter.c:975
uint8_t
AVCodecContext * avctx
Definition: hevc.h:792
static void decode_nal_sei_display_orientation(HEVCContext *s)
Definition: hevc_sei.c:77
int frame_field_info_present_flag
Definition: hevc.h:327
int sei_anticlockwise_rotation
Definition: hevc.h:920
#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
#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:923
ret
Definition: avfilter.c:974
AVBufferRef * sps_list[MAX_SPS_COUNT]
Definition: hevc.h:819
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 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:397
int sei_display_orientation_present
display orientation
Definition: hevc.h:919
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:85
int ff_hevc_decode_nal_sei(HEVCContext *s)
Definition: hevc_sei.c:200
uint8_t md5[3][16]
Definition: hevc.h:899
uint8_t is_md5
Definition: hevc.h:900
uint8_t * data
The data buffer.
Definition: buffer.h:89
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:754
enum NALUnitType nal_unit_type
Definition: hevc.h:831
HEVCLocalContext * HEVClc
Definition: hevc.h:797
int sei_vflip
Definition: hevc.h:921
static int active_parameter_sets(HEVCContext *s)
Definition: hevc_sei.c:117
static int decode_nal_sei_message(HEVCContext *s)
Definition: hevc_sei.c:147
static int decode_pic_timing(HEVCContext *s)
Definition: hevc_sei.c:92
static void decode_nal_sei_frame_packing_arrangement(HEVCContext *s)
Definition: hevc_sei.c:52
exp golomb vlc stuff