@@ -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// —————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
7473void 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() {
962963const 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;
0 commit comments