From cae878ccd486baf0eddc084e196d3d18c3a5c5eb Mon Sep 17 00:00:00 2001 From: Lakshmi Kumar Date: Fri, 27 Oct 2023 06:11:00 -0700 Subject: [PATCH] sequence callback function (#25) * seq callback function * bug fix * changing some params for callback * review comments * switch case * fixing minor border cases [ROCm/rocdecode commit: 47ede638a3ab0434e907432084d12acbd91862b9] --- projects/rocdecode/src/parser/hevc_parser.cpp | 90 ++++++++++++++++++- projects/rocdecode/src/parser/hevc_parser.h | 3 + .../rocdecode/src/parser/roc_video_parser.h | 2 + 3 files changed, 93 insertions(+), 2 deletions(-) diff --git a/projects/rocdecode/src/parser/hevc_parser.cpp b/projects/rocdecode/src/parser/hevc_parser.cpp index fe3a222112..24f5569ca8 100644 --- a/projects/rocdecode/src/parser/hevc_parser.cpp +++ b/projects/rocdecode/src/parser/hevc_parser.cpp @@ -155,6 +155,90 @@ ParserResult HEVCVideoParser::Init() { return PARSER_OK; } +void HEVCVideoParser::FillSeqCallbackFn(SpsData* sps_data) { + video_format_params_.codec = rocDecVideoCodec_HEVC; + // TODO: Check the two frame_rate - setting default + video_format_params_.frame_rate.numerator = 0; + video_format_params_.frame_rate.denominator = 0; + video_format_params_.bit_depth_luma_minus8 = sps_data->bit_depth_luma_minus8; + video_format_params_.bit_depth_chroma_minus8 = sps_data->bit_depth_chroma_minus8; + if (sps_data->profile_tier_level.general_progressive_source_flag && !sps_data->profile_tier_level.general_interlaced_source_flag) + video_format_params_.progressive_sequence = 1; + else if (!sps_data->profile_tier_level.general_progressive_source_flag && sps_data->profile_tier_level.general_interlaced_source_flag) + video_format_params_.progressive_sequence = 0; + else // default value + video_format_params_.progressive_sequence = 1; + // TODO: Change for different layers, using 0th layer currently + video_format_params_.min_num_decode_surfaces = sps_data->sps_max_dec_pic_buffering_minus1[0] + 1; + video_format_params_.coded_width = sps_data->pic_width_in_luma_samples; + video_format_params_.coded_height = sps_data->pic_height_in_luma_samples; + video_format_params_.chroma_format = static_cast(sps_data->chroma_format_idc); + int sub_width_c, sub_height_c; + switch (video_format_params_.chroma_format) { + case rocDecVideoChromaFormat_Monochrome: { + sub_width_c = 1; + sub_height_c = 1; + break; + } + case rocDecVideoChromaFormat_420: { + sub_width_c = 2; + sub_height_c = 2; + break; + } + case rocDecVideoChromaFormat_422: { + sub_width_c = 2; + sub_height_c = 1; + break; + } + case rocDecVideoChromaFormat_444: { + sub_width_c = 1; + sub_height_c = 1; + break; + } + default: + ERR(STR("Error: Sequence Callback function - Chroma Format is not supported")); + return; + } + if(sps_data->conformance_window_flag) { + video_format_params_.display_area.left = sub_width_c * sps_data->conf_win_left_offset; + video_format_params_.display_area.top = sub_height_c * sps_data->conf_win_top_offset; + video_format_params_.display_area.right = sps_data->pic_width_in_luma_samples - (sub_width_c * sps_data->conf_win_right_offset); + video_format_params_.display_area.bottom = sps_data->pic_height_in_luma_samples - (sub_height_c * sps_data->conf_win_bottom_offset); + } + else { // default values + video_format_params_.display_area.left = 0; + video_format_params_.display_area.top = 0; + video_format_params_.display_area.right = video_format_params_.coded_width; + video_format_params_.display_area.bottom = video_format_params_.coded_height; + } + + // TODO: Check bitrate - setting default + video_format_params_.bitrate = 0; + if (sps_data->vui_parameters_present_flag) { + if (sps_data->vui_parameters.aspect_ratio_info_present_flag) { + video_format_params_.display_aspect_ratio.x = sps_data->vui_parameters.sar_width; + video_format_params_.display_aspect_ratio.y = sps_data->vui_parameters.sar_height; + } + else { // default values + video_format_params_.display_aspect_ratio.x = 0; + video_format_params_.display_aspect_ratio.y = 0; + } + } + if (sps_data->vui_parameters_present_flag) { + video_format_params_.video_signal_description.video_format = sps_data->vui_parameters.video_format; + video_format_params_.video_signal_description.video_full_range_flag = sps_data->vui_parameters.video_full_range_flag; + video_format_params_.video_signal_description.color_primaries = sps_data->vui_parameters.colour_primaries; + video_format_params_.video_signal_description.transfer_characteristics = sps_data->vui_parameters.transfer_characteristics; + video_format_params_.video_signal_description.matrix_coefficients = sps_data->vui_parameters.matrix_coeffs; + video_format_params_.video_signal_description.reserved_zero_bits = 0; + } + // TODO: check seqhdr_data_length + video_format_params_.seqhdr_data_length = 0; + + // callback function with RocdecVideoFormat params filled out + pfn_sequece_cb_ = PFNVIDSEQUENCECALLBACK(&video_format_params_); +} + bool HEVCVideoParser::ParseFrameData(const uint8_t* p_stream, uint32_t frame_data_size) { int ret = PARSER_OK; NalUnitHeader nal_unit_header; @@ -1060,11 +1144,13 @@ bool HEVCVideoParser::ParseSliceHeader(uint32_t nal_unit_type, uint8_t *nalu, si m_active_vps_id_ = sps_ptr->sps_video_parameter_set_id; // Check video dimension change - if ( pic_width_ != sps_ptr->pic_width_in_luma_samples || pic_height_ != sps_ptr->pic_height_in_luma_samples) - { + if ( pic_width_ != sps_ptr->pic_width_in_luma_samples || pic_height_ != sps_ptr->pic_height_in_luma_samples) { pic_width_ = sps_ptr->pic_width_in_luma_samples; pic_height_ = sps_ptr->pic_height_in_luma_samples; pic_dimension_changed_ = true; // Note: clear this flag after the actions with size change are taken. + + // called to fill structure RocdecVideoFormat and callback function if pic_dimensions_changed + FillSeqCallbackFn(sps_ptr); } if (!m_sh_->first_slice_segment_in_pic_flag) { diff --git a/projects/rocdecode/src/parser/hevc_parser.h b/projects/rocdecode/src/parser/hevc_parser.h index 804a9efe26..02e52be1bc 100644 --- a/projects/rocdecode/src/parser/hevc_parser.h +++ b/projects/rocdecode/src/parser/hevc_parser.h @@ -819,4 +819,7 @@ private: * \return Returns pointer to the allocated memory for SliceHeaderData */ SliceHeaderData* AllocSliceHeader(); + + // functions to fill structures for callback functions + void FillSeqCallbackFn(SpsData* sps_data); }; \ No newline at end of file diff --git a/projects/rocdecode/src/parser/roc_video_parser.h b/projects/rocdecode/src/parser/roc_video_parser.h index 0c10d78f0d..8f3dbbcd00 100644 --- a/projects/rocdecode/src/parser/roc_video_parser.h +++ b/projects/rocdecode/src/parser/roc_video_parser.h @@ -55,6 +55,8 @@ protected: uint32_t pic_width_; uint32_t pic_height_; bool pic_dimension_changed_; + + RocdecVideoFormat video_format_params_; }; enum ParserSeekOrigin {