pub mod audio_decoder_wrapper;
pub mod config;
pub mod hash_map_with_ordered_keys;
pub mod media_decoder_trait;
pub mod neteq_audio_decoder;
pub mod peer_decode_manager;
pub mod peer_decoder;
pub mod video_decoder_wrapper;
pub use peer_decode_manager::{PeerDecodeManager, PeerStatus};
pub use peer_decoder::VideoPeerDecoder;
use neteq_audio_decoder::NetEqAudioPeerDecoder;
use peer_decoder::{
DecodeStatus as StandardDecodeStatus, PeerDecode as StandardPeerDecodeTrait,
StandardAudioPeerDecoder,
};
use std::sync::Arc;
use videocall_types::protos::media_packet::MediaPacket;
use wasm_bindgen::JsValue;
#[derive(Debug, Clone, Copy)]
pub struct DecodeStatus {
pub rendered: bool,
pub first_frame: bool,
}
impl DecodeStatus {
pub const SKIPPED: Self = Self {
rendered: false,
first_frame: false,
};
}
impl From<StandardDecodeStatus> for DecodeStatus {
fn from(status: StandardDecodeStatus) -> Self {
DecodeStatus {
rendered: status._rendered, first_frame: status.first_frame,
}
}
}
pub trait AudioPeerDecoderTrait {
fn decode(&mut self, packet: &Arc<MediaPacket>) -> anyhow::Result<DecodeStatus>;
fn flush(&mut self);
fn set_muted(&mut self, muted: bool);
}
impl AudioPeerDecoderTrait for StandardAudioPeerDecoder {
fn decode(&mut self, packet: &Arc<MediaPacket>) -> anyhow::Result<DecodeStatus> {
StandardPeerDecodeTrait::decode(self, packet).map(|status| status.into())
}
fn flush(&mut self) {
if let Err(e) = self.decoder.flush() {
log::error!("Failed to flush standard audio decoder: {e:?}");
}
}
fn set_muted(&mut self, _muted: bool) {
log::debug!("set_muted called on standard audio decoder (no-op)");
}
}
pub fn create_audio_peer_decoder(
speaker_device_id: Option<String>,
peer_id: String,
vad_threshold: Option<f32>,
) -> Result<Box<dyn AudioPeerDecoderTrait>, JsValue> {
NetEqAudioPeerDecoder::new_with_mute_state(speaker_device_id, peer_id, true, vad_threshold)
}