# Hardware abstraction layer
SDK The normal operation depends on the software and hardware interface provided by the hardware device platform, including microphone, speaker, camera, encryption library and other modules. We design a hardware abstraction layer to provide consistent interface definitions, and concrete interface implementations need to be SDK Access provided.
# 1. Module
abstract
Header file:
wmpf/module.h
。
We abstract each module into awx_Module
Types, there are currently the following module:
type | Header file | Introductions |
---|---|---|
wx_audio_Module | wmpf/hardware/audio.h | Audio module for input from microphone and speaker/Output audio stream |
wx_Camera_Module | wmpf/hardware/camera.h | Camera module for obtaining a video stream from the camera |
wx_crypto_Module | wmpf/crypto.h | Signature algorithm module. SDK Depends on the signature algorithm in the system's cryptographic library. |
wx_video_Module | wmpf/hardware/video.h | Video module for creating a remote video stream |
When these are implemented on demand Module After calling the wx_init()
to initialize SDK You will use the following function pointer to Module Provided to the SDK Use:
typedef wx_error_t (*wx_get_Module_t)(const char* id,
struct wx_Module** Module)
SDK When you call the implemented function, you pass in a ID, you need to return this ID The corresponding wx_Module
Examples of.
parameter
attribute | type | Introductions |
---|---|---|
id | char* | Module ID, defined in subsequent |
Module | struct wx_Module** | Corresponding Module Example |
Currently supported Module ID Already predefined in each header file:
ID | Header file |
---|---|
WX_AUDIO_MODULE_ID | wmpf/hardware/audio.h |
WX_CAMERA_MODULE_ID | wmpf/hardware/camera.h |
WX_CRYPTO_MODULE_ID | wmpf/crypto.h |
WX_VIDEO_MODULE_ID | wmpf/hardware/video.h |
Return value
wx_error_t
SDK Based on this return value, the requested Module If it works.
For example, a device does not have a camera, then when SDK request WX_CAMERA_MODULE_ID You just need to return. WXERROR_UNIMPLEMENTED
。
Error code | Introductions |
---|---|
WXERROR_OK | Requested Module It works. |
WXERROR_UNIMPLEMENTED | Requested Module Invalid. |
sample code
// Suppose you have implemented the following module:
extern struct wx_audio_Module audio_Module
extern struct wx_Camera_Module Camera_Module
extern struct wx_crypto_Module crypto_Module
// The function of HAL getting Module is as follows:
wx_error_t hal_get_Module(const char* id, struct wx_Module** Module_out) {
if (!strcmp(id, WX_AUDIO_MODULE_ID)) {
*Module_out = (struct wx_Module*)&audio_Module
return WXERROR_OK
} else if (!strcmp(id, WX_CAMERA_MODULE_ID)) {
*Module_out = (struct wx_Module*)&camera_Module
return WXERROR_OK
} else if (!strcmp(id, WX_CRYPTO_MODULE_ID)) {
*Module_out = (struct wx_Module*)&crypto_Module
return WXERROR_OK
}
// Assume that the current device does not have a screen, so there is no need to provide wx_video_Module, then it returns the WXERROR_UNIMPLEMENTED
return WXERROR_UNIMPLEMENTED
}
# 2. Audio Module
Header file:
wmpf/hardware/audio.h
。
Audio module, you need to configure a wx_audio_Module
An instance of the. This type mainly contains the following function pointers, used to get the audio input/Output device messages, or operate audio devices.
Runtime, VoIP This will be called sequentially 4 A function to complete the audio input/Configuration of output devices.
# 2.1 get_number_of_devices
Get Specified Type Audio Input/The number of output devices.
wx_error_t (*get_number_of_devices)(struct wx_audio_Module* module,
wx_audio_device_type_t device_type,
Size_t* num_devices_out)
parameter
attribute | type | Introductions |
---|---|---|
Module | struct wx_audio_Module* | context |
device_type | wx_audio_device_type_t | Device type, optional valueWX_AUDIO_DEVICE_IN Audio input devices, such as microphonesWX_AUDIO_DEVICE_OUT (Audio output devices, such as speakers) |
num_devices_out | Size_t* | Returns the number of audio devices of the corresponding type |
Return value
wx_error_t
SDK Based on this return value, it is determined whether the obtained number of devices is valid
Error code | Introductions |
---|---|
WXERROR_OK | success |
WXERROR_INVALID_ARGUMENT | num_devices_out Empty |
# 2.2 get_device_Name
Query the specified type, such as WX_AUDIO_DEVICE_IN Represents a microphone) Audio Input/Number one in the output device list index One device. ID
wx_error_t (*get_device_Name)(struct wx_audio_Module* module,
Size_t index,
wx_audio_device_type_t device_type,
char** device_Name_out)
parameter
attribute | type | Introductions |
---|---|---|
Module | struct wx_audio_Module* | context |
index | Size_t | Device specified in the device list. Value range[0, num_devices_out) |
device_type | wx_audio_device_type_t | Type of equipment, same as get_number_of_devices |
device_Name_out | char** | Returns the corresponding device's ID |
Return value
wx_error_t
SDK Based on this return value, it is judged that the resulting device ID Whether it is effective
Error code | Introductions |
---|---|
WXERROR_OK | success |
WXERROR_INVALID_ARGUMENT | num_devices_out Empty |
WXERROR_OUT_OF_RANGE | index Out of range |
# 2.3 get_device_Info
Query the specified type and device ID Details of the device. This function is used to return some audio device information, such as supported audio encoding formats, that can be retrieved without opening the audio device.
wx_error_t (*get_device_Info)(struct wx_audio_Module* module,
const char* id,
wx_audio_device_type_t device_type,
const struct wx_Metadata** Metadata_out)
parameter
attribute | type | Introductions |
---|---|---|
Module | struct wx_audio_Module* | context |
id | const char* | get_device_Name The equipment we found ID, or macro WX_AUDIO_DEVICE_PRIMARY Represents an arbitrary valid device. |
device_type | wx_audio_device_type_t | with get_number_of_devices of device_type |
Metadata_out | const struct wx_Metadata** | Returns the details of the corresponding device. The object pointed to by the second-level pointer can be a local variable. |
Return value
wx_error_t
SDK Based on this return value, it is determined whether the obtained device details are valid
Error code | Introductions |
---|---|
WXERROR_OK | success |
# 2.4 open
Calls the specified audio input/Output devices.
wx_error_t (*open)(struct wx_audio_Module* module,
const char* id,
wx_audio_device_type_t device_type,
struct wx_audio_device** device_out)
parameter
attribute | type | Introductions |
---|---|---|
Module | struct wx_audio_Module* | context |
id | const char* | with get_device_Info of id |
device_type | wx_audio_device_type_t | with get_number_of_devices of device_type |
device_out | struct wx_audio_device** | Returns the corresponding device instance. See the follow-up wx_audio_device Type Dxplaination |
Return value
wx_error_t
SDK Based on this return value, it is determined whether the resulting device instance is valid
Error code | Introductions |
---|---|
WXERROR_OK | success |
# 2.5 wx_audio_device
attribute | type | Introductions |
---|---|---|
common | wx_device | The public base class for device types. |
Metadata | wx_Metadata | For the device description information. |
struct wx_audio_device
The function itself is not much, mainly for the description of the device. What really needs to focus on are its two types of extensions:wx_audio_device_in
and wx_audio_device_out
。
# 2.5.1 wx_audio_device_in
The abstraction of an input device such as a microphone. The key to this type is the need to provide open_input_stream
Function implementation, runtime SDK This function will be called to create the audio input stream object wx_audio_stream_in
。SDK use wx_audio_stream_in
Object to further control audio capture.
The microphone device is VoIP Call is created when dialed, VoIP Destroyed at the end of the call.
attribute | type | Introductions |
---|---|---|
device | wx_audio_device | Base class. |
open_input_stream | Function pointer | SDK Use this function pointer to open the/Use microphone equipment. |
# open_input_stream
The parameters of the
parameter | type | Introductions |
---|---|---|
dev | wx_audio_device_in * | context |
config | wx_audio_config * | SDK Desired microphone configuration. |
listener | wx_audio_stream_in_listener * | SDK A callback function that listens for microphone events. Developers need to call these functions correctly at the right time. |
user_Data | void * | SDK Other dependent context Information. This pointer is required when calling the microphone event callback function. |
stream_out | wx_audio_stream_in ** | Returns a newly created audio input stream object. Defined as follows. |
# wx_audio_stream_in
parameter | type | Introductions |
---|---|---|
common | wx_audio_stream * | context |
Pause | Function pointer | SDK Call this function to pause audio data entry. |
Resume | Function pointer | SDK Call this function to recover audio data input. |
# wx_audio_stream_in_listener
parameter | type | Introductions |
---|---|---|
common | wx_struct | Base class |
Data | Function pointer | The system calls this function to SDK Provides audio data collected by the microphone. |
error | Function pointer | The system informs by calling this function SDK There was an error with the microphone capturing audio data. |
Notes:
- SDK Currently only collecting PCM Format audio data, in the future may add other audio formats.
- config At present, the sampling rate 16000, sampling length 20ms、16bit Is configured by default and may be dynamically adjusted. If the device does not support these audio configurations, the device manufacturer should make their own PCM The data is transformed.
- Data Callbacks can be understood as non-blocking, that is, network agnostic.
- Data One frame of audio data provided by the callback, which needs to be determined according to the
config
Set the parameters provided. For example: PCM sampling rate 16000, sampling format 16bit, sample length 20ms Of single channel audio data, containing the16000 / 1000 * 20 * 1 * (16 / 8)
Bytes of data (sampling rate / 1000 * Sampling length * Number of channels * Sampling format / 8Bit
)。
# 2.5.2 wx_audio_device_out type
For the abstraction of the speaker device. The key to this type is to provide open_output_stream
Function implementation, runtime SDK This function is called to create the audio output stream object wx_audio_stream_out
。SDK use wx_audio_stream_out
Object to further control audio playback.
The speaker device in the VoIP The call is created when the call begins to be dialed, the ringtone is played first, and the VoIP Start playing voice when the call starts, VoIP Destroyed at the end of the call.
attribute | type | Introductions |
---|---|---|
device | wx_audio_device | Base class. |
open_output_stream | Function pointer | SDK Use this function pointer to open the/Use speaker devices. |
# open_output_stream
Of the parameters:
parameter | type | Introductions |
---|---|---|
dev | wx_audio_device_out * | context |
config | wx_audio_config * | SDK Desired speaker configuration. |
listener | wx_audio_stream_out_listener * | SDK A callback function that listens for speaker events. These functions should be called correctly at the right time. |
user_Data | void * | SDK Other dependent context Information. This pointer is required when calling the speaker event callback function. |
stream_out | wx_audio_stream_out ** | Returns a newly created audio output stream object. Defined as follows. |
# wx_audio_stream_out
type
parameter | type | Introductions |
---|---|---|
common | wx_audio_stream * | context |
Pause | Function pointer | SDK Call this function to pause audio data playback. |
Resume | Function pointer | SDK Call this function to restore audio data playback. |
flush | Function pointer | SDK Calling this function requires the audio playback cache to immediately play back the audio data in the cache. |
# wx_audio_stream_out_listener
type
parameter | type | Introductions |
---|---|---|
common | wx_struct | Base class |
Data | Function pointer | System by calling this function to the SDK Pulls audio data to be played (ringtone or voice stream received). |
error | Function pointer | The system notifies by calling this function SDK Audio playback error. |
Notes:
- SDK Currently only available PCM Format audio data, in the future may add other audio formats.
- config At present, the sampling rate 16000, sampling length 20ms、16bit Is configured by default and may be dynamically adjusted. If the device does not support these audio configurations, the device manufacturer should make their own PCM The data is transformed.
- Data Callbacks can be understood as non-blocking, that is, network agnostic.
- Data Callback the incoming buffer Need to be big enough to hold config Set a frame of audio data. For example: PCM sampling rate 16000, sampling format 16bit, sample length 20ms Of single channel audio data, containing the 16000 / 1000 _ 20 _ 1 _ (16 / 8) Byte data (sampling rate / 1000 _ Sampling length _ Number of channels _ Sampling format / 8Bit)。
# 3. Signature algorithm module
Header file:
wmpf/crypto.h
。
SDK Relying on the system's built-in signature algorithm, we provide OpenSSL, MbedTLS, WolfSSL of Demo Implementation, stored in the example In the directory. If you use the above crypto Implementation, which can often be used directly with the example Of the code implementation. Otherwise, refer to the example Implementation for adaptation.
Demo Achieve:
example/crypto_mbedtls.c
example/crypto_openssl.c
example/crypto_wolfssl.c
# 4. (available)Camera module
Header file:
wmpf/hardware/camera.h
。
Camera module, it is necessary to configure a wx_Camera_Module
An instance of the. This type mainly requires you to provide the following function pointers, which are used to generate video streams from the device to the phone using the camera device object provided by the device.
At runtime, the SDK This will be called sequentially 3 A function to complete the configuration of the camera equipment.
# 4.1 get_number_of_devices
Get the number of camera devices.
wx_error_t (*get_number_of_devices)(struct wx_Camera_Module* module,
Size_t* num_devices_out)
parameter
attribute | type | Introductions |
---|---|---|
Module | struct wx_Camera_Module* | context |
num_devices_out | Size_t* | Returns the number of camera devices of the corresponding type |
Return value
wx_error_t
SDK Based on this return value, it is determined whether the obtained number of devices is valid
Error code | Introductions |
---|---|
WXERROR_OK | success |
WXERROR_INVALID_ARGUMENT | num_devices_out Empty |
# 4.2 get_device_Info
Query details for the specified camera device.
wx_error_t (*get_device_Info)(struct wx_Camera_Module* module,
Size_t index,
struct wx_Camera_device_Info* device_Info)
parameter
attribute | type | Introductions |
---|---|---|
Module | struct wx_Camera_Module* | context |
index | Size_t | Device specified in the device list. Value range[0, num_devices_out) |
device_Info | struct wx_Camera_device_Info* | SDK Will be passed into this device_Info, the contents of this construction need to be filled. |
Return value
wx_error_t
SDK Based on this return value, it is determined whether the obtained device details are valid
Error code | Introductions |
---|---|
WXERROR_OK | The requested device details are valid. |
# 4.3 open
Invokes the specified camera device.
wx_error_t (*open)(struct wx_Camera_Module* module,
const char* id,
struct wx_Camera_device** device_out)
parameter
attribute | type | Introductions |
---|---|---|
Module | struct wx_Camera_Module* | context |
id | char * | get_device_Info The equipment we found ID, or macro WX_CAMERA_DEVICE_PRIMARY Represents an arbitrary valid device. |
device_out | struct wx_Camera_device ** | Returns the corresponding device instance. |
Return value
wx_error_t
SDK Based on this return value, it is determined whether the resulting device instance is valid
Error code | Introductions |
---|---|
WXERROR_OK | success |
# 4.4 wx_Camera_device
For the abstraction of the camera device. The key to this type is the need to provide open_stream
Function implementation, runtime SDK This function is called to create a video input stream object wx_Camera_stream
。SDK use wx_Camera_stream
Object to further control the video capture.
attribute | type | Introductions |
---|---|---|
common | wx_device | The public base class for device types. |
Metadata | wx_Metadata | For the device description information. |
open_stream | Function pointer | SDK Use this function pointer to open the/Use of camera equipment. |
open_stream
Of the parameters:
parameter | type | Introductions |
---|---|---|
dev | wx_Camera_device * | context |
config | wx_Camera_stream_config * | SDK Required camera configuration, including data flow type. |
listener | wx_Camera_stream_listener * | SDK A callback function that listens for camera events. These functions should be called correctly at the right time. |
user_Data | void * | SDK Other dependent context Information. This pointer is required when calling the camera event callback function. |
stream_out | wx_Camera_stream ** | Returns a newly created video input stream object. Defined as follows. |
# wx_Camera_stream type
parameter | type | Introductions |
---|---|---|
common | wx_struct | Base class |
update | Function pointer | SDK This function is called to update the camera recording parameters. |
Make_i_frame | Function pointer | SDK Call this function to request to receive an immediate H264/H265 I Frame. |
# wx_Camera_stream_listener type
parameter | type | Introductions |
---|---|---|
common | wx_struct | Base class |
Data | Function pointer | The system calls this function to SDK Provide video data collected by the camera. |
error | Function pointer | The system informs by calling this function SDK There was an error with the camera capturing video data. |
Notes:
- SDK Currently only collecting H264/H265 Format of video data.
- Data Callbacks can be understood as non-blocking, that is, network agnostic.
- Equipment needs to be timed (recommended 1 Seconds, the maximum shall not exceed 5 Seconds) to provide PPS、SPS、I Frame.
- Device incoming rotation Only in Linux SDK 0xD5000084 And above version, WeChat client 8.0.41 And above version is effective, for the older WeChat version, you need to call on the mini program side VoIP Plug-in
setUIConfig
Sets the angle of swing.
# 5. (available)Video module
Header file:
wmpf/hardware/video.h
。
Camera module, it is necessary to configure a wx_video_Module
An instance of the.
At runtime, the SDK Will call the create_output_stream
Function to create a video output stream and output the received video recorded by the remote (cell phone) camera through the stream object.
# 5.1 create_output_stream
Create a video output stream.
wx_error_t (*create_output_stream)(struct wx_video_Module* module,
const struct wx_video_stream_config* config,
struct wx_video_stream** stream)
parameter
attribute | type | Introductions |
---|---|---|
Module | struct wx_video_Module* | context |
config | const struct wx_video_stream_config* | Video output stream parameters |
stream | struct wx_video_stream** | Return Video Output Stream Object |
Return value
wx_error_t
SDK According to this return value, it is judged whether the video output stream is valid
Error code | Introductions |
---|---|
WXERROR_OK | success |
# 5.2 wx_video_stream
parameter | type | Introductions |
---|---|---|
common | wx_struct | Base class |
write | Function pointer | SDK Call this function to write to the video output stream. |
close | Function pointer | SDK Call this function to turn off the video output stream. |