Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl Encoder {
for &byte in len.to_le_bytes()[..count].iter().rev() {
self.buffer.push_front(byte);
}
self.buffer.push_front((0xEF + count).try_into().unwrap());
self.buffer.push_front((0xef + count).try_into().unwrap());
}
Head::Reserved(value) => self.buffer.push_front(value),
}
Expand Down
2 changes: 1 addition & 1 deletion src/flac_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ impl FlacBuilder {
streaminfo.extend_from_slice(&4096u16.to_be_bytes());
streaminfo.extend_from_slice(&4096u16.to_be_bytes());
streaminfo.extend_from_slice(&[0; 6]);
streaminfo.extend_from_slice(&[0x0A, 0xC4, 0x42, 0xF0]);
streaminfo.extend_from_slice(&[0x0a, 0xc4, 0x42, 0xf0]);
streaminfo.extend_from_slice(&self.samples.to_be_bytes());
streaminfo.extend_from_slice(&[0; 16]);

Expand Down
2 changes: 1 addition & 1 deletion src/flac_decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl<'a> Iterator for Blocks<'a> {
Some(Ok(Block {
body,
end,
ty: header[0] & 0x7F,
ty: header[0] & 0x7f,
}))
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/head.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl Head {
Self::Medium(len) => {
if len == 1 {
ensure! {
*buffer.get(1).context(decode_error::Truncated)? > 0x7F,
*buffer.get(1).context(decode_error::Truncated)? > 0x7f,
decode_error::Overlong,
}
}
Expand All @@ -76,7 +76,7 @@ impl Head {

if count == 1 {
ensure! {
len > 0x6F,
len > 0x6f,
decode_error::Overlong,
}
}
Expand All @@ -92,9 +92,9 @@ impl From<u8> for Head {
fn from(head: u8) -> Self {
match head {
0x00..0x80 => Self::Small,
0x80..0xF0 => Self::Medium((head - 0x80).into()),
0xF0..0xF8 => Self::Large((head - 0xEF).into()),
0xF8..=0xFF => Self::Reserved(head),
0x80..0xf0 => Self::Medium((head - 0x80).into()),
0xf0..0xf8 => Self::Large((head - 0xef).into()),
0xf8..=0xff => Self::Reserved(head),
}
}
}
Expand Down Expand Up @@ -130,13 +130,13 @@ mod tests {

#[test]
fn head_parse() {
for i in 0..=0xFF {
for i in 0..=0xff {
let head = Head::from(i);
match i {
0x00..0x80 => assert_eq!(head, Head::Small),
0x80..0xF0 => assert_eq!(head, Head::Medium((i - 0x80).into())),
0xF0..0xF8 => assert_eq!(head, Head::Large((i - 0xEF).into())),
0xF8..=0xFF => assert_eq!(head, Head::Reserved(i)),
0x80..0xf0 => assert_eq!(head, Head::Medium((i - 0x80).into())),
0xf0..0xf8 => assert_eq!(head, Head::Large((i - 0xef).into())),
0xf8..=0xff => assert_eq!(head, Head::Reserved(i)),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/jpeg_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub(crate) struct JpegBuilder {

impl JpegBuilder {
fn app1(header: &[u8], payload: &[u8]) -> Vec<u8> {
let mut segment = vec![0xFF, 0xE1];
let mut segment = vec![0xff, 0xe1];
segment.extend_from_slice(
&u16::try_from(header.len() + payload.len() + 2)
.unwrap()
Expand All @@ -39,7 +39,7 @@ impl JpegBuilder {
let mut bytes = buffer.into_inner();

if let Some(sampling) = self.sampling {
let sof = bytes.windows(2).position(|w| w == [0xFF, 0xC0]).unwrap();
let sof = bytes.windows(2).position(|w| w == [0xff, 0xc0]).unwrap();
bytes[sof + 11] = sampling;
}

Expand Down
10 changes: 5 additions & 5 deletions src/mp3_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,18 @@ impl Mp3Builder {
}

fn standard() -> Vec<u8> {
let mut bytes = vec![0xFF, 0xFB, 0x90, 0x00];
let mut bytes = vec![0xff, 0xfb, 0x90, 0x00];
bytes.resize(417, 0);
bytes
}

fn syncsafe(n: usize) -> [u8; 4] {
let n = u32::try_from(n).unwrap();
[
u8::try_from((n >> 21) & 0x7F).unwrap(),
u8::try_from((n >> 14) & 0x7F).unwrap(),
u8::try_from((n >> 7) & 0x7F).unwrap(),
u8::try_from(n & 0x7F).unwrap(),
u8::try_from((n >> 21) & 0x7f).unwrap(),
u8::try_from((n >> 14) & 0x7f).unwrap(),
u8::try_from((n >> 7) & 0x7f).unwrap(),
u8::try_from(n & 0x7f).unwrap(),
]
}

Expand Down
28 changes: 14 additions & 14 deletions src/mp3_decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl<'a> Mp3Decoder<'a> {
.unwrap();

ensure! {
header[0] == 0xFF && header[1] & 0xE0 == 0xE0,
header[0] == 0xff && header[1] & 0xe0 == 0xe0,
mp3_error::Sync { offset },
}

Expand Down Expand Up @@ -479,44 +479,44 @@ mod tests {
);

case(
Mp3Builder::new().frame([0xFF, 0xEB, 0x90, 0x00], 417),
Mp3Builder::new().frame([0xff, 0xeb, 0x90, 0x00], 417),
Mp3Error::Version,
);

case(
Mp3Builder::new().frame([0xFF, 0xF9, 0x90, 0x00], 417),
Mp3Builder::new().frame([0xff, 0xf9, 0x90, 0x00], 417),
Mp3Error::LayerInvalid,
);

case(
Mp3Builder::new().frame([0xFF, 0xFD, 0x90, 0x00], 417),
Mp3Builder::new().frame([0xff, 0xfd, 0x90, 0x00], 417),
Mp3Error::LayerUnsupported { layer: 2 },
);

case(
Mp3Builder::new().frame([0xFF, 0xFF, 0x90, 0x00], 417),
Mp3Builder::new().frame([0xff, 0xff, 0x90, 0x00], 417),
Mp3Error::LayerUnsupported { layer: 1 },
);

case(
Mp3Builder::new().frame([0xFF, 0xFB, 0x00, 0x00], 417),
Mp3Builder::new().frame([0xff, 0xfb, 0x00, 0x00], 417),
Mp3Error::Bitrate { index: 0 },
);

case(
Mp3Builder::new().frame([0xFF, 0xFB, 0xF0, 0x00], 417),
Mp3Builder::new().frame([0xff, 0xfb, 0xf0, 0x00], 417),
Mp3Error::Bitrate { index: 15 },
);

case(
Mp3Builder::new().frame([0xFF, 0xFB, 0x9C, 0x00], 417),
Mp3Builder::new().frame([0xff, 0xfb, 0x9c, 0x00], 417),
Mp3Error::SampleRate,
);

case(
Mp3Builder::new()
.frames(1)
.frame([0xFF, 0xFB, 0x90, 0xC0], 417),
.frame([0xff, 0xfb, 0x90, 0xc0], 417),
Mp3Error::ChannelsMismatch {
actual: 1,
expected: 2,
Expand All @@ -526,7 +526,7 @@ mod tests {
case(
Mp3Builder::new()
.frames(1)
.frame([0xFF, 0xFB, 0x94, 0x00], 384),
.frame([0xff, 0xfb, 0x94, 0x00], 384),
Mp3Error::SampleRateMismatch {
actual: 48000,
expected: 44100,
Expand Down Expand Up @@ -597,7 +597,7 @@ mod tests {

case(
Mp3Builder::new()
.frame([0xFF, 0xFB, 0x92, 0x00], 418)
.frame([0xff, 0xfb, 0x92, 0x00], 418)
.frames(1),
AudioProperties {
channels: 2,
Expand All @@ -608,7 +608,7 @@ mod tests {
);

case(
Mp3Builder::new().frame([0xFF, 0xFB, 0x90, 0xC0], 417),
Mp3Builder::new().frame([0xff, 0xfb, 0x90, 0xc0], 417),
AudioProperties {
channels: 1,
sample_rate: 44100,
Expand All @@ -618,7 +618,7 @@ mod tests {
);

case(
Mp3Builder::new().frame([0xFF, 0xF3, 0x90, 0x00], 261),
Mp3Builder::new().frame([0xff, 0xf3, 0x90, 0x00], 261),
AudioProperties {
channels: 2,
sample_rate: 22050,
Expand All @@ -628,7 +628,7 @@ mod tests {
);

case(
Mp3Builder::new().frame([0xFF, 0xE3, 0x90, 0x00], 522),
Mp3Builder::new().frame([0xff, 0xe3, 0x90, 0x00], 522),
AudioProperties {
channels: 2,
sample_rate: 11025,
Expand Down
10 changes: 5 additions & 5 deletions src/mp4_decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,23 +311,23 @@ mod tests {
Some(config(8, ChromaSubsampling::Yuv420)),
);
case(
&[0x67, 100, 0, 31, 0xA6],
&[0x67, 100, 0, 31, 0xa6],
Some(config(10, ChromaSubsampling::Yuv420)),
);
case(
&[0x67, 100, 0, 31, 0xB8],
&[0x67, 100, 0, 31, 0xb8],
Some(config(8, ChromaSubsampling::Yuv422)),
);
case(
&[0x67, 100, 0, 31, 0x91],
Some(config(8, ChromaSubsampling::Yuv444)),
);
case(
&[0x67, 100, 0, 31, 0xE0],
&[0x67, 100, 0, 31, 0xe0],
Some(config(8, ChromaSubsampling::Yuv400)),
);
case(
&[0x67, 100, 0, 0, 0x03, 0xA6],
&[0x67, 100, 0, 0, 0x03, 0xa6],
Some(config(10, ChromaSubsampling::Yuv420)),
);
case(&[0x67, 100, 0, 31], None);
Expand Down Expand Up @@ -475,7 +475,7 @@ mod tests {
assert_eq!(
case(
Mp4Builder::new()
.sps(&[0x67, 100, 0, 31, 0xA6])
.sps(&[0x67, 100, 0, 31, 0xa6])
.video_track(2, 1),
)
.unwrap()
Expand Down
10 changes: 5 additions & 5 deletions src/orientation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ mod tests {
fn from_exif_big_endian() {
assert_eq!(
Orientation::from_exif(&[
0x4D, 0x4D, 0x00, 0x2A, 0x00, 0x00, 0x00, 0x08, 0x00, 0x01, 0x01, 0x12, 0x00, 0x03, 0x00,
0x4d, 0x4d, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x08, 0x00, 0x01, 0x01, 0x12, 0x00, 0x03, 0x00,
0x00, 0x00, 0x01, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
])
.unwrap(),
Expand All @@ -194,15 +194,15 @@ mod tests {
case(b"foo", "invalid byte order");
case(b"II", "truncated EXIF data");
case(
&[0x49, 0x49, 0x2B, 0x00, 0x08, 0x00, 0x00, 0x00],
&[0x49, 0x49, 0x2b, 0x00, 0x08, 0x00, 0x00, 0x00],
"expected magic 42 but found 43",
);
case(
&[0x49, 0x49, 0x2A, 0x00, 0x08, 0x00, 0x00, 0x00],
&[0x49, 0x49, 0x2a, 0x00, 0x08, 0x00, 0x00, 0x00],
"truncated EXIF data",
);
case(
&[0x49, 0x49, 0x2A, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00],
&[0x49, 0x49, 0x2a, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00],
"truncated EXIF data",
);
case(&exif(0), "invalid orientation value 0");
Expand All @@ -226,7 +226,7 @@ mod tests {

assert_eq!(
Orientation::from_exif(&[
0x49, 0x49, 0x2A, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x49, 0x49, 0x2a, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
])
.unwrap(),
Orientation::new(),
Expand Down
34 changes: 17 additions & 17 deletions src/webm_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ pub(crate) struct WebmBuilder {
impl WebmBuilder {
pub(crate) fn audio_settings(channels: u64, sampling_frequency: f64) -> Vec<u8> {
Self::element(
&[0xE1],
&[0xe1],
&[
Self::unsigned(&[0x9F], channels),
Self::float(&[0xB5], sampling_frequency),
Self::unsigned(&[0x9f], channels),
Self::float(&[0xb5], sampling_frequency),
]
.concat(),
)
Expand All @@ -36,7 +36,7 @@ impl WebmBuilder {
let info = [
self
.timestamp_scale
.map(|timestamp_scale| Self::unsigned(&[0x2A, 0xD7, 0xB1], timestamp_scale))
.map(|timestamp_scale| Self::unsigned(&[0x2a, 0xd7, 0xb1], timestamp_scale))
.unwrap_or_default(),
self
.duration
Expand All @@ -45,22 +45,22 @@ impl WebmBuilder {
self
.title
.as_deref()
.map(|title| Self::string(&[0x7B, 0xA9], title))
.map(|title| Self::string(&[0x7b, 0xa9], title))
.unwrap_or_default(),
Self::string(&[0x4D, 0x80], "foo"),
Self::string(&[0x4d, 0x80], "foo"),
Self::string(&[0x57, 0x41], "bar"),
]
.concat();

let segment = [
Self::element(&[0x15, 0x49, 0xA9, 0x66], &info),
Self::element(&[0x16, 0x54, 0xAE, 0x6B], &self.tracks.concat()),
Self::element(&[0x1F, 0x43, 0xB6, 0x75], &self.blocks.concat()),
Self::element(&[0x15, 0x49, 0xa9, 0x66], &info),
Self::element(&[0x16, 0x54, 0xae, 0x6b], &self.tracks.concat()),
Self::element(&[0x1f, 0x43, 0xb6, 0x75], &self.blocks.concat()),
]
.concat();

[
Self::element(&[0x1A, 0x45, 0xDF, 0xA3], &header),
Self::element(&[0x1a, 0x45, 0xdf, 0xa3], &header),
Self::element(&[0x18, 0x53, 0x80, 0x67], &segment),
]
.concat()
Expand Down Expand Up @@ -97,7 +97,7 @@ impl WebmBuilder {
payload.push(0x80);
payload.extend_from_slice(data);

self.blocks.push(Self::element(&[0xA3], &payload));
self.blocks.push(Self::element(&[0xa3], &payload));

self
}
Expand Down Expand Up @@ -140,15 +140,15 @@ impl WebmBuilder {
let number = u64::try_from(self.tracks.len() + 1).unwrap();

let entry = [
Self::unsigned(&[0xD7], number),
Self::unsigned(&[0x73, 0xC5], number),
Self::unsigned(&[0xd7], number),
Self::unsigned(&[0x73, 0xc5], number),
Self::unsigned(&[0x83], ty),
Self::string(&[0x86], codec_id),
settings.to_vec(),
]
.concat();

self.tracks.push(Self::element(&[0xAE], &entry));
self.tracks.push(Self::element(&[0xae], &entry));

self
}
Expand All @@ -159,10 +159,10 @@ impl WebmBuilder {

pub(crate) fn video_settings(width: u64, height: u64) -> Vec<u8> {
Self::element(
&[0xE0],
&[0xe0],
&[
Self::unsigned(&[0xB0], width),
Self::unsigned(&[0xBA], height),
Self::unsigned(&[0xb0], width),
Self::unsigned(&[0xba], height),
]
.concat(),
)
Expand Down
Loading