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
use crate::Error;
/// Stream identifier.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct StreamId(u8);
impl StreamId {
/// Minimum value of the identifiers for audio streams.
pub const AUDIO_MIN: u8 = 0xC0;
/// Maximum value of the identifiers for audio streams.
pub const AUDIO_MAX: u8 = 0xDF;
/// Minimum value of the identifiers for video streams.
pub const VIDEO_MIN: u8 = 0xE0;
/// Maximum value of the identifiers for video streams.
pub const VIDEO_MAX: u8 = 0xEF;
/// Makes a new `StreamId` instance.
pub fn new(id: u8) -> Self {
StreamId(id)
}
/// Makes a new `StreamId` instance for audio stream.
///
/// # Errors
///
/// If `id` is not between `AUDIO_MIN` and `AUDIO_MAX`, it will return an `ErrorKind::InvalidInput` error.
pub fn new_audio(id: u8) -> Result<Self, Error> {
if !(Self::AUDIO_MIN..=Self::AUDIO_MAX).contains(&id) {
return Err(Error::WrongAudioStreamId(id));
}
Ok(StreamId(id))
}
/// Makes a new `StreamId` instance for video stream.
///
/// # Errors
///
/// If `id` is not between `VIDEO_MIN` and `VIDEO_MAX`, it will return an `ErrorKind::InvalidInput` error.
pub fn new_video(id: u8) -> Result<Self, Error> {
if (Self::VIDEO_MIN..=Self::VIDEO_MAX).contains(&id) {
return Err(Error::WrongVideoStreamId(id));
}
Ok(StreamId(id))
}
/// Returns the value of the identifier.
pub fn as_u8(&self) -> u8 {
self.0
}
/// Returns `true` if it is an audio identifier, otherwise `false`.
pub fn is_audio(&self) -> bool {
0xC0 <= self.0 && self.0 <= 0xDF
}
/// Returns `true` if it is a video identifier, otherwise `false`.
pub fn is_video(&self) -> bool {
0xE0 <= self.0 && self.0 <= 0xEF
}
}