#define IS_VALID_FRAME_MP3(x) \
((((x)[0] & mp3FrameMasking[0]) == mp3FrameDataValid[0]) && \
- (((x)[1] & mp3FrameMasking[1]) == mp3FrameDataValid[1]) && \
- (((x)[2] & mp3FrameMasking[2]) == mp3FrameDataValid[2]) && \
- (((x)[3] & mp3FrameMasking[3]) == mp3FrameDataValid[3]))
+ (((x)[1] & mp3FrameMasking[1]) == mp3FrameDataValid[1]) && \
+ (((x)[2] & mp3FrameMasking[2]) == mp3FrameDataValid[2]) && \
+ (((x)[3] & mp3FrameMasking[3]) == mp3FrameDataValid[3]))
int mmfile_format_close_mp3(MMFileFormatContext *formatContext);
/* internal */
-static int mmf_file_mp3_get_infomation(char *src, AvFileContentInfo *pInfo);
+static int mmf_file_mp3_get_tag_info(char *src, AvFileContentInfo *pInfo);
+static int mmf_file_mp3_get_stream_info(char *src, AvFileContentInfo *pInfo);
+
EXPORT_API
int mmfile_format_open_mp3(MMFileFormatContext *formatContext)
return MMFILE_FORMAT_FAIL;
}
- if (formatContext->pre_checked == 0) {
- ret = MMFileFormatIsValidMP3(NULL, formatContext->uriFileName, 5);
- if (ret == 0) {
- debug_error(DEBUG, "It is not mp3 file\n");
- return MMFILE_FORMAT_FAIL;
- }
+ ret = MMFileFormatIsValidMP3(NULL, formatContext->uriFileName, 5);
+ if (ret == 0) {
+ debug_error(DEBUG, "It is not mp3 file\n");
+ return MMFILE_FORMAT_FAIL;
}
-
formatContext->ReadStream = mmfile_format_read_stream_mp3;
formatContext->ReadFrame = mmfile_format_read_frame_mp3;
formatContext->ReadTag = mmfile_format_read_tag_mp3;
formatContext->privateFormatData = privateData;
- ret = mmf_file_mp3_get_infomation(formatContext->uriFileName, privateData);
- if (ret == -1) {
- debug_error(DEBUG, "error: mmfile_format_read_stream_mp3\n");
- goto exception;
- }
-
return MMFILE_FORMAT_SUCCESS;
-
-exception:
- mmfile_format_close_mp3(formatContext);
- return MMFILE_FORMAT_FAIL;
}
return MMFILE_FORMAT_FAIL;
}
+ if (mmf_file_mp3_get_stream_info(formatContext->uriFileName, formatContext->privateFormatData) < 0) {
+ debug_error(DEBUG, "getting stream information is failed");
+ return MMFILE_FORMAT_FAIL;
+ }
+
privateData = formatContext->privateFormatData;
formatContext->duration = privateData->duration;
formatContext->audioTotalTrackNum = 1;
formatContext->nbStreams = 1;
formatContext->streams[MMFILE_AUDIO_STREAM] = mmfile_malloc(sizeof(MMFileFormatStream));
- if (NULL == formatContext->streams[MMFILE_AUDIO_STREAM]) {
+ if (!formatContext->streams[MMFILE_AUDIO_STREAM]) {
debug_error(DEBUG, "formatContext->streams[MMFILE_AUDIO_STREAM] is NULL\n");
return MMFILE_FORMAT_FAIL;
}
return MMFILE_FORMAT_FAIL;
}
+ if (mmf_file_mp3_get_tag_info(formatContext->uriFileName, formatContext->privateFormatData) < 0) {
+ debug_error(DEBUG, "getting tag information is failed");
+ return MMFILE_FORMAT_FAIL;
+ }
+
privateData = formatContext->privateFormatData;
- if (privateData->pTitle) formatContext->title = mmfile_strdup(privateData->pTitle);
- if (privateData->pArtist) formatContext->artist = mmfile_strdup(privateData->pArtist);
- if (privateData->pAuthor) formatContext->author = mmfile_strdup(privateData->pAuthor);
- if (privateData->pCopyright) formatContext->copyright = mmfile_strdup(privateData->pCopyright);
- if (privateData->pComment) formatContext->comment = mmfile_strdup(privateData->pComment);
- if (privateData->pAlbum) formatContext->album = mmfile_strdup(privateData->pAlbum);
- if (privateData->pAlbum_Artist) formatContext->album_artist = mmfile_strdup(privateData->pAlbum_Artist);
- if (privateData->pYear) formatContext->year = mmfile_strdup(privateData->pYear);
- if (privateData->pGenre) formatContext->genre = mmfile_strdup(privateData->pGenre);
- if (privateData->pTrackNum) formatContext->tagTrackNum = mmfile_strdup(privateData->pTrackNum);
- if (privateData->pComposer) formatContext->composer = mmfile_strdup(privateData->pComposer);
- if (privateData->pContentGroup) formatContext->classification = mmfile_strdup(privateData->pContentGroup);
- if (privateData->pConductor) formatContext->conductor = mmfile_strdup(privateData->pConductor);
- if (privateData->pUnsyncLyrics) formatContext->unsyncLyrics = mmfile_strdup(privateData->pUnsyncLyrics);
- if (privateData->pSyncLyrics) formatContext->syncLyrics = privateData->pSyncLyrics;
- if (privateData->syncLyricsNum) formatContext->syncLyricsNum = privateData->syncLyricsNum;
- if (privateData->pRecDate) formatContext->recDate = mmfile_strdup(privateData->pRecDate);
+ formatContext->title = mmfile_strdup(privateData->pTitle);
+ formatContext->artist = mmfile_strdup(privateData->pArtist);
+ formatContext->copyright = mmfile_strdup(privateData->pCopyright);
+ formatContext->comment = mmfile_strdup(privateData->pComment);
+ formatContext->album = mmfile_strdup(privateData->pAlbum);
+ formatContext->album_artist = mmfile_strdup(privateData->pAlbum_Artist);
+ formatContext->year = mmfile_strdup(privateData->pYear);
+ formatContext->genre = mmfile_strdup(privateData->pGenre);
+ formatContext->tagTrackNum = mmfile_strdup(privateData->pTrackNum);
+ formatContext->composer = mmfile_strdup(privateData->pComposer);
+ formatContext->classification = mmfile_strdup(privateData->pContentGroup);
+ formatContext->conductor = mmfile_strdup(privateData->pConductor);
+ formatContext->unsyncLyrics = mmfile_strdup(privateData->pUnsyncLyrics);
+ formatContext->syncLyrics = privateData->pSyncLyrics;
+ formatContext->syncLyricsNum = privateData->syncLyricsNum;
+ formatContext->recDate = mmfile_strdup(privateData->pRecDate);
+ formatContext->part_of_set = mmfile_strdup(privateData->pPartOfASet);
if (privateData->imageInfo.imageLen > 0) {
formatContext->artwork = mmfile_malloc(privateData->imageInfo.imageLen);
}
debug_msg(RELEASE, "Xing header: sampling-rate:%d, stream-size:%d, frame-number:%d\n",
- headData->sampRate, headData->bytes, headData->frames);
+ headData->sampRate, headData->bytes, headData->frames);
return 1; /* success */
}
buf += 2;
headData->framesPerTable = __AvExtractI2(buf);
- debug_msg(RELEASE, "Vbri header: sampling-rate:%d, stream-size:%d, frame-number:%d\n",
- headData->sampRate, headData->bytes, headData->frames);
+ debug_msg(RELEASE, "Vbri header: sampling-rate:%d, stream-size:%d, frame-number:%d\n", headData->sampRate, headData->bytes, headData->frames);
return true; /* success */
}
if (VALID_SYNC(buf)) {
mp3FrameDataValid[0] = (0xFF) & (mp3FrameMasking[0]);
- mp3FrameDataValid[1] = (0xE0 | (buf[AV_MP3HDR_VERSION_OFS] & AV_MP3HDR_VERSION_M)
- | (buf[AV_MP3HDR_LAYER_OFS] & AV_MP3HDR_LAYER_M)) & (mp3FrameMasking[1]);
- mp3FrameDataValid[2] = (buf[AV_MP3HDR_SAMPLERATE_OFS] & AV_MP3HDR_SAMPLERATE_M) &
- (mp3FrameMasking[2]);
- mp3FrameDataValid[3] = (buf[AV_MP3HDR_CHANNEL_OFS] & AV_MP3HDR_CHANNEL_M) &
- (mp3FrameMasking[3]);
+ mp3FrameDataValid[1] = (0xE0 | (buf[AV_MP3HDR_VERSION_OFS] & AV_MP3HDR_VERSION_M) | (buf[AV_MP3HDR_LAYER_OFS] & AV_MP3HDR_LAYER_M)) & (mp3FrameMasking[1]);
+ mp3FrameDataValid[2] = (buf[AV_MP3HDR_SAMPLERATE_OFS] & AV_MP3HDR_SAMPLERATE_M) & (mp3FrameMasking[2]);
+ mp3FrameDataValid[3] = (buf[AV_MP3HDR_CHANNEL_OFS] & AV_MP3HDR_CHANNEL_M) & (mp3FrameMasking[3]);
- debug_msg(RELEASE, "*** [%02x][%02x][%02x][%02x] : [%02x][%02x][%02x][%02x]",
- buf[0], buf[1], buf[2], buf[3],
- mp3FrameDataValid[0], mp3FrameDataValid[1], mp3FrameDataValid[2], mp3FrameDataValid[3]);
+ debug_msg(RELEASE, "*** [%02x][%02x][%02x][%02x] : [%02x][%02x][%02x][%02x]", buf[0], buf[1], buf[2], buf[3], mp3FrameDataValid[0], mp3FrameDataValid[1], mp3FrameDataValid[2], mp3FrameDataValid[3]);
/*
- * MPEG Audio Layer I/II/III frame header
- * from : http://www.mp3-tech.org/programmer/frame_header.html *
- *
- * AAAAAAAA AAABBCCD EEEEFFGH IIJJKLMM
- *
- * A 11 (31-21) Frame sync (all bits must be set)
- * B 2 (20,19) MPEG Audio version ID
- * C 2 (18,17) Layer description
- * D 1 (16) Protection bit
- * E 4 (15,12) Bitrate index
- * F 2 (11,10) Sampling rate frequency index
- * G 1 (9) Padding bit
- * H 1 (8) Private bit. This one is only informative.
- * I 2 (7,6) Channel Mode
- * J 2 (5,4) Mode extension (Only used in Joint stereo)
- * K 1 (3) Copyright
- * L 1 (2) Original
- * M 2 (1,0) Emphasis
- *
- */
+ * MPEG Audio Layer I/II/III frame header
+ * from : http://www.mp3-tech.org/programmer/frame_header.html *
+ *
+ * AAAAAAAA AAABBCCD EEEEFFGH IIJJKLMM
+ *
+ * A 11 (31-21) Frame sync (all bits must be set)
+ * B 2 (20,19) MPEG Audio version ID
+ * C 2 (18,17) Layer description
+ * D 1 (16) Protection bit
+ * E 4 (15,12) Bitrate index
+ * F 2 (11,10) Sampling rate frequency index
+ * G 1 (9) Padding bit
+ * H 1 (8) Private bit. This one is only informative.
+ * I 2 (7,6) Channel Mode
+ * J 2 (5,4) Mode extension (Only used in Joint stereo)
+ * K 1 (3) Copyright
+ * L 1 (2) Original
+ * M 2 (1,0) Emphasis
+ *
+ */
/* Simple check for version, layer, bitrate, samplerate */
if ((buf[1] & 0x18) != 0x08 && /* 000XX000 : MPEG Audio version ID, XX=01 - reserved => 00001000(0x08) */
- (buf[1] & 0x06) != 0x00 && /* 00000XX0 : Layer description, XX=00 - reserved => 00000000(0x00) */
- (buf[2] & 0xF0) != 0xF0 && /* XXXX0000 : Bitrate index, XX=1111 - bad => 11110000(0xF0) */
- (buf[2] & 0x0C) != 0x0C) { /* 0000XX00 : Sampling rate frequency index, XX=11 -reserved => 00001100(0x0C) */
+ (buf[1] & 0x06) != 0x00 && /* 00000XX0 : Layer description, XX=00 - reserved => 00000000(0x00) */
+ (buf[2] & 0xF0) != 0xF0 && /* XXXX0000 : Bitrate index, XX=1111 - bad => 11110000(0xF0) */
+ (buf[2] & 0x0C) != 0x0C) { /* 0000XX00 : Sampling rate frequency index, XX=11 -reserved => 00001100(0x0C) */
bSync = true;
}
debug_msg(RELEASE, "=> %s\n", bSync ? "Good!" : "Bad...");
/* 1. Check the version of mp3 */
result = header[1] & MASK_MPEG;
switch (result) {
- case MASK_MPEG_1:
- pInfo->mpegVersion = AV_MPEG_VER_1;
- break;
- case MASK_MPEG_2:
- pInfo->mpegVersion = AV_MPEG_VER_2;
- break;
- case MASK_MPEG_25:
- pInfo->mpegVersion = AV_MPEG_VER_25;
- break;
- default:
- return false;
+ case MASK_MPEG_1:
+ pInfo->mpegVersion = AV_MPEG_VER_1;
+ break;
+ case MASK_MPEG_2:
+ pInfo->mpegVersion = AV_MPEG_VER_2;
+ break;
+ case MASK_MPEG_25:
+ pInfo->mpegVersion = AV_MPEG_VER_25;
+ break;
+ default:
+ return false;
}
/* 2. Get a layer */
result = header[1] & MASK_LAYER;
switch (result) {
- case MASK_LAYER_1:
- pInfo->layer = AV_MP3_LAYER_1;
- break;
- case MASK_LAYER_2:
- pInfo->layer = AV_MP3_LAYER_2;
- break;
- case MASK_LAYER_3:
- pInfo->layer = AV_MP3_LAYER_3;
- break;
- default:
- return false;
+ case MASK_LAYER_1:
+ pInfo->layer = AV_MP3_LAYER_1;
+ break;
+ case MASK_LAYER_2:
+ pInfo->layer = AV_MP3_LAYER_2;
+ break;
+ case MASK_LAYER_3:
+ pInfo->layer = AV_MP3_LAYER_3;
+ break;
+ default:
+ return false;
}
/* 3. bitrate */
/* 5. channel */
result = header[3] & MASK_CHANNEL;
switch (result) {
- case MASK_CHANNEL_ST:
- pInfo->channelIndex = 0;
- pInfo->channels = 2;
- break;
- case MASK_CHANNEL_JS:
- pInfo->channelIndex = 1;
- pInfo->channels = 2;
- break;
- case MASK_CHANNEL_DC:
- pInfo->channelIndex = 2;
- pInfo->channels = 2;
- break;
- case MASK_CHANNEL_MN:
- pInfo->channelIndex = 3;;
- pInfo->channels = 1;
- break;
- default:
- return false;
+ case MASK_CHANNEL_ST:
+ pInfo->channelIndex = 0;
+ pInfo->channels = 2;
+ break;
+ case MASK_CHANNEL_JS:
+ pInfo->channelIndex = 1;
+ pInfo->channels = 2;
+ break;
+ case MASK_CHANNEL_DC:
+ pInfo->channelIndex = 2;
+ pInfo->channels = 2;
+ break;
+ case MASK_CHANNEL_MN:
+ pInfo->channelIndex = 3;;
+ pInfo->channels = 1;
+ break;
+ default:
+ return false;
}
/* 6. padding */
else
pInfo->bPadding = false;
- debug_msg(RELEASE, "=> samplerate=%d, bitrate=%d, layer=%d, version=%d, channel=%d, padding=%d",
- pInfo->sampleRate, pInfo->bitRate, pInfo->layer, pInfo->mpegVersion, pInfo->channels, pInfo->bPadding);
+ debug_msg(RELEASE, "=> samplerate=%d, bitrate=%d, layer=%d, version=%d, channel=%d, padding=%d", pInfo->sampleRate, pInfo->bitRate, pInfo->layer, pInfo->mpegVersion, pInfo->channels, pInfo->bPadding);
return true;
}
memset(&data, 0x00, sizeof(AvVBRIHeadData));
/* 1. Xing Header */
- if ((pInfo->mpegVersion == AV_MPEG_VER_1) && (pInfo->channels == 2)) {
- if (buf[36] != 'V') return false;
- if (buf[37] != 'B') return false;
- if (buf[38] != 'R') return false;
- if (buf[39] != 'I') return false;
- } else if ((pInfo->mpegVersion == AV_MPEG_VER_2) && (pInfo->channels == 1)) {
- if (buf[36] != 'V') return false;
- if (buf[37] != 'B') return false;
- if (buf[38] != 'R') return false;
- if (buf[39] != 'I') return false;
- } else {
- if (buf[36] != 'V') return false;
- if (buf[37] != 'B') return false;
- if (buf[38] != 'R') return false;
- if (buf[39] != 'I') return false;
- }
+ if (buf[36] != 'V') return false;
+ if (buf[37] != 'B') return false;
+ if (buf[38] != 'R') return false;
+ if (buf[39] != 'I') return false;
/* 2. TOC */
if (pInfo->pToc)
pInfo->bitRate = frameSize * pInfo->sampleRate / 48000;
} else {
frameSize += 0/* FIXME: possible_free_framelen*/;
- pInfo->bitRate = frameSize * pInfo->sampleRate /
- ((pInfo->layer == AV_MP3_LAYER_3 && pInfo->mpegVersion != AV_MPEG_VER_1) ? 72000 : 144000);
+ pInfo->bitRate = frameSize * pInfo->sampleRate / ((pInfo->layer == AV_MP3_LAYER_3 && pInfo->mpegVersion != AV_MPEG_VER_1) ? 72000 : 144000);
}
} else {
/* calculating */
if (pInfo->layer == 1) {
frameSize = ((12000 * pInfo->bitRate / pInfo->sampleRate) + frameSize) * 4;
} else {
- frameSize += ((pInfo->layer == AV_MP3_LAYER_3
- && pInfo->mpegVersion != AV_MPEG_VER_1) ? 72000 : 144000) * pInfo->bitRate / pInfo->sampleRate;
+ frameSize += ((pInfo->layer == AV_MP3_LAYER_3 && pInfo->mpegVersion != AV_MPEG_VER_1) ? 72000 : 144000) * pInfo->bitRate / pInfo->sampleRate;
}
}
}
#endif
-
static bool
-__AvGetXingBitrate(AvFileContentInfo *pInfo)
+__AvGetBitrate(AvFileContentInfo *pInfo)
{
float br, factor;
int padding;
return true;
}
-static bool
-__AvGetVBRIBitrate(AvFileContentInfo *pInfo)
+
+static bool __AvGetFileSize(MMFileIOHandle *hFile, long long *file_size)
{
- float br, factor;
- int padding;
+ long long fileLen = 0;
- if (pInfo == NULL || pInfo->bVbr == false)
+ mmfile_seek(hFile, 0L, SEEK_END);
+ fileLen = mmfile_tell(hFile);
+ if (fileLen <= 0) {
+ debug_error(DEBUG, "file is too small.\n");
return false;
+ }
+ mmfile_seek(hFile, 0L, SEEK_SET);
- if (pInfo->bPadding)
- padding = 1;
- else
- padding = 0;
+ *file_size = fileLen;
- if (pInfo->mpegVersion == AV_MPEG_VER_1) { /* MPEG version 1 */
- if (pInfo->layer == AV_MP3_LAYER_1) /* Layer 1 */
- factor = 48000.0;
- else /* Layer 2, 3 */
- factor = 144000.0;
- } else { /* MPEG version 2 */
- if (pInfo->layer == AV_MP3_LAYER_1) /* Layer 1 */
- factor = 24000.0;
- else /* Layer 2, 3 */
- factor = 72000.0;
+ return true;
+}
+
+static bool __AvGetID3v1Header(unsigned char *buf, size_t buf_size, int *offset)
+{
+ unsigned char TagV1ID[4] = { 0x54, 0x41, 0x47}; /* TAG */
+ int id3v1_offset = 0;
+
+ if (!buf || buf_size < 3) {
+ debug_error(DEBUG, "Invalid parameters!");
+ return false;
}
- br = (pInfo->frameSize - padding) * pInfo->sampleRate / factor;
+ id3v1_offset = __AvMemstr(buf, TagV1ID, 3, TAGV1_SEEK_GAP + 5);
+ if (id3v1_offset < 0) {
+ debug_msg(RELEASE, "ID3v1 is not existing");
+ return false;
+ }
- pInfo->bitRate = (int) br;
+ if (offset)
+ *offset = id3v1_offset;
+ debug_msg(RELEASE, "ID3v1 is existing");
return true;
}
-static int __AvGetLastID3offset(MMFileIOHandle *fp, unsigned int *offset)
+static bool __AvGetID3v2Header(unsigned char *buf, size_t buf_size, AvTagVer2AdditionalData *id3v2info)
{
-#define _MMFILE_MP3_TAGV2_HEADER_LEN 10
-#define _MMFILE_GET_INT_NUMBER(buff) (int)((((int)(buff)[0]) << 24) | (((int)(buff)[1]) << 16) | (((int)(buff)[2]) << 8) | (((int)(buff)[3])))
+ if (!buf || buf_size < MP3_TAGv2_HEADER_LEN || !id3v2info) {
+ debug_error(DEBUG, "Invalid parameters!");
+ return false;
+ }
+
+ if (!IS_ID3V2_TAG(buf)) { /* ID3 */
+ debug_error(RELEASE, "Invalid ID3v2 identifier !");
+ return false;
+ }
+
+ /* weak id3v2 tag check */
+ if (buf[3] == 0xFF || buf[4] == 0xFF || buf[6] >= 0x80 || buf[7] >= 0x80 || buf[8] >= 0x80 || buf[9] >= 0x80) {
+ debug_error(RELEASE, "Invalid ID3v2 base header!");
+ return false;
+ }
+
+ if (buf[3] > 0x04) {
+ debug_error(RELEASE, "Invalid or not supported ID3v2 version(%d)!", buf[3]);
+ return false;
+ }
+
+ id3v2info->tagVersion = buf[3];
+ id3v2info->tagLen = MP3_TAGv2_HEADER_LEN;
+ id3v2info->tagLen += (unsigned long)buf[6] << 21 | (unsigned long)buf[7] << 14 | (unsigned long)buf[8] << 7 | (unsigned long)buf[9];
+ debug_msg(RELEASE, "ID3v2 version(%d), length (%d)\n", id3v2info->tagVersion, id3v2info->tagLen);
- unsigned char tagHeader[_MMFILE_MP3_TAGV2_HEADER_LEN] = {0, };
- unsigned int tagInfoSize = 0;
- unsigned int acc_tagsize = 0;
- int tagVersion = 0;
- int encSize = 0;
- int readed = 0;
+ return true;
+}
+
+static int __AvGetLastID3v2offset(MMFileIOHandle *fp, unsigned int *offset)
+{
+ unsigned char tagHeader[MP3_TAGv2_HEADER_LEN] = {0, };
+ unsigned int total_taglen = 0;
+ int read = 0;
+ AvTagVer2AdditionalData tagInfo = { 0, };
/*init offset*/
*offset = 0;
_START_TAG_SEARCH:
- readed = mmfile_read(fp, tagHeader, _MMFILE_MP3_TAGV2_HEADER_LEN);
- if (readed != _MMFILE_MP3_TAGV2_HEADER_LEN) {
+ read = mmfile_read(fp, tagHeader, MP3_TAGv2_HEADER_LEN);
+ if (read != MP3_TAGv2_HEADER_LEN) {
debug_error(DEBUG, "read error occured.\n");
return 0;
}
- if (memcmp(tagHeader, "ID3", 3) == 0) {
- debug_msg(RELEASE, "'ID3' found.\n");
- } else {
- debug_msg(RELEASE, "'ID3' not found.\n");
- goto search_end;
- }
-
- /**@note weak id3v2 tag checking*/
- if (tagHeader[3] != 0xFF && tagHeader[4] != 0xFF &&
- (tagHeader[6] & 0x80) == 0 && (tagHeader[7] & 0x80) == 0 &&
- (tagHeader[8] & 0x80) == 0 && (tagHeader[9] & 0x80) == 0) {
- debug_msg(RELEASE, "good ID3V2 tag.\n");
- } else {
- debug_warning(DEBUG, "It's bad ID3V2 tag.\n");
+ if (!__AvGetID3v2Header(tagHeader, MP3_TAGv2_HEADER_LEN, &tagInfo)) {
+ debug_msg(RELEASE, "Invalid ID3 header\n");
goto search_end;
}
- tagVersion = tagHeader[3];
-
- if (tagVersion > 4) {
- debug_msg(RELEASE, "Tag version not supported\n");
- goto search_end;
- }
-
- encSize = _MMFILE_GET_INT_NUMBER(&tagHeader[6]);
- tagInfoSize = _MMFILE_MP3_TAGV2_HEADER_LEN;
- tagInfoSize += (((encSize & 0x0000007F) >> 0) | ((encSize & 0x00007F00) >> 1) | ((encSize & 0x007F0000) >> 2) | ((encSize & 0x7F000000) >> 3));
-
/**@note unfortunately, some contents has many id3 tag.*/
- acc_tagsize += tagInfoSize;
- debug_msg(RELEASE, "tag size: %u, offset: %u\n", tagInfoSize, acc_tagsize);
+ total_taglen += tagInfo.tagLen;
+ debug_msg(RELEASE, "tag size: %u, offset: %u\n", tagInfo.tagLen, total_taglen);
- mmfile_seek(fp, acc_tagsize, MMFILE_SEEK_SET);
- *offset = acc_tagsize;
+ mmfile_seek(fp, total_taglen, MMFILE_SEEK_SET);
+ *offset = total_taglen;
goto _START_TAG_SEARCH;
search_end:
return 1;
}
+static bool __AvGetID3v1Tags(unsigned char *buf, int offset, AvFileContentInfo *pInfo)
+{
+ unsigned char TmpBuff[MP3TAGINFO_SIZE] = {0, };
+
+ if (!buf || !pInfo || offset < 0) {
+ debug_error(DEBUG, "Invalid parameters!");
+ return true;
+ }
+
+ if (pInfo->tagV2Info.tagLen != 0 || offset != TAGV1_SEEK_GAP) {
+ debug_msg(RELEASE, "No need to check id3v1");
+ return true;
+ }
+
+ memcpy(TmpBuff, buf, MP3TAGINFO_SIZE);
+
+ return mm_file_id3tag_parse_v110(pInfo, TmpBuff);
+}
+
+static void __AvGetID3v2Tags(unsigned char *buf, AvFileContentInfo *pInfo)
+{
+ if (!buf || !pInfo || pInfo->tagV2Info.tagLen == 0) {
+ debug_error(DEBUG, "Invalid parameters!");
+ return;
+ }
+ if (pInfo->tagV2Info.tagVersion == 0x02) {
+ mm_file_id3tag_parse_v222(pInfo, buf);
+ } else if (pInfo->tagV2Info.tagVersion == 0x03) {
+ mm_file_id3tag_parse_v223(pInfo, buf);
+ } else if (pInfo->tagV2Info.tagVersion == 0x04) {
+ mm_file_id3tag_parse_v224(pInfo, buf); /* currently 2.4 ver pased by 2.3 routine */
+ } else {
+ debug_msg(RELEASE, "Invalid tag version(%d)\n", pInfo->tagV2Info.tagVersion);
+ }
+}
/*
* This fuction retrieves the start position of header.
* This function returns the start position of header.
*/
static int
-__AvFindStartOfMp3Header(MMFileIOHandle *hFile, unsigned char *buf, AvFileContentInfo *pInfo)
+__AvFindStartOfMp3Header(unsigned char *buf, unsigned long bufLen, AvFileContentInfo *pInfo)
{
unsigned int index = 0;
- long readLen;
unsigned long id3v2TagLen = 0;
unsigned char *pHeader = NULL;
unsigned long preHeaderGap = 0;
unsigned long frameLen = 0;
unsigned long nextFrameOff = 0; /* Offset to the start of the next frame */
unsigned long nextFrameOffEnd = 0;
- unsigned long bufLen = 0;
bool bFoundSync = false;
unsigned long minLen;
- if (pInfo->fileLen > ((long long)_AV_MP3_HEADER_POSITION_MAX + (long long)pInfo->tagV2Info.tagLen))
- bufLen = _AV_MP3_HEADER_POSITION_MAX;
- else
- bufLen = pInfo->fileLen - pInfo->tagV2Info.tagLen;
-
- if (IS_ID3V2_TAG(buf)) {
-
-
- if (pInfo->tagV2Info.tagVersion == 0x02) {
-
- if (!mm_file_id3tag_parse_v222(pInfo, buf))
- pInfo->tagV2Info.tagLen = 0;
- } else if (pInfo->tagV2Info.tagVersion == 0x03) {
-
- if (!mm_file_id3tag_parse_v223(pInfo, buf))
- pInfo->tagV2Info.tagLen = 0;
- } else if (pInfo->tagV2Info.tagVersion == 0x04) {
-
- if (!mm_file_id3tag_parse_v224(pInfo, buf)) /* currently 2.4 ver pased by 2.3 routine */
- pInfo->tagV2Info.tagLen = 0;
- } else {
- debug_msg(RELEASE, "pInfo->tagV2Info.tagVersion(%d)\n", pInfo->tagV2Info.tagVersion);
- }
-
- id3v2TagLen = pInfo->tagV2Info.tagLen;
+ if (!buf || !pInfo) {
+ debug_error(DEBUG, "Invalid parameters");
+ return -1;
+ }
- debug_msg(RELEASE, "id3v2TagLen(%lu)\n", id3v2TagLen);
+ id3v2TagLen = pInfo->tagV2Info.tagLen;
- if (id3v2TagLen) {
- if (mmfile_seek(hFile, id3v2TagLen, SEEK_SET) < 0) {
- debug_error(DEBUG, "seek failed.\n");
- return -1;
- }
- if ((readLen = mmfile_read(hFile, buf, bufLen)) <= 0) {
- debug_error(DEBUG, "seek failed.\n");
- return -1;
- }
- }
- while (1) {
- if (preHeaderGap == bufLen - 2)
- break;
- if (__AvIsValidHeader(pInfo, buf + preHeaderGap))
- break;
- preHeaderGap++;
- }
-
- } else {
- while (1) {
- if (preHeaderGap == bufLen - 2)
- break;
- if (__AvIsValidHeader(pInfo, buf + preHeaderGap))
- break;
- preHeaderGap++;
- }
+ debug_msg(RELEASE, "id3v2TagLen(%lu)\n", id3v2TagLen);
+ while (1) {
+ if (preHeaderGap == bufLen - 2)
+ break;
+ if (__AvIsValidHeader(pInfo, buf + preHeaderGap))
+ break;
+ preHeaderGap++;
}
+
minLen = 4;
buf += preHeaderGap;
}
if (__AvParseMp3Header(pInfo, pHeader) == false) {
/*return -1; */
- if (pHeader)
- _FREE_EX(pHeader);
+ mmfile_free(pHeader);
debug_warning(DEBUG, "Mp3 parse header failed & index(%d)\n", index);
buf++;
index++;
debug_msg(RELEASE, "This header is valid. index(%d)\n", index);
}
- if (__AvParseXingHeader(pInfo, pHeader)) {
- __AvGetXingBitrate(pInfo);
- } else if (__AvParseVBRIHeader(pInfo, pHeader)) {
- __AvGetVBRIBitrate(pInfo);
- }
+ if (__AvParseXingHeader(pInfo, pHeader) || __AvParseVBRIHeader(pInfo, pHeader))
+ __AvGetBitrate(pInfo);
if (pInfo->bVbr) {
- if (pHeader)
- _FREE_EX(pHeader);
+ mmfile_free(pHeader);
bFoundSync = true;
break;
} else {
if (__AvIsValidHeader(pInfo, pHeader)) {
- if (pHeader)
- _FREE_EX(pHeader);
+ mmfile_free(pHeader);
__AvGetMp3FrameSize(pInfo);
pInfo->datafileLen = pInfo->fileLen - pInfo->headerPos;
debug_warning(DEBUG, "Is not vaild header pHeader\n");
}
}
- if (pHeader)
- _FREE_EX(pHeader);
+ mmfile_free(pHeader);
} else {
debug_warning(RELEASE, "Mp3 file frist byte is 0xff, but not header sync\n");
}
index++;
}
- _FREE_EX(pHeader);
+ mmfile_free(pHeader);
- if (mmfile_seek(hFile, 0, SEEK_SET) < 0) {
- debug_error(DEBUG, "seek error!\n");
- return -1;
- }
if (index > (bufLen - minLen)) {
debug_warning(DEBUG, "Mp3 file sync is not found : index(%u) bufLen(%lu), minLen(%lu)\n", index, bufLen, minLen);
return -1;
}
/*
- * This function retrieves the mp3 information.
- * Param szFileName [in] Specifies a mp3 file path.
- * Param _frame [out] Specifies a struct pointer for mp3 information.
+ * This function retrieves the ID3 tag information.
+ * Param filename [in] Specifies a mp3 file path.
+ * Param pInfo [out] Specifies a struct pointer for ID3 tag information.
* This function returns true on success, or false on failure.
*/
-static int mmf_file_mp3_get_infomation(char *filename, AvFileContentInfo *pInfo)
+static int mmf_file_mp3_get_tag_info(char *filename, AvFileContentInfo *pInfo)
{
MMFileIOHandle *hFile;
- unsigned char header[256];
- unsigned long frameSamples = 0;
unsigned char *buf = NULL;
unsigned char *v2TagExistCheck = NULL;
- int readAmount = 0, readedDataLen = 0;
unsigned char TagBuff[MP3TAGINFO_SIZE + TAGV1_SEEK_GAP];
- unsigned char TagV1ID[4] = { 0x54, 0x41, 0x47}; /*TAG */
int tagHeaderPos = 0;
int ret = 0;
unsigned int head_offset = 0;
return -1;
}
- mmfile_seek(hFile, 0L, SEEK_END);
- pInfo->fileLen = mmfile_tell(hFile);
- if (pInfo->fileLen <= 0) {
+ if (!__AvGetFileSize(hFile, &pInfo->fileLen)) {
debug_error(DEBUG, "file is too small.\n");
goto EXCEPTION;
}
- mmfile_seek(hFile, 0L, SEEK_SET);
v2TagExistCheck = mmfile_malloc(MP3_TAGv2_HEADER_LEN);
- if (v2TagExistCheck == NULL) {
+ if (!v2TagExistCheck) {
debug_error(DEBUG, "malloc failed.\n");
goto EXCEPTION;
}
- if (mmfile_read(hFile, v2TagExistCheck, MP3_TAGv2_HEADER_LEN) > 0) {
- if (IS_ID3V2_TAG(v2TagExistCheck)) {
- if (!(v2TagExistCheck[3] == 0xFF || v2TagExistCheck[4] == 0xFF || v2TagExistCheck[6] >= 0x80 || v2TagExistCheck[7] >= 0x80 || v2TagExistCheck[8] >= 0x80 || v2TagExistCheck[9] >= 0x80)) {
- if (!(v2TagExistCheck[3] > 0x04)) {
- pInfo->tagV2Info.tagVersion = v2TagExistCheck[3];
- pInfo->tagV2Info.tagLen = MP3_TAGv2_HEADER_LEN;
- pInfo->tagV2Info.tagLen += (unsigned long)v2TagExistCheck[6] << 21 | (unsigned long)v2TagExistCheck[7] << 14 | (unsigned long)v2TagExistCheck[8] << 7 | (unsigned long)v2TagExistCheck[9];
- debug_msg(RELEASE, "pInfo->tagV2Info.tagLen(%d), pInfo->tagV2Info.tagVersion(%d)\n", pInfo->tagV2Info.tagLen, pInfo->tagV2Info.tagVersion);
- } else {
- debug_msg(RELEASE, "tag is a not supported version(%d)\n", v2TagExistCheck[3]);
- }
- } else {
- debug_msg(RELEASE, "tag is a tag data is valid.\n");
- }
- } else {
- debug_msg(RELEASE, "this mp3 file is not included ID3v2 tag info!\n");
- }
- } else {
+ /* check ID3v2 header */
+ if (mmfile_read(hFile, v2TagExistCheck, MP3_TAGv2_HEADER_LEN) != MP3_TAGv2_HEADER_LEN) {
debug_error(DEBUG, "v2TagExistCheck value read fail!\n");
- if (v2TagExistCheck)
- _FREE_EX(v2TagExistCheck);
+ mmfile_free(v2TagExistCheck);
goto EXCEPTION;
}
- if (v2TagExistCheck)
- _FREE_EX(v2TagExistCheck);
-
- if (!(pInfo->fileLen > pInfo->tagV2Info.tagLen))
- pInfo->tagV2Info.tagLen = 0;
+ __AvGetID3v2Header(v2TagExistCheck, MP3_TAGv2_HEADER_LEN, &pInfo->tagV2Info);
+ mmfile_free(v2TagExistCheck);
if (mmfile_seek(hFile, 0L, SEEK_SET) < 0)
goto EXCEPTION;
debug_msg(RELEASE, "pInfo->fileLen(%lld)\n", pInfo->fileLen);
- if (pInfo->fileLen > ((long long)_AV_MP3_HEADER_POSITION_MAX + (long long)pInfo->tagV2Info.tagLen)) {
- readAmount = _AV_MP3_HEADER_POSITION_MAX + pInfo->tagV2Info.tagLen;
- buf = mmfile_malloc(readAmount);
- if (buf == NULL) {
- debug_error(DEBUG, "malloc failed.\n");
- goto EXCEPTION;
- }
+ /* read file to get ID3v2 */
+ if (pInfo->fileLen <= (long long)pInfo->tagV2Info.tagLen)
+ pInfo->tagV2Info.tagLen = pInfo->fileLen;
- while (readAmount > 0) {
- if (readAmount >= AV_MP3_HEADER_READ_MAX) {
- if ((readedDataLen <= _AV_MP3_HEADER_POSITION_MAX + pInfo->tagV2Info.tagLen)
- && (mmfile_read(hFile, buf + readedDataLen, AV_MP3_HEADER_READ_MAX) <= 0)) {
- if (buf)
- _FREE_EX(buf);
+ debug_msg(RELEASE, "buf size(%d)\n", pInfo->tagV2Info.tagLen);
- goto EXCEPTION;
- } else {
- debug_msg(RELEASE, "Reading buf readedDataLen(%d) readAmount (%d)\n", readedDataLen, readAmount);
- }
- } else {
- if ((readedDataLen <= _AV_MP3_HEADER_POSITION_MAX + pInfo->tagV2Info.tagLen)
- && (mmfile_read(hFile, buf + readedDataLen, readAmount) <= 0)) {
- if (buf)
- _FREE_EX(buf);
+ buf = mmfile_malloc(pInfo->tagV2Info.tagLen);
+ if (!buf) {
+ debug_error(DEBUG, "malloc failed.\n");
+ goto EXCEPTION;
+ }
- goto EXCEPTION;
- } else {
- debug_msg(RELEASE, "The remained buf readed! readedDataLen(%d) readAmount (%d)\n", readedDataLen, readAmount);
- }
- }
+ if (mmfile_read(hFile, buf, pInfo->tagV2Info.tagLen) != pInfo->tagV2Info.tagLen) {
+ mmfile_free(buf);
+ goto EXCEPTION;
+ }
- readAmount -= AV_MP3_HEADER_READ_MAX;
- readedDataLen += AV_MP3_HEADER_READ_MAX;
+ /* Is this needed? */
+ if (__AvGetLastID3v2offset(hFile, &head_offset)) {
+ debug_msg(RELEASE, "search start offset: %u\n", head_offset);
+ pInfo->tagV2Info.tagLen = head_offset;
+ }
+
+ /* get ID3v2 information */
+ __AvGetID3v2Tags(buf, pInfo);
+
+ /* relocate file to read TAG(ID3v1) information */
+ if (mmfile_seek(hFile, -(MP3TAGINFO_SIZE + TAGV1_SEEK_GAP), SEEK_END) < 0)
+ goto EXCEPTION;
- if (readAmount <= 0)
- break;
- }
- } else {
- buf = mmfile_malloc(pInfo->fileLen);
- if (buf == NULL) {
- goto EXCEPTION;
- }
- if (mmfile_read(hFile, buf, pInfo->fileLen) <= 0) {
- if (buf)
- _FREE_EX(buf);
+ pInfo->bV1tagFound = false;
+
+ /* read with TAG(ID3v1) length */
+ if (mmfile_read(hFile, TagBuff, MP3TAGINFO_SIZE + TAGV1_SEEK_GAP) != MP3TAGINFO_SIZE + TAGV1_SEEK_GAP)
+ goto EXCEPTION;
+
+ /* check and get TAG(ID3v1) information */
+ if (__AvGetID3v1Header(TagBuff, MP3TAGINFO_SIZE + TAGV1_SEEK_GAP, &tagHeaderPos)) {
+ pInfo->bV1tagFound = true;
+ if (!__AvGetID3v1Tags((TagBuff + tagHeaderPos), tagHeaderPos, pInfo))
goto EXCEPTION;
- }
}
+ mm_file_id3tag_restore_content_info(pInfo);
- if (__AvGetLastID3offset(hFile, &head_offset)) {
- debug_msg(RELEASE, "search start offset: %u\n", head_offset);
- pInfo->tagV2Info.tagLen = head_offset;
- }
+ mmfile_close(hFile);
- pInfo->headerPos = (long) __AvFindStartOfMp3Header(hFile, buf, pInfo);
+ /*debug print*/
+ debug_msg(RELEASE, "**** Info #1 ****\n");
+ debug_msg(RELEASE, "Title : %s\n", pInfo->pTitle);
+ debug_msg(RELEASE, "Artist : %s\n", pInfo->pArtist);
+ debug_msg(RELEASE, "Album : %s\n", pInfo->pAlbum);
+ debug_msg(RELEASE, "Album_Artist: %s\n", pInfo->pAlbum_Artist);
+ debug_msg(RELEASE, "Year : %s\n", pInfo->pYear);
+ debug_msg(RELEASE, "Comment : %s\n", pInfo->pComment);
+ debug_msg(RELEASE, "TrackNum : %s\n", pInfo->pTrackNum);
+ debug_msg(RELEASE, "Genre : %s\n", pInfo->pGenre);
+ debug_msg(RELEASE, "**** Info #2 ****\n");
+ debug_msg(RELEASE, "Copyright : %s\n", pInfo->pCopyright);
+ debug_msg(RELEASE, "Comment : %s\n", pInfo->pComment);
+ debug_msg(RELEASE, "RecDate : %s\n", pInfo->pRecDate);
+ debug_msg(RELEASE, "PartOfASet : %s\n", pInfo->pPartOfASet);
+ debug_msg(RELEASE, "Encoded by : %s\n", pInfo->pEncBy);
+ debug_msg(RELEASE, "URL : %s\n", pInfo->pURL);
+ debug_msg(RELEASE, "Ori. Artist : %s\n", pInfo->pOriginArtist);
+ debug_msg(RELEASE, "Composer : %s\n", pInfo->pComposer);
+ debug_msg(RELEASE, "Conductor : %s\n", pInfo->pConductor);
+ debug_msg(RELEASE, "Artwork : mime(%s) addr(%p) size(%d)\n", pInfo->imageInfo.imageMIMEType, pInfo->imageInfo.pImageBuf, pInfo->imageInfo.imageLen);
+ debug_msg(RELEASE, "UnsyncLyrics : %s\n", pInfo->pUnsyncLyrics);
+ debug_msg(RELEASE, "SyncLyrics size : %d\n", pInfo->syncLyricsNum);
- debug_msg(RELEASE, "Header Pos: %ld\n", pInfo->headerPos);
+ return 0;
- if (buf)
- _FREE_EX(buf);
+EXCEPTION:
+ debug_error(DEBUG, "Error occured!\n");
+ mmfile_close(hFile);
+ return -1;
+}
- if (pInfo->headerPos == -1)
- goto EXCEPTION;
+/*
+ * This function retrieves the MP3 stream information.
+ * Param filename [in] Specifies a mp3 file path.
+ * Param pInfo [out] Specifies a struct pointer for MP3 stream information.
+ * This function returns true on success, or false on failure.
+ */
+static int mmf_file_mp3_get_stream_info(char *filename, AvFileContentInfo *pInfo)
+{
+ MMFileIOHandle *hFile;
+ unsigned char header[256];
+ unsigned long frameSamples = 0;
+ unsigned char *buf = NULL;
+ unsigned char *v2TagExistCheck = NULL;
+ unsigned char TagBuff[MP3TAGINFO_SIZE + TAGV1_SEEK_GAP];
+ int ret = 0;
+ unsigned int head_offset = 0;
+ unsigned long bufLen = 0;
- if (mmfile_seek(hFile, pInfo->headerPos, SEEK_SET) < 0)
- goto EXCEPTION;
+ debug_fenter(RELEASE);
- if (mmfile_read(hFile, header, 256) <= 0)
- goto EXCEPTION;
+ if (pInfo == NULL || filename == NULL)
+ return -1;
- if (__AvParseMp3Header(pInfo, header) == false)
- goto EXCEPTION;
+ memset(pInfo, 0x00, sizeof(AvFileContentInfo));
- if (__AvParseXingHeader(pInfo, header)) {
- __AvGetXingBitrate(pInfo);
- } else if (__AvParseVBRIHeader(pInfo, header)) {
- __AvGetVBRIBitrate(pInfo);
- } else {
- __AvGetMp3FrameSize(pInfo);
- pInfo->datafileLen = pInfo->fileLen - pInfo->headerPos;
- debug_msg(RELEASE, "Mp3 File FrameSize (%d) pInfo->headerPos(%ld)\n", pInfo->frameSize, pInfo->headerPos);
+ pInfo->tagV2Info.tagLen = 0;
+ pInfo->headerPos = 0;
+ pInfo->genre = 148;
+
+ /*open*/
+ ret = mmfile_open(&hFile, filename, MMFILE_RDONLY);
+ if (ret == MMFILE_UTIL_FAIL) {
+ debug_error(DEBUG, "open failed.\n");
+ return -1;
}
- if (mmfile_seek(hFile, -(MP3TAGINFO_SIZE + TAGV1_SEEK_GAP), SEEK_END) < 0)
+ if (!__AvGetFileSize(hFile, &pInfo->fileLen)) {
+ debug_error(DEBUG, "file is too small.\n");
goto EXCEPTION;
+ }
+ v2TagExistCheck = mmfile_malloc(MP3_TAGv2_HEADER_LEN);
+ if (!v2TagExistCheck) {
+ debug_error(DEBUG, "malloc failed.\n");
+ goto EXCEPTION;
+ }
- pInfo->bV1tagFound = false;
+ if (mmfile_read(hFile, v2TagExistCheck, MP3_TAGv2_HEADER_LEN) != MP3_TAGv2_HEADER_LEN) {
+ debug_error(DEBUG, "v2TagExistCheck value read fail!\n");
+ mmfile_free(v2TagExistCheck);
+ goto EXCEPTION;
+ }
+
+ __AvGetID3v2Header(v2TagExistCheck, MP3_TAGv2_HEADER_LEN, &pInfo->tagV2Info);
+ mmfile_free(v2TagExistCheck);
- if (mmfile_read(hFile, TagBuff, MP3TAGINFO_SIZE + TAGV1_SEEK_GAP) <= 0)
+ if (mmfile_seek(hFile, 0L, SEEK_SET) < 0)
goto EXCEPTION;
- if ((tagHeaderPos = __AvMemstr(TagBuff, TagV1ID, 3, TAGV1_SEEK_GAP + 5)) >= 0) {
- debug_msg(RELEASE, "Mp3 File Tag is existing\n");
+ debug_msg(RELEASE, "pInfo->fileLen(%lld)\n", pInfo->fileLen);
- pInfo->bV1tagFound = true;
- /* In this case, V2 Tag not exist.. So, try to read V1 tag */
- if (pInfo->tagV2Info.tagLen == 0 && tagHeaderPos == TAGV1_SEEK_GAP) {
- unsigned char TmpBuff[MP3TAGINFO_SIZE] = {0, };
+ /* read file to get MP3 stream info */
+ if (pInfo->fileLen - (long long)pInfo->tagV2Info.tagLen > (long long)_AV_MP3_HEADER_POSITION_MAX) {
+ if (mmfile_seek(hFile, pInfo->tagV2Info.tagLen, SEEK_SET) < 0)
+ goto EXCEPTION;
- memcpy(TmpBuff, (TagBuff + tagHeaderPos), MP3TAGINFO_SIZE);
- if (!mm_file_id3tag_parse_v110(pInfo, TmpBuff))
- goto EXCEPTION;
- }
+ bufLen = _AV_MP3_HEADER_POSITION_MAX;
+ } else if (pInfo->fileLen - (long long)pInfo->tagV2Info.tagLen > 0) {
+ if (mmfile_seek(hFile, pInfo->tagV2Info.tagLen, SEEK_SET) < 0)
+ goto EXCEPTION;
+
+ bufLen = pInfo->fileLen - (long long)pInfo->tagV2Info.tagLen;
+ } else {
+ /* if taglen is invlaid, check whole file to get MP3 info */
+ pInfo->tagV2Info.tagLen = 0;
+ bufLen = pInfo->fileLen;
}
- mm_file_id3tag_restore_content_info(pInfo);
+ debug_msg(RELEASE, "buf size(%lu)\n", bufLen);
- if (pInfo->mpegVersion == 1) {
- if (pInfo->layer == 1)
- frameSamples = MPEG_1_SIZE_LAYER_1;
- else
- frameSamples = MPEG_1_SIZE_LAYER_2_3;
- } else {
- if (pInfo->layer == 1)
- frameSamples = MPEG_2_SIZE_LAYER_1;
- else
- frameSamples = MPEG_2_SIZE_LAYER_2_3;
+ buf = mmfile_malloc(bufLen);
+ if (!buf) {
+ goto EXCEPTION;
}
-#if 0
- unsigned long numOfFrames = 0;
- unsigned long long tempduration = 0;
- unsigned int tempNumFrames = 0;
+ if (mmfile_read(hFile, buf, bufLen) != (int)bufLen) {
+ mmfile_free(buf);
+ goto EXCEPTION;
+ }
- if (pInfo->bVbr)
- numOfFrames = pInfo->frameNum * 10;
- else {
- numOfFrames = ((pInfo->fileLen
- - (pInfo->headerPos + (pInfo->bV1tagFound ? MP3TAGINFO_SIZE : 0))) * 10) / pInfo->frameSize;
+ if (__AvGetLastID3v2offset(hFile, &head_offset)) {
+ debug_msg(RELEASE, "search start offset: %u\n", head_offset);
+ pInfo->tagV2Info.tagLen = head_offset;
}
- tempNumFrames = (unsigned int)(numOfFrames / 10);
- if ((numOfFrames - tempNumFrames * 10) > 5)
- numOfFrames = (numOfFrames / 10) + 1;
- else
- numOfFrames = numOfFrames / 10;
+ /* get position of MP3 header */
+ pInfo->headerPos = (long) __AvFindStartOfMp3Header(buf, bufLen, pInfo);
+
+ debug_msg(RELEASE, "Header Pos: %ld\n", pInfo->headerPos);
+
+ mmfile_free(buf);
+
+ /* get MP3 stream information from MP3 header */
+ if (pInfo->headerPos == -1)
+ goto EXCEPTION;
+
+ if (mmfile_seek(hFile, pInfo->headerPos, SEEK_SET) < 0)
+ goto EXCEPTION;
+ if (mmfile_read(hFile, header, 256) != 256)
+ goto EXCEPTION;
+ if (!__AvParseMp3Header(pInfo, header))
+ goto EXCEPTION;
- tempduration = (unsigned long long)(numOfFrames * 1000);
+ if (__AvParseXingHeader(pInfo, header) || __AvParseVBRIHeader(pInfo, header)) {
+ __AvGetBitrate(pInfo);
+ } else {
+ __AvGetMp3FrameSize(pInfo);
+ pInfo->datafileLen = pInfo->fileLen - pInfo->headerPos;
+ debug_msg(RELEASE, "Mp3 File FrameSize (%d) pInfo->headerPos(%ld)\n", pInfo->frameSize, pInfo->headerPos);
+ }
if (pInfo->mpegVersion == 1) {
if (pInfo->layer == 1)
frameSamples = MPEG_2_SIZE_LAYER_2_3;
}
- debug_msg(RELEASE, "frameSamples : %d, tempduration : %ld", frameSamples, tempduration);
+ /* check TAG(ID3v1) exist due to duration */
+ if (mmfile_seek(hFile, -(MP3TAGINFO_SIZE + TAGV1_SEEK_GAP), SEEK_END) < 0)
+ goto EXCEPTION;
- if (tempduration < (unsigned long long)pInfo->sampleRate) {
- tempduration = (tempduration * frameSamples * 10) / pInfo->sampleRate;
- tempduration = (tempduration / 10);
- } else
- tempduration = (tempduration * frameSamples) / pInfo->sampleRate;
+ pInfo->bV1tagFound = false;
+
+ if (mmfile_read(hFile, TagBuff, MP3TAGINFO_SIZE + TAGV1_SEEK_GAP) != MP3TAGINFO_SIZE + TAGV1_SEEK_GAP)
+ goto EXCEPTION;
+
+ if (__AvGetID3v1Header(TagBuff, MP3TAGINFO_SIZE + TAGV1_SEEK_GAP, NULL))
+ pInfo->bV1tagFound = true;
- pInfo->duration = tempduration;
-#else
if (pInfo->bVbr) {
pInfo->duration = ((double)(frameSamples * 1000) / pInfo->sampleRate) * pInfo->frameNum;
debug_msg(DEBUG, "duration for VBR : %lld", pInfo->duration);
/*pInfo->duration = ((double)file_size_except_header / (double)pInfo->frameSize) * (frameSamples * 1000 / pInfo->sampleRate); */
debug_msg(DEBUG, "duration from new algorithm : %lld", pInfo->duration);
}
-#endif
mmfile_close(hFile);
debug_msg(RELEASE, "Bitrate : %u\n", pInfo->bitRate);
debug_msg(RELEASE, "SampleRate : %u\n", pInfo->sampleRate);
debug_msg(RELEASE, "Channels : %u\n", pInfo->channels);
- debug_msg(RELEASE, "**** Info #1 ****\n");
- debug_msg(RELEASE, "Title : %s\n", pInfo->pTitle);
- debug_msg(RELEASE, "Artist : %s\n", pInfo->pArtist);
- debug_msg(RELEASE, "Album : %s\n", pInfo->pAlbum);
- debug_msg(RELEASE, "Album_Artist: %s\n", pInfo->pAlbum_Artist);
- debug_msg(RELEASE, "Year : %s\n", pInfo->pYear);
- debug_msg(RELEASE, "Comment : %s\n", pInfo->pComment);
- debug_msg(RELEASE, "TrackNum : %s\n", pInfo->pTrackNum);
- debug_msg(RELEASE, "Genre : %s\n", pInfo->pGenre);
- debug_msg(RELEASE, "**** Info #2 ****\n");
- debug_msg(RELEASE, "Author : %s\n", pInfo->pAuthor);
- debug_msg(RELEASE, "Copyright : %s\n", pInfo->pCopyright);
- debug_msg(RELEASE, "Comment : %s\n", pInfo->pComment);
- debug_msg(RELEASE, "Rating : %s\n", pInfo->pRating);
- debug_msg(RELEASE, "RecDate : %s\n", pInfo->pRecDate);
- debug_msg(RELEASE, "Encoded by : %s\n", pInfo->pEncBy);
- debug_msg(RELEASE, "URL : %s\n", pInfo->pURL);
- debug_msg(RELEASE, "Ori. Artist : %s\n", pInfo->pOriginArtist);
- debug_msg(RELEASE, "Composer : %s\n", pInfo->pComposer);
- debug_msg(RELEASE, "Conductor : %s\n", pInfo->pConductor);
- debug_msg(RELEASE, "Artwork : mime(%s) addr(%p) size(%d)\n", pInfo->imageInfo.imageMIMEType, pInfo->imageInfo.pImageBuf, pInfo->imageInfo.imageLen);
- debug_msg(RELEASE, "UnsyncLyrics : %s\n", pInfo->pUnsyncLyrics);
- debug_msg(RELEASE, "SyncLyrics size : %d\n", pInfo->syncLyricsNum);
return 0;