Libav
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 Libav.
9  *
10  * Libav 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  * Libav 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 Libav; 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  GetBitContext *gb = &s->HEVClc.gb;
60  uint8_t hash_type = get_bits(gb, 8);
61 
62  for (cIdx = 0; cIdx < 3; cIdx++) {
63  if (hash_type == 0) {
64  s->is_md5 = 1;
65  for (i = 0; i < 16; i++)
66  s->md5[cIdx][i] = get_bits(gb, 8);
67  } else if (hash_type == 1) {
68  // picture_crc = get_bits(gb, 16);
69  skip_bits(gb, 16);
70  } else if (hash_type == 2) {
71  // picture_checksum = get_bits(gb, 32);
72  skip_bits(gb, 32);
73  }
74  }
75  return 0;
76 }
77 
79 {
80  GetBitContext *gb = &s->HEVClc.gb;
81 
82  get_ue_golomb(gb); // frame_packing_arrangement_id
84 
89 
90  // the following skips spatial_flipping_flag frame0_flipped_flag
91  // field_views_flag current_frame_is_frame0_flag
92  // frame0_self_contained_flag frame1_self_contained_flag
93  skip_bits(gb, 6);
94 
96  skip_bits(gb, 16); // frame[01]_grid_position_[xy]
97  skip_bits(gb, 8); // frame_packing_arrangement_reserved_byte
98  skip_bits1(gb); // frame_packing_arrangement_persistence_flag
99  }
100  skip_bits1(gb); // upsampled_aspect_ratio_flag
101  return 0;
102 }
103 
105 {
106  GetBitContext *gb = &s->HEVClc.gb;
107 
109 
111  s->sei_hflip = get_bits1(gb); // hor_flip
112  s->sei_vflip = get_bits1(gb); // ver_flip
113 
115  skip_bits1(gb); // display_orientation_persistence_flag
116  }
117 
118  return 0;
119 }
120 
121 static int decode_nal_sei_prefix(HEVCContext *s, int type, int size)
122 {
123  GetBitContext *gb = &s->HEVClc.gb;
124 
125  switch (type) {
126  case 256: // Mismatched value from HM 8.1
132  default:
133  av_log(s->avctx, AV_LOG_DEBUG, "Skipped PREFIX SEI %d\n", type);
134  skip_bits_long(gb, 8 * size);
135  return 0;
136  }
137 }
138 
139 static int decode_nal_sei_suffix(HEVCContext *s, int type, int size)
140 {
141  GetBitContext *gb = &s->HEVClc.gb;
142 
143  switch (type) {
146  default:
147  av_log(s->avctx, AV_LOG_DEBUG, "Skipped SUFFIX SEI %d\n", type);
148  skip_bits_long(gb, 8 * size);
149  return 0;
150  }
151 }
152 
154 {
155  GetBitContext *gb = &s->HEVClc.gb;
156 
157  int payload_type = 0;
158  int payload_size = 0;
159  int byte = 0xFF;
160  av_log(s->avctx, AV_LOG_DEBUG, "Decoding SEI\n");
161 
162  while (byte == 0xFF) {
163  byte = get_bits(gb, 8);
164  payload_type += byte;
165  }
166  byte = 0xFF;
167  while (byte == 0xFF) {
168  byte = get_bits(gb, 8);
169  payload_size += byte;
170  }
171  if (s->nal_unit_type == NAL_SEI_PREFIX) {
172  return decode_nal_sei_prefix(s, payload_type, payload_size);
173  } else { /* nal_unit_type == NAL_SEI_SUFFIX */
174  return decode_nal_sei_suffix(s, payload_type, payload_size);
175  }
176  return 0;
177 }
178 
180 {
181  return get_bits_left(gb) > 0 && show_bits(gb, 8) != 0x80;
182 }
183 
185 {
186  do {
188  } while (more_rbsp_data(&s->HEVClc.gb));
189  return 0;
190 }
int frame_packing_arrangement_type
Definition: hevc.h:852
int sei_frame_packing_present
frame packing arrangement variables
Definition: hevc.h:851
int size
int quincunx_subsampling
Definition: hevc.h:854
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:228
int content_interpretation_type
Definition: hevc.h:853
static void skip_bits_long(GetBitContext *s, int n)
Definition: get_bits.h:187
int sei_hflip
Definition: hevc.h:859
av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (%s)\, len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic ? ac->func_descr_generic :ac->func_descr)
HEVC_SEI_TYPE
Definition: hevc_sei.c:28
static int more_rbsp_data(GetBitContext *gb)
Definition: hevc_sei.c:179
uint8_t
AVCodecContext * avctx
Definition: hevc.h:761
int sei_anticlockwise_rotation
Definition: hevc.h:858
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:526
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
HEVCLocalContext HEVClc
Definition: hevc.h:763
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:145
static int decode_nal_sei_prefix(HEVCContext *s, int type, int size)
Definition: hevc_sei.c:121
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
Definition: get_bits.h:250
static int decode_nal_sei_suffix(HEVCContext *s, int type, int size)
Definition: hevc_sei.c:139
int sei_display_orientation_present
display orientation
Definition: hevc.h:857
int ff_hevc_decode_nal_sei(HEVCContext *s)
Definition: hevc_sei.c:184
uint8_t md5[3][16]
Definition: hevc.h:839
uint8_t is_md5
Definition: hevc.h:840
static int decode_nal_sei_display_orientation(HEVCContext *s)
Definition: hevc_sei.c:104
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:267
static void skip_bits1(GetBitContext *s)
Definition: get_bits.h:292
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:259
GetBitContext gb
Definition: hevc.h:728
enum NALUnitType nal_unit_type
Definition: hevc.h:786
static int decode_nal_sei_frame_packing_arrangement(HEVCContext *s)
Definition: hevc_sei.c:78
int sei_vflip
Definition: hevc.h:859
static int decode_nal_sei_message(HEVCContext *s)
Definition: hevc_sei.c:153
exp golomb vlc stuff