xref: /aosp_15_r20/external/libhevc/encoder/hme_interface.h (revision c83a76b084498d55f252f48b2e3786804cdf24b7)
1 /******************************************************************************
2  *
3  * Copyright (C) 2018 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 hme_interface.h
23 *
24 * \brief
25 *    Interfaces exported by ME to the world outside of ME
26 *
27 * \date
28 *    18/09/2012
29 *
30 * \author
31 *    Ittiam
32 *
33 ******************************************************************************
34 */
35 
36 #ifndef _HME_INTERFACE_H_
37 #define _HME_INTERFACE_H_
38 
39 /*****************************************************************************/
40 /* Constant Macros                                                           */
41 /*****************************************************************************/
42 
43 /**
44 ******************************************************************************
45  *  @brief      Maximum number of layers allowed
46 ******************************************************************************
47  */
48 #define MAX_NUM_LAYERS 4
49 
50 /**
51 ******************************************************************************
52  *  @brief      layer max dimensions
53 ******************************************************************************
54  */
55 #define HME_MAX_WIDTH 1920
56 #define HME_MAX_HEIGHT 1088
57 
58 /**
59 ******************************************************************************
60  *  @brief      layer min dimensions
61 ******************************************************************************
62  */
63 #define MIN_WD_COARSE 16
64 #define MIN_HT_COARSE 16
65 
66 /**
67 ******************************************************************************
68  *  @brief     HME COARSE LAYER STEP SIZE
69 ******************************************************************************
70  */
71 
72 #define HME_COARSE_STEP_SIZE_HIGH_SPEED 4
73 #define HME_COARSE_STEP_SIZE_HIGH_QUALITY 2
74 
75 /**
76 ******************************************************************************
77  *  @brief      Memtabs required by layer ctxt: each layer ctxt requires 1
78  *               memtab for itslf, 1 for mv bank, 1 for ref idx bank, one
79  *               for input bufffer and 1 for storing segmentation info in
80  *               worst case
81 ******************************************************************************
82  */
83 #define HME_MEMTABS_COARSE_LAYER_CTXT (5 * (MAX_NUM_LAYERS - 1) * (MAX_NUM_REF + 1))
84 
85 /**
86 ******************************************************************************
87  *  @brief      Total number of memtabs reuqired by HME. Atleast 22 memtabs
88  *              for different search results structure, 2*MAX_NUM_REF memtabs
89  *              for search nodes maintaining coarse layer results in prev
90  *              row, and for histograms. Memtabs reqd for layer,me ctxt
91  *              ctb node mgr and buf mgr plus some 8 for safety
92  *              if multi threaded then some memtabs will be more
93 ******************************************************************************
94  */
95 #define HME_COARSE_TOT_MEMTABS                                                                     \
96     (22 + HME_MEMTABS_COARSE_LAYER_CTXT + (3 * MAX_NUM_REF) + 8 * MAX_NUM_FRM_PROC_THRDS_PRE_ENC + \
97      1)
98 
99 /**
100 ******************************************************************************
101  *  @brief      Memtabs required by layer ctxt (enc): each layer ctxt requires 1
102  *               memtab for itslf, 1 for mv bank, 1 for ref idx bank, one
103  *               for input bufffer and 1 for storing segmentation info in
104  *               worst case
105 ******************************************************************************
106  */
107 #define MIN_HME_MEMTABS_ENC_LAYER_CTXT (5 * 1 * (MAX_NUM_REF + 1))
108 
109 #define MAX_HME_MEMTABS_ENC_LAYER_CTXT (5 * 1 * (MAX_NUM_REF + 1 + MAX_NUM_ME_PARALLEL))
110 
111 /**
112 ******************************************************************************
113  *  @brief      Total number of memtabs reuqired by HME. Atleast 22 memtabs
114  *              for different search results structure, 2*MAX_NUM_REF memtabs
115  *              for search nodes maintaining coarse layer results in prev
116  *              row, and for histograms. Memtabs reqd for layer,me ctxt
117  *              ctb node mgr and buf mgr plus some 8 for safety
118  *              if multi threaded then some memtabs will be more
119 ******************************************************************************
120  */
121 
122 #define MIN_HME_ENC_TOT_MEMTABS                                                                    \
123     (22 + MIN_HME_MEMTABS_ENC_LAYER_CTXT + (3 * MAX_NUM_REF) + 28 * MAX_NUM_FRM_PROC_THRDS_ENC +   \
124      2 /* Clustering */ + 1 /*traqo*/ + 1 /* ME Optimised Function List */)
125 
126 #define MAX_HME_ENC_TOT_MEMTABS                                                                    \
127     ((22 * MAX_NUM_ME_PARALLEL) + MAX_HME_MEMTABS_ENC_LAYER_CTXT +                                 \
128      (3 * MAX_NUM_REF * MAX_NUM_ME_PARALLEL) +                                                     \
129      28 * MAX_NUM_FRM_PROC_THRDS_ENC * MAX_NUM_ME_PARALLEL + 2 /* Clustering */ + 1 /*traqo*/ +    \
130      1 /* ME Optimised Function List */)
131 
132 /*****************************************************************************/
133 /* Enumerations                                                              */
134 /*****************************************************************************/
135 /**
136 ******************************************************************************
137  *  @enum     HME_MEM_ATTRS_T
138  *  @brief      Contains type of memory: scratch, scratch ovly, persistent
139 ******************************************************************************
140  */
141 typedef enum
142 {
143     HME_SCRATCH_MEM,
144     HME_SCRATCH_OVLY_MEM,
145     HME_PERSISTENT_MEM
146 } HME_MEM_ATTRS_T;
147 
148 /**
149 ******************************************************************************
150  *  @enum     ME_QUALITY_PRESETS_T
151  *  @brief    Describes the source for values in me_quality_params_t struct
152 ******************************************************************************
153  */
154 typedef enum
155 {
156     ME_PRISTINE_QUALITY = 0,
157     ME_HIGH_QUALITY = 2,
158     ME_MEDIUM_SPEED,
159     ME_HIGH_SPEED,
160     ME_XTREME_SPEED,
161     ME_XTREME_SPEED_25
162 } ME_QUALITY_PRESETS_T;
163 
164 /*****************************************************************************/
165 /* Structures                                                                */
166 /*****************************************************************************/
167 
168 /**
169 ******************************************************************************
170  *  @struct     hme_ref_buf_info_t
171  *  @brief      Contains all required information of a ref picture
172  *              Valid for a given layer.
173 ******************************************************************************
174  */
175 typedef struct
176 {
177     /** Amt of padding in X direction both sides. */
178     U08 u1_pad_x;
179 
180     /** Amt of padding in Y direction both sides */
181     U08 u1_pad_y;
182 
183     /** Recon stride, in pixels */
184     S32 luma_stride;
185 
186     /** Offset w.r.t. actual start of the buffer */
187     S32 luma_offset;
188 
189     /** Src ptrs of the reference pictures*/
190     U08 *pu1_ref_src;
191 
192     /** Reference ptrs for fpel plane, needed for this layer closed loop ME */
193     U08 *pu1_rec_fxfy;
194 
195     /** Reference ptrs for hxfy plane (x = k+0.5, y = m) */
196     U08 *pu1_rec_hxfy;
197 
198     /** Reference ptrs for fxhy plane (x = k, y = m + 0.5 */
199     U08 *pu1_rec_fxhy;
200 
201     /** Reference ptrs for hxhy plane (x = k + 0.5, y = m + 0.5 */
202     U08 *pu1_rec_hxhy;
203 
204     /** Reference ptr for u plane */
205     U08 *pu1_rec_u;
206 
207     /** Reference ptr for v plane */
208     U08 *pu1_rec_v;
209 
210     /** chroma plane stride in pixels */
211     S32 chroma_stride;
212 
213     S32 chroma_offset;
214 
215     /** Pointer to dependency manager of recon buffer */
216     void *pv_dep_mngr;
217 
218 } hme_ref_buf_info_t;
219 
220 /**
221 ******************************************************************************
222  *  @struct     interp_prms_t
223  *  @brief      All parameters for the interpolation function
224 ******************************************************************************
225  */
226 typedef struct
227 {
228     /** Array of ptr of 4 planes in order fxfy, hxfy, fxhy, hxhy */
229     U08 **ppu1_ref;
230 
231     /**
232      *  Array of pointers for ping-pong buffers, used to store interp out
233      *  Output during a call goes to any one of these buffers
234      */
235     U08 *apu1_interp_out[5];
236 
237     /**
238      *  Working memory to store 16 bit intermediate output. This has to be
239      *  of size i4_blk_wd * (i4_blk_ht + 7) * 2
240      */
241     U08 *pu1_wkg_mem;
242 
243     /** Stride of all 4 planes of ref buffers */
244     S32 i4_ref_stride;
245 
246     /** Width of interpolated output blk desired */
247     S32 i4_blk_wd;
248 
249     /** Ht of interpolated output blk desired */
250     S32 i4_blk_ht;
251 
252     /**
253      *  Stride of interpolated output bufers,
254      *  applicable for both ping and pong
255      */
256     S32 i4_out_stride;
257 
258     /** Final output pointer, which may be one of ping-pong or hpel planes */
259     U08 *pu1_final_out;
260 
261     /** STride of the output bfufer */
262     S32 i4_final_out_stride;
263 
264 } interp_prms_t;
265 
266 /*****************************************************************************/
267 /* Typedefs                                                                  */
268 /*****************************************************************************/
269 typedef void (*PF_EXT_UPDATE_FXN_T)(void *, void *, S32, S32);
270 
271 //typedef void (*PF_GET_INTRA_CU_AND_COST)(void *, S32, S32, S32 *, S32*, double *, S32);
272 
273 typedef void (*PF_INTERP_FXN_T)(interp_prms_t *ps_prms, S32 i4_mv_x, S32 i4_mv_y, S32 interp_buf_id);
274 
275 typedef void (*PF_SCALE_FXN_T)(
276     U08 *pu1_src, S32 src_stride, U08 *pu1_dst, S32 dst_stride, S32 wd, S32 ht, U08 *pu1_wkg_mem);
277 
278 /**
279 ******************************************************************************
280  *  @struct     hme_ref_desc_t
281  *  @brief      Contains all reqd information for ref pics across all layers
282  *              but for a given POC/ref id
283 ******************************************************************************
284  */
285 typedef struct
286 {
287     /**
288      *  Reference id in LC list. This is a unified list containing both fwd
289      *  and backward direction references. Having a unified list just does
290      *  a unique mapping of frames to ref id and eases out addressing in the
291      *  ME search.
292      */
293     S08 i1_ref_id_lc;
294 
295     /**
296      *  Reference id in L0 list. Priority is given to temporally fwd dirn
297      *  unless of a scene change like case
298      */
299     S08 i1_ref_id_l0;
300 
301     /**
302      *  Reference id in L1 list. Priority to backward dirn unless scene change
303      *  like case
304     */
305     S08 i1_ref_id_l1;
306 
307     /** Whether this ref is temporally forward w.r.t. current pic */
308     U08 u1_is_fwd;
309 
310     /** POC of this ref pic. */
311     S32 i4_poc;
312 
313     /** display_num of this ref pic. */
314     S32 i4_display_num;
315     /**
316      *  Lambda to be used for S + lambda*bits style cost computations when
317      *  using this ref pic. This is a function of ref dist and hence diff
318      *  ref has diff lambda
319      */
320     S32 lambda;
321 
322     /** Ref buffer info for all layers */
323     hme_ref_buf_info_t as_ref_info[MAX_NUM_LAYERS];
324 
325     /** Weights and offset of reference picture
326      * used for weighted pred analysis
327      */
328     S16 i2_weight;
329 
330     S16 i2_offset;
331 
332     /*
333     * IDR GOP number
334     */
335 
336     WORD32 i4_GOP_num;
337 
338 } hme_ref_desc_t;
339 
340 /**
341 ******************************************************************************
342  *  @struct     hme_ref_map_t
343  *  @brief      Complete ref information across all layers and POCs
344  *              Information valid for a given inp frame with a given POC.
345 ******************************************************************************
346  */
347 typedef struct
348 {
349     /** Number of active ref picturs in LC list */
350     S32 i4_num_ref;
351 
352     /** Recon Pic buffer pointers for L0 list */
353     recon_pic_buf_t **pps_rec_list_l0;
354 
355     /** Recon Pic buffer pointers for L0 list */
356     recon_pic_buf_t **pps_rec_list_l1;
357 
358     /** Reference descriptors for all ref pics */
359     hme_ref_desc_t as_ref_desc[MAX_NUM_REF];
360 
361 } hme_ref_map_t;
362 
363 /**
364  ******************************************************************************
365  *  @struct me_coding_params_t
366  *  @param e_me_quality_presets : Quality preset value
367  *  @brief  ME Parameters that affect quality depending on their state
368  ******************************************************************************
369 */
370 typedef struct
371 {
372     ME_QUALITY_PRESETS_T e_me_quality_presets;
373 
374     S32 i4_num_steps_hpel_refine;
375 
376     S32 i4_num_steps_qpel_refine;
377 
378     U08 u1_l0_me_controlled_via_cmd_line;
379 
380     U08 u1_num_results_per_part_in_l0me;
381 
382     U08 u1_num_results_per_part_in_l1me;
383 
384     U08 u1_num_results_per_part_in_l2me;
385 
386     U08 u1_max_num_coloc_cands;
387 
388     U08 u1_max_2nx2n_tu_recur_cands;
389 
390     U08 u1_max_num_fpel_refine_centers;
391 
392     U08 u1_max_num_subpel_refine_centers;
393 } me_coding_params_t;
394 
395 /**
396  ******************************************************************************
397  *  @struct hme_init_prms_t
398  *  @brief  Initialization parameters used during HME instance creation
399  ******************************************************************************
400 */
401 typedef struct
402 {
403     /** Pointer to widths of various simulcast layers,
404      * starting with biggest resolution
405      */
406     S32 a_wd[MAX_NUM_LAYERS];
407 
408     /** Pointer to heights of various simulcast layers,
409      *  starting with biggest resolution
410      */
411     S32 a_ht[MAX_NUM_LAYERS];
412 
413     /** Maximum number of reference frames that a frame ever has to search */
414     S32 max_num_ref;
415 
416     /** Number of results to be stored in the coarsest layer */
417     S32 max_num_results_coarse;
418 
419     /**
420      *  Number of layers for which explicit ME is to be done
421      *  0 or MAX_NUM_LAYERS: encoder will do explicit ME for all layers
422      *  anything in between, explicit ME done for that many layers
423      */
424     S32 num_layers_explicit_search;
425 
426     /** Number of simulcast layers to be encoded */
427     S32 num_simulcast_layers;
428 
429     /** Maximum number of results per reference per partition */
430     S32 max_num_results;
431 
432     /**
433      *  If enabled, all layers store segmentation info at 16x16 lvl
434      *  If not enabled, then only finest layer stores this info
435      */
436     S32 segment_higher_layers;
437 
438     /**
439      *  If enabled, the non enocde layers use 8x8 blks with 4x4 partial
440      *  sads also being evaluated, which is more powerful but computationally
441      *  less efficient
442      */
443     S32 use_4x4;
444 
445     /**
446      *  Number of B frames allowed between P frames
447      */
448     S32 num_b_frms;
449 
450     /** CTB Size as passed by encoder */
451     S32 log_ctb_size;
452 
453     /** number of threads created run time */
454     S32 i4_num_proc_thrds;
455 
456     /* This struct contains fields corresponding to quality knobs for ME */
457     me_coding_params_t s_me_coding_tools;
458 
459     S32 max_vert_search_range;
460 
461     S32 max_horz_search_range;
462 
463     S32 is_interlaced;
464 
465     U08 u1_max_tr_depth;
466 
467     U08 u1_is_stasino_enabled;
468 
469     IV_ARCH_T e_arch_type;
470 } hme_init_prms_t;
471 
472 /**
473  ******************************************************************************
474  *  @struct hme_frm_prms_t
475  *  @brief  Frame level prms for HME execution
476  ******************************************************************************
477 */
478 typedef struct
479 {
480     /** Range of the Motion vector in fpel units at finest layer x dirn */
481     S16 i2_mv_range_x;
482 
483     /** range of motion vector in fpel units at finest layer y dirn */
484     S16 i2_mv_range_y;
485 
486     /** Context for computing the cost function */
487     void *pv_mv_cost_ctxt;
488 
489     /** Interpolation function pointers */
490     PF_INTERP_FXN_T pf_interp_fxn;
491 
492     U08 is_i_pic;
493 
494     S32 bidir_enabled;
495 
496     S32 i4_temporal_layer_id;
497 
498     /**
499       * Lambda values in Q format. 4 values exist: Closed loop SATD/SAD
500       * and open loop SATD/SAD
501       */
502     S32 i4_cl_sad_lambda_qf;
503     S32 i4_cl_satd_lambda_qf;
504     S32 i4_ol_sad_lambda_qf;
505     S32 i4_ol_satd_lambda_qf;
506 
507     /** Shift for lambda QFormat */
508     S32 lambda_q_shift;
509 
510     S32 qstep;
511     S32 qstep_ls8;
512     S32 i4_frame_qp;
513     S32 is_pic_second_field;
514 
515     /**
516      * Number of active references in l0
517      */
518     U08 u1_num_active_ref_l0;
519 
520     /**
521      * Number of active references in l1
522      */
523     U08 u1_num_active_ref_l1;
524 
525     /* Flag that specifies whether CU level QP */
526     /* modulation is enabled */
527     U08 u1_is_cu_qp_delta_enabled;
528 
529 } hme_frm_prms_t;
530 
531 /**
532  ******************************************************************************
533  *  @struct hme_memtab_t
534  *  @brief  Structure to return memory requirements for one buffer.
535  ******************************************************************************
536 */
537 typedef struct
538 {
539     /** Base of the memtab. Filled by application */
540     U08 *pu1_mem;
541 
542     /** Required size of the memtab. Filed by module */
543     S32 size;
544 
545     /** Alignment required */
546     S32 align;
547 
548     /** type of memory */
549     HME_MEM_ATTRS_T e_mem_attr;
550 
551 } hme_memtab_t;
552 
553 /**
554  ******************************************************************************
555  *  @struct hme_inp_buf_attr_t
556  *  @brief  Attributes of input buffer and planes
557  ******************************************************************************
558 */
559 typedef struct
560 {
561     /** Luma ptr 0, 0 position */
562     U08 *pu1_y;
563 
564     /** Cb component or U component, 0, 0 position */
565     U08 *pu1_u;
566 
567     /** Cr component or V component, 0, 0 position */
568     U08 *pu1_v;
569 
570     /** Stride of luma component in pixels */
571     S32 luma_stride;
572 
573     /** Stride of chroma component in pixels */
574     S32 chroma_stride;
575 } hme_inp_buf_attr_t;
576 
577 /**
578  ******************************************************************************
579  *  @struct hme_inp_desc_t
580  *  @brief  Descriptor of a complete input frames (all simulcast layers incl)
581  ******************************************************************************
582 */
583 typedef struct
584 {
585     /** input attributes for all simulcast layers */
586     hme_inp_buf_attr_t s_layer_desc[MAX_NUM_LAYERS];
587 
588     /** POC of the current input frame */
589     S32 i4_poc;
590 
591     /** idr GOP number*/
592     S32 i4_idr_gop_num;
593 
594     /** is refence picture */
595     S32 i4_is_reference;
596 
597 } hme_inp_desc_t;
598 
599 /*****************************************************************************/
600 /* Extern Function Declarations                                              */
601 /*****************************************************************************/
602 
603 /**
604 ********************************************************************************
605 *  @fn     hme_enc_num_alloc()
606 *
607 *  @brief  returns number of memtabs that is required by hme module
608 *
609 *  @return   Number of memtabs required
610 ********************************************************************************
611 */
612 S32 hme_enc_num_alloc(WORD32 i4_num_me_frm_pllel);
613 
614 /**
615 ********************************************************************************
616 *  @fn     hme_coarse_num_alloc()
617 *
618 *  @brief  returns number of memtabs that is required by hme module
619 *
620 *  @return   Number of memtabs required
621 ********************************************************************************
622 */
623 S32 hme_coarse_num_alloc();
624 
625 /**
626 ********************************************************************************
627 *  @fn     hme_coarse_dep_mngr_num_alloc()
628 *
629 *  @brief  returns number of memtabs that is required by Dep Mngr for hme module
630 *
631 *  @return   Number of memtabs required
632 ********************************************************************************
633 */
634 WORD32 hme_coarse_dep_mngr_num_alloc();
635 
636 /**
637 ********************************************************************************
638 *  @fn     S32 hme_coarse_alloc(hme_memtab_t *ps_memtabs, hme_init_prms_t *ps_prms)
639 *
640 *  @brief  Fills up memtabs with memory information details required by HME
641 *
642 *  @param[out] ps_memtabs : Pointre to an array of memtabs where module fills
643 *              up its requirements of memory
644 *
645 *  @param[in] ps_prms : Input parameters to module crucial in calculating reqd
646 *                       amt of memory
647 *
648 *  @return   Number of memtabs required
649 *******************************************************************************
650 */
651 S32 hme_coarse_alloc(hme_memtab_t *ps_memtabs, hme_init_prms_t *ps_prms);
652 
653 /**
654 *******************************************************************************
655 *  @fn hme_coarse_dep_mngr_alloc
656 *
657 *  @brief  Fills up memtabs with memory information details required by Coarse HME
658 *
659 * \param[in,out]  ps_mem_tab : pointer to memory descriptors table
660 * \param[in] ps_init_prms : Create time static parameters
661 * \param[in] i4_mem_space : memspace in whihc memory request should be done
662 *
663 *  @return   Number of memtabs required
664 *******************************************************************************
665 */
666 WORD32 hme_coarse_dep_mngr_alloc(
667     iv_mem_rec_t *ps_mem_tab,
668     ihevce_static_cfg_params_t *ps_init_prms,
669     WORD32 i4_mem_space,
670     WORD32 i4_num_proc_thrds,
671     WORD32 i4_resolution_id);
672 
673 /**
674 ********************************************************************************
675 *  @fn     S32 hme_enc_alloc(hme_memtab_t *ps_memtabs, hme_init_prms_t *ps_prms)
676 *
677 *  @brief  Fills up memtabs with memory information details required by HME
678 *
679 *  @param[out] ps_memtabs : Pointer to an array of memtabs where module fills
680 *              up its requirements of memory
681 *
682 *  @param[in] ps_prms : Input parameters to module crucial in calculating reqd
683 *                       amt of memory
684 *
685 *  @return   Number of memtabs required
686 *******************************************************************************
687 */
688 S32 hme_enc_alloc(hme_memtab_t *ps_memtabs, hme_init_prms_t *ps_prms, WORD32 i4_num_me_frm_pllel);
689 
690 /**
691 ********************************************************************************
692 *  @fn     S32 hme_enc_init(void *pv_ctxt,
693 *                       hme_memtab_t *ps_memtabs,
694 *                       hme_init_prms_t *ps_prms);
695 *
696 *  @brief  Initialization (one time) of HME
697 *
698 *  @param[in,out] pv_ctxt : Pointer to context of HME
699 *
700 *  @param[in] ps_memtabs : updated memtabs by application (allocated memory)
701 *
702 *  @param[in] ps_prms : Initialization parametres
703 *
704 *  @return   0 : success, -1 : failure
705 *******************************************************************************
706 */
707 S32 hme_enc_init(
708     void *pv_ctxt,
709     hme_memtab_t *ps_memtabs,
710     hme_init_prms_t *ps_prms,
711     rc_quant_t *ps_rc_quant_ctxt,
712     WORD32 i4_num_me_frm_pllel);
713 
714 /**
715 ********************************************************************************
716 *  @fn     S32 hme_coarse_init(void *pv_ctxt,
717 *                       hme_memtab_t *ps_memtabs,
718 *                       hme_init_prms_t *ps_prms);
719 *
720 *  @brief  Initialization (one time) of HME
721 *
722 *  @param[in,out] pv_ctxt : Pointer to context of HME
723 *
724 *  @param[in] ps_memtabs : updated memtabs by application (allocated memory)
725 *
726 *  @param[in] ps_prms : Initialization parametres
727 *
728 *  @return   0 : success, -1 : failure
729 *******************************************************************************
730 */
731 S32 hme_coarse_init(void *pv_ctxt, hme_memtab_t *ps_memtabs, hme_init_prms_t *ps_prms);
732 
733 /*!
734 ******************************************************************************
735 * \if Function name : ihevce_coarse_me_get_lyr_prms_dep_mngr \endif
736 *
737 * \brief Returns to the caller key attributes relevant for dependency manager,
738 *        ie, the number of vertical units in each layer
739 *
740 * \par Description:
741 *    This function requires the precondition that the width and ht of encode
742 *    layer is known.
743 *    The number of layers, number of vertical units in each layer, and for
744 *    each vertial unit in each layer, its dependency on previous layer's units
745 *    From ME's perspective, a vertical unit is one which is smallest min size
746 *    vertically (and spans the entire row horizontally). This is CTB for encode
747 *    layer, and 8x8 / 4x4 for non encode layers.
748 *
749 * \param[in] num_layers : Number of ME Layers
750 * \param[in] pai4_ht    : Array storing ht at each layer
751 * \param[in] pai4_wd    : Array storing wd at each layer
752 * \param[out] pi4_num_vert_units_in_lyr : Array of size N (num layers), each
753 *                     entry has num vertical units in that particular layer
754 *
755 * \return
756 *    None
757 *
758 * \author
759 *  Ittiam
760 *
761 *****************************************************************************
762 */
763 void ihevce_coarse_me_get_lyr_prms_dep_mngr(
764     WORD32 num_layers, WORD32 *pai4_ht, WORD32 *pai4_wd, WORD32 *pai4_num_vert_units_in_lyr);
765 
766 /**
767 ********************************************************************************
768 *  @fn     hme_coarse_dep_mngr_alloc_mem()
769 *
770 *  @brief  Requests/ assign memory for HME Dep Mngr
771 *
772 * \param[in,out]  ps_mem_tab : pointer to memory descriptors table
773 * \param[in] ps_init_prms : Create time static parameters
774 * \param[in] i4_mem_space : memspace in whihc memory request should be done
775 *
776 *  @return  number of memtabs
777 ********************************************************************************
778 */
779 WORD32 hme_coarse_dep_mngr_alloc_mem(
780     iv_mem_rec_t *ps_mem_tab,
781     ihevce_static_cfg_params_t *ps_init_prms,
782     WORD32 i4_mem_space,
783     WORD32 i4_num_proc_thrds,
784     WORD32 i4_resolution_id);
785 
786 /**
787 ********************************************************************************
788 *  @fn     hme_coarse_dep_mngr_init()
789 *
790 *  @brief  Assign memory for HME Dep Mngr
791 *
792 * \param[in,out]  ps_mem_tab : pointer to memory descriptors table
793 * \param[in] ps_init_prms : Create time static parameters
794 *  @param[in] pv_ctxt : ME ctxt
795 * \param[in] pv_osal_handle : Osal handle
796 *
797 *  @return  number of memtabs
798 ********************************************************************************
799 */
800 WORD32 hme_coarse_dep_mngr_init(
801     iv_mem_rec_t *ps_mem_tab,
802     ihevce_static_cfg_params_t *ps_init_prms,
803     void *pv_ctxt,
804     void *pv_osal_handle,
805     WORD32 i4_num_proc_thrds,
806     WORD32 i4_resolution_id);
807 
808 /**
809 ********************************************************************************
810 *  @fn     hme_coarse_dep_mngr_reg_sem()
811 *
812 *  @brief  Assign semaphores for HME Dep Mngr
813 *
814 * \param[in] pv_me_ctxt : pointer to Coarse ME ctxt
815 * \param[in] ppv_sem_hdls : Arry of semaphore handles
816 * \param[in] i4_num_proc_thrds : Number of processing threads
817 *
818 *  @return  number of memtabs
819 ********************************************************************************
820 */
821 void hme_coarse_dep_mngr_reg_sem(void *pv_ctxt, void **ppv_sem_hdls, WORD32 i4_num_proc_thrds);
822 
823 /**
824 ********************************************************************************
825 *  @fn     hme_coarse_dep_mngr_delete()
826 *
827 *    Destroy Coarse ME Dep Mngr module
828 *   Note : Only Destroys the resources allocated in the module like
829 *   semaphore,etc. Memory free is done Separately using memtabs
830 *
831 * \param[in] pv_me_ctxt : pointer to Coarse ME ctxt
832 * \param[in] ps_init_prms : Create time static parameters
833 *
834 *  @return  none
835 ********************************************************************************
836 */
837 void hme_coarse_dep_mngr_delete(
838     void *pv_me_ctxt, ihevce_static_cfg_params_t *ps_init_prms, WORD32 i4_resolution_id);
839 
840 void hme_coarse_get_layer1_mv_bank_ref_idx_size(
841     S32 n_tot_layers,
842     S32 *a_wd,
843     S32 *a_ht,
844     S32 max_num_ref,
845     S32 *pi4_mv_bank_size,
846     S32 *pi4_ref_idx_size);
847 
848 /**
849 ********************************************************************************
850 *  @fn     S32 hme_add_inp(void *pv_ctxt,
851 *                       hme_inp_desc_t *ps_inp_desc);
852 *
853 *  @brief  Updates the HME context with details of the input buffers and POC.
854 *          Layers that are not encoded are processed further in terms of
855 *          pyramid generation.
856 *
857 *  @param[in,out] pv_ctxt : Pointer to context of HME
858 *
859 *  @param[in] ps_inp_desc : Input descriptor containing information of all
860 *             simulcast layers of input.
861 *
862 *  @return   void
863 *******************************************************************************
864 */
865 void hme_add_inp(void *pv_ctxt, hme_inp_desc_t *ps_inp_desc, S32 me_frm_id, WORD32 thrd_id);
866 
867 void hme_coarse_add_inp(void *pv_me_ctxt, hme_inp_desc_t *ps_inp_desc, WORD32 i4_curr_idx);
868 
869 /**
870 ********************************************************************************
871 *  @fn     hme_process_frm_init
872 *
873 *  @brief  HME frame level initialsation processing function
874 *
875 *  @param[in] pv_me_ctxt : ME ctxt pointer
876 *
877 *  @param[in] ps_ref_map : Reference map prms pointer
878 *
879 *  @param[in] ps_frm_prms :Pointer to frame params
880 *
881 *  @return Scale factor in Q8 format
882 ********************************************************************************
883 */
884 
885 void hme_process_frm_init(
886     void *pv_me_ctxt,
887     hme_ref_map_t *ps_ref_map,
888     hme_frm_prms_t *ps_frm_prms,
889     WORD32 me_frm_id,
890     WORD32 i4_num_me_frm_pllel);
891 
892 void hme_coarse_process_frm_init(
893     void *pv_me_ctxt, hme_ref_map_t *ps_ref_map, hme_frm_prms_t *ps_frm_prms);
894 
895 /**
896 ********************************************************************************
897 *  @fn     void hme_process_frm(void *pv_ctxt,
898 *                    hme_ref_map_t *ps_ref_map,
899 *                    U16 **ppu2_intra_cost,
900 *                    hme_frm_prms_t *ps_frm_prms);
901 *
902 *  @brief  Processes all the layers of the input, and updates the MV Banks.
903 *          Note that this function is not to be called if processing of a single
904 *          layer is desired.
905 *
906 *  @param[in,out] pv_ctxt : Pointer to context of HME
907 *
908 *  @param[in] ps_ref_map : Map structure that has for current input, lists of
909 *             ref pics (POC) mapping to LC, L0 and L1, and buffer ptrs as well
910 *             Informatino for all simulcast layers present.
911 *
912 *  @param[in] ppu2_intra_cost : array of Pointer to intra cost evaluated at an
913 *              8x8 level, stored in raster order. At each layer, the
914 *              corresponding ptr points to raster ordered array of wdxht/64,
915 *              wd and ht are layer width and ht respectively. Also, note that
916 *              ppu2_intra_cost[0] points to biggest resolution layer,
917 *              and from there on in decreasing order of size.
918 *
919 * @param[in]  ps_frm_prms : input frame parameters (excluding ref info) that
920 *             control the search complexity. Refer to hme_frm_prms_t for more
921 *              info regards the same.
922 *
923 *  @return   void
924 *******************************************************************************
925 */
926 
927 void hme_process_frm(
928     void *pv_me_ctxt,
929     pre_enc_L0_ipe_encloop_ctxt_t *ps_l0_ipe_input,
930     hme_ref_map_t *ps_ref_map,
931     double **ppd_intra_costs,
932     hme_frm_prms_t *ps_frm_prms,
933     PF_EXT_UPDATE_FXN_T pf_ext_update_fxn,
934     //PF_GET_INTRA_CU_AND_COST pf_get_intra_cu_and_cost,
935     void *pv_coarse_layer,
936     void *pv_multi_thrd_ctxt,
937     WORD32 i4_frame_parallelism_level,
938     S32 thrd_id,
939     S32 i4_me_frm_id);
940 
941 void hme_coarse_process_frm(
942     void *pv_me_ctxt,
943     hme_ref_map_t *ps_ref_map,
944     hme_frm_prms_t *ps_frm_prms,
945     void *pv_multi_thrd_ctxt,
946     WORD32 i4_ping_pong,
947     void **ppv_dep_mngr_hme_sync);
948 
949 void hme_discard_frm(
950     void *pv_ctxt, S32 *p_pocs_to_remove, S32 i4_idr_gop_num, S32 i4_num_me_frm_pllel);
951 
952 void hme_coarse_discard_frm(void *pv_me_ctxt, S32 *p_pocs_to_remove);
953 
954 /**
955 *******************************************************************************
956 *  @fn     S32 hme_set_resolution(void *pv_me_ctxt,
957 *                                   S32 n_enc_layers,
958 *                                   S32 *p_wd,
959 *                                   S32 *p_ht
960 *
961 *  @brief  Sets up the layers based on resolution information.
962 *
963 *  @param[in, out] pv_me_ctxt : ME handle, updated with the resolution info
964 *
965 *  @param[in] n_enc_layers : Number of layers encoded
966 *
967 *  @param[in] p_wd : Pointer to an array having widths for each encode layer
968 *
969 *  @param[in] p_ht : Pointer to an array having heights for each encode layer
970 *
971 *  @return   void
972 *******************************************************************************
973 */
974 
975 void hme_set_resolution(void *pv_me_ctxt, S32 n_enc_layers, S32 *p_wd, S32 *p_ht, S32 me_frm_id);
976 
977 void hme_coarse_set_resolution(void *pv_me_ctxt, S32 n_enc_layers, S32 *p_wd, S32 *p_ht);
978 
979 /**
980 *******************************************************************************
981 *  @fn     WORD32 hme_get_active_pocs_list(void *pv_me_ctxt)
982 *
983 *  @brief  Returns the list of active POCs in ME ctxt
984 *
985 *  @param[in] pv_me_ctxt : handle to ME context
986 *
987 *  @param[out] p_pocs_buffered_in_me : pointer to an array which this fxn
988 *                                      populates with pocs active
989 *
990 *  @return   void
991 *******************************************************************************
992 */
993 WORD32 hme_get_active_pocs_list(void *pv_me_ctxt, S32 i4_num_me_frm_pllel);
994 
995 void hme_coarse_get_active_pocs_list(void *pv_me_ctxt, S32 *p_pocs_buffered_in_me);
996 
997 S32 hme_get_blk_size(S32 use_4x4, S32 layer_id, S32 n_layers, S32 encode);
998 
999 /**
1000 ********************************************************************************
1001 *  @fn     hme_get_mv_blk_size()
1002 *
1003 *  @brief  returns whether blk uses 4x4 size or something else.
1004 *
1005 *  @param[in] enable_4x4 : input param from application to enable 4x4
1006 *
1007 *  @param[in] layer_id : id of current layer (0 finest)
1008 *
1009 *  @param[in] num_layeers : total num layers
1010 *
1011 *  @param[in] is_enc : Whether encoding enabled for layer
1012 *
1013 *  @return   1 for 4x4 blks, 0 for 8x8
1014 ********************************************************************************
1015 */
1016 S32 hme_get_mv_blk_size(S32 enable_4x4, S32 layer_id, S32 num_layers, S32 is_enc);
1017 
1018 void hme_set_refine_prms(
1019     void *pv_refine_prms,
1020     U08 u1_encode,
1021     S32 num_ref,
1022     S32 layer_id,
1023     S32 num_layers,
1024     S32 num_layers_explicit_search,
1025     S32 use_4x4,
1026     hme_frm_prms_t *ps_frm_prms,
1027     double **ppd_intra_costs,
1028     me_coding_params_t *ps_me_coding_tools);
1029 
1030 S32 hme_coarse_find_free_descr_idx(void *pv_ctxt);
1031 
1032 S32 hme_derive_num_layers(S32 n_enc_layers, S32 *p_wd, S32 *p_ht, S32 *p_disp_wd, S32 *p_disp_ht);
1033 
1034 #endif /* #ifndef _HME_INTERFACE_H_ */
1035