add enabling/disabling features for files with both encoder and decoder
[nihav.git] / nihav-ms / src / codecs / msadpcm.rs
index 5010c03dc330457ef6e8de7a5b8d56af9be5c1bc..068dd410fe7708a8a7ca2c5ffb5b348d40140ec2 100644 (file)
@@ -37,6 +37,7 @@ impl Predictor {
     }
 }
 
+#[cfg(feature="decoder_ms_adpcm")]
 struct MSADPCMDecoder {
     ainfo:          NAAudioInfo,
     chmap:          NAChannelMap,
@@ -45,6 +46,7 @@ struct MSADPCMDecoder {
     block_samps:    usize,
 }
 
+#[cfg(feature="decoder_ms_adpcm")]
 impl MSADPCMDecoder {
     fn new() -> Self {
         Self {
@@ -57,6 +59,7 @@ impl MSADPCMDecoder {
     }
 }
 
+#[cfg(feature="decoder_ms_adpcm")]
 impl NADecoder for MSADPCMDecoder {
     #[allow(clippy::int_plus_one)]
     fn init(&mut self, _supp: &mut NADecoderSupport, info: NACodecInfoRef) -> DecoderResult<()> {
@@ -68,7 +71,7 @@ impl NADecoder for MSADPCMDecoder {
             self.block_samps = (self.block_len / channels - 7) * 2 + 2;
             self.ainfo = NAAudioInfo::new(ainfo.get_sample_rate(), channels as u8, SND_S16P_FORMAT, self.block_samps);
             self.chmap = NAChannelMap::from_str(if channels == 1 { "C" } else { "L,R" }).unwrap();
-            self.adapt_coeffs.truncate(0);
+            self.adapt_coeffs.clear();
             if let Some(ref buf) = info.get_extradata() {
                 validate!(buf.len() >= 6);
                 validate!((buf.len() & 3) == 0);
@@ -162,17 +165,20 @@ impl NADecoder for MSADPCMDecoder {
     }
 }
 
+#[cfg(feature="decoder_ms_adpcm")]
 impl NAOptionHandler for MSADPCMDecoder {
     fn get_supported_options(&self) -> &[NAOptionDefinition] { &[] }
     fn set_options(&mut self, _options: &[NAOption]) { }
     fn query_option_value(&self, _name: &str) -> Option<NAValue> { None }
 }
 
+#[cfg(feature="decoder_ms_adpcm")]
 pub fn get_decoder() -> Box<dyn NADecoder + Send> {
     Box::new(MSADPCMDecoder::new())
 }
 
 #[derive(Default)]
+#[cfg(feature="encoder_ms_adpcm")]
 struct MSADPCMEncoder {
     stream:     Option<NAStreamRef>,
     samples:    Vec<i16>,
@@ -182,8 +188,10 @@ struct MSADPCMEncoder {
     srate:      u32,
 }
 
+#[cfg(feature="encoder_ms_adpcm")]
 const DEFAULT_BLOCK_LEN: usize = 256;
 
+#[cfg(feature="encoder_ms_adpcm")]
 impl MSADPCMEncoder {
     fn new() -> Self { Self::default() }
     fn encode_packet(&mut self) -> EncoderResult<NAPacket> {
@@ -297,6 +305,7 @@ impl MSADPCMEncoder {
     }
 }
 
+#[cfg(feature="encoder_ms_adpcm")]
 impl NAEncoder for MSADPCMEncoder {
     fn negotiate_format(&self, encinfo: &EncodeParameters) -> EncoderResult<EncodeParameters> {
         match encinfo.format {
@@ -394,12 +403,14 @@ impl NAEncoder for MSADPCMEncoder {
     }
 }
 
+#[cfg(feature="encoder_ms_adpcm")]
 impl NAOptionHandler for MSADPCMEncoder {
     fn get_supported_options(&self) -> &[NAOptionDefinition] { &[] }
     fn set_options(&mut self, _options: &[NAOption]) { }
     fn query_option_value(&self, _name: &str) -> Option<NAValue> { None }
 }
 
+#[cfg(feature="encoder_ms_adpcm")]
 pub fn get_encoder() -> Box<dyn NAEncoder + Send> {
     Box::new(MSADPCMEncoder::new())
 }
@@ -464,7 +475,7 @@ mod test {
                 tb_den:  0,
                 flags:   0,
             };
-        test_encoding_md5(&dec_config, &enc_config, enc_params,
-                          &[0xe1591a1e, 0x816d0239, 0x4cc42291, 0x4e6b69cb]);
+        test_encoding_md5(&dec_config, &enc_config, enc_params, &[],
+                          &[0x82259f45, 0xba7b984a, 0xc03c94e5, 0x00b4312b]);
     }
 }