introduce option handling for decoders
[nihav.git] / nihav-commonfmt / src / codecs / pcm.rs
index 132d4c3a60755e91548643f05d9d8287e10d0b12..b4ded8746bccb11a8f63e392b18bc6f7af40a8de 100644 (file)
@@ -25,15 +25,15 @@ fn get_default_chmap(nch: u8) -> NAChannelMap {
 fn get_duration(ainfo: &NAAudioInfo, duration: Option<u64>, data_size: usize) -> u64 {
     if duration == None {
         let size_bits = (data_size as u64) * 8;
-        let blk_size = (ainfo.get_channels() as u64) * (ainfo.get_format().get_bits() as u64);
+        let blk_size = u64::from(ainfo.get_channels()) * u64::from(ainfo.get_format().get_bits());
         size_bits / blk_size
     } else {
-        duration.unwrap() as u64
+        duration.unwrap()
     }
 }
 
 impl NADecoder for PCMDecoder {
-    fn init(&mut self, info: NACodecInfoRef) -> DecoderResult<()> {
+    fn init(&mut self, _supp: &mut NADecoderSupport, info: NACodecInfoRef) -> DecoderResult<()> {
         if let NACodecTypeInfo::Audio(ainfo) = info.get_properties() {
             self.chmap = get_default_chmap(ainfo.get_channels());
             if self.chmap.num_channels() == 0 { return Err(DecoderError::InvalidData); }
@@ -42,7 +42,7 @@ impl NADecoder for PCMDecoder {
             Err(DecoderError::InvalidData)
         }
     }
-    fn decode(&mut self, pkt: &NAPacket) -> DecoderResult<NAFrameRef> {
+    fn decode(&mut self, _supp: &mut NADecoderSupport, pkt: &NAPacket) -> DecoderResult<NAFrameRef> {
         let info = pkt.get_stream().get_info();
         if let NACodecTypeInfo::Audio(ainfo) = info.get_properties() {
             let duration = get_duration(&ainfo, pkt.get_duration(), pkt.get_buffer().len());
@@ -51,13 +51,21 @@ impl NADecoder for PCMDecoder {
             let mut frm = NAFrame::new_from_pkt(pkt, info, NABufferType::AudioPacked(abuf));
             frm.set_duration(Some(duration));
             frm.set_keyframe(true);
-            Ok(Rc::new(RefCell::new(frm)))
+            Ok(frm.into_ref())
         } else {
             Err(DecoderError::InvalidData)
         }
     }
+    fn flush(&mut self) {
+    }
+}
+
+impl NAOptionHandler for PCMDecoder {
+    fn get_supported_options(&self) -> &[NAOptionDefinition] { &[] }
+    fn set_options(&mut self, _options: &[NAOption]) { }
+    fn query_option_value(&self, _name: &str) -> Option<NAValue> { None }
 }
 
-pub fn get_decoder() -> Box<NADecoder> {
+pub fn get_decoder() -> Box<dyn NADecoder + Send> {
     Box::new(PCMDecoder::new())
 }