fn get_packet(&mut self) -> Option<(Vec<u8>, u32, bool)>;
fn flush(&mut self);
fn finish(&mut self, bw: &mut ByteWriter) -> MuxerResult<()>;
+ fn set_pkt_size(&mut self, pkt_size: usize);
}
#[derive(Clone,Copy)]
keyframe: bool,
audio: bool,
index: Vec<IndexEntry>,
+ debug: bool,
}
impl RMStream {
- fn new(strno: usize, stream: &NAStream) -> MuxerResult<Self> {
+ fn new(strno: usize, stream: &NAStream, pkt_size: usize) -> MuxerResult<Self> {
let packetiser = match stream.get_media_type() {
- StreamType::Video => create_video_stream(stream)?,
+ StreamType::Video => create_video_stream(stream, pkt_size)?,
StreamType::Audio => create_audio_stream(stream)?,
_ => Box::new(DummyStreamWriter{}),
};
keyframe: false,
audio: false,
index: Vec::new(),
+ debug: false,
})
}
fn write_mdpr(&mut self, bw: &mut ByteWriter, strm: &NAStream) -> MuxerResult<()> {
self.mdpr_pos = bw.tell();
bw.write_chunk(b"MDPR", 0, 0)?;
- bw.write_u16be(self.stream_id as u16)?;
+ bw.write_u16be(self.stream_id)?;
bw.write_u32be(0)?; //max br
bw.write_u32be(0)?; //avg br
bw.write_u32be(0)?; //max ps
self.index.push(IndexEntry{ time: ts, pos: bw.tell(), pkt_no: *pkt_no });
}
let is_keyframe = self.keyframe && (!self.audio || first);
+ if self.debug {
+ println!(" writing packet for stream {} size {}{}", self.stream_id, data.len(), if is_keyframe { " kf" } else { "" });
+ }
bw.write_u16be(0)?; //version;
bw.write_u16be((data.len() + 12) as u16)?;
bw.write_u16be(self.stream_id)?;
data_pos: u64,
num_chunks: u32,
cur_packet: u32,
+
+ debug: bool,
+ vpkt_size: usize,
}
impl<'a> RMMuxer<'a> {
data_pos: 0,
num_chunks: 0,
cur_packet: 0,
+
+ debug: false,
+ vpkt_size: 1400,
}
}
fn write_index(&mut self) -> MuxerResult<()> {
self.streams.clear();
for (strno, strm) in strmgr.iter().enumerate() {
- let mut swriter = RMStream::new(strno, &strm)?;
+ let mut swriter = RMStream::new(strno, &strm, self.vpkt_size)?;
swriter.write_mdpr(self.bw, &strm)?;
self.streams.push(swriter);
self.num_chunks += 1;
}
}
+const DEBUG_OPTION: &str = "debug";
+const VPKT_SIZE_OPTION: &str = "vpkt_size";
+
+const MUXER_OPTIONS: &[NAOptionDefinition] = &[
+ NAOptionDefinition {
+ name: DEBUG_OPTION, description: "print some muxer statistics",
+ opt_type: NAOptionDefinitionType::Bool },
+ NAOptionDefinition {
+ name: VPKT_SIZE_OPTION, description: "video packet maximum size",
+ opt_type: NAOptionDefinitionType::Int(Some(1024), Some(14800)) },
+];
+
impl<'a> NAOptionHandler for RMMuxer<'a> {
- fn get_supported_options(&self) -> &[NAOptionDefinition] { &[] }
- fn set_options(&mut self, _options: &[NAOption]) { }
- fn query_option_value(&self, _name: &str) -> Option<NAValue> { None }
+ fn get_supported_options(&self) -> &[NAOptionDefinition] { MUXER_OPTIONS }
+ fn set_options(&mut self, options: &[NAOption]) {
+ for option in options.iter() {
+ for opt_def in MUXER_OPTIONS.iter() {
+ if opt_def.check(option).is_ok() {
+ match option.name {
+ DEBUG_OPTION => {
+ if let NAValue::Bool(val) = option.value {
+ self.debug = val;
+ for stream in self.streams.iter_mut() {
+ stream.debug = val;
+ }
+ }
+ },
+ VPKT_SIZE_OPTION => {
+ if let NAValue::Int(intval) = option.value {
+ self.vpkt_size = intval as usize;
+ for stream in self.streams.iter_mut() {
+ stream.packetiser.set_pkt_size(self.vpkt_size);
+ }
+ }
+ },
+ _ => {},
+ };
+ }
+ }
+ }
+ }
+ fn query_option_value(&self, name: &str) -> Option<NAValue> {
+ match name {
+ DEBUG_OPTION => Some(NAValue::Bool(self.debug)),
+ VPKT_SIZE_OPTION => Some(NAValue::Int(self.vpkt_size as i64)),
+ _ => None,
+ }
+ }
}
pub struct RealMediaMuxerCreator {}
}
fn end(&mut self) -> MuxerResult<()> {
if let Some(ref mut sw) = self.sw {
- sw.finish(&mut self.bw)?;
+ sw.finish(self.bw)?;
}
Ok(())
}
};
test_remuxing(&dec_config, &enc_config);*/
test_remuxing_md5(&dec_config, "realmedia", &mux_reg,
- [0x26422839, 0xa2d7bdd1, 0xd6ea2a78, 0x1b58033a]);
+ [0x9bc90ab0, 0x6b8c42f7, 0xaf81e8bf, 0x7c76ec57]);
}
#[test]
};
test_remuxing(&dec_config, &enc_config);*/
test_remuxing_md5(&dec_config, "realmedia", &mux_reg,
- [0xcfa1a27b, 0x78314fa7, 0xeb90c31c, 0x7eafeaa8]);
+ [0x8392bb8c, 0xeb8f4d04, 0x25262829, 0x63b2fda7]);
}
#[test]
fn test_rm_muxer_ralf() {
};
test_remuxing(&dec_config, &enc_config);*/
test_remuxing_md5(&dec_config, "realmedia", &mux_reg,
- [0xa0c336d1, 0x76221455, 0x75252067, 0x6189d4af]);
+ [0xe90893eb, 0x8634642c, 0xef679ac4, 0x2e89314a]);
}
}