From ce6b940fedad37b63f28e4b25aa98e32730b9198 Mon Sep 17 00:00:00 2001 From: Ram Mohan M Date: Sat, 30 Sep 2023 01:19:52 +0530 Subject: [PATCH] libavcenc: Remove duplicate code and improve readability This commit does not introduce any new functionality w.r.t previous commit. But it fixes few things. They are listed below: 1. Guard Bands in header files are fixed 2. Header files contains function definition comments. These are same as in source file. Maintaining same comment at two locations is unnecessary. These are removed. 3. Improved consistency and code indentation 4. Removed comments that dont align with implementation 5. Grouped headers of a workspace together --- encoder/arm/ih264e_function_selector.c | 41 +- encoder/arm/ih264e_function_selector_a9q.c | 88 +- encoder/arm/ih264e_function_selector_av8.c | 340 +++--- encoder/arm/ih264e_platform_macros.h | 101 +- encoder/arm/ime_platform_macros.h | 2 +- encoder/armv8/ih264e_platform_macros.h | 101 +- encoder/armv8/ime_platform_macros.h | 2 +- encoder/ih264e.h | 113 +- encoder/ih264e_api.c | 267 ++--- encoder/ih264e_bitstream.c | 27 +- encoder/ih264e_bitstream.h | 214 +--- encoder/ih264e_cabac.c | 489 ++++---- encoder/ih264e_cabac.h | 375 +----- encoder/ih264e_cabac_encode.c | 1065 ++++++++---------- encoder/ih264e_cabac_init.c | 162 ++- encoder/ih264e_cabac_structs.h | 169 +-- encoder/ih264e_cavlc.c | 46 +- encoder/ih264e_cavlc.h | 78 +- encoder/ih264e_config.h | 9 +- encoder/ih264e_core_coding.c | 164 +-- encoder/ih264e_core_coding.h | 531 +-------- encoder/ih264e_deblk.c | 80 +- encoder/ih264e_deblk.h | 50 +- encoder/ih264e_defs.h | 217 ++-- encoder/ih264e_encode.c | 53 +- encoder/ih264e_encode_header.c | 79 +- encoder/ih264e_encode_header.h | 239 +--- encoder/ih264e_error.h | 15 +- encoder/ih264e_fmt_conv.c | 262 ++++- encoder/ih264e_fmt_conv.h | 41 +- encoder/ih264e_function_selector_generic.c | 80 +- encoder/ih264e_globals.c | 19 +- encoder/ih264e_globals.h | 147 +-- encoder/ih264e_half_pel.c | 22 +- encoder/ih264e_half_pel.h | 135 +-- encoder/ih264e_intra_modes_eval.c | 69 +- encoder/ih264e_intra_modes_eval.h | 372 +----- encoder/ih264e_master.h | 104 +- encoder/ih264e_mc.c | 167 +-- encoder/ih264e_mc.h | 65 +- encoder/ih264e_me.c | 238 ++-- encoder/ih264e_me.h | 264 +---- encoder/ih264e_modify_frm_rate.c | 34 +- encoder/ih264e_modify_frm_rate.h | 99 +- encoder/ih264e_process.c | 119 +- encoder/ih264e_process.h | 293 +---- encoder/ih264e_rate_control.c | 120 +- encoder/ih264e_rate_control.h | 261 +---- encoder/ih264e_rc_mem_interface.c | 172 +-- encoder/ih264e_rc_mem_interface.h | 148 +-- encoder/ih264e_statistics.h | 18 +- encoder/ih264e_structs.h | 12 +- encoder/ih264e_time_stamp.c | 78 +- encoder/ih264e_time_stamp.h | 353 +----- encoder/ih264e_trace.h | 70 +- encoder/ih264e_utils.c | 446 ++++---- encoder/ih264e_utils.h | 304 +---- encoder/ih264e_version.c | 18 +- encoder/ih264e_version.h | 34 +- encoder/ime.c | 95 +- encoder/ime.h | 139 +-- encoder/ime_defs.h | 20 +- encoder/ime_distortion_metrics.c | 419 ++++--- encoder/ime_distortion_metrics.h | 56 +- encoder/ime_macros.h | 7 +- encoder/ime_statistics.h | 7 +- encoder/ime_structs.h | 66 +- encoder/ime_typedefs.h | 9 +- encoder/irc_cbr_buffer_control.c | 3 +- encoder/irc_datatypes.h | 22 +- encoder/irc_mem_req_and_acq.h | 83 +- encoder/irc_rate_control_api.c | 93 +- encoder/irc_rate_control_api_structs.h | 2 +- encoder/irc_rd_model.c | 2 - encoder/irc_trace_support.h | 55 +- encoder/irc_vbr_str_prms.c | 1 + encoder/iv2.h | 14 +- encoder/ive2.h | 12 +- encoder/svc/irc_svc_rate_control_api.c | 2 +- encoder/svc/isvce_api.c | 1 + encoder/svc/isvce_rate_control.c | 1 - encoder/svc/isvce_rc_mem_interface.c | 1 + encoder/svc/isvce_rc_mem_interface.h | 2 +- encoder/svc/isvce_utils.c | 1 + encoder/x86/ih264e_function_selector.c | 43 +- encoder/x86/ih264e_function_selector_sse42.c | 68 +- encoder/x86/ih264e_function_selector_ssse3.c | 146 +-- encoder/x86/ih264e_half_pel_ssse3.c | 13 +- encoder/x86/ih264e_intra_modes_eval_ssse3.c | 8 +- encoder/x86/ih264e_platform_macros.h | 137 +-- encoder/x86/ime_platform_macros.h | 3 +- 91 files changed, 3497 insertions(+), 7715 deletions(-) diff --git a/encoder/arm/ih264e_function_selector.c b/encoder/arm/ih264e_function_selector.c index 04862000..2b155cac 100644 --- a/encoder/arm/ih264e_function_selector.c +++ b/encoder/arm/ih264e_function_selector.c @@ -27,12 +27,14 @@ * Contains functions to initialize function pointers used in h264 * * @author -* Ittiam +* ittiam * * @par List of Functions: +* - ih264e_init_function_ptr +* - ih264e_default_arch * * @remarks -* None +* none * ******************************************************************************* */ @@ -52,38 +54,46 @@ #include "ih264_typedefs.h" #include "iv2.h" #include "ive2.h" -#include "ih264_defs.h" -#include "ih264_size_defs.h" -#include "ih264e_defs.h" -#include "ih264e_error.h" -#include "ih264e_bitstream.h" -#include "ime_distortion_metrics.h" -#include "ime_defs.h" -#include "ime_structs.h" + +#include "ih264_macros.h" #include "ih264_error.h" +#include "ih264_defs.h" +#include "ih264_mem_fns.h" +#include "ih264_padding.h" #include "ih264_structs.h" +#include "ih264_size_defs.h" #include "ih264_trans_quant_itrans_iquant.h" #include "ih264_inter_pred_filters.h" -#include "ih264_mem_fns.h" -#include "ih264_padding.h" #include "ih264_intra_pred_filters.h" #include "ih264_deblk_edge_filters.h" #include "ih264_cabac_tables.h" -#include "ih264_macros.h" #include "ih264_platform_macros.h" + +#include "ime_defs.h" +#include "ime_distortion_metrics.h" +#include "ime_structs.h" + #include "irc_cntrl_param.h" #include "irc_frame_info_collector.h" + +#include "ih264e_error.h" +#include "ih264e_defs.h" #include "ih264e_rate_control.h" +#include "ih264e_bitstream.h" #include "ih264e_cabac_structs.h" #include "ih264e_structs.h" #include "ih264e_cabac.h" #include "ih264e_platform_macros.h" + +/*****************************************************************************/ +/* Function Definitions */ +/*****************************************************************************/ + /** ******************************************************************************* * -* @brief Initialize the intra/inter/transform/deblk function pointers of -* codec context +* @brief Initialize the intra/inter/transform/deblk/entropy function pointers * * @par Description: the current routine initializes the function pointers of * codec context basing on the architecture in use @@ -100,6 +110,7 @@ void ih264e_init_function_ptr(void *pv_codec) { codec_t *ps_codec = (codec_t *)pv_codec; + ih264e_init_function_ptr_generic(ps_codec); switch(ps_codec->s_cfg.e_arch) { diff --git a/encoder/arm/ih264e_function_selector_a9q.c b/encoder/arm/ih264e_function_selector_a9q.c index 30d77951..18063508 100644 --- a/encoder/arm/ih264e_function_selector_a9q.c +++ b/encoder/arm/ih264e_function_selector_a9q.c @@ -20,19 +20,19 @@ /** ******************************************************************************* * @file -* ih264e_function_selector_generic.c +* ih264e_function_selector_a9q.c * * @brief * Contains functions to initialize function pointers of codec context * * @author -* Ittiam +* ittiam * * @par List of Functions: -* - ih264e_init_function_ptr_generic +* - ih264e_init_function_ptr_neon_a9q * * @remarks -* None +* none * ******************************************************************************* */ @@ -42,52 +42,59 @@ /* File Includes */ /*****************************************************************************/ -/* System Include files */ +/* System Include Files */ #include #include #include #include -/* User Include files */ +/* User Include Files */ #include "ih264_typedefs.h" #include "iv2.h" #include "ive2.h" -#include "ih264_defs.h" -#include "ih264_size_defs.h" -#include "ih264e_defs.h" -#include "ih264e_error.h" -#include "ih264e_bitstream.h" -#include "ime_distortion_metrics.h" -#include "ime_defs.h" -#include "ime_structs.h" + #include "ih264_error.h" +#include "ih264_defs.h" +#include "ih264_mem_fns.h" +#include "ih264_padding.h" #include "ih264_structs.h" #include "ih264_trans_quant_itrans_iquant.h" #include "ih264_inter_pred_filters.h" -#include "ih264_mem_fns.h" -#include "ih264_padding.h" #include "ih264_intra_pred_filters.h" #include "ih264_deblk_edge_filters.h" +#include "ih264_cavlc_tables.h" #include "ih264_cabac_tables.h" + +#include "ime_defs.h" +#include "ime_distortion_metrics.h" +#include "ime_structs.h" + #include "irc_cntrl_param.h" #include "irc_frame_info_collector.h" + +#include "ih264e_error.h" +#include "ih264e_defs.h" #include "ih264e_rate_control.h" +#include "ih264e_bitstream.h" #include "ih264e_cabac_structs.h" #include "ih264e_structs.h" -#include "ih264e_platform_macros.h" -#include "ih264e_cabac.h" +#include "ih264e_half_pel.h" +#include "ih264e_intra_modes_eval.h" #include "ih264e_core_coding.h" -#include "ih264_cavlc_tables.h" #include "ih264e_cavlc.h" -#include "ih264e_intra_modes_eval.h" +#include "ih264e_cabac.h" #include "ih264e_fmt_conv.h" -#include "ih264e_half_pel.h" +#include "ih264e_platform_macros.h" + + +/*****************************************************************************/ +/* Function Definitions */ +/*****************************************************************************/ /** ******************************************************************************* * -* @brief Initialize the intra/inter/transform/deblk function pointers of -* codec context +* @brief Initialize the intra/inter/transform/deblk/entropy function pointers * * @par Description: the current routine initializes the function pointers of * codec context basing on the architecture in use @@ -104,9 +111,6 @@ void ih264e_init_function_ptr_neon_a9q(codec_t *ps_codec) { WORD32 i= 0; - /* curr proc ctxt */ - process_ctxt_t *ps_proc = NULL; - me_ctxt_t *ps_me_ctxt = NULL; /* Init function pointers for intra pred leaf level functions luma * Intra 16x16 */ @@ -146,21 +150,21 @@ void ih264e_init_function_ptr_neon_a9q(codec_t *ps_codec) ps_codec->apf_intra_pred_c[3] = ih264_intra_pred_chroma_8x8_mode_plane_a9q; /* Init forward transform fn ptr */ - ps_codec->pf_resi_trans_quant_8x8 = ih264_resi_trans_quant_8x8; - ps_codec->pf_resi_trans_quant_4x4 = ih264_resi_trans_quant_4x4_a9; - ps_codec->pf_resi_trans_quant_chroma_4x4 = ih264_resi_trans_quant_chroma_4x4_a9; - ps_codec->pf_hadamard_quant_4x4 = ih264_hadamard_quant_4x4_a9; - ps_codec->pf_hadamard_quant_2x2_uv = ih264_hadamard_quant_2x2_uv_a9; + ps_codec->pf_resi_trans_quant_8x8 = ih264_resi_trans_quant_8x8; + ps_codec->pf_resi_trans_quant_4x4 = ih264_resi_trans_quant_4x4_a9; + ps_codec->pf_resi_trans_quant_chroma_4x4 = ih264_resi_trans_quant_chroma_4x4_a9; + ps_codec->pf_hadamard_quant_4x4 = ih264_hadamard_quant_4x4_a9; + ps_codec->pf_hadamard_quant_2x2_uv = ih264_hadamard_quant_2x2_uv_a9; /* Init inverse transform fn ptr */ - ps_codec->pf_iquant_itrans_recon_8x8 = ih264_iquant_itrans_recon_8x8; - ps_codec->pf_iquant_itrans_recon_4x4 = ih264_iquant_itrans_recon_4x4_a9; - ps_codec->pf_iquant_itrans_recon_4x4_dc = ih264_iquant_itrans_recon_4x4_dc_a9; - ps_codec->pf_iquant_itrans_recon_chroma_4x4 = ih264_iquant_itrans_recon_chroma_4x4_a9; - ps_codec->pf_iquant_itrans_recon_chroma_4x4_dc = ih264_iquant_itrans_recon_chroma_4x4_dc_a9; - ps_codec->pf_ihadamard_scaling_4x4 = ih264_ihadamard_scaling_4x4_a9; - ps_codec->pf_ihadamard_scaling_2x2_uv = ih264_ihadamard_scaling_2x2_uv_a9; - ps_codec->pf_interleave_copy = ih264_interleave_copy_a9; + ps_codec->pf_iquant_itrans_recon_8x8 = ih264_iquant_itrans_recon_8x8; + ps_codec->pf_iquant_itrans_recon_4x4 = ih264_iquant_itrans_recon_4x4_a9; + ps_codec->pf_iquant_itrans_recon_4x4_dc = ih264_iquant_itrans_recon_4x4_dc_a9; + ps_codec->pf_iquant_itrans_recon_chroma_4x4 = ih264_iquant_itrans_recon_chroma_4x4_a9; + ps_codec->pf_iquant_itrans_recon_chroma_4x4_dc = ih264_iquant_itrans_recon_chroma_4x4_dc_a9; + ps_codec->pf_ihadamard_scaling_4x4 = ih264_ihadamard_scaling_4x4_a9; + ps_codec->pf_ihadamard_scaling_2x2_uv = ih264_ihadamard_scaling_2x2_uv_a9; + ps_codec->pf_interleave_copy = ih264_interleave_copy_a9; /* Init fn ptr luma core coding */ ps_codec->luma_energy_compaction[0] = ih264e_code_luma_intra_macroblock_16x16; @@ -218,8 +222,9 @@ void ih264e_init_function_ptr_neon_a9q(codec_t *ps_codec) /* sad me level functions */ for (i = 0; i < (MAX_PROCESS_CTXT); i++) { - ps_proc = &ps_codec->as_process[i]; - ps_me_ctxt = &ps_proc->s_me_ctxt; + process_ctxt_t *ps_proc = &ps_codec->as_process[i]; + me_ctxt_t *ps_me_ctxt = &ps_proc->s_me_ctxt; + ps_me_ctxt->pf_ime_compute_sad_16x16[0] = ime_compute_sad_16x16_a9q; ps_me_ctxt->pf_ime_compute_sad_16x16[1] = ime_compute_sad_16x16_fast_a9q; ps_me_ctxt->pf_ime_compute_sad_16x8 = ime_compute_sad_16x8_a9q; @@ -242,6 +247,5 @@ void ih264e_init_function_ptr_neon_a9q(codec_t *ps_codec) /* Halp pel generation function - encoder level */ ps_codec->pf_ih264e_sixtapfilter_horz = ih264e_sixtapfilter_horz_a9q; ps_codec->pf_ih264e_sixtap_filter_2dvh_vert = ih264e_sixtap_filter_2dvh_vert_a9q; - } diff --git a/encoder/arm/ih264e_function_selector_av8.c b/encoder/arm/ih264e_function_selector_av8.c index 1679af32..5ecd982e 100644 --- a/encoder/arm/ih264e_function_selector_av8.c +++ b/encoder/arm/ih264e_function_selector_av8.c @@ -20,79 +20,80 @@ /** ******************************************************************************* * @file -* ih264e_function_selector_generic.c +* ih264e_function_selector_av8.c * * @brief * Contains functions to initialize function pointers of codec context * * @author -* Ittiam +* ittiam * * @par List of Functions: -* - ih264e_init_function_ptr_generic +* - ih264e_init_function_ptr_neon_av8 * * @remarks -* None +* none * ******************************************************************************* */ - -/*****************************************************************************/ -/* File Includes */ -/*****************************************************************************/ - /*****************************************************************************/ /* File Includes */ /*****************************************************************************/ -/* System Include files */ +/* System Include Files */ #include #include #include #include -/* User Include files */ +/* User Include Files */ #include "ih264_typedefs.h" #include "iv2.h" #include "ive2.h" -#include "ih264_defs.h" -#include "ih264_size_defs.h" -#include "ih264e_defs.h" -#include "ih264e_error.h" -#include "ih264e_bitstream.h" -#include "ime_distortion_metrics.h" -#include "ime_defs.h" -#include "ime_structs.h" + #include "ih264_error.h" +#include "ih264_defs.h" +#include "ih264_mem_fns.h" +#include "ih264_padding.h" #include "ih264_structs.h" #include "ih264_trans_quant_itrans_iquant.h" #include "ih264_inter_pred_filters.h" -#include "ih264_mem_fns.h" -#include "ih264_padding.h" #include "ih264_intra_pred_filters.h" #include "ih264_deblk_edge_filters.h" +#include "ih264_cavlc_tables.h" #include "ih264_cabac_tables.h" + +#include "ime_defs.h" +#include "ime_distortion_metrics.h" +#include "ime_structs.h" + #include "irc_cntrl_param.h" #include "irc_frame_info_collector.h" + +#include "ih264e_error.h" +#include "ih264e_defs.h" #include "ih264e_rate_control.h" +#include "ih264e_bitstream.h" #include "ih264e_cabac_structs.h" #include "ih264e_structs.h" -#include "ih264e_platform_macros.h" -#include "ih264e_cabac.h" +#include "ih264e_half_pel.h" +#include "ih264e_intra_modes_eval.h" #include "ih264e_core_coding.h" -#include "ih264_cavlc_tables.h" #include "ih264e_cavlc.h" -#include "ih264e_intra_modes_eval.h" +#include "ih264e_cabac.h" #include "ih264e_fmt_conv.h" -#include "ih264e_half_pel.h" +#include "ih264e_platform_macros.h" +/*****************************************************************************/ +/* Function Definitions */ +/*****************************************************************************/ + /** ******************************************************************************* * -* @brief Initialize the intra/inter/transform/deblk function pointers of -* codec context +* @brief Initialize the intra/inter/transform/deblk/entropy function pointers * * @par Description: the current routine initializes the function pointers of * codec context basing on the architecture in use @@ -108,151 +109,146 @@ */ void ih264e_init_function_ptr_neon_av8(codec_t *ps_codec) { - WORD32 i= 0; - /* curr proc ctxt */ - process_ctxt_t *ps_proc = NULL; - me_ctxt_t *ps_me_ctxt = NULL; - - /* Init function pointers for intra pred leaf level functions luma - * Intra 16x16 */ - ps_codec->apf_intra_pred_16_l[0] = ih264_intra_pred_luma_16x16_mode_vert_av8; - ps_codec->apf_intra_pred_16_l[1] = ih264_intra_pred_luma_16x16_mode_horz_av8; - ps_codec->apf_intra_pred_16_l[2] = ih264_intra_pred_luma_16x16_mode_dc_av8; - ps_codec->apf_intra_pred_16_l[3] = ih264_intra_pred_luma_16x16_mode_plane_av8; - - /* Init function pointers for intra pred leaf level functions luma - * Intra 4x4 */ - ps_codec->apf_intra_pred_4_l[0] = ih264_intra_pred_luma_4x4_mode_vert_av8; - ps_codec->apf_intra_pred_4_l[1] = ih264_intra_pred_luma_4x4_mode_horz_av8; - ps_codec->apf_intra_pred_4_l[2] = ih264_intra_pred_luma_4x4_mode_dc_av8; - ps_codec->apf_intra_pred_4_l[3] = ih264_intra_pred_luma_4x4_mode_diag_dl_av8; - ps_codec->apf_intra_pred_4_l[4] = ih264_intra_pred_luma_4x4_mode_diag_dr_av8; - ps_codec->apf_intra_pred_4_l[5] = ih264_intra_pred_luma_4x4_mode_vert_r_av8; - ps_codec->apf_intra_pred_4_l[6] = ih264_intra_pred_luma_4x4_mode_horz_d_av8; - ps_codec->apf_intra_pred_4_l[7] = ih264_intra_pred_luma_4x4_mode_vert_l_av8; - ps_codec->apf_intra_pred_4_l[8] = ih264_intra_pred_luma_4x4_mode_horz_u_av8; - - /* Init function pointers for intra pred leaf level functions luma - * Intra 8x8 */ - ps_codec->apf_intra_pred_8_l[0] = ih264_intra_pred_luma_8x8_mode_vert_av8; - ps_codec->apf_intra_pred_8_l[2] = ih264_intra_pred_luma_8x8_mode_dc_av8; - ps_codec->apf_intra_pred_8_l[3] = ih264_intra_pred_luma_8x8_mode_diag_dl_av8; - ps_codec->apf_intra_pred_8_l[4] = ih264_intra_pred_luma_8x8_mode_diag_dr_av8; - ps_codec->apf_intra_pred_8_l[5] = ih264_intra_pred_luma_8x8_mode_vert_r_av8; - ps_codec->apf_intra_pred_8_l[6] = ih264_intra_pred_luma_8x8_mode_horz_d_av8; - ps_codec->apf_intra_pred_8_l[7] = ih264_intra_pred_luma_8x8_mode_vert_l_av8; - ps_codec->apf_intra_pred_8_l[8] = ih264_intra_pred_luma_8x8_mode_horz_u_av8; - - /* Init function pointers for intra pred leaf level functions chroma - * Intra 8x8 */ - ps_codec->apf_intra_pred_c[0] = ih264_intra_pred_chroma_8x8_mode_dc_av8; - ps_codec->apf_intra_pred_c[1] = ih264_intra_pred_chroma_8x8_mode_horz_av8; - ps_codec->apf_intra_pred_c[2] = ih264_intra_pred_chroma_8x8_mode_vert_av8; - ps_codec->apf_intra_pred_c[3] = ih264_intra_pred_chroma_8x8_mode_plane_av8; - - - /* Init forward transform fn ptr */ - ps_codec->pf_resi_trans_quant_8x8 = ih264_resi_trans_quant_8x8; - ps_codec->pf_resi_trans_quant_4x4 = ih264_resi_trans_quant_4x4_av8; - ps_codec->pf_resi_trans_quant_chroma_4x4 = ih264_resi_trans_quant_chroma_4x4_av8; - ps_codec->pf_hadamard_quant_4x4 = ih264_hadamard_quant_4x4_av8; - ps_codec->pf_hadamard_quant_2x2_uv = ih264_hadamard_quant_2x2_uv_av8; - - /* Init inverse transform fn ptr */ - ps_codec->pf_iquant_itrans_recon_8x8 = ih264_iquant_itrans_recon_8x8_av8; - ps_codec->pf_iquant_itrans_recon_4x4 = ih264_iquant_itrans_recon_4x4_av8; - ps_codec->pf_iquant_itrans_recon_4x4_dc = ih264_iquant_itrans_recon_4x4_dc_av8; - ps_codec->pf_iquant_itrans_recon_chroma_4x4 = ih264_iquant_itrans_recon_chroma_4x4_av8; - ps_codec->pf_iquant_itrans_recon_chroma_4x4_dc = ih264_iquant_itrans_recon_chroma_4x4_dc_av8; - ps_codec->pf_ihadamard_scaling_4x4 = ih264_ihadamard_scaling_4x4_av8; - ps_codec->pf_ihadamard_scaling_2x2_uv = ih264_ihadamard_scaling_2x2_uv_av8; - ps_codec->pf_interleave_copy = ih264_interleave_copy_av8; - - /* Init fn ptr luma core coding */ - ps_codec->luma_energy_compaction[0] = ih264e_code_luma_intra_macroblock_16x16; - ps_codec->luma_energy_compaction[1] = ih264e_code_luma_intra_macroblock_4x4; - ps_codec->luma_energy_compaction[3] = ih264e_code_luma_inter_macroblock_16x16; - - /* Init fn ptr chroma core coding */ - ps_codec->chroma_energy_compaction[0] = ih264e_code_chroma_intra_macroblock_8x8; - ps_codec->chroma_energy_compaction[1] = ih264e_code_chroma_inter_macroblock_8x8; - - /* Init fn ptr luma deblocking */ - ps_codec->pf_deblk_luma_vert_bs4 = ih264_deblk_luma_vert_bs4_av8; - ps_codec->pf_deblk_luma_vert_bslt4 = ih264_deblk_luma_vert_bslt4_av8; - ps_codec->pf_deblk_luma_horz_bs4 = ih264_deblk_luma_horz_bs4_av8; - ps_codec->pf_deblk_luma_horz_bslt4 = ih264_deblk_luma_horz_bslt4_av8; - - /* Init fn ptr chroma deblocking */ - ps_codec->pf_deblk_chroma_vert_bs4 = ih264_deblk_chroma_vert_bs4_av8; - ps_codec->pf_deblk_chroma_vert_bslt4 = ih264_deblk_chroma_vert_bslt4_av8; - ps_codec->pf_deblk_chroma_horz_bs4 = ih264_deblk_chroma_horz_bs4_av8; - ps_codec->pf_deblk_chroma_horz_bslt4 = ih264_deblk_chroma_horz_bslt4_av8; - - /* write mb syntax layer */ - /* write mb syntax layer */ - ps_codec->pf_write_mb_syntax_layer[CAVLC][ISLICE] = ih264e_write_islice_mb_cavlc; - ps_codec->pf_write_mb_syntax_layer[CAVLC][PSLICE] = ih264e_write_pslice_mb_cavlc; - ps_codec->pf_write_mb_syntax_layer[CAVLC][BSLICE] = ih264e_write_bslice_mb_cavlc; - ps_codec->pf_write_mb_syntax_layer[CABAC][ISLICE] = ih264e_write_islice_mb_cabac; - ps_codec->pf_write_mb_syntax_layer[CABAC][PSLICE] = ih264e_write_pslice_mb_cabac; - - /* Padding Functions */ - ps_codec->pf_pad_top = ih264_pad_top_av8; - ps_codec->pf_pad_bottom = ih264_pad_bottom; - ps_codec->pf_pad_left_luma = ih264_pad_left_luma_av8; - ps_codec->pf_pad_left_chroma = ih264_pad_left_chroma_av8; - ps_codec->pf_pad_right_luma = ih264_pad_right_luma_av8; - ps_codec->pf_pad_right_chroma = ih264_pad_right_chroma_av8; - - /* Inter pred leaf level functions */ - ps_codec->pf_inter_pred_luma_copy = ih264_inter_pred_luma_copy_av8; - ps_codec->pf_inter_pred_luma_horz = ih264_inter_pred_luma_horz_av8; - ps_codec->pf_inter_pred_luma_vert = ih264_inter_pred_luma_vert_av8; - ps_codec->pf_inter_pred_luma_bilinear = ih264_inter_pred_luma_bilinear; - ps_codec->pf_inter_pred_chroma = ih264_inter_pred_chroma_av8; - - /* sad me level functions */ - ps_codec->apf_compute_sad_16x16[0] = ime_compute_sad_16x16_av8; - ps_codec->apf_compute_sad_16x16[1] = ime_compute_sad_16x16_fast_av8; - ps_codec->pf_compute_sad_16x8 = ime_compute_sad_16x8_av8; - - /* memor handling operations */ - ps_codec->pf_mem_cpy = ih264_memcpy_av8; - ps_codec->pf_mem_cpy_mul8 = ih264_memcpy_mul_8_av8; - ps_codec->pf_mem_set = ih264_memset_av8; - ps_codec->pf_mem_set_mul8 = ih264_memset_mul_8_av8; - - /* sad me level functions */ - for(i = 0; i < (MAX_PROCESS_CTXT); i++) - { - ps_proc = &ps_codec->as_process[i]; - ps_me_ctxt = &ps_proc->s_me_ctxt; - ps_me_ctxt->pf_ime_compute_sad_16x16[0] = ime_compute_sad_16x16_av8; - ps_me_ctxt->pf_ime_compute_sad_16x16[1] = ime_compute_sad_16x16_fast_av8; - ps_me_ctxt->pf_ime_compute_sad_16x8 = ime_compute_sad_16x8_av8; - ps_me_ctxt->pf_ime_compute_sad4_diamond = ime_calculate_sad4_prog_av8; - ps_me_ctxt->pf_ime_compute_sad3_diamond = ime_calculate_sad3_prog_av8; - ps_me_ctxt->pf_ime_compute_sad2_diamond = ime_calculate_sad2_prog_av8; - ps_me_ctxt->pf_ime_sub_pel_compute_sad_16x16 = ime_sub_pel_compute_sad_16x16_av8; - ps_me_ctxt->pf_ime_compute_sad_stat_luma_16x16 = ime_compute_satqd_16x16_lumainter_av8; - } - - /* intra mode eval -encoder level function */ - ps_codec->pf_ih264e_evaluate_intra16x16_modes = ih264e_evaluate_intra16x16_modes_av8; - ps_codec->pf_ih264e_evaluate_intra_chroma_modes = ih264e_evaluate_intra_chroma_modes_av8; - ps_codec->pf_ih264e_evaluate_intra_4x4_modes = ih264e_evaluate_intra_4x4_modes; - - /* csc */ - ps_codec->pf_ih264e_conv_420p_to_420sp = ih264e_fmt_conv_420p_to_420sp; - ps_codec->pf_ih264e_fmt_conv_422i_to_420sp = ih264e_fmt_conv_422i_to_420sp; - - /* Halp pel generation function - encoder level*/ - ps_codec->pf_ih264e_sixtapfilter_horz = ih264e_sixtapfilter_horz_av8; - ps_codec->pf_ih264e_sixtap_filter_2dvh_vert = ih264e_sixtap_filter_2dvh_vert_av8; - - return ; + /* Init function pointers for intra pred leaf level functions luma + * Intra 16x16 */ + ps_codec->apf_intra_pred_16_l[0] = ih264_intra_pred_luma_16x16_mode_vert_av8; + ps_codec->apf_intra_pred_16_l[1] = ih264_intra_pred_luma_16x16_mode_horz_av8; + ps_codec->apf_intra_pred_16_l[2] = ih264_intra_pred_luma_16x16_mode_dc_av8; + ps_codec->apf_intra_pred_16_l[3] = ih264_intra_pred_luma_16x16_mode_plane_av8; + + /* Init function pointers for intra pred leaf level functions luma + * Intra 4x4 */ + ps_codec->apf_intra_pred_4_l[0] = ih264_intra_pred_luma_4x4_mode_vert_av8; + ps_codec->apf_intra_pred_4_l[1] = ih264_intra_pred_luma_4x4_mode_horz_av8; + ps_codec->apf_intra_pred_4_l[2] = ih264_intra_pred_luma_4x4_mode_dc_av8; + ps_codec->apf_intra_pred_4_l[3] = ih264_intra_pred_luma_4x4_mode_diag_dl_av8; + ps_codec->apf_intra_pred_4_l[4] = ih264_intra_pred_luma_4x4_mode_diag_dr_av8; + ps_codec->apf_intra_pred_4_l[5] = ih264_intra_pred_luma_4x4_mode_vert_r_av8; + ps_codec->apf_intra_pred_4_l[6] = ih264_intra_pred_luma_4x4_mode_horz_d_av8; + ps_codec->apf_intra_pred_4_l[7] = ih264_intra_pred_luma_4x4_mode_vert_l_av8; + ps_codec->apf_intra_pred_4_l[8] = ih264_intra_pred_luma_4x4_mode_horz_u_av8; + + /* Init function pointers for intra pred leaf level functions luma + * Intra 8x8 */ + ps_codec->apf_intra_pred_8_l[0] = ih264_intra_pred_luma_8x8_mode_vert_av8; + ps_codec->apf_intra_pred_8_l[2] = ih264_intra_pred_luma_8x8_mode_dc_av8; + ps_codec->apf_intra_pred_8_l[3] = ih264_intra_pred_luma_8x8_mode_diag_dl_av8; + ps_codec->apf_intra_pred_8_l[4] = ih264_intra_pred_luma_8x8_mode_diag_dr_av8; + ps_codec->apf_intra_pred_8_l[5] = ih264_intra_pred_luma_8x8_mode_vert_r_av8; + ps_codec->apf_intra_pred_8_l[6] = ih264_intra_pred_luma_8x8_mode_horz_d_av8; + ps_codec->apf_intra_pred_8_l[7] = ih264_intra_pred_luma_8x8_mode_vert_l_av8; + ps_codec->apf_intra_pred_8_l[8] = ih264_intra_pred_luma_8x8_mode_horz_u_av8; + + /* Init function pointers for intra pred leaf level functions chroma + * Intra 8x8 */ + ps_codec->apf_intra_pred_c[0] = ih264_intra_pred_chroma_8x8_mode_dc_av8; + ps_codec->apf_intra_pred_c[1] = ih264_intra_pred_chroma_8x8_mode_horz_av8; + ps_codec->apf_intra_pred_c[2] = ih264_intra_pred_chroma_8x8_mode_vert_av8; + ps_codec->apf_intra_pred_c[3] = ih264_intra_pred_chroma_8x8_mode_plane_av8; + + /* Init forward transform fn ptr */ + ps_codec->pf_resi_trans_quant_8x8 = ih264_resi_trans_quant_8x8; + ps_codec->pf_resi_trans_quant_4x4 = ih264_resi_trans_quant_4x4_av8; + ps_codec->pf_resi_trans_quant_chroma_4x4 = ih264_resi_trans_quant_chroma_4x4_av8; + ps_codec->pf_hadamard_quant_4x4 = ih264_hadamard_quant_4x4_av8; + ps_codec->pf_hadamard_quant_2x2_uv = ih264_hadamard_quant_2x2_uv_av8; + + /* Init inverse transform fn ptr */ + ps_codec->pf_iquant_itrans_recon_8x8 = ih264_iquant_itrans_recon_8x8_av8; + ps_codec->pf_iquant_itrans_recon_4x4 = ih264_iquant_itrans_recon_4x4_av8; + ps_codec->pf_iquant_itrans_recon_4x4_dc = ih264_iquant_itrans_recon_4x4_dc_av8; + ps_codec->pf_iquant_itrans_recon_chroma_4x4 = ih264_iquant_itrans_recon_chroma_4x4_av8; + ps_codec->pf_iquant_itrans_recon_chroma_4x4_dc = ih264_iquant_itrans_recon_chroma_4x4_dc_av8; + ps_codec->pf_ihadamard_scaling_4x4 = ih264_ihadamard_scaling_4x4_av8; + ps_codec->pf_ihadamard_scaling_2x2_uv = ih264_ihadamard_scaling_2x2_uv_av8; + ps_codec->pf_interleave_copy = ih264_interleave_copy_av8; + + /* Init fn ptr luma core coding */ + ps_codec->luma_energy_compaction[0] = ih264e_code_luma_intra_macroblock_16x16; + ps_codec->luma_energy_compaction[1] = ih264e_code_luma_intra_macroblock_4x4; + ps_codec->luma_energy_compaction[3] = ih264e_code_luma_inter_macroblock_16x16; + + /* Init fn ptr chroma core coding */ + ps_codec->chroma_energy_compaction[0] = ih264e_code_chroma_intra_macroblock_8x8; + ps_codec->chroma_energy_compaction[1] = ih264e_code_chroma_inter_macroblock_8x8; + + /* Init fn ptr luma deblocking */ + ps_codec->pf_deblk_luma_vert_bs4 = ih264_deblk_luma_vert_bs4_av8; + ps_codec->pf_deblk_luma_vert_bslt4 = ih264_deblk_luma_vert_bslt4_av8; + ps_codec->pf_deblk_luma_horz_bs4 = ih264_deblk_luma_horz_bs4_av8; + ps_codec->pf_deblk_luma_horz_bslt4 = ih264_deblk_luma_horz_bslt4_av8; + + /* Init fn ptr chroma deblocking */ + ps_codec->pf_deblk_chroma_vert_bs4 = ih264_deblk_chroma_vert_bs4_av8; + ps_codec->pf_deblk_chroma_vert_bslt4 = ih264_deblk_chroma_vert_bslt4_av8; + ps_codec->pf_deblk_chroma_horz_bs4 = ih264_deblk_chroma_horz_bs4_av8; + ps_codec->pf_deblk_chroma_horz_bslt4 = ih264_deblk_chroma_horz_bslt4_av8; + + /* write mb syntax layer */ + /* write mb syntax layer */ + ps_codec->pf_write_mb_syntax_layer[CAVLC][ISLICE] = ih264e_write_islice_mb_cavlc; + ps_codec->pf_write_mb_syntax_layer[CAVLC][PSLICE] = ih264e_write_pslice_mb_cavlc; + ps_codec->pf_write_mb_syntax_layer[CAVLC][BSLICE] = ih264e_write_bslice_mb_cavlc; + ps_codec->pf_write_mb_syntax_layer[CABAC][ISLICE] = ih264e_write_islice_mb_cabac; + ps_codec->pf_write_mb_syntax_layer[CABAC][PSLICE] = ih264e_write_pslice_mb_cabac; + + /* Padding Functions */ + ps_codec->pf_pad_top = ih264_pad_top_av8; + ps_codec->pf_pad_bottom = ih264_pad_bottom; + ps_codec->pf_pad_left_luma = ih264_pad_left_luma_av8; + ps_codec->pf_pad_left_chroma = ih264_pad_left_chroma_av8; + ps_codec->pf_pad_right_luma = ih264_pad_right_luma_av8; + ps_codec->pf_pad_right_chroma = ih264_pad_right_chroma_av8; + + /* Inter pred leaf level functions */ + ps_codec->pf_inter_pred_luma_copy = ih264_inter_pred_luma_copy_av8; + ps_codec->pf_inter_pred_luma_horz = ih264_inter_pred_luma_horz_av8; + ps_codec->pf_inter_pred_luma_vert = ih264_inter_pred_luma_vert_av8; + ps_codec->pf_inter_pred_luma_bilinear = ih264_inter_pred_luma_bilinear; + ps_codec->pf_inter_pred_chroma = ih264_inter_pred_chroma_av8; + + /* sad me level functions */ + ps_codec->apf_compute_sad_16x16[0] = ime_compute_sad_16x16_av8; + ps_codec->apf_compute_sad_16x16[1] = ime_compute_sad_16x16_fast_av8; + ps_codec->pf_compute_sad_16x8 = ime_compute_sad_16x8_av8; + + /* memor handling operations */ + ps_codec->pf_mem_cpy = ih264_memcpy_av8; + ps_codec->pf_mem_cpy_mul8 = ih264_memcpy_mul_8_av8; + ps_codec->pf_mem_set = ih264_memset_av8; + ps_codec->pf_mem_set_mul8 = ih264_memset_mul_8_av8; + + /* sad me level functions */ + for(i = 0; i < (MAX_PROCESS_CTXT); i++) + { + process_ctxt_t *ps_proc = &ps_codec->as_process[i]; + me_ctxt_t *ps_me_ctxt = &ps_proc->s_me_ctxt; + + ps_me_ctxt->pf_ime_compute_sad_16x16[0] = ime_compute_sad_16x16_av8; + ps_me_ctxt->pf_ime_compute_sad_16x16[1] = ime_compute_sad_16x16_fast_av8; + ps_me_ctxt->pf_ime_compute_sad_16x8 = ime_compute_sad_16x8_av8; + ps_me_ctxt->pf_ime_compute_sad4_diamond = ime_calculate_sad4_prog_av8; + ps_me_ctxt->pf_ime_compute_sad3_diamond = ime_calculate_sad3_prog_av8; + ps_me_ctxt->pf_ime_compute_sad2_diamond = ime_calculate_sad2_prog_av8; + ps_me_ctxt->pf_ime_sub_pel_compute_sad_16x16 = ime_sub_pel_compute_sad_16x16_av8; + ps_me_ctxt->pf_ime_compute_sad_stat_luma_16x16 = ime_compute_satqd_16x16_lumainter_av8; } + /* intra mode eval -encoder level function */ + ps_codec->pf_ih264e_evaluate_intra16x16_modes = ih264e_evaluate_intra16x16_modes_av8; + ps_codec->pf_ih264e_evaluate_intra_chroma_modes = ih264e_evaluate_intra_chroma_modes_av8; + ps_codec->pf_ih264e_evaluate_intra_4x4_modes = ih264e_evaluate_intra_4x4_modes; + + /* csc */ + ps_codec->pf_ih264e_conv_420p_to_420sp = ih264e_fmt_conv_420p_to_420sp; + ps_codec->pf_ih264e_fmt_conv_422i_to_420sp = ih264e_fmt_conv_422i_to_420sp; + + /* Halp pel generation function - encoder level*/ + ps_codec->pf_ih264e_sixtapfilter_horz = ih264e_sixtapfilter_horz_av8; + ps_codec->pf_ih264e_sixtap_filter_2dvh_vert = ih264e_sixtap_filter_2dvh_vert_av8; + + return ; +} + diff --git a/encoder/arm/ih264e_platform_macros.h b/encoder/arm/ih264e_platform_macros.h index 39cac962..7fdba26c 100644 --- a/encoder/arm/ih264e_platform_macros.h +++ b/encoder/arm/ih264e_platform_macros.h @@ -34,110 +34,17 @@ ******************************************************************************* */ -#ifndef IH264E_PLATFORM_MACROS_H_ -#define IH264E_PLATFORM_MACROS_H_ +#ifndef _IH264E_PLATFORM_MACROS_H_ +#define _IH264E_PLATFORM_MACROS_H_ /*****************************************************************************/ -/* Extern Function Declarations */ +/* Function Declarations */ /*****************************************************************************/ -/** -******************************************************************************* -* -* @brief Initialize the intra/inter/transform/deblk function pointers of -* codec context -* -* @par Description: the current routine initializes the function pointers of -* codec context basing on the architecture in use -* -* @param[in] ps_codec -* Codec context pointer -* -* @returns none -* -* @remarks none -* -******************************************************************************* -*/ void ih264e_init_function_ptr_neon_a9q(codec_t *ps_codec); - -/** -******************************************************************************* -* -* @brief Initialize the intra/inter/transform/deblk function pointers of -* codec context -* -* @par Description: the current routine initializes the function pointers of -* codec context basing on the architecture in use -* -* @param[in] ps_codec -* Codec context pointer -* -* @returns none -* -* @remarks none -* -******************************************************************************* -*/ void ih264e_init_function_ptr_neon_av8(codec_t *ps_codec); - -/** -******************************************************************************* -* -* @brief Initialize the intra/inter/transform/deblk function pointers of -* codec context -* -* @par Description: the current routine initializes the function pointers of -* codec context basing on the architecture in use -* -* @param[in] ps_codec -* Codec context pointer -* -* @returns none -* -* @remarks none -* -******************************************************************************* -*/ void ih264e_init_function_ptr_generic(codec_t *ps_codec); - -/** -******************************************************************************* -* -* @brief Initialize the intra/inter/transform/deblk function pointers of -* codec context -* -* @par Description: the current routine initializes the function pointers of -* codec context basing on the architecture in use -* -* @param[in] ps_codec -* Codec context pointer -* -* @returns none -* -* @remarks none -* -******************************************************************************* -*/ void ih264e_init_function_ptr(void *pv_codec); - -/** -******************************************************************************* -* -* @brief Determine the architecture of the encoder executing environment -* -* @par Description: This routine returns the architecture of the enviro- -* ment in which the current encoder is being tested -* -* @param[in] void -* -* @returns IV_ARCH_T -* architecture -* -* @remarks none -* -******************************************************************************* -*/ IV_ARCH_T ih264e_default_arch(void); -#endif /* IH264E_PLATFORM_MACROS_H_ */ +#endif /* _IH264E_PLATFORM_MACROS_H_ */ diff --git a/encoder/arm/ime_platform_macros.h b/encoder/arm/ime_platform_macros.h index 0f5b2f22..fc3b1a3b 100644 --- a/encoder/arm/ime_platform_macros.h +++ b/encoder/arm/ime_platform_macros.h @@ -48,4 +48,4 @@ ABS(src[3]-est[3]) -#endif /* _IH264_PLATFORM_MACROS_H_ */ +#endif /* _IME_PLATFORM_MACROS_H_ */ diff --git a/encoder/armv8/ih264e_platform_macros.h b/encoder/armv8/ih264e_platform_macros.h index 39cac962..7fdba26c 100644 --- a/encoder/armv8/ih264e_platform_macros.h +++ b/encoder/armv8/ih264e_platform_macros.h @@ -34,110 +34,17 @@ ******************************************************************************* */ -#ifndef IH264E_PLATFORM_MACROS_H_ -#define IH264E_PLATFORM_MACROS_H_ +#ifndef _IH264E_PLATFORM_MACROS_H_ +#define _IH264E_PLATFORM_MACROS_H_ /*****************************************************************************/ -/* Extern Function Declarations */ +/* Function Declarations */ /*****************************************************************************/ -/** -******************************************************************************* -* -* @brief Initialize the intra/inter/transform/deblk function pointers of -* codec context -* -* @par Description: the current routine initializes the function pointers of -* codec context basing on the architecture in use -* -* @param[in] ps_codec -* Codec context pointer -* -* @returns none -* -* @remarks none -* -******************************************************************************* -*/ void ih264e_init_function_ptr_neon_a9q(codec_t *ps_codec); - -/** -******************************************************************************* -* -* @brief Initialize the intra/inter/transform/deblk function pointers of -* codec context -* -* @par Description: the current routine initializes the function pointers of -* codec context basing on the architecture in use -* -* @param[in] ps_codec -* Codec context pointer -* -* @returns none -* -* @remarks none -* -******************************************************************************* -*/ void ih264e_init_function_ptr_neon_av8(codec_t *ps_codec); - -/** -******************************************************************************* -* -* @brief Initialize the intra/inter/transform/deblk function pointers of -* codec context -* -* @par Description: the current routine initializes the function pointers of -* codec context basing on the architecture in use -* -* @param[in] ps_codec -* Codec context pointer -* -* @returns none -* -* @remarks none -* -******************************************************************************* -*/ void ih264e_init_function_ptr_generic(codec_t *ps_codec); - -/** -******************************************************************************* -* -* @brief Initialize the intra/inter/transform/deblk function pointers of -* codec context -* -* @par Description: the current routine initializes the function pointers of -* codec context basing on the architecture in use -* -* @param[in] ps_codec -* Codec context pointer -* -* @returns none -* -* @remarks none -* -******************************************************************************* -*/ void ih264e_init_function_ptr(void *pv_codec); - -/** -******************************************************************************* -* -* @brief Determine the architecture of the encoder executing environment -* -* @par Description: This routine returns the architecture of the enviro- -* ment in which the current encoder is being tested -* -* @param[in] void -* -* @returns IV_ARCH_T -* architecture -* -* @remarks none -* -******************************************************************************* -*/ IV_ARCH_T ih264e_default_arch(void); -#endif /* IH264E_PLATFORM_MACROS_H_ */ +#endif /* _IH264E_PLATFORM_MACROS_H_ */ diff --git a/encoder/armv8/ime_platform_macros.h b/encoder/armv8/ime_platform_macros.h index 0f5b2f22..fc3b1a3b 100644 --- a/encoder/armv8/ime_platform_macros.h +++ b/encoder/armv8/ime_platform_macros.h @@ -48,4 +48,4 @@ ABS(src[3]-est[3]) -#endif /* _IH264_PLATFORM_MACROS_H_ */ +#endif /* _IME_PLATFORM_MACROS_H_ */ diff --git a/encoder/ih264e.h b/encoder/ih264e.h index bf874ebf..65f23b0f 100644 --- a/encoder/ih264e.h +++ b/encoder/ih264e.h @@ -17,25 +17,23 @@ ***************************************************************************** * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore */ -/*****************************************************************************/ -/* */ -/* File Name : ih264e.h */ -/* */ -/* Description : This file contains all the necessary structure and */ -/* enumeration definitions needed for the Application */ -/* Program Interface(API) of the Ittiam MPEG4 */ -/* Encoder on Cortex A8 - Neon platform */ -/* */ -/* List of Functions : ih264e_api_function */ -/* */ -/* Issues / Problems : None */ -/* */ -/* Revision History : */ -/* */ -/* DD MM YYYY Author(s) Changes (Describe the changes made) */ -/* 26 08 2010 100239(RCY) Draft */ -/* */ -/*****************************************************************************/ + +/** +****************************************************************************** +* @file +* ih264e.h +* +* @brief +* This file contains all the necessary structure and enumeration definitions +* needed for the Application Program Interface(API) of the Ittiam H264 Encoder +* +* @author +* ittiam +* +* @remarks +* none +****************************************************************************** +*/ #ifndef _IH264E_H_ #define _IH264E_H_ @@ -46,10 +44,17 @@ extern "C" { #include "iv2.h" #include "ive2.h" + +/*****************************************************************************/ +/* Constant Macros */ +/*****************************************************************************/ + + /*****************************************************************************/ -/* API Function Prototype */ +/* Function Declarations */ /*****************************************************************************/ -IV_STATUS_T ih264e_api_function(iv_obj_t *ps_handle, void *pv_api_ip,void *pv_api_op); +IV_STATUS_T ih264e_api_function(iv_obj_t *ps_handle, void *pv_api_ip, + void *pv_api_op); /*****************************************************************************/ /* Enums */ @@ -59,6 +64,14 @@ typedef enum IH264E_CMD_CTL_SET_ME_INFO_ENABLE, }IH264E_CMD_CTL_SUB_CMDS; +/* NOTE: Ensure this enum values are not greater than 8 bits as this is being + * assigned to WORD8 */ +typedef enum +{ + INTRA16x16 = 0, + INTRA4x4, + INTER16x16, +}IV_MB_TYPE_T; /*****************************************************************************/ /* Extended Structures */ @@ -67,31 +80,24 @@ typedef enum /*****************************************************************************/ /* Get Number of Memory Records */ /*****************************************************************************/ - - typedef struct { iv_num_mem_rec_ip_t s_ive_ip; }ih264e_num_mem_rec_ip_t; - typedef struct { iv_num_mem_rec_op_t s_ive_op; }ih264e_num_mem_rec_op_t; - /*****************************************************************************/ /* Fill Memory Records */ /*****************************************************************************/ - - typedef struct { iv_fill_mem_rec_ip_t s_ive_ip; }ih264e_fill_mem_rec_ip_t; - typedef struct { iv_fill_mem_rec_op_t s_ive_op; @@ -100,36 +106,29 @@ typedef struct /*****************************************************************************/ /* Retrieve Memory Records */ /*****************************************************************************/ - - typedef struct { iv_retrieve_mem_rec_ip_t s_ive_ip; }ih264e_retrieve_mem_rec_ip_t; - typedef struct { iv_retrieve_mem_rec_op_t s_ive_op; }ih264e_retrieve_mem_rec_op_t; - /*****************************************************************************/ /* Initialize encoder */ /*****************************************************************************/ - typedef struct { ive_init_ip_t s_ive_ip; }ih264e_init_ip_t; - typedef struct { ive_init_op_t s_ive_op; }ih264e_init_op_t; - /*****************************************************************************/ /* Queue Input raw buffer - Send the YUV buffer to be encoded */ /*****************************************************************************/ @@ -156,7 +155,6 @@ typedef struct ive_dequeue_inp_op_t s_ive_op; }ih264e_dequeue_inp_op_t; - /*****************************************************************************/ /* Queue Output bitstream buffer - Send the bistream buffer to be filled */ /*****************************************************************************/ @@ -183,7 +181,6 @@ typedef struct ive_dequeue_out_op_t s_ive_op; }ih264e_dequeue_out_op_t; - /*****************************************************************************/ /* Get Recon data - Get the reconstructed data from encoder */ /*****************************************************************************/ @@ -196,17 +193,15 @@ typedef struct { ive_get_recon_op_t s_ive_op; }ih264e_get_recon_op_t; + /*****************************************************************************/ /* Video control Flush */ /*****************************************************************************/ - - typedef struct { ive_ctl_flush_ip_t s_ive_ip; }ih264e_ctl_flush_ip_t; - typedef struct { ive_ctl_flush_op_t s_ive_op; @@ -215,68 +210,50 @@ typedef struct /*****************************************************************************/ /* Video control reset */ /*****************************************************************************/ - - typedef struct { ive_ctl_reset_ip_t s_ive_ip; }ih264e_ctl_reset_ip_t; - typedef struct { ive_ctl_reset_op_t s_ive_op; }ih264e_ctl_reset_op_t; - /*****************************************************************************/ /* Video control:Get Buf Info */ /*****************************************************************************/ - - typedef struct { ive_ctl_getbufinfo_ip_t s_ive_ip; }ih264e_ctl_getbufinfo_ip_t; - - typedef struct { ive_ctl_getbufinfo_op_t s_ive_op; }ih264e_ctl_getbufinfo_op_t; - - /*****************************************************************************/ /* Video control:Get Version Info */ /*****************************************************************************/ - - typedef struct { ive_ctl_getversioninfo_ip_t s_ive_ip; }ih264e_ctl_getversioninfo_ip_t; - - typedef struct { ive_ctl_getversioninfo_op_t s_ive_op; }ih264e_ctl_getversioninfo_op_t; /*****************************************************************************/ -/* Video control:Set default params */ +/* Video control:Set default params */ /*****************************************************************************/ - - typedef struct { ive_ctl_setdefault_ip_t s_ive_ip; }ih264e_ctl_setdefault_ip_t; - - typedef struct { ive_ctl_setdefault_op_t s_ive_op; @@ -315,12 +292,12 @@ typedef struct { ive_ctl_set_frame_rate_ip_t s_ive_ip; }ih264e_ctl_set_frame_rate_ip_t; + typedef struct { ive_ctl_set_frame_rate_op_t s_ive_op; }ih264e_ctl_set_frame_rate_op_t; - /*****************************************************************************/ /* Video control Set Bitrate */ /*****************************************************************************/ @@ -334,7 +311,6 @@ typedef struct ive_ctl_set_bitrate_op_t s_ive_op; }ih264e_ctl_set_bitrate_op_t; - /*****************************************************************************/ /* Video control Set Frame type */ /*****************************************************************************/ @@ -478,7 +454,6 @@ typedef struct ive_video_encode_op_t s_ive_op; }ih264e_video_encode_op_t; - /*****************************************************************************/ /* Video usability information */ /*****************************************************************************/ @@ -910,14 +885,6 @@ typedef struct } ih264e_ctl_set_sei_sii_params_op_t; -/* The enum values should not have greater than 8 bits as this is assigned to WORD8 */ -typedef enum -{ - INTRA16x16 = 0, - INTRA4x4, - INTER16x16 -}IV_MB_TYPE_T; - /*****************************************************************************/ /* Pic info structures */ /*****************************************************************************/ @@ -1024,11 +991,10 @@ typedef struct WORD8 ai1_intra_mode[16]; }; - - }ih264e_mb_info4_t; -/* Add any new structures to the following union. It is used to calculate the max size needed for allocation of memory */ +/* Add any new structures to the following union. It is used to calculate the + * max size needed for allocation of memory */ typedef struct { union @@ -1042,5 +1008,6 @@ typedef struct #ifdef __cplusplus } /* closing brace for extern "C" */ + #endif #endif /* _IH264E_H_ */ diff --git a/encoder/ih264e_api.c b/encoder/ih264e_api.c index 010004c5..edabe644 100644 --- a/encoder/ih264e_api.c +++ b/encoder/ih264e_api.c @@ -30,36 +30,36 @@ * ittiam * * @par List of Functions: -* - api_check_struct_sanity() -* - ih264e_codec_update_config() -* - ih264e_set_default_params() -* - ih264e_init() -* - ih264e_get_num_rec() -* - ih264e_fill_num_mem_rec() -* - ih264e_init_mem_rec() -* - ih264e_retrieve_memrec() -* - ih264e_set_flush_mode() -* - ih264e_get_buf_info() -* - ih264e_set_dimensions() -* - ih264e_set_frame_rate() -* - ih264e_set_bit_rate() -* - ih264e_set_frame_type() -* - ih264e_set_qp() -* - ih264e_set_enc_mode() -* - ih264e_set_vbv_params() -* - ih264_set_air_params() -* - ih264_set_me_params() -* - ih264_set_ipe_params() -* - ih264_set_gop_params() -* - ih264_set_profile_params() -* - ih264_set_deblock_params() -* - ih264e_set_num_cores() -* - ih264e_reset() -* - ih264e_ctl() -* - ih264e_api_function() +* - api_check_struct_sanity +* - ih264e_codec_update_config +* - ih264e_set_default_params +* - ih264e_init +* - ih264e_get_num_rec +* - ih264e_fill_num_mem_rec +* - ih264e_init_mem_rec +* - ih264e_retrieve_memrec +* - ih264e_set_flush_mode +* - ih264e_get_buf_info +* - ih264e_set_dimensions +* - ih264e_set_frame_rate +* - ih264e_set_bit_rate +* - ih264e_set_frame_type +* - ih264e_set_qp +* - ih264e_set_enc_mode +* - ih264e_set_vbv_params +* - ih264_set_air_params +* - ih264_set_me_params +* - ih264_set_ipe_params +* - ih264_set_gop_params +* - ih264_set_profile_params +* - ih264_set_deblock_params +* - ih264e_set_num_cores +* - ih264e_reset +* - ih264e_ctl +* - ih264e_api_function * * @remarks -* None +* none * ******************************************************************************* */ @@ -78,60 +78,57 @@ /* User Include Files */ #include "ih264e_config.h" #include "ih264_typedefs.h" -#include "ih264_size_defs.h" #include "iv2.h" #include "ive2.h" -#include "ih264e.h" #include "ithread.h" + #include "ih264_debug.h" -#include "ih264_defs.h" +#include "ih264_macros.h" #include "ih264_error.h" +#include "ih264_defs.h" +#include "ih264_mem_fns.h" +#include "ih264_padding.h" #include "ih264_structs.h" +#include "ih264_size_defs.h" #include "ih264_trans_quant_itrans_iquant.h" #include "ih264_inter_pred_filters.h" -#include "ih264_mem_fns.h" -#include "ih264_padding.h" #include "ih264_intra_pred_filters.h" #include "ih264_deblk_edge_filters.h" +#include "ih264_common_tables.h" +#include "ih264_cavlc_tables.h" #include "ih264_cabac_tables.h" -#include "ih264_macros.h" -#include "ih264e_defs.h" -#include "ih264e_globals.h" #include "ih264_buf_mgr.h" +#include "ih264_list.h" +#include "ih264_dpb_mgr.h" +#include "ih264_platform_macros.h" + +#include "ime_defs.h" +#include "ime_distortion_metrics.h" +#include "ime_structs.h" + #include "irc_mem_req_and_acq.h" #include "irc_cntrl_param.h" #include "irc_frame_info_collector.h" #include "irc_rate_control_api.h" + +#include "ih264e.h" +#include "ih264e_error.h" +#include "ih264e_version.h" +#include "ih264e_defs.h" +#include "ih264e_globals.h" #include "ih264e_time_stamp.h" #include "ih264e_modify_frm_rate.h" #include "ih264e_rate_control.h" -#include "ih264e_error.h" +#include "ih264e_rc_mem_interface.h" #include "ih264e_bitstream.h" -#include "ime_defs.h" -#include "ime_distortion_metrics.h" -#include "ime_structs.h" #include "ih264e_cabac_structs.h" #include "ih264e_structs.h" #include "ih264e_utils.h" #include "ih264e_core_coding.h" -#include "ih264_platform_macros.h" -#include "ih264e_platform_macros.h" -#include "ih264_list.h" -#include "ih264_dpb_mgr.h" -#include "ih264_cavlc_tables.h" #include "ih264e_cavlc.h" -#include "ih264_common_tables.h" #include "ih264e_master.h" #include "ih264e_fmt_conv.h" -#include "ih264e_version.h" - - -/*****************************************************************************/ -/* Function Declarations */ -/*****************************************************************************/ -WORD32 ih264e_get_rate_control_mem_tab(void *pv_rate_control, - iv_mem_rec_t *ps_mem, - ITT_FUNC_TYPE_E e_func_type); +#include "ih264e_platform_macros.h" /*****************************************************************************/ @@ -1719,15 +1716,8 @@ static IV_STATUS_T api_check_struct_sanity(iv_obj_t *ps_handle, if ((ps_ip->s_ive_ip.u4_i_qp > ps_ip->s_ive_ip.u4_i_qp_max) || (ps_ip->s_ive_ip.u4_p_qp > ps_ip->s_ive_ip.u4_p_qp_max) - || (ps_ip->s_ive_ip.u4_b_qp > ps_ip->s_ive_ip.u4_b_qp_max)) - { - ps_op->s_ive_op.u4_error_code |= 1 - << IVE_UNSUPPORTEDPARAM; - ps_op->s_ive_op.u4_error_code |= IH264E_INVALID_INIT_QP; - return IV_FAIL; - } - - if ((ps_ip->s_ive_ip.u4_i_qp < ps_ip->s_ive_ip.u4_i_qp_min) + || (ps_ip->s_ive_ip.u4_b_qp > ps_ip->s_ive_ip.u4_b_qp_max) + || (ps_ip->s_ive_ip.u4_i_qp < ps_ip->s_ive_ip.u4_i_qp_min) || (ps_ip->s_ive_ip.u4_p_qp < ps_ip->s_ive_ip.u4_p_qp_min) || (ps_ip->s_ive_ip.u4_b_qp < ps_ip->s_ive_ip.u4_b_qp_min)) { @@ -2580,100 +2570,14 @@ IH264E_ERROR_T ih264e_codec_update_config(codec_t *ps_codec, else if (ps_cfg->e_cmd == IVE_CMD_CTL_SET_IPE_PARAMS) { ps_curr_cfg->u4_enc_speed_preset = ps_cfg->u4_enc_speed_preset; - ps_curr_cfg->u4_constrained_intra_pred = ps_cfg->u4_constrained_intra_pred; - if (ps_curr_cfg->u4_enc_speed_preset == IVE_SLOWEST) - {/* high quality */ - /* enable diamond search */ - ps_curr_cfg->u4_me_speed_preset = DMND_SRCH; - ps_curr_cfg->u4_enable_fast_sad = 0; - - /* disable intra 4x4 */ - ps_curr_cfg->u4_enable_intra_4x4 = 1; - ps_codec->luma_energy_compaction[1] = - ih264e_code_luma_intra_macroblock_4x4_rdopt_on; - - /* sub pel off */ - ps_curr_cfg->u4_enable_hpel = 1; - - /* deblocking off */ - ps_curr_cfg->u4_disable_deblock_level = DISABLE_DEBLK_LEVEL_0; - - /* disabled intra inter gating in Inter slices */ - ps_codec->u4_inter_gate = 0; - } - else if (ps_curr_cfg->u4_enc_speed_preset == IVE_NORMAL) - {/* normal */ - /* enable diamond search */ - ps_curr_cfg->u4_me_speed_preset = DMND_SRCH; - ps_curr_cfg->u4_enable_fast_sad = 0; - - /* disable intra 4x4 */ - ps_curr_cfg->u4_enable_intra_4x4 = 1; - - /* sub pel off */ - ps_curr_cfg->u4_enable_hpel = 1; - - /* deblocking off */ - ps_curr_cfg->u4_disable_deblock_level = DISABLE_DEBLK_LEVEL_0; - - /* disabled intra inter gating in Inter slices */ - ps_codec->u4_inter_gate = 0; - } - else if (ps_curr_cfg->u4_enc_speed_preset == IVE_FAST) - {/* normal */ - /* enable diamond search */ - ps_curr_cfg->u4_me_speed_preset = DMND_SRCH; - ps_curr_cfg->u4_enable_fast_sad = 0; - - /* disable intra 4x4 */ - ps_curr_cfg->u4_enable_intra_4x4 = 0; - - /* sub pel off */ - ps_curr_cfg->u4_enable_hpel = 1; - - /* deblocking off */ - ps_curr_cfg->u4_disable_deblock_level = DISABLE_DEBLK_LEVEL_0; - - /* disabled intra inter gating in Inter slices */ - ps_codec->u4_inter_gate = 1; - } - else if (ps_curr_cfg->u4_enc_speed_preset == IVE_HIGH_SPEED) - {/* fast */ - /* enable diamond search */ - ps_curr_cfg->u4_me_speed_preset = DMND_SRCH; - ps_curr_cfg->u4_enable_fast_sad = 0; - /* disable intra 4x4 */ - ps_curr_cfg->u4_enable_intra_4x4 = 0; - - /* sub pel off */ - ps_curr_cfg->u4_enable_hpel = 0; - - /* deblocking off */ - ps_curr_cfg->u4_disable_deblock_level = DISABLE_DEBLK_LEVEL_4; - - /* disabled intra inter gating in Inter slices */ - ps_codec->u4_inter_gate = 0; - } - else if (ps_curr_cfg->u4_enc_speed_preset == IVE_FASTEST) - {/* fastest */ - /* enable diamond search */ - ps_curr_cfg->u4_me_speed_preset = DMND_SRCH; - //u4_num_layers = 4; - - /* disable intra 4x4 */ - ps_curr_cfg->u4_enable_intra_4x4 = 0; - - /* sub pel off */ - ps_curr_cfg->u4_enable_hpel = 0; - - /* deblocking off */ - ps_curr_cfg->u4_disable_deblock_level = DISABLE_DEBLK_LEVEL_4; + ps_curr_cfg->u4_constrained_intra_pred = ps_cfg->u4_constrained_intra_pred; - /* disabled intra inter gating in Inter slices */ - ps_codec->u4_inter_gate = 1; + if (ps_curr_cfg->u4_enc_speed_preset != IVE_CONFIG) + { + ih264e_speed_preset_side_effects(ps_codec); } - else if (ps_curr_cfg->u4_enc_speed_preset == IVE_CONFIG) + else { ps_curr_cfg->u4_enable_intra_4x4 = ps_cfg->u4_enable_intra_4x4; } @@ -2690,8 +2594,7 @@ IH264E_ERROR_T ih264e_codec_update_config(codec_t *ps_codec, /* re-init air map */ ih264e_init_air_map(ps_codec); - /*Effect intra frame interval change*/ - + /* Effect intra frame interval change */ irc_change_intra_frm_int_call( ps_codec->s_rate_control.pps_rate_control_api, ps_curr_cfg->u4_i_frm_interval); @@ -3112,7 +3015,8 @@ static WORD32 ih264e_init(codec_t *ps_codec) ps_codec->i4_pps_id = 0; /* Process thread created status */ - memset(ps_codec->ai4_process_thread_created, 0, MAX_PROCESS_THREADS); + memset(ps_codec->ai4_process_thread_created, 0, + sizeof(ps_codec->ai4_process_thread_created)); memset(&ps_codec->s_global_quality_stats, 0, sizeof(ps_codec->s_global_quality_stats)); @@ -5745,7 +5649,6 @@ static IV_STATUS_T ih264_set_ipe_params(void *pv_api_ip, ps_cfg->u4_enable_intra_4x4 = ps_ip->s_ive_ip.u4_enable_intra_4x4; ps_cfg->u4_enc_speed_preset = ps_ip->s_ive_ip.u4_enc_speed_preset; - ps_cfg->u4_constrained_intra_pred = ps_ip->s_ive_ip.u4_constrained_intra_pred; ps_cfg->u4_timestamp_high = ps_ip->s_ive_ip.u4_timestamp_high; @@ -5790,8 +5693,7 @@ static IV_STATUS_T ih264_set_gop_params(void *pv_api_ip, ps_cfg->u4_i_frm_interval = ps_ip->s_ive_ip.u4_i_frm_interval; ps_cfg->u4_idr_frm_interval = ps_ip->s_ive_ip.u4_idr_frm_interval; - - if(ps_cfg->u4_idr_frm_interval < ps_cfg->u4_i_frm_interval) + if (ps_cfg->u4_idr_frm_interval < ps_cfg->u4_i_frm_interval) ps_cfg->u4_i_frm_interval = ps_cfg->u4_idr_frm_interval; ps_cfg->u4_timestamp_high = ps_ip->s_ive_ip.u4_timestamp_high; @@ -5835,7 +5737,6 @@ static IV_STATUS_T ih264_set_profile_params(void *pv_api_ip, ps_op->s_ive_op.u4_error_code = 0; ps_cfg->e_profile = ps_ip->s_ive_ip.e_profile; - ps_cfg->u4_entropy_coding_mode = ps_ip->s_ive_ip.u4_entropy_coding_mode; ps_cfg->u4_timestamp_high = ps_ip->s_ive_ip.u4_timestamp_high; @@ -5922,50 +5823,36 @@ static WORD32 ih264e_set_vui_params(void *pv_api_ip, ps_op->u4_error_code = 0; - ps_vui->u1_aspect_ratio_info_present_flag = - ps_ip->u1_aspect_ratio_info_present_flag; + ps_vui->u1_aspect_ratio_info_present_flag = ps_ip->u1_aspect_ratio_info_present_flag; ps_vui->u1_aspect_ratio_idc = ps_ip->u1_aspect_ratio_idc; ps_vui->u2_sar_width = ps_ip->u2_sar_width; ps_vui->u2_sar_height = ps_ip->u2_sar_height; - ps_vui->u1_overscan_info_present_flag = - ps_ip->u1_overscan_info_present_flag; + ps_vui->u1_overscan_info_present_flag = ps_ip->u1_overscan_info_present_flag; ps_vui->u1_overscan_appropriate_flag = ps_ip->u1_overscan_appropriate_flag; - ps_vui->u1_video_signal_type_present_flag = - ps_ip->u1_video_signal_type_present_flag; + ps_vui->u1_video_signal_type_present_flag = ps_ip->u1_video_signal_type_present_flag; ps_vui->u1_video_format = ps_ip->u1_video_format; ps_vui->u1_video_full_range_flag = ps_ip->u1_video_full_range_flag; - ps_vui->u1_colour_description_present_flag = - ps_ip->u1_colour_description_present_flag; + ps_vui->u1_colour_description_present_flag = ps_ip->u1_colour_description_present_flag; ps_vui->u1_colour_primaries = ps_ip->u1_colour_primaries; ps_vui->u1_transfer_characteristics = ps_ip->u1_transfer_characteristics; ps_vui->u1_matrix_coefficients = ps_ip->u1_matrix_coefficients; - ps_vui->u1_chroma_loc_info_present_flag = - ps_ip->u1_chroma_loc_info_present_flag; - ps_vui->u1_chroma_sample_loc_type_top_field = - ps_ip->u1_chroma_sample_loc_type_top_field; - ps_vui->u1_chroma_sample_loc_type_bottom_field = - ps_ip->u1_chroma_sample_loc_type_bottom_field; - ps_vui->u1_vui_timing_info_present_flag = - ps_ip->u1_vui_timing_info_present_flag; + ps_vui->u1_chroma_loc_info_present_flag = ps_ip->u1_chroma_loc_info_present_flag; + ps_vui->u1_chroma_sample_loc_type_top_field = ps_ip->u1_chroma_sample_loc_type_top_field; + ps_vui->u1_chroma_sample_loc_type_bottom_field = ps_ip->u1_chroma_sample_loc_type_bottom_field; + ps_vui->u1_vui_timing_info_present_flag = ps_ip->u1_vui_timing_info_present_flag; ps_vui->u4_vui_num_units_in_tick = ps_ip->u4_vui_num_units_in_tick; ps_vui->u4_vui_time_scale = ps_ip->u4_vui_time_scale; ps_vui->u1_fixed_frame_rate_flag = ps_ip->u1_fixed_frame_rate_flag; - ps_vui->u1_nal_hrd_parameters_present_flag = - ps_ip->u1_nal_hrd_parameters_present_flag; - ps_vui->u1_vcl_hrd_parameters_present_flag = - ps_ip->u1_vcl_hrd_parameters_present_flag; + ps_vui->u1_nal_hrd_parameters_present_flag = ps_ip->u1_nal_hrd_parameters_present_flag; + ps_vui->u1_vcl_hrd_parameters_present_flag = ps_ip->u1_vcl_hrd_parameters_present_flag; ps_vui->u1_low_delay_hrd_flag = ps_ip->u1_low_delay_hrd_flag; ps_vui->u1_pic_struct_present_flag = ps_ip->u1_pic_struct_present_flag; - ps_vui->u1_bitstream_restriction_flag = - ps_ip->u1_bitstream_restriction_flag; - ps_vui->u1_motion_vectors_over_pic_boundaries_flag = - ps_ip->u1_motion_vectors_over_pic_boundaries_flag; + ps_vui->u1_bitstream_restriction_flag = ps_ip->u1_bitstream_restriction_flag; + ps_vui->u1_motion_vectors_over_pic_boundaries_flag = ps_ip->u1_motion_vectors_over_pic_boundaries_flag; ps_vui->u1_max_bytes_per_pic_denom = ps_ip->u1_max_bytes_per_pic_denom; ps_vui->u1_max_bits_per_mb_denom = ps_ip->u1_max_bits_per_mb_denom; - ps_vui->u1_log2_max_mv_length_horizontal = - ps_ip->u1_log2_max_mv_length_horizontal; - ps_vui->u1_log2_max_mv_length_vertical = - ps_ip->u1_log2_max_mv_length_vertical; + ps_vui->u1_log2_max_mv_length_horizontal = ps_ip->u1_log2_max_mv_length_horizontal; + ps_vui->u1_log2_max_mv_length_vertical = ps_ip->u1_log2_max_mv_length_vertical; ps_vui->u1_num_reorder_frames = ps_ip->u1_num_reorder_frames; ps_vui->u1_max_dec_frame_buffering = ps_ip->u1_max_dec_frame_buffering; diff --git a/encoder/ih264e_bitstream.c b/encoder/ih264e_bitstream.c index ef8dc3d0..dfdacff4 100644 --- a/encoder/ih264e_bitstream.c +++ b/encoder/ih264e_bitstream.c @@ -30,13 +30,13 @@ * ittiam * * @par List of Functions: -* - ih264e_bitstrm_init() -* - ih264e_put_bits() -* - ih264e_put_bit() -* - ih264e_put_rbsp_trailing_bits() -* - ih264e_put_uev() -* - ih264e_put_sev() -* - ih264e_put_nal_start_code_prefix() +* - ih264e_bitstrm_init +* - ih264e_put_bits +* - ih264e_put_bit +* - ih264e_put_rbsp_trailing_bits +* - ih264e_put_uev +* - ih264e_put_sev +* - ih264e_put_nal_start_code_prefix * ****************************************************************************** */ @@ -45,7 +45,7 @@ /* File Includes */ /*****************************************************************************/ -/* System include files */ +/* System Include Files */ #include #include #include @@ -53,16 +53,17 @@ #include #include -/* User include files */ +/* User Include Files */ #include "ih264e_config.h" #include "ih264_typedefs.h" -#include "ih264_platform_macros.h" + #include "ih264_debug.h" -#include "ih264e_error.h" -#include "ih264e_bitstream.h" -#include "ih264_defs.h" #include "ih264_macros.h" +#include "ih264_defs.h" +#include "ih264_platform_macros.h" +#include "ih264e_error.h" +#include "ih264e_bitstream.h" /*****************************************************************************/ /* Function Definitions */ diff --git a/encoder/ih264e_bitstream.h b/encoder/ih264e_bitstream.h index 58bfc5f7..aee049bf 100644 --- a/encoder/ih264e_bitstream.h +++ b/encoder/ih264e_bitstream.h @@ -36,8 +36,8 @@ ******************************************************************************* */ -#ifndef IH264E_BITSTREAM_H_ -#define IH264E_BITSTREAM_H_ +#ifndef _IH264E_BITSTREAM_H_ +#define _IH264E_BITSTREAM_H_ /*****************************************************************************/ /* Constant Macros */ @@ -273,209 +273,25 @@ static inline IH264E_ERROR_T ih264e_put_byte_epb(bitstrm_t *ps_bitstrm, UWORD8 b /*****************************************************************************/ -/* Extern Function Declarations */ +/* Function Declarations */ /*****************************************************************************/ -/** -****************************************************************************** -* -* @brief Initializes the encoder bitstream engine -* -* @par Description -* This routine needs to be called at start of slice/frame encode -* -* @param[in] ps_bitstrm -* pointer to bitstream context (handle) -* -* @param[in] p1_bitstrm_buf -* bitstream buffer pointer where the encoded stream is generated in byte order -* -* @param[in] u4_max_bitstrm_size -* indicates maximum bitstream buffer size. (in bytes) -* If actual stream size exceeds the maximum size, encoder should -* 1. Not corrupt data beyond u4_max_bitstrm_size bytes -* 2. Report an error back to application indicating overflow -* -* @return success or failure error code -* -****************************************************************************** -*/ -IH264E_ERROR_T ih264e_bitstrm_init - ( - bitstrm_t *ps_bitstrm, - UWORD8 *pu1_bitstrm_buf, - UWORD32 u4_max_bitstrm_size - ); +IH264E_ERROR_T ih264e_bitstrm_init(bitstrm_t *ps_bitstrm, + UWORD8 *pu1_bitstrm_buf, + UWORD32 u4_max_bitstrm_size); -/** -****************************************************************************** -* -* @brief puts a code with specified number of bits into the bitstream -* -* @par Description -* inserts code_len number of bits from lsb of code_val into the -* bitstream. If the total bytes (u4_strm_buf_offset) exceeds max -* available size (u4_max_strm_size), returns error without corrupting data -* beyond it -* -* @param[in] ps_bitstrm -* pointer to bitstream context (handle) -* -* @param[in] u4_code_val -* code value that needs to be inserted in the stream. -* -* @param[in] code_len -* indicates code length (in bits) of code_val that would be inserted in -* bitstream buffer size. -* -* @remarks Assumptions: all bits from bit position code_len to msb of -* code_val shall be zero -* -* @return success or failure error code -* -****************************************************************************** -*/ -IH264E_ERROR_T ih264e_put_bits - ( - bitstrm_t *ps_bitstrm, - UWORD32 u4_code_val, - WORD32 code_len - ); +IH264E_ERROR_T ih264e_put_bits(bitstrm_t *ps_bitstrm, UWORD32 u4_code_val, + WORD32 code_len); -/** -****************************************************************************** -* -* @brief inserts a 1-bit code into the bitstream -* -* @par Description -* inserts 1bit lsb of code_val into the bitstream -* updates context members like u4_cur_word, u4_strm_buf_offset and -* i4_bits_left_in_cw. If the total words (u4_strm_buf_offset) exceeds max -* available size (u4_max_strm_size), returns error without corrupting data -* beyond it -* -* @param[in] ps_bitstrm -* pointer to bitstream context (handle) -* -* @param[in] u4_code_val -* code value that needs to be inserted in the stream. -* -* @remarks Assumptions: all bits from bit position 1 to msb of code_val -* shall be zero -* -* @return success or failure error code -* -****************************************************************************** -*/ -IH264E_ERROR_T ih264e_put_bit - ( - bitstrm_t *ps_bitstrm, - UWORD32 u4_code_val - ); +IH264E_ERROR_T ih264e_put_bit(bitstrm_t *ps_bitstrm, UWORD32 u4_code_val); -/** -****************************************************************************** -* -* @brief inserts rbsp trailing bits at the end of stream buffer (NAL) -* -* @par Description -* inserts rbsp trailing bits, updates context members like u4_cur_word and -* i4_bits_left_in_cw and flushes the same in the bitstream buffer. If the -* total words (u4_strm_buf_offset) exceeds max available size -* (u4_max_strm_size), returns error without corrupting data beyond it -* -* @param[in] ps_bitstrm -* pointer to bitstream context (handle) -* -* @return success or failure error code -* -****************************************************************************** -*/ -IH264E_ERROR_T ih264e_put_rbsp_trailing_bits - ( - bitstrm_t *ps_bitstrm - ); +IH264E_ERROR_T ih264e_put_rbsp_trailing_bits(bitstrm_t *ps_bitstrm); -/** -****************************************************************************** -* -* @brief puts exponential golomb code of a unsigned integer into bitstream -* -* @par Description -* computes uev code for given syntax element and inserts the same into -* bitstream by calling ih264e_put_bits() interface. -* -* @param[in] ps_bitstrm -* pointer to bitstream context (handle) -* -* @param[in] u4_code_num -* unsigned integer input whose golomb code is written in stream -* -* @remarks Assumptions: code value can be represented in less than 16bits -* -* @return success or failure error code -* -****************************************************************************** -*/ -IH264E_ERROR_T ih264e_put_uev - ( - bitstrm_t *ps_bitstrm, - UWORD32 u4_code_num - ); +IH264E_ERROR_T ih264e_put_uev(bitstrm_t *ps_bitstrm, UWORD32 u4_code_num); -/** -****************************************************************************** -* -* @brief puts exponential golomb code of a signed integer into bitstream -* -* @par Description -* computes sev code for given syntax element and inserts the same into -* bitstream by calling ih264e_put_bits() interface. -* -* @param[in] ps_bitstrm -* pointer to bitstream context (handle) -* -* @param[in] syntax_elem -* signed integer input whose golomb code is written in stream -* -* @remarks Assumptions: code value can be represented in less than 16bits -* -* @return success or failure error code -* -****************************************************************************** -*/ -IH264E_ERROR_T ih264e_put_sev - ( - bitstrm_t *ps_bitstrm, - WORD32 syntax_elem - ); +IH264E_ERROR_T ih264e_put_sev(bitstrm_t *ps_bitstrm, WORD32 syntax_elem); -/** -****************************************************************************** -* -* @brief insert NAL start code prefix (0x000001) into bitstream with an option -* of inserting leading_zero_8bits (which makes startcode prefix as 0x00000001) -* -* @par Description -* Although start code prefix could have been put by calling ih264e_put_bits(), -* ih264e_put_nal_start_code_prefix() is specially added to make sure emulation -* prevention insertion is not done for the NAL start code prefix which will -* surely happen otherwise by calling ih264e_put_bits() interface. -* -* @param[in] ps_bitstrm -* pointer to bitstream context (handle) -* -* @param[in] insert_leading_zero_8bits -* flag indicating if one more zero bytes needs to prefixed before start code -* -* @return success or failure error code -* -****************************************************************************** -*/ -IH264E_ERROR_T ih264e_put_nal_start_code_prefix - ( - bitstrm_t *ps_bitstrm, - WORD32 insert_leading_zero_8bits - ); +IH264E_ERROR_T ih264e_put_nal_start_code_prefix(bitstrm_t *ps_bitstrm, + WORD32 insert_leading_zero_8bits); -#endif /* IH264E_BITSTREAM_H_ */ +#endif /* _IH264E_BITSTREAM_H_ */ diff --git a/encoder/ih264e_cabac.c b/encoder/ih264e_cabac.c index fb54475d..9e9add99 100644 --- a/encoder/ih264e_cabac.c +++ b/encoder/ih264e_cabac.c @@ -26,15 +26,21 @@ * @brief * Contains all leaf level functions for CABAC entropy coding. * -* * @author -* Doney Alex +* ittiam * * @par List of Functions: -* +* - ih264e_cabac_UEGk0_binarization +* - ih264e_get_cabac_context +* - ih264e_cabac_put_byte +* - ih264e_cabac_encode_bin +* - ih264e_encode_decision_bins +* - ih264e_cabac_encode_terminate +* - ih264e_cabac_encode_bypass_bin +* - ih264e_cabac_encode_bypass_bins * * @remarks -* None +* none * ******************************************************************************* */ @@ -43,44 +49,47 @@ /* File Includes */ /*****************************************************************************/ -/* System include files */ +/* System Include Files */ #include #include #include #include -/* User include files */ +/* User Include Files */ #include "ih264e_config.h" #include "ih264_typedefs.h" #include "iv2.h" #include "ive2.h" + #include "ih264_debug.h" -#include "ih264_defs.h" -#include "ih264e_defs.h" #include "ih264_macros.h" -#include "ih264e_error.h" -#include "ih264e_bitstream.h" -#include "ime_distortion_metrics.h" -#include "ime_defs.h" -#include "ime_structs.h" #include "ih264_error.h" +#include "ih264_defs.h" +#include "ih264_mem_fns.h" +#include "ih264_padding.h" #include "ih264_structs.h" #include "ih264_trans_quant_itrans_iquant.h" #include "ih264_inter_pred_filters.h" -#include "ih264_mem_fns.h" -#include "ih264_padding.h" -#include "ih264_platform_macros.h" #include "ih264_intra_pred_filters.h" #include "ih264_deblk_edge_filters.h" +#include "ih264_cavlc_tables.h" #include "ih264_cabac_tables.h" +#include "ih264_platform_macros.h" + +#include "ime_defs.h" +#include "ime_distortion_metrics.h" +#include "ime_structs.h" + #include "irc_cntrl_param.h" #include "irc_frame_info_collector.h" -#include "ih264e_rate_control.h" + +#include "ih264e_error.h" +#include "ih264e_defs.h" +#include "ih264e_bitstream.h" #include "ih264e_cabac_structs.h" #include "ih264e_structs.h" -#include "ih264e_cabac.h" #include "ih264e_encode_header.h" -#include "ih264_cavlc_tables.h" +#include "ih264e_cabac.h" #include "ih264e_statistics.h" #include "ih264e_trace.h" @@ -89,29 +98,26 @@ /* Function Definitions */ /*****************************************************************************/ - /** - ******************************************************************************* - * - * @brief - * k-th order Exp-Golomb (UEGk) binarization process: Implements concatenated - * unary/ k-th order Exp-Golomb (UEGk) binarization process, - * where k = 0 as defined in 9.3.2.3 of ITU_T_H264-201402 - * - * @param[in] i2_sufs - * Suffix bit string - * - * @param[in] pi1_bins_len - * Pointer to length of tthe string - * - * @returns Binarized value - * - * @remarks - * None - * - ******************************************************************************* - */ - +******************************************************************************* +* +* @brief +* k-th order Exp-Golomb (UEGk) binarization process: Implements concatenated +* unary/ k-th order Exp-Golomb (UEGk) binarization process, where k = 0 as +* defined in 9.3.2.3 of ITU_T_H264-201402 +* +* @param[in] i2_sufs +* Suffix bit string +* +* @param[in] pi1_bins_len +* Pointer to length of tthe string +* +* @returns Binarized value +* +* @remarks none +* +******************************************************************************* +*/ UWORD32 ih264e_cabac_UEGk0_binarization(WORD16 i2_sufs, WORD8 *pi1_bins_len) { WORD32 unary_length; @@ -135,33 +141,29 @@ UWORD32 ih264e_cabac_UEGk0_binarization(WORD16 i2_sufs, WORD8 *pi1_bins_len) } /** - ******************************************************************************* - * - * @brief - * Get cabac context for the MB :calculates the pointers to Top and left - * cabac neighbor context depending upon neighbor availability. - * - * @param[in] ps_ent_ctxt - * Pointer to entropy context structure - * - * @param[in] u4_mb_type - * Type of MB - * - * @returns - * - * @remarks - * None - * - ******************************************************************************* - */ +******************************************************************************* +* +* @brief +* Get cabac context for the MB :calculates the pointers to Top and left +* cabac neighbor context depending upon neighbor availability. +* +* @param[in] ps_ent_ctxt +* Pointer to entropy context structure +* +* @param[in] u4_mb_type +* Type of MB +* +* @returns none +* +* @remarks none +* +******************************************************************************* +*/ void ih264e_get_cabac_context(entropy_ctxt_t *ps_ent_ctxt, WORD32 u4_mb_type) { - - /* CABAC context */ cabac_ctxt_t *ps_cabac_ctxt = ps_ent_ctxt->ps_cabac; mb_info_ctxt_t *ps_ctx_inc_mb_map; cab_csbp_t *ps_lft_csbp; - WORD32 i4_lft_avail, i4_top_avail, i4_is_intra; WORD32 i4_mb_x, i4_mb_y; UWORD8 *pu1_slice_idx = ps_ent_ctxt->pu1_slice_idx; @@ -222,29 +224,25 @@ void ih264e_get_cabac_context(entropy_ctxt_t *ps_ent_ctxt, WORD32 u4_mb_type) ps_cabac_ctxt->ps_curr_ctxt_mb_info->i1_ref_idx[3] = 0; memset(ps_cabac_ctxt->ps_curr_ctxt_mb_info->u1_mv, 0, 16); } - } - - /** - ******************************************************************************* - * @brief - * flushing at termination: Explained in flowchart 9-12(ITU_T_H264-201402). - * - * @param[in] ps_cabac_ctxt - * pointer to cabac context (handle) - * - * @returns none - * - * @remarks - * None - * - ******************************************************************************* - */ +******************************************************************************* +* +* @brief +* flushing at termination: Explained in flowchart 9-12(ITU_T_H264-201402). +* +* @param[in] ps_cabac_ctxt +* pointer to cabac context (handle) +* +* @returns none +* +* @remarks none +* +******************************************************************************* +*/ IH264E_ERROR_T ih264e_cabac_flush(cabac_ctxt_t *ps_cabac_ctxt) { - /* bit stream ptr */ bitstrm_t *ps_stream = ps_cabac_ctxt->ps_bitstrm; encoding_envirnoment_t *ps_cab_enc_env = &(ps_cabac_ctxt->s_cab_enc_env); UWORD32 u4_low = ps_cab_enc_env->u4_code_int_low; @@ -328,30 +326,28 @@ IH264E_ERROR_T ih264e_cabac_flush(cabac_ctxt_t *ps_cabac_ctxt) } /** - ****************************************************************************** - * - * @brief Puts new byte (and outstanding bytes) into bitstream after cabac - * renormalization - * - * @par Description - * 1. Extract the leading byte of low(L) - * 2. If leading byte=0xff increment outstanding bytes and return - * (as the actual bits depend on carry propogation later) - * 3. If leading byte is not 0xff check for any carry propogation - * 4. Insert the carry (propogated in previous byte) along with outstanding - * bytes (if any) and leading byte - * - * - * @param[in] ps_cabac_ctxt - * pointer to cabac context (handle) - * - * @return - * - ****************************************************************************** - */ +****************************************************************************** +* +* @brief Puts new byte (and outstanding bytes) into bitstream after cabac +* renormalization +* +* @par Description +* 1. Extract the leading byte of low(L) +* 2. If leading byte=0xff increment outstanding bytes and return +* (as the actual bits depend on carry propogation later) +* 3. If leading byte is not 0xff check for any carry propogation +* 4. Insert the carry (propogated in previous byte) along with outstanding +* bytes (if any) and leading byte +* +* @param[in] ps_cabac_ctxt +* pointer to cabac context (handle) +* +* @returns none +* +****************************************************************************** +*/ IH264E_ERROR_T ih264e_cabac_put_byte(cabac_ctxt_t *ps_cabac_ctxt) { - /* bit stream ptr */ bitstrm_t *ps_stream = ps_cabac_ctxt->ps_bitstrm; encoding_envirnoment_t *ps_cab_enc_env = &(ps_cabac_ctxt->s_cab_enc_env); UWORD32 u4_low = ps_cab_enc_env->u4_code_int_low; @@ -435,36 +431,32 @@ IH264E_ERROR_T ih264e_cabac_put_byte(cabac_ctxt_t *ps_cabac_ctxt) return status; } - - - - /** - ****************************************************************************** - * - * @brief Codes a bin based on probablilty and mps packed context model - * - * @par Description - * 1. Apart from encoding bin, context model is updated as per state transition - * 2. Range and Low renormalization is done based on bin and original state - * 3. After renorm bistream is updated (if required) - * - * @param[in] ps_cabac - * pointer to cabac context (handle) - * - * @param[in] bin - * bin(boolean) to be encoded - * - * @param[in] pu1_bin_ctxts - * index of cabac context model containing pState[bits 5-0] | MPS[bit6] - * - * @return - * - ****************************************************************************** - */ +/** +****************************************************************************** +* +* @brief Codes a bin based on probablilty and mps packed context model +* +* @par Description +* 1. Apart from encoding bin, context model is updated as per state transition +* 2. Range and Low renormalization is done based on bin and original state +* 3. After renorm bistream is updated (if required) +* +* @param[in] ps_cabac +* pointer to cabac context (handle) +* +* @param[in] bin +* bin(boolean) to be encoded +* +* @param[in] pu1_bin_ctxts +* index of cabac context model containing pState[bits 5-0] | MPS[bit6] +* +* @return none +* +****************************************************************************** +*/ void ih264e_cabac_encode_bin(cabac_ctxt_t *ps_cabac, WORD32 bin, bin_ctxt_model *pu1_bin_ctxts) { - encoding_envirnoment_t *ps_cab_enc_env = &(ps_cabac->s_cab_enc_env); UWORD32 u4_range = ps_cab_enc_env->u4_code_int_range; UWORD32 u4_low = ps_cab_enc_env->u4_code_int_low; @@ -473,6 +465,7 @@ void ih264e_cabac_encode_bin(cabac_ctxt_t *ps_cabac, WORD32 bin, UWORD8 u1_mps = !!((*pu1_bin_ctxts) & (0x40)); WORD32 shift; UWORD32 u4_table_val; + /* Sanity checks */ ASSERT((bin == 0) || (bin == 1)); ASSERT((u4_range >= 256) && (u4_range < 512)); @@ -503,64 +496,58 @@ void ih264e_cabac_encode_bin(cabac_ctxt_t *ps_cabac, WORD32 bin, (*pu1_bin_ctxts) = (u1_mps << 6) | state_mps; - /*****************************************************************/ - /* Renormalization; calculate bits generated based on range(R) */ - /* Note : 6 <= R < 512; R is 2 only for terminating encode */ - /*****************************************************************/ - GETRANGE(shift, u4_range); - shift = 9 - shift; - u4_low <<= shift; - u4_range <<= shift; - - /* bits to be inserted in the bitstream */ - ps_cab_enc_env->u4_bits_gen += shift; - ps_cab_enc_env->u4_code_int_range = u4_range; - ps_cab_enc_env->u4_code_int_low = u4_low; - - /* generate stream when a byte is ready */ - if (ps_cab_enc_env->u4_bits_gen > CABAC_BITS) - { - ih264e_cabac_put_byte(ps_cabac); - } - -} - - + /*****************************************************************/ + /* Renormalization; calculate bits generated based on range(R) */ + /* Note : 6 <= R < 512; R is 2 only for terminating encode */ + /*****************************************************************/ + GETRANGE(shift, u4_range); + shift = 9 - shift; + u4_low <<= shift; + u4_range <<= shift; + /* bits to be inserted in the bitstream */ + ps_cab_enc_env->u4_bits_gen += shift; + ps_cab_enc_env->u4_code_int_range = u4_range; + ps_cab_enc_env->u4_code_int_low = u4_low; - /** - ******************************************************************************* - * - * @brief - * Encoding process for a binary decision :implements encoding process of a decision - * as defined in 9.3.4.2 . This function encodes multiple bins, of a symbol. Implements - * flowchart Figure 9-7( ITU_T_H264-201402) - * - * @param[in] u4_bins - * array of bin values - * - * @param[in] i1_bins_len - * Length of bins, maximum 32 - * - * @param[in] u4_ctx_inc - * CtxInc, byte0- bin0, byte1-bin1 .. - * - * @param[in] i1_valid_len - * valid length of bins, after that CtxInc is constant - * - * @param[in] pu1_bin_ctxt_type - * Pointer to binary contexts + /* generate stream when a byte is ready */ + if (ps_cab_enc_env->u4_bits_gen > CABAC_BITS) + { + ih264e_cabac_put_byte(ps_cabac); + } +} - * @param[in] ps_cabac - * Pointer to cabac_context_structure - * - * @returns - * - * @remarks - * None - * - ******************************************************************************* - */ +/** +******************************************************************************* +* +* @brief Encoding process for a binary decision: implements encoding process of +* a decision as defined in 9.3.4.2. This function encodes multiple bins, of a +* symbol. Implements flowchart Figure 9-7( ITU_T_H264-201402) +* +* @param[in] u4_bins +* array of bin values +* +* @param[in] i1_bins_len +* Length of bins, maximum 32 +* +* @param[in] u4_ctx_inc +* CtxInc, byte0- bin0, byte1-bin1 .. +* +* @param[in] i1_valid_len +* valid length of bins, after that CtxInc is constant +* +* @param[in] pu1_bin_ctxt_type +* Pointer to binary contexts +* +* @param[in] ps_cabac +* Pointer to cabac_context_structure +* +* @returns none +* +* @remarks none +* +******************************************************************************* +*/ void ih264e_encode_decision_bins(UWORD32 u4_bins, WORD8 i1_bins_len, UWORD32 u4_ctx_inc, WORD8 i1_valid_len, bin_ctxt_model *pu1_bin_ctxt_type, @@ -580,38 +567,29 @@ void ih264e_encode_decision_bins(UWORD32 u4_bins, WORD8 i1_bins_len, ih264e_cabac_encode_bin(ps_cabac, u1_bin, pu1_bin_ctxt_type + u1_ctx_inc); } - } - - - - - /** - ******************************************************************************* - * @brief - * Encoding process for a binary decision before termination:Encoding process - * of a termination(9.3.4.5 :ITU_T_H264-201402) . Explained in flowchart 9-11. - * - * @param[in] ps_cabac - * Pointer to cabac structure - * - * @param[in] term_bin - * Symbol value, end of slice or not, term_bin is binary - * - * @returns - * - * @remarks - * None - * - ******************************************************************************* - */ +******************************************************************************* +* @brief +* Encoding process for a binary decision before termination:Encoding process +* of a termination(9.3.4.5:ITU_T_H264-201402). Explained in flowchart 9-11. +* +* @param[in] ps_cabac +* Pointer to cabac structure +* +* @param[in] term_bin +* Symbol value, end of slice or not, term_bin is binary +* +* @returns none +* +* @remarks none +* +******************************************************************************* +*/ void ih264e_cabac_encode_terminate(cabac_ctxt_t *ps_cabac, WORD32 term_bin) { - encoding_envirnoment_t *ps_cab_enc_env = &(ps_cabac->s_cab_enc_env); - UWORD32 u4_range = ps_cab_enc_env->u4_code_int_range; UWORD32 u4_low = ps_cab_enc_env->u4_code_int_low; UWORD32 u4_rlps; @@ -657,33 +635,28 @@ void ih264e_cabac_encode_terminate(cabac_ctxt_t *ps_cabac, WORD32 term_bin) { ih264e_cabac_flush(ps_cabac); } - } - /** - ******************************************************************************* - * @brief - * Bypass encoding process for binary decisions: Explained (9.3.4.4 :ITU_T_H264-201402) - * , flowchart 9-10. - * - * @param[ino] ps_cabac : pointer to cabac context (handle) - * - * @param[in] bin : bypass bin(0/1) to be encoded - * - * @returns - * - * @remarks - * None - * - ******************************************************************************* - */ - +******************************************************************************* +* @brief Bypass encoding process for binary decisions. +* Explained (9.3.4.4 :ITU_T_H264-201402), flowchart 9-10. +* +* @param[ino] ps_cabac +* pointer to cabac context (handle) +* +* @param[in] bin +* bypass bin(0/1) to be encoded +* +* @returns none +* +* @remarks none +* +******************************************************************************* +*/ void ih264e_cabac_encode_bypass_bin(cabac_ctxt_t *ps_cabac, WORD32 bin) { - encoding_envirnoment_t *ps_cab_enc_env = &(ps_cabac->s_cab_enc_env); - UWORD32 u4_range = ps_cab_enc_env->u4_code_int_range; UWORD32 u4_low = ps_cab_enc_env->u4_code_int_low; @@ -707,40 +680,35 @@ void ih264e_cabac_encode_bypass_bin(cabac_ctxt_t *ps_cabac, WORD32 bin) { ih264e_cabac_put_byte(ps_cabac); } - } - - /** - ****************************************************************************** - * - * @brief Encodes a series of bypass bins (FLC bypass bins) - * - * @par Description - * This function is more optimal than calling ih264e_cabac_encode_bypass_bin() - * in a loop as cabac low, renorm and generating the stream (8bins at a time) - * can be done in one operation - * - * @param[inout]ps_cabac - * pointer to cabac context (handle) - * - * @param[in] u4_bins - * syntax element to be coded (as FLC bins) - * - * @param[in] num_bins - * This is the FLC length for u4_sym - * - * @return - * - ****************************************************************************** - */ - +/** +****************************************************************************** +* +* @brief Encodes a series of bypass bins (FLC bypass bins) +* +* @par Description +* This function is more optimal than calling ih264e_cabac_encode_bypass_bin() +* in a loop as cabac low, renorm and generating the stream (8bins at a time) +* can be done in one operation +* +* @param[inout]ps_cabac +* pointer to cabac context (handle) +* +* @param[in] u4_bins +* syntax element to be coded (as FLC bins) +* +* @param[in] num_bins +* This is the FLC length for u4_sym +* +* @return none +* +****************************************************************************** +*/ void ih264e_cabac_encode_bypass_bins(cabac_ctxt_t *ps_cabac, UWORD32 u4_bins, WORD32 num_bins) { - encoding_envirnoment_t *ps_cab_enc_env = &(ps_cabac->s_cab_enc_env); - UWORD32 u4_range = ps_cab_enc_env->u4_code_int_range; WORD32 next_byte; @@ -782,5 +750,4 @@ void ih264e_cabac_encode_bypass_bins(cabac_ctxt_t *ps_cabac, UWORD32 u4_bins, /* insert the leading byte of low into stream */ ih264e_cabac_put_byte(ps_cabac); } - } diff --git a/encoder/ih264e_cabac.h b/encoder/ih264e_cabac.h index bc4b07c1..c8492dfe 100644 --- a/encoder/ih264e_cabac.h +++ b/encoder/ih264e_cabac.h @@ -19,38 +19,40 @@ */ /** - ******************************************************************************* - * @file - * ih264e_cabac_structs.h - * - * @brief - * This file contains cabac related macros, enums, tables and function declarations. - * - * @author - * Doney Alex - * - * @remarks - * none - * - ******************************************************************************* - */ - -#ifndef IH264E_CABAC_H_ -#define IH264E_CABAC_H_ +******************************************************************************* +* @file +* ih264e_cabac.h +* +* @brief +* This file contains declarations necessary for cabac encoding +* +* @author +* ittiam +* +* @remarks +* none +* +******************************************************************************* +*/ +#ifndef _IH264E_CABAC_H_ +#define _IH264E_CABAC_H_ +/*****************************************************************************/ +/* Macros */ +/*****************************************************************************/ -/******************************************************************************* -@brief Bit precision of cabac engine; +/** +******************************************************************************* +* @brief Bit precision of cabac engine; ******************************************************************************* */ #define CABAC_BITS 9 - /** -****************************************************************************** - * @macro Reverse bits in an unsigned integer -****************************************************************************** +******************************************************************************* +* @macro Reverse bits in an unsigned integer +******************************************************************************* */ #define REV(u4_input, u4_output) \ { \ @@ -65,370 +67,57 @@ } /** -****************************************************************************** +******************************************************************************* *! Bit manipulation macros -****************************************************************************** +******************************************************************************* */ #define SETBIT(a, i) ((a) |= (1 << (i))) #define CLEARBIT(a, i) ((a) &= ~(1 << (i))) - /** -****************************************************************************** +******************************************************************************* *! Cabac module expect atlesat MIN_STREAM_SIZE_MB bytes left in stream buffer *! for encoding an MB -****************************************************************************** +******************************************************************************* */ #define MIN_STREAM_SIZE_MB 1024 - /*****************************************************************************/ -/* Function Declarations */ +/* Function Declarations */ /*****************************************************************************/ - -/** - ******************************************************************************* - * - * @brief - * Initialize default context values and pointers. - * - * @param[in] ps_ent_ctxt - * Pointer to entropy context structure - * - * @returns - * - * @remarks - * None - * - ******************************************************************************* - */ void ih264e_init_cabac_table(entropy_ctxt_t *ps_ent_ctxt); - -/** - ******************************************************************************* - * - * @brief - * Initialize cabac context: Intitalize all contest with init values given in the spec. - * Called at the beginning of entropy coding of each slice for CABAC encoding. - * - * @param[in] ps_ent_ctxt - * Pointer to entropy context structure - * - * @returns - * - * @remarks - * None - * - ******************************************************************************* - */ void ih264e_init_cabac_ctxt(entropy_ctxt_t *ps_ent_ctxt); - - -/** - ******************************************************************************* - * - * @brief - * k-th order Exp-Golomb (UEGk) binarization process: Implements concatenated - * unary/ k-th order Exp-Golomb (UEGk) binarization process, - * where k = 0 as defined in 9.3.2.3 of ITU_T_H264-201402 - * - * @param[in] i2_sufs - * Suffix bit string - * - * @param[in] pi1_bins_len - * Pointer to length of the string - * - * @returns Binarized value - * - * @remarks - * None - * - ******************************************************************************* - */ UWORD32 ih264e_cabac_UEGk0_binarization(WORD16 i2_sufs, WORD8 *pi1_bins_len); - -/** - ******************************************************************************* - * - * @brief - * Get cabac context for the MB :calculates the pointers to Top and left - * cabac neighbor context depending upon neighbor availability. - * - * @param[in] ps_ent_ctxt - * Pointer to entropy context structure - * - * @param[in] u4_mb_type - * Type of MB - * - * @returns - * - * @remarks - * None - * - ******************************************************************************* - */ void ih264e_get_cabac_context(entropy_ctxt_t *ps_ent_ctxt, WORD32 u4_mb_type); - -/** - ******************************************************************************* - * @brief - * flushing at termination: Explained in flowchart 9-12(ITU_T_H264-201402). - * - * @param[in] ps_cabac_ctxt - * pointer to cabac context (handle) - * - * @returns none - * - * @remarks - * None - * - ******************************************************************************* - */ IH264E_ERROR_T ih264e_cabac_flush(cabac_ctxt_t *ps_cabac_ctxt); - -/** - ****************************************************************************** - * - * @brief Puts new byte (and outstanding bytes) into bitstream after cabac - * renormalization - * - * @par Description - * 1. Extract the leading byte of low(L) - * 2. If leading byte=0xff increment outstanding bytes and return - * (as the actual bits depend on carry propogation later) - * 3. If leading byte is not 0xff check for any carry propogation - * 4. Insert the carry (propogated in previous byte) along with outstanding - * bytes (if any) and leading byte - * - * - * @param[inout] ps_cabac_ctxt - * pointer to cabac context (handle) - * - * @return - * - ****************************************************************************** - */ IH264E_ERROR_T ih264e_cabac_put_byte(cabac_ctxt_t *ps_cabac_ctxt); - -/** - ****************************************************************************** - * - * @brief Codes a bin based on probablilty and mps packed context model - * - * @par Description - * 1. Apart from encoding bin, context model is updated as per state transition - * 2. Range and Low renormalization is done based on bin and original state - * 3. After renorm bistream is updated (if required) - * - * @param[inout] ps_cabac - * pointer to cabac context (handle) - * - * @param[in] bin - * bin(boolean) to be encoded - * - * @param[in] pu1_bin_ctxts - * index of cabac context model containing pState[bits 5-0] | MPS[bit6] - * - * @return - * - ****************************************************************************** - */ void ih264e_cabac_encode_bin(cabac_ctxt_t *ps_cabac, WORD32 bin, bin_ctxt_model *pu1_bin_ctxts); - - -/** - ******************************************************************************* - * - * @brief - * Encoding process for a binary decision :implements encoding process of a decision - * as defined in 9.3.4.2 . This function encodes multiple bins, of a symbol. Implements - * flowchart Figure 9-7( ITU_T_H264-201402) - * - * @param[in] u4_bins - * array of bin values - * - * @param[in] i1_bins_len - * Length of bins, maximum 32 - * - * @param[in] u4_ctx_inc - * CtxInc, byte0- bin0, byte1-bin1 .. - * - * @param[in] i1_valid_len - * valid length of bins, after that CtxInc is constant - * - * @param[in] pu1_bin_ctxt_type - * Pointer to binary contexts - - * @param[in] ps_cabac - * Pointer to cabac_context_structure - * - * @returns - * - * @remarks - * None - * - ******************************************************************************* - */ void ih264e_encode_decision_bins(UWORD32 u4_bins, WORD8 i1_bins_len, UWORD32 u4_ctx_inc, WORD8 i1_valid_len, bin_ctxt_model *pu1_bin_ctxt_type, cabac_ctxt_t *ps_cabac); -/** - ******************************************************************************* - * @brief - * Encoding process for a binary decision before termination:Encoding process - * of a termination(9.3.4.5 :ITU_T_H264-201402) . Explained in flowchart 9-11. - * - * @param[in] ps_cabac - * Pointer to cabac structure - * - * @param[in] term_bin - * Symbol value, end of slice or not, term_bin is binary - * - * @returns - * - * @remarks - * None - * - ******************************************************************************* - */ void ih264e_cabac_encode_terminate(cabac_ctxt_t *ps_cabac, WORD32 term_bin); - -/** - ******************************************************************************* - * @brief - * Bypass encoding process for binary decisions: Explained (9.3.4.4 :ITU_T_H264-201402) - * , flowchart 9-10. - * - * @param[in] ps_cabac : pointer to cabac context (handle) - * - * @param[in] bin : bypass bin(0/1) to be encoded - * - * @returns - * - * @remarks - * None - * - ******************************************************************************* - */ - void ih264e_cabac_encode_bypass_bin(cabac_ctxt_t *ps_cabac, WORD32 bin); - - -/** - ****************************************************************************** - * - * @brief Encodes a series of bypass bins (FLC bypass bins) - * - * @par Description - * This function is more optimal than calling ih264e_cabac_encode_bypass_bin() - * in a loop as cabac low, renorm and generating the stream (8bins at a time) - * can be done in one operation - * - * @param[inout]ps_cabac - * pointer to cabac context (handle) - * - * @param[in] u4_bins - * syntax element to be coded (as FLC bins) - * - * @param[in] num_bins - * This is the FLC length for u4_sym - * - * @return - * - ****************************************************************************** - */ - void ih264e_cabac_encode_bypass_bins(cabac_ctxt_t *ps_cabac, UWORD32 u4_bins, WORD32 num_bins); - - - - -/** - ******************************************************************************* - * - * @brief - * This function generates CABAC coded bit stream for an Intra Slice. - * - * @description - * The mb syntax layer for intra slices constitutes luma mb mode, luma sub modes - * (if present), mb qp delta, coded block pattern, chroma mb mode and - * luma/chroma residue. These syntax elements are written as directed by table - * 7.3.5 of h264 specification. - * - * @param[in] ps_ent_ctxt - * pointer to entropy context - * - * @returns error code - * - * @remarks none - * - ******************************************************************************* - */ IH264E_ERROR_T ih264e_write_islice_mb_cabac(entropy_ctxt_t *ps_ent_ctxt); - -/** - ******************************************************************************* - * - * @brief - * This function generates CABAC coded bit stream for Inter slices - * - * @description - * The mb syntax layer for inter slices constitutes luma mb mode, luma sub modes - * (if present), mb qp delta, coded block pattern, chroma mb mode and - * luma/chroma residue. These syntax elements are written as directed by table - * 7.3.5 of h264 specification - * - * @param[in] ps_ent_ctxt - * pointer to entropy context - * - * @returns error code - * - * @remarks none - * - ******************************************************************************* - */ IH264E_ERROR_T ih264e_write_pslice_mb_cabac(entropy_ctxt_t *ps_ent_ctxt); - -/** - ******************************************************************************* - * - * @brief - * This function generates CABAC coded bit stream for B slices - * - * @description - * The mb syntax layer for inter slices constitutes luma mb mode, - * mb qp delta, coded block pattern, chroma mb mode and - * luma/chroma residue. These syntax elements are written as directed by table - * 7.3.5 of h264 specification - * - * @param[in] ps_ent_ctxt - * pointer to entropy context - * - * @returns error code - * - * @remarks none - * - ******************************************************************************* - */ IH264E_ERROR_T ih264e_write_bslice_mb_cabac(entropy_ctxt_t *ps_ent_ctxt); - -#endif /* IH264E_CABAC_H_ */ +#endif /* _IH264E_CABAC_H_ */ diff --git a/encoder/ih264e_cabac_encode.c b/encoder/ih264e_cabac_encode.c index d17e5fb5..156632c0 100644 --- a/encoder/ih264e_cabac_encode.c +++ b/encoder/ih264e_cabac_encode.c @@ -21,20 +21,34 @@ /** ******************************************************************************* * @file -* ih264e_cabac.c +* ih264e_cabac_encode.c * * @brief * Contains all functions to encode in CABAC entropy mode * -* * @author -* Doney Alex -* -* @par List of Functions: +* ittiam * +* @par List of Functions +* - ih264e_cabac_enc_mb_skip +* - ih264e_cabac_enc_intra_mb_type +* - ih264e_cabac_enc_4x4mb_modes +* - ih264e_cabac_enc_chroma_predmode +* - ih264e_cabac_enc_cbp +* - ih264e_cabac_enc_mb_qp_delta +* - ih264e_cabac_write_coeff4x4 +* - ih264e_cabac_encode_residue_luma_dc +* - ih264e_cabac_write_chroma_residue +* - ih264e_cabac_encode_residue +* - ih264e_cabac_enc_ctx_mvd +* - ih264e_cabac_enc_mvds_p16x16 +* - ih264e_cabac_enc_mvds_b16x16 +* - ih264e_write_islice_mb_cabac +* - ih264e_write_pslice_mb_cabac +* - ih264e_write_bslice_mb_cabac * * @remarks -* None +* none * ******************************************************************************* */ @@ -43,100 +57,55 @@ /* File Includes */ /*****************************************************************************/ -/* System include files */ +/* System Include Files */ #include #include #include #include -/* User include files */ +/* User Include Files */ #include "ih264e_config.h" #include "ih264_typedefs.h" #include "iv2.h" #include "ive2.h" + #include "ih264_debug.h" -#include "ih264_defs.h" -#include "ih264e_defs.h" #include "ih264_macros.h" -#include "ih264e_error.h" -#include "ih264e_bitstream.h" -#include "ime_distortion_metrics.h" -#include "ime_defs.h" -#include "ime_structs.h" #include "ih264_error.h" +#include "ih264_defs.h" +#include "ih264_mem_fns.h" +#include "ih264_padding.h" #include "ih264_structs.h" #include "ih264_trans_quant_itrans_iquant.h" #include "ih264_inter_pred_filters.h" -#include "ih264_mem_fns.h" -#include "ih264_padding.h" -#include "ih264_platform_macros.h" #include "ih264_intra_pred_filters.h" #include "ih264_deblk_edge_filters.h" +#include "ih264_cavlc_tables.h" #include "ih264_cabac_tables.h" +#include "ih264_platform_macros.h" + +#include "ime_defs.h" +#include "ime_distortion_metrics.h" +#include "ime_structs.h" + #include "irc_cntrl_param.h" #include "irc_frame_info_collector.h" -#include "ih264e_rate_control.h" + +#include "ih264e_error.h" +#include "ih264e_defs.h" +#include "ih264e_bitstream.h" #include "ih264e_cabac_structs.h" #include "ih264e_structs.h" -#include "ih264e_cabac.h" #include "ih264e_encode_header.h" -#include "ih264_cavlc_tables.h" -#include "ih264e_cavlc.h" +#include "ih264e_cabac.h" #include "ih264e_statistics.h" #include "ih264e_trace.h" /*****************************************************************************/ -/* Function Definitions */ +/* Global Definitions */ /*****************************************************************************/ - - - -/** - ******************************************************************************* - * - * @brief - * Encodes mb_skip_flag using CABAC entropy coding mode. - * - * @param[in] u1_mb_skip_flag - * mb_skip_flag - * - * @param[in] ps_cabac_ctxt - * Pointer to cabac context structure - * - * @param[in] u4_ctxidx_offset - * ctxIdxOffset for mb_skip_flag context - * - * @returns - * - * @remarks - * None - * - ******************************************************************************* - */ -static void ih264e_cabac_enc_mb_skip(UWORD8 u1_mb_skip_flag, - cabac_ctxt_t *ps_cabac_ctxt, - UWORD32 u4_ctxidx_offset) -{ - - UWORD8 u4_ctx_inc; - WORD8 a, b; - a = ((ps_cabac_ctxt->ps_left_ctxt_mb_info->u1_mb_type & CAB_SKIP_MASK) ? - 0 : 1); - b = ((ps_cabac_ctxt->ps_top_ctxt_mb_info->u1_mb_type & CAB_SKIP_MASK) ? - 0 : 1); - - u4_ctx_inc = a + b; - /* Encode the bin */ - ih264e_cabac_encode_bin(ps_cabac_ctxt, - (UWORD32) u1_mb_skip_flag, - ps_cabac_ctxt->au1_cabac_ctxt_table + u4_ctxidx_offset - + u4_ctx_inc); - -} - - -/* ! < Table 9-36 – Binarization for macroblock types in I slices in ITU_T_H264-201402 +/* ! < Table 9-36 : Binarization for macroblock types in I slices in ITU_T_H264 * Bits 0-7 : binarised value * Bits 8-15: length of binary sequence */ @@ -145,7 +114,6 @@ static const UWORD32 u4_mb_type_intra[26] = 0x074c, 0x074d, 0x074e, 0x074f, 0x0628, 0x0629, 0x062a, 0x062b, 0x0758, 0x0759, 0x075a, 0x075b, 0x075c, 0x075d, 0x075e, 0x075f, 0x0203 }; - /* CtxInc for mb types */ static const UWORD32 u4_mb_ctxinc[2][26] = { @@ -163,39 +131,97 @@ static const UWORD32 u4_mb_ctxinc[2][26] = 0x0012233, 0x0012233, 0x0012233, 0x00} }; +/* ! < Table 9-37 : Binarization for macroblock types in B slices in ITU_T_H264-201402 + * Bits 0-7 : binarised value + * Bits 8-15: length of binary sequence */ +static const UWORD32 u4_b_mb_type[27] = + { 0x0100, 0x0301, 0x0305, 0x0603, 0x0623, 0x0613, 0x0633, 0x060b, 0x062b, + 0x061b, 0x063b, 0x061f, 0x0707, 0x0747, 0x0727, 0x0767, 0x0717, 0x0757, + 0x0737, 0x0777, 0x070f, 0x074f, 0x063f }; + +/* CtxInc for mb types in B slices */ +static const UWORD32 ui_b_mb_type_ctx_inc[27] = + { 0x00, 0x0530, 0x0530, 0x0555430, 0x0555430, 0x0555430, 0x0555430, + 0x0555430, 0x0555430, 0x0555430, 0x0555430, 0x0555430, 0x05555430, + 0x05555430, 0x05555430, 0x05555430, 0x05555430, 0x05555430, 0x05555430, + 0x05555430, 0x05555430, 0x05555430, 0x0555430 }; + + +/*****************************************************************************/ +/* Function Definitions */ +/*****************************************************************************/ /** - ******************************************************************************* - * - * @brief - * Encodes mb_type for an intra MB. - * - * @param[in] u4_slice_type - * slice type - * - * @param[in] u4_intra_mb_type - * MB type (Table 7-11) - * - * @param[in] ps_cabac_ctxt - * Pointer to cabac context structure - * - ** @param[in] u4_ctxidx_offset - * ctxIdxOffset for mb_type context - * - * @returns - * - * @remarks - * None - * - ******************************************************************************* - */ +******************************************************************************* +* +* @brief +* Encodes mb_skip_flag using CABAC entropy coding mode. +* +* @param[in] u1_mb_skip_flag +* mb_skip_flag +* +* @param[in] ps_cabac_ctxt +* Pointer to cabac context structure +* +* @param[in] u4_ctxidx_offset +* ctxIdxOffset for mb_skip_flag context +* +* @returns none +* +* @remarks none +* +******************************************************************************* +*/ +static void ih264e_cabac_enc_mb_skip(UWORD8 u1_mb_skip_flag, + cabac_ctxt_t *ps_cabac_ctxt, + UWORD32 u4_ctxidx_offset) +{ + UWORD8 u4_ctx_inc; + WORD8 a, b; + + a = ((ps_cabac_ctxt->ps_left_ctxt_mb_info->u1_mb_type & CAB_SKIP_MASK) ? + 0 : 1); + b = ((ps_cabac_ctxt->ps_top_ctxt_mb_info->u1_mb_type & CAB_SKIP_MASK) ? + 0 : 1); + + u4_ctx_inc = a + b; + + /* Encode the bin */ + ih264e_cabac_encode_bin(ps_cabac_ctxt, + (UWORD32) u1_mb_skip_flag, + ps_cabac_ctxt->au1_cabac_ctxt_table + + u4_ctxidx_offset + u4_ctx_inc); +} +/** +******************************************************************************* +* +* @brief +* Encodes mb_type for an intra MB. +* +* @param[in] u4_slice_type +* slice type +* +* @param[in] u4_intra_mb_type +* MB type (Table 7-11) +* +* @param[in] ps_cabac_ctxt +* Pointer to cabac context structure +* +* @param[in] u4_ctxidx_offset +* ctxIdxOffset for mb_type context +* +* @returns none +* +* @remarks none +* +******************************************************************************* +*/ static void ih264e_cabac_enc_intra_mb_type(UWORD32 u4_slice_type, UWORD32 u4_intra_mb_type, cabac_ctxt_t *ps_cabac_ctxt, UWORD32 u4_ctx_idx_offset) { - encoding_envirnoment_t *ps_cab_enc_env = &(ps_cabac_ctxt->s_cab_enc_env); bin_ctxt_model *pu1_mb_bin_ctxt, *pu1_bin_ctxt; UWORD8 u1_bin; @@ -252,8 +278,7 @@ static void ih264e_cabac_enc_intra_mb_type(UWORD32 u4_slice_type, WORD8 i1_state = (*pu1_bin_ctxt) & 0x3F; u2_quant_code_int_range = ((u4_code_int_range >> 6) & 0x03); - u4_table_val = - gau4_ih264_cabac_table[i1_state][u2_quant_code_int_range]; + u4_table_val = gau4_ih264_cabac_table[i1_state][u2_quant_code_int_range]; u4_code_int_range_lps = u4_table_val & 0xFF; u4_code_int_range -= u4_code_int_range_lps; @@ -303,39 +328,36 @@ static void ih264e_cabac_enc_intra_mb_type(UWORD32 u4_slice_type, ih264e_cabac_put_byte(ps_cabac_ctxt); u4_code_int_range = ps_cab_enc_env->u4_code_int_range; u4_code_int_low = ps_cab_enc_env->u4_code_int_low; - } } } - - /** - ******************************************************************************* - * - * @brief - * Encodes prev_intra4x4_pred_mode_flag and - * rem_intra4x4_pred_mode using CABAC entropy coding mode - * - * @param[in] ps_cabac_ctxt - * Pointer to cabac context structure - * - * @param[in] pu1_intra_4x4_modes - * Pointer to array containing prev_intra4x4_pred_mode_flag and - * rem_intra4x4_pred_mode - * - * @returns - * - * @remarks - * None - * - ******************************************************************************* - */ +******************************************************************************* +* +* @brief +* Encodes prev_intra4x4_pred_mode_flag and rem_intra4x4_pred_mode using +* CABAC entropy coding mode +* +* @param[in] ps_cabac_ctxt +* Pointer to cabac context structure +* +* @param[in] pu1_intra_4x4_modes +* Pointer to array containing prev_intra4x4_pred_mode_flag and +* rem_intra4x4_pred_mode +* +* @returns none +* +* @remarks none +* +******************************************************************************* +*/ static void ih264e_cabac_enc_4x4mb_modes(cabac_ctxt_t *ps_cabac_ctxt, UWORD8 *pu1_intra_4x4_modes) { WORD32 i; WORD8 byte; + for (i = 0; i < 16; i += 2) { /* sub blk idx 1 */ @@ -380,31 +402,27 @@ static void ih264e_cabac_enc_4x4mb_modes(cabac_ctxt_t *ps_cabac_ctxt, } } - - /** - ******************************************************************************* - * - * @brief - * Encodes chroma intrapred mode for the MB. - * - * @param[in] u1_chroma_pred_mode - * Chroma intr prediction mode - * - * @param[in] ps_cabac_ctxt - * Pointer to cabac context structure - * - * @returns - * - * @remarks - * None - * - ******************************************************************************* - */ +******************************************************************************* +* +* @brief +* Encodes chroma intra pred mode for the MB. +* +* @param[in] u1_chroma_pred_mode +* Chroma intra prediction mode +* +* @param[in] ps_cabac_ctxt +* Pointer to cabac context structure +* +* @returns none +* +* @remarks none +* +******************************************************************************* +*/ static void ih264e_cabac_enc_chroma_predmode(UWORD8 u1_chroma_pred_mode, cabac_ctxt_t *ps_cabac_ctxt) { - WORD8 i1_temp; mb_info_ctxt_t *ps_curr_ctxt = ps_cabac_ctxt->ps_curr_ctxt_mb_info; mb_info_ctxt_t *ps_left_ctxt = ps_cabac_ctxt->ps_left_ctxt_mb_info; @@ -413,6 +431,7 @@ static void ih264e_cabac_enc_chroma_predmode(UWORD8 u1_chroma_pred_mode, WORD8 i1_bins_len = 1; UWORD32 u4_ctx_inc = 0; UWORD8 a, b; + a = ((ps_left_ctxt->u1_intrapred_chroma_mode != 0) ? 1 : 0); b = ((ps_top_ctxt->u1_intrapred_chroma_mode != 0) ? 1 : 0); @@ -447,29 +466,25 @@ static void ih264e_cabac_enc_chroma_predmode(UWORD8 u1_chroma_pred_mode, ps_cabac_ctxt->au1_cabac_ctxt_table + INTRA_CHROMA_PRED_MODE, ps_cabac_ctxt); - } - /** - ******************************************************************************* - * - * @brief - * Encodes CBP for the MB. - * - * @param[in] u1_cbp - * CBP for the MB - * - * @param[in] ps_cabac_ctxt - * Pointer to cabac context structure - * - * @returns - * - * @remarks - * None - * - ******************************************************************************* - */ +******************************************************************************* +* +* @brief Encodes CBP for the MB. +* +* @param[in] u1_cbp +* CBP for the MB +* +* @param[in] ps_cabac_ctxt +* Pointer to cabac context structure +* +* @returns none +* +* @remarks none +* +******************************************************************************* +*/ static void ih264e_cabac_enc_cbp(UWORD32 u4_cbp, cabac_ctxt_t *ps_cabac_ctxt) { mb_info_ctxt_t *ps_left_ctxt = ps_cabac_ctxt->ps_left_ctxt_mb_info; @@ -555,38 +570,36 @@ static void ih264e_cabac_enc_cbp(UWORD32 u4_cbp, cabac_ctxt_t *ps_cabac_ctxt) ps_cabac_ctxt); } - /** - ******************************************************************************* - * - * @brief - * Encodes mb_qp_delta for the MB. - * - * @param[in] i1_mb_qp_delta - * mb_qp_delta - * - * @param[in] ps_cabac_ctxt - * Pointer to cabac context structure - * - * @returns - * - * @remarks - * None - * - ******************************************************************************* - */ +******************************************************************************* +* +* @brief Encodes mb_qp_delta for the MB. +* +* @param[in] i1_mb_qp_delta +* mb_qp_delta +* +* @param[in] ps_cabac_ctxt +* Pointer to cabac context structure +* +* @returns none +* +* @remarks none +* +******************************************************************************* +*/ static void ih264e_cabac_enc_mb_qp_delta(WORD8 i1_mb_qp_delta, cabac_ctxt_t *ps_cabac_ctxt) { UWORD8 u1_code_num; UWORD8 u1_ctxt_inc; - UWORD32 u4_ctx_inc; UWORD32 u4_bins; WORD8 i1_bins_len; UWORD8 u1_ctx_inc, u1_bin; + /* Range of ps_mb_qp_delta_ctxt= -26 to +25 inclusive */ - ASSERT((i1_mb_qp_delta < 26) && (i1_mb_qp_delta > -27)); + ASSERT((i1_mb_qp_delta < 26) && (i1_mb_qp_delta > -27)); + /* if ps_mb_qp_delta_ctxt=0, then codeNum=0 */ u1_code_num = 0; if (i1_mb_qp_delta > 0) @@ -692,42 +705,38 @@ static void ih264e_cabac_enc_mb_qp_delta(WORD8 i1_mb_qp_delta, } } - - - /** - ******************************************************************************* - * @brief - * Encodes 4residual_block_cabac as defined in 7.3.5.3.3. - * - * @param[in] pi2_res_block - * pointer to the array of residues - * - * @param[in] u1_nnz - * Number of non zero coeffs in the block - * - * @param[in] u1_max_num_coeffs - * Max number of coeffs that can be there in the block - * - * @param[in] u2_sig_coeff_map - * Significant coeff map - * - * @param[in] u4_ctx_cat_offset - * ctxIdxOffset for absolute value contexts - * - * @param[in] pu1_ctxt_sig_coeff - * Pointer to residual state variables - * - * @param[in] ps_cabac_ctxt - * Pointer to cabac context structure - * - * @returns - * - * @remarks - * None - * - ******************************************************************************* - */ +******************************************************************************* +* @brief +* Encodes 4x4 residual_block_cabac as defined in 7.3.5.3.3. +* +* @param[in] pi2_res_block +* pointer to the array of residues +* +* @param[in] u1_nnz +* Number of non zero coeffs in the block +* +* @param[in] u1_max_num_coeffs +* Max number of coeffs that can be there in the block +* +* @param[in] u2_sig_coeff_map +* Significant coeff map +* +* @param[in] u4_ctx_cat_offset +* ctxIdxOffset for absolute value contexts +* +* @param[in] pu1_ctxt_sig_coeff +* Pointer to residual state variables +* +* @param[in] ps_cabac_ctxt +* Pointer to cabac context structure +* +* @returns none +* +* @remarks none +* +******************************************************************************* +*/ static void ih264e_cabac_write_coeff4x4(WORD16 *pi2_res_block, UWORD8 u1_nnz, UWORD8 u1_max_num_coeffs, UWORD16 u2_sig_coeff_map, @@ -735,7 +744,6 @@ static void ih264e_cabac_write_coeff4x4(WORD16 *pi2_res_block, UWORD8 u1_nnz, bin_ctxt_model *pu1_ctxt_sig_coeff, cabac_ctxt_t *ps_cabac_ctxt) { - WORD8 i; WORD16 *pi16_coeffs; UWORD32 u4_sig_coeff, u4_bins; @@ -743,152 +751,151 @@ static void ih264e_cabac_write_coeff4x4(WORD16 *pi2_res_block, UWORD8 u1_nnz, UWORD8 u1_last_sig_coef_index = (31 - CLZ(u2_sig_coeff_map)); /* Always put Coded Block Flag as 1 */ + pi16_coeffs = pi2_res_block; + { + bin_ctxt_model *pu1_bin_ctxt; + UWORD8 u1_bin, uc_last; + + i = 0; + pu1_bin_ctxt = pu1_ctxt_sig_coeff; + u4_sig_coeff = 0; + u1_bin = 1; + if ((u1_last_sig_coef_index)) + { + u1_bin = !!(u2_sig_coeff_map & 01); + } + uc_last = 1; - pi16_coeffs = pi2_res_block; + do { - bin_ctxt_model *pu1_bin_ctxt; - UWORD8 u1_bin, uc_last; - - i = 0; - pu1_bin_ctxt = pu1_ctxt_sig_coeff; - u4_sig_coeff = 0; - u1_bin = 1; - if ((u1_last_sig_coef_index)) + /* Encode Decision */ + ih264e_cabac_encode_bin(ps_cabac_ctxt, u1_bin, pu1_bin_ctxt); + + if (u1_bin & uc_last) { - u1_bin = !!(u2_sig_coeff_map & 01); + u4_sig_coeff = (u4_sig_coeff | (1 << i)); + pu1_bin_ctxt = pu1_ctxt_sig_coeff + i + + LAST_SIGNIFICANT_COEFF_FLAG_FRAME + - SIGNIFICANT_COEFF_FLAG_FRAME; + u1_bin = (i == u1_last_sig_coef_index); + uc_last = 0; } - uc_last = 1; - - do + else { - /* Encode Decision */ - ih264e_cabac_encode_bin(ps_cabac_ctxt, u1_bin, pu1_bin_ctxt); - - if (u1_bin & uc_last) + i = i + 1; + pu1_bin_ctxt = pu1_ctxt_sig_coeff + i; + u1_bin = (i == u1_last_sig_coef_index); + uc_last = 1; + if ((i != u1_last_sig_coef_index)) { - u4_sig_coeff = (u4_sig_coeff | (1 << i)); - pu1_bin_ctxt = pu1_ctxt_sig_coeff + i - + LAST_SIGNIFICANT_COEFF_FLAG_FRAME - - SIGNIFICANT_COEFF_FLAG_FRAME; - u1_bin = (i == u1_last_sig_coef_index); - uc_last = 0; + u1_bin = !!((u2_sig_coeff_map >> i) & 01); } - else - { - i = i + 1; - pu1_bin_ctxt = pu1_ctxt_sig_coeff + i; - u1_bin = (i == u1_last_sig_coef_index); - uc_last = 1; - if ((i != u1_last_sig_coef_index)) - { - u1_bin = !!((u2_sig_coeff_map >> i) & 01); - } - } - }while (!((i > u1_last_sig_coef_index) - || (i > (u1_max_num_coeffs - 1)))); - } + } + } while (!((i > u1_last_sig_coef_index) || (i > (u1_max_num_coeffs - 1)))); + } - /* Encode coeff_abs_level_minus1 and coeff_sign_flag */ + /* Encode coeff_abs_level_minus1 and coeff_sign_flag */ + { + UWORD8 u1_sign; + UWORD16 u2_abs_level; + UWORD8 u1_abs_level_equal1 = 1, u1_abs_level_gt1 = 0; + UWORD8 u1_ctx_inc; + UWORD8 u1_coff; + WORD16 i2_sufs; + WORD8 i1_bins_len; + + i = u1_last_sig_coef_index; + pi16_coeffs = pi2_res_block + u1_nnz - 1; + do { - UWORD8 u1_sign; - UWORD16 u2_abs_level; - UWORD8 u1_abs_level_equal1 = 1, u1_abs_level_gt1 = 0; - UWORD8 u1_ctx_inc; - UWORD8 u1_coff; - WORD16 i2_sufs; - WORD8 i1_bins_len; - i = u1_last_sig_coef_index; - pi16_coeffs = pi2_res_block + u1_nnz - 1; - do { + u4_sig_coeff = u4_sig_coeff & ((1 << i) - 1); + u4_bins = 0; + u4_ctx_inc = 0; + i1_bins_len = 1; + /* Encode the AbsLevelMinus1 */ + u2_abs_level = ABS(*(pi16_coeffs)) - 1; + /* CtxInc for bin0 */ + u4_ctx_inc = MIN(u1_abs_level_equal1, 4); + /* CtxInc for remaining */ + u1_ctx_inc = 5 + MIN(u1_abs_level_gt1, 4); + u4_ctx_inc = u4_ctx_inc + (u1_ctx_inc << 4); + if (u2_abs_level) { - u4_sig_coeff = u4_sig_coeff & ((1 << i) - 1); - u4_bins = 0; - u4_ctx_inc = 0; - i1_bins_len = 1; - /* Encode the AbsLevelMinus1 */ - u2_abs_level = ABS(*(pi16_coeffs)) - 1; - /* CtxInc for bin0 */ - u4_ctx_inc = MIN(u1_abs_level_equal1, 4); - /* CtxInc for remaining */ - u1_ctx_inc = 5 + MIN(u1_abs_level_gt1, 4); - u4_ctx_inc = u4_ctx_inc + (u1_ctx_inc << 4); - if (u2_abs_level) - { - u1_abs_level_gt1++; - u1_abs_level_equal1 = 0; - } - if (!u1_abs_level_gt1) - u1_abs_level_equal1++; + u1_abs_level_gt1++; + u1_abs_level_equal1 = 0; + } + if (!u1_abs_level_gt1) + u1_abs_level_equal1++; - u1_coff = 14; - if (u2_abs_level >= u1_coff) - { - /* Prefix TU i.e string of 14 1's */ - u4_bins = 0x3fff; - i1_bins_len = 14; - ih264e_encode_decision_bins(u4_bins, i1_bins_len, - u4_ctx_inc, 1, ps_cabac_ctxt->au1_cabac_ctxt_table + u1_coff = 14; + if (u2_abs_level >= u1_coff) + { + /* Prefix TU i.e string of 14 1's */ + u4_bins = 0x3fff; + i1_bins_len = 14; + ih264e_encode_decision_bins( + u4_bins, + i1_bins_len, + u4_ctx_inc, + 1, + ps_cabac_ctxt->au1_cabac_ctxt_table + u4_ctx_cat_offset, - ps_cabac_ctxt); - - /* Suffix, uses EncodeBypass */ - i2_sufs = u2_abs_level - u1_coff; + ps_cabac_ctxt); - u4_bins = ih264e_cabac_UEGk0_binarization(i2_sufs, - &i1_bins_len); + /* Suffix, uses EncodeBypass */ + i2_sufs = u2_abs_level - u1_coff; - ih264e_cabac_encode_bypass_bins(ps_cabac_ctxt, u4_bins, - i1_bins_len); + u4_bins = ih264e_cabac_UEGk0_binarization(i2_sufs, + &i1_bins_len); - } - else - { - /* Prefix only */ - u4_bins = (1 << u2_abs_level) - 1; - i1_bins_len = u2_abs_level + 1; - /* Encode Terminating bit */ - ih264e_encode_decision_bins(u4_bins, i1_bins_len, - u4_ctx_inc, 1, ps_cabac_ctxt->au1_cabac_ctxt_table + ih264e_cabac_encode_bypass_bins(ps_cabac_ctxt, u4_bins, + i1_bins_len); + } + else + { + /* Prefix only */ + u4_bins = (1 << u2_abs_level) - 1; + i1_bins_len = u2_abs_level + 1; + /* Encode Terminating bit */ + ih264e_encode_decision_bins( + u4_bins, + i1_bins_len, + u4_ctx_inc, + 1, + ps_cabac_ctxt->au1_cabac_ctxt_table + u4_ctx_cat_offset, - ps_cabac_ctxt); - } + ps_cabac_ctxt); } - /* encode coeff_sign_flag[i] */ - u1_sign = ((*pi16_coeffs) < 0) ? 1 : 0; - ih264e_cabac_encode_bypass_bin(ps_cabac_ctxt, u1_sign); - i = CLZ(u4_sig_coeff); - i = 31 - i; - pi16_coeffs--; - }while (u4_sig_coeff); - } - + } + /* encode coeff_sign_flag[i] */ + u1_sign = ((*pi16_coeffs) < 0) ? 1 : 0; + ih264e_cabac_encode_bypass_bin(ps_cabac_ctxt, u1_sign); + i = CLZ(u4_sig_coeff); + i = 31 - i; + pi16_coeffs--; + } while (u4_sig_coeff); + } } - /** - ******************************************************************************* - * @brief - * Write DC coeffs for intra predicted luma block - * - * @param[in] ps_ent_ctxt - * Pointer to entropy context structure - * - * @returns - * - * @remarks - * None - * - ******************************************************************************* - */ +******************************************************************************* +* @brief +* Write DC coeffs for intra predicted luma block +* +* @param[in] ps_ent_ctxt +* Pointer to entropy context structure +* +* @returns none +* +* @remarks none +* +******************************************************************************* +*/ static void ih264e_cabac_encode_residue_luma_dc(entropy_ctxt_t *ps_ent_ctxt) { - - /* CABAC context */ cabac_ctxt_t *ps_cabac_ctxt = ps_ent_ctxt->ps_cabac; tu_sblk_coeff_data_t *ps_mb_coeff_data; - - /* packed residue */ void *pv_mb_coeff_data = ps_ent_ctxt->pv_mb_coeff_data; UWORD16 u2_sig_coeff_map; WORD16 *pi2_res_block; @@ -941,34 +948,28 @@ static void ih264e_cabac_encode_residue_luma_dc(entropy_ctxt_t *ps_ent_ctxt) ps_ent_ctxt->pv_mb_coeff_data = pv_mb_coeff_data; } - - - /** - ******************************************************************************* - * @brief - * Write chroma residues to the bitstream - * - * @param[in] ps_ent_ctxt - * Pointer to entropy context structure - * - * @param[in] u1_chroma_cbp - * coded block pattern, chroma - * - * @returns - * - * @remarks - * None - * - ******************************************************************************* - */ +******************************************************************************* +* @brief +* Write chroma residues to the bitstream +* +* @param[in] ps_ent_ctxt +* Pointer to entropy context structure +* +* @param[in] u1_chroma_cbp +* coded block pattern, chroma +* +* @returns none +* +* @remarks none +* +******************************************************************************* +*/ static void ih264e_cabac_write_chroma_residue(entropy_ctxt_t *ps_ent_ctxt, UWORD8 u1_chroma_cbp) { - /* CABAC context */ cabac_ctxt_t *ps_cabac_ctxt = ps_ent_ctxt->ps_cabac; tu_sblk_coeff_data_t *ps_mb_coeff_data; - /* packed residue */ void *pv_mb_coeff_data = ps_ent_ctxt->pv_mb_coeff_data; UWORD16 u2_sig_coeff_map; UWORD8 u1_nnz; @@ -1114,38 +1115,31 @@ static void ih264e_cabac_write_chroma_residue(entropy_ctxt_t *ps_ent_ctxt, ps_ent_ctxt->pv_mb_coeff_data = pv_mb_coeff_data; } - - - /** - ******************************************************************************* - * @brief - * Encodes Residues for the MB as defined in 7.3.5.3 - * - * @param[in] ps_ent_ctxt - * Pointer to entropy context structure - * - * @param[in] u1_cbp - * coded block pattern - * - * @param[in] u1_ctx_cat - * Context category, LUMA_AC_CTXCAT or LUMA_4x4_CTXCAT - * - * @returns - * - * @remarks - * None - * - ******************************************************************************* - */ +******************************************************************************* +* @brief +* Encodes Residues for the MB as defined in 7.3.5.3 +* +* @param[in] ps_ent_ctxt +* Pointer to entropy context structure +* +* @param[in] u1_cbp +* coded block pattern +* +* @param[in] u1_ctx_cat +* Context category, LUMA_AC_CTXCAT or LUMA_4x4_CTXCAT +* +* @returns none +* +* @remarks none +* +******************************************************************************* +*/ static void ih264e_cabac_encode_residue(entropy_ctxt_t *ps_ent_ctxt, UWORD32 u4_cbp, UWORD8 u1_ctx_cat) { - /* CABAC context */ cabac_ctxt_t *ps_cabac_ctxt = ps_ent_ctxt->ps_cabac; - tu_sblk_coeff_data_t *ps_mb_coeff_data; - /* packed residue */ void *pv_mb_coeff_data = ps_ent_ctxt->pv_mb_coeff_data; UWORD16 u2_sig_coeff_map; UWORD8 u1_nnz; @@ -1154,6 +1148,7 @@ static void ih264e_cabac_encode_residue(entropy_ctxt_t *ps_ent_ctxt, UWORD8 u1_left_ac_csbp; UWORD8 u1_top_ac_csbp; UWORD32 u4_ctx_idx_offset_sig_coef, u4_ctx_idx_offset_abs_lvl; + ps_curr_ctxt = ps_cabac_ctxt->ps_curr_ctxt_mb_info; ps_top_ctxt = ps_cabac_ctxt->ps_top_ctxt_mb_info; u1_left_ac_csbp = ps_cabac_ctxt->pu1_left_y_ac_csbp[0]; @@ -1193,10 +1188,10 @@ static void ih264e_cabac_encode_residue(entropy_ctxt_t *ps_ent_ctxt, if (!((u4_cbp >> u1_b3b2) & 0x1)) { - /* ---------------------------------------------------------- */ + /************************************************************/ /* The current block is not coded so skip all the sub block */ /* and set the pointer of scan level, csbp accrodingly */ - /* ---------------------------------------------------------- */ + /************************************************************/ CLEARBIT(u1_top_ac_csbp, u1_b2b0); CLEARBIT(u1_top_ac_csbp, (u1_b2b0 + 1)); CLEARBIT(u1_left_ac_csbp, u1_b3b1); @@ -1267,7 +1262,6 @@ static void ih264e_cabac_encode_residue(entropy_ctxt_t *ps_ent_ctxt, } /* Write chroma residue */ - ps_ent_ctxt->pv_mb_coeff_data = pv_mb_coeff_data; { UWORD8 u1_cbp_chroma; @@ -1287,34 +1281,32 @@ static void ih264e_cabac_encode_residue(entropy_ctxt_t *ps_ent_ctxt, } /** - ******************************************************************************* - * @brief - * Encodes a Motion vector (9.3.3.1.1.7 ) - * - * @param[in] u1_mvd - * Motion vector to be encoded - * - * @param[in] u4_ctx_idx_offset - * * ctxIdxOffset for MV_X or MV_Ycontext - * - * @param[in] ui2_abs_mvd - * sum of absolute value of corresponding neighboring motion vectors - * - * @param[in] ps_cabac_ctxt - * Pointer to cabac context structure - * - * @returns - * - * @remarks - * None - * - ******************************************************************************* - */ +******************************************************************************* +* @brief +* Encodes a Motion vector (Sec. 9.3.3.1.1.7 ITU T. H264) +* +* @param[in] u1_mvd +* Motion vector to be encoded +* +* @param[in] u4_ctx_idx_offset +* ctxIdxOffset for MV_X or MV_Ycontext +* +* @param[in] ui2_abs_mvd +* sum of absolute value of corresponding neighboring motion vectors +* +* @param[in] ps_cabac_ctxt +* Pointer to cabac context structure +* +* @returns none +* +* @remarks none +* +******************************************************************************* +*/ static void ih264e_cabac_enc_ctx_mvd(WORD16 u1_mvd, UWORD32 u4_ctx_idx_offset, UWORD16 ui2_abs_mvd, cabac_ctxt_t *ps_cabac_ctxt) { - UWORD8 u1_bin, u1_ctxt_inc; WORD8 k = 3, u1_coff = 9; WORD16 i2_abs_mvd, i2_sufs; @@ -1322,16 +1314,6 @@ static void ih264e_cabac_enc_ctx_mvd(WORD16 u1_mvd, UWORD32 u4_ctx_idx_offset, UWORD32 u4_bins; WORD8 i1_bins_len; - /* if mvd < u1_coff - only Prefix - else - Prefix + Suffix - - encode sign bit - - Prefix TU encoding Cmax =u1_coff and Suffix 3rd order Exp-Golomb - */ - if (ui2_abs_mvd < 3) u4_ctx_inc = 0; else if (ui2_abs_mvd > 32) @@ -1436,34 +1418,31 @@ static void ih264e_cabac_enc_ctx_mvd(WORD16 u1_mvd, UWORD32 u4_ctx_idx_offset, } /** - ******************************************************************************* - * @brief - * Encodes all motion vectors for a P16x16 MB - * - * @param[in] ps_cabac_ctxt - * Pointer to cabac context structure - * - * @param[in] pi2_mv_ptr - * Pointer to array of motion vectors - * - * @returns - * - * @remarks - * None - * - ******************************************************************************* - */ +******************************************************************************* +* @brief +* Encodes all motion vectors for a P16x16 MB +* +* @param[in] ps_cabac_ctxt +* Pointer to cabac context structure +* +* @param[in] pi2_mv_ptr +* Pointer to array of motion vectors +* +* @returns none +* +* @remarks none +* +******************************************************************************* +*/ static void ih264e_cabac_enc_mvds_p16x16(cabac_ctxt_t *ps_cabac_ctxt, WORD16 *pi2_mv_ptr) { - - /* Encode the differential component of the motion vectors */ - { UWORD8 u1_abs_mvd_x, u1_abs_mvd_y; UWORD8 *pu1_top_mv_ctxt, *pu1_lft_mv_ctxt; WORD16 u2_mv; + u1_abs_mvd_x = 0; u1_abs_mvd_y = 0; pu1_top_mv_ctxt = ps_cabac_ctxt->ps_curr_ctxt_mb_info->u1_mv[0]; @@ -1498,36 +1477,34 @@ static void ih264e_cabac_enc_mvds_p16x16(cabac_ctxt_t *ps_cabac_ctxt, } } - /** - ******************************************************************************* - * @brief - * Encodes all motion vectors for a B MB (Assues that mbype is B_L0_16x16, B_L1_16x16 or B_Bi_16x16 - * - * @param[in] ps_cabac_ctxt - * Pointer to cabac context structure - * - * @param[in] pi2_mv_ptr - * Pointer to array of motion vectors - * - * @returns - * - * @remarks - * None - * - ******************************************************************************* - */ +******************************************************************************* +* @brief +* Encodes all motion vectors for a B MB (Assumes that mbype is B_L0_16x16, +* B_L1_16x16 or B_Bi_16x16 +* +* @param[in] ps_cabac_ctxt +* Pointer to cabac context structure +* +* @param[in] pi2_mv_ptr +* Pointer to array of motion vectors +* +* @returns none +* +* @remarks none +* +******************************************************************************* +*/ static void ih264e_cabac_enc_mvds_b16x16(cabac_ctxt_t *ps_cabac_ctxt, WORD16 *pi2_mv_ptr, WORD32 i4_mb_part_pred_mode ) { - /* Encode the differential component of the motion vectors */ - { UWORD8 u1_abs_mvd_x, u1_abs_mvd_y; UWORD8 *pu1_top_mv_ctxt, *pu1_lft_mv_ctxt; WORD16 u2_mv; + u1_abs_mvd_x = 0; u1_abs_mvd_y = 0; pu1_top_mv_ctxt = ps_cabac_ctxt->ps_curr_ctxt_mb_info->u1_mv[0]; @@ -1595,35 +1572,30 @@ static void ih264e_cabac_enc_mvds_b16x16(cabac_ctxt_t *ps_cabac_ctxt, } } - - /** - ******************************************************************************* - * - * @brief - * This function generates CABAC coded bit stream for an Intra Slice. - * - * @description - * The mb syntax layer for intra slices constitutes luma mb mode, mb qp delta, coded block pattern, chroma mb mode and - * luma/chroma residue. These syntax elements are written as directed by table - * 7.3.5 of h264 specification. - * - * @param[in] ps_ent_ctxt - * pointer to entropy context - * - * @returns error code - * - * @remarks none - * - ******************************************************************************* - */ +******************************************************************************* +* +* @brief +* This function generates CABAC coded bit stream for an Intra Slice. +* +* @description +* The mb syntax layer for intra slices constitutes luma mb mode, mb qp delta, +* coded block pattern, chroma mb mode and luma/chroma residue. These syntax +* elements are written as directed by table 7.3.5 of h264 specification. +* +* @param[in] ps_ent_ctxt +* pointer to entropy context +* +* @returns error code +* +* @remarks none +* +******************************************************************************* +*/ IH264E_ERROR_T ih264e_write_islice_mb_cabac(entropy_ctxt_t *ps_ent_ctxt) { - /* bit stream ptr */ bitstrm_t *ps_bitstream = ps_ent_ctxt->ps_bitstrm; - /* CABAC context */ cabac_ctxt_t *ps_cabac_ctxt = ps_ent_ctxt->ps_cabac; - /* packed header data */ UWORD8 *pu1_byte = ps_ent_ctxt->pv_mb_header_data; mb_hdr_common_t *ps_mb_hdr = (mb_hdr_common_t *)ps_ent_ctxt->pv_mb_header_data; mb_info_ctxt_t *ps_curr_ctxt; @@ -1748,34 +1720,30 @@ IH264E_ERROR_T ih264e_write_islice_mb_cabac(entropy_ctxt_t *ps_ent_ctxt) } /** - ******************************************************************************* - * - * @brief - * This function generates CABAC coded bit stream for Inter slices - * - * @description - * The mb syntax layer for inter slices constitutes luma mb mode, mb qp delta, coded block pattern, chroma mb mode and - * luma/chroma residue. These syntax elements are written as directed by table - * 7.3.5 of h264 specification - * - * @param[in] ps_ent_ctxt - * pointer to entropy context - * - * @returns error code - * - * @remarks none - * - ******************************************************************************* - */ +******************************************************************************* +* +* @brief +* This function generates CABAC coded bit stream for Inter slices +* +* @description +* The mb syntax layer for inter slices constitutes luma mb mode, mb qp delta, +* coded block pattern, chroma mb mode and luma/chroma residue. These syntax +* elements are written as directed by table 7.3.5 of h264 specification +* +* @param[in] ps_ent_ctxt +* pointer to entropy context +* +* @returns error code +* +* @remarks none +* +******************************************************************************* +*/ IH264E_ERROR_T ih264e_write_pslice_mb_cabac(entropy_ctxt_t *ps_ent_ctxt) { - /* bit stream ptr */ bitstrm_t *ps_bitstream = ps_ent_ctxt->ps_bitstrm; - /* CABAC context */ cabac_ctxt_t *ps_cabac_ctxt = ps_ent_ctxt->ps_cabac; - mb_info_ctxt_t *ps_curr_ctxt; - WORD32 bitstream_start_offset, bitstream_end_offset; WORD32 mb_tpm, mb_type, cbp, chroma_intra_mode, luma_intra_mode; WORD8 mb_qp_delta; @@ -2014,61 +1982,31 @@ IH264E_ERROR_T ih264e_write_pslice_mb_cabac(entropy_ctxt_t *ps_ent_ctxt) } } - -/* ! < Table 9-37 – Binarization for macroblock types in B slices in ITU_T_H264-201402 - * Bits 0-7 : binarised value - * Bits 8-15: length of binary sequence */ - - -static const UWORD32 u4_b_mb_type[27] = { 0x0100, 0x0301, 0x0305, 0x0603, - 0x0623, 0x0613, 0x0633, 0x060b, - 0x062b, 0x061b, 0x063b, 0x061f, - 0x0707, 0x0747, 0x0727, 0x0767, - 0x0717, 0x0757, 0x0737, 0x0777, - 0x070f, 0x074f, 0x063f }; -/* CtxInc for mb types in B slices */ -static const UWORD32 ui_b_mb_type_ctx_inc[27] = { 0x00, 0x0530, 0x0530, - 0x0555430, 0x0555430, - 0x0555430, 0x0555430, - 0x0555430, 0x0555430, - 0x0555430, 0x0555430, - 0x0555430, 0x05555430, - 0x05555430, 0x05555430, - 0x05555430, 0x05555430, - 0x05555430, 0x05555430, - 0x05555430, 0x05555430, - 0x05555430, 0x0555430 }; - /** - ******************************************************************************* - * - * @brief - * This function generates CABAC coded bit stream for B slices - * - * @description - * The mb syntax layer for inter slices constitutes luma mb mode, - * mb qp delta, coded block pattern, chroma mb mode and - * luma/chroma residue. These syntax elements are written as directed by table - * 7.3.5 of h264 specification - * - * @param[in] ps_ent_ctxt - * pointer to entropy context - * - * @returns error code - * - * @remarks none - * - ******************************************************************************* - */ +******************************************************************************* +* +* @brief +* This function generates CABAC coded bit stream for B slices +* +* @description +* The mb syntax layer for inter slices constitutes luma mb mode, mb qp delta, +* coded block pattern, chroma mb mode and luma/chroma residue. These syntax +* elements are written as directed by table 7.3.5 of h264 specification +* +* @param[in] ps_ent_ctxt +* pointer to entropy context +* +* @returns error code +* +* @remarks none +* +******************************************************************************* +*/ IH264E_ERROR_T ih264e_write_bslice_mb_cabac(entropy_ctxt_t *ps_ent_ctxt) { - /* bit stream ptr */ bitstrm_t *ps_bitstream = ps_ent_ctxt->ps_bitstrm; - /* CABAC context */ cabac_ctxt_t *ps_cabac_ctxt = ps_ent_ctxt->ps_cabac; - mb_info_ctxt_t *ps_curr_ctxt; - WORD32 bitstream_start_offset, bitstream_end_offset; WORD32 mb_tpm, mb_type, cbp, chroma_intra_mode, luma_intra_mode; WORD8 mb_qp_delta; @@ -2224,7 +2162,6 @@ IH264E_ERROR_T ih264e_write_bslice_mb_cabac(entropy_ctxt_t *ps_ent_ctxt) return IH264E_SUCCESS; } - else /* Inter MB */ { /* Starting bitstream offset for header in bits */ @@ -2284,7 +2221,6 @@ IH264E_ERROR_T ih264e_write_bslice_mb_cabac(entropy_ctxt_t *ps_ent_ctxt) pu1_byte += sizeof(mb_hdr_bdirect_t); } - else if (mb_type == BSKIP)/* MB = BSKIP */ { ih264e_cabac_enc_mb_skip(1, ps_cabac_ctxt, MB_SKIP_FLAG_B_SLICE); @@ -2303,7 +2239,6 @@ IH264E_ERROR_T ih264e_write_bslice_mb_cabac(entropy_ctxt_t *ps_ent_ctxt) pu1_byte += sizeof(mb_hdr_bskip_t); } - else /* mbype is B_L0_16x16, B_L1_16x16 or B_Bi_16x16 */ { mb_hdr_b16x16_t *ps_mb_hdr_b16x16 = (mb_hdr_b16x16_t *)ps_ent_ctxt->pv_mb_header_data; diff --git a/encoder/ih264e_cabac_init.c b/encoder/ih264e_cabac_init.c index 77c768db..6eb2e34d 100644 --- a/encoder/ih264e_cabac_init.c +++ b/encoder/ih264e_cabac_init.c @@ -21,19 +21,21 @@ /** ******************************************************************************* * @file -* ih264e_cabac_init.c +* ih264e_cabac_init.c * * @brief * Contains all initialization functions for cabac contexts * * @author -* Doney Alex -* -* @par List of Functions: +* ittiam * +* @par List of Functions +* - ih264e_init_cabac_enc_envirnoment +* - ih264e_init_cabac_table +* - ih264e_init_cabac_ctxt * * @remarks -* None +* none * ******************************************************************************* */ @@ -42,7 +44,7 @@ /* File Includes */ /*****************************************************************************/ -/* System include files */ +/* System Include Files */ #include #include #include @@ -50,57 +52,43 @@ #include #include -/* User include files */ +/* User Include Files */ +#include "ih264e_config.h" #include "ih264_typedefs.h" #include "iv2.h" #include "ive2.h" -#include "ih264_defs.h" + #include "ih264_debug.h" -#include "ime_distortion_metrics.h" -#include "ime_defs.h" -#include "ime_structs.h" +#include "ih264_macros.h" #include "ih264_error.h" +#include "ih264_defs.h" +#include "ih264_mem_fns.h" +#include "ih264_padding.h" #include "ih264_structs.h" #include "ih264_trans_quant_itrans_iquant.h" #include "ih264_inter_pred_filters.h" -#include "ih264_mem_fns.h" -#include "ih264_padding.h" #include "ih264_intra_pred_filters.h" #include "ih264_deblk_edge_filters.h" -#include "ih264_platform_macros.h" -#include "ih264_macros.h" -#include "ih264_buf_mgr.h" -#include "ih264e_error.h" -#include "ih264e_bitstream.h" -#include "ih264_common_tables.h" +#include "ih264_cavlc_tables.h" #include "ih264_cabac_tables.h" -#include "ih264_list.h" -#include "ih264e_defs.h" +#include "ih264_platform_macros.h" + +#include "ime_defs.h" +#include "ime_distortion_metrics.h" +#include "ime_structs.h" + #include "irc_cntrl_param.h" #include "irc_frame_info_collector.h" -#include "ih264e_rate_control.h" + +#include "ih264e_error.h" +#include "ih264e_defs.h" +#include "ih264e_bitstream.h" #include "ih264e_cabac_structs.h" #include "ih264e_structs.h" -#include "ih264e_cabac.h" -#include "ih264e_process.h" -#include "ithread.h" -#include "ih264e_intra_modes_eval.h" #include "ih264e_encode_header.h" -#include "ih264e_globals.h" -#include "ih264e_config.h" -#include "ih264e_trace.h" +#include "ih264e_cabac.h" #include "ih264e_statistics.h" -#include "ih264_cavlc_tables.h" -#include "ih264e_deblk.h" -#include "ih264e_me.h" -#include "ih264e_debug.h" -#include "ih264e_master.h" -#include "ih264e_utils.h" -#include "irc_mem_req_and_acq.h" -#include "irc_rate_control_api.h" -#include "ih264e_platform_macros.h" -#include "ime_statistics.h" - +#include "ih264e_trace.h" /*****************************************************************************/ @@ -108,20 +96,18 @@ /*****************************************************************************/ /** - ******************************************************************************* - * - * @brief - * Initialize cabac encoding environment - * - * @param[in] ps_cab_enc_env - * Pointer to encoding_envirnoment_t structure - * - * @returns - * - * @remarks - * None - * - ******************************************************************************* +******************************************************************************* +* +* @brief Initialize cabac encoding environment +* +* @param[in] ps_cab_enc_env +* Pointer to encoding_envirnoment_t structure +* +* @returns none +* +* @remarks none +* +******************************************************************************* */ static void ih264e_init_cabac_enc_envirnoment(encoding_envirnoment_t *ps_cab_enc_env) { @@ -131,26 +117,23 @@ static void ih264e_init_cabac_enc_envirnoment(encoding_envirnoment_t *ps_cab_enc ps_cab_enc_env->u4_bits_gen = 0; } - /** - ******************************************************************************* - * - * @brief - * Initialize default context values and pointers (Called once at the beginning of encoding). - * - * @param[in] ps_ent_ctxt - * Pointer to entropy context structure - * - * @returns - * - * @remarks - * None - * - ******************************************************************************* +******************************************************************************* +* +* @brief Initialize default context values and pointers. Called once at the +* beginning of encoding. +* +* @param[in] ps_ent_ctxt +* Pointer to entropy context structure +* +* @returns none +* +* @remarks none +* +******************************************************************************* */ void ih264e_init_cabac_table(entropy_ctxt_t *ps_ent_ctxt) { - /* CABAC context */ cabac_ctxt_t *ps_cabac_ctxt = ps_ent_ctxt->ps_cabac; ps_cabac_ctxt->ps_mb_map_ctxt_inc = ps_cabac_ctxt->ps_mb_map_ctxt_inc_base + 1; ps_cabac_ctxt->ps_lft_csbp = &ps_cabac_ctxt->s_lft_csbp; @@ -158,7 +141,7 @@ void ih264e_init_cabac_table(entropy_ctxt_t *ps_ent_ctxt) { /* 0th entry of mb_map_ctxt_inc will be always be containing default values */ - /* for CABAC context representing MB not available */ + /* for CABAC context representing MB not available */ mb_info_ctxt_t *ps_def_ctxt = ps_cabac_ctxt->ps_mb_map_ctxt_inc - 1; ps_def_ctxt->u1_mb_type = CAB_SKIP; @@ -171,30 +154,25 @@ void ih264e_init_cabac_table(entropy_ctxt_t *ps_ent_ctxt) } } - /** - ******************************************************************************* - * - * @brief - * Initialize cabac context: Initialize all contest with init values given in the spec. - * Called at the beginning of entropy coding of each slice for CABAC encoding. - * - * @param[in] ps_ent_ctxt - * Pointer to entropy context structure - * - * @returns - * - * @remarks - * None - * - ******************************************************************************* - */ +******************************************************************************* +* +* @brief Initialize cabac context: Initialize all contest with init values given +* in the spec. Called at the beginning of entropy coding of each slice for +* CABAC encoding. +* +* @param[in] ps_ent_ctxt +* Pointer to entropy context structure +* +* @returns none +* +* @remarks none +* +******************************************************************************* +*/ void ih264e_init_cabac_ctxt(entropy_ctxt_t *ps_ent_ctxt) { - /* CABAC context */ cabac_ctxt_t *ps_cabac_ctxt = ps_ent_ctxt->ps_cabac; - - /* slice header */ slice_header_t *ps_slice_hdr = ps_ent_ctxt->ps_slice_hdr_base; const UWORD8 u1_slice_type = ps_slice_hdr->u1_slice_type; WORD8 i1_cabac_init_idc = 0; @@ -212,11 +190,9 @@ void ih264e_init_cabac_ctxt(entropy_ctxt_t *ps_ent_ctxt) else { i1_cabac_init_idc = 3; - } memcpy(au1_cabac_ctxt_table, gau1_ih264_cabac_ctxt_init_table[i1_cabac_init_idc][u1_qp_y], NUM_CABAC_CTXTS * sizeof(bin_ctxt_model)); - } diff --git a/encoder/ih264e_cabac_structs.h b/encoder/ih264e_cabac_structs.h index 382500cb..bc6ba983 100644 --- a/encoder/ih264e_cabac_structs.h +++ b/encoder/ih264e_cabac_structs.h @@ -19,45 +19,52 @@ */ /** - ******************************************************************************* - * @file - * ih264e_cabac_structs.h - * - * @brief - * This file contains cabac related structure definitions. - * - * @author - * Doney Alex - * - * @remarks - * none - * - ******************************************************************************* - */ +******************************************************************************* +* @file +* ih264e_cabac_structs.h +* +* @brief +* This file contains structure definitions necessary for cabac encoding +* +* @author +* ittiam +* +* @remarks +* none +* +******************************************************************************* +*/ -#ifndef IH264E_CABAC_STRUCTS_H_ -#define IH264E_CABAC_STRUCTS_H_ +#ifndef _IH264E_CABAC_STRUCTS_H_ +#define _IH264E_CABAC_STRUCTS_H_ +/*****************************************************************************/ +/* Constant Macros */ +/*****************************************************************************/ #define CABAC_INIT_IDC 2 +/*****************************************************************************/ +/* Structures */ +/*****************************************************************************/ + /** - ****************************************************************************** - * @brief typedef for context model - ****************************************************************************** - */ +******************************************************************************* +* @brief typedef for context model +******************************************************************************* +*/ /* bits 0 to 5 :state bit 6 :mps */ typedef UWORD8 bin_ctxt_model; /** - ****************************************************************************** - * @brief MB info for cabac - ****************************************************************************** - */ +******************************************************************************* +* @brief MB info for cabac +******************************************************************************* +*/ typedef struct { /* Neighbour availability Variables needed to get CtxtInc, for CABAC */ @@ -72,6 +79,7 @@ typedef struct /* CSBP: V1 V0 U1 U0 Y3 Y2 Y1 Y0 */ /*************************************************************************/ UWORD8 u1_yuv_ac_csbp; + /*************************************************************************/ /* Arrangnment of DC CSBP */ /* bits: b7 b6 b5 b4 b3 b2 b1 b0 */ @@ -81,14 +89,15 @@ typedef struct WORD8 i1_ref_idx[4]; UWORD8 u1_mv[4][4]; + } mb_info_ctxt_t; /** - ****************************************************************************** - * @brief CSBP info for CABAC - ****************************************************************************** - */ +******************************************************************************* +* @brief CSBP info for CABAC +******************************************************************************* +*/ typedef struct { /*************************************************************************/ @@ -123,47 +132,56 @@ typedef struct /*************************************************************************/ UWORD8 u1_yuv_dc_csbp_top_mb; UWORD8 u1_yuv_dc_csbp_bot_mb; + } cab_csbp_t; /** - ****************************************************************************** - * @brief CABAC Encoding Environment - ****************************************************************************** - */ - +******************************************************************************* +* @brief CABAC Encoding Environment +******************************************************************************* +*/ typedef struct { - /** cabac interval start L */ + /** + * cabac interval start L + */ UWORD32 u4_code_int_low; - /** cabac interval range R */ + /** + * cabac interval range R + */ UWORD32 u4_code_int_range; /** bytes_outsanding; number of 0xFF bits that occur during renorm - * These will be accumulated till the carry bit is knwon - */ + * These will be accumulated till the carry bit is knwon + */ UWORD32 u4_out_standing_bytes; /** bits generated during renormalization - * A byte is put to stream/u4_out_standing_bytes from u4_low(L) when - * u4_bits_gen exceeds 8 - */ + * A byte is put to stream/u4_out_standing_bytes from u4_low(L) when + * u4_bits_gen exceeds 8 + */ UWORD32 u4_bits_gen; + } encoding_envirnoment_t; /** - ****************************************************************************** - * @brief CABAC Context structure : Variables to handle Cabac - ****************************************************************************** - */ +******************************************************************************* +* @brief CABAC Context structure : Variables to handle Cabac +******************************************************************************* +*/ typedef struct { - /* Base pointer to all the cabac contexts */ + /** + * Base pointer to all the cabac contexts + */ bin_ctxt_model au1_cabac_ctxt_table[NUM_CABAC_CTXTS]; - + /** + * left csbp + */ cab_csbp_t s_lft_csbp; /** @@ -171,51 +189,72 @@ typedef struct */ bitstrm_t *ps_bitstrm; - /* Pointer to mb_info_ctxt_t map_base */ + /** + * Pointer to mb_info_ctxt_t map_base + */ mb_info_ctxt_t *ps_mb_map_ctxt_inc_base; - /* Pointer to encoding_envirnoment_t */ + /** + * Pointer to encoding_envirnoment_t + */ encoding_envirnoment_t s_cab_enc_env; /* These things need to be updated at each MbLevel */ - - /* prev mb qp delta ctxt */ + /** + * Prev mb_qp_delta_ctxt + */ WORD8 i1_prev_mb_qp_delta_ctxt; - /* Pointer to mb_info_ctxt_t map */ + /** + * Pointer to mb_info_ctxt_t map + */ mb_info_ctxt_t *ps_mb_map_ctxt_inc; - /* Pointer to default mb_info_ctxt_t */ + /** + * Pointer to default mb_info_ctxt_t + */ mb_info_ctxt_t *ps_def_ctxt_mb_info; - /* Pointer to current mb_info_ctxt_t */ + /** + * Pointer to current mb_info_ctxt_t + */ mb_info_ctxt_t *ps_curr_ctxt_mb_info; - /* Pointer to left mb_info_ctxt_t */ + /** + * Pointer to left mb_info_ctxt_t + */ mb_info_ctxt_t *ps_left_ctxt_mb_info; - /* Pointer to top mb_info_ctxt_t */ + /** + * Pointer to top mb_info_ctxt_t + */ mb_info_ctxt_t *ps_top_ctxt_mb_info; - /* Poniter to left csbp structure */ + /** + * Pointer to csbp structures + */ cab_csbp_t *ps_lft_csbp; UWORD8 *pu1_left_y_ac_csbp; UWORD8 *pu1_left_uv_ac_csbp; UWORD8 *pu1_left_yuv_dc_csbp; - /***************************************************************************/ - /* Ref_idx contexts are stored in the following way */ - /* Array Idx 0,1 for reference indices in Forward direction */ - /* Array Idx 2,3 for reference indices in backward direction */ - /***************************************************************************/ - /* Dimensions for u1_left_ref_ctxt_inc_arr is [2][4] for Mbaff:Top and Bot */ + /**************************************************************************/ + /* Ref_idx contexts are stored in the following way */ + /* Array Idx 0,1 for reference indices in Forward direction */ + /* Array Idx 2,3 for reference indices in backward direction */ + /**************************************************************************/ + /** + * Dimensions for u1_left_ref_ctxt_inc_arr is [2][4] for Mbaff:Top and Bot + */ WORD8 i1_left_ref_idx_ctx_inc_arr[2][4]; WORD8 *pi1_left_ref_idx_ctxt_inc; - /* Dimensions for u1_left_mv_ctxt_inc_arr is [2][4][4] for Mbaff case */ + /** + * Dimensions for u1_left_mv_ctxt_inc_arr is [2][4][4] for Mbaff case + */ UWORD8 u1_left_mv_ctxt_inc_arr[2][4][4]; UWORD8 (*pu1_left_mv_ctxt_inc)[4]; } cabac_ctxt_t; -#endif /* IH264E_CABAC_STRUCTS_H_ */ +#endif /* _IH264E_CABAC_STRUCTS_H_ */ diff --git a/encoder/ih264e_cavlc.c b/encoder/ih264e_cavlc.c index ed34a43b..e3546ab2 100644 --- a/encoder/ih264e_cavlc.c +++ b/encoder/ih264e_cavlc.c @@ -31,15 +31,16 @@ * ittiam * * @par List of Functions: -* - ih264e_compute_zeroruns_and_trailingones() -* - ih264e_write_coeff4x4_cavlc() -* - ih264e_write_coeff8x8_cavlc() -* - ih264e_encode_residue() -* - ih264e_write_islice_mb_cavlc() -* - ih264e_write_pslice_mb_cavlc() +* - ih264e_compute_zeroruns_and_trailingones +* - ih264e_write_coeff4x4_cavlc +* - ih264e_write_coeff8x8_cavlc +* - ih264e_encode_residue +* - ih264e_write_islice_mb_cavlc +* - ih264e_write_pslice_mb_cavlc +* - ih264e_write_bslice_mb_cavlc * * @remarks -* None +* none * ******************************************************************************* */ @@ -48,41 +49,44 @@ /* File Includes */ /*****************************************************************************/ -/* System include files */ +/* System Include Files */ #include #include #include -/* User include files */ +/* User Include Files */ #include "ih264e_config.h" #include "ih264_typedefs.h" #include "iv2.h" #include "ive2.h" + #include "ih264_debug.h" #include "ih264_macros.h" -#include "ih264_defs.h" -#include "ih264e_defs.h" -#include "ih264e_error.h" -#include "ih264e_bitstream.h" -#include "ime_distortion_metrics.h" -#include "ime_defs.h" -#include "ime_structs.h" #include "ih264_error.h" +#include "ih264_defs.h" +#include "ih264_mem_fns.h" +#include "ih264_padding.h" #include "ih264_structs.h" #include "ih264_trans_quant_itrans_iquant.h" #include "ih264_inter_pred_filters.h" -#include "ih264_mem_fns.h" -#include "ih264_padding.h" #include "ih264_intra_pred_filters.h" #include "ih264_deblk_edge_filters.h" +#include "ih264_cavlc_tables.h" #include "ih264_cabac_tables.h" + +#include "ime_defs.h" +#include "ime_distortion_metrics.h" +#include "ime_structs.h" + #include "irc_cntrl_param.h" #include "irc_frame_info_collector.h" -#include "ih264e_rate_control.h" + +#include "ih264e_error.h" +#include "ih264e_defs.h" +#include "ih264e_bitstream.h" #include "ih264e_cabac_structs.h" #include "ih264e_structs.h" #include "ih264e_encode_header.h" -#include "ih264_cavlc_tables.h" #include "ih264e_cavlc.h" #include "ih264e_statistics.h" #include "ih264e_trace.h" @@ -117,7 +121,7 @@ * Bits 16-24 contains total number of zeros. * * @remarks -* None +* none * ******************************************************************************* */ diff --git a/encoder/ih264e_cavlc.h b/encoder/ih264e_cavlc.h index 8da2ceac..4d5c4011 100644 --- a/encoder/ih264e_cavlc.h +++ b/encoder/ih264e_cavlc.h @@ -24,8 +24,7 @@ * ih264e_cavlc.h * * @brief -* This file contains enumerations, macros and extern declarations of H264 -* cavlc tables +* This file contains declarations necessary for cavlc encoding * * @author * ittiam @@ -35,84 +34,17 @@ ****************************************************************************** */ -#ifndef IH264E_CAVLC_H_ -#define IH264E_CAVLC_H_ +#ifndef _IH264E_CAVLC_H_ +#define _IH264E_CAVLC_H_ /*****************************************************************************/ -/* Function macro definitions */ +/* Function Declarations */ /*****************************************************************************/ -/*****************************************************************************/ -/* Extern Function Declarations */ -/*****************************************************************************/ - -/** -******************************************************************************* -* -* @brief -* This function generates CAVLC coded bit stream for an Intra Slice. -* -* @description -* The mb syntax layer for intra slices constitutes luma mb mode, luma sub modes -* (if present), mb qp delta, coded block pattern, chroma mb mode and -* luma/chroma residue. These syntax elements are written as directed by table -* 7.3.5 of h264 specification. -* -* @param[in] ps_ent_ctxt -* pointer to entropy context -* -* @returns error code -* -* @remarks none -* -******************************************************************************* -*/ IH264E_ERROR_T ih264e_write_islice_mb_cavlc(entropy_ctxt_t *ps_ent_ctxt); -/** -******************************************************************************* -* -* @brief -* This function generates CAVLC coded bit stream for Inter slices -* -* @description -* The mb syntax layer for inter slices constitutes luma mb mode, luma sub modes -* (if present), mb qp delta, coded block pattern, chroma mb mode and -* luma/chroma residue. These syntax elements are written as directed by table -* 7.3.5 of h264 specification -* -* @param[in] ps_ent_ctxt -* pointer to entropy context -* -* @returns error code -* -* @remarks none -* -******************************************************************************* -*/ IH264E_ERROR_T ih264e_write_pslice_mb_cavlc(entropy_ctxt_t *ps_ent_ctxt); -/** -******************************************************************************* -* -* @brief -* This function generates CAVLC coded bit stream for Inter(B) slices -* -* @description -* The mb syntax layer for inter slices constitutes luma mb mode, luma sub modes -* (if present), mb qp delta, coded block pattern, chroma mb mode and -* luma/chroma residue. These syntax elements are written as directed by table -* 7.3.5 of h264 specification -* -* @param[in] ps_ent_ctxt -* pointer to entropy context -* -* @returns error code -* -* @remarks none -* -******************************************************************************* -*/ IH264E_ERROR_T ih264e_write_bslice_mb_cavlc(entropy_ctxt_t *ps_ent_ctxt); -#endif /* IH264E_CAVLC_H_ */ +#endif /* _IH264E_CAVLC_H_ */ diff --git a/encoder/ih264e_config.h b/encoder/ih264e_config.h index 2446cdbb..5251a577 100644 --- a/encoder/ih264e_config.h +++ b/encoder/ih264e_config.h @@ -24,8 +24,7 @@ * ih264e_config.h * * @brief -* contains any necessary declarations/definitions that are used during codec -* build +* h264 library configuration definitions * * @author * ittiam @@ -35,8 +34,8 @@ ****************************************************************************** */ -#ifndef IH264E_CONFIG_H_ -#define IH264E_CONFIG_H_ +#ifndef _IH264E_CONFIG_H_ +#define _IH264E_CONFIG_H_ /*****************************************************************************/ /* Constant Macros */ @@ -49,4 +48,4 @@ #define DEBUG_RC 0 #define TRACE_SUPPORT 0 -#endif /* IH264E_CONFIG_H_ */ +#endif /* _IH264E_CONFIG_H_ */ diff --git a/encoder/ih264e_core_coding.c b/encoder/ih264e_core_coding.c index 5b36aef1..3d0806f5 100644 --- a/encoder/ih264e_core_coding.c +++ b/encoder/ih264e_core_coding.c @@ -19,70 +19,82 @@ */ /** - ******************************************************************************* - * @file - * ih264e_core_coding.c - * - * @brief - * This file contains routines that perform luma and chroma core coding for - * intra macroblocks - * - * @author - * ittiam - * - * @par List of Functions: - * - ih264e_pack_l_mb_i16() - * - ih264e_pack_c_mb_i8() - * - ih264e_code_luma_intra_macroblock_16x16() - * - ih264e_code_luma_intra_macroblock_4x4() - * - ih264e_code_chroma_intra_macroblock_8x8() - * - * @remarks - * None - * - ******************************************************************************* - */ +******************************************************************************* +* @file +* ih264e_core_coding.c +* +* @brief +* This file contains routines that perform luma and chroma core coding of +* H264 macroblocks +* +* @author +* ittiam +* +* @par List of Functions: +* - ih264e_luma_16x16_resi_trans_dctrans_quant +* - ih264e_luma_16x16_idctrans_iquant_itrans_recon +* - ih264e_chroma_8x8_resi_trans_dctrans_quant +* - ih264e_chroma_8x8_idctrans_iquant_itrans_recon +* - ih264e_pack_l_mb_i16 +* - ih264e_pack_l_mb +* - ih264e_pack_c_mb_i8 +* - ih264e_code_luma_intra_macroblock_16x16 +* - ih264e_code_luma_intra_macroblock_4x4 +* - ih264e_code_luma_intra_macroblock_4x4_rdopt_on +* - ih264e_code_chroma_intra_macroblock_8x8 +* - ih264e_code_luma_inter_macroblock_16x16 +* - ih264e_code_chroma_inter_macroblock_8x8 +* +* @remarks +* none +* +******************************************************************************* +*/ /*****************************************************************************/ /* File Includes */ /*****************************************************************************/ -/* System include files */ +/* System Include Files */ #include #include #include -/* User include files */ +/* User Include Files */ #include "ih264e_config.h" #include "ih264_typedefs.h" -#include "ih264_platform_macros.h" #include "iv2.h" #include "ive2.h" + #include "ih264_macros.h" #include "ih264_defs.h" -#include "ih264e_defs.h" -#include "ih264_trans_data.h" -#include "ih264e_error.h" -#include "ih264e_bitstream.h" -#include "ime_distortion_metrics.h" -#include "ime_defs.h" -#include "ime_structs.h" +#include "ih264_mem_fns.h" +#include "ih264_padding.h" #include "ih264_structs.h" #include "ih264_trans_quant_itrans_iquant.h" #include "ih264_inter_pred_filters.h" -#include "ih264_mem_fns.h" -#include "ih264_padding.h" #include "ih264_intra_pred_filters.h" #include "ih264_deblk_edge_filters.h" +#include "ih264_trans_data.h" #include "ih264_cabac_tables.h" +#include "ih264_platform_macros.h" + +#include "ime_defs.h" +#include "ime_distortion_metrics.h" +#include "ime_structs.h" + #include "irc_cntrl_param.h" #include "irc_frame_info_collector.h" + +#include "ih264e_error.h" +#include "ih264e_defs.h" +#include "ih264e_globals.h" #include "ih264e_rate_control.h" +#include "ih264e_bitstream.h" #include "ih264e_cabac_structs.h" #include "ih264e_structs.h" -#include "ih264e_globals.h" -#include "ih264e_core_coding.h" #include "ih264e_mc.h" +#include "ih264e_core_coding.h" /*****************************************************************************/ @@ -222,8 +234,8 @@ void ih264e_luma_16x16_resi_trans_dctrans_quant(codec_t *ps_codec, * * @param[in] pi2_src * Input data, 16x16 size -* First 16 mem locations will have the Dc coffs in rater scan order in linear fashion -* after a stride 1st AC clock will be present again in raster can order +* First 16 mem locations will have the Dc coffs in raster scan order in linear +* fashion after a stride 1st AC clock will be present again in raster can order * Then each AC block of the 16x16 block will follow in raster scan order * * @param[in] pu1_pred @@ -252,17 +264,17 @@ void ih264e_luma_16x16_resi_trans_dctrans_quant(codec_t *ps_codec, * @param[in] qp_div * QP/6 * -* @param[in] pi4_tmp -* Input temporary buffer -* needs to be at least 20 in size -* -* @param[in] pu4_cntrl +* @param[in] u4_cntrl * Controls the transform path * total Last 17 bits are used * the 16th th bit will correspond to DC block * and 32-17 will correspond to the ac blocks in raster scan order * bit equaling zero indicates that the entire 4x4 block is zero for DC -* For AC blocks a bit equaling zero will mean that all 15 AC coffs of the block is nonzero +* For AC blocks a bit equaling zero will mean that all 15 AC coffs of the block +* is nonzero +* +* @param[in] u4_dc_trans_flag +* Differentiates intra vs inter * * @param[in] pi4_tmp * Input temporary buffer @@ -457,7 +469,7 @@ void ih264e_luma_16x16_idctrans_iquant_itrans_recon(codec_t *ps_codec, * @param[in] pred_strd * Prediction stride * -* @param[in] dst_strd +* @param[in] out_strd * Destination stride * * @param[in] pu2_scale_matrix @@ -472,18 +484,13 @@ void ih264e_luma_16x16_idctrans_iquant_itrans_recon(codec_t *ps_codec, * @param[in] u4_round_factor * Round factor for quant * -* @param[out] pu1_nnz +* @param[out] pu1_nnz_c * Memory to store the non-zeros after transform * The first byte will be the nnz od DC block for U plane * From the next byte the AC nnzs will be storerd in raster scan order * The fifth byte will be nnz of Dc block of V plane * Then Ac blocks will follow * -* @param u4_dc_flag -* Signals if Dc transform is to be done or not -* 1 -> Dc transform will be done -* 0 -> Dc transform will not be done -* * @remarks * ******************************************************************************* @@ -547,11 +554,12 @@ void ih264e_chroma_8x8_resi_trans_dctrans_quant(codec_t *ps_codec, /** ******************************************************************************* -* @brief -* This function performs the inverse transform with process for chroma MB of H264 +* @brief Does inverse DC transform, inverse quantization inverse transform for +* chroma MB * * @par Description: -* Does inverse DC transform ,inverse quantization inverse transform +* Does inverse DC transform, inverse quantization inverse transform for +* chroma MB * * @param[in] pi2_src * Input data, 16x16 size @@ -585,22 +593,23 @@ void ih264e_chroma_8x8_resi_trans_dctrans_quant(codec_t *ps_codec, * @param[in] qp_div * QP/6 * -* @param[in] pi4_tmp -* Input temporary buffer -* needs to be at least COFF_CNT_SUB_BLK_4x4 + Number of Dc cofss for chroma * number of planes -* in size -* -* @param[in] pu4_cntrl +* @param[in] u4_cntrl * Controls the transform path -* the 15 th bit will correspond to DC block of U plane , 14th will indicate the V plane Dc block -* 32-28 bits will indicate AC blocks of U plane in raster scan order -* 27-23 bits will indicate AC blocks of V plane in rater scan order +* the 15 th bit will correspond to DC block of U plane, 14th will indicate the +* V plane Dc block. 32-28 bits will indicate AC blocks of U plane in raster +* scan order. 27-23 bits will indicate AC blocks of V plane in rater scan order. * The bit 1 implies that there is at least one non zero coeff in a block * +* @param[in] pi4_tmp +* Input temporary buffer +* needs to be at least COFF_CNT_SUB_BLK_4x4 + (Number of Dc coeffs for chroma * +* number of planes) in size +* * @returns * none * * @remarks +* ******************************************************************************* */ void ih264e_chroma_8x8_idctrans_iquant_itrans_recon(codec_t *ps_codec, @@ -649,8 +658,8 @@ void ih264e_chroma_8x8_idctrans_iquant_itrans_recon(codec_t *ps_codec, if (u4_cntrl & CNTRL_FLAG_DCBLK_MASK_CHROMA) { UWORD32 cntr, u4_dc_cntrl; - /* Do inv hadamard for u an v block */ + /* Do inv hadamard for u an v block */ ps_codec->pf_ihadamard_scaling_2x2_uv(pi2_src, pi2_src, pu2_iscale_mat, pu2_weigh_mat, qp_div, NULL); /* @@ -1085,11 +1094,9 @@ void ih264e_pack_l_mb(WORD16 *pi2_res_mb, /* Decide if the 8x8 unit has to be sent for entropy coding? */ if ((b4+1) % 4 == 0) { - if ( u4_thres_resi && (u4_b8_coeff_cost <= LUMA_SUB_BLOCK_SKIP_THRESHOLD) && - (*u1_cbp_l & (1 << b8)) ) + if (u4_thres_resi && (u4_b8_coeff_cost <= LUMA_SUB_BLOCK_SKIP_THRESHOLD) && + (*u1_cbp_l & (1 << b8))) { - - /* * When we want to reset the full 8x8 block, we have to reset * both the dc and ac coeff bits hence we have the symmetric @@ -1479,7 +1486,6 @@ void ih264e_pack_c_mb(WORD16 *pi2_res_mb, * ******************************************************************************* */ - UWORD8 ih264e_code_luma_intra_macroblock_16x16(process_ctxt_t *ps_proc) { /* Codec Context */ @@ -2091,7 +2097,7 @@ UWORD8 ih264e_code_chroma_intra_macroblock_8x8(process_ctxt_t *ps_proc) /** ******************************************************************************* * -* @brief performs luma core coding when mode is inter +* @brief performs luma core coding when mode is inter * * @par Description: * If the current mb is to be coded as inter the mb is predicted based on the @@ -2103,14 +2109,12 @@ UWORD8 ih264e_code_chroma_intra_macroblock_8x8(process_ctxt_t *ps_proc) * @param[in] ps_proc_ctxt * pointer to the current macro block context * -* @returns u1_cbp_l -* coded block pattern luma +* @returns coded block pattern luma * * @remarks none * ******************************************************************************* */ - UWORD8 ih264e_code_luma_inter_macroblock_16x16(process_ctxt_t *ps_proc) { /* Codec Context */ @@ -2241,18 +2245,16 @@ UWORD8 ih264e_code_luma_inter_macroblock_16x16(process_ctxt_t *ps_proc) * @brief performs chroma core coding for inter macro blocks * * @par Description: -* If the current mb is to be coded as inter predicted mb,based on the sub mb partitions -* and corresponding motion vectors generated by ME ,prediction is done. +* If the current mb is to be coded as inter predicted mb, based on the sub mb +* partitions and corresponding motion vectors generated by ME, prediction is done. * Then, error is computed between the input blk and the estimated blk. -* This error is transformed , quantized. The quantized coefficients -* are packed in scan order for -* entropy coding. +* This error is transformed, quantized. The quantized coefficients +* are packed in scan order for entropy coding. * * @param[in] ps_proc_ctxt * pointer to the current macro block context * -* @returns u1_cbp_l -* coded block pattern chroma +* @returns coded block pattern chroma * * @remarks none * diff --git a/encoder/ih264e_core_coding.h b/encoder/ih264e_core_coding.h index 1237d25d..7087ec6f 100644 --- a/encoder/ih264e_core_coding.h +++ b/encoder/ih264e_core_coding.h @@ -24,7 +24,8 @@ * ih264e_core_coding.h * * @brief -* This file contains extern declarations of core coding routines +* This file contains declarations necessary for core coding of luma and chroma +* blocks * * @author * ittiam @@ -34,11 +35,11 @@ ****************************************************************************** */ -#ifndef IH264E_CORE_CODING_H_ -#define IH264E_CORE_CODING_H_ +#ifndef _IH264E_CORE_CODING_H_ +#define _IH264E_CORE_CODING_H_ /*****************************************************************************/ -/* Constant Macros */ +/* Macros */ /*****************************************************************************/ /** @@ -84,14 +85,14 @@ */ #define DEQUEUE_BLKID_FROM_CONTROL( u4_cntrl, blk_lin_id) \ { \ - blk_lin_id = CLZ(u4_cntrl); \ - u4_cntrl &= (0x7FFFFFFF >> blk_lin_id); \ + blk_lin_id = CLZ(u4_cntrl); \ + u4_cntrl &= (0x7FFFFFFF >> blk_lin_id); \ }; -#define IND2SUB_LUMA_MB(u4_blk_id,i4_offset_x,i4_offset_y) \ -{ \ - i4_offset_x = (u4_blk_id % 4) << 2; \ - i4_offset_y = (u4_blk_id / 4) << 2; \ +#define IND2SUB_LUMA_MB(u4_blk_id,i4_offset_x,i4_offset_y) \ +{ \ + i4_offset_x = (u4_blk_id % 4) << 2; \ + i4_offset_y = (u4_blk_id / 4) << 2; \ } #define IND2SUB_CHROMA_MB(u4_blk_id,i4_offset_x,i4_offset_y) \ @@ -105,67 +106,6 @@ /* Function Declarations */ /*****************************************************************************/ -/** -******************************************************************************* -* -* @brief -* This function performs does the DCT transform then Hadamard transform -* and quantization for a macroblock when the mb mode is intra 16x16 mode -* -* @par Description: -* First cf4 is done on all 16 4x4 blocks of the 16x16 input block. -* Then hadamard transform is done on the DC coefficients -* Quantization is then performed on the 16x16 block, 4x4 wise -* -* @param[in] pu1_src -* Pointer to source sub-block -* -* @param[in] pu1_pred -* Pointer to prediction sub-block -* -* @param[in] pi2_out -* Pointer to residual sub-block -* The output will be in linear format -* The first 16 continuous locations will contain the values of Dc block -* After DC block and a stride 1st AC block will follow -* After one more stride next AC block will follow -* The blocks will be in raster scan order -* -* @param[in] src_strd -* Source stride -* -* @param[in] pred_strd -* Prediction stride -* -* @param[in] dst_strd -* Destination stride -* -* @param[in] pu2_scale_matrix -* The quantization matrix for 4x4 transform -* -* @param[in] pu2_threshold_matrix -* Threshold matrix -* -* @param[in] u4_qbits -* 15+QP/6 -* -* @param[in] u4_round_factor -* Round factor for quant -* -* @param[out] pu1_nnz -* Memory to store the non-zeros after transform -* The first byte will be the nnz of DC block -* From the next byte the AC nnzs will be stored in raster scan order -* -* @param u4_dc_flag -* Signals if Dc transform is to be done or not -* 1 -> Dc transform will be done -* 0 -> Dc transform will not be done -* -* @remarks -* -******************************************************************************* -*/ void ih264e_luma_16x16_resi_trans_dctrans_quant( codec_t *ps_codec, UWORD8 *pu1_src, UWORD8 *pu1_pred, WORD16 *pi2_out, WORD32 src_strd, WORD32 pred_strd, @@ -173,71 +113,6 @@ void ih264e_luma_16x16_resi_trans_dctrans_quant( const UWORD16 *pu2_threshold_matrix, UWORD32 u4_qbits, UWORD32 u4_round_factor, UWORD8 *pu1_nnz, UWORD32 u4_dc_flag); -/** -******************************************************************************* -* -* @brief -* This function performs the intra 16x16 inverse transform process for H264 -* it includes inverse Dc transform, inverse quant and then inverse transform -* -* @par Description: -* -* @param[in] pi2_src -* Input data, 16x16 size -* First 16 mem locations will have the Dc coffs in rater scan order in linear fashion -* after a stride 1st AC clock will be present again in raster can order -* Then each AC block of the 16x16 block will follow in raster scan order -* -* @param[in] pu1_pred -* The predicted data, 16x16 size -* Block by block form -* -* @param[in] pu1_out -* Output 16x16 -* In block by block form -* -* @param[in] src_strd -* Source stride -* -* @param[in] pred_strd -* input stride for prediction buffer -* -* @param[in] out_strd -* input stride for output buffer -* -* @param[in] pu2_iscale_mat -* Inverse quantization matrix for 4x4 transform -* -* @param[in] pu2_weigh_mat -* weight matrix of 4x4 transform -* -* @param[in] qp_div -* QP/6 -* -* @param[in] pi4_tmp -* Input temporary buffer -* needs to be at least 20 in size -* -* @param[in] pu4_cntrl -* Controls the transform path -* total Last 17 bits are used -* the 16th th bit will correspond to DC block -* and 32-17 will correspond to the ac blocks in raster scan order -* bit equaling zero indicates that the entire 4x4 block is zero for DC -* For AC blocks a bit equaling zero will mean that all 15 AC coffs of the block is nonzero -* -* @param[in] pi4_tmp -* Input temporary buffer -* needs to be at least COFF_CNT_SUB_BLK_4x4+COFF_CNT_SUB_BLK_4x4 size -* -* @returns -* none -* -* @remarks -* The all zero case must be taken care outside -* -******************************************************************************* -*/ void ih264e_luma_16x16_idctrans_iquant_itrans_recon( codec_t *ps_codec, WORD16 *pi2_src, UWORD8 *pu1_pred, UWORD8 *pu1_out, WORD32 src_strd, WORD32 pred_strd, @@ -245,75 +120,6 @@ void ih264e_luma_16x16_idctrans_iquant_itrans_recon( const UWORD16 *pu2_weigh_mat, UWORD32 qp_div, UWORD32 u4_cntrl, UWORD32 u4_dc_trans_flag, WORD32 *pi4_tmp); -/** -******************************************************************************* -* -* @brief -* This function performs does the DCT transform then Hadamard transform -* and quantization for a chroma macroblock -* -* @par Description: -* First cf4 is done on all 16 4x4 blocks of the 8x8input block -* Then hadamard transform is done on the DC coefficients -* Quantization is then performed on the 8x8 block, 4x4 wise -* -* @param[in] pu1_src -* Pointer to source sub-block -* The input is in interleaved format for two chroma planes -* -* @param[in] pu1_pred -* Pointer to prediction sub-block -* Prediction is in inter leaved format -* -* @param[in] pi2_out -* Pointer to residual sub-block -* The output will be in linear format -* The first 4 continuous locations will contain the values of DC block for U -* and then next 4 will contain for V. -* After DC block and a stride 1st AC block of U plane will follow -* After one more stride next AC block of V plane will follow -* The blocks will be in raster scan order -* -* After all the AC blocks of U plane AC blocks of V plane will follow in exact -* same way -* -* @param[in] src_strd -* Source stride -* -* @param[in] pred_strd -* Prediction stride -* -* @param[in] dst_strd -* Destination stride -* -* @param[in] pu2_scale_matrix -* The quantization matrix for 4x4 transform -* -* @param[in] pu2_threshold_matrix -* Threshold matrix -* -* @param[in] u4_qbits -* 15+QP/6 -* -* @param[in] u4_round_factor -* Round factor for quant -* -* @param[out] pu1_nnz -* Memory to store the non-zeros after transform -* The first byte will be the nnz od DC block for U plane -* From the next byte the AC nnzs will be storerd in raster scan order -* The fifth byte will be nnz of Dc block of V plane -* Then Ac blocks will follow -* -* @param u4_dc_flag -* Signals if Dc transform is to be done or not -* 1 -> Dc transform will be done -* 0 -> Dc transform will not be done -* -* @remarks -* -******************************************************************************* -*/ void ih264e_chroma_8x8_resi_trans_dctrans_quant( codec_t *ps_codec, UWORD8 *pu1_src, UWORD8 *pu1_pred, WORD16 *pi2_out, WORD32 src_strd, WORD32 pred_strd, @@ -321,64 +127,6 @@ void ih264e_chroma_8x8_resi_trans_dctrans_quant( const UWORD16 *pu2_threshold_matrix, UWORD32 u4_qbits, UWORD32 u4_round_factor, UWORD8 *pu1_nnz_c); -/** -******************************************************************************* -* @brief -* This function performs the inverse transform with process for chroma MB of H264 -* -* @par Description: -* Does inverse DC transform ,inverse quantization inverse transform -* -* @param[in] pi2_src -* Input data, 16x16 size -* The input is in the form of, first 4 locations will contain DC coeffs of -* U plane, next 4 will contain DC coeffs of V plane, then AC blocks of U plane -* in raster scan order will follow, each block as linear array in raster scan order. -* After a stride next AC block will follow. After all AC blocks of U plane -* V plane AC blocks will follow in exact same order. -* -* @param[in] pu1_pred -* The predicted data, 8x16 size, U and V interleaved -* -* @param[in] pu1_out -* Output 8x16, U and V interleaved -* -* @param[in] src_strd -* Source stride -* -* @param[in] pred_strd -* input stride for prediction buffer -* -* @param[in] out_strd -* input stride for output buffer -* -* @param[in] pu2_iscale_mat -* Inverse quantization martix for 4x4 transform -* -* @param[in] pu2_weigh_mat -* weight matrix of 4x4 transform -* -* @param[in] qp_div -* QP/6 -* -* @param[in] pi4_tmp -* Input temporary buffer -* needs to be at least COFF_CNT_SUB_BLK_4x4 + Number of Dc cofss for chroma * number of planes -* in size -* -* @param[in] pu4_cntrl -* Controls the transform path -* the 15 th bit will correspond to DC block of U plane , 14th will indicate the V plane Dc block -* 32-28 bits will indicate AC blocks of U plane in raster scan order -* 27-23 bits will indicate AC blocks of V plane in rater scan order -* The bit 1 implies that there is at least one non zero coff in a block -* -* @returns -* none -* -* @remarks -******************************************************************************* -*/ void ih264e_chroma_8x8_idctrans_iquant_itrans_recon( codec_t *ps_codec, WORD16 *pi2_src, UWORD8 *pu1_pred, UWORD8 *pu1_out, WORD32 src_strd, WORD32 pred_strd, @@ -386,268 +134,25 @@ void ih264e_chroma_8x8_idctrans_iquant_itrans_recon( const UWORD16 *pu2_weigh_mat, UWORD32 qp_div, UWORD32 u4_cntrl, WORD32 *pi4_tmp); -/** -****************************************************************************** -* -* @brief This function packs residue of an i16x16 luma mb for entropy coding -* -* @par Description -* An i16 macro block contains two classes of units, dc 4x4 block and -* 4x4 ac blocks. while packing the mb, the dc block is sent first, and -* the 16 ac blocks are sent next in scan order. Each and every block is -* represented by 3 parameters (nnz, significant coefficient map and the -* residue coefficients itself). If a 4x4 unit does not have any coefficients -* then only nnz is sent. Inside a 4x4 block the individual coefficients are -* sent in scan order. -* -* The first byte of each block will be nnz of the block, if it is non zero, -* a 2 byte significance map is sent. This is followed by nonzero coefficients. -* This is repeated for 1 dc + 16 ac blocks. -* -* @param[in] pi2_res_mb -* pointer to residue mb -* -* @param[in, out] pv_mb_coeff_data -* buffer pointing to packed residue coefficients -* -* @param[in] u4_res_strd -* residual block stride -* -* @param[out] u1_cbp_l -* coded block pattern luma -* -* @param[in] pu1_nnz -* number of non zero coefficients in each 4x4 unit -* -* @param[out] -* Control signal for inverse transform of 16x16 blocks -* -* @return none -* -* @ remarks -* -****************************************************************************** -*/ void ih264e_pack_l_mb_i16(WORD16 *pi2_res_mb, void **pv_mb_coeff_data, WORD32 i4_res_strd, UWORD8 *u1_cbp_l, UWORD8 *pu1_nnz, UWORD32 *pu4_cntrl); -/** -****************************************************************************** -* -* @brief This function packs residue of an i8x8 chroma mb for entropy coding -* -* @par Description -* An i8 chroma macro block contains two classes of units, dc 2x2 block and -* 4x4 ac blocks. while packing the mb, the dc block is sent first, and -* the 4 ac blocks are sent next in scan order. Each and every block is -* represented by 3 parameters (nnz, significant coefficient map and the -* residue coefficients itself). If a 4x4 unit does not have any coefficients -* then only nnz is sent. Inside a 4x4 block the individual coefficients are -* sent in scan order. -* -* The first byte of each block will be nnz of the block, if it is non zero, -* a 2 byte significance map is sent. This is followed by nonzero coefficients. -* This is repeated for 1 dc + 4 ac blocks. -* -* @param[in] pi2_res_mb -* pointer to residue mb -* -* @param[in, out] pv_mb_coeff_data -* buffer pointing to packed residue coefficients -* -* @param[in] u4_res_strd -* residual block stride -* -* @param[out] u1_cbp_c -* coded block pattern chroma -* -* @param[in] pu1_nnz -* number of non zero coefficients in each 4x4 unit -* -* @param[out] pu1_nnz -* Control signal for inverse transform -* -* @param[in] u4_swap_uv -* Swaps the order of U and V planes in entropy bitstream -* -* @return none -* -* @ remarks -* -****************************************************************************** -*/ void ih264e_pack_c_mb(WORD16 *pi2_res_mb, void **pv_mb_coeff_data, WORD32 i4_res_strd, UWORD8 *u1_cbp_c, UWORD8 *pu1_nnz, UWORD32 u4_kill_coffs_flag, UWORD32 *pu4_cntrl, UWORD32 u4_swap_uv); -/** -******************************************************************************* -* -* @brief performs luma core coding when intra mode is i16x16 -* -* @par Description: -* If the current mb is to be coded as intra of mb type i16x16, the mb is first -* predicted using one of i16x16 prediction filters, basing on the intra mode -* chosen. Then, error is computed between the input blk and the estimated blk. -* This error is transformed (hierarchical transform i.e., dct followed by hada- -* -mard), quantized. The quantized coefficients are packed in scan order for -* entropy coding. -* -* @param[in] ps_proc_ctxt -* pointer to the current macro block context -* -* @returns u1_cbp_l -* coded block pattern luma -* -* @remarks none -* -******************************************************************************* -*/ -UWORD8 ih264e_code_luma_intra_macroblock_16x16 - ( - process_ctxt_t *ps_proc - ); +UWORD8 ih264e_code_luma_intra_macroblock_16x16(process_ctxt_t *ps_proc); -/** -******************************************************************************* -* -* @brief performs luma core coding when intra mode is i4x4 -* -* @par Description: -* If the current mb is to be coded as intra of mb type i4x4, the mb is first -* predicted using one of i4x4 prediction filters, basing on the intra mode -* chosen. Then, error is computed between the input blk and the estimated blk. -* This error is dct transformed and quantized. The quantized coefficients are -* packed in scan order for entropy coding. -* -* @param[in] ps_proc_ctxt -* pointer to the current macro block context -* -* @returns u1_cbp_l -* coded block pattern luma -* -* @remarks -* The traversal of 4x4 subblocks in the 16x16 macroblock is as per the scan order -* mentioned in h.264 specification -* -******************************************************************************* -*/ -UWORD8 ih264e_code_luma_intra_macroblock_4x4 - ( - process_ctxt_t *ps_proc - ); +UWORD8 ih264e_code_luma_intra_macroblock_4x4(process_ctxt_t *ps_proc); -/** -******************************************************************************* -* -* @brief performs luma core coding when intra mode is i4x4 -* -* @par Description: -* If the current mb is to be coded as intra of mb type i4x4, the mb is first -* predicted using one of i4x4 prediction filters, basing on the intra mode -* chosen. Then, error is computed between the input blk and the estimated blk. -* This error is dct transformed and quantized. The quantized coefficients are -* packed in scan order for entropy coding. -* -* @param[in] ps_proc_ctxt -* pointer to the current macro block context -* -* @returns u1_cbp_l -* coded block pattern luma -* -* @remarks -* The traversal of 4x4 subblocks in the 16x16 macroblock is as per the scan order -* mentioned in h.264 specification -* -******************************************************************************* -*/ -UWORD8 ih264e_code_luma_intra_macroblock_4x4_rdopt_on - ( - process_ctxt_t *ps_proc - ); +UWORD8 ih264e_code_luma_intra_macroblock_4x4_rdopt_on(process_ctxt_t *ps_proc); -/** -******************************************************************************* -* -* @brief performs chroma core coding for intra macro blocks -* -* @par Description: -* If the current MB is to be intra coded with mb type chroma I8x8, the MB is -* first predicted using intra 8x8 prediction filters. The predicted data is -* compared with the input for error and the error is transformed. The DC -* coefficients of each transformed sub blocks are further transformed using -* Hadamard transform. The resulting coefficients are quantized, packed and sent -* for entropy coding. -* -* @param[in] ps_proc_ctxt -* pointer to the current macro block context -* -* @returns u1_cbp_c -* coded block pattern chroma -* -* @remarks -* The traversal of 4x4 subblocks in the 8x8 macroblock is as per the scan order -* mentioned in h.264 specification -* -******************************************************************************* -*/ -UWORD8 ih264e_code_chroma_intra_macroblock_8x8 - ( - process_ctxt_t *ps_proc - ); +UWORD8 ih264e_code_chroma_intra_macroblock_8x8(process_ctxt_t *ps_proc); -/** -******************************************************************************* -* @brief performs luma core coding when mode is inter -* -* @par Description: -* If the current mb is to be coded as inter predicted mb,based on the sub mb -* partitions and corresponding motion vectors generated by ME, prediction is done. -* Then, error is computed between the input blk and the estimated blk. -* This error is transformed ( dct and with out hadamard), quantized. The -* quantized coefficients are packed in scan order for entropy coding. -* -* @param[in] ps_proc_ctxt -* pointer to the current macro block context -* -* @returns u1_cbp_l -* coded block pattern luma -* -* @remarks none -* -******************************************************************************* -*/ -UWORD8 ih264e_code_luma_inter_macroblock_16x16 - ( - process_ctxt_t *ps_proc - ); +UWORD8 ih264e_code_luma_inter_macroblock_16x16(process_ctxt_t *ps_proc); -/** -******************************************************************************* -* @brief performs chroma core coding for inter macro blocks -* -* @par Description: -* If the current mb is to be coded as inter predicted mb, based on the sub mb -* partitions and corresponding motion vectors generated by ME, prediction is done. -* Then, error is computed between the input blk and the estimated blk. -* This error is transformed, quantized. The quantized coefficients -* are packed in scan order for entropy coding. -* -* @param[in] ps_proc_ctxt -* pointer to the current macro block context -* -* @returns u1_cbp_l -* coded block pattern luma -* -* @remarks none -* -******************************************************************************* -*/ -UWORD8 ih264e_code_chroma_inter_macroblock_8x8 - ( - process_ctxt_t *ps_proc - ); +UWORD8 ih264e_code_chroma_inter_macroblock_8x8(process_ctxt_t *ps_proc); -#endif /* IH264E_CORE_CODING_H_ */ +#endif /* _IH264E_CORE_CODING_H_ */ diff --git a/encoder/ih264e_deblk.c b/encoder/ih264e_deblk.c index db176ac7..87666046 100644 --- a/encoder/ih264e_deblk.c +++ b/encoder/ih264e_deblk.c @@ -19,72 +19,76 @@ */ /** - ******************************************************************************* - * @file - * ih264e_deblk.c - * - * @brief - * This file contains functions that are associated with deblocking - * - * @author - * ittiam - * - * @par List of Functions: - * - ih264e_fill_bs_1mv_1ref_non_mbaff - * - ih264e_calculate_csbp - * - ih264e_compute_bs - * - ih264e_filter_top_edge - * - ih264e_filter_left_edge - * - ih264e_deblock_mb - * - * @remarks - * None - * - ******************************************************************************* - */ +******************************************************************************* +* @file +* ih264e_deblk.c +* +* @brief +* This file contains functions that are associated with deblocking +* +* @author +* ittiam +* +* @par List of Functions: +* - ih264e_fill_bs_1mv_1ref_non_mbaff +* - ih264e_calculate_csbp +* - ih264e_compute_bs +* - ih264e_filter_top_edge +* - ih264e_filter_left_edge +* - ih264e_deblock_mb +* +* @remarks +* none +* +******************************************************************************* +*/ /*****************************************************************************/ /* File Includes */ /*****************************************************************************/ -/* System include files */ +/* System Include Files */ #include #include #include -/* User include files */ +/* User Include Files */ #include "ih264e_config.h" #include "ih264_typedefs.h" #include "iv2.h" #include "ive2.h" + #include "ih264_macros.h" #include "ih264_defs.h" -#include "ih264e_defs.h" -#include "ih264e_error.h" -#include "ih264e_bitstream.h" -#include "ime_distortion_metrics.h" -#include "ime_defs.h" -#include "ime_structs.h" +#include "ih264_mem_fns.h" +#include "ih264_padding.h" #include "ih264_structs.h" #include "ih264_trans_quant_itrans_iquant.h" #include "ih264_inter_pred_filters.h" -#include "ih264_mem_fns.h" -#include "ih264_padding.h" #include "ih264_intra_pred_filters.h" #include "ih264_deblk_edge_filters.h" +#include "ih264_trans_data.h" #include "ih264_cabac_tables.h" +#include "ih264_deblk_tables.h" + +#include "ime_defs.h" +#include "ime_distortion_metrics.h" +#include "ime_structs.h" + #include "irc_cntrl_param.h" #include "irc_frame_info_collector.h" + +#include "ih264e_error.h" +#include "ih264e_defs.h" #include "ih264e_rate_control.h" +#include "ih264e_bitstream.h" #include "ih264e_cabac_structs.h" #include "ih264e_structs.h" -#include "ih264_trans_data.h" -#include "ih264_deblk_tables.h" #include "ih264e_deblk.h" /*****************************************************************************/ -/* Extern global definitions */ +/* global definitions */ /*****************************************************************************/ /** @@ -161,7 +165,6 @@ static const UWORD16 ih264e_gu2_4x4_v2h_reorder[16] = * @param[in] ps_curr_pu * PU for current MB * -* * @returns none * * @remarks none @@ -296,7 +299,7 @@ static void ih264e_fill_bs_1mv_1ref_non_mbaff(UWORD32 *pu4_horz_bs, { u4_left_flag = 1; } - else if(ps_curr_pu->b2_pred_mode != 2)/* Not bipred */ + else if (ps_curr_pu->b2_pred_mode != 2)/* Not bipred */ { i16_pMvl0_x = ps_left_pu->s_me_info[ps_left_pu->b2_pred_mode].s_mv.i2_mvx; i16_pMvl0_y = ps_left_pu->s_me_info[ps_left_pu->b2_pred_mode].s_mv.i2_mvy; @@ -310,7 +313,6 @@ static void ih264e_fill_bs_1mv_1ref_non_mbaff(UWORD32 *pu4_horz_bs, } else { - i16_pMvl0_x = ps_left_pu->s_me_info[PRED_L0].s_mv.i2_mvx; i16_pMvl0_y = ps_left_pu->s_me_info[PRED_L0].s_mv.i2_mvy; i16_pMvl1_x = ps_left_pu->s_me_info[PRED_L1].s_mv.i2_mvx; diff --git a/encoder/ih264e_deblk.h b/encoder/ih264e_deblk.h index 9b3b67b3..35be2fb4 100644 --- a/encoder/ih264e_deblk.h +++ b/encoder/ih264e_deblk.h @@ -24,7 +24,7 @@ * ih264e_deblk.h * * @brief -* This file contains extern declarations of deblocking routines +* This file contains declarations of deblocking routines * * @author * ittiam @@ -34,8 +34,8 @@ ****************************************************************************** */ -#ifndef IH264E_DEBLK_H_ -#define IH264E_DEBLK_H_ +#ifndef _IH264E_DEBLK_H_ +#define _IH264E_DEBLK_H_ /*****************************************************************************/ /* Constant Macros */ @@ -43,9 +43,9 @@ /** ****************************************************************************** - * @brief masks to extract csbp +* @brief masks to extract csbp ****************************************************************************** - */ +*/ #define CSBP_LEFT_BLOCK_MASK 0x1111 #define CSBP_RIGHT_BLOCK_MASK 0x8888 @@ -54,46 +54,8 @@ /* Function Declarations */ /*****************************************************************************/ -/** -******************************************************************************* -* -* @brief This function computes blocking strength for an mb -* -* @par Description: -* This function computes blocking strength for an mb -* -* @param[in] ps_proc -* process context -* -* @returns none -* -* @remarks In this module it is assumed that their is only single reference -* frame and is always the most recently used anchor frame -* -******************************************************************************* -*/ void ih264e_compute_bs(process_ctxt_t * ps_proc); -/** -******************************************************************************* -* -* @brief This function performs deblocking on an mb -* -* @par Description: -* This function performs deblocking on an mb -* -* @param[in] ps_proc -* process context corresponding to the job -* -* @param[in] ps_deblk -* pointer to deblock context -* -* @returns none -* -* @remarks none -* -******************************************************************************* -*/ void ih264e_deblock_mb(process_ctxt_t *ps_proc, deblk_ctxt_t * ps_deblk); -#endif /* IH264E_DEBLK_H_ */ +#endif /* _IH264E_DEBLK_H_ */ diff --git a/encoder/ih264e_defs.h b/encoder/ih264e_defs.h index 1ed57797..4eac48e4 100644 --- a/encoder/ih264e_defs.h +++ b/encoder/ih264e_defs.h @@ -23,21 +23,29 @@ * ih264e_defs.h * * @brief -* Definitions used in the encoder +* Declarations of common definitions used in the encoder library * * @author * ittiam * * @remarks -* None +* none * ******************************************************************************* */ -#ifndef IH264E_DEFS_H_ -#define IH264E_DEFS_H_ +#ifndef _IH264E_DEFS_H_ +#define _IH264E_DEFS_H_ +/*****************************************************************************/ +/* Function Macros */ +/*****************************************************************************/ +/** + ***************************************************************************** + * Macro to extract residue, nnz, significant coefficient map for a 4x4 blk + ***************************************************************************** + */ #define PARSE_COEFF_DATA_BLOCK_4x4(pv_mb_coeff_data, ps_mb_coeff_data, u4_nnz, u4_sig_coeff_map, pi2_res_block) \ { \ ps_mb_coeff_data = pv_mb_coeff_data; \ @@ -54,6 +62,33 @@ } \ } +/** + ***************************************************************************** + * Macro to compute total size required to hold on set of scaling matrices + ***************************************************************************** + */ +#define SCALING_MAT_SIZE(m_scaling_mat_size) \ +{ \ + m_scaling_mat_size = 6 * TRANS_SIZE_4 * TRANS_SIZE_4; \ + m_scaling_mat_size += 6 * TRANS_SIZE_8 * TRANS_SIZE_8; \ + m_scaling_mat_size += 6 * TRANS_SIZE_16 * TRANS_SIZE_16; \ + m_scaling_mat_size += 2 * TRANS_SIZE_32 * TRANS_SIZE_32; \ +} + +/** + ****************************************************************************** + * @brief Macros to get raster scan position of a block[8x8] / sub block[4x4] + ****************************************************************************** + */ +#define GET_BLK_RASTER_POS_X(x) ((x & 0x01)) +#define GET_BLK_RASTER_POS_Y(y) ((y >> 1)) +#define GET_SUB_BLK_RASTER_POS_X(x) ((x & 0x01)) +#define GET_SUB_BLK_RASTER_POS_Y(y) ((y >> 1)) + +/*****************************************************************************/ +/* Constant Macros */ +/*****************************************************************************/ + /*****************************************************************************/ /* Width and height restrictions */ /*****************************************************************************/ @@ -202,7 +237,9 @@ #define LOG2_MAX_SLICE_HDR_CNT 8 #define MAX_SLICE_HDR_CNT (1 << LOG2_MAX_SLICE_HDR_CNT) -/* Generic declarations */ +/** + * Generic declarations + */ #define DEFAULT_MAX_LEVEL 40 #define DEFAULT_RECON_ENABLE 0 #define DEFAULT_QUALITY_METRICS_ENABLE 0 @@ -268,32 +305,88 @@ /** Number of buffers Needed for SUBPEL and BIPRED computation */ #define SUBPEL_BUFF_CNT 4 +#define NUM_RC_MEMTABS 17 + +#define DISABLE_DEBLOCK_INTERVAL 8 + /** Mask value for PSNR. Needed when quality metrics is enabled */ #define QUALITY_MASK_PSNR 0x1 + /** - ***************************************************************************** - * Macro to compute total size required to hold on set of scaling matrices - ***************************************************************************** + **************************************************************************** + * Number of buffers for I/O based on format + **************************************************************************** */ -#define SCALING_MAT_SIZE(m_scaling_mat_size) \ -{ \ - m_scaling_mat_size = 6 * TRANS_SIZE_4 * TRANS_SIZE_4; \ - m_scaling_mat_size += 6 * TRANS_SIZE_8 * TRANS_SIZE_8; \ - m_scaling_mat_size += 6 * TRANS_SIZE_16 * TRANS_SIZE_16; \ - m_scaling_mat_size += 2 * TRANS_SIZE_32 * TRANS_SIZE_32; \ -} + +/** Minimum number of input buffers */ +#define MIN_INP_BUFS 2 + +/** Minimum number of output buffers */ +#define MIN_OUT_BUFS 1 + +/** Minimum number of components in bitstream buffer */ +#define MIN_BITS_BUFS_COMP 1 + +/** Minimum number of components in raw buffer */ +#define MIN_RAW_BUFS_420_COMP 3 +#define MIN_RAW_BUFS_422ILE_COMP 1 +#define MIN_RAW_BUFS_RGB565_COMP 1 +#define MIN_RAW_BUFS_RGBA8888_COMP 1 +#define MIN_RAW_BUFS_420SP_COMP 2 + +/** Maximum number of active config paramter sets */ +#define MAX_ACTIVE_CONFIG_PARAMS 32 /** - ****************************************************************************** - * @brief Macros to get raster scan position of a block[8x8] / sub block[4x4] - ****************************************************************************** - */ -#define GET_BLK_RASTER_POS_X(x) ((x & 0x01)) -#define GET_BLK_RASTER_POS_Y(y) ((y >> 1)) -#define GET_SUB_BLK_RASTER_POS_X(x) ((x & 0x01)) -#define GET_SUB_BLK_RASTER_POS_Y(y) ((y >> 1)) +****************************************************************************** + * @brief Thresholds for luma & chroma to determine if the 8x8 subblock needs + * to be encoded or skipped +****************************************************************************** +*/ +#define LUMA_SUB_BLOCK_SKIP_THRESHOLD 4 +#define LUMA_BLOCK_SKIP_THRESHOLD 5 +#define CHROMA_BLOCK_SKIP_THRESHOLD 4 -#define NUM_RC_MEMTABS 17 +/** +****************************************************************************** + * @brief defines the first byte of a NAL unit + * forbidden zero bit - nal_ref_idc - nal_unit_type +****************************************************************************** +*/ +/* [0 - 11 - 00111] */ +#define NAL_SPS_FIRST_BYTE 0x67 + +/* [0 - 11 - 01000] */ +#define NAL_PPS_FIRST_BYTE 0x68 + +/* [0 - 11 - 00001] */ +#define NAL_SLICE_FIRST_BYTE 0x61 + +/* [0 - 00 - 00001] */ +#define NAL_NON_REF_SLICE_FIRST_BYTE 0x01 + +/* [0 - 11 - 00101] */ +#define NAL_IDR_SLICE_FIRST_BYTE 0x65 + +/* [0 - 00 - 01100] */ +#define NAL_FILLER_FIRST_BYTE 0x0C + +/* [0 - 00 - 00110] */ +#define NAL_SEI_FIRST_BYTE 0x06 + +#define H264_ALLOC_INTER_FRM_INTV 2 + +#define H264_MPEG_QP_MAP 255 + +#define MPEG2_QP_ELEM (H264_MPEG_QP_MAP + 1) +#define H264_QP_ELEM (MAX_H264_QP + 1) + +#define H264_INIT_QUANT_I 26 +#define H264_INIT_QUANT_P 34 + +/*****************************************************************************/ +/* Enums */ +/*****************************************************************************/ /** *************************************************************************** @@ -489,8 +582,6 @@ enum */ }; -#define DISABLE_DEBLOCK_INTERVAL 8 - /** **************************************************************************** * Disable deblock levels @@ -527,76 +618,4 @@ enum DISABLE_DEBLK_LEVEL_4 }; -/** - **************************************************************************** - * Number of buffers for I/O based on format - **************************************************************************** - */ - -/** Minimum number of input buffers */ -#define MIN_INP_BUFS 2 - -/** Minimum number of output buffers */ -#define MIN_OUT_BUFS 1 - -/** Minimum number of components in bitstream buffer */ -#define MIN_BITS_BUFS_COMP 1 - -/** Minimum number of components in raw buffer */ -#define MIN_RAW_BUFS_420_COMP 3 -#define MIN_RAW_BUFS_422ILE_COMP 1 -#define MIN_RAW_BUFS_RGB565_COMP 1 -#define MIN_RAW_BUFS_RGBA8888_COMP 1 -#define MIN_RAW_BUFS_420SP_COMP 2 - -/** Maximum number of active config paramter sets */ -#define MAX_ACTIVE_CONFIG_PARAMS 32 - -/** -****************************************************************************** - * @brief Thresholds for luma & chroma to determine if the 8x8 subblock needs - * to be encoded or skipped -****************************************************************************** -*/ -#define LUMA_SUB_BLOCK_SKIP_THRESHOLD 4 -#define LUMA_BLOCK_SKIP_THRESHOLD 5 -#define CHROMA_BLOCK_SKIP_THRESHOLD 4 - -/** -****************************************************************************** - * @brief defines the first byte of a NAL unit - * forbidden zero bit - nal_ref_idc - nal_unit_type -****************************************************************************** -*/ -/* [0 - 11 - 00111] */ -#define NAL_SPS_FIRST_BYTE 0x67 - -/* [0 - 11 - 01000] */ -#define NAL_PPS_FIRST_BYTE 0x68 - -/* [0 - 11 - 00001] */ -#define NAL_SLICE_FIRST_BYTE 0x61 - -/* [0 - 00 - 00001] */ -#define NAL_NON_REF_SLICE_FIRST_BYTE 0x01 - -/* [0 - 11 - 00101] */ -#define NAL_IDR_SLICE_FIRST_BYTE 0x65 - -/* [0 - 00 - 01100] */ -#define NAL_FILLER_FIRST_BYTE 0x0C - -/* [0 - 00 - 00110] */ -#define NAL_SEI_FIRST_BYTE 0x06 - -#define H264_ALLOC_INTER_FRM_INTV 2 - -#define H264_MPEG_QP_MAP 255 - -#define MPEG2_QP_ELEM (H264_MPEG_QP_MAP + 1) -#define H264_QP_ELEM (MAX_H264_QP + 1) - -#define H264_INIT_QUANT_I 26 -#define H264_INIT_QUANT_P 34 - -#endif /*IH264E_DEFS_H_*/ +#endif /*_IH264E_DEFS_H_ */ diff --git a/encoder/ih264e_encode.c b/encoder/ih264e_encode.c index 275bb59a..537ce26f 100644 --- a/encoder/ih264e_encode.c +++ b/encoder/ih264e_encode.c @@ -31,9 +31,9 @@ * ittiam * * List of Functions -* - ih264e_join_threads() -* - ih264e_wait_for_thread() -* - ih264e_encode() +* - ih264e_join_threads +* - ih264e_wait_for_thread +* - ih264e_encode * ****************************************************************************** */ @@ -50,49 +50,54 @@ #include #include #include -/* User Include files */ + +/* User Include Files */ #include "ih264e_config.h" #include "ih264_typedefs.h" #include "iv2.h" #include "ive2.h" -#include "ih264e.h" #include "ithread.h" -#include "ih264_defs.h" -#include "ih264_macros.h" + #include "ih264_debug.h" -#include "ih264_structs.h" -#include "ih264_platform_macros.h" +#include "ih264_macros.h" #include "ih264_error.h" -#include "ime_distortion_metrics.h" -#include "ime_defs.h" -#include "ime_structs.h" -#include "ih264_trans_quant_itrans_iquant.h" -#include "ih264_inter_pred_filters.h" +#include "ih264_defs.h" #include "ih264_mem_fns.h" #include "ih264_padding.h" +#include "ih264_structs.h" +#include "ih264_trans_quant_itrans_iquant.h" +#include "ih264_inter_pred_filters.h" #include "ih264_intra_pred_filters.h" #include "ih264_deblk_edge_filters.h" #include "ih264_cabac_tables.h" +#include "ih264_buf_mgr.h" #include "ih264_list.h" -#include "ih264e_error.h" -#include "ih264e_defs.h" -#include "ih264e_bitstream.h" +#include "ih264_dpb_mgr.h" +#include "ih264_platform_macros.h" + +#include "ime_defs.h" +#include "ime_distortion_metrics.h" +#include "ime_structs.h" + #include "irc_mem_req_and_acq.h" #include "irc_cntrl_param.h" #include "irc_frame_info_collector.h" -#include "ih264e_rate_control.h" + +#include "ih264e.h" +#include "ih264e_error.h" +#include "ih264e_defs.h" #include "ih264e_time_stamp.h" +#include "ih264e_rate_control.h" +#include "ih264e_bitstream.h" #include "ih264e_cabac_structs.h" #include "ih264e_structs.h" +#include "ih264e_utils.h" +#include "ih264e_encode_header.h" #include "ih264e_master.h" #include "ih264e_process.h" -#include "ih264_buf_mgr.h" -#include "ih264_dpb_mgr.h" -#include "ih264e_utils.h" #include "ih264e_fmt_conv.h" #include "ih264e_statistics.h" #include "ih264e_trace.h" -#include "ih264e_debug.h" #ifdef LOGO_EN #include "ih264e_ittiam_logo.h" #endif @@ -599,7 +604,6 @@ WORD32 ih264e_encode(iv_obj_t *ps_codec_obj, void *pv_api_ip, void *pv_api_op) } - /**************************************************************************** * RECON * Since we have forward dependent frames, we cannot return recon in encoding @@ -715,7 +719,6 @@ WORD32 ih264e_encode(iv_obj_t *ps_codec_obj, void *pv_api_ip, void *pv_api_op) } } - /*************************************************************************** * Free reference buffers: * In case of a post enc skip, we have to ensure that those pics will not @@ -794,7 +797,6 @@ WORD32 ih264e_encode(iv_obj_t *ps_codec_obj, void *pv_api_ip, void *pv_api_op) } } - /************************************************************************** * Signaling to APP * 1) If we valid a valid output mark it so @@ -823,7 +825,6 @@ WORD32 ih264e_encode(iv_obj_t *ps_codec_obj, void *pv_api_ip, void *pv_api_op) ps_video_encode_op->s_ive_op.u4_timestamp_low = s_inp_buf.u4_timestamp_low; ps_video_encode_op->s_ive_op.u4_timestamp_high = s_inp_buf.u4_timestamp_high; - switch (ps_codec->pic_type) { case PIC_IDR: diff --git a/encoder/ih264e_encode_header.c b/encoder/ih264e_encode_header.c index 4eb00179..aa2aa27d 100644 --- a/encoder/ih264e_encode_header.c +++ b/encoder/ih264e_encode_header.c @@ -30,19 +30,20 @@ * ittiam * * @par List of Functions: -* - ih264e_generate_nal_unit_header() -* - ih264e_generate_sps() -* - ih264e_generate_pps() -* - ih264e_generate_sei() -* - ih264e_generate_slice_header() -* - ih264e_get_level() -* - ih264e_populate_sps() -* - ih264e_populate_pps() -* - ih264e_populate_slice_header() -* - ih264e_add_filler_nal_unit() +* - ih264e_generate_nal_unit_header +* - ih264e_generate_vui +* - ih264e_generate_aud +* - ih264e_generate_sps +* - ih264e_generate_pps +* - ih264e_generate_slice_header +* - ih264e_populate_vui +* - ih264e_populate_sps +* - ih264e_populate_pps +* - ih264e_populate_slice_header +* - ih264e_add_filler_nal_unit * * @remarks -* None +* none * ******************************************************************************* */ @@ -51,7 +52,7 @@ /* File Includes */ /*****************************************************************************/ -/* System include files */ +/* System Include Files */ #include #include #include @@ -59,40 +60,44 @@ #include /* User Include Files */ +#include "ih264e_config.h" #include "ih264_typedefs.h" #include "iv2.h" #include "ive2.h" -#include "ih264e.h" #include "ithread.h" -#include "ih264e_config.h" -#include "ih264e_trace.h" -#include "ih264e_error.h" -#include "ih264e_bitstream.h" + #include "ih264_debug.h" -#include "ih264_defs.h" -#include "ime_distortion_metrics.h" -#include "ime_defs.h" -#include "ime_structs.h" +#include "ih264_macros.h" #include "ih264_error.h" +#include "ih264_defs.h" +#include "ih264_mem_fns.h" +#include "ih264_padding.h" #include "ih264_structs.h" #include "ih264_trans_quant_itrans_iquant.h" #include "ih264_inter_pred_filters.h" -#include "ih264_mem_fns.h" -#include "ih264_padding.h" #include "ih264_intra_pred_filters.h" #include "ih264_deblk_edge_filters.h" +#include "ih264_common_tables.h" #include "ih264_cabac_tables.h" -#include "ih264e_defs.h" + +#include "ime_defs.h" +#include "ime_distortion_metrics.h" +#include "ime_structs.h" + #include "irc_cntrl_param.h" #include "irc_frame_info_collector.h" + +#include "ih264e.h" +#include "ih264e_error.h" +#include "ih264e_defs.h" #include "ih264e_rate_control.h" +#include "ih264e_bitstream.h" #include "ih264e_cabac_structs.h" #include "ih264e_structs.h" +#include "ih264e_utils.h" #include "ih264e_sei.h" #include "ih264e_encode_header.h" -#include "ih264_common_tables.h" -#include "ih264_macros.h" -#include "ih264e_utils.h" +#include "ih264e_trace.h" /*****************************************************************************/ @@ -1056,22 +1061,29 @@ WORD32 ih264e_generate_slice_header(bitstrm_t *ps_bitstrm, */ IH264E_ERROR_T ih264e_populate_vui(codec_t *ps_codec) { - + /* vui params */ vui_t *ps_vui = &ps_codec->s_cfg.s_vui; - sps_t *ps_sps = ps_codec->ps_sps_base + ps_codec->i4_sps_id; + /* active sps params */ + sps_t *ps_sps = ps_codec->ps_sps_base + ps_codec->i4_sps_id; ps_vui->u1_nal_hrd_parameters_present_flag = 0; + ps_vui->u1_vcl_hrd_parameters_present_flag = 0; ps_vui->u1_bitstream_restriction_flag = 1; + ps_vui->u1_motion_vectors_over_pic_boundaries_flag = 1; + ps_vui->u1_max_bytes_per_pic_denom = 0; + ps_vui->u1_max_bits_per_mb_denom = 0; + ps_vui->u1_log2_max_mv_length_horizontal = 16; + ps_vui->u1_log2_max_mv_length_vertical = 16; - if(ps_codec->s_cfg.u4_num_bframes == 0) + if (ps_codec->s_cfg.u4_num_bframes == 0) { ps_vui->u1_num_reorder_frames = 0; } @@ -1082,12 +1094,9 @@ IH264E_ERROR_T ih264e_populate_vui(codec_t *ps_codec) ps_vui->u1_max_dec_frame_buffering = ps_sps->u1_max_num_ref_frames; - - return 0; + return IH264E_SUCCESS; } - - /** ****************************************************************************** * @@ -1259,6 +1268,7 @@ IH264E_ERROR_T ih264e_populate_sps(codec_t *ps_codec, sps_t *ps_sps) ps_sps->i1_direct_8x8_inference_flag = 1; } + /* cropping params */ /*NOTE : Cropping values depend on the chroma format * For our case ,decoder interprets the cropping values as 2*num pixels @@ -1365,6 +1375,7 @@ IH264E_ERROR_T ih264e_populate_pps(codec_t *ps_codec, pps_t *ps_pps) ps_pps->i1_redundant_pic_cnt_present_flag = 0; ps_pps->u1_slice_group_map_type = 0; + return IH264E_SUCCESS; } diff --git a/encoder/ih264e_encode_header.h b/encoder/ih264e_encode_header.h index c4876b38..3f480b4a 100644 --- a/encoder/ih264e_encode_header.h +++ b/encoder/ih264e_encode_header.h @@ -31,13 +31,13 @@ * ittiam * * @remarks -* None +* none * ******************************************************************************* */ -#ifndef IH264E_ENCODE_HEADER_H_ -#define IH264E_ENCODE_HEADER_H_ +#ifndef _IH264E_ENCODE_HEADER_H_ +#define _IH264E_ENCODE_HEADER_H_ /*****************************************************************************/ /* Function Macros */ @@ -106,228 +106,33 @@ } /*****************************************************************************/ -/* Extern Function Declarations */ +/* Function Declarations */ /*****************************************************************************/ -/** -****************************************************************************** -* -* @brief Generates SPS (Sequence Parameter Set) -* -* @par Description -* This function generates Sequence Parameter Set header as per the spec -* -* @param[in] ps_bitstrm -* pointer to bitstream context (handle) -* -* @param[in] ps_sps -* pointer to structure containing SPS data -* -* @return success or failure error code -* -****************************************************************************** -*/ -WORD32 ih264e_generate_sps - ( - bitstrm_t *ps_bitstrm, - sps_t *ps_sps, - vui_t *ps_vui - ); - -/** -****************************************************************************** -* -* @brief Generates PPS (Picture Parameter Set) -* -* @par Description -* Generate Picture Parameter Set as per Section 7.3.2.2 -* -* @param[in] ps_bitstrm -* pointer to bitstream context (handle) -* -* @param[in] ps_pps -* pointer to structure containing PPS data -* -* @return success or failure error code -* -****************************************************************************** -*/ -WORD32 ih264e_generate_pps - ( - bitstrm_t *ps_bitstrm, - pps_t *ps_pps, - sps_t *ps_sps - ); - -/** -****************************************************************************** -* -* @brief Generates SEI (Supplemental Enhancement Information) -* -* @par Description -* This function generates Supplemental Enhancement Information header as per the spec -* -* @param[in] ps_bitstrm -* pointer to bitstream context (handle) -* -* @param[in] ps_sei -* pointer to structure containing SEI data -* -* @return success or failure error code -* -****************************************************************************** -*/ -IH264E_ERROR_T ih264e_generate_sei - ( - bitstrm_t *ps_bitstrm, - sei_params_t *ps_sei, - UWORD32 u4_insert_per_idr - ); +WORD32 ih264e_generate_sps(bitstrm_t *ps_bitstrm, sps_t *ps_sps, vui_t *ps_vui); -/** -****************************************************************************** -* -* @brief Generates Slice Header -* -* @par Description -* Generate Slice Header as per Section 7.3.5.1 -* -* @param[inout] ps_bitstrm -* pointer to bitstream context for generating slice header -* -* @param[in] ps_slice_hdr -* pointer to slice header params -* -* @param[in] ps_pps -* pointer to pps params referred by slice -* -* @param[in] ps_sps -* pointer to sps params referred by slice -* -* @param[out] ps_dup_bit_strm_ent_offset -* Bitstream struct to store bitstream state -* -* @param[out] pu4_first_slice_start_offset -* first slice offset is returned -* -* @return success or failure error code -* -****************************************************************************** -*/ -WORD32 ih264e_generate_slice_header - ( - bitstrm_t *ps_bitstrm, - slice_header_t *ps_slice_hdr, - pps_t *ps_pps, - sps_t *ps_sps - ); +WORD32 ih264e_generate_pps(bitstrm_t *ps_bitstrm, pps_t *ps_pps, sps_t *ps_sps); -/** -****************************************************************************** -* -* @brief Populates sps structure -* -* @par Description -* Populates sps structure for its use in header generation -* -* @param[in] ps_codec -* pointer to encoder context -* -* @param[out] ps_sps -* pointer to sps params that needs to be populated -* -* @return success or failure error code -* -****************************************************************************** -*/ -IH264E_ERROR_T ih264e_populate_sps - ( - codec_t *ps_codec, - sps_t *ps_sps - ); +IH264E_ERROR_T ih264e_generate_sei(bitstrm_t *ps_bitstrm, + sei_params_t *ps_sei, + UWORD32 u4_insert_per_idr); -/** -****************************************************************************** -* -* @brief Populates pps structure -* -* @par Description -* Populates pps structure for its use in header generation -* -* @param[in] ps_codec -* pointer to encoder context -* -* @param[out] ps_pps -* pointer to pps params that needs to be populated -* -* @return success or failure error code -* -****************************************************************************** -*/ -IH264E_ERROR_T ih264e_populate_pps - ( - codec_t *ps_codec, - pps_t *ps_pps - ); +WORD32 ih264e_generate_slice_header(bitstrm_t *ps_bitstrm, + slice_header_t *ps_slice_hdr, + pps_t *ps_pps, + sps_t *ps_sps); +IH264E_ERROR_T ih264e_populate_sps(codec_t *ps_codec, sps_t *ps_sps); -/** -****************************************************************************** -* -* @brief Populates slice header structure -* -* @par Description -* Populates slice header structure for its use in header generation -* -* @param[in] ps_proc -* pointer to proc context -* -* @param[out] ps_slice_hdr -* pointer to slice header structure that needs to be populated -* -* @param[in] ps_pps -* pointer to pps params structure referred by the slice -* -* @param[in] ps_sps -* pointer to sps params referred by the pps -* -* @return success or failure error code -* -****************************************************************************** -*/ -WORD32 ih264e_populate_slice_header - ( - process_ctxt_t *ps_proc, - slice_header_t *ps_slice_hdr, - pps_t *ps_pps, - sps_t *ps_sps - ); +IH264E_ERROR_T ih264e_populate_pps(codec_t *ps_codec, pps_t *ps_pps); +WORD32 ih264e_populate_slice_header(process_ctxt_t *ps_proc, + slice_header_t *ps_slice_hdr, + pps_t *ps_pps, + sps_t *ps_sps); -/** -****************************************************************************** -* -* @brief inserts FILLER Nal Unit. -* -* @par Description -* In constant bit rate rc mode, when the bits generated by the codec is -* underflowing the target bit rate, the encoder library inserts filler nal unit. -* -* @param[in] ps_bitstrm -* pointer to bitstream context (handle) -* -* @param[in] insert_fill_bytes -* Number of fill bytes to be inserted -* -* @return success or failure error code -* -****************************************************************************** -*/ -IH264E_ERROR_T ih264e_add_filler_nal_unit - ( - bitstrm_t *ps_bitstrm, - WORD32 insert_fill_bytes - ); +IH264E_ERROR_T ih264e_add_filler_nal_unit(bitstrm_t *ps_bitstrm, + WORD32 insert_fill_bytes); -#endif //IH264E_ENCODE_HEADER_H_ +#endif /* _IH264E_ENCODE_HEADER_H_ */ diff --git a/encoder/ih264e_error.h b/encoder/ih264e_error.h index f0cc3fc1..d0fd2945 100644 --- a/encoder/ih264e_error.h +++ b/encoder/ih264e_error.h @@ -30,13 +30,17 @@ * ittiam * * @remarks -* None +* none * ******************************************************************************* */ -#ifndef IH264E_ERROR_H_ -#define IH264E_ERROR_H_ +#ifndef _IH264E_ERROR_H_ +#define _IH264E_ERROR_H_ + +/*****************************************************************************/ +/* Function Macros */ +/*****************************************************************************/ /** ****************************************************************************** @@ -51,6 +55,9 @@ if (severity == IVE_FATALERROR) return (ret_code);\ } +/*****************************************************************************/ +/* Enums */ +/*****************************************************************************/ /** ****************************************************************************** @@ -254,4 +261,4 @@ typedef enum }IH264E_ERROR_T; -#endif /* IH264E_ERROR_H_ */ +#endif /* _IH264E_ERROR_H_ */ diff --git a/encoder/ih264e_fmt_conv.c b/encoder/ih264e_fmt_conv.c index e06aea1b..42695724 100644 --- a/encoder/ih264e_fmt_conv.c +++ b/encoder/ih264e_fmt_conv.c @@ -30,17 +30,17 @@ * ittiam * * @par List of Functions: -* - ih264e_fmt_conv_420sp_to_rgb565() -* - ih264e_fmt_conv_420sp_to_rgba8888() -* - ih264e_fmt_conv_420sp_to_420sp() -* - ih264e_fmt_conv_420sp_to_420sp_swap_uv() -* - ih264e_fmt_conv_420sp_to_420p() -* - ih264e_fmt_conv_420p_to_420sp() -* - ih264e_fmt_conv_422i_to_420sp() -* - ih264e_fmt_conv() +* - ih264e_fmt_conv_420sp_to_rgb565 +* - ih264e_fmt_conv_420sp_to_rgba8888 +* - ih264e_fmt_conv_420sp_to_420sp +* - ih264e_fmt_conv_420sp_to_420sp_swap_uv +* - ih264e_fmt_conv_420sp_to_420p +* - ih264e_fmt_conv_420p_to_420sp +* - ih264e_fmt_conv_422i_to_420sp +* - ih264e_fmt_conv * * @remarks -* None +* none * ******************************************************************************* */ @@ -49,42 +49,45 @@ /* File Includes */ /*****************************************************************************/ -/* System Include files */ +/* System Include Files */ #include #include #include #include #include -/* User Include files */ +/* User Include Files */ #include "ih264_typedefs.h" #include "iv2.h" #include "ive2.h" -#include "ih264e.h" #include "ithread.h" -#include "ih264_defs.h" + #include "ih264_debug.h" -#include "ime_distortion_metrics.h" -#include "ime_defs.h" -#include "ime_structs.h" +#include "ih264_macros.h" #include "ih264_error.h" +#include "ih264_defs.h" +#include "ih264_mem_fns.h" +#include "ih264_padding.h" #include "ih264_structs.h" #include "ih264_trans_quant_itrans_iquant.h" #include "ih264_inter_pred_filters.h" -#include "ih264_mem_fns.h" -#include "ih264_padding.h" #include "ih264_intra_pred_filters.h" #include "ih264_deblk_edge_filters.h" #include "ih264_cabac_tables.h" -#include "ih264_macros.h" #include "ih264_platform_macros.h" -#include "ih264_buf_mgr.h" -#include "ih264e_defs.h" -#include "ih264e_error.h" -#include "ih264e_bitstream.h" + +#include "ime_defs.h" +#include "ime_distortion_metrics.h" +#include "ime_structs.h" + #include "irc_cntrl_param.h" #include "irc_frame_info_collector.h" + +#include "ih264e.h" +#include "ih264e_error.h" +#include "ih264e_defs.h" #include "ih264e_rate_control.h" +#include "ih264e_bitstream.h" #include "ih264e_cabac_structs.h" #include "ih264e_structs.h" #include "ih264e_fmt_conv.h" @@ -94,6 +97,45 @@ /* Function Definitions */ /*****************************************************************************/ +/** +******************************************************************************* +* +* @brief Function used to perform color space conversion from 420SP to RGB565 +* +* @par Description +* Function used to perform color space conversion from 420SP to RGB565 +* +* @param[in] pu1_y_src +* Input Y pointer +* +* @param[in] pu1_uv_src +* Input UV pointer +* +* @param[in] pu2_rgb_dst +* Output RGB pointer +* +* @param[in] wd +* Width +* +* @param[in] ht +* Height +* +* @param[in] src_y_strd +* Input Y Stride +* +* @param[in] src_uv_strd +* Input UV stride +* +* @param[in] dst_strd +* Output stride +* +* @param[in] is_u_first +* Flag to indicate chroma ordering +* +* @returns none +* +******************************************************************************* +*/ void ih264e_fmt_conv_420sp_to_rgb565(UWORD8 *pu1_y_src, UWORD8 *pu1_uv_src, UWORD16 *pu2_rgb_dst, @@ -207,6 +249,45 @@ void ih264e_fmt_conv_420sp_to_rgb565(UWORD8 *pu1_y_src, } +/** +******************************************************************************* +* +* @brief Function used to perform color space conversion from 420SP to RGBA888 +* +* @par Description +* Function used to perform color space conversion from 420SP to RGBA888 +* +* @param[in] pu1_y_src +* Input Y pointer +* +* @param[in] pu1_uv_src +* Input UV pointer +* +* @param[in] pu4_rgba_dst +* Output RGB pointer +* +* @param[in] wd +* Width +* +* @param[in] ht +* Height +* +* @param[in] src_y_strd +* Input Y Stride +* +* @param[in] src_uv_strd +* Input UV stride +* +* @param[in] dst_strd +* Output stride +* +* @param[in] is_u_first +* Flag to indicate chroma ordering +* +* @returns none +* +******************************************************************************* +*/ void ih264e_fmt_conv_420sp_to_rgba8888(UWORD8 *pu1_y_src, UWORD8 *pu1_uv_src, UWORD32 *pu4_rgba_dst, @@ -350,10 +431,6 @@ void ih264e_fmt_conv_420sp_to_rgba8888(UWORD8 *pu1_y_src, * * @returns None * -* @remarks In case there is a need to perform partial frame copy then -* by passion appropriate source and destination pointers and appropriate -* values for wd and ht it can be done -* ******************************************************************************* */ void ih264e_fmt_conv_420sp_to_420sp(UWORD8 *pu1_y_src, @@ -407,7 +484,48 @@ void ih264e_fmt_conv_420sp_to_420sp(UWORD8 *pu1_y_src, return; } - +/** +******************************************************************************* +* +* @brief Function used for copying a 420SP buffer and interchange chroma planes +* +* @par Description +* Function used for copying a 420SP buffer and interchange chroma planes +* +* @param[in] pu1_y_src +* Input Y pointer +* +* @param[in] pu1_uv_src +* Input UV pointer (UV is interleaved either in UV or VU format) +* +* @param[in] pu1_y_dst +* Output Y pointer +* +* @param[in] pu1_uv_dst +* Output UV pointer (UV is interleaved in the opp. format as that of input) +* +* @param[in] wd +* Width +* +* @param[in] ht +* Height +* +* @param[in] src_y_strd +* Input Y Stride +* +* @param[in] src_uv_strd +* Input UV stride +* +* @param[in] dst_y_strd +* Output Y stride +* +* @param[in] dst_uv_strd +* Output UV stride +* +* @returns None +* +******************************************************************************* +*/ void ih264e_fmt_conv_420sp_to_420sp_swap_uv(UWORD8 *pu1_y_src, UWORD8 *pu1_uv_src, UWORD8 *pu1_y_dst, @@ -464,6 +582,59 @@ void ih264e_fmt_conv_420sp_to_420sp_swap_uv(UWORD8 *pu1_y_src, return; } +/** +******************************************************************************* +* +* @brief Function used to perform color space conversion from 420SP to 420P +* +* @par Description +* Function used to perform color space conversion from 420SP to 420P +* +* @param[in] pu1_y_src +* Input Y pointer +* +* @param[in] pu1_uv_src +* Input UV pointer (UV is interleaved either in UV or VU format) +* +* @param[in] pu1_y_dst +* Output Y pointer +* +* @param[in] pu1_u_dst +* Output U pointer +* +* @param[in] pu1_v_dst +* Output V pointer +* +* @param[in] wd +* Width +* +* @param[in] ht +* Height +* +* @param[in] src_y_strd +* Input Y Stride +* +* @param[in] src_uv_strd +* Input UV stride +* +* @param[in] dst_y_strd +* Output Y stride +* +* @param[in] dst_uv_strd +* Output UV stride +* +* @param[in] is_u_first +* Flag to indicate chroma ordering +* +* @param[in] disable_luma_copy +* Flag to indicate if only UV copy needs to be done +* +* @returns none +* +* @remarks none +* +******************************************************************************* +*/ void ih264e_fmt_conv_420sp_to_420p(UWORD8 *pu1_y_src, UWORD8 *pu1_uv_src, UWORD8 *pu1_y_dst, @@ -585,9 +756,7 @@ void ih264e_fmt_conv_420sp_to_420p(UWORD8 *pu1_y_src, * * @returns none * -* @remarks In case there is a need to perform partial frame copy then -* by passion appropriate source and destination pointers and appropriate -* values for wd and ht it can be done +* @remarks none * ******************************************************************************* */ @@ -615,7 +784,6 @@ void ih264e_fmt_conv_420p_to_420sp(UWORD8 *pu1_y_src, if (0 == convert_uv_only) { - /* Copy Y buffer */ pu1_dst = (UWORD8 *) pu1_y_dst; pu1_src = (UWORD8 *) pu1_y_src; @@ -693,8 +861,8 @@ void ih264e_fmt_conv_420p_to_420sp(UWORD8 *pu1_y_src, * @returns None * * @remarks For conversion -* pu1_v_buf = pu1_u_buf+1 -* u4_u_stride = u4_v_stride +* pu1_v_buf = pu1_u_buf+1 +* u4_u_stride = u4_v_stride * * The extra parameters are for maintaining API with assembly function * @@ -752,12 +920,18 @@ void ih264e_fmt_conv_422i_to_420sp(UWORD8 *pu1_y_buf, /** ******************************************************************************* * -* @brief Function used from format conversion or frame copy +* @brief Function used for format conversion or frame copy * * @par Description * Function used from copying or converting a reference frame to display buffer * in non shared mode * +* @param[in] ps_codec +* Codec ctxt +* +* @param[in] ps_pic +* Reference pic ctxt +* * @param[in] pu1_y_dst * Output Y pointer * @@ -773,19 +947,15 @@ void ih264e_fmt_conv_422i_to_420sp(UWORD8 *pu1_y_buf, * @param[in] u4_dst_u_strd * Stride of destination U/V buffer * -* @param[in] blocking -* To indicate whether format conversion should wait till frame is reconstructed -* and then return after complete copy is done. To be set to 1 when called at the -* end of frame processing and set to 0 when called between frame processing modules -* in order to utilize available MCPS +* @param[in] cur_row +* Start row of fmt conversion +* +* @param[in] num_rows +* number of rows to process * * @returns error status * -* @remarks -* Assumes that the stride of U and V buffers are same. -* This is correct in most cases -* If a case comes where this is not true we need to modify the fmt conversion -* functions called inside also +* @remarks Assumes that the stride of U and V buffers are same. * ******************************************************************************* */ @@ -810,14 +980,12 @@ IH264E_ERROR_T ih264e_fmt_conv(codec_t *ps_codec, UWORD8 *pu1_chroma; WORD32 dst_stride, wd; - if (0 == num_rows) return ret; pu1_luma = ps_pic->pu1_luma; pu1_chroma = ps_pic->pu1_chroma; - dst_stride = ps_codec->s_cfg.u4_wd; wd = ps_codec->s_cfg.u4_disp_wd; is_u_first = (IV_YUV_420SP_UV == ps_codec->e_codec_color_format) ? 1 : 0; diff --git a/encoder/ih264e_fmt_conv.h b/encoder/ih264e_fmt_conv.h index 6b33bf08..b183cea4 100644 --- a/encoder/ih264e_fmt_conv.h +++ b/encoder/ih264e_fmt_conv.h @@ -24,25 +24,33 @@ * ih264e_fmt_conv.h * * @brief -* The file contains extern declarations of color space conversion routines +* The file contains declarations of color space conversion routines * * @author * ittiam * * @remarks -* None +* none * ******************************************************************************* */ -#ifndef IH264E_FMT_CONV_H_ -#define IH264E_FMT_CONV_H_ +#ifndef _IH264E_FMT_CONV_H_ +#define _IH264E_FMT_CONV_H_ + +/*****************************************************************************/ +/* Constant Macros */ +/*****************************************************************************/ #define COEFF1 13073 #define COEFF2 -3207 #define COEFF3 -6664 #define COEFF4 16530 +/*****************************************************************************/ +/* Function Declarations */ +/*****************************************************************************/ + IH264E_ERROR_T ih264e_fmt_conv(codec_t *ps_codec, pic_buf_t *ps_pic, UWORD8 *pu1_y_dst, @@ -113,20 +121,19 @@ typedef void ih264e_fmt_conv_422i_to_420sp_ft(UWORD8 *pu1_y_buf,UWORD8 *pu1_u_bu /* C function declarations */ -ih264e_fmt_conv_420sp_to_rgba8888_ft ih264e_fmt_conv_420sp_to_rgba8888; -ih264e_fmt_conv_420sp_to_rgb565_ft ih264e_fmt_conv_420sp_to_rgb565; -ih264e_fmt_conv_420sp_to_420sp_ft ih264e_fmt_conv_420sp_to_420sp; -ih264e_fmt_conv_420sp_to_420p_ft ih264e_fmt_conv_420sp_to_420p; -ih264e_fmt_conv_420p_to_420sp_ft ih264e_fmt_conv_420p_to_420sp; -ih264e_fmt_conv_422i_to_420sp_ft ih264e_fmt_conv_422i_to_420sp; +ih264e_fmt_conv_420sp_to_rgba8888_ft ih264e_fmt_conv_420sp_to_rgba8888; +ih264e_fmt_conv_420sp_to_rgb565_ft ih264e_fmt_conv_420sp_to_rgb565; +ih264e_fmt_conv_420sp_to_420sp_ft ih264e_fmt_conv_420sp_to_420sp; +ih264e_fmt_conv_420sp_to_420p_ft ih264e_fmt_conv_420sp_to_420p; +ih264e_fmt_conv_420p_to_420sp_ft ih264e_fmt_conv_420p_to_420sp; +ih264e_fmt_conv_422i_to_420sp_ft ih264e_fmt_conv_422i_to_420sp; /* A9Q function declarations */ -ih264e_fmt_conv_420sp_to_rgba8888_ft ih264e_fmt_conv_420sp_to_rgba8888_a9q; -ih264e_fmt_conv_420sp_to_420sp_ft ih264e_fmt_conv_420sp_to_420sp_a9q; -ih264e_fmt_conv_420sp_to_420p_ft ih264e_fmt_conv_420sp_to_420p_a9q; -ih264e_fmt_conv_420p_to_420sp_ft ih264e_fmt_conv_420p_to_420sp_a9q; -ih264e_fmt_conv_422i_to_420sp_ft ih264e_fmt_conv_422i_to_420sp_a9q; - +ih264e_fmt_conv_420sp_to_rgba8888_ft ih264e_fmt_conv_420sp_to_rgba8888_a9q; +ih264e_fmt_conv_420sp_to_420sp_ft ih264e_fmt_conv_420sp_to_420sp_a9q; +ih264e_fmt_conv_420sp_to_420p_ft ih264e_fmt_conv_420sp_to_420p_a9q; +ih264e_fmt_conv_420p_to_420sp_ft ih264e_fmt_conv_420p_to_420sp_a9q; +ih264e_fmt_conv_422i_to_420sp_ft ih264e_fmt_conv_422i_to_420sp_a9q; /* A9A function declarations */ ih264e_fmt_conv_420sp_to_rgba8888_ft ih264e_fmt_conv_420sp_to_rgba8888_a9a; @@ -139,4 +146,4 @@ ih264e_fmt_conv_420sp_to_420p_ft ih264e_fmt_conv_420sp_to_420p_ssse31; /* SSE4 function declarations */ ih264e_fmt_conv_420sp_to_420p_ft ih264e_fmt_conv_420sp_to_420p_sse42; -#endif /* IH264E_FMT_CONV_H_ */ +#endif /* _IH264E_FMT_CONV_H_ */ diff --git a/encoder/ih264e_function_selector_generic.c b/encoder/ih264e_function_selector_generic.c index 8305fd2e..2730900e 100644 --- a/encoder/ih264e_function_selector_generic.c +++ b/encoder/ih264e_function_selector_generic.c @@ -33,7 +33,7 @@ * - ih264e_init_function_ptr_generic * * @remarks -* None +* none * ******************************************************************************* */ @@ -43,48 +43,50 @@ /* File Includes */ /*****************************************************************************/ - -/* System Include files */ +/* System Include Files */ #include #include #include #include -/* User Include files */ +/* User Include Files */ #include "ih264_typedefs.h" #include "iv2.h" #include "ive2.h" -#include "ih264_defs.h" -#include "ih264_size_defs.h" -#include "ih264e_defs.h" -#include "ih264e_error.h" -#include "ih264e_bitstream.h" -#include "ime_distortion_metrics.h" -#include "ime_defs.h" -#include "ime_structs.h" + #include "ih264_error.h" +#include "ih264_defs.h" +#include "ih264_mem_fns.h" +#include "ih264_padding.h" #include "ih264_structs.h" #include "ih264_trans_quant_itrans_iquant.h" #include "ih264_inter_pred_filters.h" -#include "ih264_mem_fns.h" -#include "ih264_padding.h" #include "ih264_intra_pred_filters.h" #include "ih264_deblk_edge_filters.h" +#include "ih264_cavlc_tables.h" #include "ih264_cabac_tables.h" + +#include "ime_defs.h" +#include "ime_distortion_metrics.h" +#include "ime_structs.h" + #include "irc_cntrl_param.h" #include "irc_frame_info_collector.h" + +#include "ih264e_error.h" +#include "ih264e_defs.h" #include "ih264e_rate_control.h" +#include "ih264e_bitstream.h" #include "ih264e_cabac_structs.h" #include "ih264e_structs.h" -#include "ih264e_platform_macros.h" -#include "ih264e_cabac.h" +#include "ih264e_me.h" +#include "ih264e_half_pel.h" +#include "ih264e_intra_modes_eval.h" #include "ih264e_core_coding.h" -#include "ih264_cavlc_tables.h" #include "ih264e_cavlc.h" -#include "ih264e_intra_modes_eval.h" +#include "ih264e_cabac.h" #include "ih264e_fmt_conv.h" -#include "ih264e_half_pel.h" -#include "ih264e_me.h" +#include "ih264e_platform_macros.h" /*****************************************************************************/ @@ -94,8 +96,7 @@ /** ******************************************************************************* * -* @brief Initialize the intra/inter/transform/deblk function pointers of -* codec context +* @brief Initialize the intra/inter/transform/deblk/entropy function pointers * * @par Description: the current routine initializes the function pointers of * codec context basing on the architecture in use @@ -113,10 +114,6 @@ void ih264e_init_function_ptr_generic(codec_t *ps_codec) { WORD32 i = 0; - /* curr proc ctxt */ - process_ctxt_t *ps_proc = NULL; - me_ctxt_t *ps_me_ctxt = NULL; - /* Init function pointers for intra pred leaf level functions luma * Intra 16x16 */ ps_codec->apf_intra_pred_16_l[0] = ih264_intra_pred_luma_16x16_mode_vert; @@ -155,22 +152,22 @@ void ih264e_init_function_ptr_generic(codec_t *ps_codec) ps_codec->apf_intra_pred_c[3] = ih264_intra_pred_chroma_8x8_mode_plane; /* Init luma forward transform fn ptr */ - ps_codec->pf_resi_trans_quant_8x8 = ih264_resi_trans_quant_8x8; - ps_codec->pf_resi_trans_quant_4x4 = ih264_resi_trans_quant_4x4; - ps_codec->pf_resi_trans_quant_chroma_4x4 = ih264_resi_trans_quant_chroma_4x4; - ps_codec->pf_hadamard_quant_4x4 = ih264_hadamard_quant_4x4; - ps_codec->pf_hadamard_quant_2x2_uv = ih264_hadamard_quant_2x2_uv; + ps_codec->pf_resi_trans_quant_8x8 = ih264_resi_trans_quant_8x8; + ps_codec->pf_resi_trans_quant_4x4 = ih264_resi_trans_quant_4x4; + ps_codec->pf_resi_trans_quant_chroma_4x4 = ih264_resi_trans_quant_chroma_4x4; + ps_codec->pf_hadamard_quant_4x4 = ih264_hadamard_quant_4x4; + ps_codec->pf_hadamard_quant_2x2_uv = ih264_hadamard_quant_2x2_uv; /* Init inverse transform fn ptr */ - ps_codec->pf_iquant_itrans_recon_8x8 = ih264_iquant_itrans_recon_8x8; - ps_codec->pf_iquant_itrans_recon_4x4 = ih264_iquant_itrans_recon_4x4; - ps_codec->pf_iquant_itrans_recon_4x4_dc = ih264_iquant_itrans_recon_4x4_dc; - ps_codec->pf_iquant_itrans_recon_chroma_4x4 = ih264_iquant_itrans_recon_chroma_4x4; + ps_codec->pf_iquant_itrans_recon_8x8 = ih264_iquant_itrans_recon_8x8; + ps_codec->pf_iquant_itrans_recon_4x4 = ih264_iquant_itrans_recon_4x4; + ps_codec->pf_iquant_itrans_recon_4x4_dc = ih264_iquant_itrans_recon_4x4_dc; + ps_codec->pf_iquant_itrans_recon_chroma_4x4 = ih264_iquant_itrans_recon_chroma_4x4; ps_codec->pf_iquant_itrans_recon_chroma_4x4_dc = ih264_iquant_itrans_recon_chroma_4x4_dc; - ps_codec->pf_ihadamard_scaling_4x4 = ih264_ihadamard_scaling_4x4; - ps_codec->pf_ihadamard_scaling_2x2_uv = ih264_ihadamard_scaling_2x2_uv; - ps_codec->pf_interleave_copy = ih264_interleave_copy; + ps_codec->pf_ihadamard_scaling_4x4 = ih264_ihadamard_scaling_4x4; + ps_codec->pf_ihadamard_scaling_2x2_uv = ih264_ihadamard_scaling_2x2_uv; + ps_codec->pf_interleave_copy = ih264_interleave_copy; /* Init fn ptr luma core coding */ ps_codec->luma_energy_compaction[0] = ih264e_code_luma_intra_macroblock_16x16; @@ -230,9 +227,9 @@ void ih264e_init_function_ptr_generic(codec_t *ps_codec) /* sad me level functions */ for (i = 0; i < (MAX_PROCESS_CTXT); i++) { - ps_proc = &ps_codec->as_process[i]; + process_ctxt_t *ps_proc = &ps_codec->as_process[i]; + me_ctxt_t *ps_me_ctxt = &ps_proc->s_me_ctxt; - ps_me_ctxt = &ps_proc->s_me_ctxt; ps_me_ctxt->pf_ime_compute_sad_16x16[0] = ime_compute_sad_16x16; ps_me_ctxt->pf_ime_compute_sad_16x16[1] = ime_compute_sad_16x16_fast; ps_me_ctxt->pf_ime_compute_sad_16x8 = ime_compute_sad_16x8; @@ -263,7 +260,4 @@ void ih264e_init_function_ptr_generic(codec_t *ps_codec) /* skip decision */ ps_codec->apf_find_skip_params_me[PSLICE] = &ih264e_find_pskip_params_me; ps_codec->apf_find_skip_params_me[BSLICE] = &ih264e_find_bskip_params_me; - - - return; } diff --git a/encoder/ih264e_globals.c b/encoder/ih264e_globals.c index 6719c5f2..2639273d 100644 --- a/encoder/ih264e_globals.c +++ b/encoder/ih264e_globals.c @@ -17,6 +17,7 @@ ***************************************************************************** * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore */ + /** ******************************************************************************* * @file @@ -28,9 +29,6 @@ * @author * ittiam * -* @par List of functions -* -* * @remarks * ******************************************************************************* @@ -40,19 +38,19 @@ /* File Includes */ /*****************************************************************************/ -/* User include files */ +/* User Include Files */ #include "ih264_typedefs.h" #include "ih264_defs.h" #include "ih264e_defs.h" #include "ih264e_globals.h" /*****************************************************************************/ -/* Extern global definitions */ +/* Global definitions */ /*****************************************************************************/ /** ****************************************************************************** -* @brief lamda for varying quantizer scales that would be used to +* @brief lambda for varying quantizer scales that would be used to * compute the RD cost while deciding on the MB modes. * input : qp * output : lambda @@ -112,7 +110,6 @@ const UWORD8 u1_uev_codelength[32] = 9, 9, 9, 9, 9, 9, 9, 11, }; - /** ****************************************************************************** * @brief Look up table to assign cost to a coefficient of a residual block @@ -196,7 +193,6 @@ const WORD8 gi1_mv_pred_condition[8] = -1, 0, 1, -1, 2, -1, -1, -1 }; - /******************************************************************************* * Translation of MPEG QP to H264 QP ******************************************************************************/ @@ -209,10 +205,9 @@ const WORD8 gi1_mv_pred_condition[8] = * By not considering the weight matrix in both MPEG and H264 we in effect * only changing the relation to * QPrc = c + d*2^(QPen) - * This will only entatil changin the RC model parameters, and this will + * This will only entail changing the RC model parameters, and this will * not affect rc relation at all * - * * We have MPEG qp which varies from 0-228. The quantization factor has a linear * relation ship with the size of quantized values * @@ -235,7 +230,6 @@ const WORD8 gi1_mv_pred_condition[8] = * QPm = a + b*2^(Qph/6) * QPh = 6*log((Qpm - a)/b) * - * * Unrounded values for gau1_h264_to_mpeg2_qmap[H264_QP_ELEM] = * * 0.625 0.70077 0.78581 0.88127 0.98843 1.10870 @@ -248,8 +242,6 @@ const WORD8 gi1_mv_pred_condition[8] = * 79.19990 88.89811 99.78398 112.00296 125.71830 141.11325 * 158.39350 177.78992 199.56167 223.99963 * - * - * * Unrounded values for gau1_mpeg2_to_h264_qmap[MPEG2_QP_ELEM] * * 0 4.1014 10.1288 13.6477 16.1425 18.0768 19.6568 @@ -286,7 +278,6 @@ const WORD8 gi1_mv_pred_condition[8] = * 50.7252 50.7650 50.8046 50.8440 50.8833 50.9224 50.9613 * 51.0000 */ - const UWORD8 gau1_h264_to_mpeg2_qmap[H264_QP_ELEM] = { 1, 1, 1, 1, 1, 1, 1, 1, diff --git a/encoder/ih264e_globals.h b/encoder/ih264e_globals.h index 4c3de232..5ce1dc88 100644 --- a/encoder/ih264e_globals.h +++ b/encoder/ih264e_globals.h @@ -24,169 +24,36 @@ * ih264e_globals.h * * @brief -* Contains declarations of global variables for H264 encoder +* Contains declarations of global variables used in the encoder * * @author -* Ittiam +* ittiam * * @remarks +* none * ******************************************************************************* */ -#ifndef IH264E_GLOBALS_H_ -#define IH264E_GLOBALS_H_ +#ifndef _IH264E_GLOBALS_H_ +#define _IH264E_GLOBALS_H_ /*****************************************************************************/ -/* Extern global declarations */ +/* Global Declarations */ /*****************************************************************************/ -/** -****************************************************************************** -* @brief Computes the lamda for varying quantizer scales that would be used to -* compute the RD cost while deciding on the MB modes. -* input : qp -* output : lambda -* @remarks lambda = 0.85 * pow(2, (qp - 12)/3), when SSD is used as metric -* for computing distortion (Bit rate estimation for cost function of H.264/ -* AVC by Mohd Golam Sarwer et. al.) If the use of distortion metric is SAD -* rather than SSD in the stage of encoding, consider sqrt(lambda) simply to -* adjust lambda for the lack of squaring operation in the error computation -* (from rate distortion optimization for video compression by sullivan). -****************************************************************************** -*/ extern const UWORD16 gu2_qp_lambda[52]; - -/** -****************************************************************************** -* @brief Computes the lamda for varying quantizer scales that would be used to -* compute the RD cost while deciding on the MB modes. -* input : qp -* output : lambda -* @remarks lambda = pow(2, (qp - 12)/6). When Lagrangian multiplier is disabled -* the same constant is used across mode decision and mv decisions. -****************************************************************************** -*/ extern const UWORD8 gu1_qp0[52]; - -/** -****************************************************************************** -* @brief unsigned exp. goulumb codelengths to assign cost to a coefficient of -* mb types. -* input : Integer -* output : codelength -* @remarks Refer sec. 9-1 in h264 specification -****************************************************************************** -*/ extern const UWORD8 u1_uev_codelength[32]; - -/** -****************************************************************************** -* @brief Look up table to assign cost to a coefficient of a residual block -* basing on its surrounding coefficients -* input : Numbers of T1's -* output : coeff_cost -* @remarks Refer Section 2.3 Elimination of single coefficients in inter -* macroblocks in document JVT-O079 -****************************************************************************** -*/ extern const UWORD8 gu1_coeff_cost[6]; - -/** -****************************************************************************** -* @brief Indices map to raster scan for luma 4x4 block -* input : scan index -* output : scan location -* @remarks The scan order assumes the stride to access the next row is 16 -****************************************************************************** -*/ extern const UWORD8 gu1_luma_scan_order[16]; - -/** -****************************************************************************** -* @brief Indices map to raster scan for chroma AC block -* input : scan index -* output : scan location -* @remarks The scan order assumes the stride to access the next row is 32 -****************************************************************************** -*/ extern const UWORD8 gu1_chroma_scan_order[15]; - -/** -****************************************************************************** -* @brief Indices map to raster scan for luma 4x4 dc block -* input : scan index -* output : scan location -* @remarks The scan order assumes the stride to access the next row is 16 -****************************************************************************** -*/ extern const UWORD8 gu1_luma_scan_order_dc[16]; - -/** -****************************************************************************** -* @brief Indices map to raster scan for chroma 2x2 dc block -* input : scan index -* output : scan location -* @remarks The scan order assumes the stride to access the next row is 16 -****************************************************************************** -*/ extern const UWORD8 gu1_chroma_scan_order_dc[4]; - - -/** -****************************************************************************** -* @brief choice of motion vectors to be used during mv prediction -* input : formatted reference idx comparison metric -* output : mv prediction has to be median or a simple straight forward selec -* tion from neighbors. -* @remarks If only one of the candidate blocks has a reference frame equal to - the current block then use the same block as the final predictor. A simple - look up table to assist this mv prediction condition -****************************************************************************** -*/ extern const WORD8 gi1_mv_pred_condition[8]; - - -/** -****************************************************************************** -* @brief maps the h264 quantizer to the mpeg2 quantizer scale -* input : h264 qp -* output : eqvivalent mpeg 2 qp -* @remarks mpeg2qscale = 2 ^ [((h264qp - 12) / 6) + 1] -****************************************************************************** -*/ extern const UWORD8 gau1_h264_to_mpeg2_qmap[H264_QP_ELEM]; - -/** -****************************************************************************** -* @brief maps the mpeg2 quantizer to the h264 quantizer scale -* input : mpeg2 qp -* output : eqvivalent h264q p -* @remarks MPEG-2 dequantization: (2*QFij + k)*Wij*qscale/32 -* k = 0 (for intra) k = sign(QFij) -* H.264 dequantization: (QFij*R(QP%6,i,j))>>(6 - QP/6) -* -* Excluding the portion of R(QP%6,i,j) that is due to -* the DCT scale factors, the 6 entries after dividing by 64 (2^6) -* correspond to dequant values of -* 2.5, 2.8125, 3.125, 3.5625, 3.9375, 4.4375. -* (a=0.5 b=sqrt(2/5) - refer to JVT-B038.doc) -* -* Assuming that h264Qp=12 corresponds to MPEG2 qscale of 2 -* (the actual mapping seems to be to MPEG2 qscale of 2.5), -* and the fact that the effective h264 quantizer changes by -* a factor of 2 for every 6 steps, the following mapping is -* obtained: -* h264qp = 6*(log2(mpeg2qscale/2)) + 12. -* -* Note that the quant matrix entry assumed for the above -* equality is 16. Hence when the mpeg2 quant matrix entries -* are all 16, this lookup can be used as is (which is the -* default inter quant matrix in mpeg-2). -****************************************************************************** -*/ extern const UWORD8 gau1_mpeg2_to_h264_qmap[MPEG2_QP_ELEM]; -#endif /* IH264E_GLOBALS_H_ */ +#endif /* _IH264E_GLOBALS_H_ */ diff --git a/encoder/ih264e_half_pel.c b/encoder/ih264e_half_pel.c index 4871f401..b19e7659 100644 --- a/encoder/ih264e_half_pel.c +++ b/encoder/ih264e_half_pel.c @@ -34,7 +34,7 @@ * - ih264e_sixtap_filter_2dvh_vert * * @remarks -* None +* none * ******************************************************************************* */ @@ -43,24 +43,24 @@ /* File Includes */ /*****************************************************************************/ -/* System include files */ +/* System Include Files */ #include #include #include -/* User include files */ +/* User Include Files */ #include "ih264_typedefs.h" -#include "ithread.h" -#include "ih264_platform_macros.h" -#include "ih264_defs.h" -#include "ih264e_half_pel.h" + #include "ih264_macros.h" -#include "ih264e_debug.h" -#include "ih264_inter_pred_filters.h" +#include "ih264_defs.h" #include "ih264_mem_fns.h" #include "ih264_padding.h" #include "ih264_intra_pred_filters.h" +#include "ih264_inter_pred_filters.h" #include "ih264_deblk_edge_filters.h" +#include "ih264_platform_macros.h" + +#include "ih264e_half_pel.h" /*****************************************************************************/ @@ -93,7 +93,7 @@ * @returns * * @remarks -* None +* none * ******************************************************************************* */ @@ -172,7 +172,7 @@ void ih264e_sixtapfilter_horz(UWORD8 *pu1_src, * @returns * * @remarks -* None +* none * ******************************************************************************* */ diff --git a/encoder/ih264e_half_pel.h b/encoder/ih264e_half_pel.h index 92bd37f6..5b66ec0a 100644 --- a/encoder/ih264e_half_pel.h +++ b/encoder/ih264e_half_pel.h @@ -19,27 +19,27 @@ */ /** - ******************************************************************************* - * @file - * ih264e_half_pel.h - * - * @brief - * Contains extern declarations of subpel functions used by the encoder - * - * @author - * ittiam - * - * @remarks - * none - * - ******************************************************************************* - */ +******************************************************************************* +* @file +* ih264e_half_pel.h +* +* @brief +* Contains declarations of subpel functions used by the encoder +* +* @author +* ittiam +* +* @remarks +* none +* +******************************************************************************* +*/ -#ifndef IH264E_HALF_PEL_H_ -#define IH264E_HALF_PEL_H_ +#ifndef _IH264E_HALF_PEL_H_ +#define _IH264E_HALF_PEL_H_ /*****************************************************************************/ -/* Global constants */ +/* Constant Macros */ /*****************************************************************************/ /* * Dimensions of subpel plane buffers @@ -48,99 +48,14 @@ #define HP_PL_HT MB_SIZE + 1 /*****************************************************************************/ -/* Extern Function Declarations */ +/* Function Declarations */ /*****************************************************************************/ -/** -******************************************************************************* -* -* @brief -* Interprediction luma filter for horizontal input (Filter run for width = 17 -* and height =16) -* -* @par Description: -* Applies a 6 tap horizontal filter .The output is clipped to 8 bits -* sec 8.4.2.2.1 titled "Luma sample interpolation process" -* -* @param[in] pu1_src -* UWORD8 pointer to the source -* -* @param[out] pu1_dst -* UWORD8 pointer to the destination -* -* @param[in] src_strd -* integer source stride -* -* @param[in] dst_strd -* integer destination stride -* -* @returns -* -* @remarks -* None -* -******************************************************************************* -*/ typedef void ih264e_sixtapfilter_horz_ft(UWORD8 *pu1_src, UWORD8 *pu1_dst, WORD32 src_strd, WORD32 dst_strd); -ih264e_sixtapfilter_horz_ft ih264e_sixtapfilter_horz; - -/* arm assembly */ -ih264e_sixtapfilter_horz_ft ih264e_sixtapfilter_horz_a9q; -ih264e_sixtapfilter_horz_ft ih264e_sixtapfilter_horz_av8; - -/* x86 intrinsics*/ -ih264e_sixtapfilter_horz_ft ih264e_sixtapfilter_horz_ssse3; - -/** -******************************************************************************* -* -* @brief -* This function implements a two stage cascaded six tap filter. It applies -* the six tap filter in the vertical direction on the predictor values, -* followed by applying the same filter in the horizontal direction on the -* output of the first stage. The six tap filtering operation is described in -* sec 8.4.2.2.1 titled "Luma sample interpolation process" (Filter run for -* width = 17 and height = 17) -* -* @par Description: -* The function interpolates the predictors first in the vertical direction and -* then in the horizontal direction to output the (1/2,1/2). The output of the -* first stage of the filter is stored in the buffer pointed to by -* pi16_pred1(only in C) in 16 bit precision. -* -* @param[in] pu1_src -* UWORD8 pointer to the source -* -* @param[out] pu1_dst1 -* UWORD8 pointer to the destination (Horizontal filtered output) -* -* @param[out] pu1_dst2 -* UWORD8 pointer to the destination (output after applying vertical filter to -* the intermediate horizontal output) -* -* @param[in] src_strd -* integer source stride - -* @param[in] dst_strd -* integer destination stride of pu1_dst -* -* @param[in] pi4_pred -* Pointer to 16bit intermediate buffer (used only in c) -* -* @param[in] i4_pred_strd -* integer destination stride of pi16_pred1 -* -* @returns -* -* @remarks -* None -* -******************************************************************************* -*/ typedef void ih264e_sixtap_filter_2dvh_vert_ft(UWORD8 *pu1_src, UWORD8 *pu1_dst1, UWORD8 *pu1_dst2, @@ -149,14 +64,20 @@ typedef void ih264e_sixtap_filter_2dvh_vert_ft(UWORD8 *pu1_src, WORD32 *pi4_pred, WORD32 i4_pred_strd); +/* C Declarations */ +ih264e_sixtapfilter_horz_ft ih264e_sixtapfilter_horz; ih264e_sixtap_filter_2dvh_vert_ft ih264e_sixtap_filter_2dvh_vert; -/* assembly */ +/* A9 Declarations */ +ih264e_sixtapfilter_horz_ft ih264e_sixtapfilter_horz_a9q; ih264e_sixtap_filter_2dvh_vert_ft ih264e_sixtap_filter_2dvh_vert_a9q; +/* AV8 Declarations */ +ih264e_sixtapfilter_horz_ft ih264e_sixtapfilter_horz_av8; ih264e_sixtap_filter_2dvh_vert_ft ih264e_sixtap_filter_2dvh_vert_av8; -/* x86 intrinsics */ +/* SSSE3 Declarations */ +ih264e_sixtapfilter_horz_ft ih264e_sixtapfilter_horz_ssse3; ih264e_sixtap_filter_2dvh_vert_ft ih264e_sixtap_filter_2dvh_vert_ssse3; -#endif /* IH264E_HALF_PEL_H_ */ +#endif /* _IH264E_HALF_PEL_H_ */ diff --git a/encoder/ih264e_intra_modes_eval.c b/encoder/ih264e_intra_modes_eval.c index 6023aea3..a0e447e1 100644 --- a/encoder/ih264e_intra_modes_eval.c +++ b/encoder/ih264e_intra_modes_eval.c @@ -31,19 +31,19 @@ * ittiam * * @par List of Functions: -* - ih264e_derive_neighbor_availability_of_mbs() -* - ih264e_derive_ngbr_avbl_of_mb_partitions() -* - ih264e_evaluate_intra16x16_modes_for_least_cost_rdoptoff() -* - ih264e_evaluate_intra8x8_modes_for_least_cost_rdoptoff() -* - ih264e_evaluate_intra4x4_modes_for_least_cost_rdoptoff() -* - ih264e_evaluate_intra4x4_modes_for_least_cost_rdopton() -* - ih264e_evaluate_chroma_intra8x8_modes_for_least_cost_rdoptoff() -* - ih264e_evaluate_intra16x16_modes() -* - ih264e_evaluate_intra4x4_modes() -* - ih264e_evaluate_intra_chroma_modes() +* - ih264e_derive_neighbor_availability_of_mbs +* - ih264e_derive_ngbr_avbl_of_mb_partitions +* - ih264e_evaluate_intra16x16_modes_for_least_cost_rdoptoff +* - ih264e_evaluate_intra8x8_modes_for_least_cost_rdoptoff +* - ih264e_evaluate_intra4x4_modes_for_least_cost_rdoptoff +* - ih264e_evaluate_intra4x4_modes_for_least_cost_rdopton +* - ih264e_evaluate_chroma_intra8x8_modes_for_least_cost_rdoptoff +* - ih264e_evaluate_intra16x16_modes +* - ih264e_evaluate_intra4x4_modes +* - ih264e_evaluate_intra_chroma_modes * * @remarks -* None +* none * ******************************************************************************* */ @@ -52,43 +52,47 @@ /* File Includes */ /*****************************************************************************/ -/* System include files */ +/* System Include Files */ #include #include #include #include -/* User include files */ +/* User Include Files */ #include "ih264e_config.h" #include "ih264_typedefs.h" -#include "ih264e_defs.h" #include "iv2.h" #include "ive2.h" + #include "ih264_debug.h" -#include "ih264_defs.h" #include "ih264_macros.h" -#include "ih264_intra_pred_filters.h" +#include "ih264_defs.h" +#include "ih264_mem_fns.h" +#include "ih264_padding.h" #include "ih264_structs.h" -#include "ih264_common_tables.h" #include "ih264_trans_quant_itrans_iquant.h" #include "ih264_inter_pred_filters.h" -#include "ih264_mem_fns.h" -#include "ih264_padding.h" +#include "ih264_intra_pred_filters.h" #include "ih264_deblk_edge_filters.h" +#include "ih264_common_tables.h" #include "ih264_cabac_tables.h" -#include "ime_distortion_metrics.h" -#include "ih264e_error.h" -#include "ih264e_bitstream.h" + #include "ime_defs.h" +#include "ime_distortion_metrics.h" #include "ime_structs.h" +#include "ime_platform_macros.h" + #include "irc_cntrl_param.h" #include "irc_frame_info_collector.h" + +#include "ih264e_error.h" +#include "ih264e_defs.h" +#include "ih264e_globals.h" #include "ih264e_rate_control.h" +#include "ih264e_bitstream.h" #include "ih264e_cabac_structs.h" #include "ih264e_structs.h" #include "ih264e_intra_modes_eval.h" -#include "ih264e_globals.h" -#include "ime_platform_macros.h" /*****************************************************************************/ @@ -322,7 +326,6 @@ UWORD8 ih264e_derive_ngbr_avbl_of_mb_partitions(block_neighbors_t *ps_ngbr_avbl, * ****************************************************************************** */ - void ih264e_evaluate_intra16x16_modes_for_least_cost_rdoptoff(process_ctxt_t *ps_proc) { /* Codec Context */ @@ -364,6 +367,7 @@ void ih264e_evaluate_intra16x16_modes_for_least_cost_rdoptoff(process_ctxt_t *ps UWORD8 *pu1_mb_b = pu1_ref_mb - i4_rec_strd; UWORD8 *pu1_mb_d = pu1_mb_b - 1; UWORD8 u1_mb_a, u1_mb_b, u1_mb_d; + /* valid intra modes map */ UWORD32 u4_valid_intra_modes; @@ -570,6 +574,7 @@ void ih264e_evaluate_intra8x8_modes_for_least_cost_rdoptoff(process_ctxt_t *ps_p UWORD8 *pu1_top_mb_intra_modes = ps_proc->pu1_top_mb_intra_modes + (ps_proc->i4_mb_x << 4); mb_info_t *ps_top_mb_syn_ele = ps_proc->ps_top_row_mb_syntax_ele + ps_proc->i4_mb_x; mb_info_t *ps_top_right_mb_syn_ele = ps_proc->ps_top_row_mb_syntax_ele + ps_proc->i4_mb_x; + /* valid intra modes map */ UWORD32 u4_valid_intra_modes; @@ -594,7 +599,7 @@ void ih264e_evaluate_intra8x8_modes_for_least_cost_rdoptoff(process_ctxt_t *ps_p && (u4_constrained_intra_pred ? ps_top_right_mb_syn_ele->u2_is_intra : 1)); - for(b8 = 0; b8 < 4; b8++) + for (b8 = 0; b8 < 4; b8++) { u4_pix_x = (b8 & 0x01) << 3; u4_pix_y = (b8 >> 1) << 3; @@ -835,6 +840,7 @@ void ih264e_evaluate_intra4x4_modes_for_least_cost_rdoptoff(process_ctxt_t *ps_p UWORD32 u4_constrained_intra_pred = ps_proc->ps_codec->s_cfg.u4_constrained_intra_pred; UWORD8 u1_mb_a, u1_mb_b, u1_mb_c, u1_mb_d; + if (ps_proc->ps_ngbr_avbl->u1_mb_c) { ps_top_right_mb_syn_ele = ps_proc->ps_top_row_mb_syntax_ele + ps_proc->i4_mb_x + 1; @@ -1094,7 +1100,7 @@ void ih264e_evaluate_intra4x4_modes_for_least_cost_rdopton(process_ctxt_t *ps_pr UWORD8 *pu1_mb_d; /* number of non zero coeffs*/ - UWORD8 *pu1_nnz = (UWORD8 *)ps_proc->au4_nnz_intra_4x4; + UWORD8 *pu1_nnz = (UWORD8 *)ps_proc->au4_nnz_intra_4x4; /* quantization parameters */ quant_params_t *ps_qp_params = ps_proc->ps_qp_params[0]; @@ -1148,11 +1154,11 @@ void ih264e_evaluate_intra4x4_modes_for_least_cost_rdopton(process_ctxt_t *ps_pr i4_ngbr_avbl = (u1_mb_a) + (u1_mb_d << 1) + (u1_mb_b << 2) + (u1_mb_c << 3); memcpy(ps_proc->au1_ngbr_avbl_4x4_subblks, gau1_ih264_4x4_ngbr_avbl[i4_ngbr_avbl], 16); - for(b8 = 0; b8 < 4; b8++) + for (b8 = 0; b8 < 4; b8++) { u4_blk_x = (b8 & 0x01) << 3; u4_blk_y = (b8 >> 1) << 3; - for(b4 = 0; b4 < 4; b4++, pu1_nnz++, pi2_res_mb += MB_SIZE) + for (b4 = 0; b4 < 4; b4++, pu1_nnz++, pi2_res_mb += MB_SIZE) { u4_pix_x = u4_blk_x + ((b4 & 0x01) << 2); u4_pix_y = u4_blk_y + ((b4 >> 1) << 2); @@ -1377,7 +1383,6 @@ void ih264e_evaluate_intra4x4_modes_for_least_cost_rdopton(process_ctxt_t *ps_pr * ****************************************************************************** */ - void ih264e_evaluate_chroma_intra8x8_modes_for_least_cost_rdoptoff(process_ctxt_t *ps_proc) { /* Codec Context */ @@ -1422,8 +1427,8 @@ void ih264e_evaluate_chroma_intra8x8_modes_for_least_cost_rdoptoff(process_ctxt_ UWORD8 i; UWORD32 u4_constrained_intra_pred = ps_proc->ps_codec->s_cfg.u4_constrained_intra_pred; UWORD8 u1_mb_a, u1_mb_b, u1_mb_d; - /* locating neighbors that are available for prediction */ + /* locating neighbors that are available for prediction */ /* gather prediction pels from the neighbors */ /* left pels */ u1_mb_a = ((ps_proc->ps_ngbr_avbl->u1_mb_a) @@ -2054,7 +2059,6 @@ void ih264e_evaluate_intra_4x4_modes(UWORD8 *pu1_src, pu1_dst += dst_strd; memset(pu1_dst, u4_dcval, 4); } - else if (i4_min_cost == i4_cost[3]) { *u4_intra_mode = DIAG_DL_I4x4; @@ -2080,7 +2084,6 @@ void ih264e_evaluate_intra_4x4_modes(UWORD8 *pu1_src, pu1_dst += dst_strd; memcpy(pu1_dst, (pu1_pred_val - 3), 4); } - else if (i4_min_cost == i4_cost[5]) { *u4_intra_mode = VERT_R_I4x4; diff --git a/encoder/ih264e_intra_modes_eval.h b/encoder/ih264e_intra_modes_eval.h index c8402e5c..f6cad82b 100644 --- a/encoder/ih264e_intra_modes_eval.h +++ b/encoder/ih264e_intra_modes_eval.h @@ -36,293 +36,31 @@ ******************************************************************************* */ -#ifndef IH264E_INTRA_MODES_EVAL_H_ -#define IH264E_INTRA_MODES_EVAL_H_ +#ifndef _IH264E_INTRA_MODES_EVAL_H_ +#define _IH264E_INTRA_MODES_EVAL_H_ /*****************************************************************************/ -/* Extern Function Declarations */ +/* Function Declarations */ /*****************************************************************************/ -/** -****************************************************************************** -* -* @brief -* derivation process for macroblock availability -* -* @par Description -* Calculates the availability of the left, top, topright and topleft macroblocks. -* -* @param[in] ps_proc_ctxt -* pointer to proc context (handle) -* -* @remarks Based on section 6.4.5 in H264 spec -* -* @return none -* -****************************************************************************** -*/ -void ih264e_derive_nghbr_avbl_of_mbs - ( - process_ctxt_t *ps_proc_ctxt - ); +void ih264e_derive_nghbr_avbl_of_mbs(process_ctxt_t *ps_proc_ctxt); -/** -****************************************************************************** -* -* @brief -* derivation process for subblock/partition availability -* -* @par Description -* Calculates the availability of the left, top, topright and topleft subblock -* or partitions. -* -* @param[in] ps_proc_ctxt -* pointer to macroblock context (handle) -* -* @param[in] i1_pel_pos_x -* column position of the pel wrt the current block -* -* @param[in] i1_pel_pos_y -* row position of the pel in wrt current block -* -* @remarks Assumptions: before calling this function it is assumed that -* the neighbor availability of the current macroblock is already derived. -* Based on table 6-3 of H264 specification -* -* @return availability status (yes or no) -* -****************************************************************************** -*/ -UWORD8 ih264e_derive_ngbr_avbl_of_mb_partitions - ( - block_neighbors_t *s_ngbr_avbl, - WORD8 i1_pel_pos_x, - WORD8 i1_pel_pos_y - ); +UWORD8 ih264e_derive_ngbr_avbl_of_mb_partitions(block_neighbors_t *s_ngbr_avbl, + WORD8 i1_pel_pos_x, + WORD8 i1_pel_pos_y); -/** -****************************************************************************** -* -* @brief -* evaluate best intra 16x16 mode (rate distortion opt off) -* -* @par Description -* This function evaluates all the possible intra 16x16 modes and finds the mode -* that best represents the macro-block (least distortion) and occupies fewer -* bits in the bit-stream. -* -* @param[in] ps_proc_ctxt -* pointer to process context (handle) -* -* @remarks -* Ideally the cost of encoding a macroblock is calculated as -* (distortion + lambda*rate). Where distortion is SAD/SATD,... between the -* input block and the reconstructed block and rate is the number of bits taken -* to place the macroblock in the bit-stream. In this routine the rate does not -* exactly point to the total number of bits it takes, rather it points to header -* bits necessary for encoding the macroblock. Assuming the deltaQP, cbp bits -* and residual bits fall in to texture bits the number of bits taken to encoding -* mbtype is considered as rate, we compute cost. Further we will approximate -* the distortion as the deviation b/w input and the predicted block as opposed -* to input and reconstructed block. -* -* NOTE: As per the Document JVT-O079, for intra 16x16 macroblock, -* the SAD and cost are one and the same. -* -* @return none -* -****************************************************************************** -*/ -void ih264e_evaluate_intra16x16_modes_for_least_cost_rdoptoff - ( - process_ctxt_t *ps_proc_ctxt - ); +void ih264e_evaluate_intra16x16_modes_for_least_cost_rdoptoff(process_ctxt_t *ps_proc); -/** -****************************************************************************** -* -* @brief -* evaluate best intra 8x8 mode (rate distortion opt on) -* -* @par Description -* This function evaluates all the possible intra 8x8 modes and finds the mode -* that best represents the macro-block (least distortion) and occupies fewer -* bits in the bit-stream. -* -* @param[in] ps_proc_ctxt -* pointer to proc ctxt -* -* @remarks Ideally the cost of encoding a macroblock is calculated as -* (distortion + lambda*rate). Where distortion is SAD/SATD,... between the -* input block and the reconstructed block and rate is the number of bits taken -* to place the macroblock in the bit-stream. In this routine the rate does not -* exactly point to the total number of bits it takes, rather it points to header -* bits necessary for encoding the macroblock. Assuming the deltaQP, cbp bits -* and residual bits fall in to texture bits the number of bits taken to encoding -* mbtype is considered as rate, we compute cost. Further we will approximate -* the distortion as the deviation b/w input and the predicted block as opposed -* to input and reconstructed block. -* -* NOTE: TODO: This function needs to be tested -* -* @return none -* -****************************************************************************** -*/ -void ih264e_evaluate_intra8x8_modes_for_least_cost_rdoptoff - ( - process_ctxt_t *ps_proc_ctxt - ); +void ih264e_evaluate_intra8x8_modes_for_least_cost_rdoptoff(process_ctxt_t *ps_proc); -/** -****************************************************************************** -* -* @brief -* evaluate best intra 4x4 mode (rate distortion opt on) -* -* @par Description -* This function evaluates all the possible intra 4x4 modes and finds the mode -* that best represents the macro-block (least distortion) and occupies fewer -* bits in the bit-stream. -* -* @param[in] ps_proc_ctxt -* pointer to proc ctxt -* -* @remarks -* Ideally the cost of encoding a macroblock is calculated as -* (distortion + lambda*rate). Where distortion is SAD/SATD,... between the -* input block and the reconstructed block and rate is the number of bits taken -* to place the macroblock in the bit-stream. In this routine the rate does not -* exactly point to the total number of bits it takes, rather it points to header -* bits necessary for encoding the macroblock. Assuming the deltaQP, cbp bits -* and residual bits fall in to texture bits the number of bits taken to encoding -* mbtype is considered as rate, we compute cost. Further we will approximate -* the distortion as the deviation b/w input and the predicted block as opposed -* to input and reconstructed block. -* -* NOTE: As per the Document JVT-O079, for the whole intra 4x4 macroblock, -* 24*lambda is added to the SAD before comparison with the best SAD for -* inter prediction. This is an empirical value to prevent using too many intra -* blocks. -* -* @return none -* -****************************************************************************** -*/ -void ih264e_evaluate_intra4x4_modes_for_least_cost_rdopton - ( - process_ctxt_t *ps_proc_ctxt - ); +void ih264e_evaluate_intra4x4_modes_for_least_cost_rdoptoff(process_ctxt_t *ps_proc); -/** -****************************************************************************** -* -* @brief -* evaluate best intra 4x4 mode (rate distortion opt off) -* -* @par Description -* This function evaluates all the possible intra 4x4 modes and finds the mode -* that best represents the macro-block (least distortion) and occupies fewer -* bits in the bit-stream. -* -* @param[in] ps_proc_ctxt -* pointer to proc ctxt -* -* @remarks -* Ideally the cost of encoding a macroblock is calculated as -* (distortion + lambda*rate). Where distortion is SAD/SATD,... between the -* input block and the reconstructed block and rate is the number of bits taken -* to place the macroblock in the bit-stream. In this routine the rate does not -* exactly point to the total number of bits it takes, rather it points to header -* bits necessary for encoding the macroblock. Assuming the deltaQP, cbp bits -* and residual bits fall in to texture bits the number of bits taken to encoding -* mbtype is considered as rate, we compute cost. Further we will approximate -* the distortion as the deviation b/w input and the predicted block as opposed -* to input and reconstructed block. -* -* NOTE: As per the Document JVT-O079, for the whole intra 4x4 macroblock, -* 24*lambda is added to the SAD before comparison with the best SAD for -* inter prediction. This is an empirical value to prevent using too many intra -* blocks. -* -* @return none -* -****************************************************************************** -*/ -void ih264e_evaluate_intra4x4_modes_for_least_cost_rdoptoff - ( - process_ctxt_t *ps_proc_ctxt - ); +void ih264e_evaluate_intra4x4_modes_for_least_cost_rdopton(process_ctxt_t *ps_proc); -/** -****************************************************************************** -* -* @brief -* evaluate best chroma intra 8x8 mode (rate distortion opt off) -* -* @par Description -* This function evaluates all the possible chroma intra 8x8 modes and finds -* the mode that best represents the macroblock (least distortion) and occupies -* fewer bits in the bitstream. -* -* @param[in] ps_proc_ctxt -* pointer to macroblock context (handle) -* -* @remarks -* For chroma best intra pred mode is calculated based only on SAD -* -* @returns none -* -****************************************************************************** -*/ -void ih264e_evaluate_chroma_intra8x8_modes_for_least_cost_rdoptoff - ( - process_ctxt_t *ps_proc_ctxt - ); +void ih264e_evaluate_chroma_intra8x8_modes_for_least_cost_rdoptoff(process_ctxt_t *ps_proc); +void ih264e_evaluate_intra8x8_modes_for_least_cost_rdoptoff(process_ctxt_t *ps_proc_ctxt); -/** -****************************************************************************** -* -* @brief -* Evaluate best intra 16x16 mode (among VERT, HORZ and DC) and do the -* prediction. -* -* @par Description -* This function evaluates first three 16x16 modes and compute corresponding sad -* and return the buffer predicted with best mode. -* -* @param[in] pu1_src -* UWORD8 pointer to the source -* -* @param[in] pu1_ngbr_pels_i16 -* UWORD8 pointer to neighbouring pels -* -* @param[out] pu1_dst -* UWORD8 pointer to the destination -* -* @param[in] src_strd -* integer source stride -* -* @param[in] dst_strd -* integer destination stride -* -* @param[in] u4_n_avblty -* availability of neighbouring pixels -* -* @param[in] u4_intra_mode -* Pointer to the variable in which best mode is returned -* -* @param[in] pu4_sadmin -* Pointer to the variable in which minimum sad is returned -* -* @param[in] u4_valid_intra_modes -* Says what all modes are valid -* -* @returns none -* -****************************************************************************** -*/ typedef void ih264e_evaluate_intra_modes_ft(UWORD8 *pu1_src, UWORD8 *pu1_ngbr_pels_i16, UWORD8 *pu1_dst, @@ -333,67 +71,6 @@ typedef void ih264e_evaluate_intra_modes_ft(UWORD8 *pu1_src, WORD32 *pu4_sadmin, UWORD32 u4_valid_intra_modes); -ih264e_evaluate_intra_modes_ft ih264e_evaluate_intra16x16_modes; -ih264e_evaluate_intra_modes_ft ih264e_evaluate_intra_chroma_modes; - -/* assembly */ -ih264e_evaluate_intra_modes_ft ih264e_evaluate_intra16x16_modes_a9q; -ih264e_evaluate_intra_modes_ft ih264e_evaluate_intra_chroma_modes_a9q; - -ih264e_evaluate_intra_modes_ft ih264e_evaluate_intra16x16_modes_av8; -ih264e_evaluate_intra_modes_ft ih264e_evaluate_intra_chroma_modes_av8; - -/* x86 intrinsics */ -ih264e_evaluate_intra_modes_ft ih264e_evaluate_intra16x16_modes_ssse3; -ih264e_evaluate_intra_modes_ft ih264e_evaluate_intra_chroma_modes_ssse3; - -/** -****************************************************************************** -* -* @brief -* Evaluate best intra 4x4 mode and perform prediction. -* -* @par Description -* This function evaluates 4x4 modes and compute corresponding sad -* and return the buffer predicted with best mode. -* -* @param[in] pu1_src -* UWORD8 pointer to the source -* -* @param[in] pu1_ngbr_pels -* UWORD8 pointer to neighbouring pels -* -* @param[out] pu1_dst -* UWORD8 pointer to the destination -* -* @param[in] src_strd -* integer source stride -* -* @param[in] dst_strd -* integer destination stride -* -* @param[in] u4_n_avblty -* availability of neighbouring pixels -* -* @param[in] u4_intra_mode -* Pointer to the variable in which best mode is returned -* -* @param[in] pu4_sadmin -* Pointer to the variable in which minimum cost is returned -* -* @param[in] u4_valid_intra_modes -* Says what all modes are valid -* -* @param[in] u4_lambda -* Lamda value for computing cost from SAD -* -* @param[in] u4_predictd_mode -* Predicted mode for cost computation -* -* @returns none -* -****************************************************************************** -*/ typedef void ih264e_evaluate_intra_4x4_modes_ft(UWORD8 *pu1_src, UWORD8 *pu1_ngbr_pels, UWORD8 *pu1_dst, @@ -403,16 +80,27 @@ typedef void ih264e_evaluate_intra_4x4_modes_ft(UWORD8 *pu1_src, UWORD32 *u4_intra_mode, WORD32 *pu4_sadmin, UWORD32 u4_valid_intra_modes, - UWORD32 u4_lambda, + UWORD32 u4_lambda, UWORD32 u4_predictd_mode); +/* C Declarations */ +ih264e_evaluate_intra_modes_ft ih264e_evaluate_intra16x16_modes; +ih264e_evaluate_intra_modes_ft ih264e_evaluate_intra_chroma_modes; ih264e_evaluate_intra_4x4_modes_ft ih264e_evaluate_intra_4x4_modes; -/* x86 intrinsics */ -ih264e_evaluate_intra_4x4_modes_ft ih264e_evaluate_intra_4x4_modes_ssse3; - -/* assembly */ +/* A9 Declarations */ +ih264e_evaluate_intra_modes_ft ih264e_evaluate_intra16x16_modes_a9q; +ih264e_evaluate_intra_modes_ft ih264e_evaluate_intra_chroma_modes_a9q; ih264e_evaluate_intra_4x4_modes_ft ih264e_evaluate_intra_4x4_modes_a9q; + +/* AV8 Declarations */ +ih264e_evaluate_intra_modes_ft ih264e_evaluate_intra16x16_modes_av8; +ih264e_evaluate_intra_modes_ft ih264e_evaluate_intra_chroma_modes_av8; ih264e_evaluate_intra_4x4_modes_ft ih264e_evaluate_intra_4x4_modes_av8; -#endif /* IH264E_INTRA_MODES_EVAL_H_ */ +/* SSSE3 Declarations */ +ih264e_evaluate_intra_modes_ft ih264e_evaluate_intra16x16_modes_ssse3; +ih264e_evaluate_intra_modes_ft ih264e_evaluate_intra_chroma_modes_ssse3; +ih264e_evaluate_intra_4x4_modes_ft ih264e_evaluate_intra_4x4_modes_ssse3; + +#endif /* _IH264E_INTRA_MODES_EVAL_H_ */ diff --git a/encoder/ih264e_master.h b/encoder/ih264e_master.h index 67354fdc..94fb9b06 100644 --- a/encoder/ih264e_master.h +++ b/encoder/ih264e_master.h @@ -30,120 +30,26 @@ * ittiam * * @remarks -* None +* none * ******************************************************************************* */ -#ifndef IH264E_MASTER_H_ -#define IH264E_MASTER_H_ +#ifndef _IH264E_MASTER_H_ +#define _IH264E_MASTER_H_ /*****************************************************************************/ -/* Extern Function Declarations */ +/* Function Declarations */ /*****************************************************************************/ -/** -****************************************************************************** -* -* @brief -* This function joins all the spawned threads after successful completion of -* their tasks -* -* @par Description -* -* @param[in] ps_codec -* pointer to codec context -* -* @returns none -* -****************************************************************************** -*/ void ih264e_join_threads(codec_t *ps_codec); -/** -****************************************************************************** -* -* @brief -* This function calculates various quality metrics; the initial one is PSNR. -* -* @par Description -* -* @param[in] ps_codec -* pointer to process context -* -* @returns none -* -****************************************************************************** -*/ void ih264e_compute_quality_stats(process_ctxt_t *ps_proc); -/** -****************************************************************************** -* -* @brief This function puts the current thread to sleep for a duration -* of sleep_us -* -* @par Description -* ithread_yield() method causes the calling thread to yield execution to another -* thread that is ready to run on the current processor. The operating system -* selects the thread to yield to. ithread_usleep blocks the current thread for -* the specified number of milliseconds. In other words, yield just says, -* end my timeslice prematurely, look around for other threads to run. If there -* is nothing better than me, continue. Sleep says I don't want to run for x -* milliseconds. Even if no other thread wants to run, don't make me run. -* -* @param[in] sleep_us -* thread sleep duration -* -* @returns error_status -* -****************************************************************************** -*/ IH264E_ERROR_T ih264e_wait_for_thread(UWORD32 sleep_us); -/** -****************************************************************************** -* -* @brief -* Encodes in synchronous api mode -* -* @par Description -* This routine processes input yuv, encodes it and outputs bitstream and recon -* -* @param[in] ps_codec_obj -* Pointer to codec object at API level -* -* @param[in] pv_api_ip -* Pointer to input argument structure -* -* @param[out] pv_api_op -* Pointer to output argument structure -* -* @returns Status -* -****************************************************************************** -*/ WORD32 ih264e_encode(iv_obj_t *ps_codec_obj, void *pv_api_ip, void *pv_api_op); -/** -******************************************************************************* -* -* @brief update encoder configuration parameters -* -* @par Description: -* updates encoder configuration parameters from the given config set. -* Initialize/reinitialize codec parameters according to new configurations. -* -* @param[in] ps_codec -* Pointer to codec context -* -* @param[in] ps_cfg -* Pointer to config param set -* -* @remarks none -* -******************************************************************************* -*/ IH264E_ERROR_T ih264e_codec_update_config(codec_t *ps_codec, cfg_params_t *ps_cfg); -#endif /* IH264E_MASTER_H_ */ +#endif /* _IH264E_MASTER_H_ */ diff --git a/encoder/ih264e_mc.c b/encoder/ih264e_mc.c index 2b19dd19..6d4a1df4 100644 --- a/encoder/ih264e_mc.c +++ b/encoder/ih264e_mc.c @@ -19,93 +19,98 @@ */ /** - ******************************************************************************* - * @file - * ih264e_mc.c - * - * @brief - * Contains definition of functions for motion compensation - * - * @author - * ittiam - * - * @par List of Functions: - * - ih264e_motion_comp_luma() - * - ih264e_motion_comp_chroma() - * - * @remarks - * None - * - ******************************************************************************* - */ +******************************************************************************* +* @file +* ih264e_mc.c +* +* @brief +* Contains definition of functions for motion compensation +* +* @author +* ittiam +* +* @par List of Functions: +* - ih264e_motion_comp_luma +* - ih264e_motion_comp_chroma +* +* @remarks +* none +* +******************************************************************************* +*/ /*****************************************************************************/ /* File Includes */ /*****************************************************************************/ -/* System include files */ +/* System Include Files */ #include -/* User include files */ +/* User Include Files */ #include "ih264_typedefs.h" -#include "ih264_defs.h" #include "iv2.h" #include "ive2.h" -#include "ime_distortion_metrics.h" -#include "ime_defs.h" -#include "ime_structs.h" -#include "ih264_structs.h" -#include "ih264_inter_pred_filters.h" + +#include "ih264_defs.h" #include "ih264_mem_fns.h" #include "ih264_padding.h" +#include "ih264_structs.h" +#include "ih264_trans_quant_itrans_iquant.h" +#include "ih264_inter_pred_filters.h" #include "ih264_intra_pred_filters.h" #include "ih264_deblk_edge_filters.h" -#include "ih264_trans_quant_itrans_iquant.h" #include "ih264_cabac_tables.h" -#include "ih264e_defs.h" -#include "ih264e_error.h" -#include "ih264e_bitstream.h" + +#include "ime_defs.h" +#include "ime_distortion_metrics.h" +#include "ime_structs.h" + #include "irc_cntrl_param.h" #include "irc_frame_info_collector.h" + +#include "ih264e_error.h" +#include "ih264e_defs.h" #include "ih264e_rate_control.h" +#include "ih264e_bitstream.h" #include "ih264e_cabac_structs.h" #include "ih264e_structs.h" #include "ih264e_mc.h" #include "ih264e_half_pel.h" + /*****************************************************************************/ /* Function Definitions */ /*****************************************************************************/ /** - ****************************************************************************** - * - * @brief - * performs motion compensation for a luma mb for the given mv. - * - * @par Description - * This routine performs motion compensation of an inter mb. When the inter - * mb mode is P16x16, there is no need to copy 16x16 unit from reference buffer - * to pred buffer. In this case the function returns pointer and stride of the - * ref. buffer and this info is used in place of pred buffer else where. - * In other cases, the pred buffer is populated via copy / filtering + copy - * (q pel cases) and returned. - * - * @param[in] ps_proc - * pointer to current proc ctxt - * - * @param[out] pu1_pseudo_pred - * pseudo prediction buffer - * - * @param[out] u4_pseudo_pred_strd - * pseudo pred buffer stride - * - * @return none - * - * @remarks Assumes half pel buffers for the entire frame are populated. - * - ****************************************************************************** - */ +****************************************************************************** +* +* @brief +* performs motion compensation for a luma mb for the given mv. +* +* @par Description +* This routine performs motion compensation of an inter mb. When the inter +* mb mode is P16x16, there is no need to copy 16x16 unit from reference buffer +* to pred buffer. In this case the function returns pointer and stride of the +* ref. buffer and this info is used in place of pred buffer else where. +* In other cases, the pred buffer is populated via copy / filtering + copy +* (q pel cases) and returned. +* +* @param[in] ps_proc +* pointer to current proc ctxt +* +* @param[out] pu1_pseudo_pred +* pseudo prediction buffer +* +* @param[out] u4_pseudo_pred_strd +* pseudo pred buffer stride +* +* @return none +* +* @remarks Assumes half pel buffers for the entire frame are populated. +* +****************************************************************************** +*/ void ih264e_motion_comp_luma(process_ctxt_t *ps_proc, UWORD8 **pu1_pseudo_pred, WORD32 *pi4_pseudo_pred_strd) { @@ -161,7 +166,7 @@ void ih264e_motion_comp_luma(process_ctxt_t *ps_proc, UWORD8 **pu1_pseudo_pred, ps_me_ctxt->u4_subpel_buf_strd; for (u4_num_prtn = 0; u4_num_prtn < ps_proc->u4_num_sub_partitions; - u4_num_prtn++) + u4_num_prtn++) { mv_t *ps_curr_mv; @@ -255,7 +260,8 @@ void ih264e_motion_comp_luma(process_ctxt_t *ps_proc, UWORD8 **pu1_pseudo_pred, } /* * Copying half pel or full pel to prediction buffer - * Currently ps_proc->u4_num_sub_partitions will always be 1 as we only support 16x16 in P mbs + * Currently ps_proc->u4_num_sub_partitions will always be 1 as we + * only support 16x16 in P mbs */ else { @@ -265,30 +271,29 @@ void ih264e_motion_comp_luma(process_ctxt_t *ps_proc, UWORD8 **pu1_pseudo_pred, i4_pred_strd, ht, wd, NULL, 0); } - } } } /** - ****************************************************************************** - * - * @brief - * performs motion compensation for chroma mb - * - * @par Description - * Copies a MB of data from the reference buffer (Full pel, half pel or q pel) - * according to the motion vectors given - * - * @param[in] ps_proc - * pointer to current proc ctxt - * - * @return none - * - * @remarks Assumes half pel and quarter pel buffers for the entire frame are - * populated. - ****************************************************************************** - */ +****************************************************************************** +* +* @brief +* performs motion compensation for chroma mb +* +* @par Description +* Copies a MB of data from the reference buffer (Full pel, half pel or q pel) +* according to the motion vectors given +* +* @param[in] ps_proc +* pointer to current proc ctxt +* +* @return none +* +* @remarks Assumes half pel and quarter pel buffers for the entire frame are +* populated. +****************************************************************************** +*/ void ih264e_motion_comp_chroma(process_ctxt_t *ps_proc) { /* codec context */ @@ -329,7 +334,7 @@ void ih264e_motion_comp_chroma(process_ctxt_t *ps_proc) UWORD8 u1_dx, u1_dy; for (u4_num_prtn = 0; u4_num_prtn < ps_proc->u4_num_sub_partitions; - u4_num_prtn++) + u4_num_prtn++) { mv_t *ps_curr_mv; diff --git a/encoder/ih264e_mc.h b/encoder/ih264e_mc.h index 965e1d12..fb80272b 100644 --- a/encoder/ih264e_mc.h +++ b/encoder/ih264e_mc.h @@ -36,69 +36,16 @@ ******************************************************************************* */ -#ifndef IH264E_MC_H_ -#define IH264E_MC_H_ +#ifndef _IH264E_MC_H_ +#define _IH264E_MC_H_ /*****************************************************************************/ -/* Extern Function Declarations */ +/* Function Declarations */ /*****************************************************************************/ -/** -****************************************************************************** -* -* @brief -* performs motion compensation for a luma mb for the given mv. -* -* @par Description -* This routine performs motion compensation of an inter mb. When the inter -* mb mode is P16x16, there is no need to copy 16x16 unit from reference buffer -* to pred buffer. In this case the function returns pointer and stride of the -* ref. buffer and this info is used in place of pred buffer else where. -* In other cases, the pred buffer is populated via copy / filtering + copy -* (q pel cases) and returned. -* -* @param[in] ps_proc -* pointer to current proc ctxt -* -* @param[out] pu1_pseudo_pred -* pseudo prediction buffer -* -* @param[out] u4_pseudo_pred_strd -* pseudo pred buffer stride -* -* @return none -* -* @remarks Assumes half pel buffers for the entire frame are populated. -* -****************************************************************************** -*/ -void ih264e_motion_comp_luma(process_ctxt_t *ps_proc, - UWORD8 **pu1_pseudo_pred, +void ih264e_motion_comp_luma(process_ctxt_t *ps_proc, UWORD8 **pu1_pseudo_pred, WORD32 *pi4_pseudo_pred_strd); -/** -****************************************************************************** -* -* @brief -* performs motion compensation for chroma mb -* -* @par Description -* Copies a MB of data from the reference buffer (Full pel, half pel or q pel) -* according to the motion vectors given -* -* @param[in] ps_proc -* pointer to current proc ctxt -* -* @return none -* -* @remarks Assumes half pel and quarter pel buffers for the entire frame are -* populated. -****************************************************************************** -*/ -void ih264e_motion_comp_chroma - ( - process_ctxt_t *ps_proc - ); - +void ih264e_motion_comp_chroma(process_ctxt_t *ps_proc); -#endif // IH264E_MC_H_ +#endif /* _IH264E_MC_H_ */ diff --git a/encoder/ih264e_me.c b/encoder/ih264e_me.c index 36182e41..f4822191 100644 --- a/encoder/ih264e_me.c +++ b/encoder/ih264e_me.c @@ -19,82 +19,86 @@ */ /** - ******************************************************************************* - * @file - * ih264e_me.c - * - * @brief - * Contains definition of functions for motion estimation - * - * @author - * ittiam - * - * @par List of Functions: - * - ih264e_init_mv_bits() - * - ih264e_skip_analysis_chroma() - * - ih264e_skip_analysis_luma() - * - ih264e_analyse_skip() - * - ih264e_get_search_candidates() - * - ih264e_find_skip_motion_vector() - * - ih264e_get_mv_predictor() - * - ih264e_mv_pred() - * - ih264e_mv_pred_me() - * - ih264e_init_me() - * - ih264e_compute_me() - * - ih264e_compute_me_nmb() - * - * @remarks - * None - * - ******************************************************************************* - */ +******************************************************************************* +* @file +* ih264e_me.c +* +* @brief +* Contains definition of functions for motion estimation +* +* @author +* ittiam +* +* @par List of Functions: +* - ih264e_init_mv_bits +* - ih264e_get_search_candidates +* - ih264e_find_pskip_params +* - ih264e_find_pskip_params_me +* - ih264e_get_mv_predictor +* - ih264e_mv_pred +* - ih264e_mv_pred_me +* - ih264e_compute_me_single_reflist +* - ih264e_compute_me_nmb +* - ih264e_find_bskip_params_me +* - ih264e_find_bskip_params +* - ih264e_evaluate_bipred +* - ih264e_compute_me_multi_reflist +* +* @remarks +* none +* +******************************************************************************* +*/ /*****************************************************************************/ /* File Includes */ /*****************************************************************************/ -/* System include files */ +/* System Include Files */ #include #include #include -/* User include files */ +/* User Include Files */ #include "ih264_typedefs.h" #include "iv2.h" #include "ive2.h" #include "ithread.h" -#include "ih264_platform_macros.h" + +#include "ih264_debug.h" +#include "ih264_macros.h" #include "ih264_defs.h" -#include "ime_defs.h" -#include "ime_distortion_metrics.h" -#include "ime_structs.h" +#include "ih264_mem_fns.h" +#include "ih264_padding.h" #include "ih264_structs.h" #include "ih264_trans_quant_itrans_iquant.h" #include "ih264_inter_pred_filters.h" -#include "ih264_mem_fns.h" -#include "ih264_padding.h" #include "ih264_intra_pred_filters.h" #include "ih264_deblk_edge_filters.h" #include "ih264_cabac_tables.h" -#include "ih264e_defs.h" -#include "ih264e_error.h" -#include "ih264e_bitstream.h" +#include "ih264_platform_macros.h" + +#include "ime_defs.h" +#include "ime_distortion_metrics.h" +#include "ime_structs.h" +#include "ime.h" +#include "ime_statistics.h" + #include "irc_cntrl_param.h" #include "irc_frame_info_collector.h" + +#include "ih264e_error.h" +#include "ih264e_defs.h" +#include "ih264e_globals.h" #include "ih264e_rate_control.h" +#include "ih264e_bitstream.h" #include "ih264e_cabac_structs.h" #include "ih264e_structs.h" -#include "ih264e_globals.h" -#include "ih264_macros.h" +#include "ih264e_mc.h" #include "ih264e_me.h" -#include "ime.h" -#include "ih264_debug.h" +#include "ih264e_half_pel.h" #include "ih264e_intra_modes_eval.h" #include "ih264e_core_coding.h" -#include "ih264e_mc.h" -#include "ih264e_debug.h" -#include "ih264e_half_pel.h" -#include "ime_statistics.h" #include "ih264e_platform_macros.h" @@ -116,7 +120,7 @@ * length of the codeword for all mv's * * @remarks The length of the code words are derived from signed exponential -* goloumb codes. +* goloumb codes. * ******************************************************************************* */ @@ -164,44 +168,27 @@ void ih264e_init_mv_bits(me_ctxt_t *ps_me_ctxt) } } - - /** ******************************************************************************* * * @brief Determines the valid candidates for which the initial search shall happen. * The best of these candidates is used to center the diamond pixel search. * -* @par Description: The function sends the skip, (0,0), left, top and top-right +* @par Description The function sends the skip, (0,0), left, top and top-right * neighbouring MBs MVs. The left, top and top-right MBs MVs are used because * these are the same MVs that are used to form the MV predictor. This initial MV * search candidates need not take care of slice boundaries and hence neighbor * availability checks are not made here. * -* @param[in] ps_left_mb_pu -* pointer to left mb motion vector info -* -* @param[in] ps_top_mb_pu -* pointer to top & top right mb motion vector info -* -* @param[in] ps_top_left_mb_pu -* pointer to top left mb motion vector info -* -* @param[out] ps_skip_mv -* pointer to skip motion vectors for the curr mb -* -* @param[in] i4_mb_x -* mb index x -* -* @param[in] i4_mb_y -* mb index y -* -* @param[in] i4_wd_mbs -* pic width in mbs +* @param[in] ps_proc +* Pointer to process context * -* @param[in] ps_motionEst +* @param[in] ps_me_ctxt * pointer to me context * +* @param[in] i4_ref_list +* Current active reference list +* * @returns The list of MVs to be used of priming the full pel search and the * number of such MVs * @@ -319,7 +306,6 @@ static void ih264e_get_search_candidates(process_ctxt_t *ps_proc, } } - /********************************************************************/ /* MV Prediction */ /********************************************************************/ @@ -371,22 +357,16 @@ static void ih264e_get_search_candidates(process_ctxt_t *ps_proc, * * @par Description: * The function updates the skip motion vector and checks if the current -* MB can be a skip PSKIP mB or not +* MB can be a PSKIP MB or not * * @param[in] ps_proc * Pointer to process context * -* @param[in] u4_for_me -* Flag to indicate function is called for ME or not -* -* @param[out] i4_ref_list -* Current active refernce list +* @param[in] i4_ref_list +* Current active reference list * * @returns Flag indicating if the current MB can be marked as skip * -* @remarks The code implements the logic as described in sec 8.4.1.2.2 in H264 -* specification. -* ******************************************************************************* */ WORD32 ih264e_find_pskip_params(process_ctxt_t *ps_proc, WORD32 i4_reflist) @@ -402,7 +382,7 @@ WORD32 ih264e_find_pskip_params(process_ctxt_t *ps_proc, WORD32 i4_reflist) UNUSED(i4_reflist); - ps_left_mb_pu = &ps_proc->s_left_mb_pu ; + ps_left_mb_pu = &ps_proc->s_left_mb_pu; ps_top_mb_pu = ps_proc->ps_top_row_pu + ps_proc->i4_mb_x; if ((!ps_proc->ps_ngbr_avbl->u1_mb_a) || @@ -418,7 +398,6 @@ WORD32 ih264e_find_pskip_params(process_ctxt_t *ps_proc, WORD32 i4_reflist) (ps_top_mb_pu->s_me_info[PRED_L0].s_mv.i2_mvy == 0) ) ) - { ps_skip_mv->i2_mvx = 0; ps_skip_mv->i2_mvy = 0; @@ -429,7 +408,7 @@ WORD32 ih264e_find_pskip_params(process_ctxt_t *ps_proc, WORD32 i4_reflist) ps_skip_mv->i2_mvy = ps_proc->ps_pred_mv[PRED_L0].s_mv.i2_mvy; } - if ( (ps_proc->ps_pu->s_me_info[PRED_L0].s_mv.i2_mvx == ps_skip_mv->i2_mvx) + if ((ps_proc->ps_pu->s_me_info[PRED_L0].s_mv.i2_mvx == ps_skip_mv->i2_mvx) && (ps_proc->ps_pu->s_me_info[PRED_L0].s_mv.i2_mvy == ps_skip_mv->i2_mvy)) { return 1; @@ -445,22 +424,16 @@ WORD32 ih264e_find_pskip_params(process_ctxt_t *ps_proc, WORD32 i4_reflist) * * @par Description: * The function updates the skip motion vector and checks if the current -* MB can be a skip PSKIP mB or not +* MB can be a PSKIP MB or not * * @param[in] ps_proc * Pointer to process context * -* @param[in] u4_for_me -* Flag to dincate fucntion is called for ME or not -* -* @param[out] i4_ref_list -* Current active refernce list +* @param[in] i4_ref_list +* Current active reference list * * @returns Flag indicating if the current MB can be marked as skip * -* @remarks The code implements the logic as described in sec 8.4.1.2.2 in H264 -* specification. -* ******************************************************************************* */ WORD32 ih264e_find_pskip_params_me(process_ctxt_t *ps_proc, WORD32 i4_reflist) @@ -492,7 +465,6 @@ WORD32 ih264e_find_pskip_params_me(process_ctxt_t *ps_proc, WORD32 i4_reflist) (ps_top_mb_pu->s_me_info[PRED_L0].s_mv.i2_mvy == 0) ) ) - { ps_skip_mv->i2_mvx = 0; ps_skip_mv->i2_mvy = 0; @@ -506,7 +478,6 @@ WORD32 ih264e_find_pskip_params_me(process_ctxt_t *ps_proc, WORD32 i4_reflist) return PRED_L0; } - /** ******************************************************************************* * @@ -525,6 +496,9 @@ WORD32 ih264e_find_pskip_params_me(process_ctxt_t *ps_proc, WORD32 i4_reflist) * @param[out] ps_pred_mv * pointer to candidate predictors for the current block * +* @param[in] i4_ref_list +* Current active reference list +* * @returns The x & y components of the MV predictor. * * @remarks The code implements the logic as described in sec 8.4.1.3 in H264 @@ -539,7 +513,6 @@ void ih264e_get_mv_predictor(enc_pu_t *ps_left_mb_pu, enc_pu_mv_t *ps_pred_mv, WORD32 i4_ref_list) { - /* Indicated the current ref */ WORD8 i1_ref_idx; @@ -607,6 +580,9 @@ void ih264e_get_mv_predictor(enc_pu_t *ps_left_mb_pu, * @param[in] ps_proc * Process context corresponding to the job * +* @param[in] i4_slice_type +* slice type +* * @returns none * * @remarks none @@ -617,7 +593,6 @@ void ih264e_get_mv_predictor(enc_pu_t *ps_left_mb_pu, */ void ih264e_mv_pred(process_ctxt_t *ps_proc, WORD32 i4_slice_type) { - /* left mb motion vector */ enc_pu_t *ps_left_mb_pu; @@ -701,7 +676,6 @@ void ih264e_mv_pred(process_ctxt_t *ps_proc, WORD32 i4_slice_type) ih264e_get_mv_predictor(ps_left_mb_pu, ps_top_row_pu, &ps_pred_mv[i4_reflist], i4_reflist); } - } /** @@ -714,6 +688,9 @@ void ih264e_mv_pred(process_ctxt_t *ps_proc, WORD32 i4_slice_type) * @param[in] ps_proc * Process context corresponding to the job * +* @param[in] i4_ref_list +* Current active reference list +* * @returns none * * @remarks none @@ -758,7 +735,6 @@ void ih264e_mv_pred_me(process_ctxt_t *ps_proc, WORD32 i4_ref_list) * Before performing mv prediction prepare the ngbr information and * reset motion vectors basing on their availability */ - if (!ps_ngbr_avbl->u1_mb_a || (ps_left_mb_pu->b2_pred_mode == i4_cmpl_predmode)) { /* left mv */ @@ -841,6 +817,7 @@ void ih264e_init_me(process_ctxt_t *ps_proc) /* src ptr */ ps_me_ctxt->pu1_src_buf_luma = ps_proc->pu1_src_buf_luma; + /* src stride */ ps_me_ctxt->i4_src_strd = ps_proc->i4_src_strd; @@ -938,9 +915,9 @@ void ih264e_compute_me_single_reflist(process_ctxt_t *ps_proc) /* Get the seed motion vector candidates */ ih264e_get_search_candidates(ps_proc, ps_me_ctxt, PRED_L0); - /* **************************************************************** - *Evaluate the SKIP for current list - * ****************************************************************/ + /***************************************************************** + * Evaluate the SKIP for current list + *****************************************************************/ s_skip_mbpart.s_mv_curr.i2_mvx = 0; s_skip_mbpart.s_mv_curr.i2_mvy = 0; s_skip_mbpart.i4_mb_cost = INT_MAX; @@ -985,9 +962,9 @@ void ih264e_compute_me_single_reflist(process_ctxt_t *ps_proc) if (ps_me_ctxt->u4_enable_hpel) { /* moving src pointer to the converged motion vector location*/ - pu1_hpel_src = ps_me_ctxt->apu1_ref_buf_luma[PRED_L0] - + (ps_me_ctxt->as_mb_part[PRED_L0].s_mv_curr.i2_mvx >> 2) - + (ps_me_ctxt->as_mb_part[PRED_L0].s_mv_curr.i2_mvy >> 2)* i4_rec_strd; + pu1_hpel_src = ps_me_ctxt->apu1_ref_buf_luma[PRED_L0] + + (ps_me_ctxt->as_mb_part[PRED_L0].s_mv_curr.i2_mvx >> 2) + + (ps_me_ctxt->as_mb_part[PRED_L0].s_mv_curr.i2_mvy >> 2) * i4_rec_strd; ps_me_ctxt->apu1_subpel_buffs[0] = ps_proc->apu1_subpel_buffs[0]; ps_me_ctxt->apu1_subpel_buffs[1] = ps_proc->apu1_subpel_buffs[1]; @@ -1083,7 +1060,6 @@ void ih264e_compute_me_single_reflist(process_ctxt_t *ps_proc) ps_proc->ps_cur_mb->u4_min_sad_reached = 1; ps_proc->ps_cur_mb->u4_min_sad = ps_me_ctxt->i4_min_sad; } - } /** @@ -1092,12 +1068,15 @@ void ih264e_compute_me_single_reflist(process_ctxt_t *ps_proc) * @brief This function performs motion estimation for the current NMB * * @par Description: -* Intializes input and output pointers required by the function ih264e_compute_me -* and calls the function ih264e_compute_me in a loop to process NMBs. +* Intializes input and output pointers required by the function ih264e_compute_me +* and calls the function ih264e_compute_me in a loop to process NMBs. * * @param[in] ps_proc * Process context corresponding to the job * +* @param[in] u4_nmb_count +* Number of mb's to process +* * @returns * * @remarks none @@ -1221,7 +1200,6 @@ void ih264e_compute_me_nmb(process_ctxt_t *ps_proc, UWORD32 u4_nmb_count) ps_proc->pu4_mb_pu_cnt += 1; } - ps_proc->ps_pu = ps_pu_begin; ps_proc->i4_mb_x = ps_proc->i4_mb_x - u4_nmb_count; @@ -1240,7 +1218,6 @@ void ih264e_compute_me_nmb(process_ctxt_t *ps_proc, UWORD32 u4_nmb_count) ps_proc->apu1_ref_buf_chroma[0] -= MB_SIZE * u4_nmb_count; ps_proc->apu1_ref_buf_chroma[1] -= MB_SIZE * u4_nmb_count; - ps_proc->pu4_mb_pu_cnt -= u4_nmb_count; } @@ -1257,11 +1234,8 @@ void ih264e_compute_me_nmb(process_ctxt_t *ps_proc, UWORD32 u4_nmb_count) * @param[in] ps_proc * Pointer to process context * -* @param[in] u4_for_me -* Dummy -* * @param[in] i4_reflist -* Dummy +* Current active reference list * * @returns Flag indicating if the current Mb can be skip or not * @@ -1271,7 +1245,8 @@ void ih264e_compute_me_nmb(process_ctxt_t *ps_proc, UWORD32 u4_nmb_count) * * Need to add condition for this fucntion to be used in ME * -*******************************************************************************/ +******************************************************************************* +*/ WORD32 ih264e_find_bskip_params_me(process_ctxt_t *ps_proc, WORD32 i4_reflist) { /* Colzero for co-located MB */ @@ -1459,10 +1434,7 @@ WORD32 ih264e_find_bskip_params_me(process_ctxt_t *ps_proc, WORD32 i4_reflist) * @param[in] ps_proc * Pointer to process context * -* @param[in] u4_for_me -* Dummy -* -* @param[in] u4_for_me +* @param[in] i4_reflist * Dummy * * @returns Flag indicating if the current Mb can be skip or not @@ -1473,6 +1445,7 @@ WORD32 ih264e_find_bskip_params_me(process_ctxt_t *ps_proc, WORD32 i4_reflist) *******************************************************************************/ WORD32 ih264e_find_bskip_params(process_ctxt_t *ps_proc, WORD32 i4_reflist) { + /* Colzero for co-located MB */ WORD32 i4_colzeroflag; /* motion vectors */ @@ -1496,7 +1469,7 @@ WORD32 ih264e_find_bskip_params(process_ctxt_t *ps_proc, WORD32 i4_reflist) UNUSED(i4_reflist); /************************************************************************** - *Find co-locates parameters + * Find co-locates parameters * See sec 8.4.1.2.1 for reference **************************************************************************/ { @@ -1651,18 +1624,18 @@ WORD32 ih264e_find_bskip_params(process_ctxt_t *ps_proc, WORD32 i4_reflist) * This function determines the position in the search window at which the motion * estimation should begin in order to minimise the number of search iterations. * -* @param[in] ps_mb_part -* pointer to current mb partition ctxt with respect to ME +* @param[in] ps_me_ctxt +* pointer to me context * -* @param[in] u4_lambda_motion -* lambda motion +* @param[in] ps_proc +* process context * -* @param[in] u4_fast_flag -* enable/disable fast sad computation +* @param[in] ps_mb_ctxt_bi +* pointer to current mb partition ctxt with respect to ME * * @returns mv pair & corresponding distortion and cost * -* @remarks Currently onyl 4 search candiates are supported +* @remarks Currently only 4 search candiates are supported * ******************************************************************************* */ @@ -1688,6 +1661,7 @@ void ih264e_evaluate_bipred(me_ctxt_t *ps_me_ctxt, u4_fast_sad = ps_me_ctxt->u4_enable_fast_sad; i4_dest_buff = 0; + for (i = 0; i < ps_me_ctxt->u4_num_candidates[PRED_BI]; i += 2) { pu1_dst_buf = ps_me_ctxt->apu1_subpel_buffs[i4_dest_buff]; @@ -1902,10 +1876,10 @@ void ih264e_compute_me_multi_reflist(process_ctxt_t *ps_proc) /********************************************************************/ ime_full_pel_motion_estimation_16x16(ps_me_ctxt, i4_reflist); - DEBUG_MV_HISTOGRAM_ADD((ps_me_ctxt->s_mb_part.s_mv_curr.i2_mvx >> 2), - (ps_me_ctxt->s_mb_part.s_mv_curr.i2_mvy >> 2)); + DEBUG_MV_HISTOGRAM_ADD((ps_me_ctxt->as_mb_part[i4_reflist].s_mv_curr.i2_mvx >> 2), + (ps_me_ctxt->as_mb_part[i4_reflist].s_mv_curr.i2_mvy >> 2)); - DEBUG_SAD_HISTOGRAM_ADD(ps_me_ctxt->s_mb_part.i4_mb_distortion, 1); + DEBUG_SAD_HISTOGRAM_ADD(ps_me_ctxt->as_mb_part[i4_reflist].i4_mb_distortion, 1); /* Scale the MV to qpel resolution */ ps_me_ctxt->as_mb_part[i4_reflist].s_mv_curr.i2_mvx <<= 2; diff --git a/encoder/ih264e_me.h b/encoder/ih264e_me.h index 2266e5a1..8af8c8a2 100644 --- a/encoder/ih264e_me.h +++ b/encoder/ih264e_me.h @@ -24,7 +24,7 @@ * ih264e_me.h * * @brief - * Contains declarations of global variables for H264 encoder + * Contains declarations of h264 me * * @author * ittiam @@ -34,8 +34,9 @@ ******************************************************************************* */ -#ifndef IH264E_ME_H_ -#define IH264E_ME_H_ +#ifndef _IH264E_ME_H_ +#define _IH264E_ME_H_ + /*****************************************************************************/ /* Constant Macros */ @@ -66,7 +67,6 @@ * in to result. This is used for mv prediction ****************************************************************************** */ - #define MEDIAN(a, b, c, result) if (a > b){\ if (b > c)\ result = b;\ @@ -89,284 +89,32 @@ } /*****************************************************************************/ -/* Extern Function Declarations */ +/* Function Declarations */ /*****************************************************************************/ -/** - ******************************************************************************* - * - * @brief - * This function populates the length of the codewords for motion vectors in the - * range (-search range, search range) in pixels - * - * @param[in] ps_me - * Pointer to me ctxt - * - * @param[out] pu1_mv_bits - * length of the codeword for all mv's - * - * @remarks The length of the code words are derived from signed exponential - * goloumb codes. - * - ******************************************************************************* - */ void ih264e_init_mv_bits(me_ctxt_t *ps_me); -/** - ******************************************************************************* - * - * @brief The function computes the parameters for a P skip MB - * - * @par Description: - * The function computes the parameters for a P skip MB - * - * @param[in] ps_proc - * Process context - * - * @param[in] u4_for_me - * Flag to indicate the purpose of computing skip - * - * @param[out] ps_pred_mv - * Flag to indicate the current active refernce list - * - * @returns - * 1) Updates skip MV in proc - * 2) Returns if the current MB can be coded as skip or not - * - * @remarks The code implements the logic as described in sec 8.4.1.1 in H264 - * specification. - * - ******************************************************************************* -*/ ih264e_skip_params_ft ih264e_find_pskip_params; -/** - ******************************************************************************* - * - * @brief The function computes the parameters for a P skip MB - * - * @par Description: - * The function computes the parameters for a P skip MB - * - * @param[in] ps_proc - * Process context - * - * @param[in] u4_for_me - * Flag to indicate the purpose of computing skip - * - * @param[out] ps_pred_mv - * Flag to indicate the current active refernce list - * - * @returns - * 1) Updates skip MV in proc - * 2) Returns if the current MB can be coded as skip or not - * - * @remarks The code implements the logic as described in sec 8.4.1.1 in H264 - * specification. - * - ******************************************************************************* -*/ ih264e_skip_params_ft ih264e_find_pskip_params_me; -/** - ******************************************************************************* - * - * @brief The function computes the parameters for a B skip MB - * - * @par Description: - * The function computes the parameters for a B skip MB - * - * @param[in] ps_proc - * Process context - * - * @param[in] u4_for_me - * Flag to indicate the purpose of computing skip - * - * @param[out] ps_pred_mv - * Flag to indicate the current active refernce list - * - * @returns - * 1) Updates skip MV in proc - * 2) Returns if the current MB can be coded as skip or not - * - * @remarks The code implements the logic as described in sec 8.4.1.1 in H264 - * specification. - * - ******************************************************************************* -*/ ih264e_skip_params_ft ih264e_find_bskip_params; -/** - ******************************************************************************* - * - * @brief The function computes the parameters for a B skip MB - * - * @par Description: - * The function computes the parameters for a B skip MB - * - * @param[in] ps_proc - * Process context - * - * @param[in] u4_for_me - * Flag to indicate the purpose of computing skip - * - * @param[out] ps_pred_mv - * Flag to indicate the current active refernce list - * - * @returns - * 1) Updates skip MV in proc - * 2) The type of SKIP [L0/L1/BI] - * - * @remarks - ******************************************************************************* -*/ ih264e_skip_params_ft ih264e_find_bskip_params_me; -/** - ******************************************************************************* - * - * @brief motion vector predictor - * - * @par Description: - * The routine calculates the motion vector predictor for a given block, - * given the candidate MV predictors. - * - * @param[in] ps_left_mb_pu - * pointer to left mb motion vector info - * - * @param[in] ps_top_row_pu - * pointer to top & top right mb motion vector info - * - * @param[out] ps_pred_mv - * pointer to candidate predictors for the current block - * - * @returns The x & y components of the MV predictor. - * - * @remarks The code implements the logic as described in sec 8.4.1.3 in H264 - * specification. - * Assumptions : 1. Assumes Only partition of size 16x16 - * - ******************************************************************************* - */ void ih264e_get_mv_predictor(enc_pu_t *ps_left_mb_pu, enc_pu_t *ps_top_row_pu, enc_pu_mv_t *ps_pred_mv, WORD32 i4_ref_list); -/** - ******************************************************************************* - * - * @brief This fucntion evalues ME for 2 reference lists - * - * @par Description: - * It evaluates skip, full-pel an half-pel and assigns the correct MV in proc - * - * @param[in] ps_proc - * Process context corresponding to the job - * - * @returns none - * - * @remarks none - * - ******************************************************************************* - */ ih264e_compute_me_ft ih264e_compute_me_multi_reflist; -/** - ******************************************************************************* - * - * @brief This fucntion evalues ME for single reflist [Pred L0] - * - * @par Description: - * It evaluates skip, full-pel an half-pel and assigns the correct MV in proc - * - * @param[in] ps_proc - * Process context corresponding to the job - * - * @returns none - * - * @remarks none - * - ******************************************************************************* - */ ih264e_compute_me_ft ih264e_compute_me_single_reflist; -/** - ******************************************************************************* - * - * @brief This function initializes me ctxt - * - * @par Description: - * Before dispatching the current job to me thread, the me context associated - * with the job is initialized. - * - * @param[in] ps_proc - * Process context corresponding to the job - * - * @returns none - * - * @remarks none - * - ******************************************************************************* - */ void ih264e_init_me(process_ctxt_t *ps_proc); -/** - ******************************************************************************* - * - * @brief This function performs motion estimation for the current NMB - * - * @par Description: - * Intializes input and output pointers required by the function ih264e_compute_me - * and calls the function ih264e_compute_me in a loop to process NMBs. - * - * @param[in] ps_proc - * Process context corresponding to the job - * - * @returns - * - * @remarks none - * - ******************************************************************************* - */ void ih264e_compute_me_nmb(process_ctxt_t *ps_proc, UWORD32 u4_nmb_count); -/** - ******************************************************************************* - * - * @brief This function performs MV prediction - * - * @par Description: - * - * @param[in] ps_proc - * Process context corresponding to the job - * - * @returns none - * - * @remarks none - * This function will update the MB availability since intra inter decision - * should be done before the call - * - ******************************************************************************* - */ void ih264e_mv_pred(process_ctxt_t *ps_proc, WORD32 i4_reflist); -/** - ******************************************************************************* - * - * @brief This function approximates Pred. MV - * - * @par Description: - * - * @param[in] ps_proc - * Process context corresponding to the job - * - * @returns none - * - * @remarks none - * Motion estimation happens at nmb level. For cost calculations, mv is appro - * ximated using this function - * - ******************************************************************************* - */ void ih264e_mv_pred_me(process_ctxt_t *ps_proc, WORD32 i4_ref_list); -#endif /* IH264E_ME_H_ */ +#endif /* _IH264E_ME_H_ */ diff --git a/encoder/ih264e_modify_frm_rate.c b/encoder/ih264e_modify_frm_rate.c index f1e6e616..8f93f642 100644 --- a/encoder/ih264e_modify_frm_rate.c +++ b/encoder/ih264e_modify_frm_rate.c @@ -24,19 +24,19 @@ * ih264e_modify_frm_rate.c * * @brief -* Functions used to modify frame rate +* Handle source frame rate pulldown * * @author * ittiam * * @par List of Functions: -* - ih264e_pd_frm_rate_get_init_free_memtab() -* - ih264e_init_pd_frm_rate() -* - ih264e_update_pd_frm_rate() -* - ih264e_get_pd_avg_frm_rate() +* - ih264e_pd_frm_rate_get_init_free_memtab +* - ih264e_init_pd_frm_rate +* - ih264e_update_pd_frm_rate +* - ih264e_get_pd_avg_frm_rate * * @remarks -* None +* none * ******************************************************************************* */ @@ -45,31 +45,35 @@ /* File Includes */ /*****************************************************************************/ -/* User include files */ -#include "irc_datatypes.h" +/* User Include Files */ +#include "ih264_typedefs.h" #include "iv2.h" #include "ive2.h" + #include "ih264_defs.h" +#include "ih264_mem_fns.h" +#include "ih264_padding.h" #include "ih264_structs.h" #include "ih264_trans_quant_itrans_iquant.h" #include "ih264_inter_pred_filters.h" -#include "ih264_mem_fns.h" -#include "ih264_padding.h" #include "ih264_intra_pred_filters.h" #include "ih264_deblk_edge_filters.h" #include "ih264_cabac_tables.h" -#include "ih264e_error.h" -#include "ih264e_bitstream.h" -#include "ih264e_defs.h" -#include "ime_distortion_metrics.h" + #include "ime_defs.h" +#include "ime_distortion_metrics.h" #include "ime_structs.h" + +#include "irc_mem_req_and_acq.h" #include "irc_cntrl_param.h" #include "irc_frame_info_collector.h" + +#include "ih264e_error.h" +#include "ih264e_defs.h" #include "ih264e_rate_control.h" +#include "ih264e_bitstream.h" #include "ih264e_cabac_structs.h" #include "ih264e_structs.h" -#include "ih264e_rc_mem_interface.h" #include "ih264e_time_stamp.h" #include "ih264e_modify_frm_rate.h" diff --git a/encoder/ih264e_modify_frm_rate.h b/encoder/ih264e_modify_frm_rate.h index c301e2c2..1bcf73eb 100644 --- a/encoder/ih264e_modify_frm_rate.h +++ b/encoder/ih264e_modify_frm_rate.h @@ -24,19 +24,19 @@ * ih264e_modify_frm_rate.h * * @brief -* Functions declarations used to modify frame rate +* Handle source frame rate pulldown * * @author * ittiam * * @remarks -* None +* none * ******************************************************************************* */ -#ifndef IH264E_MODIFY_FRM_RATE_H_ -#define IH264E_MODIFY_FRM_RATE_H_ +#ifndef _IH264E_MODIFY_FRM_RATE_H_ +#define _IH264E_MODIFY_FRM_RATE_H_ /*****************************************************************************/ /* Constant Definitions */ @@ -80,103 +80,16 @@ typedef struct pd_frm_rate_t *pd_frm_rate_handle; /* Function Declarations */ /*****************************************************************************/ -/** -******************************************************************************* -* -* @brief Function to init pd frame rate memtab -* -* @par Description -* Function to init pull down frame rate memtab -* -* @param[in] pps_pd_frm_rate -* pull down frame rate context -* -* @param[in] ps_memtab -* Handle to memtab -* -* @param[in] e_func_type -* Function type (get memtab/ update memtab) -* -* @returns Number of memtabs used -* -* @remarks None -* -******************************************************************************* -*/ WORD32 ih264e_pd_frm_rate_get_init_free_memtab(pd_frm_rate_handle *pps_pd_frm_rate, itt_memtab_t *ps_memtab, ITT_FUNC_TYPE_E e_func_type); -/** -******************************************************************************* -* -* @brief Initializes the pull down frame rate state structure based on input -* frame rate -* -* @par Description -* Initializes the pull down frame rate state structure based on input frame rate -* -* @param[in] ps_pd_frm_rate -* Pull down frame rate context -* -* @param[in] u4_input_frm_rate -* Input frame rate in frame per 1000sec -* -* @returns none -* -* @remarks -* -******************************************************************************* -*/ + void ih264e_init_pd_frm_rate(pd_frm_rate_handle ps_pd_frm_rate, UWORD32 u4_input_frm_rate); -/** -******************************************************************************* -* -* @brief Function to update pull down frame rate -* -* @par Description -* For each frame a run time frame rate value is sent based on whether a frame -* is skipped or not. If it is skipped for pull down then the current frame -* rate for the pull down period is signaled as 4/5th of the original frame -* rate. Thus when this is averaged the frame rate gradually switches from the -* input frame rate to 4/5th of input frame rate as and when more 3:2 pull -* down patterns are detected -* -* @param[in] ps_pd_frm_rate -* Pull down frame rate context -* -* @param[in] u4_input_frm_rate -* Input frame rate in frame per 1000sec -* -* @returns none -* -* @remarks -* -******************************************************************************* -*/ void ih264e_update_pd_frm_rate(pd_frm_rate_handle ps_pd_frm_rate, UWORD32 u4_cur_frm_rate); -/** -******************************************************************************* -* -* @brief returns average frame rate in 1 sec duration -* -* @par Description -* Averages the last N frame in period(1 sec) and then gives that -* as the current frames frame rate. Thus this averages out the sudden -* variation in frame rate -* -* @param[in] ps_pd_frm_rate -* Handle to pull down frame rate context -* -* @returns average frame rate -* -* @remarks -* -******************************************************************************* -*/ UWORD32 ih264e_get_pd_avg_frm_rate(pd_frm_rate_handle ps_pd_frm_rate); -#endif /* IH264E_MODIFY_FRM_RATE_H_ */ +#endif /* _IH264E_MODIFY_FRM_RATE_H_ */ diff --git a/encoder/ih264e_process.c b/encoder/ih264e_process.c index abeea1e7..d3212c06 100644 --- a/encoder/ih264e_process.c +++ b/encoder/ih264e_process.c @@ -27,24 +27,23 @@ * Contains functions for codec thread * * @author -* Harish +* ittiam * * @par List of Functions: -* - ih264e_generate_sps_pps() -* - ih264e_init_entropy_ctxt() -* - ih264e_entropy() -* - ih264e_pack_header_data() -* - ih264e_update_proc_ctxt() -* - ih264e_init_proc_ctxt() -* - ih264e_pad_recon_buffer() -* - ih264e_dblk_pad_hpel_processing_n_mbs() -* - ih264e_process() -* - ih264e_set_rc_pic_params() -* - ih264e_update_rc_post_enc() -* - ih264e_process_thread() +* - ih264e_generate_sps_pps +* - ih264e_init_entropy_ctxt +* - ih264e_entropy +* - ih264e_pack_header_data +* - ih264e_update_proc_ctxt +* - ih264e_init_proc_ctxt +* - ih264e_pad_recon_buffer +* - ih264e_dblk_pad_hpel_processing_n_mbs +* - ih264e_process +* - ih264e_update_rc_post_enc +* - ih264e_process_thread * * @remarks -* None +* none * ******************************************************************************* */ @@ -53,7 +52,7 @@ /* File Includes */ /*****************************************************************************/ -/* System include files */ +/* System Include Files */ #include #include #include @@ -61,57 +60,60 @@ #include #include -/* User include files */ +/* User Include Files */ +#include "ih264e_config.h" #include "ih264_typedefs.h" #include "iv2.h" #include "ive2.h" -#include "ih264_defs.h" +#include "ithread.h" + #include "ih264_debug.h" -#include "ime_distortion_metrics.h" -#include "ime_defs.h" -#include "ime_structs.h" +#include "ih264_macros.h" #include "ih264_error.h" +#include "ih264_defs.h" +#include "ih264_mem_fns.h" +#include "ih264_padding.h" #include "ih264_structs.h" #include "ih264_trans_quant_itrans_iquant.h" #include "ih264_inter_pred_filters.h" -#include "ih264_mem_fns.h" -#include "ih264_padding.h" #include "ih264_intra_pred_filters.h" #include "ih264_deblk_edge_filters.h" +#include "ih264_common_tables.h" +#include "ih264_cavlc_tables.h" #include "ih264_cabac_tables.h" -#include "ih264_platform_macros.h" -#include "ih264_macros.h" #include "ih264_buf_mgr.h" -#include "ih264e_error.h" -#include "ih264e_bitstream.h" -#include "ih264_common_tables.h" #include "ih264_list.h" -#include "ih264e_defs.h" +#include "ih264_platform_macros.h" + +#include "ime_defs.h" +#include "ime_distortion_metrics.h" +#include "ime_structs.h" +#include "ime_statistics.h" + +#include "irc_mem_req_and_acq.h" #include "irc_cntrl_param.h" #include "irc_frame_info_collector.h" +#include "irc_rate_control_api.h" + +#include "ih264e_error.h" +#include "ih264e_defs.h" +#include "ih264e_globals.h" #include "ih264e_rate_control.h" +#include "ih264e_bitstream.h" #include "ih264e_cabac_structs.h" #include "ih264e_structs.h" +#include "ih264e_deblk.h" +#include "ih264e_encode_header.h" +#include "ih264e_utils.h" +#include "ih264e_me.h" +#include "ih264e_intra_modes_eval.h" +#include "ih264e_cavlc.h" #include "ih264e_cabac.h" +#include "ih264e_master.h" #include "ih264e_process.h" -#include "ithread.h" -#include "ih264e_intra_modes_eval.h" -#include "ih264e_encode_header.h" -#include "ih264e_globals.h" -#include "ih264e_config.h" #include "ih264e_trace.h" #include "ih264e_statistics.h" -#include "ih264_cavlc_tables.h" -#include "ih264e_cavlc.h" -#include "ih264e_deblk.h" -#include "ih264e_me.h" -#include "ih264e_debug.h" -#include "ih264e_master.h" -#include "ih264e_utils.h" -#include "irc_mem_req_and_acq.h" -#include "irc_rate_control_api.h" #include "ih264e_platform_macros.h" -#include "ime_statistics.h" /*****************************************************************************/ @@ -121,17 +123,17 @@ /** ****************************************************************************** * -* @brief This function generates sps, pps set on request +* @brief This function generates sps, pps set on request * -* @par Description +* @par Description * When the encoder is set in header generation mode, the following function * is called. This generates sps and pps headers and returns the control back * to caller. * -* @param[in] ps_codec +* @param[in] ps_codec * pointer to codec context * -* @return success or failure error code +* @return success or failure error code * ****************************************************************************** */ @@ -275,7 +277,6 @@ IH264E_ERROR_T ih264e_init_entropy_ctxt(process_ctxt_t *ps_proc) * ******************************************************************************* */ - IH264E_ERROR_T ih264e_entropy(process_ctxt_t *ps_proc) { /* codec context */ @@ -1093,7 +1094,8 @@ WORD32 ih264e_update_proc_ctxt(process_ctxt_t *ps_proc) } /* update intra cost if valid */ - if (ps_proc->i4_mb_intra_cost != INT_MAX) { + if (ps_proc->i4_mb_intra_cost != INT_MAX) + { ps_codec->pi4_mb_intra_cost[(i4_mb_y * i4_wd_mbs) + i4_mb_x] = ps_proc->i4_mb_intra_cost; } @@ -1278,7 +1280,7 @@ IH264E_ERROR_T ih264e_init_proc_ctxt(process_ctxt_t *ps_proc) ps_proc->pu1_rec_buf_luma = ps_proc->pu1_rec_buf_luma_base + (i4_mb_x * MB_SIZE) + i4_rec_strd * (i4_mb_y * MB_SIZE); ps_proc->pu1_rec_buf_chroma = ps_proc->pu1_rec_buf_chroma_base + (i4_mb_x * MB_SIZE) + i4_rec_strd * (i4_mb_y * BLK8x8SIZE); - /* Tempral back and forward reference buffer */ + /* Temporal back and forward reference buffer */ ps_proc->apu1_ref_buf_luma[0] = ps_proc->apu1_ref_buf_luma_base[0] + (i4_mb_x * MB_SIZE) + i4_rec_strd * (i4_mb_y * MB_SIZE); ps_proc->apu1_ref_buf_chroma[0] = ps_proc->apu1_ref_buf_chroma_base[0] + (i4_mb_x * MB_SIZE) + i4_rec_strd * (i4_mb_y * BLK8x8SIZE); ps_proc->apu1_ref_buf_luma[1] = ps_proc->apu1_ref_buf_luma_base[1] + (i4_mb_x * MB_SIZE) + i4_rec_strd * (i4_mb_y * MB_SIZE); @@ -1607,9 +1609,6 @@ IH264E_ERROR_T ih264e_pad_recon_buffer(process_ctxt_t *ps_proc, return IH264E_SUCCESS; } - - - /** ******************************************************************************* * @@ -1930,7 +1929,7 @@ IH264E_ERROR_T ih264e_dblk_pad_hpel_processing_n_mbs(process_ctxt_t *ps_proc, /** ******************************************************************************* * -* @brief This function performs luma & chroma core coding for a set of mb's. +* @brief This function performs luma & chroma encoding for a set of mb's. * * @par Description: * The mb to be coded is taken and is evaluated over a predefined set of modes @@ -2041,7 +2040,6 @@ WORD32 ih264e_process(process_ctxt_t *ps_proc) u4_valid_modes |= (1 << B16x16); } - /* init entropy */ ps_proc->s_entropy.i4_mb_x = ps_proc->i4_mb_x; ps_proc->s_entropy.i4_mb_y = ps_proc->i4_mb_y; @@ -2091,17 +2089,14 @@ WORD32 ih264e_process(process_ctxt_t *ps_proc) /* get the min sad condition for current mb */ ps_proc->u4_min_sad_reached = ps_proc->ps_nmb_info[u4_mb_index].u4_min_sad_reached; ps_proc->u4_min_sad = ps_proc->ps_nmb_info[u4_mb_index].u4_min_sad; + ps_proc->i4_mb_distortion = ps_proc->ps_nmb_info[u4_mb_index].i4_mb_distortion; + ps_proc->i4_mb_cost = ps_proc->ps_nmb_info[u4_mb_index].i4_mb_cost; + ps_proc->u4_mb_type = ps_proc->ps_nmb_info[u4_mb_index].u4_mb_type; ps_proc->ps_skip_mv = &(ps_proc->ps_nmb_info[u4_mb_index].as_skip_mv[0]); ps_proc->ps_ngbr_avbl = &(ps_proc->ps_nmb_info[u4_mb_index].s_ngbr_avbl); ps_proc->ps_pred_mv = &(ps_proc->ps_nmb_info[u4_mb_index].as_pred_mv[0]); - ps_proc->i4_mb_distortion = ps_proc->ps_nmb_info[u4_mb_index].i4_mb_distortion; - ps_proc->i4_mb_cost = ps_proc->ps_nmb_info[u4_mb_index].i4_mb_cost; - ps_proc->u4_min_sad = ps_proc->ps_nmb_info[u4_mb_index].u4_min_sad; - ps_proc->u4_min_sad_reached = ps_proc->ps_nmb_info[u4_mb_index].u4_min_sad_reached; - ps_proc->u4_mb_type = ps_proc->ps_nmb_info[u4_mb_index].u4_mb_type; - /* get the best sub pel buffer */ ps_proc->pu1_best_subpel_buf = ps_proc->ps_nmb_info[u4_mb_index].pu1_best_sub_pel_buf; ps_proc->u4_bst_spel_buf_strd = ps_proc->ps_nmb_info[u4_mb_index].u4_bst_spel_buf_strd; @@ -2205,8 +2200,8 @@ WORD32 ih264e_process(process_ctxt_t *ps_proc) } } + } } - } /* is intra */ if (ps_proc->u4_mb_type == I4x4 || ps_proc->u4_mb_type == I16x16 || ps_proc->u4_mb_type == I8x8) diff --git a/encoder/ih264e_process.h b/encoder/ih264e_process.h index 9cfdac89..a5c65567 100644 --- a/encoder/ih264e_process.h +++ b/encoder/ih264e_process.h @@ -30,305 +30,46 @@ * ittiam * * @remarks -* None +* none * ******************************************************************************* */ -#ifndef IH264E_PROCESS_H_ -#define IH264E_PROCESS_H_ +#ifndef _IH264E_PROCESS_H_ +#define _IH264E_PROCESS_H_ /*****************************************************************************/ /* Function Declarations */ /*****************************************************************************/ -/** -****************************************************************************** -* -* @brief This function generates sps, pps set on request -* -* @par Description -* When the encoder is set in header generation mode, the following function -* is called. This generates sps and pps headers and returns the control back -* to caller. -* -* @param[in] ps_codec -* pointer to codec context -* -* @return success or failure error code -* -****************************************************************************** -*/ -IH264E_ERROR_T ih264e_generate_sps_pps - ( - codec_t *ps_codec - ); +IH264E_ERROR_T ih264e_generate_sps_pps(codec_t *ps_codec); -/** -******************************************************************************* -* -* @brief initialize entropy context. -* -* @par Description: -* Before invoking the call to perform to entropy coding the entropy context -* associated with the job needs to be initialized. This involves the start -* mb address, end mb address, slice index and the pointer to location at -* which the mb residue info and mb header info are packed. -* -* @param[in] ps_proc -* Pointer to the current process context -* -* @returns error status -* -* @remarks none -* -******************************************************************************* -*/ IH264E_ERROR_T ih264e_init_entropy_ctxt(process_ctxt_t *ps_proc); -/** -******************************************************************************* -* -* @brief entry point for entropy coding -* -* @par Description -* This function calls lower level functions to perform entropy coding for a -* group (n rows) of mb's. After encoding 1 row of mb's, the function takes -* back the control, updates the ctxt and calls lower level functions again. -* This process is repeated till all the rows or group of mb's (which ever is -* minimum) are coded -* -* @param[in] ps_proc -* process context -* -* @returns error status -* -* @remarks -* NOTE : It is assumed that this routine is invoked at the start of a slice, -* so the slice header is generated by default. -* -******************************************************************************* -*/ IH264E_ERROR_T ih264e_entropy(process_ctxt_t *ps_proc); -/** -******************************************************************************* -* -* @brief Packs header information of a mb in to a buffer -* -* @par Description: -* After the deciding the mode info of a macroblock, the syntax elements -* associated with the mb are packed and stored. The entropy thread unpacks -* this buffer and generates the end bit stream. -* -* @param[in] ps_proc -* Pointer to the current process context -* -* @returns error status -* -* @remarks none -* -******************************************************************************* -*/ -IH264E_ERROR_T ih264e_pack_header_data - ( - process_ctxt_t *ps_proc - ); +IH264E_ERROR_T ih264e_pack_header_data(process_ctxt_t *ps_proc); -/** -******************************************************************************* -* -* @brief update process context after encoding an mb. This involves preserving -* the current mb information for later use, initialize the proc ctxt elements to -* encode next mb. -* -* @par Description: -* This function performs house keeping tasks after encoding an mb. -* After encoding an mb, various elements of the process context needs to be -* updated to encode the next mb. For instance, the source, recon and reference -* pointers, mb indices have to be adjusted to the next mb. The slice index of -* the current mb needs to be updated. If mb qp modulation is enabled, then if -* the qp changes the quant param structure needs to be updated. Also to encoding -* the next mb, the current mb info is used as part of mode prediction or mv -* prediction. Hence the current mb info has to preserved at top/top left/left -* locations. -* -* @param[in] ps_proc -* Pointer to the current process context -* -* @returns none -* -* @remarks none -* -******************************************************************************* -*/ -WORD32 ih264e_update_proc_ctxt - ( - process_ctxt_t *ps_proc - ); +WORD32 ih264e_update_proc_ctxt(process_ctxt_t *ps_proc); -/** -******************************************************************************* -* -* @brief initialize process context. -* -* @par Description: -* Before dispatching the current job to process thread, the process context -* associated with the job is initialized. Usually every job aims to encode one -* row of mb's. Basing on the row indices provided by the job, the process -* context's buffer ptrs, slice indices and other elements that are necessary -* during core-coding are initialized. -* -* @param[in] ps_proc -* Pointer to the current process context -* -* @returns error status -* -* @remarks none -* -******************************************************************************* -*/ IH264E_ERROR_T ih264e_init_proc_ctxt(process_ctxt_t *ps_proc); -/** -******************************************************************************* -* -* @brief This function performs luma & chroma padding -* -* @par Description: -* -* @param[in] ps_proc -* Process context corresponding to the job -* -* @param[in] pu1_curr_pic_luma -* Pointer to luma buffer -* -* @param[in] pu1_curr_pic_chroma -* Pointer to chroma buffer -* -* @param[in] i4_mb_x -* mb index x -* -* @param[in] i4_mb_y -* mb index y -* -* @param[in] i4_pad_ht -* number of rows to be padded -* -* @returns error status -* -* @remarks none -* -******************************************************************************* -*/ -IH264E_ERROR_T ih264e_pad_recon_buffer - ( - process_ctxt_t *ps_proc, - UWORD8 *pu1_curr_pic_luma, - UWORD8 *pu1_curr_pic_chroma, - WORD32 i4_mb_x, - WORD32 i4_mb_y, - WORD32 i4_pad_ht - ); +IH264E_ERROR_T ih264e_pad_recon_buffer(process_ctxt_t *ps_proc, + UWORD8 *pu1_curr_pic_luma, + UWORD8 *pu1_curr_pic_chroma, + WORD32 i4_mb_x, + WORD32 i4_mb_y, + WORD32 i4_pad_ht); -/** -******************************************************************************* -* -* @brief This function performs luma half pel planes generation -* -* @par Description: -* -* @param[in] ps_proc -* Process context corresponding to the job -* -* @returns error status -* -* @remarks none -* -******************************************************************************* -*/ -IH264E_ERROR_T ih264e_halfpel_generation - ( - process_ctxt_t *ps_proc, - UWORD8 *pu1_curr_pic_luma, - WORD32 i4_mb_x, - WORD32 i4_mb_y - ); +IH264E_ERROR_T ih264e_halfpel_generation(process_ctxt_t *ps_proc, + UWORD8 *pu1_curr_pic_luma, + WORD32 i4_mb_x, + WORD32 i4_mb_y); -/** -******************************************************************************* -* -* @brief This function performs luma & chroma core coding for a set of mb's. -* -* @par Description: -* The mb to be coded is taken and is evaluated over a predefined set of modes -* (intra (i16, i4, i8)/inter (mv, skip)) for best cost. The mode with least cost -* is selected and using intra/inter prediction filters, prediction is carried out. -* The deviation between src and pred signal constitutes error signal. This error -* signal is transformed (hierarchical transform if necessary) and quantized. The -* quantized residue is packed in to entropy buffer for entropy coding. This is -* repeated for all the mb's enlisted under the job. -* -* @param[in] ps_proc -* Process context corresponding to the job -* -* @returns error status -* -* @remarks none -* -******************************************************************************* -*/ WORD32 ih264e_process(process_ctxt_t *ps_proc); -/** -******************************************************************************* -* -* @brief -* Function to update rc context after encoding -* -* @par Description -* This function updates the rate control context after the frame is encoded. -* Number of bits consumed by the current frame, frame distortion, frame cost, -* number of intra/inter mb's, ... are passed on to rate control context for -* updating the rc model. -* -* @param[in] ps_codec -* Handle to codec context -* -* @param[in] ctxt_sel -* frame context selector -* -* @param[in] pic_cnt -* pic count -* -* @returns i4_stuffing_byte -* number of stuffing bytes (if necessary) -* -* @remarks -* -******************************************************************************* -*/ WORD32 ih264e_update_rc_post_enc(codec_t *ps_codec, WORD32 ctxt_sel, WORD32 pic_cnt); -/** -******************************************************************************* -* -* @brief -* entry point of a spawned encoder thread -* -* @par Description: -* The encoder thread dequeues a proc/entropy job from the encoder queue and -* calls necessary routines. -* -* @param[in] pv_proc -* Process context corresponding to the thread -* -* @returns error status -* -* @remarks -* -******************************************************************************* -*/ WORD32 ih264e_process_thread(void *pv_proc); -#endif /* IH264E_PROCESS_H_ */ +#endif /* _IH264E_PROCESS_H_ */ diff --git a/encoder/ih264e_rate_control.c b/encoder/ih264e_rate_control.c index 1c96f69e..a11558bc 100644 --- a/encoder/ih264e_rate_control.c +++ b/encoder/ih264e_rate_control.c @@ -30,16 +30,16 @@ * ittiam * * @par List of Functions: -* - ih264e_rc_init() -* - ih264e_rc_get_picture_details() -* - ih264e_rc_pre_enc() -* - ih264e_update_rc_mb_info() -* - ih264e_rc_get_buffer_status() -* - ih264e_rc_post_enc() -* - ih264e_update_rc_bits_info() +* - ih264e_rc_init +* - ih264e_rc_get_picture_details +* - ih264e_update_rc_framerates +* - ih264e_update_rc_mb_info +* - ih264e_rc_get_buffer_status +* - ih264e_rc_post_enc +* - ih264e_update_rc_bits_info * * @remarks -* None +* none * ******************************************************************************* */ @@ -48,7 +48,7 @@ /* File Includes */ /*****************************************************************************/ -/* System include files */ +/* System Include Files */ #include #include #include @@ -56,70 +56,49 @@ #include #include -/* User include files */ -#include "irc_datatypes.h" +/* User Include Files */ +#include "ih264_typedefs.h" #include "iv2.h" #include "ive2.h" -#include "ih264e.h" -#include "ih264_defs.h" + #include "ih264_macros.h" +#include "ih264_defs.h" +#include "ih264_mem_fns.h" +#include "ih264_padding.h" #include "ih264_structs.h" #include "ih264_trans_quant_itrans_iquant.h" #include "ih264_inter_pred_filters.h" -#include "ih264_mem_fns.h" -#include "ih264_padding.h" #include "ih264_intra_pred_filters.h" #include "ih264_deblk_edge_filters.h" #include "ih264_common_tables.h" #include "ih264_cabac_tables.h" -#include "ih264e_defs.h" -#include "ih264e_globals.h" + +#include "ime_defs.h" +#include "ime_distortion_metrics.h" +#include "ime_structs.h" + #include "irc_mem_req_and_acq.h" #include "irc_cntrl_param.h" #include "irc_frame_info_collector.h" #include "irc_rate_control_api.h" -#include "ih264e_time_stamp.h" -#include "ih264e_modify_frm_rate.h" -#include "ih264e_rate_control.h" + +#include "ih264e.h" #include "ih264e_error.h" +#include "ih264e_defs.h" +#include "ih264e_globals.h" +#include "ih264e_rate_control.h" #include "ih264e_bitstream.h" -#include "ime_distortion_metrics.h" -#include "ime_defs.h" -#include "ime_structs.h" #include "ih264e_cabac_structs.h" #include "ih264e_structs.h" #include "ih264e_utils.h" -#include "irc_trace_support.h" +#include "ih264e_time_stamp.h" +#include "ih264e_modify_frm_rate.h" /*****************************************************************************/ /* Function Definitions */ /*****************************************************************************/ -/** -******************************************************************************* -* -* @brief This function does nothing -* -* @par Description -* This function does nothing -* -* @param[in] variadic function - -* @returns none -* -* @remarks This function is used by the rc library for debugging purposes. -* However this function was not part of rc library. So this is defined here -* to resolve link issues. -* -******************************************************************************* -*/ -int trace_printf(const WORD8 *format, ...) -{ - UNUSED(format); - return(0); -}; - /** ******************************************************************************* * @@ -299,12 +278,13 @@ picture_type_e ih264e_rc_get_picture_details(void *pv_rc_api, /** ******************************************************************************* * -* @brief Function to get rate control output before encoding +* @brief Function to catch frame skips before encoding due to source framerate +* pulldown * * @par Description -* This function is called before queing the current frame. It decides if we should -* skip the current iput buffer due to frame rate mismatch. It also updates RC about -* the acehivble frame rate +* This function is called before queuing the current frame. It decides if we +* should skip the current input buffer due to frame rate mismatch. It also +* updates RC about the framerate pulldown * * @param[in] ps_rate_control_api * Handle to rate control api @@ -318,18 +298,6 @@ picture_type_e ih264e_rc_get_picture_details(void *pv_rc_api, * @param[in] ps_frame_time * Handle to frame time context * -* @param[in] i4_delta_time_stamp -* Time stamp difference between frames -* -* @param[in] i4_total_mb_in_frame -* Total Macro Blocks in frame -* -* @param[in/out] pe_vop_coding_type -* Picture coding type(I/P/B) -* -* @param[in/out] pu1_frame_qp -* QP for current frame -* * @returns * Skip or queue the current frame * @@ -425,9 +393,12 @@ void ih264e_update_rc_mb_info(frame_info_t *ps_frame_info, void *pv_proc) ps_frame_info->num_mbs[mb_type]++; /* cost */ - if (ps_proc->i4_mb_intra_cost != INT_MAX) { + if (ps_proc->i4_mb_intra_cost != INT_MAX) + { ps_frame_info->intra_mb_cost_sum += ps_proc->i4_mb_intra_cost; - } else { + } + else + { /* codec context */ codec_t *ps_codec = ps_proc->ps_codec; @@ -510,7 +481,7 @@ void ih264e_rc_get_buffer_status(void *pv_rc_api, * @par Description * This function is used to update the rate control module after the current * frame encoding is done with details such as bits consumed, SAD for I/P/B, -* intra cost ,mb type and other +* intra cost, mb type and other * * @param[in] ps_rate_control_api * Handle to rate control api context @@ -536,7 +507,7 @@ void ih264e_rc_get_buffer_status(void *pv_rc_api, * @param[in] i4_is_first_frame * Is first frame * -* @param[in] pi4_is_post_encode_skip +* @param[out] pi4_is_post_encode_skip * Post encoding skip flag * * @param[in] u1_frame_qp @@ -548,7 +519,9 @@ void ih264e_rc_get_buffer_status(void *pv_rc_api, * @param[in] pi4_avg_activity * Average activity * -* @returns +* @returns In case of underflow, number of stuffing bytes to be added and in +* case of overflow, flag signalling the encoder to avoid this frame from +* sending * * @remarks * @@ -707,10 +680,12 @@ WORD32 ih264e_rc_post_enc(void * ps_rate_control_api, /** ******************************************************************************* * -* @brief Function to update bits consumed info to rate control context +* @brief Function to update total header and texture bits consumed information +* to rate control context * * @par Description -* Function to update bits consume info to rate control context +* Function to update total header and texture bits consumed information +* to rate control context * * @param[in] ps_frame_info * Frame info context @@ -718,8 +693,7 @@ WORD32 ih264e_rc_post_enc(void * ps_rate_control_api, * @param[in] ps_entropy * Entropy context * -* @returns -* total bits consumed by the frame +* @returns none * * @remarks * diff --git a/encoder/ih264e_rate_control.h b/encoder/ih264e_rate_control.h index cca9ad3b..7c3b3b12 100644 --- a/encoder/ih264e_rate_control.h +++ b/encoder/ih264e_rate_control.h @@ -24,93 +24,24 @@ * ih264e_rate_control.h * * @brief -* This file contains function declarations of api functions for h264 rate -* control +* This file contains declarations of api functions for h264 rate control * * @author * ittiam * * @remarks -* None +* none * ******************************************************************************* */ -#ifndef IH264E_RATE_CONTROL_H_ -#define IH264E_RATE_CONTROL_H_ +#ifndef _IH264E_RATE_CONTROL_H_ +#define _IH264E_RATE_CONTROL_H_ /*****************************************************************************/ /* Function Declarations */ /*****************************************************************************/ -/** -******************************************************************************* -* -* @brief -* This function initializes rate control context and variables -* -* @par Description -* This function initializes rate control type, source and target frame rate, -* average and peak bitrate, intra-inter frame interval and initial -* quantization parameter -* -* @param[in] pv_rc_api -* Handle to rate control api -* -* @param[in] pv_frame_time -* Handle to frame time context -* -* @param[in] pv_time_stamp -* Handle to time stamp context -* -* @param[in] pv_pd_frm_rate -* Handle to pull down frame time context -* -* @param[in] u4_max_frm_rate -* Maximum frame rate -* -* @param[in] u4_src_frm_rate -* Source frame rate -* -* @param[in] u4_tgt_frm_rate -* Target frame rate -* -* @param[in] e_rate_control_type -* Rate control type -* -* @param[in] u4_avg_bit_rate -* Average bit rate -* -* @param[in] u4_peak_bit_rate -* Peak bit rate -* -* @param[in] u4_max_delay -* Maximum delay between frames -* -* @param[in] u4_intra_frame_interval -* Intra frame interval -* -* @param[in] i4_inter_frm_int -* Inter frame interval -* -* @param[in] pu1_init_qp -* Initial qp -* -* @param[in] i4_max_inter_frm_int -* Maximum inter frame interval -* -* @param[in] pu1_min_max_qp -* Array of min/max qp -* -* @param[in] u1_profile_level -* Encoder profile level -* -* @returns none -* -* @remarks -* -******************************************************************************* -*/ void ih264e_rc_init(void *pv_rc_api, void *pv_frame_time, void *pv_time_stamp, @@ -129,120 +60,17 @@ void ih264e_rc_init(void *pv_rc_api, UWORD8 *pu1_min_max_qp, UWORD8 u1_profile_level); -/** -******************************************************************************* -* -* @brief Function to get picture details -* -* @par Description -* This function returns the Picture type(I/P/B) -* -* @param[in] pv_rc_api -* Handle to Rate control api -* -* @returns -* Picture type -* -* @remarks none -* -******************************************************************************* -*/ picture_type_e ih264e_rc_get_picture_details(void *pv_rc_api, WORD32 *pi4_pic_id, WORD32 *pi4_pic_disp_order_no); - -/** -******************************************************************************* -* -* @brief Function to set frame rate inside RC. -* -* @par Description -* This function is called before encoding the current frame and gets the qp -* for the current frame from rate control module -* -* @param[in] ps_rate_control_api -* Handle to rate control api -* -* @param[in] ps_pd_frm_rate -* Handle to pull down frm rate context -* -* @param[in] ps_time_stamp -* Handle to time stamp context -* -* @param[in] ps_frame_time -* Handle to frame time context -* -* @returns -* Skip or encode the current frame -* -* @remarks -* -******************************************************************************* -*/ WORD32 ih264e_update_rc_framerates(void *ps_rate_control_api, - void *ps_pd_frm_rate, - void *ps_time_stamp, - void *ps_frame_time - ); + void *ps_pd_frm_rate, + void *ps_time_stamp, + void *ps_frame_time); -/** -******************************************************************************* -* -* @brief Function to update mb info for rate control context -* -* @par Description -* After encoding a mb, information such as mb type, qp used, mb distortion -* resulted in encoding the block and so on needs to be preserved for modelling -* RC. This is preserved via this function call. -* -* @param[in] ps_frame_info -* Handle Frame info context -* -* @param[in] ps_proc -* Process context -* -* @returns -* -* @remarks -* -******************************************************************************* -*/ void ih264e_update_rc_mb_info(frame_info_t *ps_frame_info, void *pv_proc); -/** -******************************************************************************* -* -* @brief Function to get rate control buffer status -* -* @par Description -* This function is used to get buffer status(underflow/overflow) by rate -* control module -* -* @param[in] pv_rc_api -* Handle to rate control api context -* -* @param[in] i4_total_frame_bits -* Total frame bits -* -* @param[in] u1_pic_type -* Picture type -* -* @param[in] pi4_num_bits_to_prevent_vbv_underflow -* Number of bits to prevent underflow -* -* @param[out] pu1_is_enc_buf_overflow -* Buffer overflow indication flag -* -* @param[out] pu1_is_enc_buf_underflow -* Buffer underflow indication flag -* -* @returns -* -* @remarks -* -******************************************************************************* -*/ void ih264e_rc_get_buffer_status(void *pv_rc_api, WORD32 i4_total_frame_bits, picture_type_e e_pic_type, @@ -250,58 +78,6 @@ void ih264e_rc_get_buffer_status(void *pv_rc_api, UWORD8 *pu1_is_enc_buf_overflow, UWORD8 *pu1_is_enc_buf_underflow); -/** -******************************************************************************* -* -* @brief Function to update rate control module after encoding -* -* @par Description -* This function is used to update the rate control module after the current -* frame encoding is done with details such as bits consumed, SAD for I/P/B, -* intra cost ,mb type and other -* -* @param[in] ps_rate_control_api -* Handle to rate control api context -* -* @param[in] ps_frame_info -* Handle to frame info context -* -* @param[in] ps_pd_frm_rate -* Handle to pull down frame rate context -* -* @param[in] ps_time_stamp -* Handle to time stamp context -* -* @param[in] ps_frame_time -* Handle to frame time context -* -* @param[in] i4_total_mb_in_frame -* Total mb in frame -* -* @param[in] pe_vop_coding_type -* Picture coding type -* -* @param[in] i4_is_first_frame -* Is first frame -* -* @param[in] pi4_is_post_encode_skip -* Post encoding skip flag -* -* @param[in] u1_frame_qp -* Frame qp -* -* @param[in] pi4_num_intra_in_prev_frame -* Number of intra mbs in previous frame -* -* @param[in] pi4_avg_activity -* Average activity -* -* @returns -* -* @remarks -* -******************************************************************************* -*/ WORD32 ih264e_rc_post_enc(void *ps_rate_control_api, frame_info_t *ps_frame_info, void *ps_pd_frm_rate, @@ -315,28 +91,7 @@ WORD32 ih264e_rc_post_enc(void *ps_rate_control_api, WORD32 *pi4_num_intra_in_prev_frame, WORD32 *pi4_avg_activity); -/** -******************************************************************************* -* -* @brief Function to update bits consumed info to rate control context -* -* @par Description -* Function to update bits consume info to rate control context -* -* @param[in] ps_frame_info -* Frame info context -* -* @param[in] ps_entropy -* Entropy context -* -* @returns -* total bits consumed by the frame -* -* @remarks -* -******************************************************************************* -*/ void ih264e_update_rc_bits_info(frame_info_t *ps_frame_info, void *pv_entropy); -#endif /* IH264E_RATE_CONTROL_H */ +#endif /* _IH264E_RATE_CONTROL_H_ */ diff --git a/encoder/ih264e_rc_mem_interface.c b/encoder/ih264e_rc_mem_interface.c index a74513a6..85699f6d 100644 --- a/encoder/ih264e_rc_mem_interface.c +++ b/encoder/ih264e_rc_mem_interface.c @@ -30,14 +30,12 @@ * ittiam * * List of Functions -* - fill_memtab() -* - use_or_fill_base() -* - ih264e_map_rc_mem_recs_to_itt_api() -* - ih264e_map_itt_mem_rec_to_rc_mem_rec() -* - ih264e_get_rate_control_mem_tab() +* - ih264e_map_rc_mem_recs_to_itt_api +* - ih264e_map_itt_mem_rec_to_rc_mem_rec +* - ih264e_get_rate_control_mem_tab * * @remarks -* None +* none * ******************************************************************************* */ @@ -47,60 +45,37 @@ /* File Includes */ /*****************************************************************************/ -/* System include files */ +/* System Include Files */ #include -#include +#include #include +#include #include -#include -#include /* User Include Files */ #include "ih264e_config.h" #include "ih264_typedefs.h" -#include "ih264_size_defs.h" -#include "iv2.h" -#include "ive2.h" -#include "ime_distortion_metrics.h" -#include "ime_defs.h" -#include "ime_structs.h" -#include "ih264e.h" -#include "ithread.h" -#include "ih264_defs.h" + #include "ih264_debug.h" -#include "ih264_macros.h" -#include "ih264_platform_macros.h" -#include "ih264_error.h" +#include "ih264_defs.h" +#include "ih264_mem_fns.h" +#include "ih264_padding.h" #include "ih264_structs.h" +#include "ih264_size_defs.h" #include "ih264_trans_quant_itrans_iquant.h" #include "ih264_inter_pred_filters.h" -#include "ih264_mem_fns.h" -#include "ih264_padding.h" #include "ih264_intra_pred_filters.h" #include "ih264_deblk_edge_filters.h" -#include "ih264_common_tables.h" -#include "ih264_list.h" #include "ih264_cabac_tables.h" -#include "ih264e_error.h" -#include "ih264e_defs.h" -#include "ih264e_bitstream.h" + +#include "ime_defs.h" +#include "ime_distortion_metrics.h" +#include "ime_structs.h" + +#include "irc_mem_req_and_acq.h" #include "irc_cntrl_param.h" #include "irc_frame_info_collector.h" -#include "ih264e_rate_control.h" -#include "ih264e_cabac_structs.h" -#include "ih264e_structs.h" -#include "ih264e_master.h" -#include "ih264_buf_mgr.h" -#include "ih264_dpb_mgr.h" -#include "ih264e_utils.h" -#include "ih264e_platform_macros.h" -#include "ih264_cavlc_tables.h" -#include "ih264e_statistics.h" -#include "ih264e_trace.h" -#include "ih264e_fmt_conv.h" -#include "ih264e_cavlc.h" -#include "ih264e_rc_mem_interface.h" -#include "ih264e_time_stamp.h" +#include "irc_rate_control_api.h" #include "irc_common.h" #include "irc_rd_model.h" #include "irc_est_sad.h" @@ -111,112 +86,23 @@ #include "irc_mb_model_based.h" #include "irc_cbr_buffer_control.h" #include "irc_vbr_str_prms.h" -#include "irc_rate_control_api.h" #include "irc_rate_control_api_structs.h" + +#include "ih264e.h" +#include "ih264e_error.h" +#include "ih264e_defs.h" +#include "ih264e_time_stamp.h" #include "ih264e_modify_frm_rate.h" +#include "ih264e_rate_control.h" +#include "ih264e_bitstream.h" +#include "ih264e_cabac_structs.h" +#include "ih264e_structs.h" /*****************************************************************************/ /* Function Definitions */ /*****************************************************************************/ -/** -****************************************************************************** -* -* @brief This function fills memory record attributes -* -* @par Description -* This function fills memory record attributes -* -* @param[in] ps_mem_tab -* pointer to mem records -* -* @param[in] u4_size -* size of the record -* -* @param[in] i4_alignment -* memory alignment size -* -* @param[in] e_usage -* usage -* -* @param[in] e_mem_region -* mem region -* -* @return void -* -****************************************************************************** -*/ -void fill_memtab(itt_memtab_t *ps_mem_tab, - WORD32 u4_size, - WORD32 i4_alignment, - ITT_MEM_USAGE_TYPE_E e_usage, - ITT_MEM_REGION_E e_mem_region) -{ - /* Make the size next multiple of alignment */ - WORD32 i4_aligned_size = (((u4_size) + (i4_alignment-1)) & (~(i4_alignment-1))); - - /* Fill the memtab */ - ps_mem_tab->u4_size = i4_aligned_size; - ps_mem_tab->i4_alignment = i4_alignment; - ps_mem_tab->e_usage = e_usage; - ps_mem_tab->e_mem_region = e_mem_region; -} - -/** -****************************************************************************** -* -* @brief This function fills memory record attributes -* -* @par Description -* This function fills memory record attributes -* -* @param[in] ps_mem_tab -* pointer to mem records -* -* @param[in] ptr_to_be_filled -* handle to the memory record storage space -* -* @param[in] e_func_type -* enum that dictates fill memory records or use memory records -* -* @return void -* -****************************************************************************** -*/ -WORD32 use_or_fill_base(itt_memtab_t *ps_mem_tab, - void **ptr_to_be_filled, - ITT_FUNC_TYPE_E e_func_type) -{ - /* Fill base for freeing the allocated memory */ - if (e_func_type == FILL_BASE) - { - if (ptr_to_be_filled[0] != 0) - { - ps_mem_tab->pv_base = ptr_to_be_filled[0]; - return (0); - } - else - { - return (-1); - } - } - /* obtain the allocated memory from base pointer */ - if (e_func_type == USE_BASE) - { - if (ps_mem_tab->pv_base != 0) - { - ptr_to_be_filled[0] = ps_mem_tab->pv_base; - return (0); - } - else - { - return (-1); - } - } - return (0); -} - /** ****************************************************************************** * @@ -308,7 +194,7 @@ void ih264e_map_itt_mem_rec_to_rc_mem_rec(iv_mem_rec_t *ps_mem, /** ****************************************************************************** * -* @brief Get memtabs for rate control +* @brief Get/Init memtabs for rate control * * @par Description * This routine is used to Get/init memtabs for rate control diff --git a/encoder/ih264e_rc_mem_interface.h b/encoder/ih264e_rc_mem_interface.h index a2946a75..8b05c4c8 100644 --- a/encoder/ih264e_rc_mem_interface.h +++ b/encoder/ih264e_rc_mem_interface.h @@ -24,156 +24,24 @@ * ih264e_rc_mem_interface.h * * @brief -* This file contains function declaration and structures for rate control -* memtabs +* Get memory requirements of rate control library * * @author * ittiam * -* @remarks -* The rate control library is a global library across various codecs. It -* anticipates certain structures definitions. Those definitions are to be -* imported from global workspace. Instead of that, the structures needed for -* rc library are copied in to this file and exported to rc library. If the -* structures / enums / ... in the global workspace change, this file also needs -* to be modified accordingly. -* ****************************************************************************** */ -#ifndef IH264E_RC_MEM_INTERFACE_H_ -#define IH264E_RC_MEM_INTERFACE_H_ - - -/*****************************************************************************/ -/* Function Macros */ -/*****************************************************************************/ - -#define FILL_MEMTAB(m_pv_mem_rec, m_j, m_mem_size, m_align, m_type) \ -{ \ - m_pv_mem_rec[m_j].u4_size = sizeof(iv_mem_rec_t); \ - m_pv_mem_rec[m_j].u4_mem_size = m_mem_size; \ - m_pv_mem_rec[m_j].u4_mem_alignment = m_align; \ - m_pv_mem_rec[m_j].e_mem_type = m_type; \ -} - -/*****************************************************************************/ -/* Enums */ -/*****************************************************************************/ -typedef enum -{ - ALIGN_BYTE = 1, - ALIGN_WORD16 = 2, - ALIGN_WORD32 = 4, - ALIGN_WORD64 = 8, - ALIGN_128_BYTE = 128 -}ITT_MEM_ALIGNMENT_TYPE_E; - -typedef enum -{ - SCRATCH = 0, - PERSISTENT = 1, - WRITEONCE = 2 -}ITT_MEM_USAGE_TYPE_E; - -typedef enum -{ - L1D = 0, - SL2 = 1, - DDR = 3 -}ITT_MEM_REGION_E; - -typedef enum -{ - GET_NUM_MEMTAB = 0, - FILL_MEMTAB = 1, - USE_BASE = 2, - FILL_BASE =3 -}ITT_FUNC_TYPE_E; +#ifndef _IH264E_RC_MEM_INTERFACE_H_ +#define _IH264E_RC_MEM_INTERFACE_H_ /*****************************************************************************/ -/* Structures */ +/* Function Declarations */ /*****************************************************************************/ - -/*NOTE : This should be an exact replica of IALG_MemRec, any change in IALG_MemRec - must be replicated here*/ -typedef struct -{ - /* Size in bytes */ - UWORD32 u4_size; - - /* Alignment in bytes */ - WORD32 i4_alignment; - - /* decides which memory region to be placed */ - ITT_MEM_REGION_E e_mem_region; - - /* memory is scratch or persistent */ - ITT_MEM_USAGE_TYPE_E e_usage; - - /* Base pointer for allocated memory */ - void *pv_base; -} itt_memtab_t; - - -/*****************************************************************************/ -/* Extern Function Declarations */ -/*****************************************************************************/ - -/** -****************************************************************************** -* -* @brief This function fills memory record attributes -* -* @par Description -* This function fills memory record attributes -* -* @param[in] ps_mem_tab -* pointer to mem records -* -* @param[in] u4_size -* size of the record -* -* @param[in] i4_alignment -* memory alignment size -* -* @param[in] e_usage -* usage -* -* @param[in] e_mem_region -* mem region -* -* @return void -* -****************************************************************************** -*/ -void fill_memtab(itt_memtab_t *ps_mem_tab, WORD32 u4_size, WORD32 i4_alignment, - ITT_MEM_USAGE_TYPE_E e_usage, ITT_MEM_REGION_E e_mem_region); - -/** -****************************************************************************** -* -* @brief This function fills memory record attributes -* -* @par Description -* This function fills memory record attributes -* -* @param[in] ps_mem_tab -* pointer to mem records -* -* @param[in] ptr_to_be_filled -* handle to the memory record storage space -* -* @param[in] e_func_type -* enum that dictates fill memory records or use memory records -* -* @return void -* -****************************************************************************** -*/ -WORD32 use_or_fill_base(itt_memtab_t *ps_mem_tab, void **ptr_to_be_filled, - ITT_FUNC_TYPE_E e_func_type); +WORD32 ih264e_get_rate_control_mem_tab(void *pv_rate_control, + iv_mem_rec_t *ps_mem, + ITT_FUNC_TYPE_E e_func_type); -#endif // IH264E_RC_MEM_INTERFACE_H_ +#endif /* _IH264E_RC_MEM_INTERFACE_H_ */ diff --git a/encoder/ih264e_statistics.h b/encoder/ih264e_statistics.h index 0ab33cab..d917d712 100644 --- a/encoder/ih264e_statistics.h +++ b/encoder/ih264e_statistics.h @@ -24,24 +24,24 @@ * ih264e_statistics.h * * @brief -* Contains macros for generating stats about h264 encoder +* Contains macros for collecting stats during encoding process * * @author * ittiam * * @remarks -* None +* none * ******************************************************************************* */ -#ifndef IH264E_STATISTICS_H_ -#define IH264E_STATISTICS_H_ +#ifndef _IH264E_STATISTICS_H_ +#define _IH264E_STATISTICS_H_ #if CAVLC_LEVEL_STATS /*****************************************************************************/ -/* Extern global declarations */ +/* Global Tables */ /*****************************************************************************/ /** @@ -65,7 +65,7 @@ extern UWORD32 gu4_cavlc_level_bin_else_where; extern UWORD32 gu4_cavlc_level_lut_hit_rate; /*****************************************************************************/ -/* Extern function declarations */ +/* Function declarations */ /*****************************************************************************/ /** @@ -104,7 +104,7 @@ void print_cavlc_level_stats(void); #if GATING_STATS /*****************************************************************************/ -/* Extern global declarations */ +/* global declarations */ /*****************************************************************************/ /** @@ -118,7 +118,7 @@ void print_cavlc_level_stats(void); extern UWORD32 gu4_mb_gated_cnt; /*****************************************************************************/ -/* Extern function declarations */ +/* function declarations */ /*****************************************************************************/ /** @@ -138,4 +138,4 @@ void print_gating_stats(void); #endif -#endif /* IH264E_STATISTICS_H_ */ +#endif /* _IH264E_STATISTICS_H_ */ diff --git a/encoder/ih264e_structs.h b/encoder/ih264e_structs.h index 2920b172..11234f93 100644 --- a/encoder/ih264e_structs.h +++ b/encoder/ih264e_structs.h @@ -30,25 +30,23 @@ * Harish * * @remarks -* None +* none * ******************************************************************************* */ -#ifndef IH264E_STRUCTS_H_ -#define IH264E_STRUCTS_H_ +#ifndef _IH264E_STRUCTS_H_ +#define _IH264E_STRUCTS_H_ /*****************************************************************************/ /* Structure definitions */ /*****************************************************************************/ -/* Early declaration of structs */ typedef struct _codec_t codec_t; typedef struct _proc_t process_ctxt_t; - /*****************************************************************************/ -/* Extern Function type definitions */ +/* Function type definitions */ /*****************************************************************************/ /** @@ -2874,4 +2872,4 @@ struct _codec_t }; -#endif /* IH264E_STRUCTS_H_ */ +#endif /* _IH264E_STRUCTS_H_ */ diff --git a/encoder/ih264e_time_stamp.c b/encoder/ih264e_time_stamp.c index 85b75a35..ce66c1e0 100644 --- a/encoder/ih264e_time_stamp.c +++ b/encoder/ih264e_time_stamp.c @@ -30,26 +30,26 @@ * ittiam * * @par List of Functions: -* - gcd() -* - ih264e_get_range() -* - ih264e_frame_time_get_init_free_memtab() -* - ih264e_init_frame_time() -* - ih264e_should_src_be_skipped() -* - ih264e_time_stamp_get_init_free_memtab() -* - ih264e_init_time_stamp() -* - ih264e_update_time_stamp() -* - ih264e_frame_time_get_src_frame_rate() -* - ih264e_frame_time_get_tgt_frame_rate() -* - ih264e_frame_time_get_src_ticks() -* - ih264e_frame_time_get_tgt_ticks() -* - ih264e_frame_time_get_src_time() -* - ih264e_frame_time_get_tgt_time() -* - ih264e_frame_time_update_src_frame_rate() -* - ih264e_frame_time_update_tgt_frame_rate() -* - ih264_time_stamp_update_frame_rate() +* - gcd +* - ih264e_get_range +* - ih264e_frame_time_get_init_free_memtab +* - ih264e_init_frame_time +* - ih264e_should_src_be_skipped +* - ih264e_time_stamp_get_init_free_memtab +* - ih264e_init_time_stamp +* - ih264e_update_time_stamp +* - ih264e_frame_time_get_src_frame_rate +* - ih264e_frame_time_get_tgt_frame_rate +* - ih264e_frame_time_get_src_ticks +* - ih264e_frame_time_get_tgt_ticks +* - ih264e_frame_time_get_src_time +* - ih264e_frame_time_get_tgt_time +* - ih264e_frame_time_update_src_frame_rate +* - ih264e_frame_time_update_tgt_frame_rate +* - ih264_time_stamp_update_frame_rate * * @remarks -* None +* none * ******************************************************************************* */ @@ -58,34 +58,38 @@ /* File Includes */ /*****************************************************************************/ -/* user include files */ -#include "irc_datatypes.h" +/* User Include Files */ +#include "ih264_typedefs.h" #include "iv2.h" #include "ive2.h" -#include "ih264e_error.h" -#include "ih264e_bitstream.h" + #include "ih264_defs.h" -#include "ih264e_defs.h" -#include "ime_distortion_metrics.h" -#include "ime_defs.h" -#include "ime_structs.h" -#include "irc_cntrl_param.h" -#include "irc_frame_info_collector.h" -#include "ih264e_rate_control.h" +#include "ih264_mem_fns.h" +#include "ih264_padding.h" #include "ih264_structs.h" #include "ih264_trans_quant_itrans_iquant.h" #include "ih264_inter_pred_filters.h" -#include "ih264_mem_fns.h" -#include "ih264_padding.h" #include "ih264_intra_pred_filters.h" #include "ih264_deblk_edge_filters.h" #include "ih264_cabac_tables.h" + +#include "ime_defs.h" +#include "ime_distortion_metrics.h" +#include "ime_structs.h" + +#include "irc_mem_req_and_acq.h" +#include "irc_cntrl_param.h" +#include "irc_frame_info_collector.h" +#include "irc_common.h" +#include "irc_rate_control_api.h" + +#include "ih264e_error.h" +#include "ih264e_defs.h" +#include "ih264e_rate_control.h" +#include "ih264e_bitstream.h" #include "ih264e_cabac_structs.h" #include "ih264e_structs.h" -#include "ih264e_rc_mem_interface.h" #include "ih264e_time_stamp.h" -#include "irc_common.h" -#include "irc_rate_control_api.h" /*****************************************************************************/ @@ -680,7 +684,7 @@ WORD32 ih264e_frame_time_get_tgt_time(frame_time_t *frame_time) * source frame rate * * @returns -* None +* none * * @remarks * @@ -713,7 +717,7 @@ void ih264e_frame_time_update_src_frame_rate(frame_time_t *ps_frame_time, * target frame rate * * @returns -* None +* none * * @remarks * @@ -746,7 +750,7 @@ void ih264e_frame_time_update_tgt_frame_rate(frame_time_t *ps_frame_time, * source frame rate * * @returns -* None +* none * * @remarks * diff --git a/encoder/ih264e_time_stamp.h b/encoder/ih264e_time_stamp.h index 1ee559da..d3af887f 100644 --- a/encoder/ih264e_time_stamp.h +++ b/encoder/ih264e_time_stamp.h @@ -31,13 +31,13 @@ * ittiam * * @remarks -* None +* none * ******************************************************************************* */ -#ifndef IH264E_TIME_STAMP_H_ -#define IH264E_TIME_STAMP_H_ +#ifndef _IH264E_TIME_STAMP_H_ +#define _IH264E_TIME_STAMP_H_ /*****************************************************************************/ /* Structures */ @@ -68,6 +68,7 @@ typedef struct frame_time_t /* Number of frames not to be skipped while maintaining tgt_frm_rate due to delta_time_stamp */ UWORD32 u4_num_frms_dont_skip; + }frame_time_t; typedef struct frame_time_t *frame_time_handle; @@ -114,385 +115,57 @@ typedef struct time_stamp_t For mpeg4 standard, we just have 16bits and we can't accommodate more than 60000 as frame rate. So we scale it and work with it */ WORD32 is_max_frame_rate_scaled; + } time_stamp_t; typedef struct time_stamp_t *time_stamp_handle; /*****************************************************************************/ -/* Extern function declarations */ +/* Function declarations */ /*****************************************************************************/ -/** -******************************************************************************* -* -* @brief -* Function to init frame time context -* -* @par Description -* Frame time structure stores the time of the source and the target frames to -* be encoded. Based on the time we decide whether or not to encode the source -* frame -* -* @param[in] ps_frame_time -* Pointer Frame time context -* -* @param[in] u4_src_frm_rate -* Source frame rate -* -* @param[in] u4_tgt_frm_rate -* Target frame rate -* -* @returns -* none -* -* @remarks -* -******************************************************************************* -*/ void ih264e_init_frame_time(frame_time_t *ps_frame_time, UWORD32 u4_src_frm_rate, UWORD32 u4_tgt_frm_rate); -/** -******************************************************************************* -* -* @brief -* Function to check if frame can be skipped -* -* @par Description -* Based on the source and target frame time and the delta time stamp -* we decide whether to code the source or not. -* This is based on the assumption -* that the source frame rate is greater that target frame rate. -* Updates the time_stamp structure -* -* @param[in] ps_frame_time -* Handle to frame time context -* -* @param[in] u4_delta_time_stamp -* Time stamp difference between frames -* -* @param[out] pu4_frm_not_skipped_for_dts -* Flag to indicate if frame is already skipped by application -* -* @returns -* Flag to skip frame -* -* @remarks -* -******************************************************************************* -*/ UWORD8 ih264e_should_src_be_skipped(frame_time_t *ps_frame_time, UWORD32 u4_delta_time_stamp, UWORD32 *pu4_frm_not_skipped_for_dts); -/** -******************************************************************************* -* -* @brief -* Function to initialize time stamp context -* -* @par Description -* Time stamp structure stores the time stamp data that -* needs to be sent in to the header of MPEG4. Based on the -* max target frame rate the vop_time increment resolution is set -* so as to support all the frame rates below max frame rate. -* A support till the third decimal point is assumed. -* -* @param[in] ps_time_stamp -* Pointer to time stamp structure -* -* @param[in] u4_max_frm_rate -* Maximum frame rate -* -* @param[in] u4_src_frm_rate -* Source frame rate -* -* @returns -* none -* -* @remarks -* -******************************************************************************* -*/ void ih264e_init_time_stamp(time_stamp_handle time_stamp, UWORD32 max_frm_rate, UWORD32 src_frm_rate); -/** -******************************************************************************* -* -* @brief Function to update time stamp context -* -* @par Description -* Vop time is incremented by increment value. When vop time goes -* more than the vop time resolution set the modulo time base to -* 1 and reduce the vop time by vop time resolution so that the -* excess value is present in vop time and get accumulated over time -* so that the corresponding frame rate is achieved at a average of -* 1000 seconds -* -* @param[in] ps_time_stamp -* Pointer to time stamp structure -* -* @returns -* none -* -* @remarks -* -******************************************************************************* -*/ void ih264e_update_time_stamp(time_stamp_handle time_stamp); -/** -******************************************************************************* -* -* @brief -* Function to init frame time memtabs -* -* @par Description -* Function to init frame time memtabs -* -* @param[in] pps_frame_time -* Pointer to frame time contexts -* -* @param[in] ps_memtab -* Pointer to memtab -* -* @param[in] e_func_type -* Function type (get memtabs/init memtabs) -* -* @returns -* none -* -* @remarks -* -******************************************************************************* -*/ WORD32 ih264e_frame_time_get_init_free_memtab(frame_time_handle *pps_frame_time, itt_memtab_t *ps_memtab, ITT_FUNC_TYPE_E e_func_type); -/** -******************************************************************************* -* -* @brief -* Function to initialize time stamp memtabs -* -* @par Description -* Function to initialize time stamp memtabs -* -* @param[in] pps_time_stamp -* Pointer to time stamp context -* -* @param[in] ps_memtab -* Pointer to memtab -* -* @param[in] e_func_type -* Funcion type (Get memtab/ init memtab) -* -* @returns -* number of memtabs used -* -* @remarks -* -******************************************************************************* -*/ WORD32 ih264e_time_stamp_get_init_free_memtab(time_stamp_handle *pps_time_stamp, itt_memtab_t *ps_memtab, ITT_FUNC_TYPE_E e_func_type); -/**************************************************************************** - Run-Time Modifying functions -****************************************************************************/ -/** -******************************************************************************* -* -* @brief Function to get source frame rate -* -* @par Description -* Function to get source frame rate -* -* @param[in] ps_frame_time -* Pointer to frame time context -* -* @returns -* source frame rate -* -* @remarks -* -******************************************************************************* -*/ WORD32 ih264e_frame_time_get_src_frame_rate(frame_time_t *ps_frame_time); -/** -******************************************************************************* -* -* @brief Function to get target frame rate -* -* @par Description -* Function to get target frame rate -* -* @param[in] ps_frame_time -* Pointer to frame time context -* -* @returns -* target frame rate -* -* @remarks -* -******************************************************************************* -*/ WORD32 ih264e_frame_time_get_tgt_frame_rate(frame_time_t *ps_frame_time); -/** -******************************************************************************* -* -* @brief Function to get source time increment -* -* @par Description -* Function to get source time increment -* -* @param[in] ps_frame_time -* Pointer to frame time context -* -* @returns -* source time increment -* -* @remarks -* -******************************************************************************* -*/ WORD32 ih264e_frame_time_get_src_ticks(frame_time_t *ps_frame_time); -/** -******************************************************************************* -* -* @brief Function to get target time increment -* -* @par Description -* Function to get target time increment -* -* @param[in] ps_frame_time -* Pointer to frame time context -* -* @returns -* target time increment -* -* @remarks -* -******************************************************************************* -*/ WORD32 ih264e_frame_time_get_tgt_ticks(frame_time_t *ps_frame_time); -/** -******************************************************************************* -* -* @brief Function to get src frame time -* -* @par Description -* Function to get src frame time -* -* @param[in] ps_frame_time -* Pointer to frame time context -* -* @returns -* src frame time -* -* @remarks -* -******************************************************************************* -*/ WORD32 ih264e_frame_time_get_src_time(frame_time_t *frame_time); -/** -******************************************************************************* -* -* @brief Function to get tgt frame time -* -* @par Description -* Function to get tgt frame time -* -* @param[in] ps_frame_time -* Pointer to frame time context -* -* @returns -* tgt frame time -* -* @remarks -* -******************************************************************************* -*/ WORD32 ih264e_frame_time_get_tgt_time(frame_time_t *frame_time); -/** -******************************************************************************* -* -* @brief Function to update source frame time with a new source frame rate -* -* @par Description -* Function to update source frame time with a new source frame rate -* -* @param[in] ps_frame_time -* Pointer to frame time context -* -* @param[in] src_frm_rate -* source frame rate -* -* @returns -* None -* -* @remarks -* -******************************************************************************* -*/ -void ih264e_frame_time_update_src_frame_rate(frame_time_t *ps_frame_time, WORD32 src_frm_rate); +void ih264e_frame_time_update_src_frame_rate(frame_time_t *ps_frame_time, + WORD32 src_frm_rate); -/** -******************************************************************************* -* -* @brief Function to update target frame time with a new source frame rate -* -* @par Description -* Function to update target frame time with a new source frame rate -* -* @param[in] ps_frame_time -* Pointer to frame time context -* -* @param[in] tgt_frm_rate -* target frame rate -* -* @returns -* None -* -* @remarks -* -******************************************************************************* -*/ -void ih264e_frame_time_update_tgt_frame_rate(frame_time_t *ps_frame_time, WORD32 tgt_frm_rate); +void ih264e_frame_time_update_tgt_frame_rate(frame_time_t *ps_frame_time, + WORD32 tgt_frm_rate); -/** -******************************************************************************* -* -* @brief Function to update target frame time with a new source frame rate -* -* @par Description -* When the frame rate changes the time increment is modified by appropriate ticks -* -* @param[in] ps_time_stamp -* Pointer to time stamp structure -* -* @param[in] src_frm_rate -* source frame rate -* -* @returns -* None -* -* @remarks -* -******************************************************************************* -*/ -void ih264_time_stamp_update_frame_rate(time_stamp_t *ps_time_stamp, UWORD32 src_frm_rate); +void ih264_time_stamp_update_frame_rate(time_stamp_t *ps_time_stamp, + UWORD32 src_frm_rate); -#endif /*IH264E_TIME_STAMP_H_*/ +#endif /*_IH264E_TIME_STAMP_H_ */ diff --git a/encoder/ih264e_trace.h b/encoder/ih264e_trace.h index 81345244..d371cc61 100644 --- a/encoder/ih264e_trace.h +++ b/encoder/ih264e_trace.h @@ -24,20 +24,20 @@ * ih264e_trace.h * * @brief -* This file contains extern declarations of routines that could be helpful -* for debugging purposes. +* This file contains declarations of routines that could be helpful for +* debugging purposes. * * @author * ittiam * * @remarks -* None +* none * ******************************************************************************* */ -#ifndef IH264E_TRACE_H_ -#define IH264E_TRACE_H_ +#ifndef _IH264E_TRACE_H_ +#define _IH264E_TRACE_H_ #if ENABLE_TRACE /*****************************************************************************/ @@ -58,7 +58,7 @@ typedef struct }enc_trace_t; /*****************************************************************************/ -/* Extern variable declarations */ +/* Global variable declarations */ /*****************************************************************************/ extern enc_trace_t g_enc_trace; @@ -83,13 +83,13 @@ extern enc_trace_t g_enc_trace; ****************************************************************************** */ -#define ENTROPY_TRACE(syntax_string, value) \ - { \ - if(g_enc_trace.fp) \ - { \ - fprintf( g_enc_trace.fp, "%-40s : %d\n", syntax_string, value ); \ - fflush ( g_enc_trace.fp); \ - } \ +#define ENTROPY_TRACE(syntax_string, value) \ + { \ + if(g_enc_trace.fp) \ + { \ + fprintf( g_enc_trace.fp, "%-40s : %d\n", syntax_string, value ); \ + fflush ( g_enc_trace.fp); \ + } \ } @@ -100,7 +100,7 @@ extern enc_trace_t g_enc_trace; */ #define AEV_TRACE(string, value, range) \ - if(range && g_enc_trace.fp) \ + if(range && g_enc_trace.fp) \ { \ fprintf( g_enc_trace.fp, "%-40s:%8d R:%d\n", string, value, range); \ fflush ( g_enc_trace.fp); \ @@ -117,45 +117,11 @@ extern enc_trace_t g_enc_trace; /*****************************************************************************/ -/* Extern Function Declarations */ +/* Function Declarations */ /*****************************************************************************/ +WORD32 ih264e_trace_init(const char *pu1_file_name); -/** -****************************************************************************** -* -* @brief Dummy trace init when trace is disabled in encoder -* -* @par Description -* This routine needs to be called at start of trace -* -* @param[in] pu1_file_name -* Name of file where trace outputs need to be stores (handle) -* -* @return success or failure error code -* -****************************************************************************** -*/ -extern WORD32 ih264e_trace_init - ( - const char *pu1_file_name - ); - -/** -****************************************************************************** -* -* @brief Dummy trace de-init function when trace is disabled -* -* @par Description -* This routine needs to be called at end of trace -* -* @return success or failure error code -* -****************************************************************************** -*/ -extern WORD32 ih264e_trace_deinit - ( - void - ); +WORD32 ih264e_trace_deinit(void); -#endif // IH264E_TRACE_H_ +#endif /* _IH264E_TRACE_H_ */ diff --git a/encoder/ih264e_utils.c b/encoder/ih264e_utils.c index aec55764..7ea5f193 100644 --- a/encoder/ih264e_utils.c +++ b/encoder/ih264e_utils.c @@ -30,20 +30,21 @@ * ittiam * * @par List of Functions: -* - ih264e_get_min_level() -* - ih264e_get_lvl_idx() -* - ih264e_get_dpb_size() -* - ih264e_get_total_pic_buf_size() -* - ih264e_get_pic_mv_bank_size() -* - ih264e_pic_buf_mgr_add_bufs() -* - ih264e_mv_buf_mgr_add_bufs() -* - ih264e_init_quant_params() -* - ih264e_init_air_map() -* - ih264e_codec_init() -* - ih264e_pic_init() +* - ih264e_input_queue_update +* - ih264e_get_min_level +* - ih264e_get_lvl_idx +* - ih264e_get_dpb_size +* - ih264e_get_total_pic_buf_size +* - ih264e_get_pic_mv_bank_size +* - ih264e_pic_buf_mgr_add_bufs +* - ih264e_mv_buf_mgr_add_bufs +* - ih264e_init_quant_params +* - ih264e_init_air_map +* - ih264e_codec_init +* - ih264e_pic_init * * @remarks -* None +* none * ******************************************************************************* */ @@ -52,139 +53,147 @@ /* File Includes */ /*****************************************************************************/ -/* system include files */ +/* System Include Files */ #include #include #include #include #include -/* user include files */ +/* User Include Files */ +#include "ih264e_config.h" #include "ih264_typedefs.h" #include "iv2.h" #include "ive2.h" -#include "ih264e.h" #include "ithread.h" -#include "ih264_defs.h" -#include "ih264_size_defs.h" -#include "ime_distortion_metrics.h" -#include "ime_defs.h" -#include "ime_structs.h" -#include "psnr.h" + +#include "ih264_debug.h" +#include "ih264_macros.h" #include "ih264_error.h" +#include "ih264_defs.h" +#include "ih264_mem_fns.h" +#include "ih264_padding.h" #include "ih264_structs.h" +#include "ih264_size_defs.h" #include "ih264_trans_quant_itrans_iquant.h" #include "ih264_inter_pred_filters.h" -#include "ih264_mem_fns.h" -#include "ih264_padding.h" #include "ih264_intra_pred_filters.h" #include "ih264_deblk_edge_filters.h" -#include "ih264_cabac_tables.h" -#include "ih264_macros.h" #include "ih264_common_tables.h" -#include "ih264_debug.h" #include "ih264_trans_data.h" -#include "ih264e_defs.h" -#include "ih264e_globals.h" +#include "ih264_cavlc_tables.h" +#include "ih264_cabac_tables.h" #include "ih264_buf_mgr.h" +#include "ih264_list.h" #include "ih264_dpb_mgr.h" -#include "ih264e_error.h" -#include "ih264e_bitstream.h" + +#include "ime_defs.h" +#include "ime_distortion_metrics.h" +#include "ime_structs.h" +#include "ime.h" +#include "ime_statistics.h" + +#include "irc_mem_req_and_acq.h" #include "irc_cntrl_param.h" #include "irc_frame_info_collector.h" +#include "irc_rate_control_api.h" + +#include "psnr.h" + +#include "ih264e.h" +#include "ih264e_error.h" +#include "ih264e_version.h" +#include "ih264e_defs.h" +#include "ih264e_globals.h" +#include "ih264e_time_stamp.h" +#include "ih264e_modify_frm_rate.h" #include "ih264e_rate_control.h" +#include "ih264e_bitstream.h" #include "ih264e_cabac_structs.h" #include "ih264e_structs.h" -#include "ih264e_cabac.h" -#include "ih264e_utils.h" -#include "ih264e_config.h" -#include "ih264e_statistics.h" -#include "ih264e_trace.h" -#include "ih264_list.h" -#include "ih264e_encode_header.h" #include "ih264e_me.h" -#include "ime.h" +#include "ih264e_utils.h" #include "ih264e_core_coding.h" -#include "ih264e_rc_mem_interface.h" -#include "ih264e_time_stamp.h" -#include "ih264e_debug.h" -#include "ih264e_process.h" +#include "ih264e_encode_header.h" +#include "ih264e_cavlc.h" +#include "ih264e_cabac.h" #include "ih264e_master.h" -#include "irc_rate_control_api.h" -#include "ime_statistics.h" +#include "ih264e_process.h" +#include "ih264e_fmt_conv.h" +#include "ih264e_statistics.h" +#include "ih264e_trace.h" + /*****************************************************************************/ /* Function Definitions */ /*****************************************************************************/ /** - ******************************************************************************* - * - * @brief - * Queues the current buffer, gets back a another buffer for encoding with corrent - * picture type - * - * @par Description: - * This function performs 3 distinct but related functions. - * 1) Maintains an input queue [Note the the term queue donot imply a - * first-in first-out logic here] that queues input and dequeues them so - * that input frames can be encoded at any predetermined encoding order - * 2) Uses RC library to decide which frame must be encoded in current pass - * and which picture type it must be encoded to. - * 3) Uses RC library to decide the QP at which current frame has to be - * encoded - * 4) Determines if the current picture must be encoded or not based on - * PRE-ENC skip - * - * Input queue is used for storing input buffers till they are used for - * encoding. This queue is maintained at ps_codec->as_inp_list. Whenever a - * valid input comes, it is added to the end of queue. This same input is - * added to RC queue using the identifier as ps_codec->i4_pic_cnt. Hence any - * pic from RC can be located in the input queue easily. - * - * The dequeue operation does not start till we have ps_codec->s_cfg.u4_max_num_bframes - * frames in the queue. THis is done in order to ensure that once output starts - * we will have a constant stream of output with no gaps. - * - * THe output frame order is governed by RC library. When ever we dequeue a - * buffer from RC library, it ensures that we will get them in encoding order - * With the output of RC library, we can use the picture id to dequeue the - * corresponding buffer from input queue and encode it. - * - * Condition at the end of stream. - * ------------------------------- - * At the last valid buffer from the app, we will get ps_ive_ip->u4_is_last - * to be set. This will the given to lib when appropriate input buffer is - * given to encoding. - * - * Since we have to output is not in sync with input, we will have frames to - * encode even after we recive the last vaild input buffer. Hence we have to - * make sure that we donot queue any new buffers once we get the flag [It may - * mess up GOP ?]. This is acheived by setting ps_codec->i4_last_inp_buff_received - * to act as a permenent marker for last frame recived [This may not be needed, - * because in our current app, all buffers after the last are marked as last. - * But can we rely on that?] . Hence after this flgag is set no new buffers are - * queued. - * - * @param[in] ps_codec - * Pointer to codec descriptor - * - * @param[in] ps_ive_ip - * Current input buffer to the encoder - * - * @param[out] ps_inp - * Buffer to be encoded in the current pass - * - * @returns - * Flag indicating if we have a pre-enc skip or not - * - * @remarks - * TODO (bpic) - * The check for null ans is last is redudent. - * Need to see if we can remove it - * - ******************************************************************************* - */ +******************************************************************************* +* +* @brief +* Queues the current buffer, gets back a another buffer for encoding with +* current picture type +* +* @par Description: +* This function performs 3 distinct but related functions. +* 1) Maintains an input queue [Note the the term queue do not imply a first-in +* first-out logic here] that queues input and dequeues them so that input +* frames can be encoded at any predetermined encoding order +* 2) Uses RC library to decide which frame must be encoded in current pass +* and which picture type it must be encoded to. +* 3) Uses RC library to decide the QP at which current frame has to be encoded +* 4) Determines if the current picture must be encoded or not based on PRE-ENC +* skip +* +* Input queue is used for storing input buffers till they are used for +* encoding. This queue is maintained at ps_codec->as_inp_list. Whenever a +* valid input comes, it is added to the end of queue. This same input is +* added to RC queue using the identifier as ps_codec->i4_pic_cnt. Hence any +* pic from RC can be located in the input queue easily. +* +* The dequeue operation does not start till we have ps_codec->s_cfg.u4_max_num_bframes +* frames in the queue. This is done in order to ensure that once output +* starts we will have a constant stream of output with no gaps. +* +* The output frame order is governed by RC library. When ever we dequeue a +* buffer from RC library, it ensures that we will get them in encoding order +* With the output of RC library, we can use the picture id to dequeue the +* corresponding buffer from input queue and encode it. +* +* Condition at the end of stream: +* ------------------------------- +* At the last valid buffer from the app, we will get ps_ive_ip->u4_is_last +* to be set. This will the given to lib when appropriate input buffer is +* given to encoding. +* +* Since we have to output is not in sync with input, we will have frames to +* encode even after we receive the last valid input buffer. Hence we have to +* make sure that we do not queue any new buffers once we get the flag [It may +* mess up GOP ?]. This is achieved by setting ps_codec->i4_last_inp_buff_received +* to act as a permanent marker for last frame received [This may not be needed, +* because in our current app, all buffers after the last are marked as last. +* But can we rely on that?] . Hence after this flag is set no new buffers are +* queued. +* +* @param[in] ps_codec +* Pointer to codec descriptor +* +* @param[in] ps_ive_ip +* Current input buffer to the encoder +* +* @param[out] ps_inp +* Buffer to be encoded in the current pass +* +* @returns +* Flag indicating if we have a pre-enc skip or not +* +* @remarks +* TODO (bpic) : The check for null and is last is redundant. Need to see if we +* can remove it +* +******************************************************************************* +*/ WORD32 ih264e_input_queue_update(codec_t *ps_codec, ive_video_encode_ip_t *ps_ive_ip, inp_buf_t *ps_enc_buff) @@ -233,7 +242,7 @@ WORD32 ih264e_input_queue_update(codec_t *ps_codec, } /*************************************************************************** - *Queue the input to the queue + * Queue the input to the queue **************************************************************************/ ps_inp_buf = &(ps_codec->as_inp_list[ps_codec->i4_pic_cnt % MAX_NUM_INP_FRAMES]); @@ -344,7 +353,6 @@ WORD32 ih264e_input_queue_update(codec_t *ps_codec, /*************************************************************************** * Now retrieve the correct picture from the queue **************************************************************************/ - /* Mark the skip flag */ i4_skip = 0; ctxt_sel = ps_codec->i4_encode_api_call_cnt % MAX_CTXT_SETS; @@ -486,6 +494,7 @@ WORD32 ih264e_get_min_level(WORD32 wd, WORD32 ht) WORD32 lvl_idx = MAX_LEVEL, i; WORD32 pic_size = wd * ht; WORD32 max = MAX(wd, ht); + for (i = 0; i < MAX_LEVEL; i++) { if ((pic_size <= gai4_ih264_max_luma_pic_size[i]) && @@ -495,7 +504,6 @@ WORD32 ih264e_get_min_level(WORD32 wd, WORD32 ht) break; } } - return gai4_ih264_levels[lvl_idx]; } @@ -663,7 +671,6 @@ WORD32 ih264e_get_dpb_size(WORD32 level, WORD32 pic_size) * * @remarks * -* ******************************************************************************* */ WORD32 ih264e_get_total_pic_buf_size(WORD32 pic_size, @@ -1092,8 +1099,8 @@ void ih264e_init_quant_params(process_ctxt_t *ps_proc, int qp) * Initialize AIR mb frame Map * * @par Description: -* Initialize AIR mb frame map -* MB frame map indicates which frame an Mb should be coded as intra according to AIR +* Initialize AIR mb frame map. MB frame map indicates which MB in a frame +* should be coded as intra according to AIR * * @param[in] ps_codec * Pointer to codec context @@ -1102,7 +1109,6 @@ void ih264e_init_quant_params(process_ctxt_t *ps_proc, int qp) * * @remarks * -* ******************************************************************************* */ IH264E_ERROR_T ih264e_init_air_map(codec_t *ps_codec) @@ -1152,125 +1158,148 @@ IH264E_ERROR_T ih264e_init_air_map(codec_t *ps_codec) /** ******************************************************************************* * -* @brief -* Codec level initializations +* @brief Speed preset side effects * * @par Description: -* Initializes the codec with parameters that needs to be set before encoding -* first frame +* Force apply the configuration options basing on the configured speed preset * * @param[in] ps_codec * Pointer to codec context * -* @param[in] ps_inp_buf -* Pointer to input buffer context -* -* @returns error_status +* @returns none * * @remarks * -* ******************************************************************************* */ -IH264E_ERROR_T ih264e_codec_init(codec_t *ps_codec) +void ih264e_speed_preset_side_effects(codec_t *ps_codec) { - /******************************************************************** - * INITIALIZE CODEC CONTEXT * - ********************************************************************/ - /* encoder presets */ - if (ps_codec->s_cfg.u4_enc_speed_preset != IVE_CONFIG) - { - if (ps_codec->s_cfg.u4_enc_speed_preset == IVE_SLOWEST) - {/* high quality */ - /* enable diamond search */ - ps_codec->s_cfg.u4_me_speed_preset = DMND_SRCH; - ps_codec->s_cfg.u4_enable_fast_sad = 0; + cfg_params_t *ps_cfg = &ps_codec->s_cfg; - /* disable intra 4x4 */ - ps_codec->s_cfg.u4_enable_intra_4x4 = 1; - ps_codec->luma_energy_compaction[1] = - ih264e_code_luma_intra_macroblock_4x4_rdopt_on; + if (ps_cfg->u4_enc_speed_preset == IVE_SLOWEST) + {/* high quality */ + /* enable diamond search */ + ps_cfg->u4_me_speed_preset = DMND_SRCH; + ps_cfg->u4_enable_fast_sad = 0; - /* sub pel off */ - ps_codec->s_cfg.u4_enable_hpel = 1; + /* disable intra 4x4 */ + ps_cfg->u4_enable_intra_4x4 = 1; + ps_codec->luma_energy_compaction[1] = + ih264e_code_luma_intra_macroblock_4x4_rdopt_on; - /* deblocking off */ - ps_codec->s_cfg.u4_disable_deblock_level = DISABLE_DEBLK_LEVEL_0; + /* sub pel off */ + ps_cfg->u4_enable_hpel = 1; - /* disabled intra inter gating in Inter slices */ - ps_codec->u4_inter_gate = 0; - } - else if (ps_codec->s_cfg.u4_enc_speed_preset == IVE_NORMAL) - {/* normal */ - /* enable diamond search */ - ps_codec->s_cfg.u4_me_speed_preset = DMND_SRCH; - ps_codec->s_cfg.u4_enable_fast_sad = 0; + /* deblocking off */ + ps_cfg->u4_disable_deblock_level = DISABLE_DEBLK_LEVEL_0; - /* disable intra 4x4 */ - ps_codec->s_cfg.u4_enable_intra_4x4 = 1; + /* disabled intra inter gating in Inter slices */ + ps_codec->u4_inter_gate = 0; + } + else if (ps_cfg->u4_enc_speed_preset == IVE_NORMAL) + {/* normal */ + /* enable diamond search */ + ps_cfg->u4_me_speed_preset = DMND_SRCH; + ps_cfg->u4_enable_fast_sad = 0; - /* sub pel off */ - ps_codec->s_cfg.u4_enable_hpel = 1; + /* disable intra 4x4 */ + ps_cfg->u4_enable_intra_4x4 = 1; - /* deblocking off */ - ps_codec->s_cfg.u4_disable_deblock_level = DISABLE_DEBLK_LEVEL_0; + /* sub pel off */ + ps_cfg->u4_enable_hpel = 1; - /* disabled intra inter gating in Inter slices */ - ps_codec->u4_inter_gate = 0; - } - else if (ps_codec->s_cfg.u4_enc_speed_preset == IVE_FAST) - {/* normal */ - /* enable diamond search */ - ps_codec->s_cfg.u4_me_speed_preset = DMND_SRCH; - ps_codec->s_cfg.u4_enable_fast_sad = 0; + /* deblocking off */ + ps_cfg->u4_disable_deblock_level = DISABLE_DEBLK_LEVEL_0; - /* disable intra 4x4 */ - ps_codec->s_cfg.u4_enable_intra_4x4 = 0; + /* disabled intra inter gating in Inter slices */ + ps_codec->u4_inter_gate = 0; + } + else if (ps_cfg->u4_enc_speed_preset == IVE_FAST) + {/* fast */ + /* enable diamond search */ + ps_cfg->u4_me_speed_preset = DMND_SRCH; + ps_cfg->u4_enable_fast_sad = 0; - /* sub pel off */ - ps_codec->s_cfg.u4_enable_hpel = 1; + /* disable intra 4x4 */ + ps_cfg->u4_enable_intra_4x4 = 0; - /* deblocking off */ - ps_codec->s_cfg.u4_disable_deblock_level = DISABLE_DEBLK_LEVEL_0; + /* sub pel off */ + ps_cfg->u4_enable_hpel = 1; - /* disabled intra inter gating in Inter slices */ - ps_codec->u4_inter_gate = 1; - } - else if (ps_codec->s_cfg.u4_enc_speed_preset == IVE_HIGH_SPEED) - {/* fast */ - /* enable diamond search */ - ps_codec->s_cfg.u4_me_speed_preset = DMND_SRCH; - ps_codec->s_cfg.u4_enable_fast_sad = 0; + /* deblocking off */ + ps_cfg->u4_disable_deblock_level = DISABLE_DEBLK_LEVEL_0; - /* disable intra 4x4 */ - ps_codec->s_cfg.u4_enable_intra_4x4 = 0; + /* disabled intra inter gating in Inter slices */ + ps_codec->u4_inter_gate = 1; + } + else if (ps_cfg->u4_enc_speed_preset == IVE_HIGH_SPEED) + {/* high speed */ + /* enable diamond search */ + ps_cfg->u4_me_speed_preset = DMND_SRCH; + ps_cfg->u4_enable_fast_sad = 0; - /* sub pel off */ - ps_codec->s_cfg.u4_enable_hpel = 0; + /* disable intra 4x4 */ + ps_cfg->u4_enable_intra_4x4 = 0; - /* deblocking off */ - ps_codec->s_cfg.u4_disable_deblock_level = DISABLE_DEBLK_LEVEL_4; + /* sub pel off */ + ps_cfg->u4_enable_hpel = 0; - /* disabled intra inter gating in Inter slices */ - ps_codec->u4_inter_gate = 0; - } - else if (ps_codec->s_cfg.u4_enc_speed_preset == IVE_FASTEST) - {/* fastest */ - /* enable diamond search */ - ps_codec->s_cfg.u4_me_speed_preset = DMND_SRCH; + /* deblocking off */ + ps_cfg->u4_disable_deblock_level = DISABLE_DEBLK_LEVEL_4; - /* disable intra 4x4 */ - ps_codec->s_cfg.u4_enable_intra_4x4 = 0; + /* disabled intra inter gating in Inter slices */ + ps_codec->u4_inter_gate = 0; + } + else if (ps_cfg->u4_enc_speed_preset == IVE_FASTEST) + {/* fastest */ + /* enable diamond search */ + ps_cfg->u4_me_speed_preset = DMND_SRCH; - /* sub pel off */ - ps_codec->s_cfg.u4_enable_hpel = 0; + /* disable intra 4x4 */ + ps_cfg->u4_enable_intra_4x4 = 0; - /* deblocking off */ - ps_codec->s_cfg.u4_disable_deblock_level = DISABLE_DEBLK_LEVEL_4; + /* sub pel off */ + ps_cfg->u4_enable_hpel = 0; - /* disabled intra inter gating in Inter slices */ - ps_codec->u4_inter_gate = 1; - } + /* deblocking off */ + ps_cfg->u4_disable_deblock_level = DISABLE_DEBLK_LEVEL_4; + + /* disabled intra inter gating in Inter slices */ + ps_codec->u4_inter_gate = 1; + } +} + +/** +******************************************************************************* +* +* @brief +* Codec level initializations +* +* @par Description: +* Initializes the codec with parameters that needs to be set before encoding +* first frame +* +* @param[in] ps_codec +* Pointer to codec context +* +* @param[in] ps_inp_buf +* Pointer to input buffer context +* +* @returns error_status +* +* @remarks +* +******************************************************************************* +*/ +IH264E_ERROR_T ih264e_codec_init(codec_t *ps_codec) +{ + /******************************************************************** + * INITIALIZE CODEC CONTEXT * + ********************************************************************/ + /* encoder presets */ + if (ps_codec->s_cfg.u4_enc_speed_preset != IVE_CONFIG) + { + ih264e_speed_preset_side_effects(ps_codec); } /***************************************************************** @@ -1368,7 +1397,6 @@ IH264E_ERROR_T ih264e_codec_init(codec_t *ps_codec) DEBUG_HISTOGRAM_INIT(); - /* Init dependecy vars */ ps_codec->i4_last_inp_buff_received = 0; @@ -1403,7 +1431,6 @@ IH264E_ERROR_T ih264e_codec_init(codec_t *ps_codec) * * @remarks * -* ******************************************************************************* */ IH264E_ERROR_T ih264e_pic_init(codec_t *ps_codec, inp_buf_t *ps_inp_buf) @@ -1496,7 +1523,6 @@ IH264E_ERROR_T ih264e_pic_init(codec_t *ps_codec, inp_buf_t *ps_inp_buf) ps_codec->u4_is_idr = 1; ps_codec->i4_restore_frame_num = ps_codec->i4_frame_num; - /* reset frame num */ ps_codec->i4_frame_num = 0; @@ -1597,9 +1623,8 @@ IH264E_ERROR_T ih264e_pic_init(codec_t *ps_codec, inp_buf_t *ps_inp_buf) * note that i4_pic_cnt == -1 is used to filter uninit ref pics. * Now since we only have max two ref pics, we will always find max 2 * ref pics. - * - * 2) 3) Self explanatory + * 2), 3) Self explanatory ***************************************************************************/ { /* Search for buffs with maximum pic cnt */ @@ -2282,3 +2307,4 @@ void ih264e_compute_quality_stats(process_ctxt_t *ps_proc) ps_codec->s_global_quality_stats.total_frames; } } + diff --git a/encoder/ih264e_utils.h b/encoder/ih264e_utils.h index 27e37e8c..4c24c8dd 100644 --- a/encoder/ih264e_utils.h +++ b/encoder/ih264e_utils.h @@ -29,332 +29,48 @@ * @author * Harish * -* @par List of Functions: -* -ih264e_input_queue_update() -* -ih264e_get_min_level() -* -ih264e_get_lvl_idx() -* -ih264e_get_dpb_size() -* -ih264e_get_total_pic_buf_size() -* -ih264e_get_pic_mv_bank_size() -* -ih264e_pic_buf_mgr_add_bufs() -* -ih264e_mv_buf_mgr_add_bufs() -* -ih264e_init_quant_params() -* -ih264e_init_air_map() -* -ih264e_codec_init() -* -ih264e_pic_init() -* * @remarks -* None +* none * ******************************************************************************* */ -#ifndef IH264E_UTILS_H_ -#define IH264E_UTILS_H_ +#ifndef _IH264E_UTILS_H_ +#define _IH264E_UTILS_H_ + +/*****************************************************************************/ +/* Function Declarations */ +/*****************************************************************************/ -/** - ******************************************************************************* - * - * @brief - * Queues the current buffer, gets back a another buffer for encoding with corrent - * picture type - * - * @par Description: - * - * @param[in] ps_codec - * Pointer to codec descriptor - * - * @param[in] ps_ive_ip - * Current input buffer to the encoder - * - * @param[out] ps_inp - * Buffer to be encoded in the current pass - * - * @returns - * Flag indicating if we have a pre-enc skip or not - * - * @remarks - * - ******************************************************************************* - */ WORD32 ih264e_input_queue_update(codec_t *ps_codec, ive_video_encode_ip_t *ps_ive_ip, inp_buf_t *ps_enc_buff); -/** -******************************************************************************* -* -* @brief -* Used to get minimum level index for a given picture size -* -* @par Description: -* Gets the minimum level index and then gets corresponding level. -* Also used to ignore invalid levels like 2.3, 3.3 etc -* -* @param[in] wd -* Width -* -* @param[in] ht -* Height -* -* @returns Level index for a given level -* -* @remarks -* -******************************************************************************* -*/ WORD32 ih264e_get_min_level(WORD32 wd, WORD32 ht); -/** -******************************************************************************* -* -* @brief -* Used to get level index for a given level -* -* @par Description: -* Converts from level_idc (which is multiplied by 30) to an index that can be -* used as a lookup. Also used to ignore invalid levels like 2.2 , 3.2 etc -* -* @param[in] level -* Level of the stream -* -* @returns Level index for a given level -* -* @remarks -* -******************************************************************************* -*/ WORD32 ih264e_get_lvl_idx(WORD32 level); -/** -******************************************************************************* -* -* @brief returns maximum number of pictures allowed in dpb for a given level -* -* @par Description: -* For given width, height and level, number of pictures allowed in decoder -* picture buffer is computed as per Annex A.3.1 -* -* @param[in] level -* level of the bit-stream -* -* @param[in] pic_size -* width * height -* -* @returns Number of buffers in DPB -* -* @remarks -* From annexure A.3.1 of H264 specification, -* max_dec_frame_buffering <= MaxDpbSize, where MaxDpbSize is equal to -* Min( 1024 * MaxDPB / ( PicWidthInMbs * FrameHeightInMbs * 384 ), 16 ) and -* MaxDPB is given in Table A-1 in units of 1024 bytes. However the MaxDPB size -* presented in the look up table gas_ih264_lvl_tbl is in units of 512 -* bytes. Hence the expression is modified accordingly. -* -******************************************************************************* -*/ WORD32 ih264e_get_dpb_size(WORD32 level, WORD32 pic_size); -/** -******************************************************************************* -* -* @brief -* Used to get reference picture buffer size for a given level and -* and padding used -* -* @par Description: -* Used to get reference picture buffer size for a given level and padding used -* Each picture is padded on all four sides -* -* @param[in] pic_size -* Number of luma samples (Width * Height) -* -* @param[in] level -* Level -* -* @param[in] horz_pad -* Total padding used in horizontal direction -* -* @param[in] vert_pad -* Total padding used in vertical direction -* -* @returns Total picture buffer size -* -* @remarks -* -* -******************************************************************************* -*/ WORD32 ih264e_get_total_pic_buf_size(WORD32 pic_size, WORD32 level, WORD32 horz_pad, WORD32 vert_pad, WORD32 num_ref_frames, WORD32 num_reorder_frames); -/** -******************************************************************************* -* -* @brief Returns MV bank buffer size for a given number of luma samples -* -* @par Description: -* For given number of luma samples one MV bank size is computed. -* Each MV bank includes pu_map and enc_pu_t for all the min PUs(4x4) in a picture -* -* @param[in] num_luma_samples -* Max number of luma pixels in the frame -* -* @returns Total MV Bank size -* -* @remarks -* -* -******************************************************************************* -*/ WORD32 ih264e_get_pic_mv_bank_size(WORD32 num_luma_samples); -/** -******************************************************************************* -* -* @brief -* Function to initialize ps_pic_buf structs add pic buffers to -* buffer manager in case of non-shared mode -* -* @par Description: -* Function to initialize ps_pic_buf structs add pic buffers to -* buffer manager in case of non-shared mode -* To be called once per stream or for every reset -* -* @param[in] ps_codec -* Pointer to codec context -* -* @returns error status -* -* @remarks -* -* -******************************************************************************* -*/ IH264E_ERROR_T ih264e_pic_buf_mgr_add_bufs(codec_t *ps_codec); -/** -******************************************************************************* -* -* @brief Function to add buffers to MV Bank buffer manager -* -* @par Description: -* Function to add buffers to MV Bank buffer manager. To be called once per -* stream or for every reset -* -* @param[in] ps_codec -* Pointer to codec context -* -* @returns error status -* -* @remarks -* -******************************************************************************* -*/ IH264E_ERROR_T ih264e_mv_buf_mgr_add_bufs(codec_t *ps_codec); -/** -******************************************************************************* -* -* @brief Function to initialize quant params structure -* -* @par Description: -* The forward quantization modules depends on qp/6, qp mod 6, forward scale -* matrix, forward threshold matrix, weight list. The inverse quantization -* modules depends on qp/6, qp mod 6, inverse scale matrix, weight list. -* These params are initialized in this function. -* -* @param[in] ps_proc -* pointer to process context -* -* @param[in] qp -* quantization parameter -* -* @returns none -* -* @remarks -* -******************************************************************************* -*/ void ih264e_init_quant_params(process_ctxt_t *ps_proc, int qp); -/** -******************************************************************************* -* -* @brief -* Initialize AIR mb frame Map -* -* @par Description: -* Initialize AIR mb frame map -* MB frame map indicates which frame an Mb should be coded as intra according to AIR -* -* @param[in] ps_codec -* Pointer to codec context -* -* @returns error_status -* -* @remarks -* -* -******************************************************************************* -*/ IH264E_ERROR_T ih264e_init_air_map(codec_t *ps_codec); -/** -******************************************************************************* -* -* @brief -* Codec level initializations -* -* @par Description: -* Initializes the codec with parameters that needs to be set before encoding -* first frame -* -* @param[in] ps_codec -* Pointer to codec context -* -* @param[in] ps_inp_buf -* Pointer to input buffer context -* -* @returns error_status -* -* @remarks -* -* -******************************************************************************* -*/ +void ih264e_speed_preset_side_effects(codec_t *ps_codec); + IH264E_ERROR_T ih264e_codec_init(codec_t *ps_codec); -/** -******************************************************************************* -* -* @brief -* Picture level initializations -* -* @par Description: -* Before beginning to encode the frame, the current function initializes all -* the ctxts (proc, entropy, me, ...) basing on the input configured params. -* It locates space for storing recon in the encoder picture buffer set, fetches -* reference frame from encoder picture buffer set. Calls RC pre-enc to get -* qp and pic type for the current frame. Queues proc jobs so that -* the other threads can begin encoding. In brief, this function sets up the -* tone for the entire encoder. -* -* @param[in] ps_codec -* Pointer to codec context -* -* @param[in] ps_inp_buf -* Pointer to input buffer context -* -* @returns error_status -* -* @remarks -* -* -******************************************************************************* -*/ IH264E_ERROR_T ih264e_pic_init(codec_t *ps_codec, inp_buf_t *ps_inp_buf); -#endif /* IH264E_UTILS_H_ */ +#endif /* _IH264E_UTILS_H_ */ diff --git a/encoder/ih264e_version.c b/encoder/ih264e_version.c index a8b0db0d..b4889f5c 100644 --- a/encoder/ih264e_version.c +++ b/encoder/ih264e_version.c @@ -24,16 +24,16 @@ * ih264e_version.c * * @brief -* Contains version info for H264 encoder +* Contains version info of h264 encoder * * @author * ittiam * * @par List of Functions: -* - ih264e_get_version() +* - ih264e_get_version * * @remarks -* None +* none * ******************************************************************************* */ @@ -41,20 +41,16 @@ /*****************************************************************************/ /* File Includes */ /*****************************************************************************/ -/* system include files */ + +/* System Include Files */ #include #include #include #include -/* user include files */ +/* User Include Files */ #include "ih264_typedefs.h" #include "iv2.h" -#include "ive2.h" -#include "ih264e.h" -#include "ih264_defs.h" -#include "ih264_debug.h" -#include "ih264_structs.h" #include "ih264e_version.h" @@ -73,7 +69,7 @@ /** * Version string. First two digits signify major version and last two minor */ -#define CODEC_RELEASE_VER "01.00" +#define CODEC_RELEASE_VER "01.02" /** * Vendor name */ diff --git a/encoder/ih264e_version.h b/encoder/ih264e_version.h index 303a1e22..18176e47 100644 --- a/encoder/ih264e_version.h +++ b/encoder/ih264e_version.h @@ -30,35 +30,19 @@ * ittiam * * @remarks -* None +* none * ******************************************************************************* */ -#ifndef IH264E_VERSION_H_ -#define IH264E_VERSION_H_ +#ifndef _IH264E_VERSION_H_ +#define _IH264E_VERSION_H_ + + +/*****************************************************************************/ +/* Function Declarations */ +/*****************************************************************************/ -/** -******************************************************************************* -* -* @brief -* Fills the version info in the given char pointer -* -* @par Description: -* Fills the version info in the given char pointer -* -* @param[in] pc_version -* Pointer to hold version info -* -* @param[in] u4_version_bufsize -* Size of the buffer passed -* -* @returns error status -* -* @remarks none -* -******************************************************************************* -*/ IV_STATUS_T ih264e_get_version(CHAR *pc_version, UWORD32 u4_version_bufsize); -#endif /* IH264E_VERSION_H_ */ +#endif /* _IH264E_VERSION_H_ */ diff --git a/encoder/ime.c b/encoder/ime.c index cfd6e816..06a743fd 100644 --- a/encoder/ime.c +++ b/encoder/ime.c @@ -20,16 +20,21 @@ /** ******************************************************************************* * @file - * ih264e_me.c + * ime.c * * @brief - * + * This file contains functions needed for computing motion vectors of a + * 16x16 block * * @author * Ittiam * * @par List of Functions: - * - + * - ime_diamond_search_16x16 + * - ime_evaluate_init_srchposn_16x16 + * - ime_full_pel_motion_estimation_16x16 + * - ime_sub_pel_motion_estimation_16x16 + * - ime_compute_skip_cost * * @remarks * None @@ -69,17 +74,11 @@ * point of the diamond grid, the function marks the candidate Mb partition as * mv. * -* @param[in] ps_mb_part -* pointer to current mb partition ctxt with respect to ME -* * @param[in] ps_me_ctxt * pointer to me context * -* @param[in] u4_lambda_motion -* lambda motion -* -* @param[in] u4_enable_fast_sad -* enable/disable fast sad computation +* @param[in] i4_reflist +* ref list * * @returns mv pair & corresponding distortion and cost * @@ -150,7 +149,7 @@ void ime_diamond_search_16x16(me_ctxt_t *ps_me_ctxt, WORD32 i4_reflist) i2_mv_u_x = i2_mvx; i2_mv_u_y = i2_mvy; - while (u4_num_layers--) + while (u4_num_layers) { /* FIXME : is this the write way to check for out of bounds ? */ if ( (i2_mvx - 1 < i4_srch_range_w) || @@ -175,14 +174,14 @@ void ime_diamond_search_16x16(me_ctxt_t *ps_me_ctxt, WORD32 i4_reflist) DEBUG_SAD_HISTOGRAM_ADD(i4_sad[3], 2); /* compute cost */ - i4_cost[0] = i4_sad[0] + u4_lambda_motion * ( pu1_mv_bits[ ((i2_mvx - 1) << 2) - ps_mb_part->s_mv_pred.i2_mvx] - + pu1_mv_bits[(i2_mvy << 2) - ps_mb_part->s_mv_pred.i2_mvy] ); - i4_cost[1] = i4_sad[1] + u4_lambda_motion * ( pu1_mv_bits[ ((i2_mvx + 1) << 2) - ps_mb_part->s_mv_pred.i2_mvx] - + pu1_mv_bits[(i2_mvy << 2) - ps_mb_part->s_mv_pred.i2_mvy] ); - i4_cost[2] = i4_sad[2] + u4_lambda_motion * ( pu1_mv_bits[ (i2_mvx << 2) - ps_mb_part->s_mv_pred.i2_mvx] - + pu1_mv_bits[((i2_mvy - 1) << 2) - ps_mb_part->s_mv_pred.i2_mvy] ); - i4_cost[3] = i4_sad[3] + u4_lambda_motion * ( pu1_mv_bits[ (i2_mvx << 2) - ps_mb_part->s_mv_pred.i2_mvx] - + pu1_mv_bits[((i2_mvy + 1) << 2) - ps_mb_part->s_mv_pred.i2_mvy] ); + i4_cost[0] = i4_sad[0] + (WORD32)(u4_lambda_motion * ( pu1_mv_bits[ ((i2_mvx - 1) << 2) - ps_mb_part->s_mv_pred.i2_mvx] + + pu1_mv_bits[(i2_mvy << 2) - ps_mb_part->s_mv_pred.i2_mvy] )); + i4_cost[1] = i4_sad[1] + (WORD32)(u4_lambda_motion * ( pu1_mv_bits[ ((i2_mvx + 1) << 2) - ps_mb_part->s_mv_pred.i2_mvx] + + pu1_mv_bits[(i2_mvy << 2) - ps_mb_part->s_mv_pred.i2_mvy] )); + i4_cost[2] = i4_sad[2] + (WORD32)(u4_lambda_motion * ( pu1_mv_bits[ (i2_mvx << 2) - ps_mb_part->s_mv_pred.i2_mvx] + + pu1_mv_bits[((i2_mvy - 1) << 2) - ps_mb_part->s_mv_pred.i2_mvy] )); + i4_cost[3] = i4_sad[3] + (WORD32)(u4_lambda_motion * ( pu1_mv_bits[ (i2_mvx << 2) - ps_mb_part->s_mv_pred.i2_mvx] + + pu1_mv_bits[((i2_mvy + 1) << 2) - ps_mb_part->s_mv_pred.i2_mvy] )); if (i4_cost_least > i4_cost[0]) @@ -231,8 +230,7 @@ void ime_diamond_search_16x16(me_ctxt_t *ps_me_ctxt, WORD32 i4_reflist) i2_mvx = i2_mv_u_x; i2_mvy = i2_mv_u_y; } - - + u4_num_layers--; } if (i4_cost_least < ps_mb_part->i4_mb_cost) @@ -256,14 +254,11 @@ void ime_diamond_search_16x16(me_ctxt_t *ps_me_ctxt, WORD32 i4_reflist) * This function determines the position in the search window at which the motion * estimation should begin in order to minimise the number of search iterations. * -* @param[in] ps_mb_part -* pointer to current mb partition ctxt with respect to ME -* -* @param[in] u4_lambda_motion -* lambda motion +* @param[in] ps_me_ctxt +* pointer to me context * -* @param[in] u4_fast_flag -* enable/disable fast sad computation +* @param[in] i4_reflist +* ref list * * @returns mv pair & corresponding distortion and cost * @@ -339,9 +334,10 @@ void ime_evaluate_init_srchposn_16x16 ps_me_ctxt->pf_ime_compute_sad_16x16[u4_enable_fast_sad](pu1_curr_mb, pu1_ref, i4_src_strd, i4_ref_strd, i4_mb_cost_least, &i4_mb_distortion); DEBUG_SAD_HISTOGRAM_ADD(i4_mb_distortion, 3); + /* compute cost */ - i4_mb_cost = i4_mb_distortion + u4_lambda_motion * ( pu1_mv_bits[ (ps_mv_list[i].i2_mvx << 2) - ps_mb_part->s_mv_pred.i2_mvx] - + pu1_mv_bits[(ps_mv_list[i].i2_mvy << 2) - ps_mb_part->s_mv_pred.i2_mvy] ); + i4_mb_cost = i4_mb_distortion + (WORD32)(u4_lambda_motion * ( pu1_mv_bits[ (ps_mv_list[i].i2_mvx << 2) - ps_mb_part->s_mv_pred.i2_mvx] + + pu1_mv_bits[(ps_mv_list[i].i2_mvy << 2) - ps_mb_part->s_mv_pred.i2_mvy] )); if (i4_mb_cost < i4_mb_cost_least) { @@ -371,17 +367,15 @@ void ime_evaluate_init_srchposn_16x16 * range * * @par Description: -* This function begins by computing the mv predict vector for the current mb. -* This is used for cost computations. Further basing on the algo. chosen, it -* looks through a set of candidate vectors that best represent the mb a least -* cost and returns this information. -* -* @param[in] ps_proc -* pointer to current proc ctxt +* For a given algorithm (diamond, Hex, nStep, ...) chosen, it searches for the +* best matching full pixel predictor within the search range * * @param[in] ps_me_ctxt * pointer to me context * +* @param[in] i4_reflist +* ref list +* * @returns mv pair & corresponding distortion and cost * * @remarks none @@ -437,16 +431,15 @@ void ime_full_pel_motion_estimation_16x16 * @par Description: * This function begins by searching across all sub pixel sample points * around the full pel motion vector. The vector with least cost is chosen as -* the mv for the current mb. If the skip mode is not evaluated while analysing -* the initial search candidates then analyse it here and update the mv. -* -* @param[in] ps_proc -* pointer to current proc ctxt +* the mv for the current mb. * * @param[in] ps_me_ctxt * pointer to me context * -* @returns none +* @param[in] i4_reflist +* ref list +* +* @returns mv pair & corresponding distortion and cost * * @remarks none * @@ -564,8 +557,8 @@ void ime_sub_pel_motion_estimation_16x16 i4_mb_distortion = ai4_sad[i]; /* compute cost */ - i4_mb_cost = i4_mb_distortion + u4_lambda_motion * ( pu1_mv_bits[ mv_x_tmp - ps_mb_part->s_mv_pred.i2_mvx] - + pu1_mv_bits[mv_y_tmp - ps_mb_part->s_mv_pred.i2_mvy] ); + i4_mb_cost = i4_mb_distortion + (WORD32)(u4_lambda_motion * ( pu1_mv_bits[ mv_x_tmp - ps_mb_part->s_mv_pred.i2_mvx] + + pu1_mv_bits[mv_y_tmp - ps_mb_part->s_mv_pred.i2_mvy] )); if (i4_mb_cost < i4_mb_cost_least) { @@ -598,8 +591,8 @@ void ime_sub_pel_motion_estimation_16x16 i4_mb_distortion = ai4_sad[2 + i]; /* compute cost */ - i4_mb_cost = i4_mb_distortion + u4_lambda_motion * ( pu1_mv_bits[ mv_x_tmp - ps_mb_part->s_mv_pred.i2_mvx] - + pu1_mv_bits[mv_y_tmp - ps_mb_part->s_mv_pred.i2_mvy] ); + i4_mb_cost = i4_mb_distortion + (WORD32)(u4_lambda_motion * ( pu1_mv_bits[ mv_x_tmp - ps_mb_part->s_mv_pred.i2_mvx] + + pu1_mv_bits[mv_y_tmp - ps_mb_part->s_mv_pred.i2_mvy] )); if (i4_mb_cost < i4_mb_cost_least) { @@ -635,8 +628,8 @@ void ime_sub_pel_motion_estimation_16x16 i4_mb_distortion = ai4_sad[4 + i + 2 * j]; /* compute cost */ - i4_mb_cost = i4_mb_distortion + u4_lambda_motion * ( pu1_mv_bits[ mv_x_tmp - ps_mb_part->s_mv_pred.i2_mvx] - + pu1_mv_bits[mv_y_tmp - ps_mb_part->s_mv_pred.i2_mvy] ); + i4_mb_cost = i4_mb_distortion + (WORD32)(u4_lambda_motion * ( pu1_mv_bits[ mv_x_tmp - ps_mb_part->s_mv_pred.i2_mvx] + + pu1_mv_bits[mv_y_tmp - ps_mb_part->s_mv_pred.i2_mvy] )); if (i4_mb_cost < i4_mb_cost_least) { @@ -686,7 +679,7 @@ void ime_sub_pel_motion_estimation_16x16 * @remarks * NOTE: while computing the skip cost, do not enable early exit from compute * sad function because, a negative bias gets added later -* Note tha the last ME candidate in me ctxt is taken as skip motion vector +* Note that the last ME candidate in me ctxt is taken as skip motion vector * ******************************************************************************* */ diff --git a/encoder/ime.h b/encoder/ime.h index f035e9ea..98767243 100644 --- a/encoder/ime.h +++ b/encoder/ime.h @@ -23,7 +23,7 @@ * ime.h * * @brief - * Contains declarations of global variables for H264 encoder + * Contains declarations of me functions * * @author * Ittiam @@ -33,8 +33,8 @@ ******************************************************************************* */ -#ifndef IME_H_ -#define IME_H_ +#ifndef _IME_H_ +#define _IME_H_ /*****************************************************************************/ /* Constant Macros */ @@ -51,148 +51,17 @@ /* Extern Function Declarations */ /*****************************************************************************/ - -/** -******************************************************************************* -* -* @brief Diamond Search -* -* @par Description: -* This function computes the sad at vertices of several layers of diamond grid -* at a time. The number of layers of diamond grid that would be evaluated is -* configurable.The function computes the sad at vertices of a diamond grid. If -* the sad at the center of the diamond grid is lesser than the sad at any other -* point of the diamond grid, the function marks the candidate Mb partition as -* mv. -* -* @param[in] ps_mb_part -* pointer to current mb partition ctxt with respect to ME -* -* @param[in] ps_me_ctxt -* pointer to me context -* -* @param[in] u4_lambda -* lambda motion -* -* @param[in] u4_fast_flag -* enable/disable fast sad computation -* -* @returns mv pair & corresponding distortion and cost -* -* @remarks This module cannot be part of the final product due to its lack of -* computational feasibility. This is only for quality eval purposes. -* -******************************************************************************* - */ extern void ime_diamond_search_16x16(me_ctxt_t *ps_me_ctxt, WORD32 i4_reflist); - -/** -******************************************************************************* -* -* @brief This function computes the best motion vector among the tentative mv -* candidates chosen. -* -* @par Description: -* This function determines the position in the search window at which the motion -* estimation should begin in order to minimise the number of search iterations. -* -* @param[in] ps_mb_part -* pointer to current mb partition ctxt with respect to ME -* -* @param[in] u4_lambda_motion -* lambda motion -* -* @param[in] u4_fast_flag -* enable/disable fast sad computation -* -* @returns mv pair & corresponding distortion and cost -* -* @remarks none -* -******************************************************************************* -*/ extern void ime_evaluate_init_srchposn_16x16(me_ctxt_t *ps_me_ctxt, WORD32 i4_reflist); -/** -******************************************************************************* -* -* @brief Searches for the best matching full pixel predictor within the search -* range -* -* @par Description: -* This function begins by computing the mv predict vector for the current mb. -* This is used for cost computations. Further basing on the algo. chosen, it -* looks through a set of candidate vectors that best represent the mb a least -* cost and returns this information. -* -* @param[in] ps_proc -* pointer to current proc ctxt -* -* @param[in] ps_me_ctxt -* pointer to me context -* -* @returns mv pair & corresponding distortion and cost -* -* @remarks none -* -******************************************************************************* -*/ extern void ime_full_pel_motion_estimation_16x16(me_ctxt_t *ps_me_ctxt, WORD32 i4_ref_list); -/** -******************************************************************************* -* -* @brief Searches for the best matching sub pixel predictor within the search -* range -* -* @par Description: -* This function begins by searching across all sub pixel sample points -* around the full pel motion vector. The vector with least cost is chosen as -* the mv for the current mb. If the skip mode is not evaluated while analysing -* the initial search candidates then analyse it here and update the mv. -* -* @param[in] ps_proc -* pointer to current proc ctxt -* -* @param[in] ps_me_ctxt -* pointer to me context -* -* @returns none -* -* @remarks none -* -******************************************************************************* -*/ extern void ime_sub_pel_motion_estimation_16x16(me_ctxt_t *ps_me_ctxt, WORD32 i4_reflist); -/** -******************************************************************************* -* -* @brief This function computes cost of skip macroblocks -* -* @par Description: -* -* @param[in] ps_me_ctxt -* pointer to me ctxt -* -* @param[in] ps_skip_mv -* pointer to skip mv -* - @param[in] is_slice_type_b -* Whether slice type is BSLICE or not - -* @returns none -* -* @remarks -* NOTE: while computing the skip cost, do not enable early exit from compute -* sad function because, a negative bias gets added later -* -******************************************************************************* -*/ extern void ime_compute_skip_cost(me_ctxt_t *ps_me_ctxt, ime_mv_t *ps_skip_mv, mb_part_ctxt *ps_smb_part_info, @@ -201,4 +70,4 @@ extern void ime_compute_skip_cost(me_ctxt_t *ps_me_ctxt, WORD32 is_slice_type_b); -#endif /* IME_H_ */ +#endif /* _IME_H_ */ diff --git a/encoder/ime_defs.h b/encoder/ime_defs.h index f82018de..2ade8b4b 100644 --- a/encoder/ime_defs.h +++ b/encoder/ime_defs.h @@ -20,11 +20,10 @@ /** ******************************************************************************* * @file -* ihevc_typedefs.h +* ime_defs.h * * @brief -* Type definitions used in the code -* +* Constant definitions used in the code * * @remarks * None @@ -34,13 +33,14 @@ #ifndef _IME_DEFS_H_ #define _IME_DEFS_H_ - -/* Macros to Label candidates */ -#define SKIP_CAND 0 -#define ZERO_CAND 1 -#define LEFT_CAND 2 -#define TOP_CAND 3 -#define TOPR_CAND 4 +/*****************************************************************************/ +/* Constant Macros */ +/*****************************************************************************/ +#define SKIP_CAND 0 +#define ZERO_CAND 1 +#define LEFT_CAND 2 +#define TOP_CAND 3 +#define TOPR_CAND 4 #define NONE 0 #define LEFT 1 diff --git a/encoder/ime_distortion_metrics.c b/encoder/ime_distortion_metrics.c index f8c44df8..467182c9 100644 --- a/encoder/ime_distortion_metrics.c +++ b/encoder/ime_distortion_metrics.c @@ -20,7 +20,7 @@ /** ****************************************************************************** -* @file ih264e_distortion_metrics.c +* @file ime_distortion_metrics.c * * @brief * This file contains definitions of routines that compute distortion @@ -44,7 +44,6 @@ * - ime_compute_satqd_8x16_chroma() * - ime_compute_satqd_16x16_lumaintra() * -* * @remarks * None * @@ -541,7 +540,6 @@ void ime_compute_sad_16x16_fast(UWORD8 *pu1_src, WORD32 i4_max_sad, WORD32 *pi4_mb_distortion) { - WORD32 i4_sad = 0; UWORD32 u4_src_offset = 2 * src_strd - 16; UWORD32 u4_est_offset = 2 * est_strd - 16; @@ -607,7 +605,6 @@ void ime_compute_sad_16x16_fast(UWORD8 *pu1_src, * ****************************************************************************** */ - void ime_compute_sad_8x8(UWORD8 *pu1_src, UWORD8 *pu1_est, WORD32 src_strd, @@ -673,15 +670,12 @@ void ime_compute_sad_8x8(UWORD8 *pu1_src, * ****************************************************************************** */ -void ime_compute_sad_4x4 - ( - UWORD8 *pu1_src, - UWORD8 *pu1_est, - WORD32 src_strd, - WORD32 est_strd, - WORD32 i4_max_sad, - WORD32 *pi4_mb_distortion - ) +void ime_compute_sad_4x4(UWORD8 *pu1_src, + UWORD8 *pu1_est, + WORD32 src_strd, + WORD32 est_strd, + WORD32 i4_max_sad, + WORD32 *pi4_mb_distortion) { WORD32 i4_sad = 0; @@ -703,13 +697,11 @@ void ime_compute_sad_4x4 *pi4_mb_distortion = i4_sad; } - /** ****************************************************************************** * * @brief computes distortion (SAD) between 2 16x8 blocks * -* * @par Description * This functions computes SAD between 2 16x8 blocks. There is a provision * for early exit if the up-to computed SAD exceeds maximum allowed SAD. To @@ -737,15 +729,12 @@ void ime_compute_sad_4x4 * ****************************************************************************** */ -void ime_compute_sad_16x8 - ( - UWORD8 *pu1_src, - UWORD8 *pu1_est, - WORD32 src_strd, - WORD32 est_strd, - WORD32 i4_max_sad, - WORD32 *pi4_mb_distortion - ) +void ime_compute_sad_16x8(UWORD8 *pu1_src, + UWORD8 *pu1_est, + WORD32 src_strd, + WORD32 est_strd, + WORD32 i4_max_sad, + WORD32 *pi4_mb_distortion) { WORD32 i4_sad = 0; UWORD32 u4_src_offset = src_strd - 16; @@ -870,133 +859,125 @@ void ime_compute_sad_16x16_ea8(UWORD8 *pu1_src, return; } - /** ******************************************************************************* * -* @brief This function computes SAD between two 16x16 blocks -* It also computes if the block will be zero after H264 transform and quant for -* Intra 16x16 blocks +* @brief This function computes SAD between two 16x16 blocks. It also computes +* if the block will be zero after H264 transform and quant * * @param[in] pu1_src * UWORD8 pointer to the source * -* @param[out] pu1_dst -* UWORD8 pointer to the destination +* @param[out] pu1_est +* UWORD8 pointer to the estimated block * -* @param[in] src_strd -* integer source stride +* @param[in] i4_src_strd +* source stride * -* @param[in] dst_strd -* integer destination stride +* @param[in] i4_est_strd +* est buffer stride * * @param[in] pu2_thrsh -* Threshold for each element of transofrmed quantized block +* Threshold for each element of transformed quantized block * * @param[out] pi4_mb_distortion -* integer evaluated sad +* evaluated sad * * @param[out] pu4_is_zero -* Poitner to store if the block is zero after transform and quantization +* Pointer to store if the block is zero after transform and quantization * * @remarks * ****************************************************************************** */ void ime_compute_satqd_16x16_lumainter(UWORD8 *pu1_src, - UWORD8 *pu1_est, - WORD32 src_strd, - WORD32 est_strd, - UWORD16 *pu2_thrsh, - WORD32 *pi4_mb_distortion, - UWORD32 *pu4_is_non_zero) + UWORD8 *pu1_est, + WORD32 i4_src_strd, + WORD32 i4_est_strd, + UWORD16 *pu2_thrsh, + WORD32 *pi4_mb_distortion, + UWORD32 *pu4_is_non_zero) { - UWORD32 i,j; - WORD16 s1,s2,s3,s4,sad_1,sad_2,ls1,ls2,ls3,ls4,ls5,ls6,ls7,ls8; - UWORD8 *pu1_src_lp,*pu1_est_lp; + WORD32 i, j; + WORD16 s1, s2, s3, s4; + WORD16 sad_1, sad_2; + WORD16 ls1, ls2, ls3, ls4, ls5, ls6, ls7, ls8; + UWORD8 *pu1_src_lp, *pu1_est_lp; UWORD32 sad = 0; (*pi4_mb_distortion) = 0; - for(i=0;i<4;i++) + + for (i = 0; i < 4; i++) { - for(j=0;j<4;j++) + for (j = 0; j < 4; j++) { - pu1_src_lp = pu1_src + 4*j; - pu1_est_lp = pu1_est + 4*j; + pu1_src_lp = pu1_src + 4 * j; + pu1_est_lp = pu1_est + 4 * j; - s1 = ABS((WORD16)pu1_src_lp[0] - (WORD16)pu1_est_lp[0])+ ABS((WORD16)pu1_src_lp[3] - (WORD16)pu1_est_lp[3]); - s4 = ABS((WORD16)pu1_src_lp[1] - (WORD16)pu1_est_lp[1])+ ABS((WORD16)pu1_src_lp[2] - (WORD16)pu1_est_lp[2]); + s1 = ABS((WORD16)pu1_src_lp[0] - (WORD16)pu1_est_lp[0]) + ABS((WORD16)pu1_src_lp[3] - (WORD16)pu1_est_lp[3]); + s4 = ABS((WORD16)pu1_src_lp[1] - (WORD16)pu1_est_lp[1]) + ABS((WORD16)pu1_src_lp[2] - (WORD16)pu1_est_lp[2]); - pu1_src_lp += src_strd; - pu1_est_lp += est_strd; + pu1_src_lp += i4_src_strd; + pu1_est_lp += i4_est_strd; - s2 = ABS((WORD16)pu1_src_lp[0] - (WORD16)pu1_est_lp[0])+ ABS((WORD16)pu1_src_lp[3] - (WORD16)pu1_est_lp[3]); - s3 = ABS((WORD16)pu1_src_lp[1] - (WORD16)pu1_est_lp[1])+ ABS((WORD16)pu1_src_lp[2] - (WORD16)pu1_est_lp[2]); + s2 = ABS((WORD16)pu1_src_lp[0] - (WORD16)pu1_est_lp[0]) + ABS((WORD16)pu1_src_lp[3] - (WORD16)pu1_est_lp[3]); + s3 = ABS((WORD16)pu1_src_lp[1] - (WORD16)pu1_est_lp[1]) + ABS((WORD16)pu1_src_lp[2] - (WORD16)pu1_est_lp[2]); - pu1_src_lp += src_strd; - pu1_est_lp += est_strd; + pu1_src_lp += i4_src_strd; + pu1_est_lp += i4_est_strd; - s2 += ABS((WORD16)pu1_src_lp[0] - (WORD16)pu1_est_lp[0])+ ABS((WORD16)pu1_src_lp[3] - (WORD16)pu1_est_lp[3]); - s3 += ABS((WORD16)pu1_src_lp[1] - (WORD16)pu1_est_lp[1])+ ABS((WORD16)pu1_src_lp[2] - (WORD16)pu1_est_lp[2]); + s2 += ABS((WORD16)pu1_src_lp[0] - (WORD16)pu1_est_lp[0]) + ABS((WORD16)pu1_src_lp[3] - (WORD16)pu1_est_lp[3]); + s3 += ABS((WORD16)pu1_src_lp[1] - (WORD16)pu1_est_lp[1]) + ABS((WORD16)pu1_src_lp[2] - (WORD16)pu1_est_lp[2]); - pu1_src_lp += src_strd; - pu1_est_lp += est_strd; + pu1_src_lp += i4_src_strd; + pu1_est_lp += i4_est_strd; - s1 += ABS((WORD16)pu1_src_lp[0] - (WORD16)pu1_est_lp[0])+ ABS((WORD16)pu1_src_lp[3] - (WORD16)pu1_est_lp[3]); - s4 += ABS((WORD16)pu1_src_lp[1] - (WORD16)pu1_est_lp[1])+ ABS((WORD16)pu1_src_lp[2] - (WORD16)pu1_est_lp[2]); + s1 += ABS((WORD16)pu1_src_lp[0] - (WORD16)pu1_est_lp[0]) + ABS((WORD16)pu1_src_lp[3] - (WORD16)pu1_est_lp[3]); + s4 += ABS((WORD16)pu1_src_lp[1] - (WORD16)pu1_est_lp[1]) + ABS((WORD16)pu1_src_lp[2] - (WORD16)pu1_est_lp[2]); - sad_1 = s1+s2+s3+s4; + sad_1 = s1 + s2 + s3 + s4; - if(sad == 0) + if (sad == 0) { - sad_2 = sad_1<<1; - - ls1 = sad_2 -(s2 + s3); - ls2 = sad_2 -(s1 + s4); - ls3 = sad_2 -(s3 + s4); - ls4 = sad_2 -(s3 - (s1<<1)); - ls5 = sad_2 -(s4 - (s2<<1)); - ls6 = sad_2 -(s1 + s2); - ls7 = sad_2 -(s2 - (s4<<1)); - ls8 = sad_2 -(s1 - (s3<<1)); - - if( - pu2_thrsh[8] <= sad_1 || - pu2_thrsh[0] <= ls2 || - pu2_thrsh[1] <= ls1 || - pu2_thrsh[2] <= ls8 || - pu2_thrsh[3] <= ls5 || - - pu2_thrsh[4] <= ls6 || - pu2_thrsh[5] <= ls3 || - pu2_thrsh[6] <= ls7 || - pu2_thrsh[7] <= ls4 - - )sad = 1; + sad_2 = sad_1 << 1; + + ls1 = sad_2 - (s2 + s3); + ls2 = sad_2 - (s1 + s4); + ls3 = sad_2 - (s3 + s4); + ls4 = sad_2 - (s3 - (s1 << 1)); + ls5 = sad_2 - (s4 - (s2 << 1)); + ls6 = sad_2 - (s1 + s2); + ls7 = sad_2 - (s2 - (s4 << 1)); + ls8 = sad_2 - (s1 - (s3 << 1)); + + if (pu2_thrsh[8] <= sad_1 || + pu2_thrsh[0] <= ls2 || pu2_thrsh[1] <= ls1 || + pu2_thrsh[2] <= ls8 || pu2_thrsh[3] <= ls5 || + pu2_thrsh[4] <= ls6 || pu2_thrsh[5] <= ls3 || + pu2_thrsh[6] <= ls7 || pu2_thrsh[7] <= ls4) { + sad = 1; + } } (*pi4_mb_distortion) += sad_1; } - pu1_src += (src_strd *4); - pu1_est += (est_strd *4); + pu1_src += (i4_src_strd * 4); + pu1_est += (i4_est_strd * 4); } *pu4_is_non_zero = sad; } - /** ****************************************************************************** * -* @brief computes distortion (SAD and SAQTD) between 2 16x8 (interleaved) chroma blocks -* +* @brief computes distortion (SAD and SAQTD) between 2 16x8 (interleaved) chroma +* blocks * -* @par Description -* This functions computes SAD between2 16x8 chroma blocks(interleaved) -* It also checks if the SATDD(Sum of absolute transformed wuqntized differnce beteern the blocks -* If SAQTD is zero, it gives back zero -* Other wise sad is retrned -* There is no provison for early exit -* -* The transform done here is the transform for chroma blocks in H264 +* @par Description +* This functions computes SAD between2 16x8 chroma blocks(interleaved). It +* also checks if the SATQD, Sum of absolute transformed quantized difference +* between the blocks. If SAQTD is zero, it gives back zero Other wise sad is +* returned. There is no provison for early exit. The transform done here is +* the transform for chroma blocks in H264 * * @param[in] pu1_src * UWORD8 pointer to the source @@ -1017,90 +998,73 @@ void ime_compute_satqd_16x16_lumainter(UWORD8 *pu1_src, * integer evaluated sad * * @remarks -* Fucntion code is nit updated. -* Will require debugging and minor modifications * ****************************************************************************** */ void ime_compute_satqd_8x16_chroma(UWORD8 *pu1_src, - UWORD8 *pu1_est, - WORD32 src_strd, - WORD32 est_strd, - WORD32 max_sad, - UWORD16 *thrsh) + UWORD8 *pu1_est, + WORD32 src_strd, + WORD32 est_strd, + WORD32 max_sad, + UWORD16 *thrsh) { - WORD32 i,j,plane; - WORD16 s1,s2,s3,s4,sad_1,sad_2,ls1,ls2,ls3,ls4,ls5,ls6,ls7,ls8; - UWORD8 *pu1_src_lp,*pu1_est_lp,*pu1_src_plane,*pu1_est_plane; - WORD32 sad =0; - UNUSED(max_sad); + WORD32 i, j, plane; + WORD16 s1, s2, s3, s4; + WORD16 sad_1, sad_2; + WORD16 ls1, ls2, ls3, ls4, ls5, ls6, ls7, ls8; + UWORD8 *pu1_src_lp, *pu1_est_lp, *pu1_src_plane, *pu1_est_plane; + WORD32 sad = 0; + UNUSED(max_sad); pu1_src_plane = pu1_src; pu1_est_plane = pu1_est; - for(plane =0;plane<2;plane++) + for (plane = 0; plane < 2; plane++) { - for(i=0;i<4;i++) + for (i = 0; i < 4; i++) { - for(j=0;j<4;j++) + for (j = 0; j < 4; j++) { - pu1_src_lp = pu1_src + 8*j; - pu1_est_lp = pu1_est + 8*j; + pu1_src_lp = pu1_src + 8 * j; + pu1_est_lp = pu1_est + 8 * j; - s1 = ABS((WORD16)pu1_src_lp[0] - (WORD16)pu1_est_lp[0])+ ABS((WORD16)pu1_src_lp[6] - (WORD16)pu1_est_lp[6]); - s4 = ABS((WORD16)pu1_src_lp[2] - (WORD16)pu1_est_lp[2])+ ABS((WORD16)pu1_src_lp[4] - (WORD16)pu1_est_lp[4]); + s1 = ABS((WORD16)pu1_src_lp[0] - (WORD16)pu1_est_lp[0]) + ABS((WORD16)pu1_src_lp[6] - (WORD16)pu1_est_lp[6]); + s4 = ABS((WORD16)pu1_src_lp[2] - (WORD16)pu1_est_lp[2]) + ABS((WORD16)pu1_src_lp[4] - (WORD16)pu1_est_lp[4]); pu1_src_lp += src_strd; pu1_est_lp += est_strd; - s2 = ABS((WORD16)pu1_src_lp[0] - (WORD16)pu1_est_lp[0])+ ABS((WORD16)pu1_src_lp[6] - (WORD16)pu1_est_lp[6]); - s3 = ABS((WORD16)pu1_src_lp[2] - (WORD16)pu1_est_lp[2])+ ABS((WORD16)pu1_src_lp[4] - (WORD16)pu1_est_lp[4]); + s2 = ABS((WORD16)pu1_src_lp[0] - (WORD16)pu1_est_lp[0]) + ABS((WORD16)pu1_src_lp[6] - (WORD16)pu1_est_lp[6]); + s3 = ABS((WORD16)pu1_src_lp[2] - (WORD16)pu1_est_lp[2]) + ABS((WORD16)pu1_src_lp[4] - (WORD16)pu1_est_lp[4]); pu1_src_lp += src_strd; pu1_est_lp += est_strd; - s2 += ABS((WORD16)pu1_src_lp[0] - (WORD16)pu1_est_lp[0])+ ABS((WORD16)pu1_src_lp[6] - (WORD16)pu1_est_lp[6]); - s3 += ABS((WORD16)pu1_src_lp[2] - (WORD16)pu1_est_lp[2])+ ABS((WORD16)pu1_src_lp[4] - (WORD16)pu1_est_lp[4]); + s2 += ABS((WORD16)pu1_src_lp[0] - (WORD16)pu1_est_lp[0]) + ABS((WORD16)pu1_src_lp[6] - (WORD16)pu1_est_lp[6]); + s3 += ABS((WORD16)pu1_src_lp[2] - (WORD16)pu1_est_lp[2]) + ABS((WORD16)pu1_src_lp[4] - (WORD16)pu1_est_lp[4]); pu1_src_lp += src_strd; pu1_est_lp += est_strd; - s1 += ABS((WORD16)pu1_src_lp[0] - (WORD16)pu1_est_lp[0])+ ABS((WORD16)pu1_src_lp[6] - (WORD16)pu1_est_lp[6]); - s4 += ABS((WORD16)pu1_src_lp[2] - (WORD16)pu1_est_lp[2])+ ABS((WORD16)pu1_src_lp[4] - (WORD16)pu1_est_lp[4]); - - sad_1 = s1+s2+s3+s4; - sad_2 = sad_1<<1; - - ls1 = sad_2 -(s2 + s3); - ls2 = sad_2 -(s1 + s4); - ls3 = sad_2 -(s3 + s4); - ls4 = sad_2 -(s3 - (s1<<1)); - ls5 = sad_2 -(s4 - (s2<<1)); - ls6 = sad_2 -(s1 + s2); - ls7 = sad_2 -(s2 - (s4<<1)); - ls8 = sad_2 -(s1 - (s3<<1)); - - if( - //thrsh[0] > sad_1 && Chroma Dc is checked later - thrsh[1] > ls1 && - thrsh[2] > sad_1 && - thrsh[3] > ls2 && - - thrsh[4] > ls3 && - thrsh[5] > ls4 && - thrsh[6] > ls3 && - thrsh[7] > ls5 && - - thrsh[8] > sad_1 && - thrsh[9] > ls1 && - thrsh[10]> sad_1 && - thrsh[11]> ls2 && - - thrsh[12]> ls6 && - thrsh[13]> ls7 && - thrsh[14]> ls6 && - thrsh[15]> ls8 - ) + s1 += ABS((WORD16)pu1_src_lp[0] - (WORD16)pu1_est_lp[0]) + ABS((WORD16)pu1_src_lp[6] - (WORD16)pu1_est_lp[6]); + s4 += ABS((WORD16)pu1_src_lp[2] - (WORD16)pu1_est_lp[2]) + ABS((WORD16)pu1_src_lp[4] - (WORD16)pu1_est_lp[4]); + + sad_1 = s1 + s2 + s3 + s4; + sad_2 = sad_1 << 1; + + ls1 = sad_2 - (s2 + s3); + ls2 = sad_2 - (s1 + s4); + ls3 = sad_2 - (s3 + s4); + ls4 = sad_2 - (s3 - (s1 << 1)); + ls5 = sad_2 - (s4 - (s2 << 1)); + ls6 = sad_2 - (s1 + s2); + ls7 = sad_2 - (s2 - (s4 << 1)); + ls8 = sad_2 - (s1 - (s3 << 1)); + + if (thrsh[1] > ls1 && thrsh[2] > sad_1 && thrsh[3] > ls2 && + thrsh[4] > ls3 && thrsh[5] > ls4 && thrsh[6] > ls3 && thrsh[7] > ls5 && + thrsh[8] > sad_1 && thrsh[9] > ls1 && thrsh[10] > sad_1 && thrsh[11] > ls2 && + thrsh[12] > ls6 && thrsh[13] > ls7 && thrsh[14] > ls6 && thrsh[15] > ls8) { /*set current sad to be zero*/ } @@ -1112,29 +1076,28 @@ void ime_compute_satqd_8x16_chroma(UWORD8 *pu1_src, pu1_src += (src_strd *4); pu1_est += (est_strd *4); } - if(sad < (thrsh[0]<<1))sad = 0; - else return ; + if (sad < (thrsh[0] << 1)) + sad = 0; + else + return; - pu1_src = pu1_src_plane+1; - pu1_est = pu1_est_plane+1; + pu1_src = pu1_src_plane + 1; + pu1_est = pu1_est_plane + 1; } return ; } - /** ****************************************************************************** * * @brief computes distortion (SAD and SAQTD) between 2 16x16 blocks * * @par Description -* This functions computes SAD between 2 16x16 blocks. -* It also checks if the SATDD(Sum of absolute transformed wuqntized differnce beteern the blocks -* If SAQTD is zero, it gives back zero -* Other wise sad is retrned -* There is no provison for early exit -* -* The transform done here is the transform for inter 16x16 blocks in H264 +* This functions computes SAD between2 16x8 chroma blocks(interleaved). It +* also checks if the SATQD, Sum of absolute transformed quantized difference +* between the blocks. If SAQTD is zero, it gives back zero Other wise sad is +* returned. There is no provison for early exit. The transform done here is the +* transform for intra 16x16 blocks in H264 * * @param[in] pu1_src * UWORD8 pointer to the source @@ -1159,80 +1122,76 @@ void ime_compute_satqd_8x16_chroma(UWORD8 *pu1_src, ****************************************************************************** */ void ime_compute_satqd_16x16_lumaintra(UWORD8 *pu1_src, - UWORD8 *pu1_est, - WORD32 src_strd, - WORD32 est_strd, - WORD32 max_sad, - UWORD16 *thrsh, - WORD32 *pi4_mb_distortion, - UWORD8 *sig_nz_sad) + UWORD8 *pu1_est, + WORD32 src_strd, + WORD32 est_strd, + WORD32 max_sad, + UWORD16 *thrsh, + WORD32 *pi4_mb_distortion, + UWORD8 *sig_nz_sad) { - UWORD32 i,j; - WORD16 s1[4],s2[4],s3[4],s4[4],sad[4]; - UWORD8 *pu1_src_lp,*pu1_est_lp; + UWORD32 i, j; + WORD16 s1[4], s2[4], s3[4], s4[4], sad[4]; + UWORD8 *pu1_src_lp, *pu1_est_lp; UWORD8 *sig_sad_dc; UWORD32 nz_sad_sig = 0; - UNUSED(max_sad); - *pi4_mb_distortion =0; + UNUSED(max_sad); + *pi4_mb_distortion = 0; sig_sad_dc = sig_nz_sad; sig_nz_sad++; - for(i=0;i<4;i++) + for (i = 0; i < 4; i++) { - for(j=0;j<4;j++) + for (j = 0; j < 4; j++) { - pu1_src_lp = pu1_src + 4*j; - pu1_est_lp = pu1_est + 4*j; + pu1_src_lp = pu1_src + 4 * j; + pu1_est_lp = pu1_est + 4 * j; - s1[j] = ABS((WORD16)pu1_src_lp[0] - (WORD16)pu1_est_lp[0])+ ABS((WORD16)pu1_src_lp[3] - (WORD16)pu1_est_lp[3]); - s4[j] = ABS((WORD16)pu1_src_lp[1] - (WORD16)pu1_est_lp[1])+ ABS((WORD16)pu1_src_lp[2] - (WORD16)pu1_est_lp[2]); + s1[j] = ABS((WORD16)pu1_src_lp[0] - (WORD16)pu1_est_lp[0]) + ABS((WORD16)pu1_src_lp[3] - (WORD16)pu1_est_lp[3]); + s4[j] = ABS((WORD16)pu1_src_lp[1] - (WORD16)pu1_est_lp[1]) + ABS((WORD16)pu1_src_lp[2] - (WORD16)pu1_est_lp[2]); pu1_src_lp += src_strd; pu1_est_lp += est_strd; - s2[j] = ABS((WORD16)pu1_src_lp[0] - (WORD16)pu1_est_lp[0])+ ABS((WORD16)pu1_src_lp[3] - (WORD16)pu1_est_lp[3]); - s3[j] = ABS((WORD16)pu1_src_lp[1] - (WORD16)pu1_est_lp[1])+ ABS((WORD16)pu1_src_lp[2] - (WORD16)pu1_est_lp[2]); + s2[j] = ABS((WORD16)pu1_src_lp[0] - (WORD16)pu1_est_lp[0]) + ABS((WORD16)pu1_src_lp[3] - (WORD16)pu1_est_lp[3]); + s3[j] = ABS((WORD16)pu1_src_lp[1] - (WORD16)pu1_est_lp[1]) + ABS((WORD16)pu1_src_lp[2] - (WORD16)pu1_est_lp[2]); pu1_src_lp += src_strd; pu1_est_lp += est_strd; - s2[j] += ABS((WORD16)pu1_src_lp[0] - (WORD16)pu1_est_lp[0])+ ABS((WORD16)pu1_src_lp[3] - (WORD16)pu1_est_lp[3]); - s3[j] += ABS((WORD16)pu1_src_lp[1] - (WORD16)pu1_est_lp[1])+ ABS((WORD16)pu1_src_lp[2] - (WORD16)pu1_est_lp[2]); + s2[j] += ABS((WORD16)pu1_src_lp[0] - (WORD16)pu1_est_lp[0]) + ABS((WORD16)pu1_src_lp[3] - (WORD16)pu1_est_lp[3]); + s3[j] += ABS((WORD16)pu1_src_lp[1] - (WORD16)pu1_est_lp[1]) + ABS((WORD16)pu1_src_lp[2] - (WORD16)pu1_est_lp[2]); pu1_src_lp += src_strd; pu1_est_lp += est_strd; - s1[j] += ABS((WORD16)pu1_src_lp[0] - (WORD16)pu1_est_lp[0])+ ABS((WORD16)pu1_src_lp[3] - (WORD16)pu1_est_lp[3]); - s4[j] += ABS((WORD16)pu1_src_lp[1] - (WORD16)pu1_est_lp[1])+ ABS((WORD16)pu1_src_lp[2] - (WORD16)pu1_est_lp[2]); + s1[j] += ABS((WORD16)pu1_src_lp[0] - (WORD16)pu1_est_lp[0]) + ABS((WORD16)pu1_src_lp[3] - (WORD16)pu1_est_lp[3]); + s4[j] += ABS((WORD16)pu1_src_lp[1] - (WORD16)pu1_est_lp[1]) + ABS((WORD16)pu1_src_lp[2] - (WORD16)pu1_est_lp[2]); - sad[j] = ((s1[j]+s2[j]+s3[j]+s4[j])<<1); + sad[j] = ((s1[j] + s2[j] + s3[j] + s4[j]) << 1); } - for(j=0;j<4;j++) + for (j = 0; j < 4; j++) { - if( - //thrsh[0] > (sad[j] >> 1) &&Dc goes in the other part - thrsh[1] > (sad[j] -(s2[j] + s3[j])) && - thrsh[2] > (sad[j]>>1) && - thrsh[3] > (sad[j] -(s1[j] + s4[j])) && - - thrsh[4] > (sad[j] -(s3[j] + s4[j])) && - thrsh[5] > (sad[j] -(s3[j] - (s1[j]<<1))) && - thrsh[6] > (sad[j] -(s3[j] + s4[j])) && - thrsh[7] > (sad[j] -(s4[j] - (s2[j]<<1))) && - - thrsh[8] > (sad[j]>>1) && - thrsh[9] > (sad[j] -(s2[j] + s3[j])) && - thrsh[10]> (sad[j]>>1) && - thrsh[11]> (sad[j] -(s1[j] + s4[j])) && - - thrsh[12]> (sad[j] -(s1[j] + s2[j])) && - thrsh[13]> (sad[j] -(s2[j] - (s4[j]<<1))) && - thrsh[14]> (sad[j] -(s1[j] + s2[j])) && - thrsh[15]> (sad[j] -(s1[j] - (s3[j]<<1))) - ) + if (thrsh[1] > (sad[j] - (s2[j] + s3[j])) && thrsh[2] > (sad[j] >> 1) + && thrsh[3] > (sad[j] - (s1[j] + s4[j])) && + + thrsh[4] > (sad[j] - (s3[j] + s4[j])) + && thrsh[5] > (sad[j] - (s3[j] - (s1[j] << 1))) + && thrsh[6] > (sad[j] - (s3[j] + s4[j])) + && thrsh[7] > (sad[j] - (s4[j] - (s2[j] << 1))) && + + thrsh[8] > (sad[j] >> 1) + && thrsh[9] > (sad[j] - (s2[j] + s3[j])) + && thrsh[10] > (sad[j] >> 1) + && thrsh[11] > (sad[j] - (s1[j] + s4[j])) && + + thrsh[12] > (sad[j] - (s1[j] + s2[j])) + && thrsh[13] > (sad[j] - (s2[j] - (s4[j] << 1))) + && thrsh[14] > (sad[j] - (s1[j] + s2[j])) + && thrsh[15] > (sad[j] - (s1[j] - (s3[j] << 1)))) { //sad[j] = 0; /*set current sad to be zero*/ sig_nz_sad[j] = 0;/*Signal that the sad is zero*/ @@ -1243,21 +1202,25 @@ void ime_compute_satqd_16x16_lumaintra(UWORD8 *pu1_src, nz_sad_sig = 1; } - (*pi4_mb_distortion) += (sad[j]>>1); - //if((*pi4_mb_distortion) >= max_sad)return; /*return or some thing*/ + (*pi4_mb_distortion) += (sad[j] >> 1); + //if ((*pi4_mb_distortion) >= max_sad)return; /*return or some thing*/ } sig_nz_sad += 4; - pu1_src += (src_strd *4); - pu1_est += (est_strd *4); + pu1_src += (src_strd * 4); + pu1_est += (est_strd * 4); } - if((*pi4_mb_distortion) < thrsh[0]<<2) + if ((*pi4_mb_distortion) < thrsh[0] << 2) { *sig_sad_dc = 0; - if(nz_sad_sig == 0)(*pi4_mb_distortion) = 0; + if (nz_sad_sig == 0) + (*pi4_mb_distortion) = 0; + } + else + { + *sig_sad_dc = 1; } - else *sig_sad_dc = 1; } diff --git a/encoder/ime_distortion_metrics.h b/encoder/ime_distortion_metrics.h index 5056ba09..d8675dc3 100644 --- a/encoder/ime_distortion_metrics.h +++ b/encoder/ime_distortion_metrics.h @@ -20,7 +20,8 @@ /** ****************************************************************************** -* @file ih264e_distortion_metrics.h +* @file +* ime_distortion_metrics.h * * @brief * This file contains declarations of routines that compute distortion @@ -35,8 +36,8 @@ ******************************************************************************* */ -#ifndef IME_DISTORTION_METRICS_H_ -#define IME_DISTORTION_METRICS_H_ +#ifndef _IME_DISTORTION_METRICS_H_ +#define _IME_DISTORTION_METRICS_H_ /*****************************************************************************/ @@ -88,33 +89,34 @@ typedef void ime_compute_sad_stat(UWORD8 *pu1_src, UWORD32 *pu4_is_zero); typedef void ime_compute_satqd_16x16_lumainter_ft(UWORD8 *pu1_src, - UWORD8 *pu1_est, - WORD32 src_strd, - WORD32 est_strd, - UWORD16 *pu2_thrsh, - WORD32 *pi4_mb_distortion, - UWORD32 *pu4_is_zero); + UWORD8 *pu1_est, + WORD32 src_strd, + WORD32 est_strd, + UWORD16 *pu2_thrsh, + WORD32 *pi4_mb_distortion, + UWORD32 *pu4_is_zero); typedef void ime_compute_satqd_8x16_chroma_ft(UWORD8 *pu1_src, - UWORD8 *pu1_est, - WORD32 src_strd, - WORD32 est_strd, - WORD32 i4_max_sad, - UWORD16 *thrsh); + UWORD8 *pu1_est, + WORD32 src_strd, + WORD32 est_strd, + WORD32 i4_max_sad, + UWORD16 *thrsh); typedef void ime_compute_satqd_16x16_lumaintra_ft(UWORD8 *pu1_src, - UWORD8 *pu1_est, - WORD32 src_strd, - WORD32 est_strd, - WORD32 i4_max_sad, - UWORD16 *thrsh, - WORD32 *pi4_mb_distortion, - UWORD8 *sig_nz_sad); + UWORD8 *pu1_est, + WORD32 src_strd, + WORD32 est_strd, + WORD32 i4_max_sad, + UWORD16 *thrsh, + WORD32 *pi4_mb_distortion, + UWORD8 *sig_nz_sad); /*****************************************************************************/ -/* Extern Function Declarations */ +/* Function Declarations */ /*****************************************************************************/ +/* C declarations */ ime_compute_sad_ft ime_compute_sad_16x16; ime_compute_sad_ft ime_compute_sad_16x16_fast; ime_compute_sad_ft ime_compute_sad_16x8; @@ -130,8 +132,7 @@ ime_compute_satqd_16x16_lumainter_ft ime_compute_satqd_16x16_lumainter; ime_compute_satqd_8x16_chroma_ft ime_compute_satqd_8x16_chroma; ime_compute_satqd_16x16_lumaintra_ft ime_compute_satqd_16x16_lumaintra; - -/*SSE4.2 Declarations*/ +/* SSE4.2 Declarations */ ime_compute_sad_ft ime_compute_sad_16x16_sse42; ime_compute_sad_ft ime_compute_sad_16x16_fast_sse42; ime_compute_sad_ft ime_compute_sad_16x8_sse42; @@ -140,7 +141,7 @@ ime_sub_pel_compute_sad_16x16_ft ime_sub_pel_compute_sad_16x16_sse42; ime_compute_sad4_diamond ime_calculate_sad4_prog_sse42; ime_compute_satqd_16x16_lumainter_ft ime_compute_satqd_16x16_lumainter_sse42; -/* assembly */ +/* A9 Declarations */ ime_compute_sad_ft ime_compute_sad_16x16_a9q; ime_compute_sad_ft ime_compute_sad_16x16_fast_a9q; ime_compute_sad_ft ime_compute_sad_16x8_a9q; @@ -152,8 +153,7 @@ ime_sub_pel_compute_sad_16x16_ft ime_sub_pel_compute_sad_16x16_a9q; ime_compute_sad_stat ime_compute_16x16_sad_stat_a9; ime_compute_satqd_16x16_lumainter_ft ime_compute_satqd_16x16_lumainter_a9q; - -/* assembly - AV8 declarations */ +/* AV8 declarations */ ime_compute_sad_ft ime_compute_sad_16x16_av8; ime_compute_sad_ft ime_compute_sad_16x16_fast_av8; ime_compute_sad_ft ime_compute_sad_16x8_av8; @@ -165,6 +165,6 @@ ime_sub_pel_compute_sad_16x16_ft ime_sub_pel_compute_sad_16x16_av8; ime_compute_sad_stat ime_compute_16x16_sad_stat_av8; ime_compute_satqd_16x16_lumainter_ft ime_compute_satqd_16x16_lumainter_av8; -#endif /* IME_DISTORTION_METRICS_H_ */ +#endif /* _IME_DISTORTION_METRICS_H_ */ diff --git a/encoder/ime_macros.h b/encoder/ime_macros.h index a7b8c658..d00df370 100644 --- a/encoder/ime_macros.h +++ b/encoder/ime_macros.h @@ -20,11 +20,10 @@ /** ******************************************************************************* * @file -* ihevc_typedefs.h +* ime_macros.h * * @brief -* Type definitions used in the code -* +* definitions used in the code * * @remarks * None @@ -34,7 +33,7 @@ #ifndef _IME_MACROS_H_ #define _IME_MACROS_H_ -#define ABS(x) ((x) < 0 ? (-(x)) : (x)) +#define ABS(x) ((x) < 0 ? (-(x)) : (x)) #define MAX(a,b) ((a > b)?(a):(b)) #define MIN(a,b) ((a < b)?(a):(b)) diff --git a/encoder/ime_statistics.h b/encoder/ime_statistics.h index eeacaf21..45b53270 100644 --- a/encoder/ime_statistics.h +++ b/encoder/ime_statistics.h @@ -20,11 +20,10 @@ /** ******************************************************************************* * @file -* ihevc_typedefs.h +* ime_statistics.h * * @brief -* Type definitions used in the code -* +* This file presents some useful statistics associated with me * * @remarks * None @@ -33,10 +32,10 @@ */ #ifndef _IME_STATISTICS_H_ #define _IME_STATISTICS_H_ + #define DEBUG_HISTOGRAM_ENABLE 0 #define SAD_EXIT_STATS 0 - #if SAD_EXIT_STATS /** diff --git a/encoder/ime_structs.h b/encoder/ime_structs.h index 9baacb3c..6cde09e1 100644 --- a/encoder/ime_structs.h +++ b/encoder/ime_structs.h @@ -18,24 +18,21 @@ * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore */ /** - ******************************************************************************* - * @file - * ih264e_me.h - * - * @brief - * - * - * @author - * Ittiam - * - * @par List of Functions: - * - - * - * @remarks - * None - * - ******************************************************************************* - */ +******************************************************************************* +* @file +* ime_structs.h +* +* @brief +* Structure definitions used in the code +* +* @author +* Ittiam +* +* @remarks +* None +* +******************************************************************************* +*/ #ifndef _IME_STRUCTS_H_ #define _IME_STRUCTS_H_ @@ -97,7 +94,7 @@ typedef struct */ UWORD32 u4_exit; - /* + /** * Buffer corresponding to best half pel cost */ UWORD8 *pu1_best_hpel_buf; @@ -220,12 +217,12 @@ typedef struct /* * Minimum distortion to search for - * */ + */ WORD32 i4_min_sad; - /* + /** * Signal that minimum sad has been reached in ME - * */ + */ UWORD32 u4_min_sad_reached; /** @@ -243,14 +240,24 @@ typedef struct */ UWORD32 u4_me_speed_preset; + /** + * Is left mb intra + */ UWORD32 u4_left_is_intra; + /** + * Is left mb skip + */ UWORD32 u4_left_is_skip; - /* skip_type can be PREDL0, PREDL1 or BIPRED */ + /** + * skip_type can be PREDL0, PREDL1 or BIPRED + */ WORD32 i4_skip_type; - /* Biasing given for skip prediction */ + /** + * Biasing given for skip prediction + */ WORD32 i4_skip_bias[2]; /** @@ -258,7 +265,8 @@ typedef struct * We need 1(L0)+1(L1)+1(bi) */ mb_part_ctxt as_mb_part[MAX_NUM_REFLIST + 1]; - /* + + /** * Threshold to compare the sad with */ UWORD16 *pu2_sad_thrsh; @@ -273,7 +281,7 @@ typedef struct ime_compute_sad2_diamond *pf_ime_compute_sad2_diamond; ime_sub_pel_compute_sad_16x16_ft *pf_ime_sub_pel_compute_sad_16x16; - /* + /** * Function poitners for SATQD */ ime_compute_sad_stat *pf_ime_compute_sad_stat_luma_16x16; @@ -283,14 +291,14 @@ typedef struct */ UWORD8 u1_mb_qp; - /* + /** * Buffers for holding subpel and bipred temp buffers */ UWORD8 *apu1_subpel_buffs[SUBPEL_BUFF_CNT]; WORD32 u4_subpel_buf_strd; - /* + /** * Buffers to store the best halfpel plane* */ UWORD8 *pu1_hpel_buf; @@ -298,5 +306,5 @@ typedef struct } me_ctxt_t; -#endif // _IME_STRUCTS_H_ +#endif /* _IME_STRUCTS_H_ */ diff --git a/encoder/ime_typedefs.h b/encoder/ime_typedefs.h index d36632de..a0033db9 100644 --- a/encoder/ime_typedefs.h +++ b/encoder/ime_typedefs.h @@ -20,17 +20,20 @@ /** ******************************************************************************* * @file -* ihevc_typedefs.h +* ime_typedefs.h * * @brief -* Type definitions used in the code +* Type definitions used in the software * +* @author +* Ittiam * * @remarks * None * ******************************************************************************* */ + #ifndef _IME_TYPEDEFS_H_ #define _IME_TYPEDEFS_H_ @@ -47,4 +50,4 @@ typedef long WORD64; typedef char CHAR; -#endif /*_IME_TYPEDEFS_H_*/ +#endif /* _IME_TYPEDEFS_H_ */ diff --git a/encoder/irc_cbr_buffer_control.c b/encoder/irc_cbr_buffer_control.c index 9febbc85..5280e9c5 100644 --- a/encoder/irc_cbr_buffer_control.c +++ b/encoder/irc_cbr_buffer_control.c @@ -370,8 +370,7 @@ void irc_update_cbr_buffer(cbr_buffer_t *ps_cbr_buffer, /*SS - Fix for lack of stuffing*/ if(ps_cbr_buffer->i4_ebf > ps_cbr_buffer->i4_buffer_size) { - trace_printf( - (const WORD8*)"Error: Should not be coming here with stuffing\n"); + TRACE_PRINTF((const WORD8*)"Error: Should not be coming here with stuffing\n"); ps_cbr_buffer->i4_ebf = ps_cbr_buffer->i4_buffer_size; } } diff --git a/encoder/irc_datatypes.h b/encoder/irc_datatypes.h index 8e4685ac..1fc8b107 100644 --- a/encoder/irc_datatypes.h +++ b/encoder/irc_datatypes.h @@ -17,25 +17,9 @@ ***************************************************************************** * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore */ -/** -******************************************************************************* -* @file -* ih264_typedefs.h -* -* @brief -* Type definitions used in the code -* -* @author -* Ittiam -* -* @remarks -* None -* -******************************************************************************* -*/ -#ifndef _IH264_TYPEDEFS_H_ -#define _IH264_TYPEDEFS_H_ +#ifndef _RC_DATATYPES_H_ +#define _RC_DATATYPES_H_ /*****************************************************************************/ @@ -61,4 +45,4 @@ typedef int WORD32; typedef char CHAR; typedef double DOUBLE; -#endif /* _IH264_TYPEDEFS_H_ */ +#endif // _RC_DATATYPES_H_ diff --git a/encoder/irc_mem_req_and_acq.h b/encoder/irc_mem_req_and_acq.h index a2946a75..37f30fc3 100644 --- a/encoder/irc_mem_req_and_acq.h +++ b/encoder/irc_mem_req_and_acq.h @@ -21,28 +21,23 @@ /** ****************************************************************************** * @file -* ih264e_rc_mem_interface.h +* irc_mem_req_and_acq.h * * @brief -* This file contains function declaration and structures for rate control +* This file contains interface definitions for allocating rate control * memtabs * * @author * ittiam * * @remarks -* The rate control library is a global library across various codecs. It -* anticipates certain structures definitions. Those definitions are to be -* imported from global workspace. Instead of that, the structures needed for -* rc library are copied in to this file and exported to rc library. If the -* structures / enums / ... in the global workspace change, this file also needs -* to be modified accordingly. +* none * -****************************************************************************** +******************************************************************************* */ -#ifndef IH264E_RC_MEM_INTERFACE_H_ -#define IH264E_RC_MEM_INTERFACE_H_ +#ifndef _RC_MEM_REQ_AND_ACQ_H_ +#define _RC_MEM_REQ_AND_ACQ_H_ /*****************************************************************************/ /* Function Macros */ @@ -90,13 +85,10 @@ typedef enum FILL_BASE =3 }ITT_FUNC_TYPE_E; - /*****************************************************************************/ /* Structures */ /*****************************************************************************/ -/*NOTE : This should be an exact replica of IALG_MemRec, any change in IALG_MemRec - must be replicated here*/ typedef struct { /* Size in bytes */ @@ -115,65 +107,20 @@ typedef struct void *pv_base; } itt_memtab_t; - /*****************************************************************************/ -/* Extern Function Declarations */ +/* Function Declarations */ /*****************************************************************************/ -/** -****************************************************************************** -* -* @brief This function fills memory record attributes -* -* @par Description -* This function fills memory record attributes -* -* @param[in] ps_mem_tab -* pointer to mem records -* -* @param[in] u4_size -* size of the record -* -* @param[in] i4_alignment -* memory alignment size -* -* @param[in] e_usage -* usage -* -* @param[in] e_mem_region -* mem region -* -* @return void -* -****************************************************************************** -*/ -void fill_memtab(itt_memtab_t *ps_mem_tab, WORD32 u4_size, WORD32 i4_alignment, - ITT_MEM_USAGE_TYPE_E e_usage, ITT_MEM_REGION_E e_mem_region); +void fill_memtab(itt_memtab_t *ps_mem_tab, + WORD32 u4_size, + WORD32 i4_alignment, + ITT_MEM_USAGE_TYPE_E e_usage, + ITT_MEM_REGION_E e_mem_region); -/** -****************************************************************************** -* -* @brief This function fills memory record attributes -* -* @par Description -* This function fills memory record attributes -* -* @param[in] ps_mem_tab -* pointer to mem records -* -* @param[in] ptr_to_be_filled -* handle to the memory record storage space -* -* @param[in] e_func_type -* enum that dictates fill memory records or use memory records -* -* @return void -* -****************************************************************************** -*/ -WORD32 use_or_fill_base(itt_memtab_t *ps_mem_tab, void **ptr_to_be_filled, +WORD32 use_or_fill_base(itt_memtab_t *ps_mem_tab, + void **ptr_to_be_filled, ITT_FUNC_TYPE_E e_func_type); -#endif // IH264E_RC_MEM_INTERFACE_H_ +#endif // _RC_MEM_REQ_AND_ACQ_H_ diff --git a/encoder/irc_rate_control_api.c b/encoder/irc_rate_control_api.c index b641aa14..ef88117d 100644 --- a/encoder/irc_rate_control_api.c +++ b/encoder/irc_rate_control_api.c @@ -54,6 +54,73 @@ #define GET_LO_DEV_QP(Qprev) (( ((WORD32) Qprev)*LO_DEV_FCTR + (1<<(DEV_Q-1)))>>DEV_Q) #define CLIP_QP(Qc, hi_d, lo_d) (((Qc) < (lo_d))?((lo_d)):(((Qc) > (hi_d))?(hi_d):(Qc))) +/***************************************************************************** + Function Name : fill_memtab + Description : fill memtab + Inputs : + ps_mem_tab - Memtab pointer + u4_size - Size of the memtab + i4_alignment - alignment of the memtab + e_usage - usage + e_mem_region - region + *****************************************************************************/ +void fill_memtab(itt_memtab_t *ps_mem_tab, + WORD32 u4_size, + WORD32 i4_alignment, + ITT_MEM_USAGE_TYPE_E e_usage, + ITT_MEM_REGION_E e_mem_region) +{ + /* Make the size next multiple of alignment */ + WORD32 i4_aligned_size = (((u4_size) + (i4_alignment-1)) & (~(i4_alignment-1))); + + /* Fill the memtab */ + ps_mem_tab->u4_size = i4_aligned_size; + ps_mem_tab->i4_alignment = i4_alignment; + ps_mem_tab->e_usage = e_usage; + ps_mem_tab->e_mem_region = e_mem_region; +} + +/***************************************************************************** + Function Name : use_or_fill_base + Description : Get or Set base pointer for the memtab + Inputs : + ps_mem_tab - Memtab pointer + ptr_to_be_filled - Pointer to base pointer + e_func_type - Get/Set flag + *****************************************************************************/ +WORD32 use_or_fill_base(itt_memtab_t *ps_mem_tab, + void **ptr_to_be_filled, + ITT_FUNC_TYPE_E e_func_type) +{ + /* Fill base for freeing the allocated memory */ + if (e_func_type == FILL_BASE) + { + if (ptr_to_be_filled[0] != 0) + { + ps_mem_tab->pv_base = ptr_to_be_filled[0]; + return (0); + } + else + { + return (-1); + } + } + /* obtain the allocated memory from base pointer */ + if (e_func_type == USE_BASE) + { + if (ps_mem_tab->pv_base != 0) + { + ptr_to_be_filled[0] = ps_mem_tab->pv_base; + return (0); + } + else + { + return (-1); + } + } + return (0); +} + /*****************************************************************************/ /* Restricts the quantization parameter variation within delta */ /*****************************************************************************/ @@ -169,7 +236,7 @@ void irc_initialise_rate_control(rate_control_api_t *ps_rate_control_api, ps_rate_control_api->e_rc_type = e_rate_control_type; ps_rate_control_api->u1_is_mb_level_rc_on = u1_is_mb_level_rc_on; - trace_printf((const WORD8*)"RC type = %d\n", e_rate_control_type); + TRACE_PRINTF((const WORD8*)"RC type = %d\n", e_rate_control_type); /* Set the avg_bitrate_changed flag for each pic_type to 0 */ for(i = 0; i < MAX_PIC_TYPE; i++) @@ -204,7 +271,7 @@ void irc_initialise_rate_control(rate_control_api_t *ps_rate_control_api, VBR_STORAGE_DVD_COMP */ if(pu4_peak_bit_rate[0] != pu4_peak_bit_rate[1]) { - trace_printf((const WORD8*)"For VBR_STORAGE and VBR_STORAGE_DVD_COMP the peak bit rates should be same\n"); + TRACE_PRINTF((const WORD8*)"For VBR_STORAGE and VBR_STORAGE_DVD_COMP the peak bit rates should be same\n"); } irc_init_vbr_vbv(ps_rate_control_api->ps_vbr_storage_vbv, (WORD32)pu4_peak_bit_rate[0], @@ -365,7 +432,7 @@ UWORD8 irc_get_frame_level_qp(rate_control_api_t *ps_rate_control_api, && (ps_rate_control_api->e_rc_type != CONST_QP) && (ps_rate_control_api->e_rc_type != VBR_STREAMING)) { - trace_printf((const WORD8*)(const WORD8*)" Only VBR,NLDRC and CONST QP supported for now \n"); + TRACE_PRINTF((const WORD8*)(const WORD8*)" Only VBR,NLDRC and CONST QP supported for now \n"); return (0); } @@ -429,7 +496,7 @@ UWORD8 irc_get_frame_level_qp(rate_control_api_t *ps_rate_control_api, /* Total estimated bits */ i4_cur_est_bits = i4_cur_est_header_bits + i4_cur_est_texture_bits; - trace_printf((const WORD8*)"ft %d, etb = %d, eb %d, ", e_pic_type, + TRACE_PRINTF((const WORD8*)"ft %d, etb = %d, eb %d, ", e_pic_type, i4_cur_est_texture_bits, i4_cur_est_bits); /* Threshold the estimated bits based on the buffer fullness*/ @@ -498,7 +565,7 @@ UWORD8 irc_get_frame_level_qp(rate_control_api_t *ps_rate_control_api, - i4_cur_est_header_bits; } - trace_printf((const WORD8*)"emtb = %d, ", i4_cur_est_texture_bits); + TRACE_PRINTF((const WORD8*)"emtb = %d, ", i4_cur_est_texture_bits); /* * If the estimated texture bits go to values less than zero @@ -518,7 +585,7 @@ UWORD8 irc_get_frame_level_qp(rate_control_api_t *ps_rate_control_api, { i4_cur_est_texture_bits = (i4_ud_max_bits - i4_cur_est_header_bits); - trace_printf((const WORD8*)"udcb = %d, ", + TRACE_PRINTF((const WORD8*)"udcb = %d, ", i4_ud_max_bits - i4_cur_est_header_bits); } @@ -551,7 +618,7 @@ UWORD8 irc_get_frame_level_qp(rate_control_api_t *ps_rate_control_api, << 1) + 1]; } - trace_printf((const WORD8*)"ehb %d, etb %d, fqp %d, es %d, eb %d, ", + TRACE_PRINTF((const WORD8*)"ehb %d, etb %d, fqp %d, es %d, eb %d, ", i4_cur_est_header_bits, i4_cur_est_texture_bits, u1_frame_qp, u4_estimated_sad, i4_cur_est_bits); @@ -664,7 +731,7 @@ UWORD8 irc_get_frame_level_qp(rate_control_api_t *ps_rate_control_api, u1_frame_qp = ps_rate_control_api->au1_init_qp[e_pic_type]; } - trace_printf((const WORD8*)"fqp %d\n", u1_frame_qp); + TRACE_PRINTF((const WORD8*)"fqp %d\n", u1_frame_qp); return (u1_frame_qp); } @@ -690,7 +757,7 @@ vbv_buf_status_e irc_get_buffer_status(rate_control_api_t *ps_rate_control_api, i4_total_frame_bits, pi4_num_bits_to_prevent_vbv_underflow); - trace_printf((const WORD8*)"e_buf_status = %d\n", e_buf_status); + TRACE_PRINTF((const WORD8*)"e_buf_status = %d\n", e_buf_status); } else if(ps_rate_control_api->e_rc_type == VBR_STORAGE) { @@ -758,6 +825,7 @@ void irc_update_frame_level_info(rate_control_api_t *ps_rate_control_api, { u1_is_scd = 0; } + /* For frames that contain plane areas that differ from reference frames, encoder * might generate more INTRA MBs because of lower SAD compared with INTER MBs. * Such cases should not be treated as scene change. @@ -767,8 +835,7 @@ void irc_update_frame_level_info(rate_control_api_t *ps_rate_control_api, { u1_is_scd = 0; } - - trace_printf((const WORD8*)"i4_total_frame_bits %d\n", i4_total_frame_bits); + TRACE_PRINTF((const WORD8*)"i4_total_frame_bits %d\n", i4_total_frame_bits); if(!i4_is_it_a_skip && !i4_is_pic_handling_done) { @@ -998,7 +1065,7 @@ void irc_update_frame_level_info(rate_control_api_t *ps_rate_control_api, */ ps_rate_control_api->au1_prev_frm_qp[I_PIC] = (UWORD8)i4_avg_qp; - trace_printf((const WORD8*)"SCD DETECTED\n"); + TRACE_PRINTF((const WORD8*)"SCD DETECTED\n"); } else { @@ -1068,7 +1135,7 @@ void irc_update_frame_level_info(rate_control_api_t *ps_rate_control_api, ps_rate_control_api->prev_ref_pic_type = e_pic_type; } - trace_printf((const WORD8*)"ft %d,hb %d,tb %d,qp %d,fs %d\n", e_pic_type, + TRACE_PRINTF((const WORD8*)"ft %d,hb %d,tb %d,qp %d,fs %d\n", e_pic_type, i4_model_updation_hdr_bits, i4_tot_texture_bits, i4_avg_qp, u4_frame_sad); diff --git a/encoder/irc_rate_control_api_structs.h b/encoder/irc_rate_control_api_structs.h index 3248c74a..562ccf33 100644 --- a/encoder/irc_rate_control_api_structs.h +++ b/encoder/irc_rate_control_api_structs.h @@ -16,7 +16,7 @@ * ***************************************************************************** * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore - */ +*/ #ifndef _RATE_CONTROL_API_STRUCTS_H_ #define _RATE_CONTROL_API_STRUCTS_H_ diff --git a/encoder/irc_rd_model.c b/encoder/irc_rd_model.c index 62c78115..1df42c7d 100644 --- a/encoder/irc_rd_model.c +++ b/encoder/irc_rd_model.c @@ -126,11 +126,9 @@ static UWORD8 find_model_coeffs(UWORD32 *pi4_res_bits, float x0, y0; float model_coeff_a = 0.0, model_coeff_b = 0.0, model_coeff_c = 0.0; -#if !(ENABLE_QUAD_RC_MODEL||ENABLE_LIN_MODEL_WITH_INTERCEPT) UNUSED(pu1_num_skips); UNUSED(pmc_model_coeff); UNUSED(pmc_model_coeff_lin); -#endif for(i = 0; i < u1_num_frms; i++) { diff --git a/encoder/irc_trace_support.h b/encoder/irc_trace_support.h index c35bd4fc..1845c90d 100644 --- a/encoder/irc_trace_support.h +++ b/encoder/irc_trace_support.h @@ -18,44 +18,17 @@ * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore */ -/** -******************************************************************************* -* @file -* ih264e_trace_support.h -* -* @brief -* This file contains extern declarations of routines that could be helpful -* for debugging purposes. -* -* @author -* Harish -* -* @remarks -* None -* -******************************************************************************* -*/ - -#ifndef TRACE_SUPPORT_H_ -#define TRACE_SUPPORT_H_ - -/*****************************************************************************/ -/* Structures */ -/*****************************************************************************/ - -typedef struct -{ - WORD8 * pu1_buf; - WORD32 i4_offset; - WORD32 i4_max_size; -}trace_support_t; - -/*****************************************************************************/ -/* Extern function declarations */ -/*****************************************************************************/ - -void init_trace_support(WORD8 *pu1_buf, WORD32 i4_size); - -int trace_printf(const WORD8 *format, ...); - -#endif // TRACE_SUPPORT_H_ +#ifndef _RC_TRACE_SUPPORT_H_ +#define _RC_TRACE_SUPPORT_H_ + +#if DEBUG_RC +#define TRACE_PRINTF(...) \ +{ \ + printf("\n[RC DBG] %s/%d:: ", __FUNCTION__, __LINE__); \ + printf(__VA_ARGS__); \ +} +#else +#define TRACE_PRINTF(...) {} +#endif + +#endif // _RC_TRACE_SUPPORT_H_ diff --git a/encoder/irc_vbr_str_prms.c b/encoder/irc_vbr_str_prms.c index 29055c26..4d5bfe0c 100644 --- a/encoder/irc_vbr_str_prms.c +++ b/encoder/irc_vbr_str_prms.c @@ -17,6 +17,7 @@ ***************************************************************************** * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore */ + /*****************************************************************************/ /* Includes */ /*****************************************************************************/ diff --git a/encoder/iv2.h b/encoder/iv2.h index 538bb1e8..ed17e815 100644 --- a/encoder/iv2.h +++ b/encoder/iv2.h @@ -23,17 +23,15 @@ * iv2.h * * @brief -* This file contains all the necessary structure and enumeration -* definitions needed for the Application Program Interface(API) of the -* Ittiam Video codecs This is version 2 of Ittiam Video API +* This file contains all the necessary structure and enumeration definitions +* needed for the Application Program Interface(API) of the Ittiam Video codecs. +* This is version 2 of Ittiam Video API * * @author -* Ittiam -* -* @par List of Functions: +* ittiam * * @remarks -* None +* none * ******************************************************************************* */ @@ -77,7 +75,6 @@ typedef enum { }IV_MEM_TYPE_T; /* The color formats used in video/image codecs */ - typedef enum { IV_CHROMA_NA = 0x7FFFFFFF, IV_YUV_420P = 0x0, @@ -267,6 +264,7 @@ typedef struct UWORD32 u4_bufsize; }iv_bits_buf_t; + /*****************************************************************************/ /* Get Number of Memory Records */ /*****************************************************************************/ diff --git a/encoder/ive2.h b/encoder/ive2.h index 2ba0ec88..a67ef902 100644 --- a/encoder/ive2.h +++ b/encoder/ive2.h @@ -23,17 +23,15 @@ * ive2.h * * @brief -* This file contains all the necessary structure and enumeration -* definitions needed for the Application Program Interface(API) of the -* Ittiam Video Encoders This is version 2 +* This file contains all the necessary structure and enumeration definitions +* needed for the Application Program Interface(API) of the Ittiam Video +* Encoders. This is version 2 * * @author -* Ittiam -* -* @par List of Functions: +* ittiam * * @remarks -* None +* none * ******************************************************************************* */ diff --git a/encoder/svc/irc_svc_rate_control_api.c b/encoder/svc/irc_svc_rate_control_api.c index a2e9453d..024713b9 100644 --- a/encoder/svc/irc_svc_rate_control_api.c +++ b/encoder/svc/irc_svc_rate_control_api.c @@ -71,7 +71,7 @@ UWORD8 irc_get_frame_level_init_qp(rate_control_handle *ps_rate_control_api, rc_ if((e_rc_type != VBR_STORAGE) && (e_rc_type != VBR_STORAGE_DVD_COMP) && (e_rc_type != CBR_NLDRC) && (e_rc_type != CONST_QP) && (e_rc_type != VBR_STREAMING)) { - trace_printf( + TRACE_PRINTF( (const WORD8 *) (const WORD8 *) " Only VBR,NLDRC and CONST QP supported for now \n"); return (0); } diff --git a/encoder/svc/isvce_api.c b/encoder/svc/isvce_api.c index 89009952..4b12925a 100644 --- a/encoder/svc/isvce_api.c +++ b/encoder/svc/isvce_api.c @@ -114,6 +114,7 @@ #include "ime_structs.h" /* Dependencies of 'ih264e_utils.h' */ #include "ih264e_defs.h" +#include "irc_mem_req_and_acq.h" #include "ih264e_rc_mem_interface.h" #include "ih264e_structs.h" #include "ih264e_utils.h" diff --git a/encoder/svc/isvce_rate_control.c b/encoder/svc/isvce_rate_control.c index 1562f086..cc3c41f6 100644 --- a/encoder/svc/isvce_rate_control.c +++ b/encoder/svc/isvce_rate_control.c @@ -49,7 +49,6 @@ /*****************************************************************************/ #include "ih264_typedefs.h" -#include "irc_datatypes.h" #include "iv2.h" #include "ive2.h" #include "isvce.h" diff --git a/encoder/svc/isvce_rc_mem_interface.c b/encoder/svc/isvce_rc_mem_interface.c index 74318544..28bea364 100644 --- a/encoder/svc/isvce_rc_mem_interface.c +++ b/encoder/svc/isvce_rc_mem_interface.c @@ -83,6 +83,7 @@ #include "ih264e_error.h" #include "isvce_defs.h" #include "ih264e_bitstream.h" +#include "irc_mem_req_and_acq.h" #include "irc_cntrl_param.h" #include "irc_frame_info_collector.h" #include "isvce_rate_control.h" diff --git a/encoder/svc/isvce_rc_mem_interface.h b/encoder/svc/isvce_rc_mem_interface.h index ff7a475b..a2cf2fc8 100644 --- a/encoder/svc/isvce_rc_mem_interface.h +++ b/encoder/svc/isvce_rc_mem_interface.h @@ -43,7 +43,7 @@ #ifndef _ISVCE_RC_MEM_INTERFACE_H_ #define _ISVCE_RC_MEM_INTERFACE_H_ -#include "ih264e_rc_mem_interface.h" +#include "irc_mem_req_and_acq.h" /** *************************************************************************** diff --git a/encoder/svc/isvce_utils.c b/encoder/svc/isvce_utils.c index 5f4220d8..23fe5697 100644 --- a/encoder/svc/isvce_utils.c +++ b/encoder/svc/isvce_utils.c @@ -101,6 +101,7 @@ #include "ih264e_defs.h" #include "ih264e_structs.h" /* Dependencies of 'ih264e_utils.h' */ +#include "irc_mem_req_and_acq.h" #include "ih264e_rc_mem_interface.h" #include "ih264e_time_stamp.h" #include "ih264e_utils.h" diff --git a/encoder/x86/ih264e_function_selector.c b/encoder/x86/ih264e_function_selector.c index b0acb19e..54dc22f9 100644 --- a/encoder/x86/ih264e_function_selector.c +++ b/encoder/x86/ih264e_function_selector.c @@ -27,17 +27,18 @@ * Contains functions to initialize function pointers used in h264 * * @author -* Ittiam +* ittiam * * @par List of Functions: +* - ih264e_init_function_ptr +* - ih264e_default_arch * * @remarks -* None +* none * ******************************************************************************* */ - /*****************************************************************************/ /* File Includes */ /*****************************************************************************/ @@ -52,38 +53,46 @@ #include "ih264_typedefs.h" #include "iv2.h" #include "ive2.h" -#include "ih264_defs.h" -#include "ih264_size_defs.h" -#include "ih264e_defs.h" -#include "ih264e_error.h" -#include "ih264e_bitstream.h" -#include "ime_distortion_metrics.h" -#include "ime_defs.h" -#include "ime_structs.h" + +#include "ih264_macros.h" #include "ih264_error.h" +#include "ih264_defs.h" +#include "ih264_mem_fns.h" +#include "ih264_padding.h" #include "ih264_structs.h" +#include "ih264_size_defs.h" #include "ih264_trans_quant_itrans_iquant.h" #include "ih264_inter_pred_filters.h" -#include "ih264_mem_fns.h" -#include "ih264_padding.h" #include "ih264_intra_pred_filters.h" #include "ih264_deblk_edge_filters.h" #include "ih264_cabac_tables.h" -#include "ih264_macros.h" #include "ih264_platform_macros.h" + +#include "ime_defs.h" +#include "ime_distortion_metrics.h" +#include "ime_structs.h" + #include "irc_cntrl_param.h" #include "irc_frame_info_collector.h" + +#include "ih264e_error.h" +#include "ih264e_defs.h" #include "ih264e_rate_control.h" +#include "ih264e_bitstream.h" #include "ih264e_cabac_structs.h" #include "ih264e_structs.h" #include "ih264e_cabac.h" #include "ih264e_platform_macros.h" + +/*****************************************************************************/ +/* Function Definitions */ +/*****************************************************************************/ + /** ******************************************************************************* * -* @brief Initialize the intra/inter/transform/deblk function pointers of -* codec context +* @brief Initialize the intra/inter/transform/deblk/entropy function pointers * * @par Description: the current routine initializes the function pointers of * codec context basing on the architecture in use @@ -100,6 +109,7 @@ void ih264e_init_function_ptr(void *pv_codec) { codec_t *ps_codec = (codec_t *)pv_codec; + ih264e_init_function_ptr_generic(ps_codec); switch(ps_codec->s_cfg.e_arch) { @@ -139,4 +149,3 @@ IV_ARCH_T ih264e_default_arch(void) return ARCH_X86_SSE42; } - diff --git a/encoder/x86/ih264e_function_selector_sse42.c b/encoder/x86/ih264e_function_selector_sse42.c index 6888e5d8..30fbc5db 100644 --- a/encoder/x86/ih264e_function_selector_sse42.c +++ b/encoder/x86/ih264e_function_selector_sse42.c @@ -26,13 +26,13 @@ * Contains functions to initialize function pointers of codec context * * @author -* Ittiam +* ittiam * * @par List of Functions: * - ih264e_init_function_ptr_sse42 * * @remarks -* None +* none * ******************************************************************************* */ @@ -42,53 +42,59 @@ /* File Includes */ /*****************************************************************************/ - -/* System Include files */ +/* System Include Files */ #include #include #include #include -/* User Include files */ +/* User Include Files */ #include "ih264_typedefs.h" #include "iv2.h" #include "ive2.h" -#include "ih264_defs.h" -#include "ih264_size_defs.h" -#include "ih264e_defs.h" -#include "ih264e_error.h" -#include "ih264e_bitstream.h" -#include "ime_distortion_metrics.h" -#include "ime_defs.h" -#include "ime_structs.h" + #include "ih264_error.h" +#include "ih264_defs.h" +#include "ih264_mem_fns.h" +#include "ih264_padding.h" #include "ih264_structs.h" #include "ih264_trans_quant_itrans_iquant.h" #include "ih264_inter_pred_filters.h" -#include "ih264_mem_fns.h" -#include "ih264_padding.h" #include "ih264_intra_pred_filters.h" #include "ih264_deblk_edge_filters.h" +#include "ih264_cavlc_tables.h" #include "ih264_cabac_tables.h" + +#include "ime_defs.h" +#include "ime_distortion_metrics.h" +#include "ime_structs.h" + #include "irc_cntrl_param.h" #include "irc_frame_info_collector.h" + +#include "ih264e_error.h" +#include "ih264e_defs.h" #include "ih264e_rate_control.h" +#include "ih264e_bitstream.h" #include "ih264e_cabac_structs.h" #include "ih264e_structs.h" -#include "ih264e_cabac.h" -#include "ih264e_platform_macros.h" +#include "ih264e_half_pel.h" +#include "ih264e_intra_modes_eval.h" #include "ih264e_core_coding.h" -#include "ih264_cavlc_tables.h" #include "ih264e_cavlc.h" -#include "ih264e_intra_modes_eval.h" +#include "ih264e_cabac.h" #include "ih264e_fmt_conv.h" -#include "ih264e_half_pel.h" +#include "ih264e_platform_macros.h" + + +/*****************************************************************************/ +/* Function Definitions */ +/*****************************************************************************/ /** ******************************************************************************* * -* @brief Initialize the intra/inter/transform/deblk function pointers of -* codec context +* @brief Initialize the intra/inter/transform/deblk/entropy function pointers * * @par Description: the current routine initializes the function pointers of * codec context basing on the architecture in use @@ -105,19 +111,17 @@ void ih264e_init_function_ptr_sse42(codec_t *ps_codec) { WORD32 i; - process_ctxt_t *ps_proc = NULL; - me_ctxt_t *ps_me_ctxt = NULL; /* Init luma forward transform fn ptr */ ps_codec->pf_resi_trans_quant_4x4 = ih264_resi_trans_quant_4x4_sse42; - ps_codec->pf_resi_trans_quant_chroma_4x4 = ih264_resi_trans_quant_chroma_4x4_sse42; - ps_codec->pf_hadamard_quant_4x4 = ih264_hadamard_quant_4x4_sse42; - ps_codec->pf_hadamard_quant_2x2_uv = ih264_hadamard_quant_2x2_uv_sse42; + ps_codec->pf_resi_trans_quant_chroma_4x4 = ih264_resi_trans_quant_chroma_4x4_sse42; + ps_codec->pf_hadamard_quant_4x4 = ih264_hadamard_quant_4x4_sse42; + ps_codec->pf_hadamard_quant_2x2_uv = ih264_hadamard_quant_2x2_uv_sse42; /* Init inverse transform fn ptr */ ps_codec->pf_iquant_itrans_recon_4x4 = ih264_iquant_itrans_recon_4x4_sse42; - ps_codec->pf_iquant_itrans_recon_chroma_4x4 = ih264_iquant_itrans_recon_chroma_4x4_sse42; - ps_codec->pf_ihadamard_scaling_4x4 = ih264_ihadamard_scaling_4x4_sse42; + ps_codec->pf_iquant_itrans_recon_chroma_4x4 = ih264_iquant_itrans_recon_chroma_4x4_sse42; + ps_codec->pf_ihadamard_scaling_4x4 = ih264_ihadamard_scaling_4x4_sse42; /* sad me level functions */ ps_codec->apf_compute_sad_16x16[0] = ime_compute_sad_16x16_sse42; @@ -127,14 +131,14 @@ void ih264e_init_function_ptr_sse42(codec_t *ps_codec) /* sad me level functions */ for(i = 0; i < (MAX_PROCESS_CTXT); i++) { - ps_proc = &ps_codec->as_process[i]; + process_ctxt_t *ps_proc = &ps_codec->as_process[i]; + me_ctxt_t *ps_me_ctxt = &ps_proc->s_me_ctxt; - ps_me_ctxt = &ps_proc->s_me_ctxt; ps_me_ctxt->pf_ime_compute_sad_16x16[0] = ime_compute_sad_16x16_sse42; ps_me_ctxt->pf_ime_compute_sad_16x16[1] = ime_compute_sad_16x16_fast_sse42; ps_me_ctxt->pf_ime_compute_sad_16x8 = ime_compute_sad_16x8_sse42; ps_me_ctxt->pf_ime_compute_sad4_diamond = ime_calculate_sad4_prog_sse42; ps_me_ctxt->pf_ime_sub_pel_compute_sad_16x16 = ime_sub_pel_compute_sad_16x16_sse42; - ps_me_ctxt->pf_ime_compute_sad_stat_luma_16x16 = ime_compute_satqd_16x16_lumainter_sse42; + ps_me_ctxt->pf_ime_compute_sad_stat_luma_16x16 = ime_compute_satqd_16x16_lumainter_sse42; } } diff --git a/encoder/x86/ih264e_function_selector_ssse3.c b/encoder/x86/ih264e_function_selector_ssse3.c index 44191125..33937c53 100644 --- a/encoder/x86/ih264e_function_selector_ssse3.c +++ b/encoder/x86/ih264e_function_selector_ssse3.c @@ -26,69 +26,74 @@ * Contains functions to initialize function pointers of codec context * * @author -* Ittiam +* ittiam * * @par List of Functions: * - ih264e_init_function_ptr_ssse3 * * @remarks -* None +* none * ******************************************************************************* */ - /*****************************************************************************/ /* File Includes */ /*****************************************************************************/ - -/* System Include files */ +/* System Include Files */ #include #include #include #include -/* User Include files */ +/* User Include Files */ #include "ih264_typedefs.h" #include "iv2.h" #include "ive2.h" -#include "ih264_defs.h" -#include "ih264_size_defs.h" -#include "ih264e_defs.h" -#include "ih264e_error.h" -#include "ih264e_bitstream.h" -#include "ime_distortion_metrics.h" -#include "ime_defs.h" -#include "ime_structs.h" + #include "ih264_error.h" +#include "ih264_defs.h" +#include "ih264_mem_fns.h" +#include "ih264_padding.h" #include "ih264_structs.h" #include "ih264_trans_quant_itrans_iquant.h" #include "ih264_inter_pred_filters.h" -#include "ih264_mem_fns.h" -#include "ih264_padding.h" #include "ih264_intra_pred_filters.h" #include "ih264_deblk_edge_filters.h" +#include "ih264_cavlc_tables.h" #include "ih264_cabac_tables.h" + +#include "ime_defs.h" +#include "ime_distortion_metrics.h" +#include "ime_structs.h" + #include "irc_cntrl_param.h" #include "irc_frame_info_collector.h" + +#include "ih264e_error.h" +#include "ih264e_defs.h" #include "ih264e_rate_control.h" +#include "ih264e_bitstream.h" #include "ih264e_cabac_structs.h" #include "ih264e_structs.h" -#include "ih264e_platform_macros.h" -#include "ih264e_cabac.h" +#include "ih264e_half_pel.h" +#include "ih264e_intra_modes_eval.h" #include "ih264e_core_coding.h" -#include "ih264_cavlc_tables.h" #include "ih264e_cavlc.h" -#include "ih264e_intra_modes_eval.h" +#include "ih264e_cabac.h" #include "ih264e_fmt_conv.h" -#include "ih264e_half_pel.h" +#include "ih264e_platform_macros.h" + + +/*****************************************************************************/ +/* Function Definitions */ +/*****************************************************************************/ /** ******************************************************************************* * -* @brief Initialize the intra/inter/transform/deblk function pointers of -* codec context +* @brief Initialize the intra/inter/transform/deblk/entropy function pointers * * @par Description: the current routine initializes the function pointers of * codec context basing on the architecture in use @@ -104,64 +109,63 @@ */ void ih264e_init_function_ptr_ssse3(codec_t *ps_codec) { + /* Init function pointers for intra pred leaf level functions luma + * Intra 16x16 */ + ps_codec->apf_intra_pred_16_l[0] = ih264_intra_pred_luma_16x16_mode_vert_ssse3; + ps_codec->apf_intra_pred_16_l[1] = ih264_intra_pred_luma_16x16_mode_horz_ssse3; + ps_codec->apf_intra_pred_16_l[2] = ih264_intra_pred_luma_16x16_mode_dc_ssse3; + ps_codec->apf_intra_pred_16_l[3] = ih264_intra_pred_luma_16x16_mode_plane_ssse3; + + /* Init function pointers for intra pred leaf level functions luma + * Intra 4x4 */ + ps_codec->apf_intra_pred_4_l[0] = ih264_intra_pred_luma_4x4_mode_vert_ssse3; + ps_codec->apf_intra_pred_4_l[1] = ih264_intra_pred_luma_4x4_mode_horz_ssse3; + ps_codec->apf_intra_pred_4_l[2] = ih264_intra_pred_luma_4x4_mode_dc_ssse3; + ps_codec->apf_intra_pred_4_l[3] = ih264_intra_pred_luma_4x4_mode_diag_dl_ssse3; + ps_codec->apf_intra_pred_4_l[4] = ih264_intra_pred_luma_4x4_mode_diag_dr_ssse3; + ps_codec->apf_intra_pred_4_l[5] = ih264_intra_pred_luma_4x4_mode_vert_r_ssse3; + ps_codec->apf_intra_pred_4_l[6] = ih264_intra_pred_luma_4x4_mode_horz_d_ssse3; + ps_codec->apf_intra_pred_4_l[7] = ih264_intra_pred_luma_4x4_mode_vert_l_ssse3; + ps_codec->apf_intra_pred_4_l[8] = ih264_intra_pred_luma_4x4_mode_horz_u_ssse3; /* Init function pointers for intra pred leaf level functions luma - * Intra 16x16 */ - ps_codec->apf_intra_pred_16_l[0] = ih264_intra_pred_luma_16x16_mode_vert_ssse3; - ps_codec->apf_intra_pred_16_l[1] = ih264_intra_pred_luma_16x16_mode_horz_ssse3; - ps_codec->apf_intra_pred_16_l[2] = ih264_intra_pred_luma_16x16_mode_dc_ssse3; - ps_codec->apf_intra_pred_16_l[3] = ih264_intra_pred_luma_16x16_mode_plane_ssse3; - - /* Init function pointers for intra pred leaf level functions luma - * Intra 4x4 */ - ps_codec->apf_intra_pred_4_l[0] = ih264_intra_pred_luma_4x4_mode_vert_ssse3; - ps_codec->apf_intra_pred_4_l[1] = ih264_intra_pred_luma_4x4_mode_horz_ssse3; - ps_codec->apf_intra_pred_4_l[2] = ih264_intra_pred_luma_4x4_mode_dc_ssse3; - ps_codec->apf_intra_pred_4_l[3] = ih264_intra_pred_luma_4x4_mode_diag_dl_ssse3; - ps_codec->apf_intra_pred_4_l[4] = ih264_intra_pred_luma_4x4_mode_diag_dr_ssse3; - ps_codec->apf_intra_pred_4_l[5] = ih264_intra_pred_luma_4x4_mode_vert_r_ssse3; - ps_codec->apf_intra_pred_4_l[6] = ih264_intra_pred_luma_4x4_mode_horz_d_ssse3; - ps_codec->apf_intra_pred_4_l[7] = ih264_intra_pred_luma_4x4_mode_vert_l_ssse3; - ps_codec->apf_intra_pred_4_l[8] = ih264_intra_pred_luma_4x4_mode_horz_u_ssse3; - - /* Init function pointers for intra pred leaf level functions luma - * Intra 8x8 */ - ps_codec->apf_intra_pred_8_l[0] = ih264_intra_pred_luma_8x8_mode_vert_ssse3; - ps_codec->apf_intra_pred_8_l[2] = ih264_intra_pred_luma_8x8_mode_dc_ssse3; - ps_codec->apf_intra_pred_8_l[3] = ih264_intra_pred_luma_8x8_mode_diag_dl_ssse3; - ps_codec->apf_intra_pred_8_l[4] = ih264_intra_pred_luma_8x8_mode_diag_dr_ssse3; - ps_codec->apf_intra_pred_8_l[5] = ih264_intra_pred_luma_8x8_mode_vert_r_ssse3; - ps_codec->apf_intra_pred_8_l[6] = ih264_intra_pred_luma_8x8_mode_horz_d_ssse3; - ps_codec->apf_intra_pred_8_l[7] = ih264_intra_pred_luma_8x8_mode_vert_l_ssse3; - ps_codec->apf_intra_pred_8_l[8] = ih264_intra_pred_luma_8x8_mode_horz_u_ssse3; - - /* Init function pointers for intra pred leaf level functions chroma - * Intra 8x8 */ - ps_codec->apf_intra_pred_c[1] = ih264_intra_pred_chroma_8x8_mode_horz_ssse3; - ps_codec->apf_intra_pred_c[2] = ih264_intra_pred_chroma_8x8_mode_vert_ssse3; - ps_codec->apf_intra_pred_c[3] = ih264_intra_pred_chroma_8x8_mode_plane_ssse3; + * Intra 8x8 */ + ps_codec->apf_intra_pred_8_l[0] = ih264_intra_pred_luma_8x8_mode_vert_ssse3; + ps_codec->apf_intra_pred_8_l[2] = ih264_intra_pred_luma_8x8_mode_dc_ssse3; + ps_codec->apf_intra_pred_8_l[3] = ih264_intra_pred_luma_8x8_mode_diag_dl_ssse3; + ps_codec->apf_intra_pred_8_l[4] = ih264_intra_pred_luma_8x8_mode_diag_dr_ssse3; + ps_codec->apf_intra_pred_8_l[5] = ih264_intra_pred_luma_8x8_mode_vert_r_ssse3; + ps_codec->apf_intra_pred_8_l[6] = ih264_intra_pred_luma_8x8_mode_horz_d_ssse3; + ps_codec->apf_intra_pred_8_l[7] = ih264_intra_pred_luma_8x8_mode_vert_l_ssse3; + ps_codec->apf_intra_pred_8_l[8] = ih264_intra_pred_luma_8x8_mode_horz_u_ssse3; + + /* Init function pointers for intra pred leaf level functions chroma + * Intra 8x8 */ + ps_codec->apf_intra_pred_c[1] = ih264_intra_pred_chroma_8x8_mode_horz_ssse3; + ps_codec->apf_intra_pred_c[2] = ih264_intra_pred_chroma_8x8_mode_vert_ssse3; + ps_codec->apf_intra_pred_c[3] = ih264_intra_pred_chroma_8x8_mode_plane_ssse3; /* Init inverse transform fn ptr */ ps_codec->pf_iquant_itrans_recon_8x8 = ih264_iquant_itrans_recon_8x8_ssse3; - ps_codec->pf_iquant_itrans_recon_4x4_dc = ih264_iquant_itrans_recon_4x4_dc_ssse3; + ps_codec->pf_iquant_itrans_recon_4x4_dc = ih264_iquant_itrans_recon_4x4_dc_ssse3; ps_codec->pf_iquant_itrans_recon_chroma_4x4_dc = ih264_iquant_itrans_recon_chroma_4x4_dc_ssse3; /* Init fn ptr luma deblocking */ ps_codec->pf_deblk_luma_vert_bs4 = ih264_deblk_luma_vert_bs4_ssse3; - ps_codec->pf_deblk_luma_vert_bslt4 = ih264_deblk_luma_vert_bslt4_ssse3; - ps_codec->pf_deblk_luma_horz_bs4 = ih264_deblk_luma_horz_bs4_ssse3; - ps_codec->pf_deblk_luma_horz_bslt4 = ih264_deblk_luma_horz_bslt4_ssse3; + ps_codec->pf_deblk_luma_vert_bslt4 = ih264_deblk_luma_vert_bslt4_ssse3; + ps_codec->pf_deblk_luma_horz_bs4 = ih264_deblk_luma_horz_bs4_ssse3; + ps_codec->pf_deblk_luma_horz_bslt4 = ih264_deblk_luma_horz_bslt4_ssse3; /* Init fn ptr chroma deblocking */ - ps_codec->pf_deblk_chroma_vert_bs4 = ih264_deblk_chroma_vert_bs4_ssse3; - ps_codec->pf_deblk_chroma_vert_bslt4 = ih264_deblk_chroma_vert_bslt4_ssse3; - ps_codec->pf_deblk_chroma_horz_bs4 = ih264_deblk_chroma_horz_bs4_ssse3; - ps_codec->pf_deblk_chroma_horz_bslt4 = ih264_deblk_chroma_horz_bslt4_ssse3; - - /* Padding Functions */ - ps_codec->pf_pad_left_luma = ih264_pad_left_luma_ssse3; - ps_codec->pf_pad_left_chroma = ih264_pad_left_chroma_ssse3; - ps_codec->pf_pad_right_luma = ih264_pad_right_luma_ssse3; - ps_codec->pf_pad_right_chroma = ih264_pad_right_chroma_ssse3; + ps_codec->pf_deblk_chroma_vert_bs4 = ih264_deblk_chroma_vert_bs4_ssse3; + ps_codec->pf_deblk_chroma_vert_bslt4 = ih264_deblk_chroma_vert_bslt4_ssse3; + ps_codec->pf_deblk_chroma_horz_bs4 = ih264_deblk_chroma_horz_bs4_ssse3; + ps_codec->pf_deblk_chroma_horz_bslt4 = ih264_deblk_chroma_horz_bslt4_ssse3; + + /* Padding Functions */ + ps_codec->pf_pad_left_luma = ih264_pad_left_luma_ssse3; + ps_codec->pf_pad_left_chroma = ih264_pad_left_chroma_ssse3; + ps_codec->pf_pad_right_luma = ih264_pad_right_luma_ssse3; + ps_codec->pf_pad_right_chroma = ih264_pad_right_chroma_ssse3; /* Inter pred leaf level functions */ ps_codec->pf_inter_pred_luma_copy = ih264_inter_pred_luma_copy_ssse3; diff --git a/encoder/x86/ih264e_half_pel_ssse3.c b/encoder/x86/ih264e_half_pel_ssse3.c index 8da73b7c..415f9a56 100644 --- a/encoder/x86/ih264e_half_pel_ssse3.c +++ b/encoder/x86/ih264e_half_pel_ssse3.c @@ -27,14 +27,14 @@ * and cascaded 2D filter used in motion estimation in H264 encoder. * * @author - * Ittiam + * ittiam * * @par List of Functions: * ih264e_sixtapfilter_horz_ssse3 * ih264e_sixtap_filter_2dvh_vert_ssse3 * * @remarks - * None + * none * ******************************************************************************* */ @@ -55,7 +55,6 @@ #include "ih264_defs.h" #include "ih264e_half_pel.h" #include "ih264_macros.h" -#include "ih264e_debug.h" #include "ih264_inter_pred_filters.h" #include "ih264_mem_fns.h" #include "ih264_padding.h" @@ -90,10 +89,10 @@ * integer destination stride * * @returns -* None +* none * * @remarks -* None +* none * ******************************************************************************* */ @@ -236,10 +235,10 @@ void ih264e_sixtapfilter_horz_ssse3(UWORD8 *pu1_src, * integer destination stride of pi16_pred1 * * @returns -* None +* none * * @remarks -* None +* none * ******************************************************************************* */ diff --git a/encoder/x86/ih264e_intra_modes_eval_ssse3.c b/encoder/x86/ih264e_intra_modes_eval_ssse3.c index ea8a6c8c..7eb7daeb 100644 --- a/encoder/x86/ih264e_intra_modes_eval_ssse3.c +++ b/encoder/x86/ih264e_intra_modes_eval_ssse3.c @@ -23,11 +23,11 @@ * ih264e_intra_modes_eval_ssse3.c * * @brief -* This file contains definitions of routines that perform rate distortion +* This file contains definitions of routines that perform rate distortion * analysis on a macroblock if they are to be coded as intra. * * @author -* Ittiam +* ittiam * * @par List of Functions: * ih264e_evaluate_intra16x16_modes_ssse3 @@ -35,7 +35,7 @@ * ih264e_evaluate_intra_chroma_modes_ssse3 * * @remarks -* None +* none * ******************************************************************************* */ @@ -128,7 +128,7 @@ * says what all modes are valid * * @return -* None +* none * ****************************************************************************** */ diff --git a/encoder/x86/ih264e_platform_macros.h b/encoder/x86/ih264e_platform_macros.h index b4dfadda..2c1513fc 100644 --- a/encoder/x86/ih264e_platform_macros.h +++ b/encoder/x86/ih264e_platform_macros.h @@ -17,138 +17,35 @@ ***************************************************************************** * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore */ -/** - ******************************************************************************* - * @file - * ih264e_platform_macros.h - * - * @brief - * Contains platform specific routines used for codec context intialization - * - * @author - * ittiam - * - * @remarks - * none - * - ******************************************************************************* - */ - - -#ifndef IH264E_PLATFORM_MACROS_H_ -#define IH264E_PLATFORM_MACROS_H_ - -/*****************************************************************************/ -/* Extern Function Declarations */ -/*****************************************************************************/ /** ******************************************************************************* +* @file +* ih264e_platform_macros.h * -* @brief Initialize the intra/inter/transform/deblk function pointers of -* codec context -* -* @par Description: the current routine initializes the function pointers of -* codec context basing on the architecture in use -* -* @param[in] ps_codec -* Codec context pointer +* @brief +* Contains platform specific routines used for codec context intialization * -* @returns none +* @author +* ittiam * -* @remarks none +* @remarks +* none * ******************************************************************************* */ + +#ifndef _IH264E_PLATFORM_MACROS_H_ +#define _IH264E_PLATFORM_MACROS_H_ + +/*****************************************************************************/ +/* Function Declarations */ +/*****************************************************************************/ + void ih264e_init_function_ptr_generic(codec_t *ps_codec); -/** -******************************************************************************* -* -* @brief Initialize the intra/inter/transform/deblk function pointers of -* codec context -* -* @par Description: the current routine initializes the function pointers of -* codec context basing on the architecture in use -* -* @param[in] ps_codec -* Codec context pointer -* -* @returns none -* -* @remarks none -* -******************************************************************************* -*/ void ih264e_init_function_ptr_ssse3(codec_t *ps_codec); void ih264e_init_function_ptr_sse42(codec_t *ps_codec); - -/** -******************************************************************************* -* -* @brief Initialize the intra/inter/transform/deblk function pointers of -* codec context -* -* @par Description: the current routine initializes the function pointers of -* codec context basing on the architecture in use -* -* @param[in] ps_codec -* Codec context pointer -* -* @returns none -* -* @remarks none -* -******************************************************************************* -*/ void ih264e_init_function_ptr(void *pv_codec); - -/** -******************************************************************************* -* -* @brief Determine the architecture of the encoder executing environment -* -* @par Description: This routine returns the architecture of the enviro- -* ment in which the current encoder is being tested -* -* @param[in] void -* -* @returns IV_ARCH_T -* architecture -* -* @remarks none -* -******************************************************************************* -*/ IV_ARCH_T ih264e_default_arch(void); -/** -******************************************************************************* -* -* @brief Data Memory Barrier, Data Synchronization Barrier -* -* -* @par Description: These functions do nothing on x86 side. But on arm platforms, -* -* Data Memory Barrier acts as a memory barrier. It ensures that all explicit -* memory accesses that appear in program order before the DMB instruction are -* observed before any explicit memory accesses that appear in program order -* after the DMB instruction. It does not affect the ordering of any other -* instructions executing on the processor -* -* Data Synchronization Barrier acts as a special kind of memory barrier. No -* instruction in program order after this instruction executes until this instruction -* completes. This instruction completes when: -* 1. All explicit memory accesses before this instruction complete. -* 2. All Cache, Branch predictor and TLB maintenance operations before -* this instruction complete. -* -* @param[in] void -* -* @returns void -* -* @remarks none -* -******************************************************************************* -*/ - -#endif /* IH264E_PLATFORM_MACROS_H_ */ +#endif /* _IH264E_PLATFORM_MACROS_H_ */ diff --git a/encoder/x86/ime_platform_macros.h b/encoder/x86/ime_platform_macros.h index 18e2e8f1..fc3b1a3b 100644 --- a/encoder/x86/ime_platform_macros.h +++ b/encoder/x86/ime_platform_macros.h @@ -34,7 +34,6 @@ ******************************************************************************* */ - #ifndef _IME_PLATFORM_MACROS_H_ #define _IME_PLATFORM_MACROS_H_ @@ -49,4 +48,4 @@ ABS(src[3]-est[3]) -#endif /* _IH264_PLATFORM_MACROS_H_ */ +#endif /* _IME_PLATFORM_MACROS_H_ */