aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKostya Shishkov <kostya.shishkov@gmail.com>2017-05-20 15:35:48 +0200
committerKostya Shishkov <kostya.shishkov@gmail.com>2017-05-20 15:35:48 +0200
commit48c88fde06894a7692eb6350cbef12aa85d923f1 (patch)
tree65c998e77efa56fc170e5472b429e8ab26631b24 /src
parent2a4130ba5dc9b9b8c34222997a0298a372578987 (diff)
downloadnihav-48c88fde06894a7692eb6350cbef12aa85d923f1.tar.gz
move NAStream/NAPacket definitions into module frame
Diffstat (limited to 'src')
-rw-r--r--src/codecs/mod.rs1
-rw-r--r--src/demuxers/mod.rs113
-rw-r--r--src/frame.rs110
3 files changed, 108 insertions, 116 deletions
diff --git a/src/codecs/mod.rs b/src/codecs/mod.rs
index ddb98e4..7edcf9e 100644
--- a/src/codecs/mod.rs
+++ b/src/codecs/mod.rs
@@ -3,7 +3,6 @@ pub mod indeo2;
use std::rc::Rc;
use frame::*;
-use demuxers::*;
use io::byteio::ByteIOError;
use io::bitreader::BitReaderError;
use io::codebook::CodebookError;
diff --git a/src/demuxers/mod.rs b/src/demuxers/mod.rs
index c6096c7..d4d70a2 100644
--- a/src/demuxers/mod.rs
+++ b/src/demuxers/mod.rs
@@ -3,107 +3,10 @@ pub mod gdv;
#[cfg(feature="demuxer_avi")]
pub mod avi;
-use std::fmt;
use std::rc::Rc;
use frame::*;
-use std::collections::HashMap;
use io::byteio::*;
-/// Possible stream types.
-#[derive(Debug,Clone,Copy)]
-#[allow(dead_code)]
-pub enum StreamType {
- /// video stream
- Video,
- /// audio stream
- Audio,
- /// subtitles
- Subtitles,
- /// any data stream (or might be an unrecognized audio/video stream)
- Data,
- /// nonexistent stream
- None,
-}
-
-impl fmt::Display for StreamType {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- match *self {
- StreamType::Video => write!(f, "Video"),
- StreamType::Audio => write!(f, "Audio"),
- StreamType::Subtitles => write!(f, "Subtitles"),
- StreamType::Data => write!(f, "Data"),
- StreamType::None => write!(f, "-"),
- }
- }
-}
-
-
-#[allow(dead_code)]
-#[derive(Clone)]
-pub struct NAStream {
- media_type: StreamType,
- id: u32,
- num: usize,
- info: Rc<NACodecInfo>,
-}
-
-impl NAStream {
- pub fn new(mt: StreamType, id: u32, info: NACodecInfo) -> Self {
- NAStream { media_type: mt, id: id, num: 0, info: Rc::new(info) }
- }
- pub fn get_id(&self) -> u32 { self.id }
- pub fn get_num(&self) -> usize { self.num }
- pub fn set_num(&mut self, num: usize) { self.num = num; }
- pub fn get_info(&self) -> Rc<NACodecInfo> { self.info.clone() }
-}
-
-impl fmt::Display for NAStream {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write!(f, "({}#{} - {})", self.media_type, self.id, self.info.get_properties())
- }
-}
-
-#[allow(dead_code)]
-pub struct NAPacket {
- stream: Rc<NAStream>,
- pts: Option<u64>,
- dts: Option<u64>,
- duration: Option<u64>,
- buffer: Rc<Vec<u8>>,
- keyframe: bool,
-// options: HashMap<String, NAValue<'a>>,
-}
-
-impl NAPacket {
- pub fn new(str: Rc<NAStream>, pts: Option<u64>, dts: Option<u64>, dur: Option<u64>, kf: bool, vec: Vec<u8>) -> Self {
-// let mut vec: Vec<u8> = Vec::new();
-// vec.resize(size, 0);
- NAPacket { stream: str, pts: pts, dts: dts, duration: dur, keyframe: kf, buffer: Rc::new(vec) }
- }
- pub fn get_stream(&self) -> Rc<NAStream> { self.stream.clone() }
- pub fn get_pts(&self) -> Option<u64> { self.pts }
- pub fn get_dts(&self) -> Option<u64> { self.dts }
- pub fn get_duration(&self) -> Option<u64> { self.duration }
- pub fn is_keyframe(&self) -> bool { self.keyframe }
- pub fn get_buffer(&self) -> Rc<Vec<u8>> { self.buffer.clone() }
-}
-
-impl Drop for NAPacket {
- fn drop(&mut self) {}
-}
-
-impl fmt::Display for NAPacket {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- let mut foo = format!("[pkt for {} size {}", self.stream, self.buffer.len());
- if let Some(pts) = self.pts { foo = format!("{} pts {}", foo, pts); }
- if let Some(dts) = self.dts { foo = format!("{} dts {}", foo, dts); }
- if let Some(dur) = self.duration { foo = format!("{} duration {}", foo, dur); }
- if self.keyframe { foo = format!("{} kf", foo); }
- foo = foo + "]";
- write!(f, "{}", foo)
- }
-}
-
#[derive(Debug)]
#[allow(dead_code)]
pub enum DemuxerError {
@@ -185,22 +88,6 @@ impl From<ByteIOError> for DemuxerError {
fn from(_: ByteIOError) -> Self { DemuxerError::IOError }
}
-pub trait FrameFromPacket {
- fn new_from_pkt(pkt: &NAPacket, info: Rc<NACodecInfo>) -> NAFrame;
- fn fill_timestamps(&mut self, pkt: &NAPacket);
-}
-
-impl FrameFromPacket for NAFrame {
- fn new_from_pkt(pkt: &NAPacket, info: Rc<NACodecInfo>) -> NAFrame {
- NAFrame::new(pkt.pts, pkt.dts, pkt.duration, info, HashMap::new())
- }
- fn fill_timestamps(&mut self, pkt: &NAPacket) {
- self.set_pts(pkt.pts);
- self.set_dts(pkt.dts);
- self.set_duration(pkt.duration);
- }
-}
-
///The structure used to create demuxers.
pub trait DemuxerCreator {
/// Create new demuxer instance that will use `ByteReader` source as an input.
diff --git a/src/frame.rs b/src/frame.rs
index 993d125..449512c 100644
--- a/src/frame.rs
+++ b/src/frame.rs
@@ -259,7 +259,113 @@ impl NAFrame {
}
}
+/// Possible stream types.
+#[derive(Debug,Clone,Copy)]
#[allow(dead_code)]
-pub struct NACodecContext<'a> {
- info: &'a NACodecInfo,
+pub enum StreamType {
+ /// video stream
+ Video,
+ /// audio stream
+ Audio,
+ /// subtitles
+ Subtitles,
+ /// any data stream (or might be an unrecognized audio/video stream)
+ Data,
+ /// nonexistent stream
+ None,
+}
+
+impl fmt::Display for StreamType {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ match *self {
+ StreamType::Video => write!(f, "Video"),
+ StreamType::Audio => write!(f, "Audio"),
+ StreamType::Subtitles => write!(f, "Subtitles"),
+ StreamType::Data => write!(f, "Data"),
+ StreamType::None => write!(f, "-"),
+ }
+ }
+}
+
+#[allow(dead_code)]
+#[derive(Clone)]
+pub struct NAStream {
+ media_type: StreamType,
+ id: u32,
+ num: usize,
+ info: Rc<NACodecInfo>,
}
+
+impl NAStream {
+ pub fn new(mt: StreamType, id: u32, info: NACodecInfo) -> Self {
+ NAStream { media_type: mt, id: id, num: 0, info: Rc::new(info) }
+ }
+ pub fn get_id(&self) -> u32 { self.id }
+ pub fn get_num(&self) -> usize { self.num }
+ pub fn set_num(&mut self, num: usize) { self.num = num; }
+ pub fn get_info(&self) -> Rc<NACodecInfo> { self.info.clone() }
+}
+
+impl fmt::Display for NAStream {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ write!(f, "({}#{} - {})", self.media_type, self.id, self.info.get_properties())
+ }
+}
+
+#[allow(dead_code)]
+pub struct NAPacket {
+ stream: Rc<NAStream>,
+ pts: Option<u64>,
+ dts: Option<u64>,
+ duration: Option<u64>,
+ buffer: Rc<Vec<u8>>,
+ keyframe: bool,
+// options: HashMap<String, NAValue<'a>>,
+}
+
+impl NAPacket {
+ pub fn new(str: Rc<NAStream>, pts: Option<u64>, dts: Option<u64>, dur: Option<u64>, kf: bool, vec: Vec<u8>) -> Self {
+// let mut vec: Vec<u8> = Vec::new();
+// vec.resize(size, 0);
+ NAPacket { stream: str, pts: pts, dts: dts, duration: dur, keyframe: kf, buffer: Rc::new(vec) }
+ }
+ pub fn get_stream(&self) -> Rc<NAStream> { self.stream.clone() }
+ pub fn get_pts(&self) -> Option<u64> { self.pts }
+ pub fn get_dts(&self) -> Option<u64> { self.dts }
+ pub fn get_duration(&self) -> Option<u64> { self.duration }
+ pub fn is_keyframe(&self) -> bool { self.keyframe }
+ pub fn get_buffer(&self) -> Rc<Vec<u8>> { self.buffer.clone() }
+}
+
+impl Drop for NAPacket {
+ fn drop(&mut self) {}
+}
+
+impl fmt::Display for NAPacket {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ let mut foo = format!("[pkt for {} size {}", self.stream, self.buffer.len());
+ if let Some(pts) = self.pts { foo = format!("{} pts {}", foo, pts); }
+ if let Some(dts) = self.dts { foo = format!("{} dts {}", foo, dts); }
+ if let Some(dur) = self.duration { foo = format!("{} duration {}", foo, dur); }
+ if self.keyframe { foo = format!("{} kf", foo); }
+ foo = foo + "]";
+ write!(f, "{}", foo)
+ }
+}
+
+pub trait FrameFromPacket {
+ fn new_from_pkt(pkt: &NAPacket, info: Rc<NACodecInfo>) -> NAFrame;
+ fn fill_timestamps(&mut self, pkt: &NAPacket);
+}
+
+impl FrameFromPacket for NAFrame {
+ fn new_from_pkt(pkt: &NAPacket, info: Rc<NACodecInfo>) -> NAFrame {
+ NAFrame::new(pkt.pts, pkt.dts, pkt.duration, info, HashMap::new())
+ }
+ fn fill_timestamps(&mut self, pkt: &NAPacket) {
+ self.set_pts(pkt.pts);
+ self.set_dts(pkt.dts);
+ self.set_duration(pkt.duration);
+ }
+}
+