diff --git a/examples/playogg_from_disk/src/main.rs b/examples/playogg_from_disk/src/main.rs index 6dc27f7d..0353843d 100644 --- a/examples/playogg_from_disk/src/main.rs +++ b/examples/playogg_from_disk/src/main.rs @@ -74,33 +74,28 @@ async fn main() -> Result<(), Box> { tokio::spawn({ let room = room.clone(); async move { - const FRAME_DURATION: Duration = Duration::from_millis(1000); // Write 1s of audio at a time - let ms = FRAME_DURATION.as_millis() as u32; - let num_samples = (header.sample_rate / 1000 * ms) as usize; - - log::info!("sample_rate: {}", header.sample_rate); log::info!("num_channels: {}", header.channels); - log::info!("chunk size: {}ms - {} samples", ms, num_samples); - - let mut last_granule: u64 = 0; while let Ok((page_data, page_header)) = reader.parse_next_page() { - let sample_count = page_header.granule_position - last_granule; - let frame_size = page_data.len(); - last_granule = page_header.granule_position; + let frame_size = page_data.len(); let mut audio_frame = AudioFrame_u8 { data: vec![0u8; 0].into(), num_channels: header.channels as u32, sample_rate: header.sample_rate, - samples_per_channel: sample_count as u32, + 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 f99ac92d..a0075411 100644 --- a/webrtc-sys/src/audio_track.cpp +++ b/webrtc-sys/src/audio_track.cpp @@ -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(), 16, sample_rate, number_of_channels, + sink->OnData(data.data(), 8, 2 * sample_rate, number_of_channels, number_of_frames); } }