1 /*
2 *
3 * Copyright 2015 Rockchip Electronics Co. LTD
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 /*
19 * @file h265d_sei.c
20 * @brief
21 * @author csy(csy@rock-chips.com)
22
23 * @version 1.0.0
24 * @history
25 * 2015.7.15 : Create
26 */
27
28 #define MODULE_TAG "h265d_sei"
29
30 #include "mpp_bitread.h"
31 #include "h265d_parser.h"
32 #include "rk_hdr_meta_com.h"
33 #include "h2645d_sei.h"
34
35
decode_nal_sei_decoded_picture_hash(BitReadCtx_t * gb)36 static RK_S32 decode_nal_sei_decoded_picture_hash(BitReadCtx_t *gb)
37 {
38 RK_S32 cIdx, i;
39 RK_U8 hash_type;
40 READ_BITS(gb, 8, &hash_type);
41
42 for (cIdx = 0; cIdx < 3/*((s->sps->chroma_format_idc == 0) ? 1 : 3)*/; cIdx++) {
43 if (hash_type == 0) {
44 //s->is_md5 = 1;
45 for (i = 0; i < 16; i++)
46 SKIP_BITS(gb, 8);
47 } else if (hash_type == 1) {
48 SKIP_BITS(gb, 16);
49 } else if (hash_type == 2) {
50 SKIP_BITS(gb, 32);
51 }
52 }
53 return 0;
54 __BITREAD_ERR:
55 return MPP_ERR_STREAM;
56 }
57
decode_nal_sei_frame_packing_arrangement(HEVCContext * s,BitReadCtx_t * gb)58 static RK_S32 decode_nal_sei_frame_packing_arrangement(HEVCContext *s, BitReadCtx_t *gb)
59 {
60 RK_S32 value = 0;
61
62 READ_UE(gb, &value); // frame_packing_arrangement_id
63 READ_ONEBIT(gb, &value);
64 s->sei_frame_packing_present = !value;
65
66 if (s->sei_frame_packing_present) {
67 READ_BITS(gb, 7, &s->frame_packing_arrangement_type);
68 READ_ONEBIT(gb, &s->quincunx_subsampling);
69 READ_BITS(gb, 6, &s->content_interpretation_type);
70
71 // the following skips spatial_flipping_flag frame0_flipped_flag
72 // field_views_flag current_frame_is_frame0_flag
73 // frame0_self_contained_flag frame1_self_contained_flag
74 SKIP_BITS(gb, 6);
75
76 if (!s->quincunx_subsampling && s->frame_packing_arrangement_type != 5)
77 SKIP_BITS(gb, 16); // frame[01]_grid_position_[xy]
78 SKIP_BITS(gb, 8); // frame_packing_arrangement_reserved_byte
79 SKIP_BITS(gb, 1); // frame_packing_arrangement_persistance_flag
80 }
81 SKIP_BITS(gb, 1); // upsampled_aspect_ratio_flag
82 return 0;
83 __BITREAD_ERR:
84 return MPP_ERR_STREAM;
85 }
86
decode_pic_timing(HEVCContext * s,BitReadCtx_t * gb)87 static RK_S32 decode_pic_timing(HEVCContext *s, BitReadCtx_t *gb)
88 {
89 HEVCSPS *sps;
90
91 if (!s->sps_list[s->active_seq_parameter_set_id])
92 return MPP_ERR_NOMEM;
93 sps = (HEVCSPS*)s->sps_list[s->active_seq_parameter_set_id];
94 s->picture_struct = MPP_PICTURE_STRUCTURE_UNKNOWN;
95 if (sps->vui.frame_field_info_present_flag) {
96 READ_BITS(gb, 4, &s->picture_struct);
97 switch (s->picture_struct) {
98 case 0 : s->picture_struct = MPP_PICTURE_STRUCTURE_FRAME; h265d_dbg(H265D_DBG_SEI, "(progressive) frame \n"); break;
99 case 1 : s->picture_struct = MPP_PICTURE_STRUCTURE_TOP_FIELD; h265d_dbg(H265D_DBG_SEI, "top field\n"); break;
100 case 2 : s->picture_struct = MPP_PICTURE_STRUCTURE_BOTTOM_FIELD; h265d_dbg(H265D_DBG_SEI, "bottom field\n"); break;
101 case 3 : s->picture_struct = MPP_PICTURE_STRUCTURE_FRAME; h265d_dbg(H265D_DBG_SEI, "top field, bottom field, in that order\n"); break;
102 case 4 : s->picture_struct = MPP_PICTURE_STRUCTURE_FRAME; h265d_dbg(H265D_DBG_SEI, "bottom field, top field, in that order\n"); break;
103 case 5 : s->picture_struct = MPP_PICTURE_STRUCTURE_FRAME; h265d_dbg(H265D_DBG_SEI, "top field, bottom field, top field repeated, in that order\n"); break;
104 case 6 : s->picture_struct = MPP_PICTURE_STRUCTURE_FRAME; h265d_dbg(H265D_DBG_SEI, "bottom field, top field, bottom field repeated, in that order\n"); break;
105 case 7 : s->picture_struct = MPP_PICTURE_STRUCTURE_FRAME; h265d_dbg(H265D_DBG_SEI, "frame doubling\n"); break;
106 case 8 : s->picture_struct = MPP_PICTURE_STRUCTURE_FRAME; h265d_dbg(H265D_DBG_SEI, "frame tripling\n"); break;
107 case 9 : s->picture_struct = MPP_PICTURE_STRUCTURE_TOP_FIELD; h265d_dbg(H265D_DBG_SEI, "top field paired with previous bottom field in output order\n"); break;
108 case 10 : s->picture_struct = MPP_PICTURE_STRUCTURE_BOTTOM_FIELD; h265d_dbg(H265D_DBG_SEI, "bottom field paired with previous top field in output order\n"); break;
109 case 11 : s->picture_struct = MPP_PICTURE_STRUCTURE_TOP_FIELD; h265d_dbg(H265D_DBG_SEI, "top field paired with next bottom field in output order\n"); break;
110 case 12 : s->picture_struct = MPP_PICTURE_STRUCTURE_BOTTOM_FIELD; h265d_dbg(H265D_DBG_SEI, "bottom field paired with next top field in output order\n"); break;
111 }
112 SKIP_BITS(gb, 2); // source_scan_type
113 SKIP_BITS(gb, 1); // duplicate_flag
114 }
115 return 0;
116 __BITREAD_ERR:
117 return MPP_ERR_STREAM;
118 }
119
active_parameter_sets(HEVCContext * s,BitReadCtx_t * gb)120 static RK_S32 active_parameter_sets(HEVCContext *s, BitReadCtx_t *gb)
121 {
122 RK_S32 num_sps_ids_minus1;
123 RK_S32 i, value;
124 RK_U32 active_seq_parameter_set_id;
125
126 SKIP_BITS(gb, 4); // active_video_parameter_set_id
127 SKIP_BITS(gb, 1); // self_contained_cvs_flag
128 SKIP_BITS(gb, 1); // num_sps_ids_minus1
129 READ_UE(gb, &num_sps_ids_minus1); // num_sps_ids_minus1
130
131 READ_UE(gb, &active_seq_parameter_set_id);
132 if (active_seq_parameter_set_id >= MAX_SPS_COUNT) {
133 mpp_err( "active_parameter_set_id %d invalid\n", active_seq_parameter_set_id);
134 return MPP_ERR_STREAM;
135 }
136 s->active_seq_parameter_set_id = active_seq_parameter_set_id;
137
138 for (i = 1; i <= num_sps_ids_minus1; i++)
139 READ_UE(gb, &value); // active_seq_parameter_set_id[i]
140
141 return 0;
142 __BITREAD_ERR:
143 return MPP_ERR_STREAM;
144 }
145
mastering_display_colour_volume(HEVCContext * s,BitReadCtx_t * gb)146 static RK_S32 mastering_display_colour_volume(HEVCContext *s, BitReadCtx_t *gb)
147 {
148 RK_S32 i = 0;
149 RK_U16 value = 0;
150 RK_U32 lum = 0;
151
152 for (i = 0; i < 3; i++) {
153 READ_BITS(gb, 16, &value);
154 s->mastering_display.display_primaries[i][0] = value;
155 READ_BITS(gb, 16, &value);
156 s->mastering_display.display_primaries[i][1] = value;
157 }
158 READ_BITS(gb, 16, &value);
159 s->mastering_display.white_point[0] = value;
160 READ_BITS(gb, 16, &value);
161 s->mastering_display.white_point[1] = value;
162 mpp_read_longbits(gb, 32, &lum);
163 s->mastering_display.max_luminance = lum;
164 mpp_read_longbits(gb, 32, &lum);
165 s->mastering_display.min_luminance = lum;
166
167 h265d_dbg(H265D_DBG_SEI, "dis_prim [%d %d] [%d %d] [%d %d] white point %d %d luminance %d %d\n",
168 s->mastering_display.display_primaries[0][0],
169 s->mastering_display.display_primaries[0][1],
170 s->mastering_display.display_primaries[1][0],
171 s->mastering_display.display_primaries[1][1],
172 s->mastering_display.display_primaries[2][0],
173 s->mastering_display.display_primaries[2][1],
174 s->mastering_display.white_point[0],
175 s->mastering_display.white_point[1],
176 s->mastering_display.max_luminance,
177 s->mastering_display.min_luminance);
178
179 return 0;
180
181 __BITREAD_ERR:
182 return MPP_ERR_STREAM;
183 }
184
content_light_info(HEVCContext * s,BitReadCtx_t * gb)185 static RK_S32 content_light_info(HEVCContext *s, BitReadCtx_t *gb)
186 {
187 RK_U32 value = 0;
188 mpp_read_longbits(gb, 16, &value);
189 s->content_light.MaxCLL = value;
190 mpp_read_longbits(gb, 16, &value);
191 s->content_light.MaxFALL = value;
192 return 0;
193 }
194
colour_remapping_info(BitReadCtx_t * gb)195 static RK_S32 colour_remapping_info(BitReadCtx_t *gb)
196 {
197 RK_U32 i = 0, j = 0;
198 RK_U32 value = 0;
199 RK_U32 in_bit_depth = 0;
200 RK_U32 out_bit_depth = 0;
201
202 READ_UE(gb, &value); //colour_remap ID
203 READ_ONEBIT(gb, &value); //colour_remap_cancel_flag
204 if (!value) {
205 READ_ONEBIT(gb, &value); //colour_remap_persistence_flag
206 READ_ONEBIT(gb, &value); //colour_remap_video_signal_info_present_flag
207 if (value) {
208 READ_ONEBIT(gb, &value); //colour_remap_full_rang_flag
209 READ_BITS(gb, 8, &value); //colour_remap_primaries
210 READ_BITS(gb, 8, &value); //colour_remap_transfer_function
211 READ_BITS(gb, 8, &value); //colour_remap_matries_coefficients
212 }
213
214 READ_BITS(gb, 8, &in_bit_depth); //colour_remap_input_bit_depth
215 READ_BITS(gb, 8, &out_bit_depth); //colour_remap_bit_depth
216 for (i = 0; i < 3; i++) {
217 RK_U32 pre_lut_num_val_minus1 = 0;
218 RK_U32 in_bit = ((in_bit_depth + 7) >> 3) << 3;
219 RK_U32 out_bit = ((out_bit_depth + 7) >> 3) << 3;
220 READ_BITS(gb, 8, &pre_lut_num_val_minus1); //pre_lut_num_val_minus1
221 if (pre_lut_num_val_minus1 > 0) {
222 for (j = 0; j <= pre_lut_num_val_minus1; j++) {
223 READ_BITS(gb, in_bit, &value); //pre_lut_coded_value
224 READ_BITS(gb, out_bit, &value); //pre_lut_target_value
225 }
226 }
227 }
228 READ_ONEBIT(gb, &value); //colour_remap_matrix_present_flag
229 if (value) {
230 READ_BITS(gb, 4, &value); //log2_matrix_denom
231 for (i = 0; i < 3; i++) {
232 for (j = 0; j < 3; j++)
233 READ_SE(gb, &value); //colour_remap_coeffs
234 }
235 }
236 for (i = 0; i < 3; i++) {
237 RK_U32 post_lut_num_val_minus1 = 0;
238 RK_U32 in_bit = ((in_bit_depth + 7) >> 3) << 3;
239 RK_U32 out_bit = ((out_bit_depth + 7) >> 3) << 3;
240 READ_BITS(gb, 8, &post_lut_num_val_minus1); //post_lut_num_val_minus1
241 if (post_lut_num_val_minus1 > 0) {
242 for (j = 0; j <= post_lut_num_val_minus1; j++) {
243 READ_BITS(gb, in_bit, &value); //post_lut_coded_value
244 READ_BITS(gb, out_bit, &value); //post_lut_target_value
245 }
246 }
247 }
248
249 }
250
251 return MPP_OK;
252 __BITREAD_ERR:
253 return MPP_ERR_STREAM;
254 }
255
tone_mapping_info(BitReadCtx_t * gb)256 static RK_S32 tone_mapping_info(BitReadCtx_t *gb)
257 {
258 RK_U32 i = 0;
259 RK_U32 value = 0;
260 RK_U32 codec_bit_depth = 0;
261 RK_U32 target_bit_depth = 0;
262
263 READ_UE(gb, &value); //tone_map ID
264 READ_ONEBIT(gb, &value); //tone_map_cancel_flag
265 if (!value) {
266 RK_U32 tone_map_model_id;
267 READ_ONEBIT(gb, &value); //tone_map_persistence_flag
268 READ_BITS(gb, 8, &codec_bit_depth); //coded_data_bit_depth
269 READ_BITS(gb, 8, &target_bit_depth); //target_bit_depth
270 READ_UE(gb, &tone_map_model_id); //tone_map_model_id
271 switch (tone_map_model_id) {
272 case 0: {
273 mpp_read_longbits(gb, 32, &value); //min_value
274 mpp_read_longbits(gb, 32, &value); //max_value
275 break;
276 }
277 case 1: {
278 mpp_read_longbits(gb, 32, &value); //sigmoid_midpoint
279 mpp_read_longbits(gb, 32, &value); //sigmoid_width
280 break;
281 }
282 case 2: {
283 RK_U32 in_bit = ((codec_bit_depth + 7) >> 3) << 3;
284 for (i = 0; i < (RK_U32)(1 << target_bit_depth); i++) {
285 READ_BITS(gb, in_bit, &value);
286 }
287 break;
288 }
289 case 3: {
290 RK_U32 num_pivots;
291 RK_U32 in_bit = ((codec_bit_depth + 7) >> 3) << 3;
292 RK_U32 out_bit = ((target_bit_depth + 7) >> 3) << 3;
293 READ_BITS(gb, 16, &num_pivots); //num_pivots
294 for (i = 0; i < num_pivots; i++) {
295 READ_BITS(gb, in_bit, &value);
296 READ_BITS(gb, out_bit, &value);
297 }
298 break;
299 }
300 case 4: {
301 RK_U32 camera_iso_speed_idc;
302 RK_U32 exposure_index_idc;
303 READ_BITS(gb, 8, &camera_iso_speed_idc);
304 if (camera_iso_speed_idc == 255) {
305 mpp_read_longbits(gb, 32, &value); //camera_iso_speed_value
306
307 }
308 READ_BITS(gb, 8, &exposure_index_idc);
309 if (exposure_index_idc == 255) {
310 mpp_read_longbits(gb, 32, &value); //exposure_index_value
311 }
312 READ_ONEBIT(gb, &value); //exposure_compensation_value_sign_flag
313 READ_BITS(gb, 16, &value); //exposure_compensation_value_numerator
314 READ_BITS(gb, 16, &value); //exposure_compensation_value_denom_idc
315 READ_BITS_LONG(gb, 32, &value); //ref_screen_luminance_white
316 READ_BITS_LONG(gb, 32, &value); //extended_range_white_level
317 READ_BITS(gb, 16, &value); //nominal_black_level_code_value
318 READ_BITS(gb, 16, &value); //nominal_white_level_code_value
319 READ_BITS(gb, 16, &value); //extended_white_level_code_value
320 break;
321 }
322 default:
323 break;
324 }
325 }
326
327 return MPP_OK;
328 __BITREAD_ERR:
329 return MPP_ERR_STREAM;
330 }
331
vivid_display_info(HEVCContext * s,BitReadCtx_t * gb,RK_U32 size)332 static RK_S32 vivid_display_info(HEVCContext *s, BitReadCtx_t *gb, RK_U32 size)
333 {
334 if (gb)
335 mpp_hevc_fill_dynamic_meta(s, gb->data_, size, HDRVIVID);
336 return 0;
337 }
338
hdr10plus_dynamic_data(HEVCContext * s,BitReadCtx_t * gb,RK_U32 size)339 static RK_S32 hdr10plus_dynamic_data(HEVCContext *s, BitReadCtx_t *gb, RK_U32 size)
340 {
341 if (gb)
342 mpp_hevc_fill_dynamic_meta(s, gb->data_, size, HDR10PLUS);
343 return 0;
344 }
345
user_data_registered_itu_t_t35(HEVCContext * s,BitReadCtx_t * gb,int size)346 static RK_S32 user_data_registered_itu_t_t35(HEVCContext *s, BitReadCtx_t *gb, int size)
347 {
348 RK_S32 country_code, provider_code;
349 RK_U16 provider_oriented_code;
350
351 if (size < 3)
352 return 0;
353
354 READ_BITS(gb, 8, &country_code);
355 if (country_code == 0xFF) {
356 if (size < 1)
357 return 0;
358
359 SKIP_BITS(gb, 8);
360 }
361
362 /* usa country_code or china country_code */
363 if (country_code != 0xB5 && country_code != 0x26) {
364 mpp_log("Unsupported User Data Registered ITU-T T35 SEI message (country_code = %d)", country_code);
365 return MPP_ERR_STREAM;
366 }
367
368 READ_BITS(gb, 16, &provider_code);
369 READ_BITS(gb, 16, &provider_oriented_code);
370 h265d_dbg(H265D_DBG_SEI, "country_code=%d provider_code=%d terminal_provider_code %d\n",
371 country_code, provider_code, provider_oriented_code);
372 switch (provider_code) {
373 case 0x4: {/* cuva provider_code is 0x4 */
374 vivid_display_info(s, gb, mpp_get_bits_left(gb) >> 3);
375 } break;
376 case 0x3c: {/* smpte2094_40 provider_code is 0x3c*/
377 const RK_U16 smpte2094_40_provider_oriented_code = 0x0001;
378 const RK_U8 smpte2094_40_application_identifier = 0x04;
379 RK_U8 application_identifier;
380
381 READ_BITS(gb, 8, &application_identifier);
382 /* hdr10plus priverder_oriented_code is 0x0001, application_identifier is 0x04 */
383 if (provider_oriented_code == smpte2094_40_provider_oriented_code &&
384 application_identifier == smpte2094_40_application_identifier)
385 hdr10plus_dynamic_data(s, gb, mpp_get_bits_left(gb) >> 3);
386 } break;
387 default:
388 break;
389 }
390
391 return 0;
392
393 __BITREAD_ERR:
394 return MPP_ERR_STREAM;
395 }
396
decode_nal_sei_alternative_transfer(HEVCContext * s,BitReadCtx_t * gb)397 static RK_S32 decode_nal_sei_alternative_transfer(HEVCContext *s, BitReadCtx_t *gb)
398 {
399 HEVCSEIAlternativeTransfer *alternative_transfer = &s->alternative_transfer;
400 RK_S32 val;
401
402 READ_BITS(gb, 8, &val);
403 alternative_transfer->present = 1;
404 alternative_transfer->preferred_transfer_characteristics = val;
405 s->is_hdr = 1;
406 return 0;
407 __BITREAD_ERR:
408 return MPP_ERR_STREAM;
409 }
410
decode_recovery_point(BitReadCtx_t * gb,HEVCContext * s)411 MPP_RET decode_recovery_point(BitReadCtx_t *gb, HEVCContext *s)
412 {
413 RK_S32 val = -1;
414
415 READ_SE(gb, &val);
416 if (val > 32767 || val < -32767) {
417 h265d_dbg(H265D_DBG_SEI, "recovery_poc_cnt %d, is out of range");
418 return MPP_ERR_STREAM;
419 }
420
421 memset(&s->recovery, 0, sizeof(RecoveryPoint));
422 s->recovery.valid_flag = 1;
423 s->recovery.recovery_frame_cnt = val;
424
425 h265d_dbg(H265D_DBG_SEI, "Recovery point: poc_cnt %d", s->recovery.recovery_frame_cnt);
426 return MPP_OK;
427 __BITREAD_ERR:
428 return MPP_ERR_STREAM;
429 }
430
mpp_hevc_decode_nal_sei(HEVCContext * s)431 MPP_RET mpp_hevc_decode_nal_sei(HEVCContext *s)
432 {
433 MPP_RET ret = MPP_OK;
434 BitReadCtx_t *gb = &s->HEVClc->gb;
435
436 RK_S32 payload_type = 0;
437 RK_S32 payload_size = 0;
438 RK_S32 byte = 0xFF;
439 RK_S32 i = 0;
440 BitReadCtx_t payload_bitctx;
441 h265d_dbg(H265D_DBG_SEI, "Decoding SEI\n");
442
443 do {
444 payload_type = 0;
445 payload_size = 0;
446 byte = 0xFF;
447 while (byte == 0xFF) {
448 if (gb->bytes_left_ < 2 || payload_type > INT_MAX - 255) {
449 mpp_err("parse payload_type error: byte_left %d payload_type %d\n",
450 gb->bytes_left_, payload_type);
451 return MPP_ERR_STREAM;
452 }
453
454 READ_BITS(gb, 8, &byte);
455 payload_type += byte;
456 }
457 byte = 0xFF;
458 while (byte == 0xFF) {
459 if ((RK_S32)gb->bytes_left_ < payload_size + 1) {
460 mpp_err("parse payload_size error: byte_left %d payload_size %d\n",
461 gb->bytes_left_, payload_size + 1);
462 return MPP_ERR_STREAM;
463 }
464
465 READ_BITS(gb, 8, &byte);
466 payload_size += byte;
467 }
468
469 if ((RK_S32)gb->bytes_left_ < payload_size) {
470 mpp_err("parse payload_size error: byte_left %d payload_size %d\n",
471 gb->bytes_left_, payload_size);
472 return MPP_ERR_STREAM;
473 }
474
475 memset(&payload_bitctx, 0, sizeof(payload_bitctx));
476 mpp_set_bitread_ctx(&payload_bitctx, s->HEVClc->gb.data_, payload_size);
477 mpp_set_bitread_pseudo_code_type(&payload_bitctx, PSEUDO_CODE_H264_H265_SEI);
478
479 h265d_dbg(H265D_DBG_SEI, "s->nal_unit_type %d payload_type %d payload_size %d\n", s->nal_unit_type, payload_type, payload_size);
480
481 if (s->nal_unit_type == NAL_SEI_PREFIX) {
482 if (payload_type == 256 /*&& s->decode_checksum_sei*/) {
483 ret = decode_nal_sei_decoded_picture_hash(&payload_bitctx);
484 } else if (payload_type == 45) {
485 ret = decode_nal_sei_frame_packing_arrangement(s, &payload_bitctx);
486 } else if (payload_type == 1) {
487 ret = decode_pic_timing(s, &payload_bitctx);
488 h265d_dbg(H265D_DBG_SEI, "Skipped PREFIX SEI %d\n", payload_type);
489 } else if (payload_type == 4) {
490 ret = user_data_registered_itu_t_t35(s, &payload_bitctx, payload_size);
491 } else if (payload_type == 5) {
492 ret = check_encoder_sei_info(&payload_bitctx, payload_size, &s->deny_flag);
493
494 if (s->deny_flag)
495 h265d_dbg(H265D_DBG_SEI, "Bitstream is encoded by special encoder.");
496 } else if (payload_type == 129) {
497 ret = active_parameter_sets(s, &payload_bitctx);
498 h265d_dbg(H265D_DBG_SEI, "Skipped PREFIX SEI %d\n", payload_type);
499 } else if (payload_type == 137) {
500 h265d_dbg(H265D_DBG_SEI, "mastering_display_colour_volume in\n");
501 ret = mastering_display_colour_volume(s, &payload_bitctx);
502 s->is_hdr = 1;
503 } else if (payload_type == 144) {
504 h265d_dbg(H265D_DBG_SEI, "content_light_info in\n");
505 ret = content_light_info(s, &payload_bitctx);
506 } else if (payload_type == 143) {
507 h265d_dbg(H265D_DBG_SEI, "colour_remapping_info in\n");
508 ret = colour_remapping_info(&payload_bitctx);
509 } else if (payload_type == 23) {
510 h265d_dbg(H265D_DBG_SEI, "tone_mapping_info in\n");
511 ret = tone_mapping_info(&payload_bitctx);
512 } else if (payload_type == 6) {
513 h265d_dbg(H265D_DBG_SEI, "recovery point in\n");
514 s->max_ra = INT_MIN;
515 ret = decode_recovery_point(&payload_bitctx, s);
516 } else if (payload_type == 147) {
517 h265d_dbg(H265D_DBG_SEI, "alternative_transfer in\n");
518 ret = decode_nal_sei_alternative_transfer(s, &payload_bitctx);
519 } else {
520 h265d_dbg(H265D_DBG_SEI, "Skipped PREFIX SEI %d\n", payload_type);
521 }
522 } else { /* nal_unit_type == NAL_SEI_SUFFIX */
523 if (payload_type == 132 /* && s->decode_checksum_sei */)
524 ret = decode_nal_sei_decoded_picture_hash(&payload_bitctx);
525 else {
526 h265d_dbg(H265D_DBG_SEI, "Skipped SUFFIX SEI %d\n", payload_type);
527 }
528 }
529
530 for (i = 0; i < payload_size; i++)
531 SKIP_BITS(gb, 8);
532
533 if (ret)
534 return ret;
535 } while (gb->bytes_left_ > 1 && gb->data_[0] != 0x80);
536
537 return ret;
538
539 __BITREAD_ERR:
540 return MPP_ERR_STREAM;
541 }
542