Skip to content

Commit b4f22e9

Browse files
committed
OGG: Read appropriate number of header packets
1 parent 53df9b4 commit b4f22e9

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

src/ogg/tag.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -435,18 +435,14 @@ where
435435
_ => err!(UnsupportedTag),
436436
};
437437

438-
let ogg_format = match file_type {
439-
FileType::Opus => OGGFormat::Opus,
440-
FileType::Vorbis => OGGFormat::Vorbis,
441-
FileType::Speex => OGGFormat::Speex,
442-
// FLAC has its own special writing needs :)
443-
FileType::FLAC => {
444-
return crate::flac::write::write_to_inner(file, self);
445-
},
446-
_ => unreachable!("You forgot to add support for FileType::{:?}!", file_type),
447-
};
438+
// FLAC has its own special writing needs :)
439+
if file_type == FileType::FLAC {
440+
return crate::flac::write::write_to_inner(file, self);
441+
}
442+
443+
let (format, header_packet_count) = OGGFormat::from_filetype(file_type);
448444

449-
super::write::write(file, self, ogg_format)
445+
super::write::write(file, self, format, header_packet_count)
450446
}
451447

452448
pub(crate) fn dump_to<W: Write>(&mut self, writer: &mut W) -> Result<()> {

src/ogg/write.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ impl OGGFormat {
3030
OGGFormat::Speex => None,
3131
}
3232
}
33+
34+
pub(super) fn from_filetype(file_type: FileType) -> (Self, isize) {
35+
match file_type {
36+
FileType::Opus => (OGGFormat::Opus, 2),
37+
FileType::Vorbis => (OGGFormat::Vorbis, 3),
38+
FileType::Speex => (OGGFormat::Speex, 2),
39+
_ => unreachable!("You forgot to add support for FileType::{:?}!", file_type),
40+
}
41+
}
3342
}
3443

3544
pub(crate) fn write_to(file: &mut File, tag: &Tag, file_type: FileType) -> Result<()> {
@@ -45,14 +54,9 @@ pub(crate) fn write_to(file: &mut File, tag: &Tag, file_type: FileType) -> Resul
4554
pictures,
4655
};
4756

48-
let format = match file_type {
49-
FileType::Opus => OGGFormat::Opus,
50-
FileType::Vorbis => OGGFormat::Vorbis,
51-
FileType::Speex => OGGFormat::Speex,
52-
_ => unreachable!(),
53-
};
57+
let (format, header_packet_count) = OGGFormat::from_filetype(file_type);
5458

55-
write(file, &mut comments_ref, format)
59+
write(file, &mut comments_ref, format, header_packet_count)
5660
}
5761

5862
pub(crate) fn create_comments(
@@ -85,6 +89,7 @@ pub(super) fn write<'a, II, IP>(
8589
file: &mut File,
8690
tag: &mut VorbisCommentsRef<'a, II, IP>,
8791
format: OGGFormat,
92+
header_packet_count: isize,
8893
) -> Result<()>
8994
where
9095
II: Iterator<Item = (&'a str, &'a str)>,
@@ -99,7 +104,7 @@ where
99104
let stream_serial = first_page_header.stream_serial;
100105

101106
file.seek(SeekFrom::Start(start))?;
102-
let mut packets = Packets::read_count(file, 3)?;
107+
let mut packets = Packets::read_count(file, header_packet_count)?;
103108

104109
let mut remaining_file_content = Vec::new();
105110
file.read_to_end(&mut remaining_file_content)?;

0 commit comments

Comments
 (0)