@@ -8,17 +8,17 @@ namespace audio_tools {
8
8
9
9
/* *
10
10
* @brief M4A Demuxer that extracts audio from M4A/MP4 containers.
11
- * If you provide a decoder (in the constructor) the audio is decoded into pcm
11
+ * The audio is decoded into pcm with the help of the provided decoder.
12
12
* format.
13
13
* @ingroup codecs
14
14
* @author Phil Schatzmann
15
15
* @copyright GPLv3
16
16
*/
17
17
class ContainerM4A : public ContainerDecoder {
18
18
public:
19
-
20
19
/* *
21
- * @brief Default constructor. Sets up the demuxer callback.
20
+ * @brief Default constructor: If no decoder is provided, the
21
+ * raw audio data is provided to the defined output.
22
22
*/
23
23
ContainerM4A () {
24
24
demux.setReference (this );
@@ -30,10 +30,7 @@ class ContainerM4A : public ContainerDecoder {
30
30
* notification.
31
31
* @param decoder Reference to a MultiDecoder for PCM output.
32
32
*/
33
- ContainerM4A (MultiDecoder& decoder) : ContainerM4A() {
34
- p_decoder = &decoder;
35
- p_decoder->addNotifyAudioChange (*this );
36
- }
33
+ ContainerM4A (MultiDecoder& decoder) : ContainerM4A() { setDecoder (decoder); }
37
34
38
35
/* *
39
36
* @brief Set the output stream for decoded or raw audio.
@@ -107,6 +104,17 @@ class ContainerM4A : public ContainerDecoder {
107
104
demux.setChunkOffsetsBuffer (buffer);
108
105
}
109
106
107
+ /* *
108
+ * @brief Sets the decoder to use for audio frames.
109
+ * @param decoder Reference to a MultiDecoder for PCM output.
110
+ * @return true if set successfully, false otherwise.
111
+ */
112
+ bool setDecoder (MultiDecoder& decoder) {
113
+ p_decoder = &decoder;
114
+ p_decoder->addNotifyAudioChange (*this );
115
+ return true ;
116
+ }
117
+
110
118
protected:
111
119
bool is_active = false ; // /< True if demuxer is active.
112
120
bool is_magic_cookie_processed =
@@ -123,8 +131,7 @@ class ContainerM4A : public ContainerDecoder {
123
131
static void decodeAudio (const M4AAudioDemuxer::Frame& frame, void * ref) {
124
132
ContainerM4A* self = static_cast <ContainerM4A*>(ref);
125
133
if (self->p_decoder == nullptr ) {
126
- LOGE (" No decoder defined, cannot decode audio frame: %s (%u bytes)" ,
127
- frame.mime , (unsigned )frame.size );
134
+ self->p_print ->write (frame.data , frame.size );
128
135
return ;
129
136
}
130
137
MultiDecoder& dec = *(self->p_decoder );
0 commit comments