1 /****************************************************************************** 2 * 3 * Copyright (C) 2022 The Android Open Source Project 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at: 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 ***************************************************************************** 18 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore 19 */ 20 /** 21 ******************************************************************************* 22 * @file 23 * isvcd_process_pslice.h 24 * 25 * @brief 26 * Contains routines that resample for SVC resampling 27 * 28 * @author 29 * Kishore 30 * 31 * @remarks 32 * None 33 * 34 ******************************************************************************* 35 */ 36 37 #ifndef _ISVCD_RESAMP_SVC_H_ 38 #define _ISVCD_RESAMP_SVC_H_ 39 40 #include "ih264_typedefs.h" 41 #include "ih264_macros.h" 42 #include "ih264_platform_macros.h" 43 #include "ih264d_structs.h" 44 45 #define SVCD_FALSE 0 46 #define SVCD_TRUE 1 47 48 #define MAP_BUFF_WIDTH 48 49 #define MAP_BUFF_HEIGHT 48 50 #define INTERMEDIATE_BUFF_WIDTH 48 51 #define INTERMEDIATE_BUFF_HEIGHT (MB_HEIGHT + 4) 52 53 #define MAX_REF_ARR_WD_HT 48 54 55 #define MAX_REF_IDX_ARRAY (MAX_REF_ARR_WD_HT + MB_WIDTH) 56 #define DYADIC_REF_W_Y 20 57 #define DYADIC_REF_H_Y 20 58 #define DYADIC_REF_W_C 10 59 #define DYADIC_REF_H_C 10 60 61 #define SUB_BLOCK_WIDTH 4 62 #define SUB_BLOCK_HEIGHT 4 63 #define SUB_BLOCK_SIZE (SUB_BLOCK_WIDTH * SUB_BLOCK_HEIGHT) 64 #define BLOCK_WIDTH 8 65 #define BLOCK_HEIGHT 8 66 #define BLOCK_SIZE (BLOCK_WIDTH * BLOCK_HEIGHT) 67 #define MB_WIDTH 16 68 #define MB_HEIGHT 16 69 #define CLIPUCHAR(x) CLIP3(0, 255, (x)) 70 #define MB_WIDTH_SHIFT 4 71 #define MB_HEIGHT_SHIFT 4 72 73 #define REF_ARRAY_WIDTH 48 74 #define REF_ARRAY_HEIGHT 48 75 #define MAX_PIX_FILL_LUMA 4 76 #define MAX_PIX_FILL_CHROMA 2 77 78 typedef void (*pf_vert_interpol_chroma_dyadic)(UWORD8 *pu1_inp_buf, WORD16 *pi2_tmp_filt_buf, 79 WORD32 i4_phase_0, WORD32 i4_phase_1); 80 81 typedef void (*pf_horz_interpol_chroma_dyadic)(WORD16 *pi2_tmp_filt_buf, UWORD8 *pu1_out_buf, 82 WORD32 i4_out_stride, WORD32 i4_phase_0, 83 WORD32 i4_phase_1); 84 85 typedef struct 86 { 87 void *pv_buffer; /*!< Buffer pointer */ 88 WORD32 i4_element_size; /*!< size of the structure or unit */ 89 WORD32 i4_num_element_stride; /*!< Stride of buffer in terms of number of elements */ 90 } mem_element_t; 91 92 typedef struct 93 { 94 UWORD8 u1_seg_dim; /*!< describes segment dimension */ 95 UWORD8 u1_seg_off; /*!< describes offset from start */ 96 UWORD8 u1_mb_adjoin; /*!< describes whether mb is adjoining 97 the segment 0 => not adjoining 98 1 => adjoining */ 99 100 WORD8 i1_dist_idx; /*!< distance to nearest MB */ 101 102 WORD8 i1_nearst_mb_bdry; /*!< describes the nearest mb boundary 103 +1 => rightMB/bottomMB 104 -1 => leftMB/topMB */ 105 } seg_description_t; 106 107 typedef struct 108 { 109 UWORD8 u1_num_segments; /*!< place holder to store the number of segments */ 110 111 UWORD8 u4_start_pos; /*!< this variable indicates where is 112 start locatiion of the segment with 113 respect to less the block_width or 114 greater than block width */ 115 116 seg_description_t s_segments[4]; /*!< place holder to store per segment description */ 117 } seg_lookup_desc_t; 118 typedef struct 119 { 120 WORD16 i2_min_pos; /*!< place holder to store the projected 121 MIN referecne position for a MB in 122 current layer. can be used to store 123 either horizontal or vertical positions 124 */ 125 WORD16 i2_max_pos; /*!< place holder to store the projected 126 MAX referecne position for a MB in 127 current layer. can be used to store 128 either horizontal or vertical positions 129 */ 130 } ref_min_max_map_t; 131 132 typedef struct 133 { 134 WORD16 i2_left; /*!< Horizontal offset of upper left luma sample 135 after resampling process on reference 136 layer with respect to upper left luma 137 sample of current layer. 138 */ 139 WORD16 i2_top; /*!< Vertical offset of upper left luma pixel 140 after resampling process on reference 141 layer 142 */ 143 WORD16 i2_rt; /*!< Horizontal offset of bottom right luma 144 sample after resampling process on 145 reference layer with respect to bottom 146 right luma sample. 147 */ 148 WORD16 i2_bot; /*!< Vertical offset of bottom right luma 149 pixel after resampling process on 150 reference layer 151 */ 152 } ref_lyr_scaled_offset_t; 153 154 typedef struct 155 { 156 UWORD8 i2_ref_pos; /*!< place holder to store the projected 157 referecne position for a pixel in 158 current layer. can be used to store 159 either horizontal or vertical positions 160 */ 161 UWORD8 i2_phase; /*!< place holder to store the projected 162 phase for a pixel in current layer. 163 can be used to store either 164 horizontal or vertical phase 165 */ 166 } ref_pixel_map_t; 167 168 typedef struct 169 { 170 WORD16 i2_offset; /*!< place holder to store the projected 171 start point of reference window 172 for each MB in current layer.can be 173 used to store either horizontal or 174 vertical offset 175 */ 176 WORD16 i2_length; /*!< place holder to store reference array 177 length of the reference window 178 for each MB in current layer.can be 179 used to store either horizontal width 180 or vertical height 181 */ 182 } ref_mb_map_t; 183 184 typedef struct 185 { 186 /* used for mapping purpose */ 187 ref_pixel_map_t *ps_x_pos_phase; /*!< buffers to store the projected 188 referecne X and phase X for each 189 pixel in current layer in 190 horizontal direction 191 */ 192 ref_pixel_map_t *ps_y_pos_phase; /*!< buffers to store the projected 193 referecne Y and phase Y for each 194 pixel in current layer in 195 vertical direction 196 */ 197 ref_mb_map_t *ps_x_offset_length; /*!< buffers to store the projected 198 start point of reference window and 199 reference array width in 200 horizontal direction for each MB in 201 current layer 202 */ 203 ref_mb_map_t *ps_y_offset_length; /*!< buffers to store the projected 204 start point of reference window and 205 reference array height in 206 vertical direction for each MB in 207 current layer 208 */ 209 } residual_samp_map_ctxt_t; 210 211 typedef struct 212 { 213 residual_samp_map_ctxt_t s_luma_map_ctxt; /*!< map structure for luma 214 projected locations 215 for curr resolution layer 216 */ 217 residual_samp_map_ctxt_t s_chroma_map_ctxt; /*!< map structure for chroma 218 projected locations 219 for curr resolution layer 220 */ 221 WORD32 i4_ref_width; /*!< reference layer width in 222 terms luma samples 223 */ 224 WORD32 i4_ref_height; /*!< reference layer height in 225 terms luma samples 226 */ 227 WORD32 i4_curr_width; /*!< current layer width in 228 terms luma samples 229 */ 230 WORD32 i4_curr_height; /*!< current layer height in 231 terms luma samples 232 */ 233 WORD32 i4_dyadic_flag; /*!< flag to indicate whether 234 the upscaling factor is 2 235 in both directions 236 237 /* following variables are for Dyadic cases only */ 238 WORD32 i4_chrm_alt_proc; /*!< Alternate processing 239 for chroma for specific 240 values of phases 241 */ 242 243 WORD32 i4_chrm_vert_int_mode; /*!< Chroma horizontal 244 interpolation alternate 245 mode 246 */ 247 248 WORD32 i4_chrm_horz_int_mode; /*!<Chroma vertical 249 interpolation alternate 250 modes 251 */ 252 } res_lyr_ctxt; 253 254 typedef struct 255 { 256 res_lyr_ctxt as_res_lyrs[MAX_NUM_RES_LYRS]; /*!< Array of resolutoin layer 257 ctxt.The first strcuture in the 258 array will be used for storing 259 the "second resolution" map in 260 an access unit w.r.t to its 261 base resolution, and for base 262 resolution nothing will be 263 computed or stored 264 */ 265 void *ps_sps; /*!< pointer to array of SPS 266 */ 267 268 WORD16 *pi2_refarray_buffer; /*!< buffer to store the reference 269 layer data before residual 270 sampling 271 */ 272 273 UWORD8 *pu1_ref_x_ptr_incr; /*!< buffer to store the reference 274 array ptr increments for 275 operand 2 of interpolation 276 */ 277 UWORD8 *pu1_ref_y_ptr_incr; /*!< buffer to store the reference 278 array ptr increments for 279 operand 2 of interpolation 280 */ 281 282 WORD32 i4_res_lyr_id; /*!< resolution id of the layer 283 which is to be processed 284 */ 285 WORD32 i4_ref_width; /*!< reference layer width in 286 terms luma samples 287 */ 288 289 WORD32 i4_ref_height; /*!< reference layer height in 290 terms luma samples 291 */ 292 } residual_sampling_ctxt_t; 293 294 typedef struct 295 { 296 WORD32 i4_res_width; /*!< Frame width of top most layer in the 297 resolution. It's expressed in terms 298 of luma samples. 299 */ 300 WORD32 i4_res_height; /*!< Frame height of top most layer in the 301 resolution. It's expressed in terms 302 of luma samples. 303 */ 304 ref_lyr_scaled_offset_t s_ref_lyr_scaled_offset; /*!< Scaled offset 305 parameters of reference layer considering 306 bottom most layer of the resolution as 307 current layer. Offsets are with respect 308 to upper left luma samples in top most 309 layer in the resolution. 310 */ 311 UWORD16 u2_scaled_ref_width; /*!< Considering bottom most layer of the 312 resolution as current layer, scaled 313 width of reference layer in terms of 314 luma pixels. It's inferred parameter 315 based on reference layer offsets. 316 */ 317 UWORD16 u2_scaled_ref_height; /*!< Considering bottom most layer of the 318 resolution as current layer, scaled 319 height of reference layer in terms of 320 luma pixels. It's inferred parameter 321 based on reference layer offsets. 322 */ 323 UWORD8 u1_rstrct_res_change_flag; /*!< restrictedResolutionChangeFlag for 324 bottom most layer of the resolution. It's 325 a inferred parameter. 326 */ 327 UWORD8 u1_cropping_change_flag; /*!< croppingChangeFlag for bottom most 328 layer of the resolution. It's a inferred 329 parameter. 330 */ 331 UWORD8 u1_disable_inter_lyr_dblk_filter_idc; /*!< Mode of operation for 332 inter layer de-blocking. It shall be 333 set for bottom most layer of the top 334 resolution. By top resolution, it 335 referes to the resolution just above 336 the current spatial resolution. This 337 shall be valid for all resolutions 338 except target resolution. 339 */ 340 WORD8 i1_inter_lyr_alpha_c0_offset; /*!< specifies the offset used in 341 accessing the alpha and tC0 deblocking 342 filter tables for filtering operations 343 in inter layer de-blocking. Applicable 344 for bottom most layer of the top 345 resolution. By top resolution, it referes 346 to the resolution just above the current 347 spatial resolution. This shall be valid 348 for resolutions except target resolution. 349 */ 350 WORD8 i1_inter_lyr_beta_offset; /*!< specifies the offset used in 351 accessing the beta deblocking filter table 352 for filtering operations in inter layer 353 de-blocking. Applicable for bottom most 354 layer of the top resolution. By top 355 resolution, it referes to the resolution 356 just above the current spatial resolution. 357 This shall be valid for resolutions 358 except target resolution. 359 */ 360 WORD8 i1_constrained_intra_rsmpl_flag; /*!< Constrained intra resampling 361 flag. Range is [0,1]. 362 */ 363 WORD8 i1_ref_lyr_chroma_phase_x_plus1_flag; /*!< specifies the horizontal 364 phase shift of the chroma components in 365 units of half luma samples of a layer 366 frame for the layer pictures that may be 367 used for inter-layer prediction 368 */ 369 370 WORD8 i1_ref_lyr_chroma_phase_y_plus1; /*!< specifies the vertical phase 371 shift of the chroma components in units of 372 half luma samples of a layer frame for the 373 layer pictures that may be used for 374 inter-layer prediction 375 */ 376 UWORD8 u1_direct_8x8_inference_flag; /*!< Direct 8x8 inference flag 377 . Range is [0,1]. 378 */ 379 380 UWORD8 u1_remap_req_flag; /*!< this flag signifies to the 381 upsampling modules whether the Map 382 buffers have to recomputed for current 383 access unit or to retain the previous 384 access units values 385 */ 386 UWORD8 u1_dyadic_flag; /*!< this flag signifies the scaling 387 ratios are 2 in both directions 388 and the cropping is MB aligned 389 */ 390 } res_prms_t; 391 392 typedef struct 393 { 394 ref_pixel_map_t *ps_x_pos_phase; /*!< buffers to store the projected 395 referecne X and phase X for each 396 pixel in current layer in 397 horizontal direction 398 */ 399 ref_pixel_map_t *ps_y_pos_phase; /*!< buffers to store the projected 400 referecne Y and phase Y for each 401 pixel in current layer in 402 vertical direction 403 */ 404 ref_mb_map_t *ps_x_offset_length; /*!< buffers to store the projected 405 start point of reference window and 406 reference array width in 407 horizontal direction for each MB in 408 current layer 409 */ 410 ref_mb_map_t *ps_y_offset_length; /*!< buffers to store the projected 411 start point of reference window and 412 reference array height in 413 vertical direction for each MB in 414 current layer 415 */ 416 ref_min_max_map_t *ps_x_min_max; 417 /*!< Buffer to store the projected 418 MIN and MAX referecne position for a 419 MB in current layer in 420 horizontal direction 421 */ 422 423 ref_min_max_map_t *ps_y_min_max; 424 /*!< Buffer to store the projected 425 MIN and MAX referecne position for a 426 MB in current layer in 427 Vertical direction 428 */ 429 430 WORD16 *pi2_xd_index; /*!< buffers to store the projected 431 XD for each pixel in an MB 432 */ 433 WORD16 *pi2_yd_index; /*!< buffers to store the projected 434 YD for each pixel in an MB 435 */ 436 WORD16 *pi2_ya_index; /*!< buffers to store the projected 437 YA for each pixel in an MB 438 */ 439 440 seg_lookup_desc_t *ps_seg_lookup_horz; /*!< buffers to store lookup for 441 horizontal segment description */ 442 443 seg_lookup_desc_t *ps_seg_lookup_vert; /*!< buffers to store lookup for 444 vertical segment description */ 445 446 UWORD8 *pu1_refarray_x_idx; /*!< buffers to store lookup for 447 x indexes to get availability 448 from 4x4 availability grid */ 449 450 UWORD8 *pu1_refarray_y_idx; /*!< buffers to store lookup for 451 y indexes to get availability 452 from 4x4 availability grid */ 453 } intra_samp_map_ctxt_t; 454 455 typedef struct 456 { 457 intra_samp_map_ctxt_t s_luma_map_ctxt; /*!< map structure for luma 458 projected locations 459 for curr resolution layer 460 */ 461 intra_samp_map_ctxt_t s_chroma_map_ctxt; /*!< map structure for chroma 462 projected locations 463 for curr resolution layer 464 */ 465 WORD32 i4_ref_width; /*!< reference layer width in 466 terms luma samples 467 */ 468 WORD32 i4_ref_height; /*!< reference layer height in 469 terms luma samples 470 */ 471 WORD32 i4_curr_width; /*!< current layer width in 472 terms luma samples 473 */ 474 WORD32 i4_curr_height; /*!< current layer height in 475 terms luma samples 476 */ 477 WORD8 i1_constrained_intra_rsmpl_flag; /*!< Constrained intra resampling 478 flag. Range is [0,1]. 479 */ 480 WORD32 i4_x_phase_0; /*!< Chroma xPhase for even 481 values of x for dyadic cases 482 */ 483 WORD32 i4_x_phase_1; /*!< Chroma xPhase for odd 484 values of x for dyadic cases 485 */ 486 WORD32 i4_y_phase_0; /*!< Chroma yPhase for even 487 values of y for dyadic cases 488 */ 489 WORD32 i4_y_phase_1; /*!< Chroma yPhase for odd 490 values of y for dyadic cases 491 */ 492 pf_vert_interpol_chroma_dyadic pf_vert_chroma_interpol; 493 /*!< Vertical interpolation 494 function for chroma 495 */ 496 pf_horz_interpol_chroma_dyadic pf_horz_chroma_interpol; 497 /*!< Horizontal interpolation 498 function for chroma 499 */ 500 } intra_samp_lyr_ctxt; 501 typedef struct 502 { 503 intra_samp_lyr_ctxt as_res_lyrs[MAX_NUM_RES_LYRS]; /*!< Array of resolution 504 layer ctxt. 505 The first strcuture in the 506 array will be used for storing 507 the "second resolution" map in 508 an access unit w.r.t to its 509 base resolution, and for base 510 resolution nothing will be 511 computed or stored 512 */ 513 void *ps_sps; /*!< pointer to array of SPS 514 */ 515 516 UWORD8 *pu1_refarray_buffer; /*!< buffer to store the reference 517 layer data before intra 518 sampling 519 */ 520 UWORD8 *pu1_refarray_cb; /*!< buffer to hold the reference 521 layer Cb data before intra 522 resampling (used for dyadic 523 cases only) 524 */ 525 UWORD8 *pu1_refarray_cr; /*!< buffer to hold the reference 526 layer Cr data before intra 527 resampling (used for dyadic 528 cases only) 529 */ 530 WORD32 *pi4_temp_interpolation_buffer; /*!< intermideate buffer 531 for interpolation 532 */ 533 534 WORD32 i4_res_lyr_id; /*!< resolution id of the layer 535 which is to be processed 536 */ 537 WORD32 i4_ref_width; /*!< reference layer width in 538 terms luma samples 539 */ 540 541 WORD32 i4_refarray_stride; /*!< reference layer width in 542 terms luma samples 543 */ 544 545 WORD32 i4_ref_height; /*!< reference layer height in 546 terms luma samples 547 */ 548 res_prms_t *ps_res_prms; /*!< Current resolution params 549 */ 550 } intra_sampling_ctxt_t; 551 552 void svcd_intra_samp_mb_dyadic(void *pv_intra_samp_ctxt, mem_element_t *ps_ref_luma, 553 mem_element_t *ps_ref_chroma, mem_element_t *ps_ref_mb_mode_map, 554 mem_element_t *ps_curr_luma, mem_element_t *ps_curr_chroma, 555 UWORD16 u2_mb_x, UWORD16 u2_mb_y, void *ps_dec); 556 557 void svcd_residual_samp_mb_dyadic(void *pv_residual_samp_ctxt, mem_element_t *ps_ref_luma, 558 mem_element_t *ps_ref_chroma, mem_element_t *ps_ref_luma_bitmap, 559 mem_element_t *ps_ref_chroma_bitmap, 560 mem_element_t *ps_ref_mb_mode, mem_element_t *ps_out_luma, 561 mem_element_t *ps_out_chroma, UWORD16 u2_mb_x, UWORD16 u2_mb_y); 562 563 void svcd_intra_samp_populate_res_prms(void *ps_dec); 564 565 void svcd_intra_samp_res_init(void *pv_intra_samp_ctxt, res_prms_t *ps_curr_lyr_res_prms, 566 ref_mb_map_t **pps_luma_map_horz, ref_mb_map_t **pps_chroma_map_horz, 567 ref_mb_map_t **pps_luma_map_vert, ref_mb_map_t **pps_chroma_map_vert, 568 void *ps_dec); 569 570 #endif /* _ISVCD_RESAMP_SVC_H_ */ 571