11//! API surface and implementation for Flutter.
22
33pub mod capability;
4+ pub mod media;
45pub mod media_info;
56pub mod media_stream_track;
67pub mod peer;
@@ -12,10 +13,7 @@ pub mod transceiver;
1213#[ cfg( doc) ]
1314use std:: sync:: mpsc;
1415use std:: {
15- sync:: {
16- Arc , LazyLock , Mutex ,
17- atomic:: { AtomicBool , Ordering } ,
18- } ,
16+ sync:: { Arc , LazyLock , Mutex } ,
1917 time:: Duration ,
2018} ;
2119
@@ -29,6 +27,13 @@ pub use self::{
2927 ScalabilityMode , get_rtp_receiver_capabilities,
3028 get_rtp_sender_capabilities, set_codec_preferences,
3129 } ,
30+ media:: {
31+ AudioConstraints , AudioProcessingConstraints , MediaStreamConstraints ,
32+ VideoConstraints , enable_fake_media, enumerate_devices,
33+ enumerate_displays, is_fake_media, microphone_volume,
34+ microphone_volume_is_available, set_audio_playout_device,
35+ set_microphone_volume, set_on_device_changed,
36+ } ,
3237 media_info:: { MediaDeviceInfo , MediaDeviceKind , MediaDisplayInfo } ,
3338 media_stream_track:: {
3439 AudioProcessingConfig , GetMediaError , GetMediaResult , MediaStreamTrack ,
@@ -68,11 +73,9 @@ pub use crate::{
6873 renderer:: TextureEvent ,
6974} ;
7075use crate :: {
71- Webrtc , devices ,
76+ Webrtc ,
7277 frb:: { FrbHandler , new_frb_handler} ,
73- frb_generated:: {
74- FLUTTER_RUST_BRIDGE_CODEGEN_VERSION , RustOpaque , StreamSink ,
75- } ,
78+ frb_generated:: { FLUTTER_RUST_BRIDGE_CODEGEN_VERSION , RustOpaque } ,
7679} ;
7780
7881/// Custom [`Handler`] for executing Rust code called from Dart.
@@ -100,9 +103,6 @@ pub(crate) static WEBRTC: LazyLock<Mutex<Webrtc>> =
100103/// Timeout for [`mpsc::Receiver::recv_timeout()`] operations.
101104pub static RX_TIMEOUT : Duration = Duration :: from_secs ( 5 ) ;
102105
103- /// Indicator whether application is configured to use fake media devices.
104- static FAKE_MEDIA : AtomicBool = AtomicBool :: new ( false ) ;
105-
106106/// [MediaStreamTrack.kind][1] representation.
107107///
108108/// [1]: https://w3.org/TR/mediacapture-streams#dfn-kind
@@ -124,104 +124,6 @@ impl From<sys::TrackKind> for TrackKind {
124124 }
125125}
126126
127- /// [MediaStreamConstraints], used to instruct what sort of
128- /// [`MediaStreamTrack`]s to return by the [`Webrtc::get_media()`].
129- ///
130- /// [1]: https://w3.org/TR/mediacapture-streams#dom-mediastreamconstraints
131- #[ derive( Debug ) ]
132- pub struct MediaStreamConstraints {
133- /// Specifies the nature and settings of the audio [`MediaStreamTrack`].
134- pub audio : Option < AudioConstraints > ,
135-
136- /// Specifies the nature and settings of the video [`MediaStreamTrack`].
137- pub video : Option < VideoConstraints > ,
138- }
139-
140- /// Nature and settings of the video [`MediaStreamTrack`] returned by
141- /// [`Webrtc::get_media()`].
142- #[ derive( Debug ) ]
143- pub struct VideoConstraints {
144- /// Identifier of the device generating the content of the
145- /// [`MediaStreamTrack`].
146- ///
147- /// The first device will be chosen if an empty [`String`] is provided.
148- pub device_id : Option < String > ,
149-
150- /// Width in pixels.
151- pub width : u32 ,
152-
153- /// Height in pixels.
154- pub height : u32 ,
155-
156- /// Exact frame rate (frames per second).
157- pub frame_rate : u32 ,
158-
159- /// Indicator whether the request video track should be acquired via screen
160- /// capturing.
161- pub is_display : bool ,
162- }
163-
164- /// Nature and settings of the audio [`MediaStreamTrack`] returned by
165- /// [`Webrtc::get_media()`].
166- #[ derive( Debug ) ]
167- pub struct AudioConstraints {
168- /// Identifier of the device generating the content of the
169- /// [`MediaStreamTrack`].
170- ///
171- /// First device will be chosen if an empty [`String`] is provided.
172- pub device_id : Option < String > ,
173-
174- /// Audio processing configuration constraints of the [`MediaStreamTrack`].
175- pub processing : AudioProcessingConstraints ,
176- }
177-
178- /// Constraints of an [`AudioProcessingConfig`].
179- #[ derive( Debug , Default ) ]
180- pub struct AudioProcessingConstraints {
181- /// Indicator whether the audio volume level should be automatically tuned
182- /// to maintain a steady overall volume level.
183- pub auto_gain_control : Option < bool > ,
184-
185- /// Indicator whether a high-pass filter should be enabled to eliminate
186- /// low-frequency noise.
187- pub high_pass_filter : Option < bool > ,
188-
189- /// Indicator whether noise suppression should be enabled to reduce
190- /// background sounds.
191- pub noise_suppression : Option < bool > ,
192-
193- /// Level of aggressiveness for noise suppression.
194- pub noise_suppression_level : Option < NoiseSuppressionLevel > ,
195-
196- /// Indicator whether echo cancellation should be enabled to prevent
197- /// feedback.
198- pub echo_cancellation : Option < bool > ,
199- }
200-
201- /// Configures media acquisition to use fake devices instead of actual camera
202- /// and microphone.
203- pub fn enable_fake_media ( ) {
204- FAKE_MEDIA . store ( true , Ordering :: Release ) ;
205- }
206-
207- /// Indicates whether application is configured to use fake media devices.
208- pub fn is_fake_media ( ) -> bool {
209- FAKE_MEDIA . load ( Ordering :: Acquire )
210- }
211-
212- /// Returns a list of all available media input and output devices, such as
213- /// microphones, cameras, headsets, and so forth.
214- pub fn enumerate_devices ( ) -> anyhow:: Result < Vec < MediaDeviceInfo > > {
215- WEBRTC . lock ( ) . unwrap ( ) . enumerate_devices ( )
216- }
217-
218- /// Returns a list of all available displays that can be used for screen
219- /// capturing.
220- #[ must_use]
221- pub fn enumerate_displays ( ) -> Vec < MediaDisplayInfo > {
222- devices:: enumerate_displays ( )
223- }
224-
225127/// Replaces the specified [`AudioTrack`] (or [`VideoTrack`]) on the
226128/// [`sys::RtpTransceiverInterface`]'s `sender`.
227129///
@@ -253,35 +155,3 @@ pub fn sender_set_parameters(
253155) -> anyhow:: Result < ( ) > {
254156 transceiver. sender_set_parameters ( params)
255157}
256-
257- /// Sets the specified `audio playout` device.
258- pub fn set_audio_playout_device ( device_id : String ) -> anyhow:: Result < ( ) > {
259- WEBRTC . lock ( ) . unwrap ( ) . set_audio_playout_device ( device_id)
260- }
261-
262- /// Indicates whether the microphone is available to set volume.
263- pub fn microphone_volume_is_available ( ) -> anyhow:: Result < bool > {
264- WEBRTC . lock ( ) . unwrap ( ) . microphone_volume_is_available ( )
265- }
266-
267- /// Sets the microphone system volume according to the specified `level` in
268- /// percents.
269- ///
270- /// Valid values range is `[0; 100]`.
271- pub fn set_microphone_volume ( level : u8 ) -> anyhow:: Result < ( ) > {
272- WEBRTC . lock ( ) . unwrap ( ) . set_microphone_volume ( level)
273- }
274-
275- /// Returns the current level of the microphone volume in `[0; 100]` range.
276- pub fn microphone_volume ( ) -> anyhow:: Result < u32 > {
277- WEBRTC . lock ( ) . unwrap ( ) . microphone_volume ( )
278- }
279-
280- /// Sets the provided `OnDeviceChangeCallback` as the callback to be called
281- /// whenever a set of available media devices changes.
282- ///
283- /// Only one callback can be set at a time, so the previous one will be dropped,
284- /// if any.
285- pub fn set_on_device_changed ( cb : StreamSink < ( ) > ) {
286- WEBRTC . lock ( ) . unwrap ( ) . set_on_device_changed ( cb) ;
287- }
0 commit comments