The following Figure 1 shows what an application using the VCU2 Control Software API could look like.
The encode thread initializes the settings for the encoder, passes these settings to the encoder create function. Then it proceeds with creating stream buffers for the output stream which it pushes into the encoder.
Next it populates the source buffer pool containing YUV frames. The encoder thread then waits in a loop for the next available source buffer, which it fills and sends to the encoder for processing. Once the last frame is encoded, the thread destroys the encoder and frees the stream and source buffers.
Reference counting is used for stream and source buffers. A callback is provided when creating a buffer that is called when the reference count reaches 0. Source buffers is put back into the pool in that case, and stream buffers are pushed back into the encoder.
The firmware does the encoding using the RISC-V CPU that is part of the VCU2 IP. The End Encoding callback is called in several cases:
- Encoding of a frame completes, in this case the stream buffer is to be output and optionally reconstructed YUV frames can be retrieved and output also.
- A stream buffer is returned that is to be freed.
- A source buffer is returned that is to be freed.
- Nothing is returned, indicating the encoding ended and nothing more is to be output.