Worker
- class mcai_worker_sdk.Worker
Worker base class to extend to define your own worker.
This class defines several abstract methods that may be re-implemented. However, most of them will be directly called and you won’t need to call them explicitly.
- Parameters:
parameters (
WorkerParameters) – Class definition of the worker’s parameters.description (
WorkerDescription) – Instance of WorkerDescription.Warning
The constructor may not be re-implemented. Use the
setup()method instead.
- setup()
Method called once to set up the worker. This method should not be called explicitly but will be called automatically after worker initialization.
This method may be used to load specific resources, perform checks, etc. before processing jobs.
Note
This method is optional but must be used instead of re-defining the constructor.
- init_process(context, parameters)
Method called for initializing the media process.
It defines the streams that will be handled through
process_frames()method and the FFmpeg filters that need to be applied.
- Parameters:
context (
FormatContext) – Context describing the media to process.parameters (
WorkerParameters) – Parameters received for the current job.- Returns:
A list of Stream descriptors that will be handled during process
- Return type:
list
- Raises:
NotImplementedError –
- process_frames(job_id, stream_index, frames)
Method called for processing a batch of frames. This is were the major logic of your worker should reside.
- Parameters:
job_id (int) – ID of the current job.
stream_index (int) – Index of the current stream.
frames (list[
Frame]) – The list of frames in the batch.- Raises:
NotImplementedError –
Note
You do not have to call this method explicitly, but you must define it. It will be called during the processing of the job.
- ending_process()
Function called at the end of the process. It might be used to clean up some variables or anything else related to the process.
Note
This method is optional.
- start()
Method called for starting the worker. Once called, the worker will automatically start listening to new orders to process.
This is the only method you will have to call explicitly, other methods will be called directly by the SDK.
Warning
This method must not be re-implemented.