@@ -16,51 +16,89 @@ namespace audio_tools {
1616 */
1717class ContainerM4A : public ContainerDecoder {
1818 public:
19+ /* *
20+ * @brief Default constructor. Sets up the demuxer callback.
21+ */
1922 ContainerM4A () {
2023 demux.setReference (this );
2124 demux.setCallback (decodeAudio);
2225 };
2326
27+ /* *
28+ * @brief Constructor with decoder. Sets up the demuxer and decoder notification.
29+ * @param decoder Reference to a MultiDecoder for PCM output.
30+ */
2431 ContainerM4A (MultiDecoder& decoder) : ContainerM4A() {
2532 p_decoder = &decoder;
2633 p_decoder->addNotifyAudioChange (*this );
2734 }
2835
36+ /* *
37+ * @brief Set the output stream for decoded or raw audio.
38+ * @param out_stream Output AudioStream.
39+ */
2940 void setOutput (AudioStream& out_stream) override {
3041 if (p_decoder != nullptr ) p_decoder->setOutput (out_stream);
3142 ContainerDecoder::setOutput (out_stream);
3243 }
3344
45+ /* *
46+ * @brief Returns true if the result is PCM (decoder is present).
47+ * @return true if PCM output, false otherwise.
48+ */
3449 bool isResultPCM () override { return p_decoder != nullptr ? true : false ; }
3550
51+ /* *
52+ * @brief Initialize the demuxer and decoder.
53+ * @return true on success.
54+ */
3655 bool begin () override {
3756 demux.begin ();
3857 if (p_decoder) p_decoder->begin ();
3958 is_active = true ;
4059 return true ;
4160 }
4261
62+ /* *
63+ * @brief End the demuxer and decoder, releasing resources.
64+ */
4365 void end () override {
4466 TRACED ();
4567 is_active = false ;
4668 is_magic_cookie_processed = false ;
4769 if (p_decoder) p_decoder->end ();
4870 }
4971
72+ /* *
73+ * @brief Feed data to the demuxer for parsing.
74+ * @param data Pointer to input data.
75+ * @param len Length of input data.
76+ * @return Number of bytes processed (always len).
77+ */
5078 size_t write (const uint8_t * data, size_t len) override {
5179 if (is_active == false ) return len;
5280 demux.write (data, len);
5381 return len;
5482 }
5583
84+ /* *
85+ * @brief Returns true if the demuxer is active.
86+ * @return true if active, false otherwise.
87+ */
5688 operator bool () override { return is_active; }
5789
5890 protected:
59- bool is_active = false ;
60- bool is_magic_cookie_processed = false ;
61- MultiDecoder* p_decoder = nullptr ;
62- M4AAudioDemuxer demux;
91+ bool is_active = false ; // /< True if demuxer is active.
92+ bool is_magic_cookie_processed = false ;// /< True if ALAC magic cookie has been processed.
93+ MultiDecoder* p_decoder = nullptr ; // /< Pointer to the MultiDecoder.
94+ M4AAudioDemuxer demux; // /< Internal demuxer instance.
6395
96+ /* *
97+ * @brief Static callback for demuxed audio frames.
98+ * Handles decoder selection and magic cookie for ALAC.
99+ * @param frame The demuxed audio frame.
100+ * @param ref Reference to the ContainerM4A instance.
101+ */
64102 static void decodeAudio (const M4AAudioDemuxer::Frame& frame, void * ref) {
65103 ContainerM4A* self = static_cast <ContainerM4A*>(ref);
66104 if (self->p_decoder == nullptr ) {
0 commit comments