Coverage Report

Created: 2025-11-11 07:01

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libhevc/encoder/ihevce_dep_mngr.c
Line
Count
Source
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 ihevce_dep_mngr.c
23
*
24
* \brief
25
*    This file contains all the functions related to Sync manager
26
*
27
* \date
28
*    12/12/2013
29
*
30
* \author
31
*    Ittiam
32
*
33
* List of Functions
34
*   <TODO: TO BE ADDED>
35
*
36
******************************************************************************
37
*/
38
39
/*****************************************************************************/
40
/* File Includes                                                             */
41
/*****************************************************************************/
42
/* System include files */
43
#include <stdio.h>
44
#include <string.h>
45
#include <stdlib.h>
46
#include <assert.h>
47
#include <stdarg.h>
48
#include <math.h>
49
50
/* User include files */
51
#include "ihevc_typedefs.h"
52
#include "itt_video_api.h"
53
#include "ihevc_debug.h"
54
#include "ihevc_macros.h"
55
#include "ihevc_platform_macros.h"
56
57
#include "ihevce_api.h"
58
#include "ihevce_dep_mngr_interface.h"
59
#include "ihevce_dep_mngr_private.h"
60
61
#include "cast_types.h"
62
#include "osal.h"
63
#include "osal_defaults.h"
64
65
/*****************************************************************************/
66
/* Function Definitions                                                      */
67
/*****************************************************************************/
68
69
/*!
70
******************************************************************************
71
* \if Function name : ihevce_dmgr_get_num_mem_recs \endif
72
*
73
* \brief
74
*    Number of memory records are returned for Dependency manager.
75
*
76
* \return
77
*    None
78
*
79
* \author
80
*  Ittiam
81
*
82
*****************************************************************************
83
*/
84
WORD32 ihevce_dmgr_get_num_mem_recs()
85
273k
{
86
273k
    return (NUM_DEP_MNGR_MEM_RECS);
87
273k
}
88
89
/*!
90
******************************************************************************
91
* \if Function name : ihevce_dmgr_get_mem_recs \endif
92
*
93
* \brief
94
*    Memory requirements are returned for Dependency manager.
95
*
96
* \param[in,out]  ps_mem_tab : pointer to memory descriptors table
97
* \param[in] dep_mngr_mode : Mode of operation of dependency manager
98
* \param[in] max_num_vert_units : Maximum nunber of units to be processed
99
* \param[in] num_tile_cols : Number of column tiles for which encoder is working
100
* \param[in] num_threads : Number of threads among which sync will be established
101
* \param[in] i4_mem_space : memspace in which memory request should be done
102
*
103
* \return
104
*    None
105
*
106
* \author
107
*  Ittiam
108
*
109
*****************************************************************************
110
*/
111
WORD32 ihevce_dmgr_get_mem_recs(
112
    iv_mem_rec_t *ps_mem_tab,
113
    WORD32 dep_mngr_mode,
114
    WORD32 max_num_vert_units,
115
    WORD32 num_tile_cols,
116
    WORD32 num_threads,
117
    WORD32 i4_mem_space)
118
84.6k
{
119
84.6k
    WORD32 num_vert_units;
120
84.6k
    WORD32 num_wait_thrd_ids;
121
122
    /* Dependency manager state structure */
123
84.6k
    ps_mem_tab[DEP_MNGR_CTXT].i4_mem_size = sizeof(dep_mngr_state_t);
124
84.6k
    ps_mem_tab[DEP_MNGR_CTXT].e_mem_type = (IV_MEM_TYPE_T)i4_mem_space;
125
84.6k
    ps_mem_tab[DEP_MNGR_CTXT].i4_mem_alignment = 8;
126
127
    /* SANITY CHECK */
128
84.6k
    ASSERT(
129
84.6k
        (DEP_MNGR_FRM_FRM_SYNC == dep_mngr_mode) || (DEP_MNGR_ROW_FRM_SYNC == dep_mngr_mode) ||
130
84.6k
        (DEP_MNGR_ROW_ROW_SYNC == dep_mngr_mode));
131
132
    /* Default value */
133
84.6k
    if(num_tile_cols < 1)
134
0
    {
135
0
        num_tile_cols = 1;
136
0
    }
137
138
    /**************** Get Processed status Memory Requirements *********************/
139
84.6k
    if(DEP_MNGR_FRM_FRM_SYNC == dep_mngr_mode)
140
41.9k
    {
141
        /* for frame to frame sync
142
           2 words are used for holding num units processed prev
143
           2 words are used for holding num units processed curr
144
           */
145
41.9k
        num_vert_units = (2 + 2) * num_threads;
146
41.9k
    }
147
42.7k
    else
148
42.7k
    {
149
        /* for both frm-row and row-row num vertical units in frame is allocated */
150
        /* (* num_tile_cols) as each column tile can separately update and check */
151
42.7k
        num_vert_units = max_num_vert_units * num_tile_cols;
152
42.7k
    }
153
154
84.6k
    ps_mem_tab[DEP_MNGR_UNITS_PRCSD_MEM].i4_mem_size = (sizeof(WORD32) * num_vert_units);
155
84.6k
    ps_mem_tab[DEP_MNGR_UNITS_PRCSD_MEM].e_mem_type = (IV_MEM_TYPE_T)i4_mem_space;
156
84.6k
    ps_mem_tab[DEP_MNGR_UNITS_PRCSD_MEM].i4_mem_alignment = 8;
157
158
    /**************** Get Wait thread ids Memory Requirements *********************/
159
84.6k
    if(DEP_MNGR_FRM_FRM_SYNC == dep_mngr_mode)
160
41.9k
    {
161
        /* for frame to frame sync number of threads worth memory is allocated */
162
41.9k
        num_wait_thrd_ids = num_threads;
163
41.9k
    }
164
42.7k
    else if(DEP_MNGR_ROW_ROW_SYNC == dep_mngr_mode)
165
42.7k
    {
166
        /* for row to row sync number of vertical rows worth memory is allocated */
167
42.7k
        num_wait_thrd_ids = max_num_vert_units;
168
42.7k
    }
169
0
    else
170
0
    {
171
        /* for row to frame sync number of threads * number of vertical rows worth memory is allocated */
172
0
        num_wait_thrd_ids = max_num_vert_units * num_threads;
173
0
    }
174
175
84.6k
    ps_mem_tab[DEP_MNGR_WAIT_THRD_ID_MEM].i4_mem_size = (sizeof(WORD32) * num_wait_thrd_ids);
176
84.6k
    ps_mem_tab[DEP_MNGR_WAIT_THRD_ID_MEM].e_mem_type = (IV_MEM_TYPE_T)i4_mem_space;
177
84.6k
    ps_mem_tab[DEP_MNGR_WAIT_THRD_ID_MEM].i4_mem_alignment = 8;
178
179
    /**************** Get Semaphore Requirements *********************/
180
84.6k
    ps_mem_tab[DEP_MNGR_SEM_HANDLE_MEM].i4_mem_size = (sizeof(void *) * num_threads);
181
84.6k
    ps_mem_tab[DEP_MNGR_SEM_HANDLE_MEM].e_mem_type = (IV_MEM_TYPE_T)i4_mem_space;
182
84.6k
    ps_mem_tab[DEP_MNGR_SEM_HANDLE_MEM].i4_mem_alignment = 8;
183
184
84.6k
    return (NUM_DEP_MNGR_MEM_RECS);
185
84.6k
}
186
187
/*!
188
******************************************************************************
189
* \if Function name : ihevce_dmgr_map_get_mem_recs \endif
190
*
191
* \brief
192
*    Memory requirements are returned for Dependency manager.
193
*
194
* \param[in,out]  ps_mem_tab : pointer to memory descriptors table
195
* \param[in] num_units : Number of units in the map
196
* \param[in] num_threads : Number of threads among which sync will be established
197
* \param[in] i4_mem_space : memspace in which memory request should be done
198
*
199
* \return
200
*    None
201
*
202
* \author
203
*  Ittiam
204
*
205
*****************************************************************************
206
*/
207
WORD32 ihevce_dmgr_map_get_mem_recs(
208
    iv_mem_rec_t *ps_mem_tab, WORD32 num_units, WORD32 num_threads, WORD32 i4_mem_space)
