-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1426b3d
commit d544f64
Showing
15 changed files
with
331 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,20 @@ | ||
use anyhow::bail; | ||
|
||
use crate::bytebufferext::{decode_impl, encode_impl, ByteBufferExtRead, ByteBufferExtWrite}; | ||
|
||
const VOICE_OPUS_FRAMES_IN_AUDIO_FRAME: usize = 20; | ||
|
||
type EncodedOpusData = Vec<u8>; | ||
#[derive(Clone, Default)] | ||
|
||
#[derive(Clone)] | ||
pub struct EncodedAudioFrame { | ||
pub opus_frames: Vec<EncodedOpusData>, | ||
pub opus_frames: [EncodedOpusData; VOICE_OPUS_FRAMES_IN_AUDIO_FRAME], | ||
} | ||
|
||
encode_impl!(EncodedAudioFrame, buf, self, { | ||
buf.write_u16(self.opus_frames.len() as u16); | ||
|
||
for frame in self.opus_frames.iter() { | ||
buf.write_byte_array(frame); | ||
} | ||
buf.write_value_array(&self.opus_frames); | ||
}); | ||
|
||
decode_impl!(EncodedAudioFrame, buf, { | ||
let frames = buf.read_u16()?; | ||
if frames > 64 { | ||
bail!("failed to decode EncodedAudioFrame, way too many frames ({frames})"); | ||
} | ||
|
||
let mut opus_frames = Vec::with_capacity(frames as usize); | ||
|
||
for _ in 0..frames { | ||
let frame = buf.read_byte_array()?; | ||
opus_frames.push(frame); | ||
} | ||
|
||
Ok(Self { opus_frames }) | ||
Ok(Self { | ||
opus_frames: buf.read_value_array()?, | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.