xref: /webrtc/rtp/src/codecs/opus/opus_test.rs (revision ffe74184)
1 use super::*;
2 
3 #[test]
test_opus_unmarshal() -> Result<()>4 fn test_opus_unmarshal() -> Result<()> {
5     let mut pck = OpusPacket::default();
6 
7     // Empty packet
8     let empty_bytes = Bytes::from_static(&[]);
9     let result = pck.depacketize(&empty_bytes);
10     assert!(result.is_err(), "Result should be err in case of error");
11 
12     // Normal packet
13     let raw_bytes = Bytes::from_static(&[0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x90]);
14     let payload = pck.depacketize(&raw_bytes)?;
15     assert_eq!(&raw_bytes, &payload, "Payload must be same");
16 
17     Ok(())
18 }
19 
20 #[test]
test_opus_payload() -> Result<()>21 fn test_opus_payload() -> Result<()> {
22     let mut pck = OpusPayloader::default();
23     let empty = Bytes::from_static(&[]);
24     let payload = Bytes::from_static(&[0x90, 0x90, 0x90]);
25 
26     // Positive MTU, empty payload
27     let result = pck.payload(1, &empty)?;
28     assert!(result.is_empty(), "Generated payload should be empty");
29 
30     // Positive MTU, small payload
31     let result = pck.payload(1, &payload)?;
32     assert_eq!(result.len(), 1, "Generated payload should be the 1");
33 
34     // Positive MTU, small payload
35     let result = pck.payload(2, &payload)?;
36     assert_eq!(result.len(), 1, "Generated payload should be the 1");
37 
38     Ok(())
39 }
40 
41 #[test]
test_opus_is_partition_head() -> Result<()>42 fn test_opus_is_partition_head() -> Result<()> {
43     let opus = OpusPacket::default();
44     //"NormalPacket"
45     assert!(
46         opus.is_partition_head(&Bytes::from_static(&[0x00, 0x00])),
47         "All OPUS RTP packet should be the head of a new partition"
48     );
49 
50     Ok(())
51 }
52