API Call Sequence

If video decoding is involved during app development, ensure that your app contains the code logic for such video decoding. For details about the API call sequence, see API Call Sequence. For details about the VDEC functions, see Functions and Restrictions.

Figure 1 Video decoding

This module implements video decoding. The key APIs are described as follows:

  1. Call aclvdecCreateChannel to create a video decoding channel.
    • Perform the following steps before creating a video decoding channel.
      1. Call aclvdecCreateChannelDesc to create a channel description.
      2. Call aclvdecSetChannelDesc series to set the decoding channel description, including the channel ID, thread, callback function, and video coding protocol.
        1. The callback function needs to be created by the user in advance. It is used to obtain the decoding output and destroy allocations in a timely manner. For details about the callback function prototype, see aclvdecCallback.

          Call acldvppGetPicDescRetCode in the callback function to obtain the return code retCode. The value 0 indicates the success of decoding, while 1 indicates failure. If the decoding fails, locate the fault based on the return code in the log. For details, see Return Codes.

          After the decoding is complete, free the input and output buffers and destroy the stream description and image description in the callback function in a timely manner.

        2. The user needs to create a thread and define a thread function in advance. Once aclrtProcessReport is called in the thread function, the created callback function in 1.b.i will be triggered after a specified period of time.

        If aclvdecSetChannelDescOutPicFormat is not called to set the output format, images in YUV420SP (NV12) are output by default.

    • The following APIs are encapsulated in aclvdecCreateChannel and do not need to be called separately:
      1. aclrtCreateStream: explicitly creates a stream. It is internally used by VDEC.
      2. aclrtSubscribeReport: subscribes to a thread for handling the callback function in a stream. The callback function and thread are specified by the calls to the aclvdecSetChannelDesc series.
  2. Call aclvdecSendFrame to decode the video stream into YUV420SP images.
    • Perform the following steps before decoding a video stream:
    • aclrtLaunchCallback is encapsulated in aclvdecSendFrame to insert a callback function that needs to be executed to the stream. aclrtLaunchCallback does not need to be called separately.
    • To obtain the frame sequence number returned after decoding, define the userData parameter of aclvdecSendFrame. Then, the sequence number can be passed to the VDEC callback function to determine the frame to be processed.
  3. Call aclvdecDestroyChannel to destroy the channel.
    • The channel is destroyed only after the transmitted frames are decoded and the callback function is processed.
    • The following APIs are encapsulated in aclvdecDestroyChannel and do not need to be called separately:
    • After destroying the channel, call aclvdecDestroyChannelDesc to destroy the channel description.
    • After destroying the channel description, destroy the thread created in 1.b.ii.