aboutsummaryrefslogtreecommitdiff
path: root/Src/aacdec-mft/MKVAACDecoder.cpp
diff options
context:
space:
mode:
authorJef <jef@targetspot.com>2024-09-24 08:54:57 -0400
committerJef <jef@targetspot.com>2024-09-24 08:54:57 -0400
commit20d28e80a5c861a9d5f449ea911ab75b4f37ad0d (patch)
tree12f17f78986871dd2cfb0a56e5e93b545c1ae0d0 /Src/aacdec-mft/MKVAACDecoder.cpp
parent537bcbc86291b32fc04ae4133ce4d7cac8ebe9a7 (diff)
downloadwinamp-20d28e80a5c861a9d5f449ea911ab75b4f37ad0d.tar.gz
Initial community commit
Diffstat (limited to 'Src/aacdec-mft/MKVAACDecoder.cpp')
-rw-r--r--Src/aacdec-mft/MKVAACDecoder.cpp116
1 files changed, 116 insertions, 0 deletions
diff --git a/Src/aacdec-mft/MKVAACDecoder.cpp b/Src/aacdec-mft/MKVAACDecoder.cpp
new file mode 100644
index 00000000..49de01d7
--- /dev/null
+++ b/Src/aacdec-mft/MKVAACDecoder.cpp
@@ -0,0 +1,116 @@
+#include "MKVAACDecoder.h"
+#include <math.h>
+#include "../nsutil/pcm.h"
+
+MKVAACDecoder::MKVAACDecoder(unsigned int bps, bool floating_point)
+: bps(bps), floating_point(floating_point)
+{
+
+}
+
+MKVAACDecoder *MKVAACDecoder::Create(const nsmkv::TrackEntryData *track_entry_data, const nsmkv::AudioData *audio_data, unsigned int preferred_bits, unsigned int max_channels, bool floating_point)
+{
+ if (!floating_point)
+ {
+ if (preferred_bits >= 24)
+ preferred_bits=24;
+ else
+ preferred_bits=16;
+ }
+ /*if (!max_channels)
+ max_channels = 8;*/
+
+ if (track_entry_data->codec_private && track_entry_data->codec_private_len)
+ {
+ MKVAACDecoder *decoder = new MKVAACDecoder(preferred_bits, floating_point);
+ if (decoder && SUCCEEDED(decoder->decoder.Open(track_entry_data->codec_private, track_entry_data->codec_private_len))) {
+ return decoder;
+ }
+ delete decoder;
+ }
+
+ return 0;
+}
+
+int MKVAACDecoder::GetOutputProperties(unsigned int *sampleRate, unsigned int *channels, unsigned int *bitsPerSample, bool *isFloat)
+{
+ uint32_t local_sample_rate, local_channels;
+ HRESULT hr = decoder.GetOutputProperties(&local_sample_rate, &local_channels);
+ if (FAILED(hr)) {
+ return MKV_FAILURE;
+ }
+
+ *sampleRate = local_sample_rate;
+ *channels = local_channels;
+
+ *bitsPerSample = bps;
+ *isFloat = floating_point;
+ return MKV_SUCCESS;
+}
+
+void MKVAACDecoder::Flush()
+{
+ decoder.Flush();
+}
+
+int MKVAACDecoder::OutputFrameSize(size_t *frame_size)
+{
+ size_t local_frame_size;
+ if (FAILED(decoder.OutputBlockSizeSamples(&local_frame_size))) {
+ return MKV_FAILURE;
+ }
+ *frame_size = local_frame_size;
+
+ return MKV_SUCCESS;
+}
+
+void MKVAACDecoder::Close()
+{
+ delete this;
+}
+
+int MKVAACDecoder::DecodeBlock(void *inputBuffer, size_t inputBufferBytes, void *outputBuffer, size_t *outputBufferBytes)
+{
+ decoder.Feed(inputBuffer, inputBufferBytes);
+ decoder.Decode(outputBuffer, outputBufferBytes, bps, false, 1.0);
+ return MKV_SUCCESS;
+}
+
+void MKVAACDecoder::EndOfStream()
+{
+ decoder.Feed(0, 0);
+}
+
+#define CBCLASS MKVAACDecoder
+START_DISPATCH;
+CB(OUTPUT_FRAME_SIZE, OutputFrameSize)
+CB(GET_OUTPUT_PROPERTIES, GetOutputProperties)
+CB(DECODE_BLOCK, DecodeBlock)
+VCB(FLUSH, Flush)
+VCB(CLOSE, Close)
+VCB(END_OF_STREAM, EndOfStream)
+END_DISPATCH;
+#undef CBCLASS
+
+
+int MKVDecoder::CreateAudioDecoder(const char *codec_id, const nsmkv::TrackEntryData *track_entry_data, const nsmkv::AudioData *audio_data, unsigned int preferred_bits, unsigned int max_channels,bool floating_point, ifc_mkvaudiodecoder **decoder)
+{
+ if (!strcmp(codec_id, "A_AAC"))
+ {
+ MKVAACDecoder *aac_decoder = MKVAACDecoder::Create(track_entry_data, audio_data, preferred_bits, max_channels, floating_point);
+ if (aac_decoder)
+ {
+ *decoder = aac_decoder;
+ return CREATEDECODER_SUCCESS;
+ }
+ return CREATEDECODER_FAILURE;
+ }
+
+ return CREATEDECODER_NOT_MINE;
+}
+
+#define CBCLASS MKVDecoder
+START_DISPATCH;
+CB(CREATE_AUDIO_DECODER, CreateAudioDecoder)
+END_DISPATCH;
+#undef CBCLASS \ No newline at end of file