Coverage Report

Created: 2026-06-10 06:32

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
7.89k
{
86
7.89k
    return (NUM_DEP_MNGR_MEM_RECS);
87
7.89k
}
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
2.52k
{
119
2.52k
    WORD32 num_vert_units;
120
2.52k
    WORD32 num_wait_thrd_ids;
121
122
    /* Dependency manager state structure */
123
2.52k
    ps_mem_tab[DEP_MNGR_CTXT].i4_mem_size = sizeof(dep_mngr_state_t);
124
2.52k
    ps_mem_tab[DEP_MNGR_CTXT].e_mem_type = (IV_MEM_TYPE_T)i4_mem_space;
125
2.52k
    ps_mem_tab[DEP_MNGR_CTXT].i4_mem_alignment = 8;
126
127
    /* SANITY CHECK */
128
2.52k
    ASSERT(
129
2.52k
        (DEP_MNGR_FRM_FRM_SYNC == dep_mngr_mode) || (DEP_MNGR_ROW_FRM_SYNC == dep_mngr_mode) ||
130
2.52k
        (DEP_MNGR_ROW_ROW_SYNC == dep_mngr_mode));
131
132
    /* Default value */
133
2.52k
    if(num_tile_cols < 1)
134
0
    {
135
0
        num_tile_cols = 1;
136
0
    }
137
138
    /**************** Get Processed status Memory Requirements *********************/
139
2.52k
    if(DEP_MNGR_FRM_FRM_SYNC == dep_mngr_mode)
140
1.19k
    {
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
1.19k
        num_vert_units = (2 + 2) * num_threads;
146
1.19k
    }
147
1.32k
    else
148
1.32k
    {
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
1.32k
        num_vert_units = max_num_vert_units * num_tile_cols;
152
1.32k
    }
153
154
2.52k
    ps_mem_tab[DEP_MNGR_UNITS_PRCSD_MEM].i4_mem_size = (sizeof(WORD32) * num_vert_units);
155
2.52k
    ps_mem_tab[DEP_MNGR_UNITS_PRCSD_MEM].e_mem_type = (IV_MEM_TYPE_T)i4_mem_space;
156
2.52k
    ps_mem_tab[DEP_MNGR_UNITS_PRCSD_MEM].i4_mem_alignment = 8;
157
158
    /**************** Get Wait thread ids Memory Requirements *********************/
159
2.52k
    if(DEP_MNGR_FRM_FRM_SYNC == dep_mngr_mode)
160
1.19k
    {
161
        /* for frame to frame sync number of threads worth memory is allocated */
162
1.19k
        num_wait_thrd_ids = num_threads;
163
1.19k
    }
164
1.32k
    else if(DEP_MNGR_ROW_ROW_SYNC == dep_mngr_mode)
165
1.32k
    {
166
        /* for row to row sync number of vertical rows worth memory is allocated */
167
1.32k
        num_wait_thrd_ids = max_num_vert_units;
168
1.32k
    }
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
2.52k
    ps_mem_tab[DEP_MNGR_WAIT_THRD_ID_MEM].i4_mem_size = (sizeof(WORD32) * num_wait_thrd_ids);
176
2.52k
    ps_mem_tab[DEP_MNGR_WAIT_THRD_ID_MEM].e_mem_type = (IV_MEM_TYPE_T)i4_mem_space;
177
2.52k
    ps_mem_tab[DEP_MNGR_WAIT_THRD_ID_MEM].i4_mem_alignment = 8;
178
179
    /**************** Get Semaphore Requirements *********************/
180
2.52k
    ps_mem_tab[DEP_MNGR_SEM_HANDLE_MEM].i4_mem_size = (sizeof(void *) * num_threads);
181
2.52k
    ps_mem_tab[DEP_MNGR_SEM_HANDLE_MEM].e_mem_type = (IV_MEM_TYPE_T)i4_mem_space;
182
2.52k
    ps_mem_tab[DEP_MNGR_SEM_HANDLE_MEM].i4_mem_alignment = 8;
183
184
2.52k
    return (NUM_DEP_MNGR_MEM_RECS);
185
2.52k
}
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
995
{
210
    /* Dependency manager state structure */
211
995
    ps_mem_tab[DEP_MNGR_CTXT].i4_mem_size = sizeof(dep_mngr_state_t);
212
995
    ps_mem_tab[DEP_MNGR_CTXT].e_mem_type = (IV_MEM_TYPE_T)i4_mem_space;
213
995
    ps_mem_tab[DEP_MNGR_CTXT].i4_mem_alignment = 8;
214
215
    /**************** Get Processed status Memory Requirements *********************/
216
995
    ps_mem_tab[DEP_MNGR_UNITS_PRCSD_MEM].i4_mem_size = (sizeof(WORD8) * num_units);
217
995
    ps_mem_tab[DEP_MNGR_UNITS_PRCSD_MEM].e_mem_type = (IV_MEM_TYPE_T)i4_mem_space;
218
995
    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
995
    ps_mem_tab[DEP_MNGR_WAIT_THRD_ID_MEM].i4_mem_size = (sizeof(WORD32) * num_threads);
223
995
    ps_mem_tab[DEP_MNGR_WAIT_THRD_ID_MEM].e_mem_type = (IV_MEM_TYPE_T)i4_mem_space;
224
995
    ps_mem_tab[DEP_MNGR_WAIT_THRD_ID_MEM].i4_mem_alignment = 8;
225
226
    /**************** Get Semaphore Requirements *********************/
227
995
    ps_mem_tab[DEP_MNGR_SEM_HANDLE_MEM].i4_mem_size = (sizeof(void *) * num_threads);
228
995
    ps_mem_tab[DEP_MNGR_SEM_HANDLE_MEM].e_mem_type = (IV_MEM_TYPE_T)i4_mem_space;
229
995
    ps_mem_tab[DEP_MNGR_SEM_HANDLE_MEM].i4_mem_alignment = 8;
230
231
995
    return (NUM_DEP_MNGR_MEM_RECS);
232
995
}
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
1.19k
{
253
1.19k
    dep_mngr_state_t *ps_dep_mngr_state;
254
1.19k
    WORD32 thrds;
255
1.19k
    ULWORD64 *pu8_num_units_proc_prev;
256
1.19k
    ULWORD64 *pu8_num_units_proc_curr;
257
258
    /* dep manager state structure */
259
1.19k
    ps_dep_mngr_state = (dep_mngr_state_t *)pv_dep_mngr_state;
260
261
    /* Reset the num units processed by each thread */
262
1.19k
    pu8_num_units_proc_curr = (ULWORD64 *)ps_dep_mngr_state->pv_units_prcsd_in_row;
263
1.19k
    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
2.38k
    for(thrds = 0; thrds < ps_dep_mngr_state->i4_num_thrds; thrds++)
267
1.19k
    {
268
1.19k
        pu8_num_units_proc_prev[thrds] = 0;
269
1.19k
        pu8_num_units_proc_curr[thrds] = 0;
270
1.19k
        ps_dep_mngr_state->pi4_wait_thrd_id[thrds] = -1;
271
1.19k
    }
272
273
1.19k
    return;
274
1.19k
}
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
3.52k
{
339
3.52k
    dep_mngr_state_t *ps_dep_mngr_state;
340
3.52k
    WORD8 *pi1_ptr;
341
342
    /* dep manager state structure */
343
3.52k
    ps_dep_mngr_state = (dep_mngr_state_t *)pv_dep_mngr_state;
344
345
3.52k
    pi1_ptr = (WORD8 *)ps_dep_mngr_state->pv_units_prcsd_in_row -
346
3.52k
              ps_dep_mngr_state->ai4_tile_xtra_ctb[0] * ps_dep_mngr_state->i4_num_horz_units -
347
3.52k
              ps_dep_mngr_state->ai4_tile_xtra_ctb[1];
348
349
3.52k
    memset(
350
3.52k
        pi1_ptr,
351
3.52k
        MAP_CTB_INIT,
352
3.52k
        ps_dep_mngr_state->i4_num_vert_units * ps_dep_mngr_state->i4_num_horz_units *
353
3.52k
            sizeof(WORD8));
354
355
    //ps_dep_mngr_state->i4_frame_map_complete = 0;
356
357
3.52k
    return;
358
3.52k
}
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
17.3k
{
379
17.3k
    dep_mngr_state_t *ps_dep_mngr_state;
380
17.3k
    WORD32 ctr;
381
382
    /* dep manager state structure */
383
17.3k
    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
90.3k
    for(ctr = 0; ctr < (ps_dep_mngr_state->i4_num_vert_units * ps_dep_mngr_state->i4_num_tile_cols);
387
72.9k
        ctr++)
388
72.9k
    {
389
72.9k
        ((WORD32 *)ps_dep_mngr_state->pv_units_prcsd_in_row)[ctr] = 0;
390
72.9k
    }
391
392
    /* Reset the values thread ids waiting on each row  */
393
90.3k
    for(ctr = 0; ctr < ps_dep_mngr_state->i4_num_vert_units; ctr++)
394
72.9k
    {
395
72.9k
        ps_dep_mngr_state->pi4_wait_thrd_id[ctr] = -1;
396
72.9k
    }
397
398
17.3k
    return;
399
17.3k
}
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
2.52k
{
437
2.52k
    dep_mngr_state_t *ps_dep_mngr_state;
438
439
2.52k
    (void)pv_osal_handle;
440
    /* dep manager state structure */
441
2.52k
    ps_dep_mngr_state = (dep_mngr_state_t *)ps_mem_tab[DEP_MNGR_CTXT].pv_base;
442
443
    /* dep manager memory init */
444
2.52k
    ps_dep_mngr_state->ppv_thrd_sem_handles = (void **)ps_mem_tab[DEP_MNGR_SEM_HANDLE_MEM].pv_base;
445
2.52k
    ps_dep_mngr_state->pi4_wait_thrd_id = (WORD32 *)ps_mem_tab[DEP_MNGR_WAIT_THRD_ID_MEM].pv_base;
446
2.52k
    ps_dep_mngr_state->pv_units_prcsd_in_row = ps_mem_tab[DEP_MNGR_UNITS_PRCSD_MEM].pv_base;
447
448
    /* SANITY CHECK */
449
2.52k
    ASSERT(NULL != pv_osal_handle);
450
2.52k
    ASSERT(
451
2.52k
        (DEP_MNGR_FRM_FRM_SYNC == dep_mngr_mode) || (DEP_MNGR_ROW_FRM_SYNC == dep_mngr_mode) ||
452
2.52k
        (DEP_MNGR_ROW_ROW_SYNC == dep_mngr_mode));
453
454
    /* Default value */
455
2.52k
    if(num_tile_cols < 1)
456
0
    {
457
0
        num_tile_cols = 1;
458
0
    }
459
460
    /* reset the state structure variables */
461
2.52k
    ps_dep_mngr_state->i4_num_horz_units = max_num_horz_units;
462
2.52k
    ps_dep_mngr_state->i4_num_vert_units = max_num_vert_units;
463
2.52k
    ps_dep_mngr_state->i1_sem_enable = sem_enable;
464
2.52k
    ps_dep_mngr_state->i4_dep_mngr_mode = dep_mngr_mode;
465
2.52k
    ps_dep_mngr_state->i4_num_thrds = num_threads;
466
2.52k
    ps_dep_mngr_state->i4_num_tile_cols = num_tile_cols;
467
468
    /* call the reset function baed on mode */
469
2.52k
    if(DEP_MNGR_FRM_FRM_SYNC == dep_mngr_mode)
470
1.19k
    {
471
1.19k
        ihevce_dmgr_rst_frm_frm_sync((void *)ps_dep_mngr_state);
472
1.19k
    }
473
1.32k
    else if(DEP_MNGR_ROW_ROW_SYNC == dep_mngr_mode)
474
1.32k
    {
475
1.32k
        ihevce_dmgr_rst_row_row_sync((void *)ps_dep_mngr_state);
476
1.32k
    }
477
0
    else
478
0
    {
479
0
        ihevce_dmgr_rst_row_frm_sync((void *)ps_dep_mngr_state);
480
0
    }
481
482
2.52k
    return ((void *)ps_dep_mngr_state);
483
2.52k
}
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
995
{
518
995
    WORD32 ctr;
519
995
    dep_mngr_state_t *ps_dep_mngr_state;
520
521
    /* dep manager state structure */
522
995
    ps_dep_mngr_state = (dep_mngr_state_t *)ps_mem_tab[DEP_MNGR_CTXT].pv_base;
523
524
995
    ps_dep_mngr_state->ai4_tile_xtra_ctb[0] = ai4_tile_xtra_ctb[0];
525
995
    ps_dep_mngr_state->ai4_tile_xtra_ctb[1] = ai4_tile_xtra_ctb[1];
526
995
    ps_dep_mngr_state->ai4_tile_xtra_ctb[2] = ai4_tile_xtra_ctb[2];
527
995
    ps_dep_mngr_state->ai4_tile_xtra_ctb[3] = ai4_tile_xtra_ctb[3];
528
529
    /* dep manager memory init */
530
995
    ps_dep_mngr_state->pv_units_prcsd_in_row = ps_mem_tab[DEP_MNGR_UNITS_PRCSD_MEM].pv_base;
531
995
    ps_dep_mngr_state->pi4_wait_thrd_id = (WORD32 *)ps_mem_tab[DEP_MNGR_WAIT_THRD_ID_MEM].pv_base;
532
995
    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
995
    ps_dep_mngr_state->pv_units_prcsd_in_row =
536
995
        (void*)((WORD8*)ps_dep_mngr_state->pv_units_prcsd_in_row +
537
995
        ps_dep_mngr_state->ai4_tile_xtra_ctb[1] +
538
995
        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
1.99k
    for(ctr = 0; ctr < num_threads; ctr++)
544
995
    {
545
995
        ps_dep_mngr_state->pi4_wait_thrd_id[ctr] = ctr;
546
995
    }
547
548
    /* reset the state structure variables */
549
995
    ps_dep_mngr_state->i4_num_horz_units = max_num_horz_units;
550
995
    ps_dep_mngr_state->i4_num_vert_units = max_num_vert_units;
551
995
    ps_dep_mngr_state->i1_sem_enable = sem_enable;
552
995
    ps_dep_mngr_state->i4_dep_mngr_mode = DEP_MNGR_MAP_SYNC;
553
995
    ps_dep_mngr_state->i4_num_thrds = num_threads;
554
555
    /* call the reset function baed on mode */
556
995
    ihevce_dmgr_map_rst_sync((void *)ps_dep_mngr_state);
557
558
995
    return ((void *)ps_dep_mngr_state);
559
995
}
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
3.51k
{
581
3.51k
    dep_mngr_state_t *ps_dep_mngr_state;
582
583
    /* dep manager state structure */
584
3.51k
    (void)ps_dep_mngr_state;
585
3.51k
    ps_dep_mngr_state = (dep_mngr_state_t *)pv_dep_mngr_state;
586
3.51k
}
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
3.51k
{
609
3.51k
    dep_mngr_state_t *ps_dep_mngr_state;
610
3.51k
    WORD32 ctr;
611
612
    /* dep manager state structure */
613
3.51k
    ps_dep_mngr_state = (dep_mngr_state_t *)pv_dep_mngr_state;
614
615
3.51k
    ASSERT(num_threads <= ps_dep_mngr_state->i4_num_thrds);
616
617
7.03k
    for(ctr = 0; ctr < num_threads; ctr++)
618
3.51k
    {
619
3.51k
        ps_dep_mngr_state->ppv_thrd_sem_handles[ctr] = ppv_thread_sem_hdl[ctr];
620
3.51k
    }
621
622
3.51k
    return;
623
3.51k
}
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
199
{
644
199
    dep_mngr_state_t *ps_dep_mngr_state;
645
199
    WORD32 thrds;
646
199
    ULWORD64 *pu8_num_units_proc_curr;
647
199
    ULWORD64 *pu8_num_units_proc_prev;
648
649
    /* dep manager state structure */
650
199
    ps_dep_mngr_state = (dep_mngr_state_t *)pv_dep_mngr_state;
651
652
    /* Reset the values num threads entering processing state  */
653
199
    pu8_num_units_proc_curr = (ULWORD64 *)ps_dep_mngr_state->pv_units_prcsd_in_row;
654
199
    pu8_num_units_proc_prev =
655
199
        (ULWORD64 *)(pu8_num_units_proc_curr + ps_dep_mngr_state->i4_num_thrds);
656
657
    /* Reset the values thread ids waiting */
658
398
    for(thrds = 0; thrds < ps_dep_mngr_state->i4_num_thrds; thrds++)
659
199
    {
660
199
        pu8_num_units_proc_prev[thrds] = 1;
661
199
        ps_dep_mngr_state->pi4_wait_thrd_id[thrds] = -1;
662
199
    }
663
664
199
    return;
665
199
}
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
1.19k
{
686
1.19k
    dep_mngr_state_t *ps_dep_mngr_state;
687
1.19k
    WORD32 thrds;
688
1.19k
    ULWORD64 *pu8_num_units_proc_curr;
689
690
    /* dep manager state structure */
691
1.19k
    ps_dep_mngr_state = (dep_mngr_state_t *)pv_dep_mngr_state;
692
693
    /* Reset the values num threads entering processing state  */
694
1.19k
    pu8_num_units_proc_curr = (ULWORD64 *)ps_dep_mngr_state->pv_units_prcsd_in_row;
695
696
    /* Reset the values thread ids waiting */
697
2.38k
    for(thrds = 0; thrds < ps_dep_mngr_state->i4_num_thrds; thrds++)
698
1.19k
    {
699
1.19k
        pu8_num_units_proc_curr[thrds] = 1;
700
1.19k
        ps_dep_mngr_state->pi4_wait_thrd_id[thrds] = -1;
701
1.19k
    }
702
703
1.19k
    return;
704
1.19k
}
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
240k
{
739
240k
    dep_mngr_state_t *ps_dep_mngr_state;
740
240k
    volatile WORD32 *pi4_ref_value;
741
240k
    WORD32 ref_value;
742
743
240k
    ps_dep_mngr_state = (dep_mngr_state_t *)pv_dep_mngr_state;
744
745
    /* Sanity Check */
746
240k
    ASSERT(dep_row >= 0);
747
240k
    ASSERT(dep_row < ps_dep_mngr_state->i4_num_vert_units);
748
240k
    ASSERT(cur_tile_col >= 0);
749
240k
    ASSERT(cur_tile_col < ps_dep_mngr_state->i4_num_tile_cols);
750
751
240k
    pi4_ref_value = ((volatile WORD32 *)(ps_dep_mngr_state->pv_units_prcsd_in_row)) +
752
240k
                    (cur_tile_col * ps_dep_mngr_state->i4_num_vert_units) + dep_row;
753
754
    /* Sanity Check */
755
240k
    ASSERT((cur_offset + dep_offset) <= ps_dep_mngr_state->i4_num_horz_units);
756
757
    /* Check whether Dep. is met */
758
240k
    while(1)
759
240k
    {
760
240k
        ref_value = *pi4_ref_value;
761
762
240k
        if(ref_value >= (cur_offset + dep_offset))
763
240k
            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
240k
    return 0;
783
240k
}
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
223k
{
810
223k
    dep_mngr_state_t *ps_dep_mngr_state;
811
223k
    WORD32 *pi4_units_prcsd;
812
223k
    void *pv_sem_handle;
813
223k
    WORD32 ret_val;
814
815
223k
    (void)ret_val;
816
223k
    ps_dep_mngr_state = (dep_mngr_state_t *)pv_dep_mngr_state;
817
818
    /* Sanity Check */
819
223k
    ASSERT(cur_offset >= 0);
820
223k
    ASSERT(cur_offset <= ps_dep_mngr_state->i4_num_horz_units);
821
223k
    ASSERT(cur_row <= ps_dep_mngr_state->i4_num_vert_units);
822
223k
    ASSERT(cur_tile_col >= 0);
823
223k
    ASSERT(cur_tile_col < ps_dep_mngr_state->i4_num_tile_cols);
824
825
223k
    DATA_SYNC();
826
827
223k
    pi4_units_prcsd = ((WORD32 *)(ps_dep_mngr_state->pv_units_prcsd_in_row)) +
828
223k
                      (cur_tile_col * ps_dep_mngr_state->i4_num_vert_units) + cur_row;
829
830
    /* Update the number of units processed */
831
223k
    *pi4_units_prcsd = cur_offset;
832
833
223k
    if(1 == ps_dep_mngr_state->i1_sem_enable)
834
184k
    {
835
184k
        WORD32 wait_thrd_id;
836
837
184k
        wait_thrd_id = ps_dep_mngr_state->pi4_wait_thrd_id[cur_row];
838
839
        /* Post on threads waiting on the current row */
840
184k
        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
184k
        if(cur_offset == ps_dep_mngr_state->i4_num_horz_units)
852
27.2k
        {
853
27.2k
            WORD32 ctr;
854
855
54.5k
            for(ctr = 0; ctr < ps_dep_mngr_state->i4_num_thrds; ctr++)
856
27.2k
            {
857
27.2k
                ret_val = osal_sem_post(ps_dep_mngr_state->ppv_thrd_sem_handles[ctr]);
858
                //ASSERT(0 == ret_val);
859
27.2k
            }
860
27.2k
        }
861
184k
    }
862
863
223k
    return 0;
864
223k
}
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
13.6k
{
889
13.6k
    dep_mngr_state_t *ps_dep_mngr_state;
890
13.6k
    void *pv_sem_handle;
891
13.6k
    volatile ULWORD64 *pu8_num_units_proc_prev;
892
13.6k
    volatile ULWORD64 *pu8_num_units_proc_curr;
893
13.6k
    ULWORD64 prev_value;
894
13.6k
    ULWORD64 curr_value;
895
896
13.6k
    ps_dep_mngr_state = (dep_mngr_state_t *)pv_dep_mngr_state;
897
13.6k
    pv_sem_handle = ps_dep_mngr_state->ppv_thrd_sem_handles[thrd_id];
898
899
13.6k
    pu8_num_units_proc_curr = (volatile ULWORD64 *)ps_dep_mngr_state->pv_units_prcsd_in_row;
900
13.6k
    pu8_num_units_proc_prev =
901
13.6k
        (volatile ULWORD64 *)(pu8_num_units_proc_curr + ps_dep_mngr_state->i4_num_thrds);
902
903
    /* Check whether Dep. is met */
904
13.6k
    while(1)
905
13.6k
    {
906
13.6k
        WORD32 ret_val;
907
908
13.6k
        (void)ret_val;
909
13.6k
        curr_value = pu8_num_units_proc_curr[thrd_id];
910
13.6k
        prev_value = pu8_num_units_proc_prev[thrd_id];
911
912
13.6k
        if(curr_value == (prev_value + 1))
913
13.6k
        {
914
13.6k
            break;
915
13.6k
        }
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
13.6k
    }
926
927
    /* store curr value to prev for next iteration */
928
13.6k
    pu8_num_units_proc_prev[thrd_id] = pu8_num_units_proc_curr[thrd_id];
929
930
13.6k
    return 0;
931
13.6k
}
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
13.4k
{
954
13.4k
    dep_mngr_state_t *ps_dep_mngr_state;
955
13.4k
    void *pv_sem_handle;
956
13.4k
    volatile ULWORD64 *pu8_num_units_proc_curr;
957
13.4k
    WORD32 ctr;
958
959
13.4k
    ps_dep_mngr_state = (dep_mngr_state_t *)pv_dep_mngr_state;
960
961
13.4k
    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
26.8k
    for(ctr = 0; ctr < ps_dep_mngr_state->i4_num_thrds; ctr++)
965
13.4k
    {
966
13.4k
        WORD32 ret_val;
967
13.4k
        WORD32 wait_thrd_id;
968
969
13.4k
        (void)ret_val;
970
        /* increment the curr unit counter for all threads */
971
13.4k
        pu8_num_units_proc_curr[ctr] = pu8_num_units_proc_curr[ctr] + 1;
972
973
13.4k
        wait_thrd_id = ctr;
974
        //wait_thrd_id    = ps_dep_mngr_state->pi4_wait_thrd_id[ctr];
975
976
13.4k
        if(-1 != wait_thrd_id)
977
13.4k
        {
978
13.4k
            pv_sem_handle = ps_dep_mngr_state->ppv_thrd_sem_handles[wait_thrd_id];
979
            /* Post on the semaphore */
980
13.4k
            ret_val = osal_sem_post(pv_sem_handle);
981
            //ASSERT(0 == ret_val);
982
983
13.4k
            ps_dep_mngr_state->pi4_wait_thrd_id[ctr] = -1;
984
13.4k
        }
985
13.4k
    }
986
987
13.4k
    return 0;
988
13.4k
}
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
15.2k
{
1013
15.2k
    WORD8 *pi1_ctb = pu1_start;
1014
15.2k
    WORD32 row, col;
1015
15.2k
    WORD32 map_ready_flag = MAP_CTB_COMPLETE;
1016
1017
56.9k
    for(row = 0; row < i4_num_ctb_y; row++)
1018
41.7k
    {
1019
206k
        for(col = 0; col < i4_num_ctb_x; col++)
1020
164k
        {
1021
164k
            map_ready_flag &= pi1_ctb[col];
1022
164k
        }
1023
41.7k
        pi1_ctb += i4_stride;
1024
41.7k
    }
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
15.2k
    return (map_ready_flag == MAP_CTB_COMPLETE);
1029
15.2k
}
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
15.2k
{
1063
15.2k
    dep_mngr_state_t *ps_dep_mngr_state;
1064
15.2k
    volatile WORD8 *pi1_ctb;
1065
15.2k
    WORD8 *pi1_tile_start;
1066
15.2k
    WORD32 i4_avail_left, i4_avail_right, i4_avail_top, i4_avail_bot;
1067
15.2k
    WORD32 i4_num_ctb_x, i4_num_ctb_y;
1068
15.2k
    WORD32 i4_stride;
1069
15.2k
    WORD32 i4_tile_wd, i4_tile_ht;  //in ctb units
1070
1071
15.2k
    ps_dep_mngr_state = (dep_mngr_state_t *)pv_dep_mngr_state;
1072
1073
15.2k
    i4_tile_wd = ps_dep_mngr_state->i4_num_horz_units - ps_dep_mngr_state->ai4_tile_xtra_ctb[1] -
1074
15.2k
                 ps_dep_mngr_state->ai4_tile_xtra_ctb[2];
1075
1076
15.2k
    i4_tile_ht = ps_dep_mngr_state->i4_num_vert_units - ps_dep_mngr_state->ai4_tile_xtra_ctb[0] -
1077
15.2k
                 ps_dep_mngr_state->ai4_tile_xtra_ctb[3];
1078
1079
15.2k
    i4_stride = ps_dep_mngr_state->i4_num_horz_units;
1080
1081
    /* Sanity Checks, confirm if ctb offsets are within tiles */
1082
15.2k
    ASSERT(offset_x >= 0);
1083
15.2k
    ASSERT(offset_y >= 0);
1084
15.2k
    ASSERT(offset_x < i4_tile_wd);
1085
15.2k
    ASSERT(offset_y < i4_tile_ht);
1086
1087
15.2k
    pi1_tile_start = (WORD8 *)ps_dep_mngr_state->pv_units_prcsd_in_row;
1088
15.2k
    pi1_ctb = (volatile WORD8 *)pi1_tile_start;
1089
1090
15.2k
    if(ps_dep_mngr_state->ai4_tile_xtra_ctb[0])
1091
0
    {
1092
0
        i4_avail_top = i4_sr_ctb_y;
1093
0
    }
1094
15.2k
    else
1095
15.2k
    {
1096
15.2k
        i4_avail_top = MIN(i4_sr_ctb_y, offset_y);
1097
15.2k
    }
1098
1099
15.2k
    if(ps_dep_mngr_state->ai4_tile_xtra_ctb[1])
1100
0
    {
1101
0
        i4_avail_left = i4_sr_ctb_x;
1102
0
    }
1103
15.2k
    else
1104
15.2k
    {
1105
15.2k
        i4_avail_left = MIN(i4_sr_ctb_x, offset_x);
1106
15.2k
    }
1107
1108
15.2k
    if(ps_dep_mngr_state->ai4_tile_xtra_ctb[2])
1109
0
    {
1110
0
        i4_avail_right = i4_sr_ctb_x;
1111
0
    }
1112
15.2k
    else
1113
15.2k
    {
1114
15.2k
        i4_avail_right = MIN(i4_sr_ctb_x, (i4_tile_wd - offset_x - 1));
1115
15.2k
    }
1116
1117
15.2k
    if(ps_dep_mngr_state->ai4_tile_xtra_ctb[3])
1118
0
    {
1119
0
        i4_avail_bot = i4_sr_ctb_y;
1120
0
    }
1121
15.2k
    else
1122
15.2k
    {
1123
15.2k
        i4_avail_bot = MIN(i4_sr_ctb_y, (i4_tile_ht - offset_y - 1));
1124
15.2k
    }
1125
1126
15.2k
    i4_num_ctb_x = (i4_avail_left + 1 + i4_avail_right);
1127
15.2k
    i4_num_ctb_y = (i4_avail_top + 1 + i4_avail_bot);
1128
1129
    /* Point to the start of the search-area */
1130
15.2k
    pi1_ctb += ((offset_y - i4_avail_top) * i4_stride + (offset_x - i4_avail_left));
1131
1132
    /* Check whether Dep. is met */
1133
15.2k
    while(1)
1134
15.2k
    {
1135
15.2k
        if(1 == ihevce_dmgr_map_chk((WORD8 *)pi1_ctb, i4_num_ctb_x, i4_num_ctb_y, i4_stride))
1136
15.2k
        {
1137
15.2k
            break;
1138
15.2k
        }
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
15.2k
    }
1147
1148
15.2k
    return 0;
1149
15.2k
}
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
13.4k
{
1174
13.4k
    dep_mngr_state_t *ps_dep_mngr_state;
1175
13.4k
    WORD8 *pi1_tile_start;
1176
13.4k
    WORD32 map_stride;
1177
1178
13.4k
    ps_dep_mngr_state = (dep_mngr_state_t *)pv_dep_mngr_state;
1179
1180
    /* Sanity Checks */
1181
13.4k
    ASSERT(offset_x >= (-ps_dep_mngr_state->ai4_tile_xtra_ctb[1]));
1182
13.4k
    ASSERT(offset_y >= (-ps_dep_mngr_state->ai4_tile_xtra_ctb[0]));
1183
1184
13.4k
    ASSERT(
1185
13.4k
        offset_x <
1186
13.4k
        (ps_dep_mngr_state->i4_num_horz_units - ps_dep_mngr_state->ai4_tile_xtra_ctb[1]));
1187
1188
13.4k
    ASSERT(
1189
13.4k
        offset_y <
1190
13.4k
        (ps_dep_mngr_state->i4_num_vert_units - ps_dep_mngr_state->ai4_tile_xtra_ctb[0]));
1191
1192
13.4k
    DATA_SYNC();
1193
1194
13.4k
    map_stride = ps_dep_mngr_state->i4_num_horz_units;
1195
1196
13.4k
    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
13.4k
    *(pi1_tile_start + offset_y * map_stride + offset_x) = (WORD8)i4_map_value;
1200
1201
13.4k
    if(1 == ps_dep_mngr_state->i1_sem_enable)
1202
8.78k
    {
1203
8.78k
        WORD32 wait_thrd_id;
1204
1205
        /* Post on threads waiting on the current row */
1206
17.5k
        for(wait_thrd_id = 0; wait_thrd_id < ps_dep_mngr_state->i4_num_thrds; wait_thrd_id++)
1207
8.78k
        {
1208
            /* Post on the semaphore */
1209
            /* Map-mode: semaphore post is unconditionally done on all threads */
1210
8.78k
            osal_sem_post(ps_dep_mngr_state->ppv_thrd_sem_handles[wait_thrd_id]);
1211
8.78k
        }
1212
8.78k
    }
1213
1214
13.4k
    return 0;
1215
13.4k
}