]> git.nihav.org Git - nihav.git/commitdiff
tta: try to initialise decoder from input format if no header was provided master
authorKostya Shishkov <kostya.shishkov@gmail.com>
Sat, 31 Oct 2026 15:17:09 +0000 (16:17 +0100)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Sat, 31 Oct 2026 15:17:09 +0000 (16:17 +0100)
nihav-llaudio/src/codecs/tta.rs

index 1bfee62eb772c642a1615b4fe5ccce3133786df6..9508a0fe7928fffbd90e7810908e82ae0985d3a9 100644 (file)
@@ -219,7 +219,7 @@ fn check_crc(buf: &[u8]) -> bool {
 
 impl NADecoder for TTADecoder {
     fn init(&mut self, _supp: &mut NADecoderSupport, info: NACodecInfoRef) -> DecoderResult<()> {
-        if let NACodecTypeInfo::Audio(_ainfo) = info.get_properties() {
+        if let NACodecTypeInfo::Audio(ainfo) = info.get_properties() {
             if let Some(buf) = info.get_extradata() {
                 if !check_crc(&buf) {
                     return Err(DecoderError::ChecksumError);
@@ -263,7 +263,30 @@ impl NADecoder for TTADecoder {
                 self.ainfo = NAAudioInfo::new(srate, channels as u8, fmt, self.framelen as usize);
                 Ok(())
             } else {
-                Err(DecoderError::InvalidData)
+                println!("no TTA header was provided, trying to make data up");
+
+                self.nsamples           = u32::MAX;
+                self.framelen = ainfo.sample_rate * 256 / 245;
+                self.chmap = if ainfo.channels == 1 {
+                        NAChannelMap::from_str("C").unwrap()
+                    } else if ainfo.channels == 2 {
+                        NAChannelMap::from_str("L,R").unwrap()
+                    } else {
+                        return Err(DecoderError::NotImplemented);
+                    };
+                self.ainfo = ainfo;
+                self.ainfo.format = match ainfo.format.bits {
+                         8 | 16 => SND_S16P_FORMAT,
+                        24 | 32 => SND_S32P_FORMAT,
+                        _ => return Err(DecoderError::NotImplemented),
+                    };
+                self.ainfo.block_len = self.framelen as usize;
+                self.bpp = (ainfo.format.bits / 8) as u8;
+                self.ch_dec = Vec::with_capacity(usize::from(ainfo.channels));
+                for _ in 0..ainfo.channels {
+                    self.ch_dec.push(ChannelDecoder::new());
+                }
+                Ok(())
             }
         } else {
             Err(DecoderError::InvalidData)