LiteAVSDK
Tencent Cloud LVB SDK, is a high availability components serving tens of thousands of enterprise customers, which is committed to helping you to minimize your research and development costs.
TXDeviceManager

Detailed Description

Tencent Cloud Device Management Module


Module: audio/video device management module Description: manages audio/video devices such as camera, mic, and speaker.

Properties

TXMediaDeviceType type
 
NSString * deviceId
 
NSString * deviceName
 

Type definitions of audio/video devices

enum  TXSystemVolumeType : NSInteger
 
enum  TXAudioRoute : NSInteger
 
enum  TXMediaDeviceType : NSInteger
 

Data Structure Documentation

◆ TXMediaDeviceInfo

class TXMediaDeviceInfo

Properties

TXMediaDeviceType type
 
NSString * deviceId
 
NSString * deviceName
 

◆ TXDeviceManager

class TXDeviceManager

Device APIs for mobile OS

(BOOL) - isFrontCamera
 
(NSInteger) - switchCamera
 
(BOOL) - isCameraZoomSupported
 
(CGFloat) - getCameraZoomMaxRatio
 
(NSInteger) - setCameraZoomRatio
 
(BOOL) - isAutoFocusEnabled
 
(NSInteger) - enableCameraAutoFocus
 
(NSInteger) - setCameraFocusPosition
 
(BOOL) - isCameraTorchSupported
 
(NSInteger) - enableCameraTorch
 
(NSInteger) - setAudioRoute
 
(NSInteger) - setSystemVolumeType
 

Device APIs for desktop OS

(NSArray< TXMediaDeviceInfo * > *_Nullable) - getDevicesList
 
(NSInteger) - setCurrentDevice:deviceId
 
(TXMediaDeviceInfo *_Nullable) - getCurrentDevice
 
(NSInteger) - setCurrentDeviceVolume:deviceType
 
(NSInteger) - getCurrentDeviceVolume
 
(NSInteger) - setCurrentDeviceMute:deviceType
 
(BOOL) - getCurrentDeviceMute
 
(NSInteger) - startCameraDeviceTest
 
(NSInteger) - stopCameraDeviceTest
 
(NSInteger) - startMicDeviceTest:testEcho
 
(NSInteger) - stopMicDeviceTest
 
(NSInteger) - startSpeakerDeviceTest:onVolumeChanged
 
(NSInteger) - stopSpeakerDeviceTest
 

Method Documentation

◆ isFrontCamera()

- (BOOL) isFrontCamera

Querying whether the front camera is being used

◆ switchCamera()

- (NSInteger) switchCamera: (BOOL)  frontCamera

Switching to the front/rear camera (for mobile OS)

◆ isCameraZoomSupported()

- (BOOL) isCameraZoomSupported

Querying whether the current camera supports zooming (for mobile OS)

◆ getCameraZoomMaxRatio()

- (CGFloat) getCameraZoomMaxRatio

Getting the maximum zoom ratio of the camera (for mobile OS)

◆ setCameraZoomRatio()

- (NSInteger) setCameraZoomRatio: (CGFloat)  zoomRatio

Setting the camera zoom ratio (for mobile OS)

Parameters
zoomRatioValue range: 1-5. 1 indicates the widest angle of view (original), and 5 the narrowest angle of view (zoomed in).

◆ isAutoFocusEnabled()

- (BOOL) isAutoFocusEnabled

Querying whether automatic face detection is supported (for mobile OS)

◆ enableCameraAutoFocus()

- (NSInteger) enableCameraAutoFocus: (BOOL)  enabled

Enabling auto focus (for mobile OS)

After auto focus is enabled, the camera will automatically detect and always focus on faces.

◆ setCameraFocusPosition()

- (NSInteger) setCameraFocusPosition: (CGPoint)  position

Adjusting the focus (for mobile OS)

