Updated on 2023-03-23 GMT+08:00

Obtaining Audio Data Streams

API Description

This API is used to obtain the audio data streams after audio mixing of each venue in a meeting.

Precautions

This API is an asynchronous API. The return value of the callback function only indicates whether the API is successfully called. The actual service processing result is returned in the corresponding notification function.

This API can be called before joining a meeting. After a meeting is created or joined, a notification is sent.

Method Definition

HWM_SDK_AGENT_API hwmsdk::HwmErrCode SetAudioRawDataOutputConfig(bool isOpen);

Callback Function

virtual void OnSetAudioRawDataOutputConfigResult(hwmsdk::HwmErrCode ret, const char* reason) {};

Notification Function

virtual void OnAudioFrameNotify(const AudioFrameData* pFrame) {};

Parameter Description

Table 1 Parameter description

Parameter

Mandatory

Type

Description

isOpen

Yes

bool

Whether to enable the function.

Table 2 Return values

Type

Description

HwmErrCode

If 0 is returned, the operation is successful. If other values are returned, the operation fails. For details about values returned upon failures, see Common Error Codes.

Table 3 AudioFrameData parameters

Parameter

Type

Description

eFrameType

AudioFrameType

Audio frame type.

iSamples

signed int

Number of sampling points for each channel.

iSamplesPerSec

signed int

Sampling ratio.

iBytesPerSample

signed int

Number of bytes of each sampling point. Generally, the PCM audio is two bytes.

iChannels

signed int

Number of audio channels.

pBuffer

char *

Data buffer. Length = iSamples x iBytesPerSample x iChannels

uiDataLen

signed int

Data length, which is used after encoding or before decoding. The value of this parameter needs to be updated after encryption or decryption.

uiBufferLen

signed int

Buffer length. The encoded data is encrypted by a third party. The data length increases to prevent overflow.

Table 4 Enumerated values of AudioFrameType

Enumerated Value

Description

AUDIO_FRAME_TYPE_PCM16

16-bit precision PCM

Sample Code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
/**
* The notification of reporting audio stream frame data
*/
void demoNotifyProc::OnAudioFrameNotify(const AudioFrameData* pFrame)
{
    if(nullptr != pFrame)
    {
        FILE* recordFile = nullptr;
        std::string Path ("D:\\AudioFrame.pcm");
        auto error = fopen_s(&recordFile,Path.c_str(), "ab+");
        if (error != 0)
        {
            CTools::OutputRetStr("open file error = " + std::to_string(error));
        }

        if (nullptr != recordFile)
        {
            fwrite(pFrame->pBuffer, sizeof(char), pFrame->iSamples * pFrame->iBytesPerSample * pFrame->iChannels, recordFile);
            fclose(recordFile);
        }
    }
}