11use crate :: config:: ParsingMode ;
2- use crate :: error:: { ErrorKind , LoftyError , Result } ;
3- use crate :: macros :: { err , try_vec } ;
4- use crate :: tag :: { ItemKey , TagType } ;
2+ use crate :: error:: { AudioError , Result } ;
3+ use crate :: text :: utf8_decode ;
4+ use crate :: { err , try_vec } ;
55
66use std:: borrow:: Cow ;
77use std:: io:: { Read , Seek , SeekFrom } ;
88
9- use aud_io:: text:: utf8_decode;
10- use aud_io:: err as io_err;
119use byteorder:: { BigEndian , ReadBytesExt } ;
1210
13- pub ( super ) const FOURCC_LEN : u64 = 4 ;
14- pub ( super ) const IDENTIFIER_LEN : u64 = 4 ;
15- pub ( super ) const ATOM_HEADER_LEN : u64 = FOURCC_LEN + IDENTIFIER_LEN ;
11+ pub const FOURCC_LEN : u64 = 4 ;
12+ pub const IDENTIFIER_LEN : u64 = 4 ;
13+ pub const ATOM_HEADER_LEN : u64 = FOURCC_LEN + IDENTIFIER_LEN ;
1614
1715/// Represents an `MP4` atom identifier
1816#[ derive( Eq , PartialEq , Debug , Clone ) ]
@@ -64,55 +62,12 @@ impl<'a> AtomIdent<'a> {
6462 }
6563}
6664
67- impl < ' a > TryFrom < & ' a ItemKey > for AtomIdent < ' a > {
68- type Error = LoftyError ;
69-
70- fn try_from ( value : & ' a ItemKey ) -> std:: result:: Result < Self , Self :: Error > {
71- if let Some ( mapped_key) = value. map_key ( TagType :: Mp4Ilst ) {
72- if mapped_key. starts_with ( "----" ) {
73- let mut split = mapped_key. split ( ':' ) ;
74-
75- split. next ( ) ;
76-
77- let mean = split. next ( ) ;
78- let name = split. next ( ) ;
79-
80- if let ( Some ( mean) , Some ( name) ) = ( mean, name) {
81- return Ok ( AtomIdent :: Freeform {
82- mean : Cow :: Borrowed ( mean) ,
83- name : Cow :: Borrowed ( name) ,
84- } ) ;
85- }
86- } else {
87- let fourcc = mapped_key. chars ( ) . map ( |c| c as u8 ) . collect :: < Vec < _ > > ( ) ;
88-
89- if let Ok ( fourcc) = TryInto :: < [ u8 ; 4 ] > :: try_into ( fourcc) {
90- return Ok ( AtomIdent :: Fourcc ( fourcc) ) ;
91- }
92- }
93- }
94-
95- io_err ! ( TextDecode (
96- "ItemKey does not map to a freeform or fourcc identifier"
97- ) )
98- }
99- }
100-
101- impl TryFrom < ItemKey > for AtomIdent < ' static > {
102- type Error = LoftyError ;
103-
104- fn try_from ( value : ItemKey ) -> std:: result:: Result < Self , Self :: Error > {
105- let ret: AtomIdent < ' _ > = ( & value) . try_into ( ) ?;
106- Ok ( ret. into_owned ( ) )
107- }
108- }
109-
11065#[ derive( Debug ) ]
111- pub ( crate ) struct AtomInfo {
112- pub ( crate ) start : u64 ,
113- pub ( crate ) len : u64 ,
114- pub ( crate ) extended : bool ,
115- pub ( crate ) ident : AtomIdent < ' static > ,
66+ pub struct AtomInfo {
67+ pub start : u64 ,
68+ pub len : u64 ,
69+ pub extended : bool ,
70+ pub ident : AtomIdent < ' static > ,
11671}
11772
11873// The spec permits any characters to be used in atom identifiers. This doesn't
@@ -125,7 +80,7 @@ fn is_valid_identifier_byte(b: u8) -> bool {
12580}
12681
12782impl AtomInfo {
128- pub ( crate ) fn read < R > (
83+ pub fn read < R > (
12984 data : & mut R ,
13085 mut reader_size : u64 ,
13186 parse_mode : ParsingMode ,
@@ -214,7 +169,7 @@ impl AtomInfo {
214169 } ) )
215170 }
216171
217- pub ( crate ) fn header_size ( & self ) -> u64 {
172+ pub fn header_size ( & self ) -> u64 {
218173 if !self . extended {
219174 return ATOM_HEADER_LEN ;
220175 }
@@ -261,10 +216,10 @@ where
261216
262217 match atom {
263218 Some ( AtomInfo {
264- ident : AtomIdent :: Fourcc ( ref fourcc) ,
265- len,
266- ..
267- } ) if fourcc == name => {
219+ ident : AtomIdent :: Fourcc ( ref fourcc) ,
220+ len,
221+ ..
222+ } ) if fourcc == name => {
268223 if len < 12 {
269224 err ! ( BadAtom ( "Found an incomplete freeform identifier chunk" ) ) ;
270225 }
@@ -284,9 +239,9 @@ where
284239 * reader_size -= len;
285240
286241 utf8_decode ( content) . map_err ( |_| {
287- LoftyError :: new ( ErrorKind :: BadAtom (
242+ AudioError :: BadAtom (
288243 "Found a non UTF-8 string while reading freeform identifier" ,
289- ) )
244+ )
290245 } )
291246 } ,
292247 _ => err ! ( BadAtom (
0 commit comments