Skip to content

Commit e09fe9e

Browse files
committed
new class MultiStreamingDecoder
1 parent 710b480 commit e09fe9e

File tree

7 files changed

+957
-209
lines changed

7 files changed

+957
-209
lines changed

src/AudioTools/AudioCodecs/AudioCodecs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
#include "AudioTools/AudioCodecs/CodecL8.h"
2525
#include "AudioTools/AudioCodecs/CodecFloat.h"
2626
#include "AudioTools/AudioCodecs/CodecBase64.h"
27-
#include "AudioTools/AudioCodecs/DecoderFromStreaming.h"
2827
#include "AudioTools/AudioCodecs/MultiDecoder.h"
2928
#include "AudioTools/AudioCodecs/CodecMTS.h"
3029
#include "AudioTools/AudioCodecs/CodecADTS.h"
3130
#include "AudioTools/AudioCodecs/CodecNetworkFormat.h"
3231
#include "AudioTools/AudioCodecs/CodecFactory.h"
32+
#include "AudioTools/AudioCodecs/StreamingDecoder.h"

src/AudioTools/AudioCodecs/AudioCodecsBase.h

Lines changed: 0 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -156,116 +156,4 @@ class CodecNOP : public AudioDecoder, public AudioEncoder {
156156
virtual const char *mime() { return nullptr; }
157157
};
158158

159-
/**
160-
* @brief A Streaming Decoder where we provide both the input and output
161-
* as streams.
162-
* @ingroup codecs
163-
* @author Phil Schatzmann
164-
* @copyright GPLv3
165-
*/
166-
class StreamingDecoder : public AudioInfoSource {
167-
public:
168-
/// Starts the processing
169-
virtual bool begin() = 0;
170-
171-
/// Releases the reserved memory
172-
virtual void end() = 0;
173-
174-
/// Defines the output Stream
175-
virtual void setOutput(Print &out_stream) { p_print = &out_stream; }
176-
177-
/// Defines the output streams and register to be notified
178-
virtual void setOutput(AudioStream &out_stream) {
179-
Print *p_print = &out_stream;
180-
setOutput(*p_print);
181-
addNotifyAudioChange(out_stream);
182-
}
183-
184-
/// Defines the output streams and register to be notified
185-
virtual void setOutput(AudioOutput &out_stream) {
186-
Print *p_print = &out_stream;
187-
setOutput(*p_print);
188-
addNotifyAudioChange(out_stream);
189-
}
190-
191-
/// Stream Interface: Decode directly by taking data from the stream. This is
192-
/// more efficient then feeding the decoder with write: just call copy() in
193-
/// the loop
194-
void setInput(Stream &inStream) { this->p_input = &inStream; }
195-
196-
/// Provides the last available MP3FrameInfo
197-
virtual AudioInfo audioInfo() = 0;
198-
199-
/// checks if the class is active
200-
virtual operator bool() = 0;
201-
202-
/// Process a single read operation - to be called in the loop
203-
virtual bool copy() = 0;
204-
205-
/// Process all data
206-
bool copyAll() {
207-
bool result = false;
208-
while (copy()) {
209-
result = true;
210-
}
211-
return result;
212-
}
213-
214-
protected:
215-
virtual size_t readBytes(uint8_t *data, size_t len) = 0;
216-
Print *p_print = nullptr;
217-
Stream *p_input = nullptr;
218-
};
219-
220-
/**
221-
* @brief Converts any AudioDecoder to a StreamingDecoder
222-
* @ingroup codecs
223-
* @author Phil Schatzmann
224-
* @copyright GPLv3
225-
*/
226-
class StreamingDecoderAdapter : public StreamingDecoder {
227-
public:
228-
StreamingDecoderAdapter(AudioDecoder &decoder,
229-
int copySize = DEFAULT_BUFFER_SIZE) {
230-
p_decoder = &decoder;
231-
if (copySize > 0) resize(copySize);
232-
}
233-
/// Starts the processing
234-
bool begin() override { return p_input != nullptr && p_decoder->begin(); }
235-
236-
/// Releases the reserved memory
237-
void end() override { p_decoder->end(); }
238-
239-
/// Defines the output Stream
240-
void setOutput(Print &out_stream) override {
241-
p_decoder->setOutput(out_stream);
242-
}
243-
244-
/// Provides the last available MP3FrameInfo
245-
AudioInfo audioInfo() override { return p_decoder->audioInfo(); }
246-
247-
/// checks if the class is active
248-
virtual operator bool() override { return *p_decoder; }
249-
250-
/// Process a single read operation - to be called in the loop
251-
virtual bool copy() override {
252-
int read = readBytes(&buffer[0], buffer.size());
253-
int written = 0;
254-
if (read > 0) written = p_decoder->write(&buffer[0], read);
255-
return written > 0;
256-
}
257-
258-
/// Adjust the buffer size: the existing content of the buffer is lost!
259-
void resize(int bufferSize) { buffer.resize(bufferSize); }
260-
261-
protected:
262-
AudioDecoder *p_decoder = nullptr;
263-
Vector<uint8_t> buffer{0};
264-
265-
size_t readBytes(uint8_t *data, size_t len) override {
266-
if (p_input == nullptr) return 0;
267-
return p_input->readBytes(data, len);
268-
}
269-
};
270-
271159
} // namespace audio_tools

src/AudioTools/AudioCodecs/CodecFLAC.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,13 @@ class FLACDecoder : public StreamingDecoder {
138138
is_md5_checing = flag;
139139
}
140140

141+
/// returns true of the stream is ogg
142+
bool isOgg() const { return is_ogg; }
143+
144+
/// Provides "audio/flac" or "audio/ogg"
145+
const char *mime() override { return is_ogg ? "audio/ogg; codecs=flac" : "audio/flac"; }
146+
147+
141148
protected:
142149
bool is_active = false;
143150
bool is_ogg = false;

src/AudioTools/AudioCodecs/CodecVorbis.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ class VorbisDecoder : public StreamingDecoder {
118118
}
119119
}
120120

121+
/// Provides "audio/ogg"
122+
const char *mime() override { return "audio/vorbis+ogg"; }
123+
121124
protected:
122125
AudioInfo cfg;
123126
Vector<uint8_t> pcm;

src/AudioTools/AudioCodecs/DecoderFromStreaming.h

Lines changed: 0 additions & 93 deletions
This file was deleted.

0 commit comments

Comments
 (0)