@@ -14,6 +14,9 @@ use crate::util::io::{FileLike, Length, Truncate};
14
14
15
15
use std:: io:: { Cursor , Seek , SeekFrom , Write } ;
16
16
17
+ use crate :: mp4:: constants:: {
18
+ BE_SIGNED_INTEGER , BE_UNSIGNED_INTEGER , BMP , JPEG , PNG , RESERVED , UTF16 , UTF8 ,
19
+ } ;
17
20
use byteorder:: { BigEndian , ReadBytesExt , WriteBytesExt } ;
18
21
19
22
// A "full" atom is a traditional length + identifier, followed by a version (1) and flags (3)
@@ -675,12 +678,12 @@ where
675
678
{
676
679
for value in data {
677
680
match value {
678
- AtomData :: UTF8 ( text) => write_data ( 1 , text. as_bytes ( ) , writer) ?,
679
- AtomData :: UTF16 ( text) => write_data ( 2 , text. as_bytes ( ) , writer) ?,
681
+ AtomData :: UTF8 ( text) => write_data ( UTF8 , text. as_bytes ( ) , writer) ?,
682
+ AtomData :: UTF16 ( text) => write_data ( UTF16 , text. as_bytes ( ) , writer) ?,
680
683
AtomData :: Picture ( ref pic) => write_picture ( pic, writer) ?,
681
684
AtomData :: SignedInteger ( int) => write_signed_int ( * int, writer) ?,
682
685
AtomData :: UnsignedInteger ( uint) => write_unsigned_int ( * uint, writer) ?,
683
- AtomData :: Bool ( b) => write_signed_int ( i32 :: from ( * b ) , writer) ?,
686
+ AtomData :: Bool ( b) => write_bool ( * b , writer) ?,
684
687
AtomData :: Unknown { code, ref data } => write_data ( * code, data, writer) ?,
685
688
} ;
686
689
}
@@ -689,7 +692,7 @@ where
689
692
}
690
693
691
694
fn write_signed_int ( int : i32 , writer : & mut AtomWriterCompanion < ' _ > ) -> Result < ( ) > {
692
- write_int ( 21 , int. to_be_bytes ( ) , 4 , writer)
695
+ write_int ( BE_SIGNED_INTEGER , int. to_be_bytes ( ) , 4 , writer)
693
696
}
694
697
695
698
fn bytes_to_occupy_uint ( uint : u32 ) -> usize {
@@ -706,7 +709,12 @@ fn bytes_to_occupy_uint(uint: u32) -> usize {
706
709
707
710
fn write_unsigned_int ( uint : u32 , writer : & mut AtomWriterCompanion < ' _ > ) -> Result < ( ) > {
708
711
let bytes_needed = bytes_to_occupy_uint ( uint) ;
709
- write_int ( 22 , uint. to_be_bytes ( ) , bytes_needed, writer)
712
+ write_int (
713
+ BE_UNSIGNED_INTEGER ,
714
+ uint. to_be_bytes ( ) ,
715
+ bytes_needed,
716
+ writer,
717
+ )
710
718
}
711
719
712
720
fn write_int (
@@ -719,15 +727,19 @@ fn write_int(
719
727
write_data ( flags, & bytes[ 4 - bytes_needed..] , writer)
720
728
}
721
729
730
+ fn write_bool ( b : bool , writer : & mut AtomWriterCompanion < ' _ > ) -> Result < ( ) > {
731
+ write_int ( BE_SIGNED_INTEGER , i32:: from ( b) . to_be_bytes ( ) , 1 , writer)
732
+ }
733
+
722
734
fn write_picture ( picture : & Picture , writer : & mut AtomWriterCompanion < ' _ > ) -> Result < ( ) > {
723
735
match picture. mime_type {
724
736
// GIF is deprecated
725
737
Some ( MimeType :: Gif ) => write_data ( 12 , & picture. data , writer) ,
726
- Some ( MimeType :: Jpeg ) => write_data ( 13 , & picture. data , writer) ,
727
- Some ( MimeType :: Png ) => write_data ( 14 , & picture. data , writer) ,
728
- Some ( MimeType :: Bmp ) => write_data ( 27 , & picture. data , writer) ,
738
+ Some ( MimeType :: Jpeg ) => write_data ( JPEG , & picture. data , writer) ,
739
+ Some ( MimeType :: Png ) => write_data ( PNG , & picture. data , writer) ,
740
+ Some ( MimeType :: Bmp ) => write_data ( BMP , & picture. data , writer) ,
729
741
// We'll assume implicit (0) was the intended type
730
- None => write_data ( 0 , & picture. data , writer) ,
742
+ None => write_data ( RESERVED , & picture. data , writer) ,
731
743
_ => Err ( FileEncodingError :: new (
732
744
FileType :: Mp4 ,
733
745
"Attempted to write an unsupported picture format" ,
@@ -766,7 +778,7 @@ fn write_data(flags: u32, data: &[u8], writer: &mut AtomWriterCompanion<'_>) ->
766
778
767
779
#[ cfg( test) ]
768
780
mod tests {
769
- use crate :: mp4 :: ilst :: write :: bytes_to_occupy_uint;
781
+ use super :: bytes_to_occupy_uint;
770
782
771
783
macro_rules! int_test {
772
784
(
0 commit comments