gosuto_libwebrtc/
audio_stream.rs1use crate::imp::audio_stream as stream_imp;
16
17#[cfg(not(target_arch = "wasm32"))]
18pub mod native {
19 use std::{
20 fmt::{Debug, Formatter},
21 pin::Pin,
22 task::{Context, Poll},
23 };
24
25 use livekit_runtime::Stream;
26
27 use super::stream_imp;
28 use crate::{audio_frame::AudioFrame, audio_track::RtcAudioTrack};
29
30 pub struct NativeAudioStream {
31 pub(crate) handle: stream_imp::NativeAudioStream,
32 }
33
34 impl Debug for NativeAudioStream {
35 fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
36 f.debug_struct("NativeAudioStream").field("track", &self.track()).finish()
37 }
38 }
39
40 impl NativeAudioStream {
41 pub fn new(audio_track: RtcAudioTrack, sample_rate: i32, num_channels: i32) -> Self {
42 Self {
43 handle: stream_imp::NativeAudioStream::new(audio_track, sample_rate, num_channels),
44 }
45 }
46
47 pub fn track(&self) -> RtcAudioTrack {
48 self.handle.track()
49 }
50
51 pub fn close(&mut self) {
52 self.handle.close()
53 }
54 }
55
56 impl Stream for NativeAudioStream {
57 type Item = AudioFrame<'static>;
58
59 fn poll_next(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Option<Self::Item>> {
60 Pin::new(&mut self.get_mut().handle).poll_next(cx)
61 }
62 }
63}