209
34.9k
{
210
    /* Dependency manager state structure */
211
34.9k
    ps_mem_tab[DEP_MNGR_CTXT].i4_mem_size = sizeof(dep_mngr_state_t);
212
34.9k
    ps_mem_tab[DEP_MNGR_CTXT].e_mem_type = (IV_MEM_TYPE_T)i4_mem_space;
213
34.9k
    ps_mem_tab[DEP_MNGR_CTXT].i4_mem_alignment = 8;
214
215
    /**************** Get Processed status Memory Requirements *********************/
216
34.9k
    ps_mem_tab[DEP_MNGR_UNITS_PRCSD_MEM].i4_mem_size = (sizeof(WORD8) * num_units);
217
34.9k
    ps_mem_tab[DEP_MNGR_UNITS_PRCSD_MEM].e_mem_type = (IV_MEM_TYPE_T)i4_mem_space;
218
34.9k
    ps_mem_tab[DEP_MNGR_UNITS_PRCSD_MEM].i4_mem_alignment = 8;
219
220
    /**************** Get Wait thread ids Memory Requirements *********************/
221
    /* Map-mode: semaphore post is unconditionally done on all threads */
222
34.9k
    ps_mem_tab[DEP_MNGR_WAIT_THRD_ID_MEM].i4_mem_size = (sizeof(WORD32) * num_threads);
223
34.9k
    ps_mem_tab[DEP_MNGR_WAIT_THRD_ID_MEM].e_mem_type = (IV_MEM_TYPE_T)i4_mem_space;
224
34.9k
    ps_mem_tab[DEP_MNGR_WAIT_THRD_ID_MEM].i4_mem_alignment = 8;
225
226
    /**************** Get Semaphore Requirements *********************/
227
34.9k
    ps_mem_tab[DEP_MNGR_SEM_HANDLE_MEM].i4_mem_size = (sizeof(void *) * num_threads);
228
34.9k
    ps_mem_tab[DEP_MNGR_SEM_HANDLE_MEM].e_mem_type = (IV_MEM_TYPE_T)i4_mem_space;
229
34.9k
    ps_mem_tab[DEP_MNGR_SEM_HANDLE_MEM].i4_mem_alignment = 8;
230
231
34.9k
    return (NUM_DEP_MNGR_MEM_RECS);
232
34.9k
}
233
234
/*!
235
******************************************************************************
236
* \if Function name : ihevce_dmgr_rst_frm_frm_sync \endif
237
*
238
* \brief
239
*    Resets the values stored to init value
240
*
241
* \param[in,out]  pv_dep_mngr_state  : Pointer to Sync Manager handle.
242
*
243
* \return
244
*    None
245
*
246
* \author
247
*  Ittiam
248
*
249
*****************************************************************************
250
*/
251
void ihevce_dmgr_rst_frm_frm_sync(void *pv_dep_mngr_state)
252
41.9k
{
253
41.9k
    dep_mngr_state_t *ps_dep_mngr_state;
254
41.9k
    WORD32 thrds;
255
41.9k
    ULWORD64 *pu8_num_units_proc_prev;
256
41.9k
    ULWORD64 *pu8_num_units_proc_curr;
257
258
    /* dep manager state structure */
259
41.9k
    ps_dep_mngr_state = (dep_mngr_state_t *)pv_dep_mngr_state;
260
261
    /* Reset the num units processed by each thread */
262
41.9k
    pu8_num_units_proc_curr = (ULWORD64 *)ps_dep_mngr_state->pv_units_prcsd_in_row;
263
41.9k
    pu8_num_units_proc_prev = pu8_num_units_proc_curr + ps_dep_mngr_state->i4_num_thrds;
264
265
    /* Reset the values thread ids waiting */
266
83.8k
    for(thrds = 0; thrds < ps_dep_mngr_state->i4_num_thrds; thrds++)
267
41.9k
    {
268
41.9k
        pu8_num_units_proc_prev[thrds] = 0;
269
41.9k
        pu8_num_units_proc_curr[thrds] = 0;
270
41.9k
        ps_dep_mngr_state->pi4_wait_thrd_id[thrds] = -1;
271
41.9k
    }
272
273
41.9k
    return;
274
41.9k
}
275
276
/*!
277
******************************************************************************
278
* \if Function name : ihevce_dmgr_rst_row_frm_sync \endif
279
*
280
* \brief
281
*    Resets the values stored to init value
282
*
283
* \param[in,out]  pv_dep_mngr_state  : Pointer to Sync Manager handle.
284
*
285
* \return
286
*    None
287
*
288
* \author
289
*  Ittiam
290
*
291
*****************************************************************************
292
*/
293
void ihevce_dmgr_rst_row_frm_sync(void *pv_dep_mngr_state)
294
0
{
295
0
    dep_mngr_state_t *ps_dep_mngr_state;
296
0
    WORD32 ctr, thrds;
297
298
    /* dep manager state structure */
299
0
    ps_dep_mngr_state = (dep_mngr_state_t *)pv_dep_mngr_state;
300
301
    /* Reset the values of number of units processed in a row */
302
0
    for(ctr = 0; ctr < ps_dep_mngr_state->i4_num_vert_units; ctr++)
303
0
    {
304
0
        ((WORD32 *)ps_dep_mngr_state->pv_units_prcsd_in_row)[ctr] = 0;
305
0
    }
306
307
    /* Reset the values thread ids waiting on each row  */
308
0
    for(ctr = 0; ctr < ps_dep_mngr_state->i4_num_vert_units; ctr++)
309
0
    {
310
0
        for(thrds = 0; thrds < ps_dep_mngr_state->i4_num_thrds; thrds++)
311
0
        {
312
0
            ps_dep_mngr_state->pi4_wait_thrd_id[thrds + (ps_dep_mngr_state->i4_num_thrds * ctr)] =
313
0
                -1;
314
0
        }
315
0
    }
316
317
0
    return;
318
0
}
319
320
/*!
321
******************************************************************************
322
* \if Function name : ihevce_dmgr_map_rst_sync \endif
323
*
324
* \brief
325
*    Resets the values stored to init value
326
*
327
* \param[in,out]  pv_dep_mngr_state  : Pointer to Sync Manager handle.
328
*
329
* \return
330
*    None
331
*
332
* \author
333
*  Ittiam
334
*
335
*****************************************************************************
336
*/
337
void ihevce_dmgr_map_rst_sync(void *pv_dep_mngr_state)
338
155k
{
339
155k
    dep_mngr_state_t *ps_dep_mngr_state;
340
155k
    WORD8 *pi1_ptr;
341
342
    /* dep manager state structure */
343
155k
    ps_dep_mngr_state = (dep_mngr_state_t *)pv_dep_mngr_state;
344
345
155k
    pi1_ptr = (WORD8 *)ps_dep_mngr_state->pv_units_prcsd_in_row -
346
155k
              ps_dep_mngr_state->ai4_tile_xtra_ctb[0] * ps_dep_mngr_state->i4_num_horz_units -
347
155k
              ps_dep_mngr_state->ai4_tile_xtra_ctb[1];
348
349
155k
    memset(
350
155k
        pi1_ptr,
351
155k
        MAP_CTB_INIT,
352
155k
        ps_dep_mngr_state->i4_num_vert_units * ps_dep_mngr_state->i4_num_horz_units *
353
155k
            sizeof(WORD8));
354
355
    //ps_dep_mngr_state->i4_frame_map_complete = 0;
356
357
155k
    return;
358
155k
}
359
360
/*!
361
******************************************************************************
362
* \if Function name : ihevce_dmgr_rst_row_row_sync \endif
363
*
364
* \brief
365
*    Resets the values stored to init value
366
*
367
* \param[in,out]  pv_dep_mngr_state  : Pointer to Sync Manager handle.
368
*
369
* \return
370
*    None
371
*
372
* \author
373
*  Ittiam
374
*
375
*****************************************************************************
376
*/
377
void ihevce_dmgr_rst_row_row_sync(void *pv_dep_mngr_state)
378
770k
{
379
770k
    dep_mngr_state_t *ps_dep_mngr_state;
380
770k
    WORD32 ctr;
381
382
    /* dep manager state structure */
383
770k
    ps_dep_mngr_state = (dep_mngr_state_t *)pv_dep_mngr_state;
384
385
    /* Reset the values of number of units processed in a row */
386
2.72M
    for(ctr = 0; ctr < (ps_dep_mngr_state->i4_num_vert_units * ps_dep_mngr_state->i4_num_tile_cols);
387
1.95M
        ctr++)
388
1.95M
    {
389
1.95M
        ((WORD32 *)ps_dep_mngr_state->pv_units_prcsd_in_row)[ctr] = 0;
390
1.95M
    }
391
392
    /* Reset the values thread ids waiting on each row  */
393
2.72M
    for(ctr = 0; ctr < ps_dep_mngr_state->i4_num_vert_units; ctr++)
394
1.95M
    {
395
1.95M
        ps_dep_mngr_state->pi4_wait_thrd_id[ctr] = -1;
396
1.95M
    }
397
398
770k
    return;
399
770k
}
400
401
/*!
402
******************************************************************************
403
* \if Function name : ihevce_dmgr_init \endif
404
*
405
* \brief
406
*    Intialization for Dependency manager state structure .
407
*
408
* \param[in] ps_mem_tab : pointer to memory descriptors table
409
* \param[in] pv_osal_handle : osal handle
410
* \param[in] dep_mngr_mode : Mode of operation of dependency manager
411
* \param[in] max_num_vert_units : Maximum nunber of units to be processed (Frame Data)
412
* \param[in] max_num_horz_units : Maximun Number of Horizontal units to be processed (Frame Data)
413
* \param[in] num_tile_cols : Number of column tiles for which encoder is working
414
* \param[in] sem_enable : Whether you want to enable semaphore or not
415
             1 : Sem. Enabled, 0 : Spin lock enabled (do-while)
416
* \param[in] num_threads : Number of threads among which sync will be established
417
* \param[in] i4_mem_space : memspace in which memory request should be do
418
*
419
* \return
420
*    Handle to context
421
*
422
* \author
423
*  Ittiam
424
*
425
*****************************************************************************
426
*/
427
void *ihevce_dmgr_init(
428
    iv_mem_rec_t *ps_mem_tab,
429
    void *pv_osal_handle,
430
    WORD32 dep_mngr_mode,
431
    WORD32 max_num_vert_units,
432
    WORD32 max_num_horz_units,
433
    WORD32 num_tile_cols,
434
    WORD32 num_threads,
435
    WORD32 sem_enable)
