2 #include "AudioTools/AudioLogger.h"
12 template <
class Decoder>
35 size_t write(uint8_t* data,
size_t len){
37 if (p_decoder==
nullptr)
return 0;
38 int pos=0;
int meta_len=0;
39 if (
findTag(data, len, pos, meta_len)){
40 LOGD(
"pos: %d len: %d",pos, meta_len);
42 p_decoder->write(data+start,pos);
45 int start_idx2 = pos+meta_len;
46 int len2 = len-start_idx2;
49 p_decoder->write(data+start_idx2,len2);
52 start = meta_len - len2;
59 p_decoder->write(data+start,len-start);
67 Decoder *p_decoder=
nullptr;
68 enum MetaType {TAG, TAG_PLUS, ID3};
79 bool findTag(uint8_t* data,
size_t len,
int &pos_tag,
int &meta_len){
81 if (
find((
const char*)data, len, pos_tag, tag_type)){
93 memcpy(&tagv2, data+pos_tag,
sizeof(
ID3v2));
94 meta_len = calcSizeID3v2(tagv2.size);
104 uint32_t calcSizeID3v2(uint8_t chars[4]) {
105 uint32_t byte0 = chars[0];
106 uint32_t byte1 = chars[1];
107 uint32_t byte2 = chars[2];
108 uint32_t byte3 = chars[3];
109 return byte0 << 21 | byte1 << 14 | byte2 << 7 | byte3;
113 bool find(
const char*str,
size_t len,
int &pos, MetaType &type){
114 if (str==
nullptr || len<=0)
return false;
115 for (
size_t j=0;j<=len-3;j++){
116 if (str[j]==
'T' && str[j+1]==
'A' && str[j+2]==
'G'){
117 type = str[j+3]==
'+' ? TAG_PLUS : TAG;
119 }
else if (str[j]==
'I' && str[j+1]==
'D' && str[j+2]==
'3'){