Skip to content

Commit 1963d58

Browse files
committed
ContainerM4A: w/o decoder
1 parent 79f1bf4 commit 1963d58

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

src/AudioTools/AudioCodecs/ContainerM4A.h

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ namespace audio_tools {
88

99
/**
1010
* @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.
1212
* format.
1313
* @ingroup codecs
1414
* @author Phil Schatzmann
1515
* @copyright GPLv3
1616
*/
1717
class ContainerM4A : public ContainerDecoder {
1818
public:
19-
2019
/**
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.
2222
*/
2323
ContainerM4A() {
2424
demux.setReference(this);
@@ -30,10 +30,7 @@ class ContainerM4A : public ContainerDecoder {
3030
* notification.
3131
* @param decoder Reference to a MultiDecoder for PCM output.
3232
*/
33-
ContainerM4A(MultiDecoder& decoder) : ContainerM4A() {
34-
p_decoder = &decoder;
35-
p_decoder->addNotifyAudioChange(*this);
36-
}
33+
ContainerM4A(MultiDecoder& decoder) : ContainerM4A() { setDecoder(decoder); }
3734

3835
/**
3936
* @brief Set the output stream for decoded or raw audio.
@@ -107,6 +104,17 @@ class ContainerM4A : public ContainerDecoder {
107104
demux.setChunkOffsetsBuffer(buffer);
108105
}
109106

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+
110118
protected:
111119
bool is_active = false; ///< True if demuxer is active.
112120
bool is_magic_cookie_processed =
@@ -123,8 +131,7 @@ class ContainerM4A : public ContainerDecoder {
123131
static void decodeAudio(const M4AAudioDemuxer::Frame& frame, void* ref) {
124132
ContainerM4A* self = static_cast<ContainerM4A*>(ref);
125133
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);
128135
return;
129136
}
130137
MultiDecoder& dec = *(self->p_decoder);

0 commit comments

Comments
 (0)