436
84.6k
{
437
84.6k
    dep_mngr_state_t *ps_dep_mngr_state;
438
439
84.6k
    (void)pv_osal_handle;
440
    /* dep manager state structure */
441
84.6k
    ps_dep_mngr_state = (dep_mngr_state_t *)ps_mem_tab[DEP_MNGR_CTXT].pv_base;
442
443
    /* dep manager memory init */
444
84.6k
    ps_dep_mngr_state->ppv_thrd_sem_handles = (void **)ps_mem_tab[DEP_MNGR_SEM_HANDLE_MEM].pv_base;
445
84.6k
    ps_dep_mngr_state->pi4_wait_thrd_id = (WORD32 *)ps_mem_tab[DEP_MNGR_WAIT_THRD_ID_MEM].pv_base;
446
84.6k
    ps_dep_mngr_state->pv_units_prcsd_in_row = ps_mem_tab[DEP_MNGR_UNITS_PRCSD_MEM].pv_base;
447
448
    /* SANITY CHECK */
449
84.6k
    ASSERT(NULL != pv_osal_handle);
450
84.6k
    ASSERT(
451
84.6k
        (DEP_MNGR_FRM_FRM_SYNC == dep_mngr_mode) || (DEP_MNGR_ROW_FRM_SYNC == dep_mngr_mode) ||
452
84.6k
        (DEP_MNGR_ROW_ROW_SYNC == dep_mngr_mode));
453
454
    /* Default value */
455
84.6k
    if(num_tile_cols < 1)
456
0
    {
457
0
        num_tile_cols = 1;
458
0
    }
459
460
    /* reset the state structure variables */
461
84.6k
    ps_dep_mngr_state->i4_num_horz_units = max_num_horz_units;
462
84.6k
    ps_dep_mngr_state->i4_num_vert_units = max_num_vert_units;
463
84.6k
    ps_dep_mngr_state->i1_sem_enable = sem_enable;
464
84.6k
    ps_dep_mngr_state->i4_dep_mngr_mode = dep_mngr_mode;
465
84.6k
    ps_dep_mngr_state->i4_num_thrds = num_threads;
466
84.6k
    ps_dep_mngr_state->i4_num_tile_cols = num_tile_cols;
467
468
    /* call the reset function baed on mode */
469
84.6k
    if(DEP_MNGR_FRM_FRM_SYNC == dep_mngr_mode)
470
41.9k
    {
471
41.9k
        ihevce_dmgr_rst_frm_frm_sync((void *)ps_dep_mngr_state);
472
41.9k
    }
473
42.7k
    else if(DEP_MNGR_ROW_ROW_SYNC == dep_mngr_mode)
474
42.7k
    {
475
42.7k
        ihevce_dmgr_rst_row_row_sync((void *)ps_dep_mngr_state);
476
42.7k
    }
477
0
    else
478
0
    {
479
0
        ihevce_dmgr_rst_row_frm_sync((void *)ps_dep_mngr_state);
480
0
    }
481
482
84.6k
    return ((void *)ps_dep_mngr_state);
483
84.6k
}
484
485
/*!
486
******************************************************************************
487
* \if Function name : ihevce_dmgr_map_init \endif
488
*
489
* \brief
490
*    Intialization for Dependency manager state structure .
491
*
492
* \param[in] ps_mem_tab : pointer to memory descriptors table
493
* \param[in] max_num_vert_units : Maximum nunber of units to be processed
494
* \param[in] max_num_horz_units : Maximun Number of Horizontal units to be processed
495
* \param[in] sem_enable : Whether you want to enable semaphore or not
496
             1 : Sem. Enabled, 0 : Spin lock enabled (do-while)
497
* \param[in] num_threads : Number of threads among which sync will be established
498
* \param[in] ai4_tile_xtra_ctb : Array containing the number of CTBs which are
499
*            are present in the Search Range outside the tile in dist-client mode.
500
*            In standalone mode this array should be zero.
501
*
502
* \return
503
*    Handle to context
504
*
505
* \author
506
*  Ittiam
507
*
508
*****************************************************************************
509
*/
510
void *ihevce_dmgr_map_init(
511
    iv_mem_rec_t *ps_mem_tab,
512
    WORD32 max_num_vert_units,
513
    WORD32 max_num_horz_units,
514
    WORD32 sem_enable,
515
    WORD32 num_threads,
516
    WORD32 ai4_tile_xtra_ctb[4])
