2 * HEVC Supplementary Enhancement Information messages
4 * Copyright (C) 2012 - 2013 Guillaume Martres
5 * Copyright (C) 2012 - 2013 Gildas Cocherel
6 * Copyright (C) 2013 Vittorio Giovara
8 * This file is part of Libav.
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.
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.
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
25 #include "golomb_legacy.h"
29 SEI_TYPE_BUFFERING_PERIOD = 0,
30 SEI_TYPE_PICTURE_TIMING = 1,
31 SEI_TYPE_PAN_SCAN_RECT = 2,
32 SEI_TYPE_FILLER_PAYLOAD = 3,
33 SEI_TYPE_USER_DATA_REGISTERED_ITU_T_T35 = 4,
34 SEI_TYPE_USER_DATA_UNREGISTERED = 5,
35 SEI_TYPE_RECOVERY_POINT = 6,
36 SEI_TYPE_SCENE_INFO = 9,
37 SEI_TYPE_FULL_FRAME_SNAPSHOT = 15,
38 SEI_TYPE_PROGRESSIVE_REFINEMENT_SEGMENT_START = 16,
39 SEI_TYPE_PROGRESSIVE_REFINEMENT_SEGMENT_END = 17,
40 SEI_TYPE_FILM_GRAIN_CHARACTERISTICS = 19,
41 SEI_TYPE_POST_FILTER_HINT = 22,
42 SEI_TYPE_TONE_MAPPING_INFO = 23,
43 SEI_TYPE_FRAME_PACKING = 45,
44 SEI_TYPE_DISPLAY_ORIENTATION = 47,
45 SEI_TYPE_SOP_DESCRIPTION = 128,
46 SEI_TYPE_ACTIVE_PARAMETER_SETS = 129,
47 SEI_TYPE_DECODING_UNIT_INFO = 130,
48 SEI_TYPE_TEMPORAL_LEVEL0_INDEX = 131,
49 SEI_TYPE_DECODED_PICTURE_HASH = 132,
50 SEI_TYPE_SCALABLE_NESTING = 133,
51 SEI_TYPE_REGION_REFRESH_INFO = 134,
52 SEI_TYPE_MASTERING_DISPLAY_INFO = 137,
53 SEI_TYPE_CONTENT_LIGHT_LEVEL_INFO = 144,
56 static int decode_nal_sei_decoded_picture_hash(HEVCContext *s)
59 GetBitContext *gb = &s->HEVClc.gb;
60 uint8_t hash_type = get_bits(gb, 8);
62 for (cIdx = 0; cIdx < 3; cIdx++) {
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);
70 } else if (hash_type == 2) {
71 // picture_checksum = get_bits(gb, 32);
78 static int decode_nal_sei_frame_packing_arrangement(HEVCContext *s)
80 GetBitContext *gb = &s->HEVClc.gb;
82 get_ue_golomb(gb); // frame_packing_arrangement_id
83 s->sei_frame_packing_present = !get_bits1(gb);
85 if (s->sei_frame_packing_present) {
86 s->frame_packing_arrangement_type = get_bits(gb, 7);
87 s->quincunx_subsampling = get_bits1(gb);
88 s->content_interpretation_type = get_bits(gb, 6);
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
95 if (!s->quincunx_subsampling && s->frame_packing_arrangement_type != 5)
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
100 skip_bits1(gb); // upsampled_aspect_ratio_flag
104 static int decode_nal_sei_display_orientation(HEVCContext *s)
106 GetBitContext *gb = &s->HEVClc.gb;
108 s->sei_display_orientation_present = !get_bits1(gb);
110 if (s->sei_display_orientation_present) {
111 s->sei_hflip = get_bits1(gb); // hor_flip
112 s->sei_vflip = get_bits1(gb); // ver_flip
114 s->sei_anticlockwise_rotation = get_bits(gb, 16);
115 skip_bits1(gb); // display_orientation_persistence_flag
121 static int decode_nal_sei_prefix(HEVCContext *s, int type, int size)
123 GetBitContext *gb = &s->HEVClc.gb;
126 case 256: // Mismatched value from HM 8.1
127 return decode_nal_sei_decoded_picture_hash(s);
128 case SEI_TYPE_FRAME_PACKING:
129 return decode_nal_sei_frame_packing_arrangement(s);
130 case SEI_TYPE_DISPLAY_ORIENTATION:
131 return decode_nal_sei_display_orientation(s);
133 av_log(s->avctx, AV_LOG_DEBUG, "Skipped PREFIX SEI %d\n", type);
134 skip_bits_long(gb, 8 * size);
139 static int decode_nal_sei_suffix(HEVCContext *s, int type, int size)
141 GetBitContext *gb = &s->HEVClc.gb;
144 case SEI_TYPE_DECODED_PICTURE_HASH:
145 return decode_nal_sei_decoded_picture_hash(s);
147 av_log(s->avctx, AV_LOG_DEBUG, "Skipped SUFFIX SEI %d\n", type);
148 skip_bits_long(gb, 8 * size);
153 static int decode_nal_sei_message(HEVCContext *s)
155 GetBitContext *gb = &s->HEVClc.gb;
157 int payload_type = 0;
158 int payload_size = 0;
160 av_log(s->avctx, AV_LOG_DEBUG, "Decoding SEI\n");
162 while (byte == 0xFF) {
163 byte = get_bits(gb, 8);
164 payload_type += byte;
167 while (byte == 0xFF) {
168 byte = get_bits(gb, 8);
169 payload_size += byte;
171 if (s->nal_unit_type == HEVC_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);
178 static int more_rbsp_data(GetBitContext *gb)
180 return get_bits_left(gb) > 0 && show_bits(gb, 8) != 0x80;
183 int ff_hevc_decode_nal_sei(HEVCContext *s)
186 decode_nal_sei_message(s);
187 } while (more_rbsp_data(&s->HEVClc.gb));