2 #include "AudioLogger.h"
3 #include "AudioTools/AudioCodecs/AudioCodecsBase.h"
4 #include "AudioTools/CoreAudio/AudioOutput.h"
5 #include "AudioTools/CoreAudio/Buffers.h"
35 if (p_writer) p_writer->begin();
40 if (p_writer) p_writer->end();
44 size_t write(
const uint8_t *data,
size_t len)
override {
48 if ((p_out ==
nullptr && p_writer ==
nullptr) || (data ==
nullptr) ||
54 if (
findTag(data, len, metadata_range.from, meta_len)) {
56 metadata_range.setLen(meta_len);
57 LOGI(
"ignoring metadata at pos: %d len: %d", metadata_range.from,
62 if (!metadata_range.isDefined()) {
63 if (p_out)
return p_out->write(data, len);
64 if (p_writer)
return p_writer->write(data, len);
69 for (
int j = 0; j < len; j++) {
70 if (!metadata_range.inRange(current_pos)) {
83 if (current_pos > metadata_range.to) {
85 metadata_range.clear();
92 Print *p_out =
nullptr;
95 enum MetaType { TAG, TAG_PLUS, ID3 };
102 bool inRange(
int pos) {
return pos >= from && pos < to; }
103 void setLen(
int len) { to = from + len; }
109 bool isDefined() {
return from != -1; }
121 bool findTag(
const uint8_t *data,
size_t len,
int &pos_tag,
int &meta_len) {
123 if (
find((
const char *)data, len, pos_tag, tag_type)) {
135 memcpy(&tagv2, data + pos_tag,
sizeof(
ID3v2));
136 meta_len = calcSizeID3v2(tagv2.size);
145 uint32_t calcSizeID3v2(uint8_t chars[4]) {
146 uint32_t byte0 = chars[0];
147 uint32_t byte1 = chars[1];
148 uint32_t byte2 = chars[2];
149 uint32_t byte3 = chars[3];
150 return byte0 << 21 | byte1 << 14 | byte2 << 7 | byte3;
154 bool find(
const char *str,
size_t len,
int &pos, MetaType &type) {
155 if (str ==
nullptr || len <= 0)
return false;
156 for (
size_t j = 0; j <= len - 3; j++) {
157 if (str[j] ==
'T' && str[j + 1] ==
'A' && str[j + 2] ==
'G') {
158 type = str[j + 3] ==
'+' ? TAG_PLUS : TAG;
161 }
else if (str[j] ==
'I' && str[j + 1] ==
'D' && str[j + 2] ==
'3') {
182 p_decoder = &decoder;
186 bool begin()
override {
189 return AudioDecoder::begin();
192 void end()
override {
198 size_t write(
const uint8_t *data,
size_t len)
override {
199 return filter.
write(data, len);
202 operator bool()
override {
return p_print !=
nullptr && is_active; }
207 bool is_active =
false;