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