From: Robert K. <may...@us...> - 2001-07-31 18:49:24
|
Update of /cvsroot/bitcollider/bitcollider/lib In directory usw-pr-cvs1:/tmp/cvs-serv21067/lib Modified Files: id3.c main.c mp3.c mp3.h Log Message: Fixed bugs #427503 (extracting ID3v2 genres) and finished off the audioSha problems. Index: id3.c =================================================================== RCS file: /cvsroot/bitcollider/bitcollider/lib/id3.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -r1.6 -r1.7 *** id3.c 2001/07/09 19:47:12 1.6 --- id3.c 2001/07/31 18:49:20 1.7 *************** *** 97,100 **** --- 97,253 ---- #define v1_1 id3.v1_1 + static char *genreList[] = + { + "Blues", + "Classic Rock", + "Country", + "Dance", + "Disco", + "Funk", + "Grunge", + "Hip-Hop", + "Jazz", + "Metal", + "New Age", + "Oldies", + "Other", + "Pop", + "R&B", + "Rap", + "Reggae", + "Rock", + "Techno", + "Industrial", + "Alternative", + "Ska", + "Death Metal", + "Pranks", + "Soundtrack", + "Euro-Techno", + "Ambient", + "Trip-Hop", + "Vocal", + "Jazz+Funk", + "Fusion", + "Trance", + "Classical", + "Instrumental", + "Acid", + "House", + "Game", + "Sound Clip", + "Gospel", + "Noise", + "AlternRock", + "Bass", + "Soul", + "Punk", + "Space", + "Meditative", + "Instrumental Pop", + "Instrumental Rock", + "Ethnic", + "Gothic", + "Darkwave", + "Techno-Industrial", + "Electronic", + "Pop-Folk", + "Eurodance", + "Dream", + "Southern Rock", + "Comedy", + "Cult", + "Gangsta", + "Top 40", + "Christian Rap", + "Pop/Funk", + "Jungle", + "Native American", + "Cabaret", + "New Wave", + "Psychadelic", + "Rave", + "Showtunes", + "Trailer", + "Lo-Fi", + "Tribal", + "Acid Punk", + "Acid Jazz", + "Polka", + "Retro", + "Musical", + "Rock & Roll", + "Hard Rock", + "Folk", + "Folk-Rock", + "National Folk", + "Swing", + "Fast Fusion", + "Bebob", + "Latin", + "Revival", + "Celtic", + "Bluegrass", + "Avantgarde", + "Gothic Rock", + "Progressive Rock", + "Psychedelic Rock", + "Symphonic Rock", + "Slow Rock", + "Big Band", + "Chorus", + "Easy Listening", + "Acoustic", + "Humour", + "Speech", + "Chanson", + "Opera", + "Chamber Music", + "Sonata", + "Symphony", + "Booty Bass", + "Primus", + "Porn Groove", + "Satire", + "Slow Jam", + "Club", + "Tango", + "Samba", + "Folklore", + "Ballad", + "Power Ballad", + "Rhythmic Soul", + "Freestyle", + "Duet", + "Punk Rock", + "Drum Solo", + "Acapella", + "Euro-House", + "Dance Hall", + "Goa", + "Drum & Bass", + "Club-House", + "Hardcore", + "Terror", + "Indie", + "BritPop", + "Negerpunk", + "Polsk Punk", + "Beat", + "Christian Gangsta", + "Heavy Metal", + "Black Metal", + "Crossover", + "Contemporary C", + "Christian Rock", + "Merengue", + "Salsa", + "Thrash Metal", + "Anime", + "JPop", + "SynthPop", + "\0" + }; + void delete_ID3_tag(ID3Info *info) { *************** *** 143,147 **** if (strcmp(tagName, "TCON") == 0) ! info->genre = strdup(frameData); if (strcmp(tagName, "TRCK") == 0) --- 296,314 ---- if (strcmp(tagName, "TCON") == 0) ! { ! int i; ! ! for(i = 0;; i++) ! { ! if (*genreList[i] == 0) ! break; ! ! if (strcasecmp(genreList[i], frameData) == 0) ! { ! info->genre = malloc(10); ! sprintf(info->genre, "%d", i); ! } ! } ! } if (strcmp(tagName, "TRCK") == 0) Index: main.c =================================================================== RCS file: /cvsroot/bitcollider/bitcollider/lib/main.c,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -r1.28 -r1.29 *** main.c 2001/07/24 02:02:08 1.28 --- main.c 2001/07/31 18:49:20 1.29 *************** *** 302,306 **** add_attribute(submission, "tag.mp3.stereo", mp3Info->stereo ? "y" : "n"); ! add_attribute(submission, "tag.mp3.audio_sha1", audioShaDigest); free(mp3Info); --- 302,306 ---- add_attribute(submission, "tag.mp3.stereo", mp3Info->stereo ? "y" : "n"); ! //add_attribute(submission, "tag.mp3.audio_sha1", audioShaDigest); free(mp3Info); Index: mp3.c =================================================================== RCS file: /cvsroot/bitcollider/bitcollider/lib/mp3.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -r1.4 -r1.5 *** mp3.c 2001/05/18 01:00:54 1.4 --- mp3.c 2001/07/31 18:49:20 1.5 *************** *** 20,23 **** --- 20,28 ---- static int mpegLayer[] = { 0, 3, 2, 1 }; + static void update_audio_sha1(mp3_info *info, + unsigned char *buf, + unsigned int bufLen); + #define ID3_TAG_LEN 128 + static int bitrate(const char *header) { *************** *** 175,181 **** --- 180,191 ---- void mp3_final(mp3_info *info) { + unsigned char *oldShaBuffer; + if (info->startBuffer) free(info->startBuffer); + /* Save the audiosha buffer... */ + oldShaBuffer = info->audioShaBuffer; + /* If there are more bad bytes in a file, than there are good bytes, assume that the file is not an MP3 file and zero out all the values *************** *** 188,192 **** --- 198,223 ---- else { + if (info->audioShaBuffer) + { + char *tag; + int i; + + /* Copy the last three characters from after the last audioSha + block to the end of the sliding window. Then, look for the + TAG and skip it if it was found. */ + memcpy(info->audioShaBuffer + ID3_TAG_LEN, info->audioShaExtra, 3); + for(tag = info->audioShaBuffer, i = 0; i < ID3_TAG_LEN+3; i++, tag++) + { + if (strncmp(tag, "TAG", 3) == 0) + break; + } + + if (i > ID3_TAG_LEN) + i = ID3_TAG_LEN; + sha_update(&info->scontext, info->audioShaBuffer, i); + } + sha_final(info->audioSha, &info->scontext); + if (info->mpegVer == 1) info->duration = info->frames * 1152 / (info->samplerate / 1000); *************** *** 196,199 **** --- 227,233 ---- } + if (oldShaBuffer) + free(oldShaBuffer); + /* printf("du: %d\n", info->duration); *************** *** 206,209 **** --- 240,244 ---- } + void mp3_update(mp3_info *info, unsigned char *buffer, *************** *** 254,259 **** /* Pass the bytes we're skipping through the sha function */ ! sha_update(&info->scontext, buffer, info->skipSize); /* Loop through the buffer trying to find frames */ for(ptr = buffer + info->skipSize, max = buffer + len; --- 289,300 ---- /* Pass the bytes we're skipping through the sha function */ ! update_audio_sha1(info, buffer, info->skipSize); + /* Save the three bytes immediately following the last audio sha + block for later. These bytes will be used to check for ID3 + tags at the end of truncated audio frames. See mp3_final for + more details. */ + memcpy(info->audioShaExtra, buffer + info->skipSize, 3); + /* Loop through the buffer trying to find frames */ for(ptr = buffer + info->skipSize, max = buffer + len; *************** *** 341,345 **** /* Update the sha hash with the data from this frame */ bytesLeft = (unsigned int)max - (unsigned int)ptr; ! sha_update(&info->scontext, ptr, (size > bytesLeft) ? bytesLeft : size); /* Move the memory pointer past the frame */ --- 382,391 ---- /* Update the sha hash with the data from this frame */ bytesLeft = (unsigned int)max - (unsigned int)ptr; ! update_audio_sha1(info, ptr, ! (size > bytesLeft) ? bytesLeft : size); ! ! /* save the first three bytes after the audio sha block (see above) */ ! memcpy(info->audioShaExtra, ! ptr + ((size > bytesLeft) ? bytesLeft : size), 3); /* Move the memory pointer past the frame */ *************** *** 358,360 **** --- 404,449 ---- if (temp) free(temp); + } + + static void update_audio_sha1(mp3_info *info, + unsigned char *buf, + unsigned int bufLen) + { + /* Allocate the space for the audiosha sliding window. Allocate three + extra bytes to allow for the possibility that the ID3 tag spans + the outer boundary of the audiosha sliding window */ + if (info->audioShaBuffer == NULL) + info->audioShaBuffer = malloc(ID3_TAG_LEN + 3); + + /* Save the last 128 bytes of the given buffer and audio sha all the + bytes passed through the sliding window */ + if (bufLen + info->audioShaBytes > ID3_TAG_LEN) + { + if (bufLen >= ID3_TAG_LEN) + { + sha_update(&info->scontext, info->audioShaBuffer, + info->audioShaBytes); + sha_update(&info->scontext, buf, bufLen - ID3_TAG_LEN); + memcpy(info->audioShaBuffer, buf + (bufLen - ID3_TAG_LEN), + ID3_TAG_LEN); + info->audioShaBytes = ID3_TAG_LEN; + } + else + { + unsigned bytesToRemove; + + bytesToRemove = info->audioShaBytes + bufLen - ID3_TAG_LEN; + sha_update(&info->scontext, info->audioShaBuffer, bytesToRemove); + memmove(info->audioShaBuffer, info->audioShaBuffer + bytesToRemove, + info->audioShaBytes - bytesToRemove); + memcpy(info->audioShaBuffer + info->audioShaBytes - bytesToRemove, + buf, bufLen); + info->audioShaBytes = info->audioShaBytes - bytesToRemove + bufLen; + } + } + else + { + memcpy(info->audioShaBuffer + info->audioShaBytes, buf, bufLen); + info->audioShaBytes += bufLen; + } } Index: mp3.h =================================================================== RCS file: /cvsroot/bitcollider/bitcollider/lib/mp3.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -r1.3 -r1.4 *** mp3.h 2001/05/18 01:00:54 1.3 --- mp3.h 2001/07/31 18:49:20 1.4 *************** *** 29,32 **** --- 29,34 ---- unsigned char *startBuffer; unsigned int startBytes; + unsigned char *audioShaBuffer, audioShaExtra[3]; + unsigned int audioShaBytes; } mp3_info; |