|
5 | 5 | #include "AudioTools/CoreAudio/AudioBasic/StrView.h"
|
6 | 6 | #include "AudioTools/CoreAudio/AudioHttp/AbstractURLStream.h"
|
7 | 7 | #include "AudioTools/CoreAudio/AudioMetaData/MimeDetector.h"
|
| 8 | +#include "AudioTools/AudioCodecs/StreamingDecoder.h" |
8 | 9 |
|
9 | 10 | namespace audio_tools {
|
10 | 11 |
|
@@ -56,6 +57,19 @@ class MultiDecoder : public AudioDecoder {
|
56 | 57 | */
|
57 | 58 | MultiDecoder(MimeSource& mimeSource) { setMimeSource(mimeSource); }
|
58 | 59 |
|
| 60 | + /** |
| 61 | + * @brief Destructor |
| 62 | + * |
| 63 | + * Cleans up any internally created DecoderAdapter instances. |
| 64 | + */ |
| 65 | + ~MultiDecoder() { |
| 66 | + // Clean up any adapters we created |
| 67 | + for (auto* adapter : adapters) { |
| 68 | + delete adapter; |
| 69 | + } |
| 70 | + adapters.clear(); |
| 71 | + } |
| 72 | + |
59 | 73 | /**
|
60 | 74 | * @brief Starts the processing and enables automatic MIME type determination
|
61 | 75 | *
|
@@ -292,6 +306,33 @@ class MultiDecoder : public AudioDecoder {
|
292 | 306 | */
|
293 | 307 | MimeDetector& mimeDetector() { return mime_detector; }
|
294 | 308 |
|
| 309 | + /** |
| 310 | + * @brief Adds a StreamingDecoder that will be selected by its MIME type |
| 311 | + * |
| 312 | + * Registers a StreamingDecoder that will be automatically selected when |
| 313 | + * the corresponding MIME type is detected in the input data. The |
| 314 | + * StreamingDecoder is wrapped in a DecoderAdapter to provide compatibility |
| 315 | + * with the write-based AudioDecoder interface used by MultiDecoder. |
| 316 | + * |
| 317 | + * @param decoder The StreamingDecoder to register |
| 318 | + * @param mime The MIME type string to associate with this decoder |
| 319 | + * @param bufferSize Buffer size for the adapter (default: 1024 bytes) |
| 320 | + */ |
| 321 | + void addDecoder(StreamingDecoder& decoder, const char* mime, |
| 322 | + int bufferSize = 1024) { |
| 323 | + if (mime != nullptr) { |
| 324 | + // Create a DecoderAdapter to wrap the StreamingDecoder |
| 325 | + decoder.addNotifyAudioChange(*this); |
| 326 | + auto adapter = new DecoderAdapter(decoder, bufferSize); |
| 327 | + adapters.push_back(adapter); // Store for cleanup |
| 328 | + |
| 329 | + // Add the adapter as a regular AudioDecoder |
| 330 | + addDecoder(*adapter, mime); |
| 331 | + } else { |
| 332 | + LOGE("MIME type is nullptr - cannot add StreamingDecoder"); |
| 333 | + } |
| 334 | + } |
| 335 | + |
295 | 336 | protected:
|
296 | 337 | /**
|
297 | 338 | * @brief Information about a registered decoder
|
@@ -319,6 +360,7 @@ class MultiDecoder : public AudioDecoder {
|
319 | 360 | } actual_decoder; ///< Currently active decoder information
|
320 | 361 |
|
321 | 362 | Vector<DecoderInfo> decoders{0}; ///< Collection of registered decoders
|
| 363 | + Vector<DecoderAdapter*> adapters{0}; ///< Collection of internally created adapters |
322 | 364 | MimeDetector mime_detector; ///< MIME type detection engine
|
323 | 365 | CodecNOP nop; ///< No-operation codec for unsupported formats
|
324 | 366 | MimeSource* p_mime_source = nullptr; ///< Optional external MIME source
|
|
0 commit comments