use NAPacketiser::attach_stream() where appropriate
[nihav-encoder.git] / src / null.rs
CommitLineData
93521506
KS
1use nihav_core::codecs::*;
2use nihav_core::muxers::*;
3use std::marker::PhantomData;
4
5#[derive(Default)]
6struct NullEncoder {
7 stream: Option<NAStreamRef>,
8 pkt: Option<NAPacket>,
9}
10
11impl NullEncoder {
12 fn new() -> Self { Self::default() }
13}
14
15impl NAEncoder for NullEncoder {
16 fn negotiate_format(&self, encinfo: &EncodeParameters) -> EncoderResult<EncodeParameters> {
17 Ok(*encinfo)
18 }
343a59ec 19 fn get_capabilities(&self) -> u64 { 0 }
93521506
KS
20 fn init(&mut self, stream_id: u32, encinfo: EncodeParameters) -> EncoderResult<NAStreamRef> {
21 let stype = match encinfo.format {
22 NACodecTypeInfo::Audio(_) => StreamType::Audio,
23 NACodecTypeInfo::Video(_) => StreamType::Video,
24 NACodecTypeInfo::None => StreamType::Data,
25 };
26 let info = NACodecInfo::new("null", encinfo.format, None);
38835733 27 let mut stream = NAStream::new(stype, stream_id, info, encinfo.tb_num, encinfo.tb_den, 0);
93521506
KS
28 stream.set_num(stream_id as usize);
29 let stream = stream.into_ref();
30 self.stream = Some(stream.clone());
31
32 Ok(stream)
33 }
34 fn encode(&mut self, frm: &NAFrame) -> EncoderResult<()> {
35 self.pkt = Some(NAPacket::new(self.stream.clone().unwrap(), frm.ts, true, Vec::new()));
36 Ok(())
37 }
38 fn get_packet(&mut self) -> EncoderResult<Option<NAPacket>> {
39 let mut npkt = None;
40 std::mem::swap(&mut self.pkt, &mut npkt);
41 Ok(npkt)
42 }
43 fn flush(&mut self) -> EncoderResult<()> {
44 Ok(())
45 }
46}
47
48impl NAOptionHandler for NullEncoder {
49 fn get_supported_options(&self) -> &[NAOptionDefinition] { &[] }
50 fn set_options(&mut self, _options: &[NAOption]) { }
51 fn query_option_value(&self, _name: &str) -> Option<NAValue> { None }
52}
53
54fn get_encoder() -> Box<dyn NAEncoder + Send> {
55 Box::new(NullEncoder::new())
56}
57
86c54d88 58pub const NULL_ENCODER: EncoderInfo = EncoderInfo { name: "null", get_encoder };
93521506
KS
59
60struct NullMuxer<'a> {
61 bw: PhantomData<&'a mut ByteWriter<'a>>,
62}
63
64impl<'a> NullMuxer<'a> {
65 fn new(_bw: &'a mut ByteWriter<'a>) -> Self {
66 Self {
67 bw: PhantomData::default(),
68 }
69 }
70}
71
72impl<'a> MuxCore<'a> for NullMuxer<'a> {
73 fn create(&mut self, _strmgr: &StreamManager) -> MuxerResult<()> {
74 Ok(())
75 }
76 fn mux_frame(&mut self, _strmgr: &StreamManager, _pkt: NAPacket) -> MuxerResult<()> {
77 Ok(())
78 }
79 fn flush(&mut self) -> MuxerResult<()> {
80 Ok(())
81 }
82 fn end(&mut self) -> MuxerResult<()> {
83 Ok(())
84 }
85}
86
87impl<'a> NAOptionHandler for NullMuxer<'a> {
88 fn get_supported_options(&self) -> &[NAOptionDefinition] { &[] }
89 fn set_options(&mut self, _options: &[NAOption]) { }
90 fn query_option_value(&self, _name: &str) -> Option<NAValue> { None }
91}
92
93pub struct NullMuxerCreator {}
94
95impl MuxerCreator for NullMuxerCreator {
96 fn new_muxer<'a>(&self, bw: &'a mut ByteWriter<'a>) -> Box<dyn MuxCore<'a> + 'a> {
97 Box::new(NullMuxer::new(bw))
98 }
99 fn get_name(&self) -> &'static str { "null" }
100 fn get_capabilities(&self) -> MuxerCapabilities { MuxerCapabilities::Universal }
101}
102
103pub const NULL_MUXER: &dyn MuxerCreator = &NullMuxerCreator{};