pub fn read_dec_packet_generic<S :Samples>(&mut self) -> Result<Option<S>, VorbisError> {
		let pck = if let Some(next_packet) = self.next_packet.take() {
			next_packet
		} else {
			try!(read_expected_packet_with_stream_serial(&mut self.rdr, self.stream_serial))
		};
		let mut decoded_pck :S = try!(read_audio_packet_generic(
				&self.ident_hdr, &self.setup_hdr, &pck.data, &mut self.pwr));

		// TODO the following comment is wrong
		// TODO If there was only two audio packets in a logical stream,
		// and the absgp for the second one is less than the number of samples retrieved from them,
		// then the current code truncate the beginning, not the ending.
		// But is it the correct way to do so?
		// I couldn't found any information about that in the spec.
		// Also this means that, if we want to indicate a positive initial absgp,
		// then we cannot truncate the trailing samepls,
		// thus cannot represent an audio whose number of samples are less than
		// short_block_length / 2.
		// Or can we?

		// TODO maybe we should remove the following comment
			// If this is the first packet in the logical stream,
			// we need to truncate the beginning so that its ending matches the absgp of the current page.

		// The leading samples are skipped after parsing the second audio packet for a logical stream,
		// or after seeking.
		let skip_count = self.skip_count.min(decoded_pck.num_samples() as u64);
		self.skip_count -= skip_count;
		decoded_pck.truncate_begin(skip_count as usize);

		if pck.last_in_stream() {
			if self.skip_count == 0 {
				// If this is the last packet in the logical bitstream,
				// we need to truncate it so that its ending matches the absgp of the current page.
				// This is what the spec mandates and also the behaviour of libvorbis.
				let truncate_size = (self.cur_absgp + decoded_pck.num_samples() as u64)
					.saturating_sub(pck.absgp_page());
				decoded_pck.truncate(truncate_size as usize);
			}
			// If skip count is non-zero, then it means that a seek beyond

			self.state = ReaderState::Finished;
		}

		self.cur_absgp += decoded_pck.num_samples() as u64;
		if pck.last_in_page() {
			if self.cur_absgp != pck.absgp_page() {
				// Should we do something else?
				// At least, it is not a good idea to panic, since the input file is subject to corruption.
				eprintln!("cur_absgp does not match.  Calculated: {}, provided: {}", pck.absgp_page(), self.cur_absgp);
				self.cur_absgp = pck.absgp_page();
			}
		}

		return Ok(Some(decoded_pck));
	}
/// Reads and decompresses an audio packet from the stream (generic).
///
/// On read errors, it returns Err(e) with the error.
///
/// On success, it either returns None, when the end of the
/// stream has been reached, or Some(packet_data),
/// with the data of the decompressed packet.
Reads and decompresses an audio packet from the stream (generic).
On read errors, it returns Err(e) with the error.

