Skip to content

Commit

Permalink
received audio frame.
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudwebrtc committed Sep 23, 2024
1 parent 365de80 commit 3cea202
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
13 changes: 11 additions & 2 deletions examples/wgpu_room/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use crate::{
};
use egui::{Rounding, Stroke};
use livekit::{e2ee::EncryptionType, prelude::*, SimulateScenario};
use livekit::webrtc::{audio_stream::native::NativeAudioStream};
use std::collections::HashMap;
use futures::StreamExt;

/// The state of the application are saved on app exit and restored on app start.
#[derive(serde::Deserialize, serde::Serialize)]
Expand Down Expand Up @@ -88,8 +90,15 @@ impl LkApp {
);
self.video_renderers
.insert((participant.identity(), track.sid()), video_renderer);
} else if let RemoteTrack::Audio(_) = track {
// TODO(theomonnom): Once we support media devices, we can play audio tracks here
} else if let RemoteTrack::Audio(ref audio_track) = track {
let rtc_track = audio_track.rtc_track();
let mut audio_stream = NativeAudioStream::new(rtc_track, 48000, 2);
// Receive the audio frames in a new task
tokio::spawn(async move {
while let Some(frame) = audio_stream.next().await {
println!("Received audio frame {:?}", frame);
}
});
}
}
RoomEvent::TrackUnsubscribed {
Expand Down
4 changes: 4 additions & 0 deletions webrtc-sys/src/audio_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,14 @@ bool AudioDevice::RecordingIsInitialized() const {
int32_t AudioDevice::StartPlayout() {
webrtc::MutexLock lock(&mutex_);
playing_ = true;
audio_device_buffer_.StartPlayout();
return 0;
}

int32_t AudioDevice::StopPlayout() {
webrtc::MutexLock lock(&mutex_);
playing_ = false;
audio_device_buffer_.StopPlayout();
return 0;
}

Expand All @@ -182,10 +184,12 @@ bool AudioDevice::Playing() const {
}

int32_t AudioDevice::StartRecording() {
audio_device_buffer_.StartRecording();
return 0;
}

int32_t AudioDevice::StopRecording() {
audio_device_buffer_.StopRecording();
return 0;
}

Expand Down

0 comments on commit 3cea202

Please sign in to comment.