| 1 | /* |
| 2 | * Copyright 2026 LiveKit, Inc. |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #pragma once |
| 18 | |
| 19 | #include <memory> |
| 20 | |
| 21 | #include "api/scoped_refptr.h" |
| 22 | #include "livekit/adm_proxy.h" |
| 23 | #include "rust/cxx.h" |
| 24 | |
| 25 | namespace livekit_ffi { |
| 26 | |
| 27 | class RtcRuntime; |
| 28 | |
| 29 | class AudioDeviceController { |
| 30 | public: |
| 31 | AudioDeviceController(std::shared_ptr<RtcRuntime> rtc_runtime, |
| 32 | webrtc::scoped_refptr<AdmProxy> adm_proxy); |
| 33 | |
| 34 | // Device enumeration |
| 35 | int16_t playout_devices() const; |
| 36 | int16_t recording_devices() const; |
| 37 | rust::String playout_device_name(uint16_t index) const; |
| 38 | rust::String recording_device_name(uint16_t index) const; |
| 39 | rust::String playout_device_guid(uint16_t index) const; |
| 40 | rust::String recording_device_guid(uint16_t index) const; |
| 41 | |
| 42 | // Device selection |
| 43 | bool set_playout_device(uint16_t index) const; |
| 44 | bool set_recording_device(uint16_t index) const; |
| 45 | bool set_playout_device_by_guid(rust::String guid) const; |
| 46 | bool set_recording_device_by_guid(rust::String guid) const; |
| 47 | |
| 48 | // Recording control |
| 49 | bool stop_recording() const; |
| 50 | bool init_recording() const; |
| 51 | bool start_recording() const; |
| 52 | bool recording_is_initialized() const; |
| 53 | |
| 54 | // Playout control |
| 55 | bool stop_playout() const; |
| 56 | bool init_playout() const; |
| 57 | bool start_playout() const; |
| 58 | bool playout_is_initialized() const; |
| 59 | |
| 60 | // Built-in audio processing |
| 61 | bool builtin_aec_is_available() const; |
| 62 | bool builtin_agc_is_available() const; |
| 63 | bool builtin_ns_is_available() const; |
| 64 | bool enable_builtin_aec(bool enable) const; |
| 65 | bool enable_builtin_agc(bool enable) const; |
| 66 | bool enable_builtin_ns(bool enable) const; |
| 67 | |
| 68 | // ADM recording control |
| 69 | void set_adm_recording_enabled(bool enabled) const; |
| 70 | bool adm_recording_enabled() const; |
| 71 | |
| 72 | // ADM playout control |
| 73 | void set_adm_playout_enabled(bool enabled) const; |
| 74 | bool adm_playout_enabled() const; |
| 75 | |
| 76 | // Platform ADM lifecycle management |
| 77 | bool acquire_platform_adm() const; |
| 78 | void release_platform_adm() const; |
| 79 | int platform_adm_ref_count() const; |
| 80 | bool is_platform_adm_active() const; |
| 81 | |
| 82 | private: |
| 83 | // The AdmProxy marshals its calls onto the runtime's worker thread, keep |
| 84 | // the runtime (and its threads) alive as long as Rust can reach the proxy. |
| 85 | // Declaration order matters: rtc_runtime_ must be declared before |
| 86 | // adm_proxy_ so it is destroyed last. ~AdmProxy does a BlockingCall onto |
| 87 | // the worker thread, which must still be running at that point. |
| 88 | std::shared_ptr<RtcRuntime> rtc_runtime_; |
| 89 | webrtc::scoped_refptr<AdmProxy> adm_proxy_; |
| 90 | }; |
| 91 | |
| 92 | } // namespace livekit_ffi |