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 {
45 LOGI(
"write: %u", (
unsigned)len);
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)) {
79 LOGI(
"output: %u", (
unsigned)to_write);
81 if (p_out) written = p_out->write(tmp.
data(), to_write);
82 if (p_writer) written = p_writer->write(tmp.
data(), to_write);
83 assert(to_write == written);
84 metadata_range.clear();
86 LOGI(
"output ignored");
90 if (current_pos > metadata_range.to) {
92 metadata_range.clear();
44 size_t write(
const uint8_t *data,
size_t len)
override {
…}
99 Print *p_out =
nullptr;
102 enum MetaType { TAG, TAG_PLUS, ID3 };
109 bool inRange(
int pos) {
return pos >= from && pos < to; }
110 void setLen(
int len) { to = from + len; }
116 bool isDefined() {
return from != -1; }
128 bool findTag(
const uint8_t *data,
size_t len,
int &pos_tag,
int &meta_len) {
130 if (
find((
const char *)data, len, pos_tag, tag_type)) {
142 memcpy(&tagv2, data + pos_tag,
sizeof(
ID3v2));
143 meta_len = calcSizeID3v2(tagv2.size);
128 bool findTag(
const uint8_t *data,
size_t len,
int &pos_tag,
int &meta_len) {
…}
152 uint32_t calcSizeID3v2(uint8_t chars[4]) {
153 uint32_t byte0 = chars[0];
154 uint32_t byte1 = chars[1];
155 uint32_t byte2 = chars[2];
156 uint32_t byte3 = chars[3];
157 return byte0 << 21 | byte1 << 14 | byte2 << 7 | byte3;
161 bool find(
const char *str,
size_t len,
int &pos, MetaType &type) {
162 if (str ==
nullptr || len <= 0)
return false;
163 for (
size_t j = 0; j <= len - 3; j++) {
164 if (str[j] ==
'T' && str[j + 1] ==
'A' && str[j + 2] ==
'G') {
165 type = str[j + 3] ==
'+' ? TAG_PLUS : TAG;
168 }
else if (str[j] ==
'I' && str[j + 1] ==
'D' && str[j + 2] ==
'3') {
161 bool find(
const char *str,
size_t len,
int &pos, MetaType &type) {
…}
189 p_decoder = &decoder;
193 bool begin()
override {
197 return AudioDecoder::begin();
200 void end()
override {
206 size_t write(
const uint8_t *data,
size_t len)
override {
207 return filter.
write(data, len);
225 operator bool()
override {
return p_print !=
nullptr && is_active; }
228 AudioDecoder *p_decoder =
nullptr;
229 MetaDataFilter filter;
230 bool is_active =
false;