517
34.9k
{
518
34.9k
    WORD32 ctr;
519
34.9k
    dep_mngr_state_t *ps_dep_mngr_state;
520
521
    /* dep manager state structure */
522
34.9k
    ps_dep_mngr_state = (dep_mngr_state_t *)ps_mem_tab[DEP_MNGR_CTXT].pv_base;
523
524
34.9k
    ps_dep_mngr_state->ai4_tile_xtra_ctb[0] = ai4_tile_xtra_ctb[0];
525
34.9k
    ps_dep_mngr_state->ai4_tile_xtra_ctb[1] = ai4_tile_xtra_ctb[1];
526
34.9k
    ps_dep_mngr_state->ai4_tile_xtra_ctb[2] = ai4_tile_xtra_ctb[2];
527
34.9k
    ps_dep_mngr_state->ai4_tile_xtra_ctb[3] = ai4_tile_xtra_ctb[3];
528
529
    /* dep manager memory init */
530
34.9k
    ps_dep_mngr_state->pv_units_prcsd_in_row = ps_mem_tab[DEP_MNGR_UNITS_PRCSD_MEM].pv_base;
531
34.9k
    ps_dep_mngr_state->pi4_wait_thrd_id = (WORD32 *)ps_mem_tab[DEP_MNGR_WAIT_THRD_ID_MEM].pv_base;
532
34.9k
    ps_dep_mngr_state->ppv_thrd_sem_handles = (void **)ps_mem_tab[DEP_MNGR_SEM_HANDLE_MEM].pv_base;
533
534
    /* Pointing to first CTB of tile */
535
34.9k
    ps_dep_mngr_state->pv_units_prcsd_in_row =
536
34.9k
        (void*)((WORD8*)ps_dep_mngr_state->pv_units_prcsd_in_row +
537
34.9k
        ps_dep_mngr_state->ai4_tile_xtra_ctb[1] +
538
34.9k
        max_num_horz_units * ps_dep_mngr_state->ai4_tile_xtra_ctb[0]);
539
540
    /* Map-mode: semaphore post is unconditionally done on all threads. Hence
541
    store these one time IDs. The use of pi4_wait_thrd_id itself can be removed
542
    altogether for map-mode, but keeping it for the sake of laziness  */
543
69.8k
    for(ctr = 0; ctr < num_threads; ctr++)
544
34.9k
    {
545
34.9k
        ps_dep_mngr_state->pi4_wait_thrd_id[ctr] = ctr;
546
34.9k
    }
547
548
    /* reset the state structure variables */
549
34.9k
    ps_dep_mngr_state->i4_num_horz_units = max_num_horz_units;
550
34.9k
    ps_dep_mngr_state->i4_num_vert_units = max_num_vert_units;
551
34.9k
    ps_dep_mngr_state->i1_sem_enable = sem_enable;
552
34.9k
    ps_dep_mngr_state->i4_dep_mngr_mode = DEP_MNGR_MAP_SYNC;
553
34.9k
    ps_dep_mngr_state->i4_num_thrds = num_threads;
554
555
    /* call the reset function baed on mode */
556
34.9k
    ihevce_dmgr_map_rst_sync((void *)ps_dep_mngr_state);
557
558
34.9k
    return ((void *)ps_dep_mngr_state);
559
34.9k
}
560
561
/*!
562
******************************************************************************
563
* \if Function name : ihevce_dmgr_del \endif
564
*
565
* \brief
566
*    Delete the Dependency manager state structure.
567
* Note : Destroys the mutex only. System has to free the allocated memory
568
*
569
* \param[in,out]  pv_dep_mngr_state  : Pointer to Sync Manager handle.
570
*
571
* \return
572
*    None
573
*
574
* \author
575
*  Ittiam
576
*
577
*****************************************************************************
578
*/
579
void ihevce_dmgr_del(void *pv_dep_mngr_state)
580
119k
{
581
119k
    dep_mngr_state_t *ps_dep_mngr_state;
582
583
    /* dep manager state structure */
584
119k
    (void)ps_dep_mngr_state;
585
119k
    ps_dep_mngr_state = (dep_mngr_state_t *)pv_dep_mngr_state;
586
119k
}
587
588
/*!
589
******************************************************************************
590
* \if Function name : ihevce_dmgr_register_sem_hdls \endif
591
*
592
* \brief
593
*    Register sem handles of threads wihci are part of dependency group
594
*
595
* \param[in,out]  pv_dep_mngr_state  : Pointer to Sync Manager handle.
596
* \param[in] ppv_thread_sem_hdl : arry of pointer to all the sem handles
597
* \param[in] num_threads : Number of threads part of this dependency group
598
*
599
* \return
600
*    None
601
*
602
* \author
603
*  Ittiam
604
*
605
*****************************************************************************
606
*/
607
void ihevce_dmgr_reg_sem_hdls(void *pv_dep_mngr_state, void **ppv_thread_sem_hdl, WORD32 num_threads)
608
119k
{
609
119k
    dep_mngr_state_t *ps_dep_mngr_state;
610
119k
    WORD32 ctr;
611
612
    /* dep manager state structure */
613
119k
    ps_dep_mngr_state = (dep_mngr_state_t *)pv_dep_mngr_state;
614
615
119k
    ASSERT(num_threads <= ps_dep_mngr_state->i4_num_thrds);
616
617
239k
    for(ctr = 0; ctr < num_threads; ctr++)
618
119k
    {
619
119k
        ps_dep_mngr_state->ppv_thrd_sem_handles[ctr] = ppv_thread_sem_hdl[ctr];
620
119k
    }
621
622
119k
    return;
623
119k
}
624
625
/*!
626
******************************************************************************
627
* \if Function name : ihevce_dmgr_set_prev_done_frm_frm_sync \endif
628
*
629
* \brief
630
*    Set the values to dependency not resolved state
631
*
632
* \param[in,out]  pv_dep_mngr_state  : Pointer to Sync Manager handle.
633
*
634
* \return
635
*    None
636
*
637
* \author
638
*  Ittiam
639
*
640
*****************************************************************************
641
*/
642
void ihevce_dmgr_set_prev_done_frm_frm_sync(void *pv_dep_mngr_state)
643
6.98k
{
644
6.98k
    dep_mngr_state_t *ps_dep_mngr_state;
645
6.98k
    WORD32 thrds;
646
6.98k
    ULWORD64 *pu8_num_units_proc_curr;
647
6.98k
    ULWORD64 *pu8_num_units_proc_prev;
648
649
    /* dep manager state structure */
650
6.98k
    ps_dep_mngr_state = (dep_mngr_state_t *)pv_dep_mngr_state;
651
652
    /* Reset the values num threads entering processing state  */
653
6.98k
    pu8_num_units_proc_curr = (ULWORD64 *)ps_dep_mngr_state->pv_units_prcsd_in_row;
654
6.98k
    pu8_num_units_proc_prev =
655
6.98k
        (ULWORD64 *)(pu8_num_units_proc_curr + ps_dep_mngr_state->i4_num_thrds);
656
657
    /* Reset the values thread ids waiting */
658
13.9k
    for(thrds = 0; thrds < ps_dep_mngr_state->i4_num_thrds; thrds++)
659
6.98k
    {
660
6.98k
        pu8_num_units_proc_prev[thrds] = 1;
661
6.98k
        ps_dep_mngr_state->pi4_wait_thrd_id[thrds] = -1;
662
6.98k
    }
663
664
6.98k
    return;
665
6.98k
}
666
667
/*!
668
******************************************************************************
669
* \if Function name : ihevce_dmgr_set_done_frm_frm_sync \endif
670
*
671
* \brief
672
*    Set the values to dependency met state
673
*
674
* \param[in,out]  pv_dep_mngr_state  : Pointer to Sync Manager handle.
675
*
676
* \return
677
*    None
678
*
679
* \author
680
*  Ittiam
681
*
682
*****************************************************************************
683
*/
684
void ihevce_dmgr_set_done_frm_frm_sync(void *pv_dep_mngr_state)
685
41.9k
{
686
41.9k
    dep_mngr_state_t *ps_dep_mngr_state;
687
41.9k
    WORD32 thrds;
688
41.9k
    ULWORD64 *pu8_num_units_proc_curr;
689
690
    /* dep manager state structure */
691
41.9k
    ps_dep_mngr_state = (dep_mngr_state_t *)pv_dep_mngr_state;
692
693
    /* Reset the values num threads entering processing state  */
694
41.9k
    pu8_num_units_proc_curr = (ULWORD64 *)ps_dep_mngr_state->pv_units_prcsd_in_row;
695
696
    /* Reset the values thread ids waiting */
697
83.8k
    for(thrds = 0; thrds < ps_dep_mngr_state->i4_num_thrds; thrds++)
698
41.9k
    {
699
41.9k
        pu8_num_units_proc_curr[thrds] = 1;
700
41.9k
        ps_dep_mngr_state->pi4_wait_thrd_id[thrds] = -1;
701
41.9k
    }
702
703
41.9k
    return;
704
41.9k
}
705
706
/*!
707
**************************************************************************
708
* \if Function name : ihevce_dmgr_chk_row_row_sync \endif
709
*
710
* \brief
711
*    This function checks whether the dependency is met to proceed with
712
*    processing. If condition is not met, it should go to a sem_wait state,
713
*    else start processing.
714
*
715
* \param[in]  pv_dep_mngr_state  : Pointer to Sync Manager handle.
716
* \param[in]  cur_offset    : Current offset of the dep. variable
717
* \param[in]  dep_offset    : Offset from the current value to meet the dep.
718
* \param[in]  dep_row       : The position of the Ref.
719
* \param[in]  cur_tile_col  : The current column tile number (not tile id)
720
*   Assuming the dependency is within the tile only (Acroos tiles won't work now)
721
* \param[in]  thrd_id       : Thread id of the current thread checking for dependency
722
*
723
* \return
724
*    0 on Success and -1 on error
725
*
726
* \author
727
*  Ittiam
728
*
729
**************************************************************************
730
*/
731
WORD32 ihevce_dmgr_chk_row_row_sync(
732
    void *pv_dep_mngr_state,
733
    WORD32 cur_offset,
734
    WORD32 dep_offset,
735
    WORD32 dep_row,
736
    WORD32 cur_tile_col,
737
    WORD32 thrd_id)
