Skip to content

Commit 9451e3c

Browse files
committed
[ESPuino :: Rfid-controlled musicplayer] [PN] 21. José Feliciano - Feliz Navidad.opus
corr. METADATA_BLOCK_PICTURE begin
1 parent e5c618c commit 9451e3c

File tree

3 files changed

+28
-23
lines changed

3 files changed

+28
-23
lines changed

src/Audio.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
Created on: 28.10.2018 */
66
char audioI2SVers[] = "\
7-
Version 3.4.3j ";
7+
Version 3.4.3k ";
88
/* Updated on: 24.10.2025
99
1010
Author: Wolle (schreibfaul1)
@@ -29,7 +29,7 @@ constexpr size_t m_frameSizeWav = 2048;
2929
constexpr size_t m_frameSizeMP3 = 1600 * 2;
3030
constexpr size_t m_frameSizeAAC = 1600 * 2;
3131
constexpr size_t m_frameSizeFLAC = 4096 * 6; // 24576
32-
constexpr size_t m_frameSizeOPUS = 2048;
32+
constexpr size_t m_frameSizeOPUS = UINT16_MAX;
3333
constexpr size_t m_frameSizeVORBIS = UINT16_MAX; // OGG length is normally 4080 bytes, but can be reach 64KB in the metadata block
3434
constexpr size_t m_outbuffSize = 4608 * 2;
3535
constexpr size_t m_samplesBuff48KSize = m_outbuffSize * 8; // 131072KB SRmin: 6KHz -> SRmax: 48K
@@ -261,7 +261,6 @@ void Audio::initInBuff() {
261261
size_t size = InBuff.init();
262262
if (size > 0) { info(*this, evt_info, "inputBufferSize: %u bytes", size - 1); }
263263
}
264-
InBuff.changeMaxBlockSize(1600); // default size mp3 or aac
265264
}
266265
// —————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
267266
esp_err_t Audio::I2Sstart() {
@@ -3893,8 +3892,7 @@ void Audio::processWebStream() {
38933892
if (m_dataMode != AUDIO_DATA) return; // guard
38943893
uint16_t readedBytes = 0;
38953894

3896-
m_pwst.maxFrameSize = InBuff.getMaxBlockSize(); // every mp3/aac frame is not bigger
3897-
m_pwst.availableBytes = 0; // available from stream
3895+
m_pwst.availableBytes = 0; // available from stream
38983896
m_pwst.f_clientIsConnected = m_client->connected();
38993897

39003898
// first call, set some values to default - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -3956,7 +3954,8 @@ void Audio::processWebStream() {
39563954
}
39573955
}
39583956
if (!m_decoder && InBuff.bufferFilled() > 127) {
3959-
if (!initializeDecoder()) return;
3957+
if (initializeDecoder()) m_pwst.maxFrameSize = InBuff.getMaxBlockSize();
3958+
else return;
39603959
}
39613960

39623961
// start audio decoding - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -4797,6 +4796,7 @@ bool Audio::initializeDecoder() {
47974796
case CODEC_VORBIS:
47984797
type = "VORBIS";
47994798
InBuff.changeMaxBlockSize(m_frameSizeVORBIS);
4799+
AUDIO_LOG_ERROR("bs %i", InBuff.getMaxBlockSize());
48004800
break;
48014801
case CODEC_WAV:
48024802
type = "WAV";

src/opus_decoder/opus_decoder.cpp

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ void OpusDecoder::reset() {
6060
silkdec.reset();
6161
celtdec.reset();
6262
m_opusSegmentTable.reset();
63-
m_streamTitle.reset();
6463
m_frameCount = 0;
6564
m_opusSegmentLength = 0;
6665
m_opusValidSamples = 0;
@@ -72,7 +71,6 @@ void OpusDecoder::reset() {
7271
}
7372
// —————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
7473
void OpusDecoder::clear() {
75-
m_streamTitle.clear();
7674
m_opusSegmentTable.clear();
7775
m_frameCount = 0;
7876
m_opusSegmentLength = 0;
@@ -134,9 +132,11 @@ int32_t OpusDecoder::decode(uint8_t* inbuf, int32_t* bytesLeft, int16_t* outbuf)
134132
int32_t bytes_consumed = 0;
135133

136134
if (m_f_lastPage && m_opusSegmentTableSize == 0) {
137-
*bytesLeft = segmLen;
138-
ret = OPUS_END;
139-
return ret;
135+
if (OPUS_specialIndexOf(inbuf, "OggS", 5) == 0) { // next round
136+
m_opusPageNr = 0;
137+
} else {
138+
return OPUS_END;
139+
}
140140
}
141141

142142
if (m_frameCount > 0) { // decode audio, next part
@@ -147,7 +147,7 @@ int32_t OpusDecoder::decode(uint8_t* inbuf, int32_t* bytesLeft, int16_t* outbuf)
147147
if (!m_opusSegmentTableSize) {
148148
m_f_opusParseOgg = false;
149149
m_opusCountCode = 0;
150-
ret = OPUSparseOGG(inbuf, bytesLeft);
150+
ret = parseOGG(inbuf, bytesLeft);
151151
bytes_consumed = bytesLeft_begin - (*bytesLeft);
152152
if (ret != OPUS_NONE) goto exit; // error
153153
inbuf += m_opusOggHeaderSize; // no return, fall through
@@ -161,6 +161,7 @@ int32_t OpusDecoder::decode(uint8_t* inbuf, int32_t* bytesLeft, int16_t* outbuf)
161161

162162
if (m_opusPageNr == 0) { // OpusHead
163163
ret = opusDecodePage0(inbuf, bytesLeft, segmLen);
164+
m_comment.reset();
164165
goto exit;
165166
}
166167

@@ -962,7 +963,7 @@ uint32_t OpusDecoder::getBitRate() {
962963
const char* OpusDecoder::getStreamTitle() {
963964
if (m_f_newSteamTitle) {
964965
m_f_newSteamTitle = false;
965-
return m_streamTitle.c_get();
966+
return m_comment.stream_title.c_get();
966967
}
967968
return NULL;
968969
}
@@ -985,7 +986,7 @@ std::vector<uint32_t> OpusDecoder::getMetadataBlockPicture() {
985986
m_f_opusNewMetadataBlockPicture = false;
986987
return m_comment.pic_vec;
987988
}
988-
std::vector<uint32_t>v;
989+
std::vector<uint32_t> v;
989990
return v;
990991
}
991992
// —————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
@@ -1052,8 +1053,9 @@ int32_t OpusDecoder::parseOpusComment(uint8_t* inbuf, int32_t nBytes, uint32_t c
10521053
ps_ptr<char> val = comment.substr(idx + 1);
10531054

10541055
if (key.starts_with_icase("metadata_block_picture")) {
1055-
for (int i = 0; i < m_comment.item_vec.size(); i += 2){
1056-
m_comment.pic_vec.push_back(m_comment.item_vec[i]); // start pos
1056+
m_comment.item_vec[0] += strlen("METADATA_BLOCK_PICTURE=");
1057+
for (int i = 0; i < m_comment.item_vec.size(); i += 2) {
1058+
m_comment.pic_vec.push_back(m_comment.item_vec[i]); // start pos
10571059
m_comment.pic_vec.push_back(m_comment.item_vec[i + 1] - m_comment.item_vec[i]); // len = end pos - start pos
10581060
}
10591061
m_comment.item_vec.clear();
@@ -1071,7 +1073,6 @@ int32_t OpusDecoder::parseOpusComment(uint8_t* inbuf, int32_t nBytes, uint32_t c
10711073
m_comment.stream_title.append(val.c_get());
10721074
}
10731075
}
1074-
10751076
if (key.starts_with_icase("title")) {
10761077
if (!m_comment.stream_title.valid()) {
10771078
m_comment.stream_title.assign(val.c_get());
@@ -1080,7 +1081,6 @@ int32_t OpusDecoder::parseOpusComment(uint8_t* inbuf, int32_t nBytes, uint32_t c
10801081
m_comment.stream_title.append(val.c_get());
10811082
}
10821083
}
1083-
10841084
// comment.println(); // optional output
10851085
m_comment.item_vec.clear();
10861086
};
@@ -1203,7 +1203,11 @@ int32_t OpusDecoder::parseOpusComment(uint8_t* inbuf, int32_t nBytes, uint32_t c
12031203
// 🔹 4. Return status
12041204
if (m_comment.oob) { return OPUS_COMMENT_NEED_MORE; }
12051205

1206-
if (m_comment.list_length == 0) { return OPUS_COMMENT_DONE; }
1206+
if (m_comment.list_length == 0) {
1207+
if (m_comment.stream_title.valid()) m_f_newSteamTitle = true;
1208+
// m_comment.stream_title.println();
1209+
return OPUS_COMMENT_DONE;
1210+
}
12071211

12081212
return OPUS_COMMENT_NEED_MORE;
12091213
}
@@ -1261,7 +1265,7 @@ int32_t OpusDecoder::parseOpusHead(uint8_t* inbuf, int32_t nBytes) { // referenc
12611265
return 1;
12621266
}
12631267
// —————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
1264-
int32_t OpusDecoder::OPUSparseOGG(uint8_t* inbuf, int32_t* bytesLeft) { // reference https://www.xiph.org/ogg/doc/rfc3533.txt
1268+
int32_t OpusDecoder::parseOGG(uint8_t* inbuf, int32_t* bytesLeft) { // reference https://www.xiph.org/ogg/doc/rfc3533.txt
12651269

12661270
int32_t idx = OPUS_specialIndexOf(inbuf, "OggS", 6);
12671271
if (idx != 0) {
@@ -1324,7 +1328,9 @@ int32_t OpusDecoder::OPUSparseOGG(uint8_t* inbuf, int32_t* bytesLeft) { // refer
13241328
m_f_firstPage = headerType & 0x02; // set: this is the first page of a logical bitstream (bos)
13251329
m_f_lastPage = headerType & 0x04; // set: this is the last page of a logical bitstream (eos)
13261330

1327-
// OPUS_LOG_INFO("firstPage %i, continuedPage %i, lastPage %i",s_f_firstPage, m_f_continuedPage, m_f_lastPage);
1331+
if (m_f_firstPage) { m_opusPageNr = 0; }
1332+
1333+
OPUS_LOG_DEBUG("firstPage %i, continuedPage %i, lastPage %i", m_f_firstPage, m_f_continuedPage, m_f_lastPage);
13281334

13291335
uint16_t headerSize = pageSegments + 27;
13301336
*bytesLeft -= headerSize;

src/opus_decoder/opus_decoder.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ class OpusDecoder : public Decoder {
165165
} comment_t;
166166
comment_t m_comment;
167167

168-
ps_ptr<char> m_streamTitle;
169168
ps_ptr<uint16_t> m_opusSegmentTable;
170169

171170
ofp2_t m_ofp2; // used in opus_FramePacking_Code2
@@ -181,7 +180,7 @@ class OpusDecoder : public Decoder {
181180
int8_t opus_FramePacking_Code1(uint8_t* inbuf, int32_t* bytesLeft, int16_t* outbuf, int32_t packetLen, uint16_t samplesPerFrame, uint8_t* frameCount);
182181
int8_t opus_FramePacking_Code2(uint8_t* inbuf, int32_t* bytesLeft, int16_t* outbuf, int32_t packetLen, uint16_t samplesPerFrame, uint8_t* frameCount);
183182
int8_t opus_FramePacking_Code3(uint8_t* inbuf, int32_t* bytesLeft, int16_t* outbuf, int32_t packetLen, uint16_t samplesPerFrame, uint8_t* frameCount);
184-
int32_t OPUSparseOGG(uint8_t* inbuf, int32_t* bytesLeft);
183+
int32_t parseOGG(uint8_t* inbuf, int32_t* bytesLeft);
185184
int32_t parseOpusHead(uint8_t* inbuf, int32_t nBytes);
186185
int32_t parseOpusComment(uint8_t* inbuf, int32_t nBytes, uint32_t current_file_pos);
187186
int8_t parseOpusTOC(uint8_t TOC_Byte);

0 commit comments

Comments
 (0)