|
| MultiStreamingDecoder ()=default |
| Default constructor.
|
|
| ~MultiStreamingDecoder () |
| Destructor.
|
|
void | addDecoder (AudioDecoder &decoder, const char *mime, int bufferSize=DEFAULT_BUFFER_SIZE) |
| Adds an AudioDecoder with explicit MIME type.
|
|
void | addDecoder (StreamingDecoder &decoder) |
| Adds a decoder that will be selected by its MIME type.
|
|
void | addDecoder (StreamingDecoder &decoder, const char *mime) |
| Adds a decoder with explicit MIME type.
|
|
virtual void | addNotifyAudioChange (AudioInfoSupport &bi) |
| Adds target to be notified about audio changes.
|
|
AudioInfo | audioInfo () override |
| Provides the audio information from the selected decoder.
|
|
virtual AudioInfo | audioInfoOut () |
|
bool | begin () override |
| Starts the processing.
|
|
virtual void | clearNotifyAudioChange () |
| Deletes all change notify subscriptions.
|
|
virtual bool | copy () override |
| Process a single read operation - to be called in the loop.
|
|
bool | copyAll () |
| Process all available data.
|
|
void | end () override |
| Releases the reserved memory.
|
|
bool | isNotifyActive () |
| Checks if the automatic AudioInfo update is active.
|
|
const char * | mime () override |
| Provides the MIME type of the selected decoder.
|
|
MimeDetector & | mimeDetector () |
| Provides access to the internal MIME detector.
|
|
virtual | operator bool () override |
| Checks if the class is active.
|
|
virtual bool | removeNotifyAudioChange (AudioInfoSupport &bi) |
| Removes a target in order not to be notified about audio changes.
|
|
bool | selectDecoder (const char *mime) |
| Selects the actual decoder by MIME type.
|
|
const char * | selectedMime () |
| Returns the MIME type that was detected and selected.
|
|
void | setInput (Stream &inStream) |
| Stream Interface: Decode directly by taking data from the stream.
|
|
void | setMimeSource (MimeSource &mimeSource) |
| Sets an external MIME source for format detection.
|
|
void | setNotifyActive (bool flag) |
| Deactivate/Reactivate automatic AudioInfo updates: (default is active)
|
|
void | setOutput (AudioOutput &out_stream) override |
| Defines the output streams and register to be notified.
|
|
void | setOutput (AudioStream &out_stream) override |
| Defines the output streams and register to be notified.
|
|
void | setOutput (Print &out_stream) override |
| Defines the output Stream.
|
|
Manage multiple StreamingDecoders with automatic format detection.
This class automatically detects the audio format from incoming streaming data and selects the appropriate decoder from a collection of registered decoders. The format detection is performed using the MimeDetector on the first chunk of data, and the detected data is preserved for the selected decoder using a buffered stream approach.
Key features:
- Automatic format detection using MimeDetector
- Support for multiple decoder registration
- Data preservation during format detection
- Custom mime type detection logic support
- Seamless integration with existing streaming architecture
- Note
- The first call to copy() will consume some data for format detection, but this data is preserved and made available to the selected decoder through a BufferedPrefixStream mechanism.
- Author
- Phil Schatzmann
- Copyright
- GPLv3
Process a single read operation - to be called in the loop.
On the first call, this method reads data for format detection, selects the appropriate decoder, and sets up a buffered stream. Subsequent calls delegate to the selected decoder's copy() method.
- Returns
- true if data was processed successfully, false if no data is available or format detection/decoding failed
Implements StreamingDecoder.
Automatically detects MIME type and selects appropriate decoder.
This method performs automatic format detection and decoder selection when no decoder is currently active. It supports two modes of operation:
- External MIME source - Uses a provided MimeSource for format information
- Auto-detection - Analyzes stream content to determine the audio format
The method reads a small sample of data (80 bytes) from the input stream for format detection, then preserves this data in a buffered stream so it remains available to the selected decoder. This ensures no audio data is lost during the detection process.
- Note
- This method is automatically called by copy() on the first invocation. Subsequent calls will return immediately if a decoder is already selected.
-
The detection data is preserved using BufferedPrefixStream, allowing the selected decoder to process the complete stream including the bytes used for format identification.
- Returns
- true if a decoder was successfully selected and initialized, or if a decoder was already active; false if MIME detection failed or no matching decoder was found
- See also
- selectDecoder(const char* mime) for explicit Decoder selection
-
setMimeSource() for providing external MIME type information
-
MimeDetector for details on automatic format detection
Sets an external MIME source for format detection.
Provides an alternative to automatic MIME detection by allowing an external source to provide the MIME type information. This is particularly useful when the MIME type is already known from other sources such as:
- HTTP Content-Type headers
- File extensions
- Metadata from containers or playlists
- User-specified format preferences
When a MIME source is set, the automatic detection process (which requires reading and analyzing stream data) is bypassed, making the decoder initialization more efficient and faster.
- Parameters
-
mimeSource | Reference to a MimeSource object that provides the MIME type through its mime() method |
- Note
- The MimeSource object must remain valid for the lifetime of this MultiStreamingDecoder instance, as only a reference is stored.
-
Setting a MIME source takes precedence over automatic detection. To revert to automatic detection, the MIME source would need to return nullptr from its mime() method.
- See also
- MimeSource interface for implementing custom MIME providers
-
selectDecoder() for how MIME type detection and selection works
- Since
- This feature allows integration with external metadata sources