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 get_capabilities(&self) -> u64 { 0 }
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,
26 let info = NACodecInfo::new("null", encinfo.format, None);
27 let mut stream = NAStream::new(stype, stream_id, info, encinfo.tb_num, encinfo.tb_den, 0);
28 stream.set_num(stream_id as usize);
29 let stream = stream.into_ref();
30 self.stream = Some(stream.clone());
34 fn encode(&mut self, frm: &NAFrame) -> EncoderResult<()> {
35 self.pkt = Some(NAPacket::new(self.stream.clone().unwrap(), frm.ts, true, Vec::new()));
38 fn get_packet(&mut self) -> EncoderResult<Option<NAPacket>> {
40 std::mem::swap(&mut self.pkt, &mut npkt);
43 fn flush(&mut self) -> EncoderResult<()> {
48 impl 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 }
54 fn get_encoder() -> Box<dyn NAEncoder + Send> {
55 Box::new(NullEncoder::new())
58 pub const NULL_ENCODER: EncoderInfo = EncoderInfo { name: "null", get_encoder };
60 struct NullMuxer<'a> {
61 bw: PhantomData<&'a mut ByteWriter<'a>>,
64 impl<'a> NullMuxer<'a> {
65 fn new(_bw: &'a mut ByteWriter<'a>) -> Self {
67 bw: PhantomData::default(),
72 impl<'a> MuxCore<'a> for NullMuxer<'a> {
73 fn create(&mut self, _strmgr: &StreamManager) -> MuxerResult<()> {
76 fn mux_frame(&mut self, _strmgr: &StreamManager, _pkt: NAPacket) -> MuxerResult<()> {
79 fn flush(&mut self) -> MuxerResult<()> {
82 fn end(&mut self) -> MuxerResult<()> {
87 impl<'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 }
93 pub struct NullMuxerCreator {}
95 impl 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))
99 fn get_name(&self) -> &'static str { "null" }
100 fn get_capabilities(&self) -> MuxerCapabilities { MuxerCapabilities::Universal }
103 pub const NULL_MUXER: &dyn MuxerCreator = &NullMuxerCreator{};