ogg/
lib.rs

1// Ogg decoder and encoder written in Rust
2//
3// Copyright (c) 2016 est31 <MTest31@outlook.com>
4// and contributors. All rights reserved.
5// Redistribution or use only under the terms
6// specified in the LICENSE file attached to this
7// source distribution.
8
9#![forbid(unsafe_code)]
10
11/*!
12Ogg container decoder and encoder
13
14The most interesting structures for in this
15mod are `PacketReader` and `PacketWriter`.
16*/
17
18extern crate byteorder;
19#[cfg(feature = "async")]
20extern crate tokio_io;
21#[cfg(feature = "async")]
22#[macro_use]
23extern crate futures;
24#[cfg(feature = "async")]
25extern crate bytes;
26
27#[cfg(test)]
28mod test;
29
30macro_rules! tri {
31	($e:expr) => {
32		match $e {
33			Ok(val) => val,
34			Err(err) => return Err(err.into()),
35		}
36	};
37}
38
39mod crc;
40pub mod reading;
41pub mod writing;
42
43pub use writing::{PacketWriter, PacketWriteEndInfo};
44pub use reading::{PacketReader, OggReadError};
45
46/**
47Ogg packet representation.
48
49For the Ogg format, packets are the logically smallest subdivision it handles.
50
51Every packet belongs to a *logical* bitstream. The *logical* bitstreams then form a *physical* bitstream, with the data combined in multiple different ways.
52
53Every logical bitstream is identified by the serial number its pages have stored. The Packet struct contains a field for that number as well, so that one can find out which logical bitstream the Packet belongs to.
54*/
55pub struct Packet {
56	/// The data the `Packet` contains
57	pub data :Vec<u8>,
58	/// `true` iff this packet is the first one in the page.
59	first_packet_pg :bool,
60	/// `true` iff this packet is the first one in the logical bitstream.
61	first_packet_stream :bool,
62	/// `true` iff this packet is the last one in the page.
63	last_packet_pg :bool,
64	/// `true` iff this packet is the last one in the logical bitstream
65	last_packet_stream :bool,
66	/// Absolute granule position of the last page the packet was in.
67	/// The meaning of the absolute granule position is defined by the codec.
68	absgp_page :u64,
69	/// Serial number. Uniquely identifying the logical bitstream.
70	stream_serial :u32,
71	/*/// Packet counter
72	/// Why u64? There are MAX_U32 pages, and every page has up to 128 packets. u32 wouldn't be sufficient here...
73	pub sequence_num :u64,*/ // TODO perhaps add this later on...
74}
75
76impl Packet {
77	/// Returns whether the packet is the first one starting in the page
78	pub fn first_in_page(&self) -> bool {
79		self.first_packet_pg
80	}
81	/// Returns whether the packet is the first one of the entire stream
82	pub fn first_in_stream(&self) -> bool {
83		self.first_packet_stream
84	}
85	/// Returns whether the packet is the last one starting in the page
86	pub fn last_in_page(&self) -> bool {
87		self.last_packet_pg
88	}
89	/// Returns whether the packet is the last one of the entire stream
90	pub fn last_in_stream(&self) -> bool {
91		self.last_packet_stream
92	}
93	/// Returns the absolute granule position of the page the packet ended in.
94	///
95	/// The meaning of the absolute granule position is defined by the codec.
96	pub fn absgp_page(&self) -> u64 {
97		self.absgp_page
98	}
99	/// Returns the serial number that uniquely identifies the logical bitstream.
100	pub fn stream_serial(&self) -> u32 {
101		self.stream_serial
102	}
103}