1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//! Opus frame structures and frame length decoding.
//!
//! This module provides types and functions for working with Opus frames within
//! packets, including frame packing modes and frame length decoding per RFC 6716.
use crate;
/// Frame packing modes defined by RFC 6716 Section 3.2.
///
/// The frame packing code (bits 0-1 of the TOC byte) determines how frames
/// are structured within an Opus packet.
/// Decode frame length from packet data.
///
/// Parses the frame length encoding from RFC 6716 Section 3.2.1.
///
/// # Returns
///
/// Returns a tuple of (`frame_length`, `bytes_consumed`) where:
/// * `frame_length` - The decoded frame length in bytes (0-1275)
/// * `bytes_consumed` - Number of bytes consumed from input (1 or 2)
///
/// # Errors
///
/// * `PacketTooShort` - If the data is empty or doesn't contain enough bytes for the length encoding
/// * `InvalidFrameLength` - If the decoded length exceeds the maximum of 1275 bytes
///
/// # Examples
///
/// ```rust
/// use moosicbox_opus::decode_frame_length;
///
/// let (len, consumed) = decode_frame_length(&[120]).expect("valid short frame length");
/// assert_eq!(len, 120);
/// assert_eq!(consumed, 1);
/// ```
/// Opus frame data within a packet.
///
/// Represents a single encoded Opus frame, which is the fundamental unit
/// of Opus compression. Frames may represent audio data or DTX (discontinuous
/// transmission) silence frames.