/// Searches the provided `MediaSourceStream` for metadata or a container format.
Searches the provided `MediaSourceStream` for metadata or a container format.
Searches the provided ` MediaSourceStream ` for metadata or a container format .
pub fn next(&self, mss: &mut MediaSourceStream) -> Result<Instantiate> {
        let mut win = 0u16;
        let init_pos = mss.pos();
        let mut count = 0;
        // Scan the stream byte-by-byte. Shifting each byte through a 2-byte window.
        while let Ok(byte) = mss.read_byte() {
            win = (win << 8) | u16::from(byte);
            count += 1;
            if count % 4096 == 0 {
                info!(
                    "searching for stream marker... {}+{} / {} bytes.",
                    init_pos,
                    count,
                    Probe::PROBE_SEARCH_LIMIT
                );
            }
            // Use the bloom filter to check if the the window may be a prefix of a registered
            // marker.
            if self.filter.may_contain(&win.to_be_bytes()) {
                // Using the 2-byte window, and a further 14 bytes, create a larger 16-byte window.
                let mut context = [0u8; 16];
                context[0..2].copy_from_slice(&win.to_be_bytes()[0..2]);
                mss.read_buf_exact(&mut context[2..])?;
                info!(
                    "found a possible stream marker within {:x?} @ {}+{} bytes.",
                    context,
                    init_pos,
                    count,
                );
                // Search for registered markers in the 16-byte window.
                for registered in &self.registered {
                    for marker in registered.markers {
                        let len = marker.len();
                        // If a match is found, return the instantiate.
                        if context[0..len] == **marker {
                            // Re-align the stream to the start of the marker.
                            mss.rewind(16);
                            // TODO: Implement scoring.
                            info!(
                                "found the stream marker {:x?} @ {}+{} bytes.",
                                &context[0..len],
                                init_pos,
                                count,
                            );
                            return Ok(registered.inst)
                        }
                    }
                }
                // If no registered markers were matched, then the bloom filter returned a false
                // positive. Re-align the stream to the end of the 2-byte window and continue the
                // search.
                mss.rewind(16 - 2);
            }
        }
        // Could not find any marker within the probe limit.
        error!("reached probe limit of {} bytes.", Probe::PROBE_SEARCH_LIMIT);
        unsupported_error("no suitable reader found")
    }
pub fn next ( & self , mss : & mut MediaSourceStream ) -> Result < Instantiate > { let mut win = 0u16 ; let init_pos = mss . pos ( ) ; let mut count = 0 ; // Scan the stream byte-by-byte. Shifting each byte through a 2-byte window. while let Ok ( byte ) = mss . read_byte ( ) { win = ( win << 8 ) | u16 :: from ( byte ) ; count += 1 ; if count % 4096 == 0 { info ! ( " " init_pos count Probe PROBE_SEARCH_LIMIT ) ; } // Use the bloom filter to check if the the window may be a prefix of a registered // marker. if self . filter . may_contain ( & win . to_be_bytes ( ) ) { // Using the 2-byte window, and a further 14 bytes, create a larger 16-byte window. let mut context = [ 0u8 ; 16 ] ; context [ 0 .. 2 ] . copy_from_slice ( & win . to_be_bytes ( ) [ 0 .. 2 ] ) ; mss . read_buf_exact ( & mut context [ 2 .. ] ) ? ; info ! ( " " context init_pos count ) ; // Search for registered markers in the 16-byte window. for registered in & self . registered { for marker in registered . markers { let len = marker . len ( ) ; // If a match is found, return the instantiate. if context [ 0 .. len ] == * * marker { // Re-align the stream to the start of the marker. mss . rewind ( 16 ) ; // TODO: Implement scoring. info ! ( " " context [ 0 len ] init_pos count ) ; return Ok ( registered . inst ) } } } // If no registered markers were matched, then the bloom filter returned a false // positive. Re-align the stream to the end of the 2-byte window and continue the // search. mss . rewind ( 16 - 2 ) ; } } // Could not find any marker within the probe limit. error ! ( " " Probe PROBE_SEARCH_LIMIT ) ; unsupported_error ( " " ) }
Searches the provided `MediaSourceStream` for metadata or a container format.
Searches the provided ` MediaSourceStream ` for metadata or a container format .
&self
mss
&mut MediaSourceStream