738
3.50M
{
739
3.50M
    dep_mngr_state_t *ps_dep_mngr_state;
740
3.50M
    volatile WORD32 *pi4_ref_value;
741
3.50M
    WORD32 ref_value;
742
743
3.50M
    ps_dep_mngr_state = (dep_mngr_state_t *)pv_dep_mngr_state;
744
745
    /* Sanity Check */
746
3.50M
    ASSERT(dep_row >= 0);
747
3.50M
    ASSERT(dep_row < ps_dep_mngr_state->i4_num_vert_units);
748
3.50M
    ASSERT(cur_tile_col >= 0);
749
3.50M
    ASSERT(cur_tile_col < ps_dep_mngr_state->i4_num_tile_cols);
750
751
3.50M
    pi4_ref_value = ((volatile WORD32 *)(ps_dep_mngr_state->pv_units_prcsd_in_row)) +
752
3.50M
                    (cur_tile_col * ps_dep_mngr_state->i4_num_vert_units) + dep_row;
753
754
    /* Sanity Check */
755
3.50M
    ASSERT((cur_offset + dep_offset) <= ps_dep_mngr_state->i4_num_horz_units);
756
757
    /* Check whether Dep. is met */
758
3.50M
    while(1)
759
3.50M
    {
760
3.50M
        ref_value = *pi4_ref_value;
761
762
3.50M
        if(ref_value >= (cur_offset + dep_offset))
763
3.50M
            break;
764
765
0
        if(1 == ps_dep_mngr_state->i1_sem_enable)
766
0
        {
767
0
            void *pv_sem_handle;
768
0
            WORD32 ret_val;
769
770
0
            (void)ret_val;
771
0
            pv_sem_handle = ps_dep_mngr_state->ppv_thrd_sem_handles[thrd_id];
772
773
            /* register the thread id before going to pend state */
774
0
            ps_dep_mngr_state->pi4_wait_thrd_id[dep_row] = thrd_id;
775
776
            /* go to the pend state */
777
0
            ret_val = osal_sem_wait(pv_sem_handle);
778
            //ASSERT(0 == ret_val);
779
0
        }
780
0
    }
781
782
3.50M
    return 0;
783
3.50M
}
784
785
/*!
786
**************************************************************************
787
* \if Function name : ihevce_dmgr_set_row_row_sync \endif
788
*
789
* \brief
790
*    This function sets the dependency and wakes up the proper semaphores
791
*    to start processing.
792
*
793
* \param[in]  pv_dep_mngr_state  : Pointer to Sync Manager handle.
794
* \param[in]  cur_offset     : Current offset processed
795
* \param[in]  cur_row       : The cur. vertical position
796
* \param[in]  cur_tile_col  : The current column tile number (not tile id)
797
*   Assuming the dependency is within the tile only (Acroos tiles won't work now)
798
*
799
* \return
800
*    0 on Success and -1 on error
801
*
802
* \author
803
*  Ittiam
804
*
805
**************************************************************************
806
*/
807
WORD32 ihevce_dmgr_set_row_row_sync(
808
    void *pv_dep_mngr_state, WORD32 cur_offset, WORD32 cur_row, WORD32 cur_tile_col)
