diff --git a/examples/playogg_from_disk/src/main.rs b/examples/playogg_from_disk/src/main.rs index 0353843d..a13c4b50 100644 --- a/examples/playogg_from_disk/src/main.rs +++ b/examples/playogg_from_disk/src/main.rs @@ -2,17 +2,16 @@ use livekit::{ options::TrackPublishOptions, track::{LocalAudioTrack, LocalTrack, TrackSource}, webrtc::{ - audio_source::native::NativeAudioSource, audio_source::native::EncodedAudioSource, + audio_source::native::NativeAudioSource, prelude::{AudioFrame_u8, AudioSourceOptions, RtcAudioSource}, }, Room, RoomOptions, }; -use std::{env, sync::Arc, time::Duration, error::Error}; use std::fs::File; -use std::io::{BufReader}; -use webrtc_media::io::ogg_reader::{OggReader}; - +use std::io::BufReader; +use std::{env, error::Error, sync::Arc, time::Duration}; +use webrtc_media::io::ogg_reader::OggReader; #[tokio::main] async fn main() -> Result<(), Box> { @@ -40,9 +39,7 @@ async fn main() -> Result<(), Box> { header.version, ); - let (room, mut rx) = Room::connect(&url, &token, RoomOptions::default()) - .await - .unwrap(); + let (room, mut rx) = Room::connect(&url, &token, RoomOptions::default()).await.unwrap(); let room = Arc::new(room); log::info!("Connected to room: {} - {}", room.name(), room.sid()); @@ -63,12 +60,9 @@ async fn main() -> Result<(), Box> { room.local_participant() .publish_track( LocalTrack::Audio(track), - TrackPublishOptions { - source: TrackSource::Microphone, - ..Default::default() - }, - ).await?; - + TrackPublishOptions { source: TrackSource::Microphone, ..Default::default() }, + ) + .await?; // Play the wav file and disconnect tokio::spawn({ @@ -78,24 +72,14 @@ async fn main() -> Result<(), Box> { log::info!("num_channels: {}", header.channels); while let Ok((page_data, page_header)) = reader.parse_next_page() { - let frame_size = page_data.len(); let mut audio_frame = AudioFrame_u8 { - data: vec![0u8; 0].into(), + data: page_data.freeze().into(), num_channels: header.channels as u32, sample_rate: header.sample_rate, samples_per_channel: (frame_size / header.channels as usize) as u32, }; - let mut bytes = 0; - for d in page_data.iter() { - bytes += 1; - audio_frame.data.push(*d); - } - - log::info!("samples_per_channel: {}, bytes: {}, frame_size: {}", - audio_frame.samples_per_channel, bytes, frame_size); - source.capture_frame(&audio_frame).await.unwrap(); } diff --git a/webrtc-sys/src/audio_track.cpp b/webrtc-sys/src/audio_track.cpp index a0075411..8799af2c 100644 --- a/webrtc-sys/src/audio_track.cpp +++ b/webrtc-sys/src/audio_track.cpp @@ -85,7 +85,7 @@ void NativeAudioSink::OnData(const void* audio_data, int sample_rate, size_t number_of_channels, size_t number_of_frames) { - RTC_CHECK_EQ(16, bits_per_sample); + // RTC_CHECK_EQ(16, bits_per_sample); rust::Slice data(static_cast(audio_data), number_of_channels * number_of_frames); observer_->on_data(data, sample_rate, number_of_channels, number_of_frames); @@ -150,7 +150,7 @@ void AudioTrackSource::InternalSource::on_captured_frame_u8( size_t number_of_frames) { webrtc::MutexLock lock(&mutex_); for (auto sink : sinks_) { - sink->OnData(data.data(), 8, 2 * sample_rate, number_of_channels, + sink->OnData(data.data(), 16, sample_rate, number_of_channels, number_of_frames); } }