xref: /OK3568_Linux_fs/external/mpp/mpp/codec/dec/h265/h265d_sei.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
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 
user_data_registered_itu_t_t35(HEVCContext * s,BitReadCtx_t * gb,int size)339 static RK_S32 user_data_registered_itu_t_t35(HEVCContext *s, BitReadCtx_t *gb, int size)
340 {
341     RK_S32 country_code, provider_code;
342     RK_U16 terminal_provide_oriented_code;
343 
344     if (size < 3)
345         return 0;
346 
347     READ_BITS(gb, 8, &country_code);
348     if (country_code == 0xFF) {
349         if (size < 1)
350             return 0;
351 
352         SKIP_BITS(gb, 8);
353     }
354 
355     /* usa country_code or china country_code */
356     if (country_code != 0xB5 && country_code != 0x26) {
357         mpp_log("Unsupported User Data Registered ITU-T T35 SEI message (country_code = %d)", country_code);
358         return MPP_ERR_STREAM;
359     }
360 
361     READ_BITS(gb, 16, &provider_code);
362     READ_BITS(gb, 16, &terminal_provide_oriented_code);
363     h265d_dbg(H265D_DBG_SEI, "country_code=%d provider_code=%d terminal_provider_code %d\n",
364               country_code, provider_code, terminal_provide_oriented_code);
365     if (provider_code == 4)
366         vivid_display_info(s, gb, mpp_get_bits_left(gb) >> 3);
367 
368     return 0;
369 
370 __BITREAD_ERR:
371     return  MPP_ERR_STREAM;
372 }
373 
decode_nal_sei_alternative_transfer(HEVCContext * s,BitReadCtx_t * gb)374 static RK_S32 decode_nal_sei_alternative_transfer(HEVCContext *s, BitReadCtx_t *gb)
375 {
376     HEVCSEIAlternativeTransfer *alternative_transfer = &s->alternative_transfer;
377     RK_S32 val;
378 
379     READ_BITS(gb, 8, &val);
380     alternative_transfer->present = 1;
381     alternative_transfer->preferred_transfer_characteristics = val;
382     s->is_hdr = 1;
383     return 0;
384 __BITREAD_ERR:
385     return  MPP_ERR_STREAM;
386 }
387 
decode_recovery_point(BitReadCtx_t * gb,HEVCContext * s)388 MPP_RET decode_recovery_point(BitReadCtx_t *gb, HEVCContext *s)
389 {
390     RK_S32 val = -1;
391 
392     READ_SE(gb, &val);
393     if (val > 32767 || val < -32767) {
394         h265d_dbg(H265D_DBG_SEI, "recovery_poc_cnt %d, is out of range");
395         return MPP_ERR_STREAM;
396     }
397 
398     memset(&s->recovery, 0, sizeof(RecoveryPoint));
399     s->recovery.valid_flag = 1;
400     s->recovery.recovery_frame_cnt = val;
401 
402     h265d_dbg(H265D_DBG_SEI, "Recovery point: poc_cnt %d", s->recovery.recovery_frame_cnt);
403     return MPP_OK;
404 __BITREAD_ERR:
405     return MPP_ERR_STREAM;
406 }
407 
mpp_hevc_decode_nal_sei(HEVCContext * s)408 MPP_RET mpp_hevc_decode_nal_sei(HEVCContext *s)
409 {
410     MPP_RET ret = MPP_OK;
411     BitReadCtx_t *gb = &s->HEVClc->gb;
412 
413     RK_S32 payload_type = 0;
414     RK_S32 payload_size = 0;
415     RK_S32 byte = 0xFF;
416     RK_S32 i = 0;
417     BitReadCtx_t payload_bitctx;
418     h265d_dbg(H265D_DBG_SEI, "Decoding SEI\n");
419 
420     do {
421         payload_type = 0;
422         payload_size = 0;
423         byte = 0xFF;
424         while (byte == 0xFF) {
425             READ_BITS(gb, 8, &byte);
426             payload_type += byte;
427         }
428         byte = 0xFF;
429         while (byte == 0xFF) {
430             READ_BITS(gb, 8, &byte);
431             payload_size += byte;
432         }
433 
434         memset(&payload_bitctx, 0, sizeof(payload_bitctx));
435         mpp_set_bitread_ctx(&payload_bitctx, s->HEVClc->gb.data_, payload_size);
436         mpp_set_bitread_pseudo_code_type(&payload_bitctx, PSEUDO_CODE_H264_H265_SEI);
437 
438         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);
439 
440         if (s->nal_unit_type == NAL_SEI_PREFIX) {
441             if (payload_type == 256 /*&& s->decode_checksum_sei*/) {
442                 ret = decode_nal_sei_decoded_picture_hash(&payload_bitctx);
443             } else if (payload_type == 45) {
444                 ret = decode_nal_sei_frame_packing_arrangement(s, &payload_bitctx);
445             } else if (payload_type == 1) {
446                 ret = decode_pic_timing(s, &payload_bitctx);
447                 h265d_dbg(H265D_DBG_SEI, "Skipped PREFIX SEI %d\n", payload_type);
448             } else if (payload_type == 4) {
449                 ret = user_data_registered_itu_t_t35(s, &payload_bitctx, payload_size);
450             } else if (payload_type == 5) {
451                 ret = check_encoder_sei_info(&payload_bitctx, payload_size, &s->deny_flag);
452 
453                 if (s->deny_flag)
454                     h265d_dbg(H265D_DBG_SEI, "Bitstream is encoded by special encoder.");
455             } else if (payload_type == 129) {
456                 ret = active_parameter_sets(s, &payload_bitctx);
457                 h265d_dbg(H265D_DBG_SEI, "Skipped PREFIX SEI %d\n", payload_type);
458             } else if (payload_type == 137) {
459                 h265d_dbg(H265D_DBG_SEI, "mastering_display_colour_volume in\n");
460                 ret = mastering_display_colour_volume(s, &payload_bitctx);
461                 s->is_hdr = 1;
462             } else if (payload_type == 144) {
463                 h265d_dbg(H265D_DBG_SEI, "content_light_info in\n");
464                 ret = content_light_info(s, &payload_bitctx);
465             } else if (payload_type == 143) {
466                 h265d_dbg(H265D_DBG_SEI, "colour_remapping_info in\n");
467                 ret = colour_remapping_info(&payload_bitctx);
468             } else if (payload_type == 23) {
469                 h265d_dbg(H265D_DBG_SEI, "tone_mapping_info in\n");
470                 ret = tone_mapping_info(&payload_bitctx);
471             } else if (payload_type == 6) {
472                 h265d_dbg(H265D_DBG_SEI, "recovery point in\n");
473                 s->max_ra = INT_MIN;
474                 ret = decode_recovery_point(&payload_bitctx, s);
475             }  else if (payload_type == 147) {
476                 h265d_dbg(H265D_DBG_SEI, "alternative_transfer in\n");
477                 ret = decode_nal_sei_alternative_transfer(s, &payload_bitctx);
478             } else {
479                 h265d_dbg(H265D_DBG_SEI, "Skipped PREFIX SEI %d\n", payload_type);
480             }
481         } else { /* nal_unit_type == NAL_SEI_SUFFIX */
482             if (payload_type == 132 /* && s->decode_checksum_sei */)
483                 ret = decode_nal_sei_decoded_picture_hash(&payload_bitctx);
484             else {
485                 h265d_dbg(H265D_DBG_SEI, "Skipped SUFFIX SEI %d\n", payload_type);
486             }
487         }
488 
489         for (i = 0; i < payload_size; i++)
490             SKIP_BITS(gb, 8);
491 
492         if (ret)
493             return ret;
494     } while (gb->bytes_left_ > 1 &&  gb->data_[0] != 0x80);
495 
496     return ret;
497 
498 __BITREAD_ERR:
499     return  MPP_ERR_STREAM;
500 }
501