@@ -754,8 +754,9 @@ static int enc_ready(oapve_ctx_t *ctx)
754754 min_num_tiles = oapv_min (min_num_tiles , num_tiles );
755755 }
756756
757- if (ctx -> cdesc .threads == OAPVE_CDESC_THREADS_AUTO ) {
758- ctx -> threads = oapv_min (OAPV_MAX_THREADS , oapv_min (oapv_get_num_cpu_cores (), min_num_tiles ));
757+ if (ctx -> cdesc .threads == OAPV_CDESC_THREADS_AUTO ) {
758+ int num_cores = oapv_get_num_cpu_cores ();
759+ ctx -> threads = oapv_min (OAPV_MAX_THREADS , oapv_min (num_cores , min_num_tiles ));
759760 }
760761 else {
761762 ctx -> threads = ctx -> cdesc .threads ;
@@ -1820,11 +1821,11 @@ static int dec_thread_tile(void *arg)
18201821
18211822static void dec_flush (oapvd_ctx_t * ctx )
18221823{
1823- if (ctx -> cdesc . threads >= 2 ) {
1824+ if (ctx -> threads >= 2 ) {
18241825 if (ctx -> tpool ) {
18251826 // thread controller instance is present
18261827 // terminate the created thread
1827- for (int i = 0 ; i < ctx -> cdesc . threads - 1 ; i ++ ) {
1828+ for (int i = 0 ; i < ctx -> threads - 1 ; i ++ ) {
18281829 if (ctx -> thread_id [i ]) {
18291830 // valid thread instance
18301831 ctx -> tpool -> release (& ctx -> thread_id [i ]);
@@ -1839,7 +1840,7 @@ static void dec_flush(oapvd_ctx_t *ctx)
18391840
18401841 oapv_tpool_sync_obj_delete (& (ctx -> sync_obj ));
18411842
1842- for (int i = 0 ; i < ctx -> cdesc . threads ; i ++ ) {
1843+ for (int i = 0 ; i < ctx -> threads ; i ++ ) {
18431844 dec_core_free (ctx -> core [i ]);
18441845 }
18451846}
@@ -1848,28 +1849,37 @@ static int dec_ready(oapvd_ctx_t *ctx)
18481849{
18491850 int i , ret = OAPV_OK ;
18501851
1852+ if (ctx -> cdesc .threads == OAPV_CDESC_THREADS_AUTO ) {
1853+ int num_cores = oapv_get_num_cpu_cores ();
1854+ ctx -> threads = oapv_min (OAPV_MAX_THREADS , num_cores );
1855+ }
1856+ else {
1857+ ctx -> threads = ctx -> cdesc .threads ;
1858+ }
1859+ oapv_assert_gv (ctx -> threads > 0 && ctx -> threads <= OAPV_MAX_THREADS , ret , OAPV_ERR_INVALID_ARGUMENT , ERR );
1860+
18511861 if (ctx -> core [0 ] == NULL ) {
18521862 // create cores
1853- for (i = 0 ; i < ctx -> cdesc . threads ; i ++ ) {
1863+ for (i = 0 ; i < ctx -> threads ; i ++ ) {
18541864 ctx -> core [i ] = dec_core_alloc ();
18551865 oapv_assert_gv (ctx -> core [i ], ret , OAPV_ERR_OUT_OF_MEMORY , ERR );
18561866 ctx -> core [i ]-> ctx = ctx ;
18571867 }
18581868 }
18591869
18601870 // initialize the threads to NULL
1861- for (i = 0 ; i < OAPV_MAX_THREADS ; i ++ ) {
1871+ for (i = 0 ; i < ctx -> threads ; i ++ ) {
18621872 ctx -> thread_id [i ] = 0 ;
18631873 }
18641874
18651875 // get the context synchronization handle
18661876 ctx -> sync_obj = oapv_tpool_sync_obj_create ();
18671877 oapv_assert_gv (ctx -> sync_obj != NULL , ret , OAPV_ERR_UNKNOWN , ERR );
18681878
1869- if (ctx -> cdesc . threads >= 2 ) {
1879+ if (ctx -> threads >= 2 ) {
18701880 ctx -> tpool = oapv_malloc (sizeof (oapv_tpool_t ));
1871- oapv_tpool_init (ctx -> tpool , ctx -> cdesc . threads - 1 );
1872- for (i = 0 ; i < ctx -> cdesc . threads - 1 ; i ++ ) {
1881+ oapv_tpool_init (ctx -> tpool , ctx -> threads - 1 );
1882+ for (i = 0 ; i < ctx -> threads - 1 ; i ++ ) {
18731883 ctx -> thread_id [i ] = ctx -> tpool -> create (ctx -> tpool , i );
18741884 oapv_assert_gv (ctx -> thread_id [i ] != NULL , ret , OAPV_ERR_UNKNOWN , ERR );
18751885 }
@@ -1919,7 +1929,7 @@ oapvd_t oapvd_create(oapvd_cdesc_t *cdesc, int *err)
19191929 ctx = NULL ;
19201930
19211931 /* check if any decoder argument is correctly set */
1922- oapv_assert_gv (cdesc -> threads > 0 && cdesc -> threads <= OAPV_MAX_THREADS , ret , OAPV_ERR_INVALID_ARGUMENT , ERR );
1932+ oapv_assert_gv (( cdesc -> threads > 0 && cdesc -> threads <= OAPV_MAX_THREADS ) || cdesc -> threads == OAPV_CDESC_THREADS_AUTO , ret , OAPV_ERR_INVALID_ARGUMENT , ERR );
19231933
19241934 /* memory allocation for ctx and core structure */
19251935 ctx = (oapvd_ctx_t * )dec_ctx_alloc ();
@@ -2008,7 +2018,7 @@ int oapvd_decode(oapvd_t did, oapv_bitb_t *bitb, oapv_frms_t *ofrms, oapvm_t mid
20082018 int parallel_task = 1 ;
20092019 int tidx = 0 ;
20102020
2011- parallel_task = (ctx -> cdesc . threads > ctx -> num_tiles ) ? ctx -> num_tiles : ctx -> cdesc . threads ;
2021+ parallel_task = (ctx -> threads > ctx -> num_tiles ) ? ctx -> num_tiles : ctx -> threads ;
20122022
20132023 /* decode tiles ************************************/
20142024 for (tidx = 0 ; tidx < (parallel_task - 1 ); tidx ++ ) {
0 commit comments