DecodeOne.cpp and covers a single-stream decoding scenario with one client.
Audio hardware connection and startup
Decoding starts by establishing a connection with the hardware acceleration unit via XApuConnect. The caller sets the requirements for the connection by using XApuConnectInputParameters to set up the following:- The processing type (in this case, XApuProcessType::DecodeOpus).
- The number of streams (in this case, 1).
- The total memory that’s required to pass and retrieve the input and the output data, in this case, 1024 for
MaxInputBufferLength(must be equal to or greater than the largest Opus packet in the stream). The number must also be a multiple of 16 and 7680. This is 20 ms of data at 48 K, which is 960 × 2 × sizeof(float) = 7680 forMaxOutputBufferLength. The output also needs to be a multiple of 16.
Activation and deactivation of streams
After the connection is established with the device, the caller should send a stream activation command to engage a single decoding engine. The caller must specify the stream index and the channel count. Only mono or stereo streams are allowed. The caller should call XApuDequeueResult to get the activation result. Because XApuConnectInputParameters::maxQueuedCommandsPerStream is set to 1 in this sample, the caller has to wait for each result before submitting the next command. This includes theActivate, Process, and Deactivate commands (for details, see XApuCommandType).
Following is the code to activate one stream.
Process command, the caller must do the following:
- Fill the input buffer with exactly one Opus packet.
- Specify the length of the packet.
- Provide the location to the output buffer that will be filled with decoded data by the audio hardware acceleration unit.
- Specify the maximum length of the output buffer.
streamIndex and frameCount values. If all the decoded data is required to be copied to the output buffer, the frameCount value can be set to any value that’s equal to or greater than the number of frames that are encoded in the packet (for example, for a 20 ms packet, frameCount can be set between 960 and 0xFFFFFFFF).
result.outputData. After it’s processed, the next packet should be submitted for decoding with a new call to XApuEnqueueCommand with the XApuCommandType::Process command.
