pub fn parse_vp9_packet(&mut self, mut packet: Vec<u8>) -> Result<Vec<Frame>> {
        if packet.is_empty() {
            return Ok(vec![]);
        }

        // Test for a super frame.
        let last_byte_index = packet.len() - 1;
        let last_byte = packet[last_byte_index];
        if last_byte & 0b1110_0000 == 0b1100_0000 {
            let bytes_per_framesize_minus_1 = (last_byte & 0b11000) >> 3;
            let frames_in_superframe_minus_1 = last_byte & 0b111;
            let bytes_size: usize = (bytes_per_framesize_minus_1 + 1).into();
            let frame_count: usize = (frames_in_superframe_minus_1 + 1).into();
            let index_size = 2 + frame_count * bytes_size;
            let first_byte_index = packet.len() - index_size;
            let first_byte = packet[first_byte_index];

            // Found a super frame.
            if first_byte == last_byte {
                let mut frames = Vec::with_capacity(frame_count);

                let index_start = first_byte_index + 1;
                let entry_size = frame_count * bytes_size;

                let mut entry_data = Vec::with_capacity(entry_size);
                entry_data.extend_from_slice(&packet[index_start..index_start + entry_size]);

                match frame_count {
                    1 => {
                        // Odd, but valid bitstream configuration.
                        let frame_size = self.read_frame_size(&mut entry_data, bytes_size, 0)?;
                        packet.truncate(frame_size);
                        let frame = self.parse_vp9_frame(packet)?;

                        frames.push(frame);
                    }
                    2 => {
                        // Most common case. The first frame produces a frame that is not displayed but
                        // stored as a reference frame. The second frame is mostly empty and references
                        // the previously stored frame.
                        let frame_size = self.read_frame_size(&mut entry_data, bytes_size, 0)?;
                        let mut left_over = packet.split_off(frame_size);
                        let first_frame = self.parse_vp9_frame(packet)?;

                        let frame_size = self.read_frame_size(&mut entry_data, bytes_size, 1)?;
                        left_over.truncate(frame_size);
                        let second_frame = self.parse_vp9_frame(left_over)?;

                        frames.push(first_frame);
                        frames.push(second_frame);
                    }
                    _ => {
                        // Odd, but also a valid bitstream configuration.
                        for frame_index in 0..frame_count {
                            let frame_size =
                                self.read_frame_size(&mut entry_data, bytes_size, frame_index)?;

                            let left_over = packet.split_off(frame_size);
                            let frame = self.parse_vp9_frame(packet)?;
                            frames.push(frame);

                            packet = left_over;
                        }
                    }
                }

                return Ok(frames);
            }
        }

        // Normal frame.
        let frame = self.parse_vp9_frame(packet)?;
        Ok(vec![frame])
    }
/// Parses a VP9 bitstream packet and returns the encoded frames.
///
/// Packets needs to be supplied in the order they are appearing in the bitstream. The caller
/// needs to reset the parser if the bitstream is changed or a seek happened. Not resetting the
/// parser in such cases results in undefined behavior of the decoder.
Parses a VP9 bitstream packet and returns the encoded frames.
Packets needs to be supplied in the order they are appearing in the bitstream. The caller
needs to reset the parser if the bitstream is changed or a seek happened. Not resetting the
parser in such cases results in undefined behavior of the decoder.
Parses a VP9 bitstream packet and returns the encoded frames . Packets needs to be supplied in the order they are appearing in the bitstream . The caller needs to reset the parser if the bitstream is changed or a seek happened . Not resetting the parser in such cases results in undefined behavior of the decoder .
pub fn parse_vp9_packet(&mut self, mut packet: Vec<u8>) -> Result<Vec<Frame>> {
        if packet.is_empty() {
            return Ok(vec![]);
        }
        // Test for a super frame.
        let last_byte_index = packet.len() - 1;
        let last_byte = packet[last_byte_index];
        if last_byte & 0b1110_0000 == 0b1100_0000 {
            let bytes_per_framesize_minus_1 = (last_byte & 0b11000) >> 3;
            let frames_in_superframe_minus_1 = last_byte & 0b111;
            let bytes_size: usize = (bytes_per_framesize_minus_1 + 1).into();
            let frame_count: usize = (frames_in_superframe_minus_1 + 1).into();
            let index_size = 2 + frame_count * bytes_size;
            let first_byte_index = packet.len() - index_size;
            let first_byte = packet[first_byte_index];
            // Found a super frame.
            if first_byte == last_byte {
                let mut frames = Vec::with_capacity(frame_count);
                let index_start = first_byte_index + 1;
                let entry_size = frame_count * bytes_size;
                let mut entry_data = Vec::with_capacity(entry_size);
                entry_data.extend_from_slice(&packet[index_start..index_start + entry_size]);
                match frame_count {
                    1 => {
                        // Odd, but valid bitstream configuration.
                        let frame_size = self.read_frame_size(&mut entry_data, bytes_size, 0)?;
                        packet.truncate(frame_size);
                        let frame = self.parse_vp9_frame(packet)?;
                        frames.push(frame);
                    }
                    2 => {
                        // Most common case. The first frame produces a frame that is not displayed but
                        // stored as a reference frame. The second frame is mostly empty and references
                        // the previously stored frame.
                        let frame_size = self.read_frame_size(&mut entry_data, bytes_size, 0)?;
                        let mut left_over = packet.split_off(frame_size);
                        let first_frame = self.parse_vp9_frame(packet)?;
                        let frame_size = self.read_frame_size(&mut entry_data, bytes_size, 1)?;
                        left_over.truncate(frame_size);
                        let second_frame = self.parse_vp9_frame(left_over)?;
                        frames.push(first_frame);
                        frames.push(second_frame);
                    }
                    _ => {
                        // Odd, but also a valid bitstream configuration.
                        for frame_index in 0..frame_count {
                            let frame_size =
                                self.read_frame_size(&mut entry_data, bytes_size, frame_index)?;
                            let left_over = packet.split_off(frame_size);
                            let frame = self.parse_vp9_frame(packet)?;
                            frames.push(frame);
                            packet = left_over;
                        }
                    }
                }
                return Ok(frames);
            }
        }
        // Normal frame.
        let frame = self.parse_vp9_frame(packet)?;
        Ok(vec![frame])
    }
