Commit 91deadbc authored by schreibfaul1's avatar schreibfaul1

determine embedded block picture

parent 2f59cc23
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* adapted for the ESP32 by schreibfaul1 * adapted for the ESP32 by schreibfaul1
* *
* Created on: 13.02.2023 * Created on: 13.02.2023
* Updated on: 13.12.2023 * Updated on: 29.12.2023
*/ */
//---------------------------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------------------------
// O G G I M P L. // O G G I M P L.
...@@ -54,6 +54,9 @@ char *s_vorbisChbuf = NULL; ...@@ -54,6 +54,9 @@ char *s_vorbisChbuf = NULL;
int32_t s_vorbisValidSamples = 0; int32_t s_vorbisValidSamples = 0;
uint8_t s_vorbisOldMode = 0; uint8_t s_vorbisOldMode = 0;
uint32_t s_blocksizes[2]; uint32_t s_blocksizes[2];
uint32_t s_blockPicPos = 0;
uint32_t s_blockPicLen = 0;
uint32_t s_commentLength = 0;
uint8_t s_nrOfCodebooks = 0; uint8_t s_nrOfCodebooks = 0;
uint8_t s_nrOfFloors = 0; uint8_t s_nrOfFloors = 0;
...@@ -152,6 +155,8 @@ void VORBISsetDefaults(){ ...@@ -152,6 +155,8 @@ void VORBISsetDefaults(){
s_vorbisSegmentTableRdPtr = -1; s_vorbisSegmentTableRdPtr = -1;
s_vorbisError = 0; s_vorbisError = 0;
s_lastSegmentTableLen = 0; s_lastSegmentTableLen = 0;
s_blockPicPos = 0;
s_blockPicLen = 0;
VORBISDecoder_ClearBuffers(); VORBISDecoder_ClearBuffers();
} }
...@@ -190,17 +195,19 @@ int VORBISDecode(uint8_t *inbuf, int *bytesLeft, short *outbuf){ ...@@ -190,17 +195,19 @@ int VORBISDecode(uint8_t *inbuf, int *bytesLeft, short *outbuf){
// log_i("first packet (identification len) %i", len); // log_i("first packet (identification len) %i", len);
s_identificatonHeaderLength = len; s_identificatonHeaderLength = len;
ret = parseVorbisFirstPacket(inbuf, len); ret = parseVorbisFirstPacket(inbuf, len);
s_blockPicPos += 28;
} }
} }
else if(s_pageNr == 2){ // comment header else if(s_pageNr == 2){ // comment header
int idx = VORBIS_specialIndexOf(inbuf, "vorbis", 10); int idx = VORBIS_specialIndexOf(inbuf, "vorbis", 10);
s_blockPicPos += 6;
if(idx == 1){ if(idx == 1){
// log_i("second packet (comment len) %i", len); // log_i("second packet (comment len) %i", len);
s_commentHeaderLength = len; s_commentHeaderLength = len;
ret = parseVorbisComment(inbuf, len); ret = parseVorbisComment(inbuf, len);
} }
else{ else{
log_e("no \"vorbis\" something went wrong %i", len); ; // commentlength is greater than (one or more) OggS frame(s)
} }
// log_w("s_vorbisSegmentTableSize %d", s_vorbisSegmentTableSize); // log_w("s_vorbisSegmentTableSize %d", s_vorbisSegmentTableSize);
// Normally the segment table has two entries, the first for comments and the second for the codebooks // Normally the segment table has two entries, the first for comments and the second for the codebooks
...@@ -406,19 +413,21 @@ int parseVorbisFirstPacket(uint8_t *inbuf, int16_t nBytes){ // 4.2.2. Identifica ...@@ -406,19 +413,21 @@ int parseVorbisFirstPacket(uint8_t *inbuf, int16_t nBytes){ // 4.2.2. Identifica
int parseVorbisComment(uint8_t *inbuf, int16_t nBytes){ // reference https://xiph.org/vorbis/doc/v-comment.html int parseVorbisComment(uint8_t *inbuf, int16_t nBytes){ // reference https://xiph.org/vorbis/doc/v-comment.html
// first bytes are: '.vorbis' // first bytes are: '.vorbis'
uint16_t pos = 7; uint32_t pos = 7;
uint32_t vendorLength = *(inbuf + pos + 3) << 24; // lengt of vendor string, e.g. Xiph.Org libVorbis I 20070622 uint32_t vendorLength = *(inbuf + pos + 3) << 24; // lengt of vendor string, e.g. Xiph.Org libVorbis I 20070622
vendorLength += *(inbuf + pos + 2) << 16; vendorLength += *(inbuf + pos + 2) << 16;
vendorLength += *(inbuf + pos + 1) << 8; vendorLength += *(inbuf + pos + 1) << 8;
vendorLength += *(inbuf + pos); vendorLength += *(inbuf + pos);
if(vendorLength > 254){ // guard if(vendorLength > 254){ // guard
log_e("vorbis comment too long"); log_e("vorbis comment too long, vendorLength %i", vendorLength);
return 0; return 0;
} }
memcpy(s_vorbisChbuf, inbuf + 11, vendorLength); memcpy(s_vorbisChbuf, inbuf + 11, vendorLength);
s_vorbisChbuf[vendorLength] = '\0'; s_vorbisChbuf[vendorLength] = '\0';
pos += 4 + vendorLength; pos += 4 + vendorLength;
s_commentHeaderLength -= (7 + 4 + vendorLength);
// log_i("vendorLength %x", vendorLength); // log_i("vendorLength %x", vendorLength);
// log_i("vendorString %s", s_vorbisChbuf); // log_i("vendorString %s", s_vorbisChbuf);
...@@ -426,6 +435,7 @@ int parseVorbisComment(uint8_t *inbuf, int16_t nBytes){ // reference https: ...@@ -426,6 +435,7 @@ int parseVorbisComment(uint8_t *inbuf, int16_t nBytes){ // reference https:
uint8_t nrOfComments = *(inbuf + pos); uint8_t nrOfComments = *(inbuf + pos);
// log_i("nrOfComments %i", nrOfComments); // log_i("nrOfComments %i", nrOfComments);
pos += 4; pos += 4;
s_commentHeaderLength -= 4;
int idx = 0; int idx = 0;
char* artist = NULL; char* artist = NULL;
...@@ -437,23 +447,30 @@ int parseVorbisComment(uint8_t *inbuf, int16_t nBytes){ // reference https: ...@@ -437,23 +447,30 @@ int parseVorbisComment(uint8_t *inbuf, int16_t nBytes){ // reference https:
commentLength += *(inbuf + pos + 2) << 16; commentLength += *(inbuf + pos + 2) << 16;
commentLength += *(inbuf + pos + 1) << 8; commentLength += *(inbuf + pos + 1) << 8;
commentLength += *(inbuf + pos); commentLength += *(inbuf + pos);
s_commentLength = commentLength;
if(commentLength > 254) {log_i("vorbis comment too long"); return 0;} uint8_t cl = min((uint32_t)254, commentLength);
memcpy(s_vorbisChbuf, inbuf + pos + 4, commentLength); memcpy(s_vorbisChbuf, inbuf + pos + 4, cl);
s_vorbisChbuf[commentLength] = '\0'; s_vorbisChbuf[cl] = '\0';
// log_i("commentLength %i comment %s", commentLength, s_vorbisChbuf); // log_i("commentLength %i comment %s", commentLength, s_vorbisChbuf);
pos += commentLength + 4;
idx = VORBIS_specialIndexOf((uint8_t*)s_vorbisChbuf, "artist=", 10); idx = VORBIS_specialIndexOf((uint8_t*)s_vorbisChbuf, "artist=", 10);
if(idx != 0) VORBIS_specialIndexOf((uint8_t*)s_vorbisChbuf, "ARTIST=", 10); if(idx != 0) VORBIS_specialIndexOf((uint8_t*)s_vorbisChbuf, "ARTIST=", 10);
if(idx == 0){ if(idx == 0){ artist = strndup((const char*)(s_vorbisChbuf + 7), commentLength - 7); s_commentLength = 0;}
artist = strndup((const char*)(s_vorbisChbuf + 7), commentLength - 7);
}
idx = VORBIS_specialIndexOf((uint8_t*)s_vorbisChbuf, "title=", 10); idx = VORBIS_specialIndexOf((uint8_t*)s_vorbisChbuf, "title=", 10);
if(idx != 0) VORBIS_specialIndexOf((uint8_t*)s_vorbisChbuf, "TITLE=", 10); if(idx != 0) VORBIS_specialIndexOf((uint8_t*)s_vorbisChbuf, "TITLE=", 10);
if(idx == 0){ title = strndup((const char*)(s_vorbisChbuf + 6), commentLength - 6); if(idx == 0){ title = strndup((const char*)(s_vorbisChbuf + 6), commentLength - 6); s_commentLength = 0;}
}
idx = VORBIS_specialIndexOf((uint8_t*)s_vorbisChbuf, "metadata_block_picture=", 25);
if(idx == 0){ s_blockPicLen = commentLength;
s_blockPicPos += pos + 23;
uint16_t blockPicLenUntilFrameEnd = s_commentHeaderLength - (4 + 23);
log_w("metadata block picture found at pos %i, length %i, first blockLength %i", s_blockPicPos, s_blockPicLen, blockPicLenUntilFrameEnd);}
pos += commentLength + 4;
s_commentHeaderLength -= (4 + commentLength);
} }
if(artist && title){ if(artist && title){
strcpy(s_vorbisChbuf, artist); strcpy(s_vorbisChbuf, artist);
...@@ -587,6 +604,7 @@ int VORBISparseOGG(uint8_t *inbuf, int *bytesLeft){ ...@@ -587,6 +604,7 @@ int VORBISparseOGG(uint8_t *inbuf, int *bytesLeft){
if(s_f_oggContinuedPage) return ERR_VORBIS_DECODER_ASYNC; if(s_f_oggContinuedPage) return ERR_VORBIS_DECODER_ASYNC;
inbuf += idx; inbuf += idx;
*bytesLeft -= idx; *bytesLeft -= idx;
s_blockPicPos += idx;
} }
int16_t segmentTableWrPtr = -1; int16_t segmentTableWrPtr = -1;
...@@ -646,6 +664,7 @@ int VORBISparseOGG(uint8_t *inbuf, int *bytesLeft){ ...@@ -646,6 +664,7 @@ int VORBISparseOGG(uint8_t *inbuf, int *bytesLeft){
} }
*bytesLeft -= headerSize; *bytesLeft -= headerSize;
s_blockPicPos += headerSize;
if(s_pageNr < 4 && !continuedPage) s_pageNr++; if(s_pageNr < 4 && !continuedPage) s_pageNr++;
s_f_oggFirstPage = firstPage; s_f_oggFirstPage = firstPage;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment