Lines Matching refs:s
184 SplitContext_t *s = NULL; in h265d_split_init() local
185 if (s == NULL) { in h265d_split_init()
186 s = mpp_calloc(SplitContext_t, 1); in h265d_split_init()
187 if (s != NULL) { in h265d_split_init()
188 *sc = s; in h265d_split_init()
194 s->buffer = mpp_malloc(RK_U8, MAX_FRAME_SIZE); in h265d_split_init()
195 s->buffer_size = MAX_FRAME_SIZE; in h265d_split_init()
196 s->fetch_timestamp = 1; in h265d_split_init()
200 static void mpp_fetch_timestamp(SplitContext_t *s, RK_S32 off) in mpp_fetch_timestamp() argument
204 s->dts = s->pts = -1; in mpp_fetch_timestamp()
205 s->offset = 0; in mpp_fetch_timestamp()
208 s->cur_offset, i, s->cur_frame_offset[i], s->frame_offset, s->next_frame_offset); in mpp_fetch_timestamp()
209 if ( s->cur_offset + off >= s->cur_frame_offset[i] in mpp_fetch_timestamp()
210 && (s->frame_offset < s->cur_frame_offset[i] || in mpp_fetch_timestamp()
211 (!s->frame_offset && !s->next_frame_offset)) // first field/frame in mpp_fetch_timestamp()
213 && /*s->next_frame_offset + off <*/ s->cur_frame_end[i]) { in mpp_fetch_timestamp()
214 s->dts = s->cur_frame_dts[i]; in mpp_fetch_timestamp()
215 s->pts = s->cur_frame_pts[i]; in mpp_fetch_timestamp()
216 s->offset = s->next_frame_offset - s->cur_frame_offset[i]; in mpp_fetch_timestamp()
217 if (s->cur_offset + off < s->cur_frame_end[i]) in mpp_fetch_timestamp()
229 SplitContext_t *s = (SplitContext_t*)sc; in h265d_split_frame() local
231 if (s->cur_offset + buf_size != in h265d_split_frame()
232 s->cur_frame_end[s->cur_frame_start_index]) { /* skip remainder packets */ in h265d_split_frame()
234 i = (s->cur_frame_start_index + 1) & (MPP_PARSER_PTS_NB - 1); in h265d_split_frame()
235 s->cur_frame_start_index = i; in h265d_split_frame()
236 s->cur_frame_offset[i] = s->cur_offset; in h265d_split_frame()
237 s->cur_frame_end[i] = s->cur_offset + buf_size; in h265d_split_frame()
238 s->cur_frame_pts[i] = pts; in h265d_split_frame()
239 s->cur_frame_dts[i] = dts; in h265d_split_frame()
241 s->cur_frame_start_index, s->cur_frame_offset[i], s->cur_frame_end[i], pts); in h265d_split_frame()
244 if (s->fetch_timestamp) { in h265d_split_frame()
245 s->fetch_timestamp = 0; in h265d_split_frame()
246 s->last_pts = s->pts; in h265d_split_frame()
247 s->last_dts = s->dts; in h265d_split_frame()
248 mpp_fetch_timestamp(s, 0); in h265d_split_frame()
251 if (s->eos && !buf_size) { in h265d_split_frame()
252 *poutbuf = s->buffer; in h265d_split_frame()
253 *poutbuf_size = s->index; in h265d_split_frame()
257 next = hevc_find_frame_end(s, buf, buf_size); in h265d_split_frame()
258 if (s->eos && buf_size && next == END_NOT_FOUND) { in h265d_split_frame()
262 if (mpp_combine_frame(s, next, &buf, &buf_size) < 0) { in h265d_split_frame()
265 s->cur_offset += buf_size; in h265d_split_frame()
277 s->frame_offset = s->next_frame_offset; in h265d_split_frame()
280 s->next_frame_offset = s->cur_offset + next; in h265d_split_frame()
281 s->fetch_timestamp = 1; in h265d_split_frame()
284 s->cur_offset += next; in h265d_split_frame()
292 SplitContext_t *s = (SplitContext_t*)sc; in h265d_split_reset() local
296 buf = s->buffer; in h265d_split_reset()
297 size = s->buffer_size; in h265d_split_reset()
298 memset(s, 0, sizeof(SplitContext_t)); in h265d_split_reset()
299 s->fetch_timestamp = 1; in h265d_split_reset()
300 s->buffer = buf; in h265d_split_reset()
301 s->buffer_size = size; in h265d_split_reset()
302 s->eos = 0; in h265d_split_reset()
309 SplitContext_t *s = (SplitContext_t *)sc; in h265d_split_deinit() local
310 if (s->buffer) { in h265d_split_deinit()
311 mpp_free(s->buffer); in h265d_split_deinit()
312 s->buffer = NULL; in h265d_split_deinit()
314 if (s) { in h265d_split_deinit()
315 mpp_free(s); in h265d_split_deinit()
316 s = NULL; in h265d_split_deinit()
321 static RK_S32 pred_weight_table(HEVCContext *s, BitReadCtx_t *gb) in pred_weight_table() argument
330 READ_UE(gb, &s->sh.luma_log2_weight_denom); in pred_weight_table()
331 if (s->sps->chroma_format_idc != 0) { in pred_weight_table()
334 s->sh.chroma_log2_weight_denom = mpp_clip(s->sh.luma_log2_weight_denom + delta, 0, 7); in pred_weight_table()
337 for (i = 0; i < s->sh.nb_refs[L0]; i++) { in pred_weight_table()
340 s->sh.luma_weight_l0[i] = 1 << s->sh.luma_log2_weight_denom; in pred_weight_table()
341 s->sh.luma_offset_l0[i] = 0; in pred_weight_table()
345 if (s->sps->chroma_format_idc != 0) { // FIXME: invert "if" and "for" in pred_weight_table()
346 for (i = 0; i < s->sh.nb_refs[L0]; i++) { in pred_weight_table()
350 for (i = 0; i < s->sh.nb_refs[L0]; i++) in pred_weight_table()
354 for (i = 0; i < s->sh.nb_refs[L0]; i++) { in pred_weight_table()
358 s->sh.luma_weight_l0[i] = (1 << s->sh.luma_log2_weight_denom) + delta_luma_weight_l0; in pred_weight_table()
359 READ_SE(gb, &s->sh.luma_offset_l0[i]); in pred_weight_table()
367 … s->sh.chroma_weight_l0[i][j] = (1 << s->sh.chroma_log2_weight_denom) + delta_chroma_weight_l0; in pred_weight_table()
368 …s->sh.chroma_offset_l0[i][j] = mpp_clip((delta_chroma_offset_l0 - ((128 * s->sh.chroma_weight_l0[i… in pred_weight_table()
369 … >> s->sh.chroma_log2_weight_denom) + 128), -128, 127); in pred_weight_table()
372 s->sh.chroma_weight_l0[i][0] = 1 << s->sh.chroma_log2_weight_denom; in pred_weight_table()
373 s->sh.chroma_offset_l0[i][0] = 0; in pred_weight_table()
374 s->sh.chroma_weight_l0[i][1] = 1 << s->sh.chroma_log2_weight_denom; in pred_weight_table()
375 s->sh.chroma_offset_l0[i][1] = 0; in pred_weight_table()
379 if (s->sh.slice_type == B_SLICE) { in pred_weight_table()
380 for (i = 0; i < s->sh.nb_refs[L1]; i++) { in pred_weight_table()
383 s->sh.luma_weight_l1[i] = 1 << s->sh.luma_log2_weight_denom; in pred_weight_table()
384 s->sh.luma_offset_l1[i] = 0; in pred_weight_table()
387 if (s->sps->chroma_format_idc != 0) { in pred_weight_table()
388 for (i = 0; i < s->sh.nb_refs[L1]; i++) in pred_weight_table()
391 for (i = 0; i < s->sh.nb_refs[L1]; i++) in pred_weight_table()
394 for (i = 0; i < s->sh.nb_refs[L1]; i++) { in pred_weight_table()
398 … s->sh.luma_weight_l1[i] = (1 << s->sh.luma_log2_weight_denom) + delta_luma_weight_l1; in pred_weight_table()
399 READ_SE(gb, &s->sh.luma_offset_l1[i]); in pred_weight_table()
407 … s->sh.chroma_weight_l1[i][j] = (1 << s->sh.chroma_log2_weight_denom) + delta_chroma_weight_l1; in pred_weight_table()
408 …s->sh.chroma_offset_l1[i][j] = mpp_clip((delta_chroma_offset_l1 - ((128 * s->sh.chroma_weight_l1[i… in pred_weight_table()
409 … >> s->sh.chroma_log2_weight_denom) + 128), -128, 127); in pred_weight_table()
412 s->sh.chroma_weight_l1[i][0] = 1 << s->sh.chroma_log2_weight_denom; in pred_weight_table()
413 s->sh.chroma_offset_l1[i][0] = 0; in pred_weight_table()
414 s->sh.chroma_weight_l1[i][1] = 1 << s->sh.chroma_log2_weight_denom; in pred_weight_table()
415 s->sh.chroma_offset_l1[i][1] = 0; in pred_weight_table()
424 static RK_S32 decode_lt_rps(HEVCContext *s, LongTermRPS *rps, BitReadCtx_t *gb) in decode_lt_rps() argument
426 const HEVCSPS *sps = s->sps; in decode_lt_rps()
433 s->rps_bit_offset[s->slice_idx] = in decode_lt_rps()
434 s->rps_bit_offset_st[s->slice_idx]; in decode_lt_rps()
475 rps->poc[i] += s->poc - delta * max_poc_lsb - s->sh.pic_order_cnt_lsb; in decode_lt_rps()
480 s->rps_bit_offset[s->slice_idx] in decode_lt_rps()
488 static RK_S32 set_sps(HEVCContext *s, const HEVCSPS *sps) in set_sps() argument
491 MppFrameFormat fmt = s->h265dctx->cfg->base.out_fmt & (~MPP_FRAME_FMT_MASK); in set_sps()
493 s->h265dctx->coded_width = sps->width; in set_sps()
494 s->h265dctx->coded_height = sps->height; in set_sps()
495 s->h265dctx->width = sps->output_width; in set_sps()
496 s->h265dctx->height = sps->output_height; in set_sps()
497 s->h265dctx->pix_fmt = fmt | sps->pix_fmt; in set_sps()
498 s->h265dctx->nBitDepth = sps->bit_depth; in set_sps()
499 s->h265dctx->sample_aspect_ratio = sps->vui.sar; in set_sps()
502 s->h265dctx->color_range = sps->vui.video_full_range_flag ? in set_sps()
505 s->h265dctx->color_range = MPP_FRAME_RANGE_MPEG; in set_sps()
508 s->h265dctx->colorspace = sps->vui.matrix_coeffs; in set_sps()
510 s->h265dctx->colorspace = MPP_FRAME_SPC_UNSPECIFIED; in set_sps()
513 s->sps = sps; in set_sps()
514 s->vps = (HEVCVPS*) s->vps_list[s->sps->vps_id]; in set_sps()
516 if (s->vps->vps_timing_info_present_flag) { in set_sps()
517 num = s->vps->vps_num_units_in_tick; in set_sps()
518 den = s->vps->vps_time_scale; in set_sps()
708 static RK_S32 hls_slice_header(HEVCContext *s) in hls_slice_header() argument
711 BitReadCtx_t *gb = &s->HEVClc->gb; in hls_slice_header()
712 SliceHeader *sh = &s->sh; in hls_slice_header()
725 if ((IS_IDR(s) || IS_BLA(s)) && sh->first_slice_in_pic_flag) { in hls_slice_header()
726 s->seq_decode = (s->seq_decode + 1) & 0xff; in hls_slice_header()
727 s->max_ra = INT_MAX; in hls_slice_header()
728 if (IS_IDR(s)) in hls_slice_header()
729 mpp_hevc_clear_refs(s); in hls_slice_header()
731 if (s->nal_unit_type >= 16 && s->nal_unit_type <= 23) in hls_slice_header()
734 if (IS_IRAP(s) && s->miss_ref_flag && sh->first_slice_in_pic_flag) { in hls_slice_header()
736 s->max_ra = INT_MAX; in hls_slice_header()
737 s->miss_ref_flag = 0; in hls_slice_header()
741 if (pps_id >= MAX_PPS_COUNT || !s->pps_list[pps_id]) { in hls_slice_header()
746 if (pps_id != s->pre_pps_id) { in hls_slice_header()
747 s->ps_need_upate = 1; in hls_slice_header()
748 s->pre_pps_id = pps_id; in hls_slice_header()
753 s->pps != (HEVCPPS*)s->pps_list[sh->pps_id]) { in hls_slice_header()
757 s->pps = (HEVCPPS*)s->pps_list[sh->pps_id]; in hls_slice_header()
759 if (s->sps_need_upate || s->sps != (HEVCSPS*)s->sps_list[s->pps->sps_id]) { in hls_slice_header()
760 s->sps = (HEVCSPS*)s->sps_list[s->pps->sps_id]; in hls_slice_header()
761 mpp_hevc_clear_refs(s); in hls_slice_header()
763 s->ps_need_upate = 1; in hls_slice_header()
764 s->sps_need_upate = 0; in hls_slice_header()
765 ret = set_sps(s, s->sps); in hls_slice_header()
769 s->seq_decode = (s->seq_decode + 1) & 0xff; in hls_slice_header()
770 s->max_ra = INT_MAX; in hls_slice_header()
780 if (s->pps->dependent_slice_segments_enabled_flag) in hls_slice_header()
783 slice_address_length = mpp_ceil_log2(s->sps->ctb_width * in hls_slice_header()
784 s->sps->ctb_height); in hls_slice_header()
788 if (sh->slice_segment_addr >= (RK_U32)(s->sps->ctb_width * s->sps->ctb_height)) { in hls_slice_header()
797 s->slice_idx++; in hls_slice_header()
801 s->slice_idx = 0; in hls_slice_header()
802 s->slice_initialized = 0; in hls_slice_header()
806 s->slice_initialized = 0; in hls_slice_header()
808 for (i = 0; i < s->pps->num_extra_slice_header_bits; i++) in hls_slice_header()
819 if (!s->decoder_id && IS_IRAP(s) && sh->slice_type != I_SLICE) { in hls_slice_header()
824 if (s->pps->output_flag_present_flag) in hls_slice_header()
827 if (s->sps->separate_colour_plane_flag) in hls_slice_header()
830 if (!IS_IDR(s)) { in hls_slice_header()
833 READ_BITS(gb, s->sps->log2_max_poc_lsb, &sh->pic_order_cnt_lsb); in hls_slice_header()
834 poc = mpp_hevc_compute_poc(s, sh->pic_order_cnt_lsb); in hls_slice_header()
835 if (!sh->first_slice_in_pic_flag && poc != s->poc) { in hls_slice_header()
836 mpp_log("Ignoring POC change between slices: %d -> %d\n", s->poc, poc); in hls_slice_header()
838 if (s->h265dctx->err_recognition & AV_EF_EXPLODE) in hls_slice_header()
841 poc = s->poc; in hls_slice_header()
843 s->poc = poc; in hls_slice_header()
851 ret = mpp_hevc_decode_short_term_rps(s, &sh->slice_rps, s->sps, 1); in hls_slice_header()
859 if (!s->sps->nb_st_rps) { in hls_slice_header()
864 numbits = mpp_ceil_log2(s->sps->nb_st_rps); in hls_slice_header()
869 if (sh->short_term_rps != &s->sps->st_rps[rps_idx]) in hls_slice_header()
870 s->rps_need_upate = 1; in hls_slice_header()
871 sh->short_term_rps = &s->sps->st_rps[rps_idx]; in hls_slice_header()
874 s->rps_bit_offset_st[s->slice_idx] = gb->used_bits - bit_begin; in hls_slice_header()
876 sh->short_term_ref_pic_set_size = s->rps_bit_offset_st[s->slice_idx]; in hls_slice_header()
878 ret = decode_lt_rps(s, &sh->long_term_rps, gb); in hls_slice_header()
885 if (s->sps->sps_temporal_mvp_enabled_flag) in hls_slice_header()
890 s->sh.short_term_rps = NULL; in hls_slice_header()
891 s->poc = 0; in hls_slice_header()
895 if (s->temporal_id == 0 && in hls_slice_header()
896 s->nal_unit_type != NAL_TRAIL_N && in hls_slice_header()
897 s->nal_unit_type != NAL_TSA_N && in hls_slice_header()
898 s->nal_unit_type != NAL_STSA_N && in hls_slice_header()
899 s->nal_unit_type != NAL_RADL_N && in hls_slice_header()
900 s->nal_unit_type != NAL_RADL_R && in hls_slice_header()
901 s->nal_unit_type != NAL_RASL_N && in hls_slice_header()
902 s->nal_unit_type != NAL_RASL_R) in hls_slice_header()
903 s->pocTid0 = s->poc; in hls_slice_header()
905 if (s->sps->sao_enabled) { in hls_slice_header()
907 if (s->sps->chroma_format_idc) { in hls_slice_header()
925 sh->nb_refs[L0] = s->pps->num_ref_idx_l0_default_active; in hls_slice_header()
927 sh->nb_refs[L1] = s->pps->num_ref_idx_l1_default_active; in hls_slice_header()
947 nb_refs = mpp_hevc_frame_nb_refs(s); in hls_slice_header()
953 if (s->pps->lists_modification_present_flag && nb_refs > 1) { in hls_slice_header()
971 if (s->pps->cabac_init_present_flag) in hls_slice_header()
995 if ((s->pps->weighted_pred_flag && sh->slice_type == P_SLICE) || in hls_slice_header()
996 (s->pps->weighted_bipred_flag && sh->slice_type == B_SLICE)) { in hls_slice_header()
997 pred_weight_table(s, gb); in hls_slice_header()
1010 if (s->pps->pic_slice_level_chroma_qp_offsets_present_flag) { in hls_slice_header()
1018 if (s->pps->deblocking_filter_control_present_flag) { in hls_slice_header()
1021 if (s->pps->deblocking_filter_override_enabled_flag) in hls_slice_header()
1033 sh->disable_deblocking_filter_flag = s->pps->disable_dbf; in hls_slice_header()
1034 sh->beta_offset = s->pps->beta_offset; in hls_slice_header()
1035 sh->tc_offset = s->pps->tc_offset; in hls_slice_header()
1043 if (s->pps->seq_loop_filter_across_slices_enabled_flag && in hls_slice_header()
1049 …sh->slice_loop_filter_across_slices_enabled_flag = s->pps->seq_loop_filter_across_slices_enabled_f… in hls_slice_header()
1051 } else if (!s->slice_initialized) { in hls_slice_header()
1057 if (s->pps->tiles_enabled_flag || s->pps->entropy_coding_sync_enabled_flag) { in hls_slice_header()
1059 if (s->pps->entropy_coding_sync_enabled_flag) { in hls_slice_header()
1060 … if (sh->num_entry_point_offsets > s->sps->ctb_height || sh->num_entry_point_offsets < 0) { in hls_slice_header()
1063 s->sps->ctb_height); in hls_slice_header()
1067 …if (sh->num_entry_point_offsets > s->sps->ctb_height * s->sps->ctb_width || sh->num_entry_point_of… in hls_slice_header()
1070 s->sps->ctb_height * s->sps->ctb_width); in hls_slice_header()
1082 if (s->pps->slice_header_extension_present_flag) { in hls_slice_header()
1086 s->start_bit = gb->used_bits; in hls_slice_header()
1091 s->end_bit = gb->used_bits; in hls_slice_header()
1095 sh->slice_qp = 26U + s->pps->pic_init_qp_minus26 + sh->slice_qp_delta; in hls_slice_header()
1097 sh->slice_qp < -s->sps->qp_bd_offset) { in hls_slice_header()
1101 -s->sps->qp_bd_offset); in hls_slice_header()
1104 if (s->h265dctx->compare_info != NULL && sh->first_slice_in_pic_flag) { in hls_slice_header()
1105 CurrentFameInf_t *info = (CurrentFameInf_t *)s->h265dctx->compare_info; in hls_slice_header()
1108 if (compare_sliceheader(openhevc_sh, &s->sh) < 0) { in hls_slice_header()
1117 if (!s->sh.slice_ctb_addr_rs && s->sh.dependent_slice_segment_flag) { in hls_slice_header()
1122 s->slice_initialized = 1; in hls_slice_header()
1133 static RK_S32 hls_nal_unit(HEVCContext *s) in hls_nal_unit() argument
1135 BitReadCtx_t*gb = &s->HEVClc->gb; in hls_nal_unit()
1140 READ_BITS(gb, 6, &s->nal_unit_type); in hls_nal_unit()
1142 READ_BITS(gb, 6, &s->nuh_layer_id); in hls_nal_unit()
1144 READ_BITS(gb, 3, &s->temporal_id); in hls_nal_unit()
1146 s->temporal_id = s->temporal_id - 1; in hls_nal_unit()
1150 s->nal_unit_type, s->nuh_layer_id, s->temporal_id); in hls_nal_unit()
1152 if (s->temporal_id < 0) in hls_nal_unit()
1155 return (s->nuh_layer_id); in hls_nal_unit()
1163 HEVCContext *s = (HEVCContext *)h265dctx->priv_data; in mpp_hevc_out_dec_order() local
1165 if (s->ref && (s->ref->flags & HEVC_FRAME_FLAG_OUTPUT)) { in mpp_hevc_out_dec_order()
1166 s->ref->flags &= ~(HEVC_FRAME_FLAG_OUTPUT); in mpp_hevc_out_dec_order()
1167 mpp_buf_slot_set_flag(s->slots, s->ref->slot_index, SLOT_QUEUE_USE); in mpp_hevc_out_dec_order()
1168 mpp_buf_slot_enqueue(s->slots, s->ref->slot_index, QUEUE_DISPLAY); in mpp_hevc_out_dec_order()
1178 HEVCContext *s = (HEVCContext *)h265dctx->priv_data; in mpp_hevc_output_frame() local
1191 for (i = 0; i < MPP_ARRAY_ELEMS(s->DPB); i++) { in mpp_hevc_output_frame()
1192 HEVCFrame *frame = &s->DPB[i]; in mpp_hevc_output_frame()
1194 frame->sequence == s->seq_output) { in mpp_hevc_output_frame()
1204 if (!flush && s->seq_output == s->seq_decode && s->sps && in mpp_hevc_output_frame()
1205 nb_output <= s->sps->temporal_layer[s->sps->max_sub_layers - 1].num_reorder_pics) { in mpp_hevc_output_frame()
1206 if (cfg->base.enable_fast_play && (IS_IDR(s) || in mpp_hevc_output_frame()
1207 (IS_BLA(s) && !s->first_i_fast_play))) { in mpp_hevc_output_frame()
1208 s->first_i_fast_play = 1; in mpp_hevc_output_frame()
1215 HEVCFrame *frame = &s->DPB[min_idx]; in mpp_hevc_output_frame()
1218 s->output_frame_idx = min_idx; in mpp_hevc_output_frame()
1220 mpp_buf_slot_set_flag(s->slots, frame->slot_index, SLOT_QUEUE_USE); in mpp_hevc_output_frame()
1221 mpp_buf_slot_enqueue(s->slots, frame->slot_index, QUEUE_DISPLAY); in mpp_hevc_output_frame()
1228 for (i = 0; i < MPP_ARRAY_ELEMS(s->DPB); i++) { in mpp_hevc_output_frame()
1229 HEVCFrame *frame_next_ready = &s->DPB[i]; in mpp_hevc_output_frame()
1231 frame_next_ready->sequence == s->seq_output) { in mpp_hevc_output_frame()
1234 s->output_frame_idx = i; in mpp_hevc_output_frame()
1237 mpp_buf_slot_set_flag(s->slots, frame->slot_index, SLOT_QUEUE_USE); in mpp_hevc_output_frame()
1238 mpp_buf_slot_enqueue(s->slots, frame->slot_index, QUEUE_DISPLAY); in mpp_hevc_output_frame()
1243 for (i = 0; i < MPP_ARRAY_ELEMS(s->DPB); i++) { in mpp_hevc_output_frame()
1244 mpp_hevc_unref_frame(s, &s->DPB[i], 0); in mpp_hevc_output_frame()
1254 if (s->seq_output != s->seq_decode) in mpp_hevc_output_frame()
1255 s->seq_output = (s->seq_output + 1) & 0xff; in mpp_hevc_output_frame()
1263 static RK_S32 hevc_frame_start(HEVCContext *s) in hevc_frame_start() argument
1267 if (s->ref) { in hevc_frame_start()
1272 s->is_decoded = 0; in hevc_frame_start()
1273 s->first_nal_type = s->nal_unit_type; in hevc_frame_start()
1274 s->miss_ref_flag = 0; in hevc_frame_start()
1276 ret = mpp_hevc_frame_rps(s); in hevc_frame_start()
1282 ret = mpp_hevc_set_new_ref(s, &s->frame, s->poc); in hevc_frame_start()
1286 if (!s->h265dctx->cfg->base.disable_error && s->recovery.valid_flag && in hevc_frame_start()
1287 s->recovery.first_frm_valid && s->recovery.first_frm_ref_missing && in hevc_frame_start()
1288 s->poc < s->recovery.recovery_pic_id && s->poc >= s->recovery.first_frm_id) { in hevc_frame_start()
1289 mpp_frame_set_discard(s->frame, 1); in hevc_frame_start()
1290 … h265d_dbg(H265D_DBG_REF, "mark recovery frame discard, poc %d\n", mpp_frame_get_poc(s->frame)); in hevc_frame_start()
1293 if (!s->h265dctx->cfg->base.disable_error && s->miss_ref_flag) { in hevc_frame_start()
1294 if (!IS_IRAP(s)) { in hevc_frame_start()
1295 … if (s->recovery.valid_flag && s->recovery.first_frm_valid && s->recovery.first_frm_id == s->poc) { in hevc_frame_start()
1296 s->recovery.first_frm_ref_missing = 1; in hevc_frame_start()
1297 mpp_frame_set_discard(s->frame, 1); in hevc_frame_start()
1299 mpp_frame_get_poc(s->frame)); in hevc_frame_start()
1301 mpp_frame_set_errinfo(s->frame, MPP_FRAME_ERR_UNKNOW); in hevc_frame_start()
1302 s->ref->error_flag = 1; in hevc_frame_start()
1303 … h265d_dbg(H265D_DBG_REF, "missing ref mark error, poc %d\n", mpp_frame_get_poc(s->frame)); in hevc_frame_start()
1313 for (i = 0; i < MPP_ARRAY_ELEMS(s->DPB); i++) { in hevc_frame_start()
1314 frame = &s->DPB[i]; in hevc_frame_start()
1315 if (frame->poc == s->poc ) { in hevc_frame_start()
1323 ret = mpp_hevc_output_frame(s->h265dctx, 1); in hevc_frame_start()
1331 mpp_buf_slot_set_prop(s->slots, s->ref->slot_index, SLOT_FRAME, s->ref->frame); in hevc_frame_start()
1336 s->ref = NULL; in hevc_frame_start()
1340 static RK_S32 parser_nal_unit(HEVCContext *s, const RK_U8 *nal, int length) in parser_nal_unit() argument
1343 HEVCLocalContext *lc = s->HEVClc; in parser_nal_unit()
1348 ret = hls_nal_unit(s); in parser_nal_unit()
1351 s->nal_unit_type); in parser_nal_unit()
1353 } else if (ret != (s->decoder_id) && s->nal_unit_type != NAL_VPS) in parser_nal_unit()
1356 if (s->temporal_id > s->temporal_layer_id) in parser_nal_unit()
1359 s->nuh_layer_id = ret; in parser_nal_unit()
1360 h265d_dbg(H265D_DBG_GLOBAL, "s->nal_unit_type = %d,len = %d \n", s->nal_unit_type, length); in parser_nal_unit()
1362 if (s->deny_flag && (s->nal_unit_type != NAL_VPS && s->nal_unit_type != NAL_SPS)) { in parser_nal_unit()
1367 switch (s->nal_unit_type) { in parser_nal_unit()
1369 ret = mpp_hevc_decode_nal_vps(s); in parser_nal_unit()
1370 if (ret < 0 && !s->is_decoded) { in parser_nal_unit()
1376 ret = mpp_hevc_decode_nal_sps(s); in parser_nal_unit()
1377 if (ret < 0 && !s->is_decoded) { in parser_nal_unit()
1382 s->deny_flag = 0; in parser_nal_unit()
1385 if (s->pre_pps_data == NULL) { in parser_nal_unit()
1386 s->pre_pps_data = mpp_calloc(RK_U8, length + 128); in parser_nal_unit()
1387 memcpy(s->pre_pps_data, nal, length); in parser_nal_unit()
1388 s->pps_len = length; in parser_nal_unit()
1389 s->pps_buf_size = length + 128; in parser_nal_unit()
1390 s->ps_need_upate = 1; in parser_nal_unit()
1391 } else if (s->pps_len == length) { in parser_nal_unit()
1392 if (memcmp(s->pre_pps_data, nal, length)) { in parser_nal_unit()
1393 s->ps_need_upate = 1; in parser_nal_unit()
1394 memcpy(s->pre_pps_data, nal, length); in parser_nal_unit()
1397 if (s->pps_buf_size < length) { in parser_nal_unit()
1398 MPP_FREE(s->pre_pps_data); in parser_nal_unit()
1399 s->pre_pps_data = mpp_calloc(RK_U8, length + 128); in parser_nal_unit()
1400 memcpy(s->pre_pps_data, nal, length); in parser_nal_unit()
1401 s->pps_buf_size = length + 128; in parser_nal_unit()
1402 s->pps_len = length; in parser_nal_unit()
1404 s->ps_need_upate = 1; in parser_nal_unit()
1406 ret = mpp_hevc_decode_nal_pps(s); in parser_nal_unit()
1407 if (ret < 0 && !s->is_decoded) { in parser_nal_unit()
1414 ret = mpp_hevc_decode_nal_sei(s); in parser_nal_unit()
1436 if (s->task == NULL) { in parser_nal_unit()
1437 s->extra_has_frame = 1; in parser_nal_unit()
1441 ret = hls_slice_header(s); in parser_nal_unit()
1447 if ((s->first_nal_type != s->nal_unit_type) && (s->first_nal_type != NAL_INIT_VALUE)) in parser_nal_unit()
1453 if (s->recovery.valid_flag) { in parser_nal_unit()
1454 if (!s->recovery.first_frm_valid) { in parser_nal_unit()
1455 s->recovery.first_frm_id = s->poc; in parser_nal_unit()
1456 s->recovery.first_frm_valid = 1; in parser_nal_unit()
1457 … s->recovery.recovery_pic_id = s->recovery.first_frm_id + s->recovery.recovery_frame_cnt; in parser_nal_unit()
1458 … h265d_dbg(H265D_DBG_SEI, "First recovery frame found, poc %d", s->recovery.first_frm_id); in parser_nal_unit()
1460 if (s->recovery.recovery_pic_id < s->poc) in parser_nal_unit()
1461 memset(&s->recovery, 0, sizeof(RecoveryPoint)); in parser_nal_unit()
1465 if (s->max_ra == INT_MAX) { in parser_nal_unit()
1466 if (s->nal_unit_type == NAL_CRA_NUT || IS_BLA(s) || in parser_nal_unit()
1467 (s->recovery.valid_flag && s->recovery.first_frm_valid && in parser_nal_unit()
1468 s->recovery.first_frm_id == s->poc)) { in parser_nal_unit()
1469 s->max_ra = s->poc; in parser_nal_unit()
1471 if (IS_IDR(s)) in parser_nal_unit()
1472 s->max_ra = INT_MIN; in parser_nal_unit()
1476 if ((s->nal_unit_type == NAL_RASL_R || s->nal_unit_type == NAL_RASL_N) && in parser_nal_unit()
1477 s->poc <= s->max_ra) { in parser_nal_unit()
1478 s->is_decoded = 0; in parser_nal_unit()
1480 } else if (!s->h265dctx->cfg->base.disable_error && in parser_nal_unit()
1481 …(s->poc < s->max_ra) && !IS_IRAP(s)) { //when seek to I slice skip the stream small then I slic poc in parser_nal_unit()
1482 s->is_decoded = 0; in parser_nal_unit()
1485 if (s->nal_unit_type == NAL_RASL_R && s->poc > s->max_ra) in parser_nal_unit()
1486 s->max_ra = INT_MIN; in parser_nal_unit()
1489 if (s->sh.first_slice_in_pic_flag) { in parser_nal_unit()
1490 ret = hevc_frame_start(s); in parser_nal_unit()
1495 } else if (!s->ref) { in parser_nal_unit()
1500 if (s->nal_unit_type != s->first_nal_type) { in parser_nal_unit()
1502 s->first_nal_type, s->nal_unit_type); in parser_nal_unit()
1506 if (!s->sh.dependent_slice_segment_flag && in parser_nal_unit()
1507 s->sh.slice_type != I_SLICE) { in parser_nal_unit()
1517 s->is_decoded = 1; in parser_nal_unit()
1522 s->seq_decode = (s->seq_decode + 1) & 0xff; in parser_nal_unit()
1523 s->max_ra = INT_MAX; in parser_nal_unit()
1530 mpp_log("Skipping NAL unit %d\n", s->nal_unit_type); in parser_nal_unit()
1553 RK_S32 mpp_hevc_extract_rbsp(HEVCContext *s, const RK_U8 *src, int length, in mpp_hevc_extract_rbsp() argument
1558 s->skipped_bytes = 0; in mpp_hevc_extract_rbsp()
1615 static RK_S32 split_nal_units(HEVCContext *s, RK_U8 *buf, RK_U32 length) in split_nal_units() argument
1619 s->nb_nals = 0; in split_nal_units()
1624 if (s->is_nalff) { in split_nal_units()
1625 for (i = 0; i < s->nal_length_size; i++) in split_nal_units()
1627 buf += s->nal_length_size; in split_nal_units()
1628 length -= s->nal_length_size; in split_nal_units()
1660 if (s->nb_nals) { in split_nal_units()
1673 if (!s->is_nalff) in split_nal_units()
1679 if (s->nals_allocated < 1) { in split_nal_units()
1680 RK_S32 new_size = s->nals_allocated + 10; in split_nal_units()
1683 s->nals_allocated = new_size; in split_nal_units()
1684 s->nals = tmp; in split_nal_units()
1686 if (s->nals_allocated < s->nb_nals + 1) { in split_nal_units()
1687 int new_size = s->nals_allocated + 10; in split_nal_units()
1695 memcpy((void*)tmp, (void*)s->nals, (new_size - 10)*sizeof(HEVCNAL)); in split_nal_units()
1696 mpp_free(s->nals); in split_nal_units()
1697 s->nals = NULL; in split_nal_units()
1698 s->nals = tmp; in split_nal_units()
1699 memset(s->nals + s->nals_allocated, 0, in split_nal_units()
1700 (new_size - s->nals_allocated) * sizeof(*tmp)); in split_nal_units()
1701 s->nals_allocated = new_size; in split_nal_units()
1703 nal = &s->nals[s->nb_nals]; in split_nal_units()
1705 consumed = mpp_hevc_extract_rbsp(s, buf, extract_length, nal); in split_nal_units()
1712 s->nb_nals++; in split_nal_units()
1714 mpp_set_bitread_ctx(&s->HEVClc->gb, (RK_U8 *)nal->data, nal->size); in split_nal_units()
1715 mpp_set_bitread_pseudo_code_type(&s->HEVClc->gb, PSEUDO_CODE_H264_H265); in split_nal_units()
1716 if (hls_nal_unit(s) < 0) in split_nal_units()
1717 s->nb_nals--; in split_nal_units()
1719 if (s->nal_unit_type < NAL_VPS) { in split_nal_units()
1735 return (s->nb_nals) ? MPP_OK : ret; in split_nal_units()
1738 void mpp_hevc_fill_dynamic_meta(HEVCContext *s, const RK_U8 *data, RK_U32 size, RK_U32 hdr_fmt) in mpp_hevc_fill_dynamic_meta() argument
1740 MppFrameHdrDynamicMeta *hdr_dynamic_meta = s->hdr_dynamic_meta; in mpp_hevc_fill_dynamic_meta()
1773 s->hdr_dynamic_meta = hdr_dynamic_meta; in mpp_hevc_fill_dynamic_meta()
1774 s->hdr_dynamic = 1; in mpp_hevc_fill_dynamic_meta()
1775 s->is_hdr = 1; in mpp_hevc_fill_dynamic_meta()
1778 static RK_S32 check_rpus(HEVCContext *s) in check_rpus() argument
1782 if (s->nb_nals <= 1) in check_rpus()
1785 nal = &s->nals[s->nb_nals - 1]; in check_rpus()
1808 mpp_hevc_fill_dynamic_meta(s, nal->data + 2, gb.bytes_left_ + 4, DLBY); in check_rpus()
1815 static RK_S32 parser_nal_units(HEVCContext *s) in parser_nal_units() argument
1820 check_rpus(s); in parser_nal_units()
1822 for (i = 0; i < s->nb_nals; i++) { in parser_nal_units()
1823 ret = parser_nal_unit(s, s->nals[i].data, s->nals[i].size); in parser_nal_units()
1829 if (s->nal_unit_type < 32) { in parser_nal_units()
1830 switch (s->nal_unit_type) { in parser_nal_units()
1847 if (s->pps && s->pps->slice_header_extension_present_flag) { in parser_nal_units()
1848 … h265d_dxva2_picture_context_t *temp = (h265d_dxva2_picture_context_t *)s->hal_pic_private; in parser_nal_units()
1849 temp->slice_cut_param[slice_cnt].start_bit = s->start_bit; in parser_nal_units()
1850 temp->slice_cut_param[slice_cnt].end_bit = s->end_bit; in parser_nal_units()
1868 static RK_S32 hevc_parser_extradata(HEVCContext *s) in hevc_parser_extradata() argument
1870 H265dContext_t *h265dctx = s->h265dctx; in hevc_parser_extradata()
1888 s->is_nalff = 1; in hevc_parser_extradata()
1889 s->nal_length_size = 1 + (ptr[14 + 7] & 3); in hevc_parser_extradata()
1916 parser_nal_unit(s, ptr, length); in hevc_parser_extradata()
1922 s->is_nalff = 0; in hevc_parser_extradata()
1923 ret = split_nal_units(s, h265dctx->extradata, h265dctx->extradata_size); in hevc_parser_extradata()
1926 ret = parser_nal_units(s); in hevc_parser_extradata()
1938 HEVCContext *s = (HEVCContext *)h265dctx->priv_data; in h265d_prepare() local
1946 s->eos = mpp_packet_get_eos(pkt); in h265d_prepare()
1949 sc->eos = s->eos; in h265d_prepare()
1969 s->extra_has_frame = 0; in h265d_prepare()
1970 s->task = NULL; in h265d_prepare()
1971 hevc_parser_extradata(s); in h265d_prepare()
1972 if (!s->extra_has_frame) { in h265d_prepare()
1979 if (h265dctx->cfg->base.split_parse && !s->is_nalff) { in h265d_prepare()
1991 s->checksum_buf = buf; //check with openhevc in h265d_prepare()
1992 s->checksum_buf_size = split_size; in h265d_prepare()
1994 s->pts = sc->pts; in h265d_prepare()
1995 s->dts = sc->dts; in h265d_prepare()
1996 s->eos = (s->eos && (mpp_packet_get_length(pkt) < 4)) ? 1 : 0; in h265d_prepare()
2002 s->pts = pts; in h265d_prepare()
2003 s->dts = dts; in h265d_prepare()
2005 if (s->eos && !length) { in h265d_prepare()
2013 if (s->nb_frame < 10 && fp != NULL) { in h265d_prepare()
2017 ret = (MPP_RET)split_nal_units(s, buf, length); in h265d_prepare()
2020 if (MPP_OK == h265d_syntax_fill_slice(s->h265dctx, task->input)) { in h265d_prepare()
2022 task->input_packet = s->input_packet; in h265d_prepare()
2033 HEVCContext *s = h265dctx->priv_data; in h265d_get_stream() local
2034 *buf = s->checksum_buf; in h265d_get_stream()
2035 *size = s->checksum_buf_size; in h265d_get_stream()
2052 HEVCContext *s = h265dctx->priv_data; in h265d_parse() local
2055 s->got_frame = 0; in h265d_parse()
2056 s->task = task; in h265d_parse()
2057 s->ref = NULL; in h265d_parse()
2058 ret = parser_nal_units(s); in h265d_parse()
2061 mpp_log("current stream is no right skip it %p\n", s->ref); in h265d_parse()
2067 h265d_dbg(H265D_DBG_GLOBAL, "decode poc = %d", s->poc); in h265d_parse()
2068 if (s->ref) { in h265d_parse()
2072 s->task->syntax.data = s->hal_pic_private; in h265d_parse()
2073 s->task->syntax.number = 1; in h265d_parse()
2074 s->task->valid = 1; in h265d_parse()
2075 s->ps_need_upate = 0; in h265d_parse()
2076 s->rps_need_upate = 0; in h265d_parse()
2078 if (s->eos) { in h265d_parse()
2080 s->task->flags.eos = 1; in h265d_parse()
2082 s->nb_frame++; in h265d_parse()
2083 if (s->is_decoded) { in h265d_parse()
2084 h265d_dbg(H265D_DBG_GLOBAL, "Decoded frame with POC %d.\n", s->poc); in h265d_parse()
2085 s->is_decoded = 0; in h265d_parse()
2094 HEVCContext *s = h265dctx->priv_data; in h265d_deinit() local
2100 mpp_hevc_unref_frame(s, &s->DPB[i], ~0); in h265d_deinit()
2101 mpp_frame_deinit(&s->DPB[i].frame); in h265d_deinit()
2105 if (s->vps_list[i]) in h265d_deinit()
2106 mpp_mem_pool_put_f(s->vps_pool, s->vps_list[i]); in h265d_deinit()
2109 if (s->sps_list[i]) in h265d_deinit()
2110 mpp_mem_pool_put_f(s->sps_pool, s->sps_list[i]); in h265d_deinit()
2113 mpp_hevc_pps_free(s->pps_list[i]); in h265d_deinit()
2115 mpp_free(s->HEVClc); in h265d_deinit()
2117 s->HEVClc = NULL; in h265d_deinit()
2119 for (i = 0; i < s->nals_allocated; i++) in h265d_deinit()
2120 mpp_free(s->nals[i].rbsp_buffer); in h265d_deinit()
2122 if (s->nals) { in h265d_deinit()
2123 mpp_free(s->nals); in h265d_deinit()
2126 MPP_FREE(s->pre_pps_data); in h265d_deinit()
2128 s->nals_allocated = 0; in h265d_deinit()
2130 if (s->hal_pic_private) { in h265d_deinit()
2131 … h265d_dxva2_picture_context_t *ctx_pic = (h265d_dxva2_picture_context_t *)s->hal_pic_private; in h265d_deinit()
2134 mpp_free(s->hal_pic_private); in h265d_deinit()
2136 if (s->input_packet) { in h265d_deinit()
2137 buf = mpp_packet_get_data(s->input_packet); in h265d_deinit()
2139 mpp_packet_deinit(&s->input_packet); in h265d_deinit()
2142 if (s->vps_pool) in h265d_deinit()
2143 mpp_mem_pool_deinit_f(s->vps_pool); in h265d_deinit()
2144 if (s->sps_pool) in h265d_deinit()
2145 mpp_mem_pool_deinit_f(s->sps_pool); in h265d_deinit()
2147 MPP_FREE((s->hdr_dynamic_meta)); in h265d_deinit()
2149 if (s) { in h265d_deinit()
2150 mpp_free(s); in h265d_deinit()
2161 HEVCContext *s = h265dctx->priv_data; in hevc_init_context() local
2164 s->h265dctx = h265dctx; in hevc_init_context()
2166 s->HEVClc = (HEVCLocalContext*)mpp_calloc(HEVCLocalContext, 1); in hevc_init_context()
2167 if (!s->HEVClc) in hevc_init_context()
2170 for (i = 0; i < MPP_ARRAY_ELEMS(s->DPB); i++) { in hevc_init_context()
2171 s->DPB[i].slot_index = 0xff; in hevc_init_context()
2172 s->DPB[i].poc = INT_MAX; in hevc_init_context()
2173 s->DPB[i].error_flag = 0; in hevc_init_context()
2174 mpp_frame_init(&s->DPB[i].frame); in hevc_init_context()
2175 if (!s->DPB[i].frame) in hevc_init_context()
2179 s->max_ra = INT_MAX; in hevc_init_context()
2182 s->temporal_layer_id = 8; in hevc_init_context()
2183 s->context_initialized = 1; in hevc_init_context()
2197 HEVCContext *s = (HEVCContext *)h265dctx->priv_data; in h265d_init() local
2202 if (s == NULL) { in h265d_init()
2203 s = (HEVCContext*)mpp_calloc(HEVCContext, 1); in h265d_init()
2204 if (s == NULL) { in h265d_init()
2208 h265dctx->priv_data = s; in h265d_init()
2211 s->first_nal_type = NAL_INIT_VALUE; in h265d_init()
2228 s->hal_pic_private = mpp_calloc_size(void, sizeof(h265d_dxva2_picture_context_t)); in h265d_init()
2230 if (s->hal_pic_private) { in h265d_init()
2231 … h265d_dxva2_picture_context_t *ctx_pic = (h265d_dxva2_picture_context_t *)s->hal_pic_private; in h265d_init()
2248 s->picture_struct = 0; in h265d_init()
2250 s->slots = parser_cfg->frame_slots; in h265d_init()
2252 s->packet_slots = parser_cfg->packet_slots; in h265d_init()
2255 ret = hevc_parser_extradata(s); in h265d_init()
2268 if (MPP_OK != mpp_packet_init(&s->input_packet, (void*)buf, size)) { in h265d_init()
2271 mpp_buf_slot_setup(s->slots, 25); in h265d_init()
2273 s->h265dctx->hw_info = parser_cfg->hw_info; in h265d_init()
2275 s->pre_pps_id = -1; in h265d_init()
2277 s->vps_pool = mpp_mem_pool_init_f("h264d_vps", sizeof(HEVCVPS)); in h265d_init()
2278 s->sps_pool = mpp_mem_pool_init_f("h265d_sps", sizeof(HEVCSPS)); in h265d_init()
2280 mpp_slots_set_prop(s->slots, SLOTS_WIDTH_ALIGN, rkv_ctu_64_align); in h265d_init()
2300 HEVCContext *s = (HEVCContext *)h265dctx->priv_data; in h265d_reset() local
2305 mpp_hevc_flush_dpb(s); in h265d_reset()
2307 s->max_ra = INT_MAX; in h265d_reset()
2308 s->eos = 0; in h265d_reset()
2309 s->first_i_fast_play = 0; in h265d_reset()
2325 HEVCContext *s = (HEVCContext *)h265dctx->priv_data; in h265d_callback() local
2331 if (s->first_nal_type >= 16 && s->first_nal_type <= 23) { in h265d_callback()
2333 s->max_ra = INT_MAX; in h265d_callback()
2336 mpp_buf_slot_get_prop(s->slots, task_dec->output, SLOT_FRAME_PTR, &frame); in h265d_callback()
2341 for (i = 0; i < MPP_ARRAY_ELEMS(s->DPB); i++) { in h265d_callback()
2342 if (s->DPB[i].slot_index == task_dec->output) { in h265d_callback()
2343 s->DPB[i].error_flag = 1; in h265d_callback()
2345 … i, mpp_frame_get_poc(s->DPB[i].frame), s->DPB[i].slot_index, s->DPB[i].error_flag, in h265d_callback()
2346 … mpp_frame_get_errinfo(s->DPB[i].frame), mpp_frame_get_discard(s->DPB[i].frame)); in h265d_callback()
2352 s->ps_need_upate = 0; in h265d_callback()
2353 s->rps_need_upate = 0; in h265d_callback()