809
3.67M
{
810
3.67M
    dep_mngr_state_t *ps_dep_mngr_state;
811
3.67M
    WORD32 *pi4_units_prcsd;
812
3.67M
    void *pv_sem_handle;
813
3.67M
    WORD32 ret_val;
814
815
3.67M
    (void)ret_val;
816
3.67M
    ps_dep_mngr_state = (dep_mngr_state_t *)pv_dep_mngr_state;
817
818
    /* Sanity Check */
819
3.67M
    ASSERT(cur_offset >= 0);
820
3.67M
    ASSERT(cur_offset <= ps_dep_mngr_state->i4_num_horz_units);
821
3.67M
    ASSERT(cur_row <= ps_dep_mngr_state->i4_num_vert_units);
822
3.67M
    ASSERT(cur_tile_col >= 0);
823
3.67M
    ASSERT(cur_tile_col < ps_dep_mngr_state->i4_num_tile_cols);
824
825
3.67M
    DATA_SYNC();
826
827
3.67M
    pi4_units_prcsd = ((WORD32 *)(ps_dep_mngr_state->pv_units_prcsd_in_row)) +
828
3.67M
                      (cur_tile_col * ps_dep_mngr_state->i4_num_vert_units) + cur_row;
829
830
    /* Update the number of units processed */
831
3.67M
    *pi4_units_prcsd = cur_offset;
832
833
3.67M
    if(1 == ps_dep_mngr_state->i1_sem_enable)
834
3.13M
    {
835
3.13M
        WORD32 wait_thrd_id;
836
837
3.13M
        wait_thrd_id = ps_dep_mngr_state->pi4_wait_thrd_id[cur_row];
838
839
        /* Post on threads waiting on the current row */
840
3.13M
        if(-1 != wait_thrd_id)
841
0
        {
842
0
            pv_sem_handle = ps_dep_mngr_state->ppv_thrd_sem_handles[wait_thrd_id];
843
            /* Post on the semaphore */
844
0
            ret_val = osal_sem_post(pv_sem_handle);
845
            //ASSERT(0 == ret_val);
846
847
0
            ps_dep_mngr_state->pi4_wait_thrd_id[cur_row] = -1;
848
0
        }
849
850
        /* towards end of row all threads are posted (to avoid any corner cases) */
851
3.13M
        if(cur_offset == ps_dep_mngr_state->i4_num_horz_units)
852
657k
        {
853
657k
            WORD32 ctr;
854
855
1.31M
            for(ctr = 0; ctr < ps_dep_mngr_state->i4_num_thrds; ctr++)
856
657k
            {
857
657k
                ret_val = osal_sem_post(ps_dep_mngr_state->ppv_thrd_sem_handles[ctr]);
858
                //ASSERT(0 == ret_val);
859
657k
            }
860
657k
        }
861
3.13M
    }
862
863
3.67M
    return 0;
864
3.67M
}
865
866
/*!
867
**************************************************************************
868
* \if Function name : ihevce_dmgr_chk_frm_frm_sync \endif
869
*
870
* \brief
871
*    This function checks whether the dependency is met to proceed with
872
*    processing. If condition is not met, it should go to a sem_wait state,
873
*    else start processing.
874
*    For Barrier case, the thread will wait till all threads have completed
875
*    the processing on the previosu instance of same stage
876
* \param[in]  pv_dep_mngr_state  : Pointer to Sync Manager handle.
877
* \param[in]  thrd_id       : Thread id checking for dependency
878
*
879
* \return
880
*    0 on Success and -1 on error
881
*
882
* \author
883
*  Ittiam
884
*
885
**************************************************************************
886
*/
887
WORD32 ihevce_dmgr_chk_frm_frm_sync(void *pv_dep_mngr_state, WORD32 thrd_id)
888
640k
{
889
640k
    dep_mngr_state_t *ps_dep_mngr_state;
890
640k
    void *pv_sem_handle;
891
640k
    volatile ULWORD64 *pu8_num_units_proc_prev;
892
640k
    volatile ULWORD64 *pu8_num_units_proc_curr;
893
640k
    ULWORD64 prev_value;
894
640k
    ULWORD64 curr_value;
895
896
640k
    ps_dep_mngr_state = (dep_mngr_state_t *)pv_dep_mngr_state;
897
640k
    pv_sem_handle = ps_dep_mngr_state->ppv_thrd_sem_handles[thrd_id];
898
899
640k
    pu8_num_units_proc_curr = (volatile ULWORD64 *)ps_dep_mngr_state->pv_units_prcsd_in_row;
900
640k
    pu8_num_units_proc_prev =
901
640k
        (volatile ULWORD64 *)(pu8_num_units_proc_curr + ps_dep_mngr_state->i4_num_thrds);
902
903
    /* Check whether Dep. is met */
904
640k
    while(1)
905
640k
    {
906
640k
        WORD32 ret_val;
907
908
640k
        (void)ret_val;
909
640k
        curr_value = pu8_num_units_proc_curr[thrd_id];
910
640k
        prev_value = pu8_num_units_proc_prev[thrd_id];
911
912
640k
        if(curr_value == (prev_value + 1))
913
640k
        {
914
640k
            break;
915
640k
        }
916
0
        else
917
0
        {
918
            /* register the thread id before going to pend state */
919
0
            ps_dep_mngr_state->pi4_wait_thrd_id[thrd_id] = thrd_id;
920
921
            /* go to the pend state */
922
0
            ret_val = osal_sem_wait(pv_sem_handle);
923
            //ASSERT(0 == ret_val);
924
0
        }
925
640k
    }
926
927
    /* store curr value to prev for next iteration */
928
640k
    pu8_num_units_proc_prev[thrd_id] = pu8_num_units_proc_curr[thrd_id];
929
930
640k
    return 0;
931
640k
}
932
933
/*!
934
**************************************************************************
935
* \if Function name : ihevce_dmgr_update_frm_frm_sync \endif
936
*
937
* \brief
938
*    This function sets the dependency and wakes up the proper semaphores
939
*    to start processing.
940
*    For barrier case, if the dep. is met, all waiting threads should be waked up
941
*
942
* \param[in]  pv_dep_mngr_state  : Pointer to Sync Manager handle.
943
*
944
* \return
945
*    0 on Success and -1 on error
946
*
947
* \author
948
*  Ittiam
949
*
950
**************************************************************************
951
*/
952
WORD32 ihevce_dmgr_update_frm_frm_sync(void *pv_dep_mngr_state)
953
633k
{
954
633k
    dep_mngr_state_t *ps_dep_mngr_state;
955
633k
    void *pv_sem_handle;
956
633k
    volatile ULWORD64 *pu8_num_units_proc_curr;
957
633k
    WORD32 ctr;
958
959
633k
    ps_dep_mngr_state = (dep_mngr_state_t *)pv_dep_mngr_state;
960
961
633k
    pu8_num_units_proc_curr = (volatile ULWORD64 *)ps_dep_mngr_state->pv_units_prcsd_in_row;
962
963
    /* Post on All vertical waiting threads semaphores & update the cur unit proc */
964
1.26M
    for(ctr = 0; ctr < ps_dep_mngr_state->i4_num_thrds; ctr++)
965
633k
    {
966
633k
        WORD32 ret_val;
967
633k
        WORD32 wait_thrd_id;
968
969
633k
        (void)ret_val;
970
        /* increment the curr unit counter for all threads */
971
633k
        pu8_num_units_proc_curr[ctr] = pu8_num_units_proc_curr[ctr] + 1;
972
973
633k
        wait_thrd_id = ctr;
974
        //wait_thrd_id    = ps_dep_mngr_state->pi4_wait_thrd_id[ctr];
975
976
633k
        if(-1 != wait_thrd_id)
977
633k
        {
978
633k
            pv_sem_handle = ps_dep_mngr_state->ppv_thrd_sem_handles[wait_thrd_id];
979
            /* Post on the semaphore */
980
633k
            ret_val = osal_sem_post(pv_sem_handle);
981
            //ASSERT(0 == ret_val);
982
983
633k
            ps_dep_mngr_state->pi4_wait_thrd_id[ctr] = -1;
984
633k
        }
985
633k
    }
986
987
633k
    return 0;
988
633k
}
989
990
/*!
991
**************************************************************************
992
* \if Function name : ihevce_dmgr_map_chk \endif
993
*
994
* \brief
995
*   This function checks whether all entries in the dependency map are set
996
*
997
* \param[in]  pu1_start    : Pointer to the start of the search area
998
* \param[in]  i4_num_ctb_x : Size   of search area
999
* \param[in]  i4_num_ctb_y : Size   of search area
1000
* \param[in]  i4_stride    : Stride of search area
1001
*
1002
* \return
1003
*    1 on Success otherwise 0
1004
*
1005
* \author
1006
*  Ittiam
1007
*
1008
**************************************************************************
1009
*/
1010
WORD32
1011
    ihevce_dmgr_map_chk(WORD8 *pu1_start, WORD32 i4_num_ctb_x, WORD32 i4_num_ctb_y, WORD32 i4_stride)
