-
Notifications
You must be signed in to change notification settings - Fork 1
Add audio input and ouptut via platform audio #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ words: | |
| - noninteractive | ||
| - nutf8 | ||
| - oneshot | ||
| - playout | ||
| - publicsans | ||
| - rsplit | ||
| - rustls | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| use livekit::options::TrackPublishOptions; | ||
| use livekit::prelude::*; | ||
| use std::sync::Arc; | ||
|
|
||
| /// Publishes real microphone audio via the shared platform Audio Device Module | ||
| /// (ADM). The [`PlatformAudio`] handle is owned by the connection (see | ||
| /// `RunningState` in `crate::service`) because it also drives remote-audio | ||
| /// playout; this type only controls the mic — it starts/stops ADM recording and | ||
| /// publishes/unpublishes the track on toggle. Frames are captured automatically | ||
| /// by WebRTC, so (unlike [`crate::media::SineTrack`]) there is no generation task. | ||
| pub struct MicTrack { | ||
| room: Arc<Room>, | ||
| track: Option<LocalAudioTrack>, | ||
| } | ||
|
|
||
| impl MicTrack { | ||
| /// Track name used when publishing; also how the UI detects the mic is live. | ||
| pub const TRACK_NAME: &str = "microphone"; | ||
|
|
||
| pub fn new(room: Arc<Room>) -> Self { | ||
| Self { room, track: None } | ||
| } | ||
|
|
||
| pub fn is_published(&self) -> bool { | ||
| self.track.is_some() | ||
| } | ||
|
|
||
| pub async fn publish(&mut self, platform_audio: &PlatformAudio) -> Result<(), RoomError> { | ||
| // Resume mic capture (initializes recording on the first start). | ||
| if let Err(err) = platform_audio.start_recording() { | ||
| log::error!("failed to start platform audio recording: {err}"); | ||
| } | ||
|
|
||
| let track = | ||
| LocalAudioTrack::create_audio_track(Self::TRACK_NAME, platform_audio.rtc_source()); | ||
|
|
||
| self.room | ||
| .local_participant() | ||
| .publish_track( | ||
| LocalTrack::Audio(track.clone()), | ||
| TrackPublishOptions { | ||
| source: TrackSource::Microphone, | ||
| ..Default::default() | ||
| }, | ||
| ) | ||
| .await?; | ||
|
|
||
| self.track = Some(track); | ||
| Ok(()) | ||
| } | ||
|
|
||
| pub async fn unpublish(&mut self, platform_audio: &PlatformAudio) -> Result<(), RoomError> { | ||
| if let Some(track) = self.track.take() { | ||
| self.room | ||
| .local_participant() | ||
| .unpublish_track(&track.sid()) | ||
| .await?; | ||
| } | ||
|
|
||
| // Pause capture (turns off the OS mic indicator); the ADM stays alive for | ||
| // remote-audio playout and is disposed only when the connection ends. | ||
| if let Err(err) = platform_audio.stop_recording() { | ||
| log::error!("failed to stop platform audio recording: {err}"); | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,15 @@ | ||
| //! Media plumbing over WebRTC, independent of the rest of the app (no `crate::` | ||
| //! deps): the synthetic local sources we publish — a generated logo video | ||
| //! ([`LogoTrack`]) and a sine-wave audio track ([`SineTrack`]) — plus the | ||
| //! [`VideoRenderer`] that turns incoming video frames into egui textures. | ||
| //! deps): the local sources we publish — a generated logo video | ||
| //! ([`LogoTrack`]), a synthetic sine-wave audio track ([`SineTrack`]), and a | ||
| //! real microphone audio track ([`MicTrack`]) — plus the [`VideoRenderer`] that | ||
| //! turns incoming video frames into egui textures. | ||
|
|
||
| pub mod logo_track; | ||
| pub mod mic_track; | ||
| pub mod sine_track; | ||
| pub mod video_renderer; | ||
|
|
||
| pub use logo_track::LogoTrack; | ||
| pub use mic_track::MicTrack; | ||
| pub use sine_track::{SineParameters, SineTrack}; | ||
| pub use video_renderer::VideoRenderer; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.