NVR Scenario Voice Intercom
This section describes the typical processes, key APIs, and precautions for NVR audio service processing.
Network Video Recorder (NVR) is the storage and forwarding component of a network video system. Working together with network cameras, an NVR records, stores, and forwards audio and video. In addition, an NVR provides a local human-machine interaction interface, video decoding, video display, and voice intercom functions.
NVR Audio Scenario Description
This section describes the API call process of the NVR audio service (voice intercom function). The voice intercom function includes initialization and deinitialization of the media data processing system, receiving voice from an IP camera and playing the audio, and recording audio and sending voice to an IP camera. The involved modules include the common module, audio input module (AI), audio encoding module (AENC), audio output module (AO), and audio decoding module (ADEC).

Receiving Audio from an IP Camera and Playing It
Figure 1 Receiving audio from an IP camera and playing it
The API call process is described as follows:
Call the hi_mpi_adec_create_chn API to create an audio decoding channel.
Enable the AO audio output device and channel:
Call the hi_mpi_ao_set_pub_attr API to set the AO device attributes.
Call the hi_mpi_ao_enable API to start the AO device.
Call the hi_mpi_ao_enable_chn API to start the AO channel.
Call the hi_mpi_ao_enable_resample API to enable the AO resampling function.
Because the AO sampling rate is fixed at 48 kHz, while the G.711a and G.711u protocols support only an 8 kHz sampling rate, the resampling function must be enabled. In contrast, 48 kHz falls within the sampling rate range supported by the AAC protocol, so no resampling is required for AO when the AAC protocol is used.
Call the hi_mpi_sys_bind API to bind ADEC and AO.
ADEC Device ID ADEC Channel Number AO Device ID AO Channel Number 0 0 2 0 0 1 3 0 Call the hi_mpi_adec_send_stream API in a loop to send each frame of audio data to be decoded to the decoder for decoding.
The decoded audio data is automatically sent to the corresponding AO device for audio playback based on the binding relationship in step 3.
After audio playback is complete, in the exit process, first call the hi_mpi_sys_unbind API to unbind ADEC and AO, then call the hi_mpi_ao_disable_resample API to disable the AO resampling function, call the hi_mpi_ao_disable_chn API to disable the AO channel, call the hi_mpi_ao_disable API to disable the AO device, and finally call the hi_mpi_adec_destroy_chn API to destroy the ADEC channel.
Recording Audio and Sending Audio to the IP Camera
Figure 2 Recording audio and sending audio to the IP Camera
The API call process is described as follows:
Enable the AI audio input device and channel:
Call the hi_mpi_ai_set_pub_attr API to set the AI device attributes.
Call the hi_mpi_ai_enable API to start the AI device.
Call the hi_mpi_ai_set_chn_attr API to set the AI channel attributes.
Call the hi_mpi_ai_enable_chn API to start the AI channel.
Call the hi_mpi_ai_enable_resample API to enable the AI resampling function.
Because the AI sampling rate is fixed at 48 kHz, while the G.711a and G.711u protocols support only an 8 kHz sampling rate, the resampling function must be enabled. In contrast, 48 kHz falls within the sampling rate range supported by the AAC protocol, so resampling is not required for AI when the AAC protocol is used.
Call the hi_mpi_aenc_create_chn API to create an audio encoding channel.
Call the hi_mpi_sys_bind API to bind AI and AENC.
AI Device ID AI Channel Number AENC Device ID AENC Channel Number 2 0 0 0 Call hi_mpi_aenc_get_stream in a loop to obtain encoded data. After the encoded data is used, call the hi_mpi_aenc_release_stream API in a timely manner to release the encoded data.
The audio data obtained through the AI device is automatically sent to the corresponding AENC channel for encoding based on the binding relationship in step 3, and is used to send voice to the IP camera.
After the voice is sent, in the exit process, first call the hi_mpi_sys_unbind API to unbind AI and AENC, then call the hi_mpi_aenc_destroy_chn API to destroy the AENC channel, and finally call the hi_mpi_ai_disable_resample API to disable the AI resampling function, the hi_mpi_ai_disable_chn API to disable the AI channel, and the hi_mpi_ai_disable API to disable the AI device in sequence.