1012
188k
{
1013
188k
    WORD8 *pi1_ctb = pu1_start;
1014
188k
    WORD32 row, col;
1015
188k
    WORD32 map_ready_flag = MAP_CTB_COMPLETE;
1016
1017
442k
    for(row = 0; row < i4_num_ctb_y; row++)
1018
253k
    {
1019
745k
        for(col = 0; col < i4_num_ctb_x; col++)
1020
492k
        {
1021
492k
            map_ready_flag &= pi1_ctb[col];
1022
492k
        }
1023
253k
        pi1_ctb += i4_stride;
1024
253k
    }
1025
1026
    /* NOTE: early exit in the above loop can taken if map_ready_flag
1027
    is found to be zero somewhere at the start itself */
1028
188k
    return (map_ready_flag == MAP_CTB_COMPLETE);
1029
188k
}
1030
1031
/*!
1032
**************************************************************************
1033
* \if Function name : ihevce_dmgr_map_chk_sync \endif
1034
*
1035
* \brief
1036
*   This function checks whether the dependency is met by searching in a
1037
*   rectangular area. If condition is not met, it should go to a sem_wait state,
1038
*    else start processing.
1039
*
1040
* \param[in]  pv_dep_mngr_state  : Pointer to Sync Manager handle.
1041
* \param[in]  thrd_id     : Thread id of the current thread checking for dependency
1042
* \param[in]  offset_x    : Offset of current CTB in Tile in ctb-unit
1043
* \param[in]  offset_y    : Offset of current CTB in Tile in ctb-unit
1044
* \param[in]  i4_sr_ctb_x : Search Range in ctb-unit
1045
* \param[in]  i4_sr_ctb_y : Search Range in ctb-unit
1046
*
1047
* \return
1048
*    0 on Success and -1 on error
1049
*
1050
* \author
1051
*  Ittiam
1052
*
1053
**************************************************************************
1054
*/
1055
WORD32 ihevce_dmgr_map_chk_sync(
1056
    void *pv_dep_mngr_state,
1057
    WORD32 thrd_id,
1058
    WORD32 offset_x,
1059
    WORD32 offset_y,
1060
    WORD32 i4_sr_ctb_x,
1061
    WORD32 i4_sr_ctb_y)