This API can be used to achieve the following:

  1. A user can tap on the camera preview.
  2. A rectangle will appear where the user taps, indicating the spot the camera will focus on.
  3. The user passes the coordinates of the spot to the SDK using this API, and the SDK will instruct the camera to focus as required.
    Attention
    Before using this API, you must first disable auto focus using enableCameraAutoFocus.
    Parameters
    positionThe spot to focus on. Pass in the coordinates of the spot you want to focus on.
    Returns
    0: operation successful; negative number: operation failed.

◆ isCameraTorchSupported()

- (BOOL) isCameraTorchSupported

Querying whether flash is supported (for mobile OS)

◆ enableCameraTorch()

- (NSInteger) enableCameraTorch: (BOOL)  enabled

Enabling/Disabling flash, i.e., the torch mode (for mobile OS)

◆ setAudioRoute()

- (NSInteger) setAudioRoute: (TXAudioRoute route

Setting the audio route (for mobile OS)

A mobile phone has two audio playback devices: the receiver at the top and the speaker at the bottom. If the audio route is set to the receiver, the volume is relatively low, and audio can be heard only when the phone is put near the ear. This mode has a high level of privacy and is suitable for answering calls. If the audio route is set to the speaker, the volume is relatively high, and there is no need to put the phone near the ear. This mode enables the "hands-free" feature.

◆ setSystemVolumeType()

- (NSInteger) setSystemVolumeType: (TXSystemVolumeType type

Setting the system volume type (for mobile OS)

◆ getDevicesList()

- (NSArray<TXMediaDeviceInfo *> * _Nullable) getDevicesList: (TXMediaDeviceType type

Getting the device list (for desktop OS)

◆ setCurrentDevice:deviceId()

- (NSInteger) setCurrentDevice: (TXMediaDeviceType type
deviceId: (NSString *)  deviceId 

Setting the device to use (for desktop OS)

Parameters
typeDevice type. For details, please see the definition of TXMediaDeviceType.
deviceIdDevice ID. You can get the ID of a device using the getDevicesList API.
Returns
0: operation successful; negative number: operation failed.

◆ getCurrentDevice()

- (TXMediaDeviceInfo * _Nullable) getCurrentDevice: (TXMediaDeviceType type

Getting the device currently in use (for desktop OS)

◆ setCurrentDeviceVolume:deviceType()

- (NSInteger) setCurrentDeviceVolume: (NSInteger)  volume
deviceType: (TXMediaDeviceType type 

Setting the volume of the current device (for desktop OS)

This API is used to set the capturing volume of the mic or playback volume of the speaker, but not the volume of the camera.

Parameters
volumeVolume. Value range: 0-100; default: 100
Attention
If 100 is still not loud enough for you, you can contact technical support to set the volume to up to 150, but there may be side effects.

◆ getCurrentDeviceVolume()

- (NSInteger) getCurrentDeviceVolume: (TXMediaDeviceType type

Getting the volume of the current device (for desktop OS)

This API is used to get the capturing volume of the mic or playback volume of the speaker, but not the volume of the camera.

◆ setCurrentDeviceMute:deviceType()

- (NSInteger) setCurrentDeviceMute: (BOOL)  mute
deviceType: (TXMediaDeviceType type 

Muting the current device (for desktop OS)

This API is used to mute the mic or speaker, but not the camera.

◆ getCurrentDeviceMute()

- (BOOL) getCurrentDeviceMute: (TXMediaDeviceType type

Querying whether the current device is muted (for desktop OS)

This API is used to query whether the mic or speaker is muted. Camera muting is not supported.

◆ startCameraDeviceTest()

- (NSInteger) startCameraDeviceTest: (NSView *)  view

Starting camera testing (for desktop OS)

Attention
You can use the setCurrentDevice API to switch between cameras during testing.

◆ stopCameraDeviceTest()

- (NSInteger) stopCameraDeviceTest

Ending camera testing (for desktop OS)

◆ startMicDeviceTest:testEcho()

- (NSInteger) startMicDeviceTest: (NSInteger)  interval
testEcho: (void(^)(NSInteger volume))  testEcho 

Starting mic testing (for desktop OS)

This API is used to test whether the mic functions properly. The mic volume detected (value range: 0-100) is returned via a callback.

Parameters
intervalInterval of volume callbacks

◆ stopMicDeviceTest()

- (NSInteger) stopMicDeviceTest

Ending mic testing (for desktop OS)

◆ startSpeakerDeviceTest:onVolumeChanged()

- (NSInteger) startSpeakerDeviceTest: (NSString *)  audioFilePath
onVolumeChanged: (void(^)(NSInteger volume, BOOL isLastFrame))  volumeBlock 

Starting speaker testing (for desktop OS)

This API is used to test whether the audio playback device functions properly by playing a specified audio file. If users can hear audio during testing, the device functions properly.

Parameters
filePathPath of the audio file

◆ stopSpeakerDeviceTest()

- (NSInteger) stopSpeakerDeviceTest

Ending speaker testing (for desktop OS)

Enumeration Type Documentation

◆ TXSystemVolumeType

enum TXSystemVolumeType : NSInteger

System volume type (for mobile devices only)

Smartphones usually have two types of system volume: call volume and media volume.

  • Call volume is designed for call scenarios. It comes with acoustic echo cancellation (AEC) and supports audio capturing by Bluetooth earphones, but its sound quality is average. If you cannot turn the volume down to 0 (i.e., mute the phone) using the volume buttons, then your phone is using call volume.
  • Media volume is designed for media scenarios such as music playback. AEC does not work when media volume is used, and Bluetooth earphones cannot be used for audio capturing. However, media volume delivers better music listening experience. If you are able to mute your phone using the volume buttons, then your phone is using media volume.

The SDK offers three system volume control modes: auto, call volume, and media volume.

Enumerator
TXSystemVolumeTypeAuto 

Auto: In the auto mode, call volume is used for anchors, and media volume for audience. This mode is suitable for live streaming scenarios.

TXSystemVolumeTypeMedia 

Media volume: In this mode, media volume is used in all scenarios. It is rarely used, mainly suitable for music scenarios with demanding requirements on audio quality. Use this mode if most of your users use peripheral devices such as audio cards. Otherwise, it is not recommended.

TXSystemVolumeTypeVOIP 

Call volume: In this mode, the audio module does not change its work mode when users switch between anchors and audience, enabling seamless mic on/off. This mode is suitable for scenarios where users need to switch frequently between anchors and audience.

◆ TXAudioRoute

enum TXAudioRoute : NSInteger

Audio route (the route via which audio is played)

Audio route is the route (speaker or receiver) via which audio is played. It applies only to mobile devices such as mobile phones. A mobile phone has two speakers: one at the top (receiver) and the other the bottom.

  • If the audio route is set to the receiver, the volume is relatively low, and audio can be heard only when the phone is put near the ear. This mode has a high level of privacy and is suitable for answering calls.
  • If the audio route is set to the speaker, the volume is relatively high, and there is no need to put the phone near the ear. This mode enables the "hands-free" feature.
Enumerator
TXAudioRouteSpeakerphone 

Speakerphone: the speaker at the bottom is used for playback (hands-free). With relatively high volume, it is used to play music out loud.

TXAudioRouteEarpiece 

Earpiece: the receiver at the top is used for playback. With relatively low volume, it is suitable for call scenarios that require privacy.

◆ TXMediaDeviceType

enum TXMediaDeviceType : NSInteger

Device type (for desktop OS)

This enumerated type defines three types of audio/video devices, namely camera, mic and speaker, so that you can use the same device management API to manage three types of devices.

Enumerator
TXMediaDeviceTypeUnknown 

undefined device type

TXMediaDeviceTypeAudioInput 

microphone

TXMediaDeviceTypeAudioOutput 

speaker or earpiece

TXMediaDeviceTypeVideoCamera 

camera

Properties

◆ type

- (TXMediaDeviceType) type
readwritenonatomicassign

device type

◆ deviceId

- (NSString*) deviceId
readwritenonatomiccopy

device id

◆ deviceName

- (NSString*) deviceName
readwritenonatomiccopy

device name