pub fn parse_vp9_packet ( & mut self , mut packet : Vec < u8 > ) -> Result < Vec < Frame > > { if packet . is_empty ( ) { return Ok ( vec ! [ ] ) ; } // Test for a super frame. let last_byte_index = packet . len ( ) - 1 ; let last_byte = packet [ last_byte_index ] ; if last_byte & 0b1110_0000 == 0b1100_0000 { let bytes_per_framesize_minus_1 = ( last_byte & 0b11000 ) >> 3 ; let frames_in_superframe_minus_1 = last_byte & 0b111 ; let bytes_size : usize = ( bytes_per_framesize_minus_1 + 1 ) . into ( ) ; let frame_count : usize = ( frames_in_superframe_minus_1 + 1 ) . into ( ) ; let index_size = 2 + frame_count * bytes_size ; let first_byte_index = packet . len ( ) - index_size ; let first_byte = packet [ first_byte_index ] ; // Found a super frame. if first_byte == last_byte { let mut frames = Vec :: with_capacity ( frame_count ) ; let index_start = first_byte_index + 1 ; let entry_size = frame_count * bytes_size ; let mut entry_data = Vec :: with_capacity ( entry_size ) ; entry_data . extend_from_slice ( & packet [ index_start .. index_start + entry_size ] ) ; match frame_count { 1 => { // Odd, but valid bitstream configuration. let frame_size = self . read_frame_size ( & mut entry_data , bytes_size , 0 ) ? ; packet . truncate ( frame_size ) ; let frame = self . parse_vp9_frame ( packet ) ? ; frames . push ( frame ) ; } 2 => { // Most common case. The first frame produces a frame that is not displayed but // stored as a reference frame. The second frame is mostly empty and references // the previously stored frame. let frame_size = self . read_frame_size ( & mut entry_data , bytes_size , 0 ) ? ; let mut left_over = packet . split_off ( frame_size ) ; let first_frame = self . parse_vp9_frame ( packet ) ? ; let frame_size = self . read_frame_size ( & mut entry_data , bytes_size , 1 ) ? ; left_over . truncate ( frame_size ) ; let second_frame = self . parse_vp9_frame ( left_over ) ? ; frames . push ( first_frame ) ; frames . push ( second_frame ) ; } _ => { // Odd, but also a valid bitstream configuration. for frame_index in 0 .. frame_count { let frame_size = self . read_frame_size ( & mut entry_data , bytes_size , frame_index ) ? ; let left_over = packet . split_off ( frame_size ) ; let frame = self . parse_vp9_frame ( packet ) ? ; frames . push ( frame ) ; packet = left_over ; } } } return Ok ( frames ) ; } } // Normal frame. let frame = self . parse_vp9_frame ( packet ) ? ; Ok ( vec ! [ frame ] ) }
Parses a VP9 bitstream packet and returns the encoded frames.
Parses a VP9 bitstream packet and returns the encoded frames .
&mut self
packet
Vec<u8>
&mut self
packet
Vec<u8>