1062
188k
{
1063
188k
    dep_mngr_state_t *ps_dep_mngr_state;
1064
188k
    volatile WORD8 *pi1_ctb;
1065
188k
    WORD8 *pi1_tile_start;
1066
188k
    WORD32 i4_avail_left, i4_avail_right, i4_avail_top, i4_avail_bot;
1067
188k
    WORD32 i4_num_ctb_x, i4_num_ctb_y;
1068
188k
    WORD32 i4_stride;
1069
188k
    WORD32 i4_tile_wd, i4_tile_ht;  //in ctb units
1070
1071
188k
    ps_dep_mngr_state = (dep_mngr_state_t *)pv_dep_mngr_state;
1072
1073
188k
    i4_tile_wd = ps_dep_mngr_state->i4_num_horz_units - ps_dep_mngr_state->ai4_tile_xtra_ctb[1] -
1074
188k
                 ps_dep_mngr_state->ai4_tile_xtra_ctb[2];
1075
1076
188k
    i4_tile_ht = ps_dep_mngr_state->i4_num_vert_units - ps_dep_mngr_state->ai4_tile_xtra_ctb[0] -
1077
188k
                 ps_dep_mngr_state->ai4_tile_xtra_ctb[3];
1078
1079
188k
    i4_stride = ps_dep_mngr_state->i4_num_horz_units;
1080
1081
    /* Sanity Checks, confirm if ctb offsets are within tiles */
1082
188k
    ASSERT(offset_x >= 0);
1083
188k
    ASSERT(offset_y >= 0);
1084
188k
    ASSERT(offset_x < i4_tile_wd);
1085
188k
    ASSERT(offset_y < i4_tile_ht);
1086
1087
188k
    pi1_tile_start = (WORD8 *)ps_dep_mngr_state->pv_units_prcsd_in_row;
1088
188k
    pi1_ctb = (volatile WORD8 *)pi1_tile_start;
1089
1090
188k
    if(ps_dep_mngr_state->ai4_tile_xtra_ctb[0])
1091
0
    {
1092
0
        i4_avail_top = i4_sr_ctb_y;
1093
0
    }
1094
188k
    else
1095
188k
    {
1096
188k
        i4_avail_top = MIN(i4_sr_ctb_y, offset_y);
1097
188k
    }
1098
1099
188k
    if(ps_dep_mngr_state->ai4_tile_xtra_ctb[1])
1100
0
    {
1101
0
        i4_avail_left = i4_sr_ctb_x;
1102
0
    }
1103
188k
    else
1104
188k
    {
1105
188k
        i4_avail_left = MIN(i4_sr_ctb_x, offset_x);
1106
188k
    }
1107
1108
188k
    if(ps_dep_mngr_state->ai4_tile_xtra_ctb[2])
1109
0
    {
1110
0
        i4_avail_right = i4_sr_ctb_x;
1111
0
    }
1112
188k
    else
1113
188k
    {
1114
188k
        i4_avail_right = MIN(i4_sr_ctb_x, (i4_tile_wd - offset_x - 1));
1115
188k
    }
1116
1117
188k
    if(ps_dep_mngr_state->ai4_tile_xtra_ctb[3])
1118
0
    {
1119
0
        i4_avail_bot = i4_sr_ctb_y;
1120
0
    }
1121
188k
    else
1122
188k
    {
1123
188k
        i4_avail_bot = MIN(i4_sr_ctb_y, (i4_tile_ht - offset_y - 1));
1124
188k
    }
1125
1126
188k
    i4_num_ctb_x = (i4_avail_left + 1 + i4_avail_right);
1127
188k
    i4_num_ctb_y = (i4_avail_top + 1 + i4_avail_bot);
1128
1129
    /* Point to the start of the search-area */
1130
188k
    pi1_ctb += ((offset_y - i4_avail_top) * i4_stride + (offset_x - i4_avail_left));
1131
1132
    /* Check whether Dep. is met */
1133
188k
    while(1)
1134
188k
    {
1135
188k
        if(1 == ihevce_dmgr_map_chk((WORD8 *)pi1_ctb, i4_num_ctb_x, i4_num_ctb_y, i4_stride))
1136
188k
        {
1137
188k
            break;
1138
188k
        }
1139
0
        else
1140
0
        {
1141
0
            if(1 == ps_dep_mngr_state->i1_sem_enable)
1142
0
            {
1143
0
                osal_sem_wait(ps_dep_mngr_state->ppv_thrd_sem_handles[thrd_id]);
1144
0
            }
1145
0
        }
1146
188k
    }
1147
1148
188k
    return 0;
1149
188k
}
1150
1151
/*!
1152
**************************************************************************
1153
* \if Function name : ihevce_dmgr_map_set_sync \endif
1154
*
1155
* \brief
1156
*    This function sets the dependency and wakes up the proper semaphores
1157
*    to start processing.
1158
*
1159
* \param[in]  pv_dep_mngr_state  : Pointer to Sync Manager handle.
1160
* \param[in]  offset_x           : Offset of current CTB in Tile(ctb unit)
1161
* \param[in]  offset_y           : Offset of current CTB in Tile(ctb unit)
1162
*
1163
* \return
1164
*    0 on Success and -1 on error
1165
*
1166
* \author
1167
*  Ittiam
1168
*
1169
**************************************************************************
1170
*/
1171
WORD32 ihevce_dmgr_map_set_sync(
1172
    void *pv_dep_mngr_state, WORD32 offset_x, WORD32 offset_y, WORD32 i4_map_value)
1173
225k
{
1174
225k
    dep_mngr_state_t *ps_dep_mngr_state;
1175
225k
    WORD8 *pi1_tile_start;
1176
225k
    WORD32 map_stride;
1177
1178
225k
    ps_dep_mngr_state = (dep_mngr_state_t *)pv_dep_mngr_state;
1179
1180
    /* Sanity Checks */
1181
225k
    ASSERT(offset_x >= (-ps_dep_mngr_state->ai4_tile_xtra_ctb[1]));
1182
225k
    ASSERT(offset_y >= (-ps_dep_mngr_state->ai4_tile_xtra_ctb[0]));
1183
1184
225k
    ASSERT(
1185
225k
        offset_x <
1186
225k
        (ps_dep_mngr_state->i4_num_horz_units - ps_dep_mngr_state->ai4_tile_xtra_ctb[1]));
1187
1188
225k
    ASSERT(
1189
225k
        offset_y <
1190
225k
        (ps_dep_mngr_state->i4_num_vert_units - ps_dep_mngr_state->ai4_tile_xtra_ctb[0]));
1191
1192
225k
    DATA_SYNC();
1193
1194
225k
    map_stride = ps_dep_mngr_state->i4_num_horz_units;
1195
1196
225k
    pi1_tile_start = (WORD8 *)ps_dep_mngr_state->pv_units_prcsd_in_row;
1197
1198
    /* Set the flag to indicate that this CTB has been processed */
1199
225k
    *(pi1_tile_start + offset_y * map_stride + offset_x) = (WORD8)i4_map_value;
1200
1201
225k
    if(1 == ps_dep_mngr_state->i1_sem_enable)
1202
143k
    {
1203
143k
        WORD32 wait_thrd_id;
1204
1205
        /* Post on threads waiting on the current row */
1206
287k
        for(wait_thrd_id = 0; wait_thrd_id < ps_dep_mngr_state->i4_num_thrds; wait_thrd_id++)
1207
143k
        {
1208
            /* Post on the semaphore */
1209
            /* Map-mode: semaphore post is unconditionally done on all threads */
1210
143k
            osal_sem_post(ps_dep_mngr_state->ppv_thrd_sem_handles[wait_thrd_id]);
1211
143k
        }
1212
143k
    }
1213
1214
225k
    return 0;
1215
225k
}