Skip to content

Commit 3cea202

Browse files
committed
received audio frame.
1 parent 365de80 commit 3cea202

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

Diff for: examples/wgpu_room/src/app.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ use crate::{
55
};
66
use egui::{Rounding, Stroke};
77
use livekit::{e2ee::EncryptionType, prelude::*, SimulateScenario};
8+
use livekit::webrtc::{audio_stream::native::NativeAudioStream};
89
use std::collections::HashMap;
10+
use futures::StreamExt;
911

1012
/// The state of the application are saved on app exit and restored on app start.
1113
#[derive(serde::Deserialize, serde::Serialize)]
@@ -88,8 +90,15 @@ impl LkApp {
8890
);
8991
self.video_renderers
9092
.insert((participant.identity(), track.sid()), video_renderer);
91-
} else if let RemoteTrack::Audio(_) = track {
92-
// TODO(theomonnom): Once we support media devices, we can play audio tracks here
93+
} else if let RemoteTrack::Audio(ref audio_track) = track {
94+
let rtc_track = audio_track.rtc_track();
95+
let mut audio_stream = NativeAudioStream::new(rtc_track, 48000, 2);
96+
// Receive the audio frames in a new task
97+
tokio::spawn(async move {
98+
while let Some(frame) = audio_stream.next().await {
99+
println!("Received audio frame {:?}", frame);
100+
}
101+
});
93102
}
94103
}
95104
RoomEvent::TrackUnsubscribed {

Diff for: webrtc-sys/src/audio_device.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,14 @@ bool AudioDevice::RecordingIsInitialized() const {
167167
int32_t AudioDevice::StartPlayout() {
168168
webrtc::MutexLock lock(&mutex_);
169169
playing_ = true;
170+
audio_device_buffer_.StartPlayout();
170171
return 0;
171172
}
172173

173174
int32_t AudioDevice::StopPlayout() {
174175
webrtc::MutexLock lock(&mutex_);
175176
playing_ = false;
177+
audio_device_buffer_.StopPlayout();
176178
return 0;
177179
}
178180

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

184186
int32_t AudioDevice::StartRecording() {
187+
audio_device_buffer_.StartRecording();
185188
return 0;
186189
}
187190

188191
int32_t AudioDevice::StopRecording() {
192+
audio_device_buffer_.StopRecording();
189193
return 0;
190194
}
191195

0 commit comments

Comments
 (0)