xref: /webrtc/rtp/src/codecs/opus/mod.rs (revision ffe74184)
1 #[cfg(test)]
2 mod opus_test;
3 
4 use crate::{
5     error::{Error, Result},
6     packetizer::{Depacketizer, Payloader},
7 };
8 
9 use bytes::Bytes;
10 
11 #[derive(Default, Debug, Copy, Clone)]
12 pub struct OpusPayloader;
13 
14 impl Payloader for OpusPayloader {
payload(&mut self, mtu: usize, payload: &Bytes) -> Result<Vec<Bytes>>15     fn payload(&mut self, mtu: usize, payload: &Bytes) -> Result<Vec<Bytes>> {
16         if payload.is_empty() || mtu == 0 {
17             return Ok(vec![]);
18         }
19 
20         Ok(vec![payload.clone()])
21     }
22 
clone_to(&self) -> Box<dyn Payloader + Send + Sync>23     fn clone_to(&self) -> Box<dyn Payloader + Send + Sync> {
24         Box::new(*self)
25     }
26 }
27 
28 /// OpusPacket represents the Opus header that is stored in the payload of an RTP Packet
29 #[derive(PartialEq, Eq, Debug, Default, Clone)]
30 pub struct OpusPacket;
31 
32 impl Depacketizer for OpusPacket {
depacketize(&mut self, packet: &Bytes) -> Result<Bytes>33     fn depacketize(&mut self, packet: &Bytes) -> Result<Bytes> {
34         if packet.is_empty() {
35             Err(Error::ErrShortPacket)
36         } else {
37             Ok(packet.clone())
38         }
39     }
40 
is_partition_head(&self, _payload: &Bytes) -> bool41     fn is_partition_head(&self, _payload: &Bytes) -> bool {
42         true
43     }
44 
is_partition_tail(&self, _marker: bool, _payload: &Bytes) -> bool45     fn is_partition_tail(&self, _marker: bool, _payload: &Bytes) -> bool {
46         true
47     }
48 }
49