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