rtc_rtp/codecs/opus/
mod.rs1#[cfg(test)]
2mod opus_test;
3
4use crate::packetizer::{Depacketizer, Payloader};
5use shared::error::{Error, Result};
6
7use bytes::Bytes;
8
9#[derive(Default, Debug, Copy, Clone)]
10pub struct OpusPayloader;
11
12impl Payloader for OpusPayloader {
13 fn payload(&mut self, mtu: usize, payload: &Bytes) -> Result<Vec<Bytes>> {
14 if payload.is_empty() || mtu == 0 {
15 return Ok(vec![]);
16 }
17
18 Ok(vec![payload.clone()])
19 }
20
21 fn clone_to(&self) -> Box<dyn Payloader> {
22 Box::new(*self)
23 }
24}
25
26#[derive(PartialEq, Eq, Debug, Default, Clone)]
28pub struct OpusPacket;
29
30impl Depacketizer for OpusPacket {
31 fn depacketize(&mut self, packet: &Bytes) -> Result<Bytes> {
32 if packet.is_empty() {
33 Err(Error::ErrShortPacket)
34 } else {
35 Ok(packet.clone())
36 }
37 }
38
39 fn is_partition_head(&self, _payload: &Bytes) -> bool {
40 true
41 }
42
43 fn is_partition_tail(&self, _marker: bool, _payload: &Bytes) -> bool {
44 true
45 }
46}