CRI Sofdec2  Last Updated: 2022-11-21 16:25 p
Library Initialization
This section describes the initialization function, the termination function and the decode processing for Sofdec.Prime codec.

For the VP9 codec, please refer to the following manual in VP9 function extension folder.
CRIWARE/Expansion/readme_cri_sofdec2_codecs_vp9_expansion_pc_en.html

PC-specific Initialization/Finalization Functions

The PC version of the CRI Mana library includes PC-specific initialization and finalization functions.
These setting functions are optional, and the normal general-purpose initialization/finalization functions can be used if you prefer.

The PC version of the CRI Mana library uses multiple cores for movie decoding by default.
Normally, this multicore setting does not need to be changed, but you can change the multicore setting by using a special initialization function.

Sofdec2 Decode Processing

Sofdec2 includes functionality to distribute video frame decoding across multiple CPU cores.

Sofdec2's decode processing is executed in the following two locations.

(1) Decoding master thread
(2) Worker threads

The decoding master thread and worker threads are created automatically at library initialization.
The decoding master thread calls criManaPlayer_ExecuteVideoProcess()
and manages worker thread tasks while performing its own video decoding.
Worker threads are triggered by criManaPlayer_ExecuteVideoProcess()
and perform video decoding for the portion they are distributed.
The maximum number of worker threads available depends on the device, but on Windows the maximum number is 7.
In CRI Sofdec2 Version 1.70 the maximum number of worker threads was increased to 7. Previously, the maximum number was limited to 3.


Thread Model and Multicore Relationship

You can specify a thread model when initializing Sofdec2. For details, refer to Threads.
This chapter explains the "multithreaded framework".

If "single thread framework" is used, no decoding master thread is created during library initialization.
However, 7 worker threads will be created regardless of the thread model or the number of threads specified during initialization.

Multicore Decoding Settings

Which CPU is used to perform which decoding process is normally assigned by the OS as necessary, and there is no need for this operation to be handled by the application.

If you want to manage the CPU assignments for decoding in your application, you must configure the CPU settings for the decoding master thread and worker threads.


Decoding Master Thread Settings

You can configure the processor settings for the decoding master thread by calling a special function after library initialization.
The priority setting values are based on the standard thread parameters for Windows.

#include <windows.h>
CriSint32 master_thread_priority;
/* Library initialization */
criMana_Initialize_PC(&lib_config, NULL, 0);
/* Decoding master thread settings */
master_thread_priority = THREAD_PRIORITY_BELOW_NORMAL;
criMana_SetDecodeThreadPriority_PC(master_thread_priority);
#define criMana_SetDefaultLibConfig_PC(p_config)
Set default values for the library initialization config structure.
Definition: cri_mana_pc.h:65
void criMana_SetDecodeThreadPriority_PC(int prio)
Change decoding master thread priority.
void criMana_Initialize_PC(const CriManaLibConfig_PC *config, void *work, CriSint32 work_size)
Library initialization function (with PC specific functions)
Mana library initialization parameters.
Definition: cri_mana_pc.h:124

Worker Thread Settings

The decoding settings for worker threads are specified as parameters to the PC-specific library initialization function, CriMana_Initialize_PC().
The PC-specific library initialization function includes the functionality of the general purpose initialization function, so do not call the general purpose initialization function.
The affinity mask and priority setting values are based on the standard thread parameters for Windows.
If NULL is specified for the affinity mask array, permission is given for all CPUs.

#include <windows.h>
#define AFFINITY_MASK_CPU00 (0x1)
#define AFFINITY_MASK_CPU01 (0x2)
#define AFFINITY_MASK_CPU02 (0x4)
#define AFFINITY_MASK_CPU03 (0x8)
#define AFFINITY_MASK_CPU04 (0x10)
#define AFFINITY_MASK_CPU05 (0x20)
#define AFFINITY_MASK_CPU06 (0x40)
#define AFFINITY_MASK_CPU07 (0x80)
#define AFFINITY_MASK_ALL (0xFF)
CriSint32 num_thread = 3;
CriUint32 affinity_masks[] = {
AFFINITY_MASK_CPU02,
AFFINITY_MASK_CPU03 | AFFINITY_MASK_CPU04,
AFFINITY_MASK_ALL,
}
/* [PC-specific] Library initialization parameter specification */
lib_config.mana.max_decoder_handles = 4;
/* [PC-specific] Worker thread processor specification */
lib_config.processor.num_threads = num_thread;
lib_config.processor.affinity_masks = affinity_masks;
lib_config.processor.priority = THREAD_PRIORITY_BELOW_NORMAL;
/* [PC-specific] Mana library initialization */
lib_work_size = criMana_Calculate_PC(&lib_config);
lib_work = malloc(lib_work_size);
//criMana_Initialize(&lib_config, lib_work, lib_work_size);
criMana_Initialize_PC(&lib_config, lib_work, lib_work_size);
.....
/* [PC-specific] Mana library finalization */
//criMana_Finalize();
criMana_Finalize_PC();
@ CRIMANA_THREAD_MODEL_MULTI
Definition: cri_mana.h:256
CriManaProcessorConfig_PC processor
Definition: cri_mana_pc.h:126
CriManaLibConfig mana
Definition: cri_mana_pc.h:125
CriUint32 max_decoder_handles
Definition: cri_mana.h:461
CriManaThreadModel thread_model
Definition: cri_mana.h:462
CriSint32 num_threads
Definition: cri_mana_pc.h:111
int priority
Definition: cri_mana_pc.h:113
const DWORD * affinity_masks
Definition: cri_mana_pc.h:112
Additional Notes
Currently, the relationship between the number of processors available for use on the PC, the decoding master thread for the PC version of the CRI Mana library,
and the number of worker threads that can be used is as follows:

Item Number Notes
PC: Number of usable processors 8
Mana: Number of decoding master threads 1 Always one on all targets
Mana: Number of usable worker threads 7 PC: Number of usable processors - Mana: Number of decoding master threads

To perform the most effective distributed movie decoding, the above decoding master thread and worker threads must be
assigned to the processors available for use on the PC.

If you want to limit the number of processors to use for movie decoding, you can choose to use only a single decoding master thread
and set the number of worker threads to 0.
However, a lower number of processors available for decoding may result in dropped
frames during movie playback. Configure and adjust these settings as required for debugging or the needs for your application.

Note that assigning the decoding master thread and worker threads to the same processor has little
meaning, and will reduce performance due to context switching load, so be careful when
configuring these settings. Be sure to configure the affinity mask settings properly to avoid this problem.