Agora Java API Reference for Android

NGIAgoraAudioDeviceManager.h
1 //
2 // Agora SDK
3 //
4 // Copyright (c) 2018 Agora.io. All rights reserved.
5 //
6
7 #pragma once // NOLINT(build/header_guard)
8
9 #include <cstring>
10
11 #include "AgoraBase.h"
12 #include "AgoraRefPtr.h"
13 #include <api/cpp/aosl_ares_class.h>
14 namespace agora {
15 namespace media {
16 namespace base {
17 class IAudioFrameObserver;
18 } // namespace base
19 } // namespace media
20
21 namespace rtc {
22
23 static const int kAdmMaxDeviceNameSize = 128;
24 static const int kAdmMaxGuidSize = 128;
25 static const int kIntervalInMillseconds = 200;
26
27
28 #if defined(_WIN32) || (defined(__APPLE__) && TARGET_OS_MAC && !TARGET_OS_IPHONE)
29
35 struct AudioDeviceInfo {
39 char deviceName[kAdmMaxDeviceNameSize];
44 char deviceTypeName[kAdmMaxDeviceNameSize];
48 char deviceId[kAdmMaxGuidSize];
54 bool isCurrentSelected;
60 bool isPlayoutDevice;
61
62 AudioDeviceInfo() : isCurrentSelected(false),
63 isPlayoutDevice(true) {
64 memset(deviceName, 0, sizeof(deviceName));
65 memset(deviceTypeName, 0, sizeof(deviceTypeName));
66 memset(deviceId, 0, sizeof(deviceId));
67 }
68 };
69 #endif // _WIN32 || (TARGET_OS_MAC && !TARGET_OS_IPHONE)
70
76 struct LoopbackRecordingOption {
80 Optional<const char *> deviceName;
84 Optional<bool> allowDeviceChange;
85 };
86
90 class IAudioDeviceManagerObserver
91 {
92 public:
93 virtual ~IAudioDeviceManagerObserver() {}
94
100 virtual void onDeviceStateChanged() = 0;
101
112 virtual void onAudioDeviceStateChanged(const char *deviceId, int deviceType, int deviceState) = 0;
113
119 virtual void onVolumeIndication(int deviceType, int volume) = 0;
120
126 virtual void onRoutingChanged(AudioRoute route) = 0;
127
137 virtual void onAudioDeviceVolumeChanged(int deviceType, int volume, bool muted) = 0;
138 };
139
140 class IRecordingDeviceSource : public RefCountInterface {
141 public:
148 virtual int initRecording(const char* deviceName = NULL) = 0;
149
156 virtual int startRecording(aosl_ref_t ares = AOSL_REF_INVALID) = 0;
157
164 virtual int stopRecording(aosl_ref_t ares = AOSL_REF_INVALID) = 0;
165
174 virtual int registerAudioFrameObserver(media::IAudioPcmFrameSink* observer, aosl_ref_t ares = AOSL_REF_INVALID) = 0;
175
184 virtual int unregisterAudioFrameObserver(media::IAudioPcmFrameSink* observer) = 0;
185
192 virtual int setLoopbackDeviceParameter(const LoopbackRecordingOption &option, aosl_ref_t ares = AOSL_REF_INVALID) = 0;
193
194 virtual ~IRecordingDeviceSource() {}
195 };
196
203 class INGAudioDeviceManager : public RefCountInterface {
204 public:
213 virtual agora_refptr<IRecordingDeviceSource> createRecordingDeviceSource(char deviceId[kAdmMaxDeviceNameSize]) = 0;
214
222 virtual int setMicrophoneVolume(unsigned int volume, aosl_ref_t ares = AOSL_REF_INVALID) = 0;
230 virtual int getMicrophoneVolume(unsigned int& volume) = 0;
238 virtual int setSpeakerVolume(unsigned int volume, aosl_ref_t ares = AOSL_REF_INVALID) = 0;
246 virtual int getSpeakerVolume(unsigned int& volume) = 0;
256 virtual int setMicrophoneMute(bool mute, aosl_ref_t ares = AOSL_REF_INVALID) = 0;
264 virtual int getMicrophoneMute(bool& mute) = 0;
274 virtual int setSpeakerMute(bool mute, aosl_ref_t ares = AOSL_REF_INVALID) = 0;
282 virtual int getSpeakerMute(bool& mute) = 0;
283
291 virtual int getPlayoutAudioParameters(AudioParameters* params) const = 0;
292
300 virtual int getRecordAudioParameters(AudioParameters* params) const = 0;
301
302 #if defined(__ANDROID__) || (defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE)
303
318 virtual int setDefaultAudioRouting(AudioRoute route, aosl_ref_t ares = AOSL_REF_INVALID) = 0;
330 virtual int changeAudioRouting(AudioRoute route, aosl_ref_t ares = AOSL_REF_INVALID) = 0;
342 virtual int setAudioRoutingSpeakerOn(bool enable, aosl_ref_t ares = AOSL_REF_INVALID) = 0;
354 virtual int getCurrentRouting(AudioRoute& route) = 0;
355 #endif // __ANDROID__ || TARGET_OS_IPHONE
356
357 #if defined(_WIN32) || (defined(__APPLE__) && TARGET_OS_MAC && !TARGET_OS_IPHONE)
358
368 virtual int getNumberOfPlayoutDevices() = 0;
369
380 virtual int getNumberOfRecordingDevices() = 0;
391 virtual AudioDeviceInfo getPlayoutDeviceInfo(int index) = 0;
402 virtual AudioDeviceInfo getRecordingDeviceInfo(int index) = 0;
414 virtual int setPlayoutDevice(int index, aosl_ref_t ares = AOSL_REF_INVALID) = 0;
426 virtual int setRecordingDevice(int index, aosl_ref_t ares = AOSL_REF_INVALID) = 0;
438 virtual int followSystemPlaybackDevice(bool enable, aosl_ref_t ares = AOSL_REF_INVALID) = 0;
439
451 virtual int followSystemRecordingDevice(bool enable, aosl_ref_t ares = AOSL_REF_INVALID) = 0;
452 #endif // _WIN32 || (TARGET_OS_MAC && !TARGET_OS_IPHONE)
453
454 #if defined(_WIN32)
455
466 virtual int setApplicationVolume(unsigned int volume, aosl_ref_t ares = AOSL_REF_INVALID) = 0;
478 virtual int getApplicationVolume(unsigned int& volume) = 0;
492 virtual int setApplicationMuteState(bool mute, aosl_ref_t ares = AOSL_REF_INVALID) = 0;
504 virtual int getApplicationMuteState(bool& mute) = 0;
515 virtual AudioDeviceInfo getLoopbackDeviceInfo(int index) = 0;
527 virtual int setLoopbackDevice(int index, aosl_ref_t ares = AOSL_REF_INVALID) = 0;
539 virtual int followSystemLoopbackDevice(bool enable, aosl_ref_t ares = AOSL_REF_INVALID) = 0;
540 #endif // _WIN32
541
553 virtual int registerObserver(IAudioDeviceManagerObserver* observer, void(*safeDeleter)(IAudioDeviceManagerObserver*) = NULL, aosl_ref_t ares = AOSL_REF_INVALID) = 0;
561 virtual int unregisterObserver(IAudioDeviceManagerObserver* observer) = 0;
562
563 virtual int setupAudioAttributeContext(void* audioAttr, aosl_ref_t ares = AOSL_REF_INVALID) = 0;
564
565 protected:
566 ~INGAudioDeviceManager() {}
567 };
568
569 } //namespace rtc
570 } // namespace agora
agora::media::IAudioPcmFrameSink
Definition: AgoraMediaBase.h:1250
agora::rtc::IAudioDeviceManagerObserver::onAudioDeviceStateChanged
virtual void onAudioDeviceStateChanged(const char *deviceId, int deviceType, int deviceState)=0
agora::agora_refptr
Definition: AgoraRefPtr.h:44
agora::rtc::INGAudioDeviceManager::setSpeakerMute
virtual int setSpeakerMute(bool mute, aosl_ref_t ares=AOSL_REF_INVALID)=0
agora::rtc::AudioParameters
Definition: AgoraMediaBase.h:217
agora::rtc::IAudioDeviceManagerObserver::onDeviceStateChanged
virtual void onDeviceStateChanged()=0
agora::rtc::INGAudioDeviceManager::getRecordAudioParameters
virtual int getRecordAudioParameters(AudioParameters *params) const =0
agora::rtc::IAudioDeviceManagerObserver::onVolumeIndication
virtual void onVolumeIndication(int deviceType, int volume)=0
agora::rtc::LoopbackRecordingOption::deviceName
Optional< const char * > deviceName
Definition: NGIAgoraAudioDeviceManager.h:80
agora::rtc::INGAudioDeviceManager::setSpeakerVolume
virtual int setSpeakerVolume(unsigned int volume, aosl_ref_t ares=AOSL_REF_INVALID)=0
agora::rtc::IAudioDeviceManagerObserver::onAudioDeviceVolumeChanged
virtual void onAudioDeviceVolumeChanged(int deviceType, int volume, bool muted)=0
agora::rtc::INGAudioDeviceManager::getMicrophoneMute
virtual int getMicrophoneMute(bool &mute)=0
agora::rtc::IRecordingDeviceSource::setLoopbackDeviceParameter
virtual int setLoopbackDeviceParameter(const LoopbackRecordingOption &option, aosl_ref_t ares=AOSL_REF_INVALID)=0
agora::rtc::LoopbackRecordingOption
Definition: NGIAgoraAudioDeviceManager.h:76
agora::rtc::IRecordingDeviceSource::registerAudioFrameObserver
virtual int registerAudioFrameObserver(media::IAudioPcmFrameSink *observer, aosl_ref_t ares=AOSL_REF_INVALID)=0
agora::rtc::INGAudioDeviceManager::getSpeakerVolume
virtual int getSpeakerVolume(unsigned int &volume)=0
agora::rtc::IRecordingDeviceSource
Definition: NGIAgoraAudioDeviceManager.h:140
agora::rtc::IRecordingDeviceSource::stopRecording
virtual int stopRecording(aosl_ref_t ares=AOSL_REF_INVALID)=0
agora::rtc::IRecordingDeviceSource::unregisterAudioFrameObserver
virtual int unregisterAudioFrameObserver(media::IAudioPcmFrameSink *observer)=0
agora::rtc::INGAudioDeviceManager::unregisterObserver
virtual int unregisterObserver(IAudioDeviceManagerObserver *observer)=0
agora::rtc::INGAudioDeviceManager::getPlayoutAudioParameters
virtual int getPlayoutAudioParameters(AudioParameters *params) const =0
agora::rtc::INGAudioDeviceManager::registerObserver
virtual int registerObserver(IAudioDeviceManagerObserver *observer, void(*safeDeleter)(IAudioDeviceManagerObserver *)=NULL, aosl_ref_t ares=AOSL_REF_INVALID)=0
agora::rtc::IRecordingDeviceSource::startRecording
virtual int startRecording(aosl_ref_t ares=AOSL_REF_INVALID)=0
agora::rtc::INGAudioDeviceManager::getSpeakerMute
virtual int getSpeakerMute(bool &mute)=0
agora::rtc::INGAudioDeviceManager
Definition: NGIAgoraAudioDeviceManager.h:203
agora::rtc::LoopbackRecordingOption::allowDeviceChange
Optional< bool > allowDeviceChange
Definition: NGIAgoraAudioDeviceManager.h:84
agora::rtc::IAudioDeviceManagerObserver
Definition: NGIAgoraAudioDeviceManager.h:91
agora::RefCountInterface
Definition: AgoraRefPtr.h:31
agora::rtc::INGAudioDeviceManager::getMicrophoneVolume
virtual int getMicrophoneVolume(unsigned int &volume)=0
agora::rtc::INGAudioDeviceManager::createRecordingDeviceSource
virtual agora_refptr< IRecordingDeviceSource > createRecordingDeviceSource(char deviceId[kAdmMaxDeviceNameSize])=0
agora::rtc::INGAudioDeviceManager::setMicrophoneVolume
virtual int setMicrophoneVolume(unsigned int volume, aosl_ref_t ares=AOSL_REF_INVALID)=0
agora::rtc::IAudioDeviceManagerObserver::onRoutingChanged
virtual void onRoutingChanged(AudioRoute route)=0
agora::rtc::INGAudioDeviceManager::setMicrophoneMute
virtual int setMicrophoneMute(bool mute, aosl_ref_t ares=AOSL_REF_INVALID)=0
agora::rtc::IRecordingDeviceSource::initRecording
virtual int initRecording(const char *deviceName=NULL)=0
agora::Optional< const char * >