13 # define assert(condition) ((void)0)
15 # define assert(condition)
19 #include "ConfigHelix.h"
20 #include "utils/Allocator.h"
21 #include "utils/Buffers.h"
22 #include "utils/Vector.h"
23 #include "utils/helix_log.h"
35 #if defined(ARDUINO) || defined(HELIX_PRINT)
36 void setOutput(Print &output) { this->out = &output; }
64 frame_buffer.resize(0);
76 virtual size_t write(
const void *in_ptr,
size_t in_size) {
77 LOGI_HELIX(
"write %zu", in_size);
80 uint8_t *data = (uint8_t *)in_ptr;
82 int bytes =
writeChunk(data, MIN(open, HELIX_CHUNK_SIZE));
84 if (bytes == 0)
break;
93 operator bool() {
return active; }
114 if (rc > 0) frame_buffer.clearArray(rc);
140 Vector<uint8_t> pcm_buffer{0};
141 SingleBuffer<uint8_t> frame_buffer{0};
142 size_t max_frame_size = 0;
143 size_t max_pcm_size = 0;
144 size_t frame_counter = 0;
146 int parse_0_count = 0;
147 int min_frame_buffer_size = 0;
148 uint64_t time_last_write = 0;
149 uint64_t time_last_result = 0;
150 void *p_caller_ref =
nullptr;
153 #if defined(ARDUINO) || defined(HELIX_PRINT)
154 Print *out =
nullptr;
159 LOGD_HELIX(
"presynch");
170 LOGD_HELIX(
"resynch: %d" , rc);
172 if (rc != 0) parse_0_count = 0;
177 LOGD_HELIX(
"rc: %d - available %d - pos %d", rc,
178 frame_buffer.available(), pos);
181 if (parse_0_count > 2) {
185 }
else if (rc == -1) {
187 LOGD_HELIX(
"rc: %d - available %d", rc,
188 frame_buffer.available());
202 LOGD_HELIX(
"removeInvalidData: %d", pos);
204 LOGI_HELIX(
"removing: %d bytes", pos);
205 frame_buffer.clearArray(pos);
207 }
else if (pos <= 0) {
208 frame_buffer.reset();
215 virtual size_t writeChunk(
const void *in_ptr,
size_t in_size) {
216 LOGI_HELIX(
"writeChunk %zu", in_size);
218 time_last_write = millis();
220 size_t result = frame_buffer.writeArray((uint8_t *)in_ptr, in_size);
228 frame_buffer.clearArray(rc);
230 LOGI_HELIX(
"rc: %d - available %d", rc,
231 frame_buffer.available());
Common Simple Arduino API.
Definition: CommonHelix.h:33
bool removeInvalidData(int pos)
Definition: CommonHelix.h:201
virtual size_t maxPCMSize()=0
virtual size_t writeChunk(const void *in_ptr, size_t in_size)
Decoding Loop: We decode the procided data until we run out of data.
Definition: CommonHelix.h:215
void setMaxFrameSize(size_t len)
Define your optimized maximum frame size in bytes.
Definition: CommonHelix.h:123
void flush()
Decode all open packets.
Definition: CommonHelix.h:104
virtual int findSynchWord(int offset=0)=0
void setReference(void *ref)
Define some additional information which will be provided back in the callbacks.
Definition: CommonHelix.h:133
virtual size_t maxFrameSize()=0
virtual void end()
Releases the reserved memory.
Definition: CommonHelix.h:63
virtual size_t write(const void *in_ptr, size_t in_size)
decodes the next segments from the input. The data can be provided in one big or in small incremental...
Definition: CommonHelix.h:76
virtual void setMinFrameBufferSize(int size)
Defines the minimum frame buffer size which is required before starting the decoding.
Definition: CommonHelix.h:251
uint64_t timeOfLastWrite()
Provides the timestamp in ms of last write.
Definition: CommonHelix.h:97
uint64_t timeOfLastResult()
Provides the timestamp in ms of last decoded result.
Definition: CommonHelix.h:100
virtual bool begin()
Starts the processing.
Definition: CommonHelix.h:43
virtual bool allocateDecoder()=0
Allocate the decoder.
void setMaxPCMSize(size_t len)
Define your optimized maximum pcm buffer size in bytes.
Definition: CommonHelix.h:130
virtual int minFrameBufferSize()
Provides the actual minimum frame buffer size.
Definition: CommonHelix.h:249
bool resynch(int rc)
Definition: CommonHelix.h:169
virtual int decode()=0
Decode w/o parsing.
bool presync()
make sure that we start with a valid sync: remove ID3 data
Definition: CommonHelix.h:158