On success, it either returns None, when the end of the
stream has been reached, or Some(packet_data),
with the data of the decompressed packet.
Reads and decompresses an audio packet from the stream ( generic ) . On read errors it returns Err ( e ) with the error . On success it either returns None when the end of the stream has been reached or Some ( packet_data ) with the data of the decompressed packet .
pub fn read_dec_packet_generic<S :Samples>(&mut self) -> Result<Option<S>, VorbisError> {
		let pck = if let Some(next_packet) = self.next_packet.take() {
			next_packet
		} else {
			try!(read_expected_packet_with_stream_serial(&mut self.rdr, self.stream_serial))
		};
		let mut decoded_pck :S = try!(read_audio_packet_generic(
				&self.ident_hdr, &self.setup_hdr, &pck.data, &mut self.pwr));
		// TODO the following comment is wrong
		// TODO If there was only two audio packets in a logical stream,
		// and the absgp for the second one is less than the number of samples retrieved from them,
		// then the current code truncate the beginning, not the ending.
		// But is it the correct way to do so?
		// I couldn't found any information about that in the spec.
		// Also this means that, if we want to indicate a positive initial absgp,
		// then we cannot truncate the trailing samepls,
		// thus cannot represent an audio whose number of samples are less than
		// short_block_length / 2.
		// Or can we?
		// TODO maybe we should remove the following comment
			// If this is the first packet in the logical stream,
			// we need to truncate the beginning so that its ending matches the absgp of the current page.
		// The leading samples are skipped after parsing the second audio packet for a logical stream,
		// or after seeking.
		let skip_count = self.skip_count.min(decoded_pck.num_samples() as u64);
		self.skip_count -= skip_count;
		decoded_pck.truncate_begin(skip_count as usize);
		if pck.last_in_stream() {
			if self.skip_count == 0 {
				// If this is the last packet in the logical bitstream,
				// we need to truncate it so that its ending matches the absgp of the current page.
				// This is what the spec mandates and also the behaviour of libvorbis.
				let truncate_size = (self.cur_absgp + decoded_pck.num_samples() as u64)
					.saturating_sub(pck.absgp_page());
				decoded_pck.truncate(truncate_size as usize);
			}
			// If skip count is non-zero, then it means that a seek beyond
			self.state = ReaderState::Finished;
		}
		self.cur_absgp += decoded_pck.num_samples() as u64;
		if pck.last_in_page() {
			if self.cur_absgp != pck.absgp_page() {
				// Should we do something else?
				// At least, it is not a good idea to panic, since the input file is subject to corruption.
				eprintln!("cur_absgp does not match.  Calculated: {}, provided: {}", pck.absgp_page(), self.cur_absgp);
				self.cur_absgp = pck.absgp_page();
			}
		}
		return Ok(Some(decoded_pck));
	}
pub fn read_dec_packet_generic < S : Samples > ( & mut self ) -> Result < Option < S > , VorbisError > { let pck = if let Some ( next_packet ) = self . next_packet . take ( ) { next_packet } else { try ! ( read_expected_packet_with_stream_serial ( mut self rdr self stream_serial ) ) } ; let mut decoded_pck : S = try ! ( read_audio_packet_generic ( self ident_hdr self setup_hdr pck data mut self pwr ) ) ; // TODO the following comment is wrong // TODO If there was only two audio packets in a logical stream, // and the absgp for the second one is less than the number of samples retrieved from them, // then the current code truncate the beginning, not the ending. // But is it the correct way to do so? // I couldn't found any information about that in the spec. // Also this means that, if we want to indicate a positive initial absgp, // then we cannot truncate the trailing samepls, // thus cannot represent an audio whose number of samples are less than // short_block_length / 2. // Or can we? // TODO maybe we should remove the following comment // If this is the first packet in the logical stream, // we need to truncate the beginning so that its ending matches the absgp of the current page. // The leading samples are skipped after parsing the second audio packet for a logical stream, // or after seeking. let skip_count = self . skip_count . min ( decoded_pck . num_samples ( ) as u64 ) ; self . skip_count -= skip_count ; decoded_pck . truncate_begin ( skip_count as usize ) ; if pck . last_in_stream ( ) { if self . skip_count == 0 { // If this is the last packet in the logical bitstream, // we need to truncate it so that its ending matches the absgp of the current page. // This is what the spec mandates and also the behaviour of libvorbis. let truncate_size = ( self . cur_absgp + decoded_pck . num_samples ( ) as u64 ) . saturating_sub ( pck . absgp_page ( ) ) ; decoded_pck . truncate ( truncate_size as usize ) ; } // If skip count is non-zero, then it means that a seek beyond self . state = ReaderState :: Finished ; } self . cur_absgp += decoded_pck . num_samples ( ) as u64 ; if pck . last_in_page ( ) { if self . cur_absgp != pck . absgp_page ( ) { // Should we do something else? // At least, it is not a good idea to panic, since the input file is subject to corruption. eprintln ! ( " " pck absgp_page ( ) self cur_absgp ) ; self . cur_absgp = pck . absgp_page ( ) ; } } return Ok ( Some ( decoded_pck ) ) ; }
Reads and decompresses an audio packet from the stream (generic).
Reads and decompresses an audio packet from the stream ( generic ) .
&mut self
&mut self