1 use nihav_core::codecs::*;
2 use nihav_core::muxers::*;
3 use std::marker::PhantomData;
7 stream: Option<NAStreamRef>,
12 fn new() -> Self { Self::default() }
15 impl NAEncoder for NullEncoder {
16 fn negotiate_format(&self, encinfo: &EncodeParameters) -> EncoderResult<EncodeParameters> {
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,
25 let info = NACodecInfo::new("null", encinfo.format, None);
26 let mut stream = NAStream::new(stype, stream_id, info, encinfo.tb_num, encinfo.tb_den, 0);
27 stream.set_num(stream_id as usize);
28 let stream = stream.into_ref();
29 self.stream = Some(stream.clone());
33 fn encode(&mut self, frm: &NAFrame) -> EncoderResult<()> {
34 self.pkt = Some(NAPacket::new(self.stream.clone().unwrap(), frm.ts, true, Vec::new()));
37 fn get_packet(&mut self) -> EncoderResult<Option<NAPacket>> {
39 std::mem::swap(&mut self.pkt, &mut npkt);
42 fn flush(&mut self) -> EncoderResult<()> {
47 impl 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 }
53 fn get_encoder() -> Box<dyn NAEncoder + Send> {
54 Box::new(NullEncoder::new())
57 pub const NULL_ENCODER: EncoderInfo = EncoderInfo { name: "null", get_encoder };
59 struct NullMuxer<'a> {
60 bw: PhantomData<&'a mut ByteWriter<'a>>,
63 impl<'a> NullMuxer<'a> {
64 fn new(_bw: &'a mut ByteWriter<'a>) -> Self {
66 bw: PhantomData::default(),
71 impl<'a> MuxCore<'a> for NullMuxer<'a> {
72 fn create(&mut self, _strmgr: &StreamManager) -> MuxerResult<()> {
75 fn mux_frame(&mut self, _strmgr: &StreamManager, _pkt: NAPacket) -> MuxerResult<()> {
78 fn flush(&mut self) -> MuxerResult<()> {
81 fn end(&mut self) -> MuxerResult<()> {
86 impl<'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 }
92 pub struct NullMuxerCreator {}
94 impl 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))
98 fn get_name(&self) -> &'static str { "null" }
99 fn get_capabilities(&self) -> MuxerCapabilities { MuxerCapabilities::Universal }
102 pub const NULL_MUXER: &dyn MuxerCreator = &NullMuxerCreator{};