Rate This Document
Findability
Accuracy
Completeness
Readability

API Description

The normal running of the instruction stream engine server requires external video encoding (VENC) APIs. These APIs are implemented by secondary developers and provided as a DLL.

The returns of the VENC API are defined as follows:

enum class EncoderRetCode : uint32_t {
    VIDEO_ENCODER_SUCCESS         = 0x00,
    VIDEO_ENCODER_CREATE_FAIL     = 0x01,  // Failed to create an encoder.
    VIDEO_ENCODER_INIT_FAIL       = 0x02,  // Failed to initialize the encoder.
    VIDEO_ENCODER_START_FAIL      = 0x03,  // Failed to start the encoder.
    VIDEO_ENCODER_ENCODE_FAIL     = 0x04,  // Failed to encode data.
    VIDEO_ENCODER_STOP_FAIL       = 0x05,  // Failed to stop the encoder.
    VIDEO_ENCODER_DESTROY_FAIL    = 0x06,  // Failed to destroy the encoder.

};

The encoder parameters are defined as follows:

struct EncodeParam {
    uint32_t width     = 0;  // I/O width of video encoding
    uint32_t height    = 0;  // I/O height of video encoding
    uint32_t frameRate = 0;  // Input frame rate of video encoding
    uint32_t bitrate   = 0;  // Output bit rate of video encoding
};

Example Call

// The function prototype declaration and definition are implemented by users.
const std::string VENC_SHARED_LIB_NAME = "libVideoEncoder.so";
using VencCreateEncoderFunc = EncoderRetCode (*)(uint32_t *encHandle);
using VencInitEncoderFunc = EncoderRetCode (*)(uint32_t encHandle, const EncodeParam encParams);
using VencStartEncoderFunc = EncoderRetCode (*)(uint32_t encHandle);
using VencEncodeOneFrameFunc = EncoderRetCode (*)(uint32_t encHandle, const uint8_t *inputData, uint32_t inputSize, uint8_t **outputData, uint32_t *outputSize);
using VencStopEncoderFunc = EncoderRetCode (*)(uint32_t encHandle);
using VencDestroyEncoderFunc = EncoderRetCode (*)(uint32_t encHandle);

void Test()  
{ 
    // Function symbol for dynamically loading the VENC dynamic library.
    void *handle = dlopen(VENC_SHARED_LIB_NAME.c_str(), RTLD_NOW);
    VencCreateEncoderFunc createEncoder = reinterpret_cast<VencCreateEncoderFunc>(dlsym(handle, VENC_CREATE_ENCODER_STR.c_str()));
    VencInitEncoderFunc initEncoder = reinterpret_cast<VencInitEncoderFunc>(dlsym(handle, VENC_CREATE_ENCODER_STR.c_str()));
    VencStartEncoderFunc startEncoder = reinterpret_cast<VencStartEncoderFunc>(dlsym(handle, VENC_CREATE_ENCODER_STR.c_str()));
    VencEncodeOneFrameFunc encodeOneFrame = reinterpret_cast<VencEncodeOneFrameFunc>(dlsym(handle, VENC_CREATE_ENCODER_STR.c_str()));
    VencStopEncoderFunc stopEncoder = reinterpret_cast<VencStopEncoderFunc>(dlsym(handle, VENC_CREATE_ENCODER_STR.c_str()));
    VencDestroyEncoderFunc destroyEncoder = reinterpret_cast<VencDestroyEncoderFunc>(dlsym(handle, VENC_CREATE_ENCODER_STR.c_str()));

    // Create an encoder.
    uint32_t encHandle = 0;
    EncoderRetCode ret = createEncoder(&encHandle);
    if (ret != VIDEO_ENCODER_SUCCESS) {
        // If the encoder fails to be created, process the error.
    }

    // Initialize the encoder.
    EncodeParam param = {
        .width = ...,
        .height = ...,
        .frameRate = ...,
        .bitrate = ...
    };
    EncoderRetCode ret = initEncoder(encHandle, param);
    if (ret != VIDEO_ENCODER_SUCCESS) {
        // If the encoder fails to be initialized, process the error.
    }

    // Start the encoder.
    EncoderRetCode ret = startEncoder(encHandle);
    if (ret != VIDEO_ENCODER_SUCCESS) {
        // If the encoder fails to be started, process the error.
    }

    // Encode data of one frame.
    uint8_t *inputData = ...; 
    uint32_t inputSize = ...;
    uint8_t *outputData = nullptr;
    uint32_t outputSize = 0;
    EncoderRetCode ret = encodeOneFrame(encHandle, inputData, inputSize, &outputData, &outputSize);
    if (ret != VIDEO_ENCODER_SUCCESS) {
        // If the data of one frame fails to be encoded, process the error.
    }

    // Stop the encoder.
    EncoderRetCode ret = stopEncoder(encHandle);
    if (ret != VIDEO_ENCODER_SUCCESS) {
        // If the encoder fails to be stopped, process the error.
    }

    // Destroy the encoder.
    EncoderRetCode ret = destroyEncoder(encHandle);
    if (ret != VIDEO_ENCODER_SUCCESS) {
        // If the encoder fails to be destroyed, process the error.
    }
    dlclose(handle);
}