6
6
#[ cfg( feature = "fuzz" ) ]
7
7
extern crate afl;
8
8
9
+ #[ macro_use]
10
+ extern crate log;
11
+
9
12
extern crate byteorder;
10
13
extern crate bitreader;
11
14
extern crate num_traits;
@@ -36,25 +39,6 @@ const BUF_SIZE_LIMIT: usize = 1024 * 1024;
36
39
// frame per table entry in 30 fps.
37
40
const TABLE_SIZE_LIMIT : u32 = 30 * 60 * 60 * 24 * 7 ;
38
41
39
- static DEBUG_MODE : std:: sync:: atomic:: AtomicBool = std:: sync:: atomic:: ATOMIC_BOOL_INIT ;
40
-
41
- pub fn set_debug_mode ( mode : bool ) {
42
- DEBUG_MODE . store ( mode, std:: sync:: atomic:: Ordering :: SeqCst ) ;
43
- }
44
-
45
- #[ inline( always) ]
46
- fn get_debug_mode ( ) -> bool {
47
- DEBUG_MODE . load ( std:: sync:: atomic:: Ordering :: Relaxed )
48
- }
49
-
50
- macro_rules! log {
51
- ( $( $args: tt) * ) => (
52
- if get_debug_mode( ) {
53
- println!( $( $args ) * ) ;
54
- }
55
- )
56
- }
57
-
58
42
// TODO: vec_push() and vec_reserve() needs to be replaced when Rust supports
59
43
// fallible memory allocation in raw_vec.
60
44
#[ allow( unreachable_code) ]
@@ -582,7 +566,7 @@ impl<'a, T: Read> Drop for BMFFBox<'a, T> {
582
566
fn drop ( & mut self ) {
583
567
if self . content . limit ( ) > 0 {
584
568
let name: FourCC = From :: from ( self . head . name ) ;
585
- log ! ( "Dropping {} bytes in '{}'" , self . content. limit( ) , name) ;
569
+ debug ! ( "Dropping {} bytes in '{}'" , self . content. limit( ) , name) ;
586
570
}
587
571
}
588
572
}
@@ -636,7 +620,7 @@ fn skip_box_content<T: Read>(src: &mut BMFFBox<T>) -> Result<()> {
636
620
// Skip the contents of unknown chunks.
637
621
let to_skip = {
638
622
let header = src. get_header ( ) ;
639
- log ! ( "{:?} (skipped)" , header) ;
623
+ debug ! ( "{:?} (skipped)" , header) ;
640
624
( header. size - header. offset ) as usize
641
625
} ;
642
626
assert_eq ! ( to_skip, src. bytes_left( ) ) ;
@@ -648,7 +632,7 @@ fn skip_box_remain<T: Read>(src: &mut BMFFBox<T>) -> Result<()> {
648
632
let remain = {
649
633
let header = src. get_header ( ) ;
650
634
let len = src. bytes_left ( ) ;
651
- log ! ( "remain {} (skipped) in {:?}" , len, header) ;
635
+ debug ! ( "remain {} (skipped) in {:?}" , len, header) ;
652
636
len
653
637
} ;
654
638
skip ( src, remain)
@@ -657,7 +641,7 @@ fn skip_box_remain<T: Read>(src: &mut BMFFBox<T>) -> Result<()> {
657
641
macro_rules! check_parser_state {
658
642
( $src: expr ) => {
659
643
if $src. limit( ) > 0 {
660
- log !( "bad parser state: {} content bytes left" , $src. limit( ) ) ;
644
+ debug !( "bad parser state: {} content bytes left" , $src. limit( ) ) ;
661
645
return Err ( Error :: InvalidData ( "unread box content or bad parser sync" ) ) ;
662
646
}
663
647
}
@@ -693,7 +677,7 @@ pub fn read_mp4<T: Read>(f: &mut T, context: &mut MediaContext) -> Result<()> {
693
677
BoxType :: FileTypeBox => {
694
678
let ftyp = read_ftyp ( & mut b) ?;
695
679
found_ftyp = true ;
696
- log ! ( "{:?}" , ftyp) ;
680
+ debug ! ( "{:?}" , ftyp) ;
697
681
}
698
682
BoxType :: MovieBox => {
699
683
read_moov ( & mut b, context) ?;
@@ -703,7 +687,7 @@ pub fn read_mp4<T: Read>(f: &mut T, context: &mut MediaContext) -> Result<()> {
703
687
} ;
704
688
check_parser_state ! ( b. content) ;
705
689
if found_moov {
706
- log ! ( "found moov {}, could stop pure 'moov' parser now" , if found_ftyp {
690
+ debug ! ( "found moov {}, could stop pure 'moov' parser now" , if found_ftyp {
707
691
"and ftyp"
708
692
} else {
709
693
"but no ftyp"
@@ -737,7 +721,7 @@ fn read_moov<T: Read>(f: &mut BMFFBox<T>, context: &mut MediaContext) -> Result<
737
721
BoxType :: MovieHeaderBox => {
738
722
let ( mvhd, timescale) = parse_mvhd ( & mut b) ?;
739
723
context. timescale = timescale;
740
- log ! ( "{:?}" , mvhd) ;
724
+ debug ! ( "{:?}" , mvhd) ;
741
725
}
742
726
BoxType :: TrackBox => {
743
727
let mut track = Track :: new ( context. tracks . len ( ) ) ;
@@ -746,12 +730,12 @@ fn read_moov<T: Read>(f: &mut BMFFBox<T>, context: &mut MediaContext) -> Result<
746
730
}
747
731
BoxType :: MovieExtendsBox => {
748
732
let mvex = read_mvex ( & mut b) ?;
749
- log ! ( "{:?}" , mvex) ;
733
+ debug ! ( "{:?}" , mvex) ;
750
734
context. mvex = Some ( mvex) ;
751
735
}
752
736
BoxType :: ProtectionSystemSpecificHeaderBox => {
753
737
let pssh = read_pssh ( & mut b) ?;
754
- log ! ( "{:?}" , pssh) ;
738
+ debug ! ( "{:?}" , pssh) ;
755
739
vec_push ( & mut context. psshs , pssh) ?;
756
740
}
757
741
_ => skip_box_content ( & mut b) ?,
@@ -834,7 +818,7 @@ fn read_trak<T: Read>(f: &mut BMFFBox<T>, track: &mut Track) -> Result<()> {
834
818
let tkhd = read_tkhd ( & mut b) ?;
835
819
track. track_id = Some ( tkhd. track_id ) ;
836
820
track. tkhd = Some ( tkhd. clone ( ) ) ;
837
- log ! ( "{:?}" , tkhd) ;
821
+ debug ! ( "{:?}" , tkhd) ;
838
822
}
839
823
BoxType :: EditBox => read_edts ( & mut b, track) ?,
840
824
BoxType :: MediaBox => read_mdia ( & mut b, track) ?,
@@ -869,7 +853,7 @@ fn read_edts<T: Read>(f: &mut BMFFBox<T>, track: &mut Track) -> Result<()> {
869
853
}
870
854
track. media_time = Some ( TrackScaledTime :: < u64 > ( elst. edits [ idx] . media_time as u64 ,
871
855
track. id ) ) ;
872
- log ! ( "{:?}" , elst) ;
856
+ debug ! ( "{:?}" , elst) ;
873
857
}
874
858
_ => skip_box_content ( & mut b) ?,
875
859
} ;
@@ -899,7 +883,7 @@ fn read_mdia<T: Read>(f: &mut BMFFBox<T>, track: &mut Track) -> Result<()> {
899
883
let ( mdhd, duration, timescale) = parse_mdhd ( & mut b, track) ?;
900
884
track. duration = duration;
901
885
track. timescale = timescale;
902
- log ! ( "{:?}" , mdhd) ;
886
+ debug ! ( "{:?}" , mdhd) ;
903
887
}
904
888
BoxType :: HandlerBox => {
905
889
let hdlr = read_hdlr ( & mut b) ?;
@@ -909,7 +893,7 @@ fn read_mdia<T: Read>(f: &mut BMFFBox<T>, track: &mut Track) -> Result<()> {
909
893
"soun" => track. track_type = TrackType :: Audio ,
910
894
_ => ( ) ,
911
895
}
912
- log ! ( "{:?}" , hdlr) ;
896
+ debug ! ( "{:?}" , hdlr) ;
913
897
}
914
898
BoxType :: MediaInformationBox => read_minf ( & mut b, track) ?,
915
899
_ => skip_box_content ( & mut b) ?,
@@ -937,41 +921,41 @@ fn read_stbl<T: Read>(f: &mut BMFFBox<T>, track: &mut Track) -> Result<()> {
937
921
match b. head . name {
938
922
BoxType :: SampleDescriptionBox => {
939
923
let stsd = read_stsd ( & mut b, track) ?;
940
- log ! ( "{:?}" , stsd) ;
924
+ debug ! ( "{:?}" , stsd) ;
941
925
}
942
926
BoxType :: TimeToSampleBox => {
943
927
let stts = read_stts ( & mut b) ?;
944
- log ! ( "{:?}" , stts) ;
928
+ debug ! ( "{:?}" , stts) ;
945
929
track. stts = Some ( stts) ;
946
930
}
947
931
BoxType :: SampleToChunkBox => {
948
932
let stsc = read_stsc ( & mut b) ?;
949
- log ! ( "{:?}" , stsc) ;
933
+ debug ! ( "{:?}" , stsc) ;
950
934
track. stsc = Some ( stsc) ;
951
935
}
952
936
BoxType :: SampleSizeBox => {
953
937
let stsz = read_stsz ( & mut b) ?;
954
- log ! ( "{:?}" , stsz) ;
938
+ debug ! ( "{:?}" , stsz) ;
955
939
track. stsz = Some ( stsz) ;
956
940
}
957
941
BoxType :: ChunkOffsetBox => {
958
942
let stco = read_stco ( & mut b) ?;
959
- log ! ( "{:?}" , stco) ;
943
+ debug ! ( "{:?}" , stco) ;
960
944
track. stco = Some ( stco) ;
961
945
}
962
946
BoxType :: ChunkLargeOffsetBox => {
963
947
let co64 = read_co64 ( & mut b) ?;
964
- log ! ( "{:?}" , co64) ;
948
+ debug ! ( "{:?}" , co64) ;
965
949
track. stco = Some ( co64) ;
966
950
}
967
951
BoxType :: SyncSampleBox => {
968
952
let stss = read_stss ( & mut b) ?;
969
- log ! ( "{:?}" , stss) ;
953
+ debug ! ( "{:?}" , stss) ;
970
954
track. stss = Some ( stss) ;
971
955
}
972
956
BoxType :: CompositionOffsetBox => {
973
957
let ctts = read_ctts ( & mut b) ?;
974
- log ! ( "{:?}" , ctts) ;
958
+ debug ! ( "{:?}" , ctts) ;
975
959
track. ctts = Some ( ctts) ;
976
960
}
977
961
_ => skip_box_content ( & mut b) ?,
@@ -1418,7 +1402,7 @@ fn find_descriptor(data: &[u8], esds: &mut ES_Descriptor) -> Result<()> {
1418
1402
read_ds_descriptor ( descriptor, esds) ?;
1419
1403
} ,
1420
1404
_ => {
1421
- log ! ( "Unsupported descriptor, tag {}" , tag) ;
1405
+ debug ! ( "Unsupported descriptor, tag {}" , tag) ;
1422
1406
} ,
1423
1407
}
1424
1408
@@ -1471,7 +1455,7 @@ fn read_ds_descriptor(data: &[u8], esds: &mut ES_Descriptor) -> Result<()> {
1471
1455
// When channel_counts is 0, we need to parse the program_config_element
1472
1456
// to calculate the channel counts.
1473
1457
if channel_counts == 0 {
1474
- log ! ( "Parsing program_config_element for channel counts" ) ;
1458
+ debug ! ( "Parsing program_config_element for channel counts" ) ;
1475
1459
1476
1460
bit_reader. skip ( 4 ) ?; // element_instance_tag
1477
1461
bit_reader. skip ( 2 ) ?; // object_type
@@ -1750,7 +1734,7 @@ fn read_video_sample_entry<T: Read>(src: &mut BMFFBox<T>) -> Result<(CodecType,
1750
1734
BoxType :: VP9SampleEntry => CodecType :: VP9 ,
1751
1735
BoxType :: ProtectedVisualSampleEntry => CodecType :: EncryptedVideo ,
1752
1736
_ => {
1753
- log ! ( "Unsupported video codec, box {:?} found" , name) ;
1737
+ debug ! ( "Unsupported video codec, box {:?} found" , name) ;
1754
1738
CodecType :: Unknown
1755
1739
}
1756
1740
} ;
@@ -1784,7 +1768,7 @@ fn read_video_sample_entry<T: Read>(src: &mut BMFFBox<T>) -> Result<(CodecType,
1784
1768
}
1785
1769
let avcc_size = b. head . size - b. head . offset ;
1786
1770
let avcc = read_buf ( & mut b. content , avcc_size as usize ) ?;
1787
- log ! ( "{:?} (avcc)" , avcc) ;
1771
+ debug ! ( "{:?} (avcc)" , avcc) ;
1788
1772
// TODO(kinetik): Parse avcC box? For now we just stash the data.
1789
1773
codec_specific = Some ( VideoCodecSpecific :: AVCConfig ( avcc) ) ;
1790
1774
}
@@ -1812,11 +1796,11 @@ fn read_video_sample_entry<T: Read>(src: &mut BMFFBox<T>) -> Result<(CodecType,
1812
1796
return Err ( Error :: InvalidData ( "malformed video sample entry" ) ) ;
1813
1797
}
1814
1798
let sinf = read_sinf ( & mut b) ?;
1815
- log ! ( "{:?} (sinf)" , sinf) ;
1799
+ debug ! ( "{:?} (sinf)" , sinf) ;
1816
1800
vec_push ( & mut protection_info, sinf) ?;
1817
1801
}
1818
1802
_ => {
1819
- log ! ( "Unsupported video codec, box {:?} found" , b. head. name) ;
1803
+ debug ! ( "Unsupported video codec, box {:?} found" , b. head. name) ;
1820
1804
skip_box_content ( & mut b) ?;
1821
1805
}
1822
1806
}
@@ -1950,12 +1934,12 @@ fn read_audio_sample_entry<T: Read>(src: &mut BMFFBox<T>) -> Result<(CodecType,
1950
1934
return Err ( Error :: InvalidData ( "malformed audio sample entry" ) ) ;
1951
1935
}
1952
1936
let sinf = read_sinf ( & mut b) ?;
1953
- log ! ( "{:?} (sinf)" , sinf) ;
1937
+ debug ! ( "{:?} (sinf)" , sinf) ;
1954
1938
codec_type = CodecType :: EncryptedAudio ;
1955
1939
vec_push ( & mut protection_info, sinf) ?;
1956
1940
}
1957
1941
_ => {
1958
- log ! ( "Unsupported audio codec, box {:?} found" , b. head. name) ;
1942
+ debug ! ( "Unsupported audio codec, box {:?} found" , b. head. name) ;
1959
1943
skip_box_content ( & mut b) ?;
1960
1944
}
1961
1945
}
@@ -2008,7 +1992,7 @@ fn read_stsd<T: Read>(src: &mut BMFFBox<T>, track: &mut Track) -> Result<SampleD
2008
1992
if track. data . is_none ( ) {
2009
1993
track. data = Some ( description. clone ( ) ) ;
2010
1994
} else {
2011
- log ! ( "** don't know how to handle multiple descriptions **" ) ;
1995
+ debug ! ( "** don't know how to handle multiple descriptions **" ) ;
2012
1996
}
2013
1997
vec_push ( & mut descriptions, description) ?;
2014
1998
check_parser_state ! ( b. content) ;
0 commit comments