#include <ctype.h>
#include <vconf.h>
#include <glib.h>
-#include <iniparser.h>
#include <stdint.h>
#include "mm_file.h"
#define FOURCC(a, b, c, d) ((a) + ((b) << 8) + ((c) << 16) + ((d) << 24))
-/*#define MIN(a, b) (((a) < (b)) ? (a):(b))*/
-
#define GENRE_COUNT 149
static const char * const MpegAudio_Genre[GENRE_COUNT] = {"Blues", "Classic Rock", "Country", "Dance", "Disco", "Funk", "Grunge", "Hip-Hop", "Jazz", "Metal",
#define ID3TAG_NUM_V22 16
#define ID3TAG_NUM_V23 21
-MMFILE_ID3TAG_INFO tag_info_v22[ID3TAG_NUM_V22] = {
+static MMFILE_ID3TAG_INFO tag_info_v22[ID3TAG_NUM_V22] = {
{"TT2", 21170, AV_ID3TAG_TITLE},
{"TP1", 21041, AV_ID3TAG_ARTIST},
{"TP2", 21042, AV_ID3TAG_ALBUM_ARTIST},
{"TCO", 20655, AV_ID3TAG_GENRE},
{"TRK", 21131, AV_ID3TAG_TRACKNUM},
{"PIC", 16739, AV_ID3TAG_PICTURE},
- {"TEN", 20718, AV_ID3TAG_ENCBY},
- {"WXX", 24408, AV_ID3TAG_URL},
{"TCR", 20658, AV_ID3TAG_COPYRIGHT},
- {"TOA", 21025, AV_ID3TAG_ORIGIN_ARTIST},
{"TCM", 20653, AV_ID3TAG_COMPOSER},
{"TRD", 21124, AV_ID3TAG_RECDATE},
};
-MMFILE_ID3TAG_INFO tag_info_v23[ID3TAG_NUM_V23] = {
+static MMFILE_ID3TAG_INFO tag_info_v23[ID3TAG_NUM_V23] = {
{"TIT2", 665266, AV_ID3TAG_TITLE},
{"TPE1", 671953, AV_ID3TAG_ARTIST},
{"TPE2", 671954, AV_ID3TAG_ALBUM_ARTIST},
{"TCON", 658990, AV_ID3TAG_GENRE},
{"TRCK", 673963, AV_ID3TAG_TRACKNUM},
{"APIC", 49507, AV_ID3TAG_PICTURE},
- {"TENC", 660995, AV_ID3TAG_ENCBY},
- {"WXXX", 779096, AV_ID3TAG_URL},
{"TCOP", 658992, AV_ID3TAG_COPYRIGHT},
- {"TOPE", 671301, AV_ID3TAG_ORIGIN_ARTIST},
{"TCOM", 658989, AV_ID3TAG_COMPOSER},
{"TRDA", 660097, AV_ID3TAG_RECDATE}, /*Recdate for 2.3*/
{"USLT", 708052, AV_ID3TAG_UNSYNCLYRICS},
{"SYLT", 648660, AV_ID3TAG_SYNCLYRICS},
- {"TPOS", 672307, AV_ID3TAG_PART_OF_SET},
{"TIT1", 665265, AV_ID3TAG_CONTENT_GROUP}, /*Content Group for 2.4*/
{"TDRC", 660099, AV_ID3TAG_RECDATE}, /*Recdate for 2.4*/
};
-static int GetJunkCounterLimit(void);
+static int g_junk_counter_limit = 0;
static int GetStringFromTextTagBox(MMFileFormatContext *formatContext, MMFileIOHandle *fp, MMFILE_MP4_BASIC_BOX_HEADER *basic_header, eMMFILE_3GP_TEXT_TAG eTag)
{
char *temp_text = NULL;
if (!formatContext || !fp || !basic_header) {
- debug_error(DEBUG, "invalid param\n");
+ debug_error(DEBUG, "invalid param");
return MMFILE_UTIL_FAIL;
}
readed = mmfile_read(fp, (unsigned char *)&texttag, MMFILE_3GP_TEXT_TAGBOX_LEN);
if (readed != MMFILE_3GP_TEXT_TAGBOX_LEN) {
- debug_error(DEBUG, "read text tag header fail\n");
+ debug_error(DEBUG, "read text tag header fail");
ret = MMFILE_UTIL_FAIL;
goto exception;
}
if (textBytes <= 1) { /* there exist only 00(null) */
- debug_error(DEBUG, "Text is NULL\n");
+ debug_error(DEBUG, "Text is NULL");
goto exception;
}
- texttag.text = mmfile_malloc(textBytes);
- if (!texttag.text) {
- debug_error(DEBUG, "malloc fail for text box\n");
- ret = MMFILE_UTIL_FAIL;
- goto exception;
- }
+ texttag.text = g_malloc0(textBytes);
readed = mmfile_read(fp, (unsigned char *)texttag.text, textBytes);
if (readed != textBytes) {
- debug_error(DEBUG, "read text fail\n");
+ debug_error(DEBUG, "read text fail");
ret = MMFILE_UTIL_FAIL;
goto exception;
}
/* check BOM char */
if ((texttag.text[0] == 0xFE) && (texttag.text[1] == 0xFF)) {
/* this char is UTF-16 */
- unsigned int bytes_written = 0;
- temp_text = mmfile_string_convert((const char *)&texttag.text[2], readed - 2, "UTF-8", "UTF-16", NULL, (unsigned int *)&bytes_written);
+ temp_text = mmfile_convert_to_utf8((const char *)&texttag.text[2], readed - 2, MMFILE_CODESET_UTF16);
} else {
- temp_text = mmfile_strdup((const char *)texttag.text);
+ temp_text = g_strdup((const char *)texttag.text);
}
switch (eTag) {
break;
}
default: {
- debug_warning(DEBUG, "Not supported Text Tag type[%d]\n", eTag);
+ debug_warning(DEBUG, "Not supported Text Tag type[%d]", eTag);
break;
}
}
char temp_year[MAX_YEAR_BUFFER] = {0, };
if (!formatContext || !fp || !basic_header) {
- debug_error(DEBUG, "invalid param\n");
+ debug_error(DEBUG, "invalid param");
return MMFILE_UTIL_FAIL;
}
readed = mmfile_read(fp, (unsigned char *)&yearbox, MMFILE_3GP_YEAR_TAGBOX_LEN);
if (readed != MMFILE_3GP_YEAR_TAGBOX_LEN) {
- debug_error(DEBUG, "read yeartag header fail\n");
+ debug_error(DEBUG, "read yeartag header fail");
goto exception;
}
yearbox.year = mmfile_io_be_int16(yearbox.year);
snprintf(temp_year, MAX_YEAR_BUFFER, "%d", yearbox.year);
temp_year[MAX_YEAR_BUFFER - 1] = '\0';
- formatContext->year = mmfile_strdup((const char *)temp_year);
+ formatContext->year = g_strdup((const char *)temp_year);
}
mmfile_seek(fp, basic_header->start_offset + basic_header->size, SEEK_SET);
MMFILE_3GP_ALBUM_TAGBOX albumbox = {0, };
if (!formatContext || !fp || !basic_header) {
- debug_error(DEBUG, "invalid param\n");
+ debug_error(DEBUG, "invalid param");
return MMFILE_UTIL_FAIL;
}
readed = mmfile_read(fp, (unsigned char *)&albumbox, MMFILE_3GP_ALBUM_TAGBOX_LEN);
if (readed != MMFILE_3GP_ALBUM_TAGBOX_LEN) {
- debug_error(DEBUG, "read albumtag header fail\n");
+ debug_error(DEBUG, "read albumtag header fail");
goto exception;
}
albumTitleLen = basic_header->size - MMFILE_MP4_BASIC_BOX_HEADER_LEN - MMFILE_3GP_ALBUM_TAGBOX_LEN - 1; /* 1: track number */
if (albumTitleLen > 1) { /* there exist only 00(null) */
- debug_msg(RELEASE, "albumTitleLen=%d\n", albumTitleLen);
+ debug_msg(RELEASE, "albumTitleLen=%d", albumTitleLen);
- albumbox.albumtile = mmfile_malloc(albumTitleLen + 1); /* 1: for null char */
- if (!albumbox.albumtile) {
- debug_error(DEBUG, "malloc fail for album title text\n");
- goto exception;
- }
+ albumbox.albumtile = g_malloc0(albumTitleLen + 1); /* 1: for null char */
readed = mmfile_read(fp, (unsigned char *)albumbox.albumtile, albumTitleLen);
if (readed != albumTitleLen) {
- debug_error(DEBUG, "read album title fail\n");
+ debug_error(DEBUG, "read album title fail");
goto exception;
}
trackFlags = 0;
readed = mmfile_read(fp, (unsigned char *)&(albumbox.albumtile[albumTitleLen]), 1);
if (readed != 1) {
- debug_error(DEBUG, "read album title fail\n");
+ debug_error(DEBUG, "read album title fail");
goto exception;
}
albumbox.albumtile[albumTitleLen] = '\0';
/* check BOM char */
if ((albumbox.albumtile[0] == 0xFE) && (albumbox.albumtile[1] == 0xFF)) {
/* this char is UTF-16 */
- unsigned int bytes_written = 0;
- temp_text = mmfile_string_convert((const char *)&albumbox.albumtile[2], readed - 2, "UTF-8", "UTF-16", NULL, (unsigned int *)&bytes_written);
+ temp_text = mmfile_convert_to_utf8((const char *)&albumbox.albumtile[2], readed - 2, MMFILE_CODESET_UTF16);
} else {
- temp_text = mmfile_strdup((const char *)albumbox.albumtile);
+ temp_text = g_strdup((const char *)albumbox.albumtile);
}
if (!formatContext->album)
else
mmfile_free(temp_text);
- debug_msg(RELEASE, "formatContext->album=%s, strlen=%zu\n", formatContext->album, strlen(formatContext->album));
+ debug_msg(RELEASE, "formatContext->album=%s, strlen=%zu", formatContext->album, strlen(formatContext->album));
}
if (trackFlags) {
readed = mmfile_read(fp, (unsigned char *)&albumbox.trackNumber, 1);
if (readed != 1) {
- debug_error(DEBUG, "read track number fail\n");
+ debug_error(DEBUG, "read track number fail");
goto exception;
}
char tracknum[10] = {0, };
snprintf(tracknum, 10, "%d", albumbox.trackNumber);
tracknum[9] = '\0';
- formatContext->tagTrackNum = mmfile_strdup((const char *)tracknum);
+ formatContext->tagTrackNum = g_strdup((const char *)tracknum);
}
}
MMFILE_3GP_RATING_TAGBOX ratingTag = {0, };
if (!formatContext || !fp || !basic_header) {
- debug_error(DEBUG, "invalid param\n");
+ debug_error(DEBUG, "invalid param");
return MMFILE_UTIL_FAIL;
}
readed = mmfile_read(fp, (unsigned char *)&ratingTag, MMFILE_3GP_RATING_TAGBOX_LEN);
if (readed != MMFILE_3GP_RATING_TAGBOX_LEN) {
- debug_error(DEBUG, "read rating tag header fail\n");
+ debug_error(DEBUG, "read rating tag header fail");
goto exception;
}
ratinginfoLen = basic_header->size - MMFILE_MP4_BASIC_BOX_HEADER_LEN - MMFILE_3GP_RATING_TAGBOX_LEN;
if (ratinginfoLen == 1) {
- debug_error(DEBUG, "Rating Text is NULL\n");
+ debug_error(DEBUG, "Rating Text is NULL");
goto exception;
}
- ratingTag.ratingInfo = mmfile_malloc(ratinginfoLen);
- if (!ratingTag.ratingInfo) {
- debug_error(DEBUG, "rating info error\n");
- goto exception;
- }
+ ratingTag.ratingInfo = g_malloc0(ratinginfoLen);
readed = mmfile_read(fp, (unsigned char *)ratingTag.ratingInfo, ratinginfoLen);
if (readed != ratinginfoLen) {
- debug_error(DEBUG, "read rating info string fail\n");
+ debug_error(DEBUG, "read rating info string fail");
goto exception;
}
/* check BOM char */
if ((ratingTag.ratingInfo[0] == 0xFE) && (ratingTag.ratingInfo[1] == 0xFF)) {
/* this char is UTF-16 */
- unsigned int bytes_written = 0;
- temp_text = mmfile_string_convert((const char *)&ratingTag.ratingInfo[2], readed - 2, "UTF-8", "UTF-16", NULL, (unsigned int *)&bytes_written);
+ temp_text = mmfile_convert_to_utf8((const char *)&ratingTag.ratingInfo[2], readed - 2, MMFILE_CODESET_UTF16);
} else {
- temp_text = mmfile_strdup((const char *)ratingTag.ratingInfo);
+ temp_text = g_strdup((const char *)ratingTag.ratingInfo);
}
if (!formatContext->rating) {
MMFILE_3GP_CLASSIFICATION_TAGBOX classTag = {0, };
if (!formatContext || !fp || !basic_header) {
- debug_error(DEBUG, "invalid param\n");
+ debug_error(DEBUG, "invalid param");
return MMFILE_UTIL_FAIL;
}
readed = mmfile_read(fp, (unsigned char *)&classTag, MMFILE_3GP_CLASS_TAGBOX_LEN);
if (readed != MMFILE_3GP_CLASS_TAGBOX_LEN) {
- debug_error(DEBUG, "read classification tag header fail\n");
+ debug_error(DEBUG, "read classification tag header fail");
goto exception;
}
classinfoLen = basic_header->size - MMFILE_MP4_BASIC_BOX_HEADER_LEN - MMFILE_3GP_CLASS_TAGBOX_LEN;
if (classinfoLen == 1) {
- debug_error(DEBUG, "Classification Text is NULL\n");
+ debug_error(DEBUG, "Classification Text is NULL");
goto exception;
}
- classTag.classificationInfo = mmfile_malloc(classinfoLen);
- if (!classTag.classificationInfo) {
- debug_error(DEBUG, "class info error\n");
- goto exception;
- }
+ classTag.classificationInfo = g_malloc0(classinfoLen);
readed = mmfile_read(fp, (unsigned char *)classTag.classificationInfo, classinfoLen);
if (readed != classinfoLen) {
- debug_error(DEBUG, "read class info string fail\n");
+ debug_error(DEBUG, "read class info string fail");
goto exception;
}
/* check BOM char */
if ((classTag.classificationInfo[0] == 0xFE) && (classTag.classificationInfo[1] == 0xFF)) {
/* this char is UTF-16 */
- unsigned int bytes_written = 0;
- temp_text = mmfile_string_convert((const char *)&classTag.classificationInfo[2], readed - 2, "UTF-8", "UTF-16", NULL, (unsigned int *)&bytes_written);
+ temp_text = mmfile_convert_to_utf8((const char *)&classTag.classificationInfo[2], readed - 2, MMFILE_CODESET_UTF16);
} else {
- temp_text = mmfile_strdup((const char *)classTag.classificationInfo);
+ temp_text = g_strdup((const char *)classTag.classificationInfo);
}
if (!formatContext->classification) {
unsigned char *buffer = NULL;
unsigned char *p = NULL;
int pos = 0;
- unsigned int bytes_written = 0;
unsigned int name_sz = 0;
unsigned int astro_sz = 0;
if (!formatContext || !fp || !basic_header) {
- debug_error(DEBUG, "invalid param\n");
+ debug_error(DEBUG, "invalid param");
return MMFILE_UTIL_FAIL;
}
readed = mmfile_read(fp, (unsigned char *)&lociTag, 6); /*6 = version + flag + pad + language */
if (readed != 6) {
- debug_error(DEBUG, "read location tag header fail\n");
+ debug_error(DEBUG, "read location tag header fail");
goto exception;
}
/*buffer len = name + role + ... + additional notes length */
bufferLen = basic_header->size - MMFILE_MP4_BASIC_BOX_HEADER_LEN - 6;
if (bufferLen < 1) {
- debug_error(DEBUG, "too small buffer\n");
+ debug_error(DEBUG, "too small buffer");
goto exception;
}
- buffer = mmfile_malloc(bufferLen);
- if (!buffer) {
- debug_error(DEBUG, "buffer malloc error\n");
- goto exception;
- }
+ buffer = g_malloc0(bufferLen);
readed = mmfile_read(fp, (unsigned char *)buffer, bufferLen);
if (readed != bufferLen) {
- debug_error(DEBUG, "read location tag fail\n");
+ debug_error(DEBUG, "read location tag fail");
goto exception;
}
p = buffer;
pos = _get_char_position(p, '\0', readed - (1 + 4 + 4 + 4 + 2));
if (pos >= 0) {
if (p[0] == 0xFE && p[1] == 0xFF) {
- lociTag.name = (unsigned char *)mmfile_string_convert((const char *)(p + 2), pos - 2, "UTF-8", "UTF-16", NULL, (unsigned int *)&bytes_written);
+ lociTag.name = (unsigned char *)mmfile_convert_to_utf8((const char *)(p + 2), pos - 2, MMFILE_CODESET_UTF16);
} else {
- lociTag.name = (unsigned char *)mmfile_strdup((const char *)p);
+ lociTag.name = (unsigned char *)g_strdup((const char *)p);
}
} else {
goto exception;
lociTag.role = *p;
p++;
- debug_msg(RELEASE, "long: 0x%02X 0x%02X 0x%02X 0x%02X \n", *(p + 0), *(p + 1), *(p + 2), *(p + 3));
- debug_msg(RELEASE, "lati: 0x%02X 0x%02X 0x%02X 0x%02X \n", *(p + 4), *(p + 5), *(p + 6), *(p + 7));
- debug_msg(RELEASE, "alti: 0x%02X 0x%02X 0x%02X 0x%02X \n", *(p + 8), *(p + 9), *(p + 10), *(p + 11));
+ debug_msg(RELEASE, "long: 0x%02X 0x%02X 0x%02X 0x%02X ", *(p + 0), *(p + 1), *(p + 2), *(p + 3));
+ debug_msg(RELEASE, "lati: 0x%02X 0x%02X 0x%02X 0x%02X ", *(p + 4), *(p + 5), *(p + 6), *(p + 7));
+ debug_msg(RELEASE, "alti: 0x%02X 0x%02X 0x%02X 0x%02X ", *(p + 8), *(p + 9), *(p + 10), *(p + 11));
ilong = mmfile_io_be_uint32(*(unsigned int *)p);
ilati = mmfile_io_be_uint32(*(unsigned int *)(p + 4));
pos = _get_char_position(p, '\0', readed - (name_sz + 1 + 4 + 4 + 4 + 1));
if (pos >= 0) {
if (p[0] == 0xFE && p[1] == 0xFF) {
- lociTag.astronomical_body = (unsigned char *)mmfile_string_convert((const char *)(p + 2), pos - 2, "UTF-8", "UTF-16", NULL, (unsigned int *)&bytes_written);
+ lociTag.astronomical_body = (unsigned char *)mmfile_convert_to_utf8((const char *)(p + 2), pos - 2, MMFILE_CODESET_UTF16);
} else {
- lociTag.astronomical_body = (unsigned char *)mmfile_strdup((const char *)p);
+ lociTag.astronomical_body = (unsigned char *)g_strdup((const char *)p);
}
} else {
goto exception;
pos = _get_char_position(p, '\0', readed - (name_sz + 1 + 4 + 4 + 4 + astro_sz));
if (pos >= 0) {
if (p[0] == 0xFE && p[1] == 0xFF) {
- lociTag.additional_notes = (unsigned char *)mmfile_string_convert((const char *)(p + 2), pos - 2, "UTF-8", "UTF-16", NULL, (unsigned int *)&bytes_written);
+ lociTag.additional_notes = (unsigned char *)mmfile_convert_to_utf8((const char *)(p + 2), pos - 2, MMFILE_CODESET_UTF16);
} else {
- lociTag.additional_notes = (unsigned char *)mmfile_strdup((const char *)p);
+ lociTag.additional_notes = (unsigned char *)g_strdup((const char *)p);
}
} else {
goto exception;
}
- debug_msg(RELEASE, "** Location Information **\n");
- debug_msg(RELEASE, "Name : %s\n", lociTag.name);
- debug_msg(RELEASE, "Role : %d (0: shooting, 1: real, 2: fictional, other: reserved)\n", lociTag.role);
- debug_msg(RELEASE, "Longitude : %16.16f\n", lociTag.longitude);
- debug_msg(RELEASE, "Latitude : %16.16f\n", lociTag.latitude);
- debug_msg(RELEASE, "Altitude : %16.16f\n", lociTag.altitude);
- debug_msg(RELEASE, "Astronomical body: %s\n", lociTag.astronomical_body);
- debug_msg(RELEASE, "Additional notes : %s\n", lociTag.additional_notes);
+ debug_msg(RELEASE, "** Location Information **");
+ debug_msg(RELEASE, "Name : %s", lociTag.name);
+ debug_msg(RELEASE, "Role : %d (0: shooting, 1: real, 2: fictional, other: reserved)", lociTag.role);
+ debug_msg(RELEASE, "Longitude : %16.16f", lociTag.longitude);
+ debug_msg(RELEASE, "Latitude : %16.16f", lociTag.latitude);
+ debug_msg(RELEASE, "Altitude : %16.16f", lociTag.altitude);
+ debug_msg(RELEASE, "Astronomical body: %s", lociTag.astronomical_body);
+ debug_msg(RELEASE, "Additional notes : %s", lociTag.additional_notes);
formatContext->longitude = lociTag.longitude;
formatContext->latitude = lociTag.latitude;
int readed = 0;
if (!formatContext || !fp || !basic_header) {
- debug_error(DEBUG, "invalid param\n");
+ debug_error(DEBUG, "invalid param");
return MMFILE_UTIL_FAIL;
}
readed = mmfile_read(fp, (unsigned char *)&smtaTag, sizeof(MMFILE_M4A_SMTA_TAGBOX));
if (readed != sizeof(MMFILE_M4A_SMTA_TAGBOX)) {
- debug_error(DEBUG, "read smta tag header fail\n");
+ debug_error(DEBUG, "read smta tag header fail");
goto exception;
}
static int GetSA3DInfoFromMP4ATagBox(MMFileFormatContext *formatContext, MMFileIOHandle *fp, MMFILE_MP4_BASIC_BOX_HEADER *basic_header)
{
if (!formatContext || !fp || !basic_header) {
- debug_error(DEBUG, "invalid param\n");
+ debug_error(DEBUG, "invalid param");
return MMFILE_UTIL_FAIL;
}
readed = mmfile_read(fp, buffer, basic_header->size);
if (readed != (int)basic_header->size) {
- debug_error(DEBUG, "read mp4a box failed\n");
+ debug_error(DEBUG, "read mp4a box failed");
goto exception;
}
for (i = 0; i + 3 < basic_header->size; ++i)
if (buffer[i] == 'S' && buffer[i + 1] == 'A' && buffer[i + 2] == '3' && buffer[i + 3] == 'D') {
- debug_warning(DEBUG, "SA3D data found at offset %d bytes\n", i);
+ debug_warning(DEBUG, "SA3D data found at offset %d bytes", i);
is_SA3D_present = true;
break;
}
readed = mmfile_read(fp, (unsigned char *)&sa3dTag, sizeof(MMFILE_MP4A_SA3D_TAGBOX));
if (readed != sizeof(MMFILE_MP4A_SA3D_TAGBOX)) {
- debug_error(DEBUG, "read SA3D tag header fail\n");
+ debug_error(DEBUG, "read SA3D tag header fail");
goto exception;
}
debug_msg(RELEASE, "sa3dTag.channel_map[%d] = %d", i, sa3dTag.channel_map[i]);
if (sa3dTag.version != RFC_AMBISONIC_SA3DBOX_VERSION_SUPPORTED) {
- debug_error(DEBUG, "SA3D tag box version is unsupported\n");
+ debug_error(DEBUG, "SA3D tag box version is unsupported");
goto exception;
} else {
if (sa3dTag.ambisonic_type == RFC_AMBISONIC_TYPE_PERIPHONIC)
(sa3dTag.channel_map[3] == 2))
formatContext->ambisonicFormat = MMFILE_AMBISONIC_FORMAT_AMB;
} else {
- debug_error(DEBUG, "Incorrect metadata: ambisonic order and channels number do not correspond\n");
+ debug_error(DEBUG, "Incorrect metadata: ambisonic order and channels number do not correspond");
goto exception;
}
(sa3dTag.channel_map[8] == 4))
formatContext->ambisonicFormat = MMFILE_AMBISONIC_FORMAT_AMB;
} else {
- debug_error(DEBUG, "Incorrect metadata: ambisonic order and channels number do not correspond\n");
+ debug_error(DEBUG, "Incorrect metadata: ambisonic order and channels number do not correspond");
goto exception;
}
(sa3dTag.channel_map[15] == 9))
formatContext->ambisonicFormat = MMFILE_AMBISONIC_FORMAT_AMB;
} else {
- debug_error(DEBUG, "Incorrect metadata: ambisonic order and channels number do not correspond\n");
+ debug_error(DEBUG, "Incorrect metadata: ambisonic order and channels number do not correspond");
goto exception;
}
}
default: {
- debug_warning(DEBUG, "Ambisonic order or format is not supported: ambix or amb formats up to 3rd order were expected.\n");
+ debug_warning(DEBUG, "Ambisonic order or format is not supported: ambix or amb formats up to 3rd order were expected.");
goto exception;
break;
}
readed = mmfile_read(fp, (unsigned char *)&stereo_mode, sizeof(uint8_t));
if (readed != sizeof(uint8_t)) {
- debug_error(DEBUG, "read st3d tag header fail\n");
+ debug_error(DEBUG, "read st3d tag header fail");
return MMFILE_UTIL_FAIL;
}
mmfile_seek(fp, start_offset, SEEK_SET);
readed = mmfile_read(fp, (unsigned char *)formatContext->metadataSourceV2, box_size);
if (readed != box_size) {
- debug_error(DEBUG, "read svhd tag header fail\n");
+ debug_error(DEBUG, "read svhd tag header fail");
if (formatContext->metadataSourceV2)
free(formatContext->metadataSourceV2);
return MMFILE_UTIL_FAIL;
readed = mmfile_read(fp, (unsigned char *)&proj_data, sizeof(proj_box_data));
if (readed != sizeof(proj_box_data)) {
- debug_error(DEBUG, "read of proj box failed\n");
+ debug_error(DEBUG, "read of proj box failed");
return MMFILE_UTIL_FAIL;
}
formatContext->projTypeV2 = mmfile_io_be_uint32(proj_data.proj_type);
- debug_error(DEBUG, "formatContext->projTypeV2 = %d\n", formatContext->projTypeV2);
- debug_error(DEBUG, "proj_data.version = %d\n", proj_data.version);
- debug_error(DEBUG, "proj_data.flags = %d\n", ((uint32_t)proj_data.flags[0] << 16) +
+ debug_error(DEBUG, "formatContext->projTypeV2 = %d", formatContext->projTypeV2);
+ debug_error(DEBUG, "proj_data.version = %d", proj_data.version);
+ debug_error(DEBUG, "proj_data.flags = %d", ((uint32_t)proj_data.flags[0] << 16) +
((uint32_t)proj_data.flags[1] << 8) + (uint32_t)proj_data.flags[2]);
mmfile_seek(fp, sizeof(proj_box_data), SEEK_CUR);
readed = mmfile_read(fp, (unsigned char *)&prhd_data, sizeof(prhd_box_data));
if (readed != sizeof(prhd_box_data)) {
- debug_error(DEBUG, "read of prhd box failed\n");
+ debug_error(DEBUG, "read of prhd box failed");
return MMFILE_UTIL_FAIL;
}
formatContext->posePitchV2 = mmfile_io_be_uint32(prhd_data.projection_pose_pitch);
formatContext->poseRollV2 = mmfile_io_be_uint32(prhd_data.projection_pose_roll);
- debug_error(DEBUG, "formatContext->poseYawV2 = %d\n", formatContext->poseYawV2);
- debug_error(DEBUG, "formatContext->posePitchV2 = %d\n", formatContext->posePitchV2);
- debug_error(DEBUG, "formatContext->poseRollV2 = %d\n", formatContext->poseRollV2);
+ debug_error(DEBUG, "formatContext->poseYawV2 = %d", formatContext->poseYawV2);
+ debug_error(DEBUG, "formatContext->posePitchV2 = %d", formatContext->posePitchV2);
+ debug_error(DEBUG, "formatContext->poseRollV2 = %d", formatContext->poseRollV2);
if (formatContext->projTypeV2 == PROJECTION_TYPE_EQUI) {
debug_msg(RELEASE, "Projection type is Equirectangular");
mmfile_seek(fp, 8, SEEK_CUR); /* 8 = 4 (for size) + 4 (fourcc) */
readed = mmfile_read(fp, (unsigned char *)&equi_data, sizeof(equi_box_data));
if (readed != sizeof(equi_box_data)) {
- debug_error(DEBUG, "read of equi box failed\n");
+ debug_error(DEBUG, "read of equi box failed");
return MMFILE_UTIL_FAIL;
}
formatContext->equiBoundsLeftV2 = mmfile_io_be_uint32(equi_data.projection_bounds_left);
formatContext->equiBoundsRightV2 = mmfile_io_be_uint32(equi_data.projection_bounds_right);
- debug_error(DEBUG, "formatContext->equiBoundsTopV2 = %d\n", formatContext->equiBoundsTopV2);
- debug_error(DEBUG, "formatContext->equiBoundsBottomV2 = %d\n", formatContext->equiBoundsBottomV2);
- debug_error(DEBUG, "formatContext->equiBoundsLeftV2 = %d\n", formatContext->equiBoundsLeftV2);
- debug_error(DEBUG, "formatContext->equiBoundsRightV2 = %d\n", formatContext->equiBoundsRightV2);
+ debug_error(DEBUG, "formatContext->equiBoundsTopV2 = %d", formatContext->equiBoundsTopV2);
+ debug_error(DEBUG, "formatContext->equiBoundsBottomV2 = %d", formatContext->equiBoundsBottomV2);
+ debug_error(DEBUG, "formatContext->equiBoundsLeftV2 = %d", formatContext->equiBoundsLeftV2);
+ debug_error(DEBUG, "formatContext->equiBoundsRightV2 = %d", formatContext->equiBoundsRightV2);
} else if (formatContext->projTypeV2 == PROJECTION_TYPE_CBMP) {
debug_msg(RELEASE, "Projection type is Cubemap");
mmfile_seek(fp, 8, SEEK_CUR); /* 8 = 4 (for size) + 4 (fourcc) */
readed = mmfile_read(fp, (unsigned char *)&cbmp_data, sizeof(cbmp_box_data));
if (readed != sizeof(cbmp_box_data)) {
- debug_error(DEBUG, "read of cbmp box failed\n");
+ debug_error(DEBUG, "read of cbmp box failed");
return MMFILE_UTIL_FAIL;
}
formatContext->cbmpLayoutV2 = mmfile_io_be_uint32(cbmp_data.layout);
formatContext->cbmpPaddingV2 = mmfile_io_be_uint32(cbmp_data.padding);
- debug_error(DEBUG, "formatContext->cbmpLayoutV2 = %d\n", formatContext->cbmpLayoutV2);
- debug_error(DEBUG, "formatContext->cbmpPaddingV2 = %d\n", formatContext->cbmpPaddingV2);
+ debug_error(DEBUG, "formatContext->cbmpLayoutV2 = %d", formatContext->cbmpLayoutV2);
+ debug_error(DEBUG, "formatContext->cbmpPaddingV2 = %d", formatContext->cbmpPaddingV2);
} else {
debug_msg(RELEASE, "Projection type is %d (unknown)", proj_data.proj_type);
static int GetVideoV2MetadataFromAvc1TagBox(MMFileFormatContext *formatContext, MMFileIOHandle *fp, MMFILE_MP4_BASIC_BOX_HEADER *basic_header)
{
if (!formatContext || !fp || !basic_header) {
- debug_error(DEBUG, "invalid param\n");
+ debug_error(DEBUG, "invalid param");
return MMFILE_UTIL_FAIL;
}
readed = mmfile_read(fp, buffer, basic_header->size);
if (readed != (int)basic_header->size) {
- debug_error(DEBUG, "read st3d box failed\n");
+ debug_error(DEBUG, "read st3d box failed");
goto exception;
}
for (i = 0; i + 3 < basic_header->size; ++i) {
if ((buffer[i] == 's' && buffer[i + 1] == 't' && buffer[i + 2] == '3' && buffer[i + 3] == 'd') && (formatContext->stereoModeV2 == INVALID_UINT_VALUE)) {
- debug_warning(DEBUG, "st3d data found at offset %lld\n", basic_header->start_offset + i);
+ debug_warning(DEBUG, "st3d data found at offset %lld", basic_header->start_offset + i);
ParseSt3dData(formatContext, fp, basic_header->start_offset + i + 4);
debug_msg(RELEASE, "formatContext->stereoModeV2 = %d", formatContext->stereoModeV2);
}
if (buffer[i] == 's' && buffer[i + 1] == 'v' && buffer[i + 2] == '3' && buffer[i + 3] == 'd') {
- debug_warning(DEBUG, "sv3d data found at offset %lld\n", basic_header->start_offset + i);
+ debug_warning(DEBUG, "sv3d data found at offset %lld", basic_header->start_offset + i);
formatContext->isSpherical = true;
}
if (buffer[i] == 's' && buffer[i + 1] == 'v' && buffer[i + 2] == 'h' && buffer[i + 3] == 'd') {
- debug_warning(DEBUG, "svhd data found at offset %lld\n", basic_header->start_offset + i);
+ debug_warning(DEBUG, "svhd data found at offset %lld", basic_header->start_offset + i);
ParseSvhdData(formatContext, fp, basic_header->start_offset + i + 4, mmfile_io_be_uint32(*((uint32_t*)(buffer - 4 + i))));
debug_msg(RELEASE, "formatContext->metadataSourceV2 = %s (length = %zu)", formatContext->metadataSourceV2, strlen(formatContext->metadataSourceV2));
}
if (buffer[i] == 'p' && buffer[i + 1] == 'r' && buffer[i + 2] == 'o' && buffer[i + 3] == 'j') {
- debug_warning(DEBUG, "proj data found at offset %lld\n", basic_header->start_offset + i);
+ debug_warning(DEBUG, "proj data found at offset %lld", basic_header->start_offset + i);
ParseProjData(formatContext, fp, basic_header->start_offset + i + 4);
}
}
int readed = 0;
if (!formatContext || !fp || !basic_header) {
- debug_error(DEBUG, "invalid param\n");
+ debug_error(DEBUG, "invalid param");
return MMFILE_UTIL_FAIL;
}
readed = mmfile_read(fp, (unsigned char *)&value, sizeof(unsigned int));
if (readed != sizeof(unsigned int)) {
- debug_error(DEBUG, "read cdis tag header fail\n");
+ debug_error(DEBUG, "read cdis tag header fail");
goto exception;
}
int id3v2Len = 0;
unsigned int meta_version = 0;
MMFILE_3GP_HANDLER_BOX hdlrBox = {0, };
- unsigned int encSize = 0;
int id3_meta = 0;
#ifdef ENABLE_ITUNES_META /* We don't support itunes meta now. so this is not defined yet */
int iTunes_meta = 0;
/* meta box */
readed = mmfile_read(fp, (unsigned char *)&meta_version, 4);
if (readed != 4) {
- debug_error(DEBUG, "read meta box version\n");
+ debug_error(DEBUG, "read meta box version");
goto exception;
}
/* hdlr box */
readed = mmfile_read(fp, (unsigned char *)&hdlrBoxHeader, MMFILE_MP4_BASIC_BOX_HEADER_LEN);
if (readed != MMFILE_MP4_BASIC_BOX_HEADER_LEN) {
- debug_error(DEBUG, "read hdlr box header\n");
+ debug_error(DEBUG, "read hdlr box header");
goto exception;
}
if (hdlrBoxHeader.type != FOURCC('h', 'd', 'l', 'r')) {
- debug_warning(DEBUG, "meta type is not hdlr\n");
+ debug_warning(DEBUG, "meta type is not hdlr");
goto exception;
}
readed = mmfile_read(fp, (unsigned char *)&hdlrBox, MMFILE_3GP_HANDLER_BOX_LEN);
if (readed != MMFILE_3GP_HANDLER_BOX_LEN) {
- debug_error(DEBUG, "read hdlr box\n");
+ debug_error(DEBUG, "read hdlr box");
goto exception;
}
* check tag type (ID3v2 or iTunes)
*/
if (hdlrBox.handler_type == FOURCC('I', 'D', '3', '2')) {
- debug_msg(RELEASE, "ID3v2 tag detected.\n");
+ debug_msg(RELEASE, "ID3v2 tag detected.");
id3_meta = 1;
#ifdef ENABLE_ITUNES_META
} else if (hdlrBox.handler_type == FOURCC('m', 'd', 'i', 'r') &&
mmfile_io_le_uint32(hdlrBox.reserved[0]) == FOURCC('a', 'p', 'p', 'l')) {
- debug_msg(RELEASE, "Apple iTunes tag detected by mdir.\n");
+ debug_msg(RELEASE, "Apple iTunes tag detected by mdir.");
#ifdef ENABLE_ITUNES_META
iTunes_meta = 1;
#endif
} else {
- debug_warning(DEBUG, "unknown meta type. 4CC:[%c%c%c%c]\n", ((char *)&hdlrBox.handler_type)[0],
+ debug_warning(DEBUG, "unknown meta type. 4CC:[%c%c%c%c]", ((char *)&hdlrBox.handler_type)[0],
((char *)&hdlrBox.handler_type)[1],
((char *)&hdlrBox.handler_type)[2],
((char *)&hdlrBox.handler_type)[3]);
readed = mmfile_read(fp, read_buf, buf_size); /* to find 'ilst' */
if (readed != buf_size) {
- debug_error(DEBUG, "read fail [%d]\n", readed);
+ debug_error(DEBUG, "read fail [%d]", readed);
goto exception;
}
if (read_buf[0] == 'i' && read_buf[1] == 'l' && read_buf[2] == 's' && read_buf[3] == 't') {
- debug_msg(RELEASE, "Apple iTunes tag detected by ilst.\n");
+ debug_msg(RELEASE, "Apple iTunes tag detected by ilst.");
iTunes_meta = 1;
}
}
artist_offset = mmfile_tell(fp);
artist_sz = mmfile_io_be_uint32(*(int *)(read_buf + 4)) - 16; /* atom len(4)+data(4)+atom verion(1)+flag(3)+null(4) = 16 */
- debug_msg(RELEASE, "----------------------------------- artist found, offset=[%lld], size=[%d]\n", artist_offset, artist_sz);
+ debug_msg(RELEASE, "----------------------------------- artist found, offset=[%lld], size=[%d]", artist_offset, artist_sz);
}
/**
track_found = 1;
track_offset = mmfile_tell(fp);
- debug_msg(RELEASE, "----------------------------------- Track found, offset=[%lld]\n", track_offset);
+ debug_msg(RELEASE, "----------------------------------- Track found, offset=[%lld]", track_offset);
}
/**
genre_found = 1;
genre_offset = mmfile_tell(fp);
- debug_msg(RELEASE, "----------------------------------- genre found, offset=[%lld]\n", genre_offset);
+ debug_msg(RELEASE, "----------------------------------- genre found, offset=[%lld]", genre_offset);
}
#endif
cover_offset = mmfile_tell(fp);
- debug_msg(RELEASE, "----------------------------------- cover_found found, offset=[%lld]\n", cover_offset);
+ debug_msg(RELEASE, "----------------------------------- cover_found found, offset=[%lld]", cover_offset);
}
mmfile_seek(fp, -(_ITUNES_READ_BUF_SZ - 1), SEEK_CUR); /*FIXME: poor search*/
} /*loop*/
- /*ffmpeg extract artist, tracknum, excep cover image. see mov_read_udta_string()*/
+ /*ffmpeg extract artist, tracknum, except cover image. see mov_read_udta_string()*/
#if 0
if (artist_found) {
if (artist_sz > 0) {
mmfile_seek(fp, artist_offset, SEEK_SET);
if (formatContext->artist) {
- debug_msg(RELEASE, "----------------------------------- previous artist was [%s] \n", formatContext->artist);
+ debug_msg(RELEASE, "----------------------------------- previous artist was [%s] ", formatContext->artist);
free(formatContext->artist);
}
- debug_msg(RELEASE, "----------------------------------- new artist will be allocated with size (len+1) [%d] \n", artist_sz + 1);
- formatContext->artist = mmfile_malloc(artist_sz + 1);
+ debug_msg(RELEASE, "----------------------------------- new artist will be allocated with size (len+1) [%d] ", artist_sz + 1);
+ formatContext->artist = g_malloc0(artist_sz + 1);
if (formatContext->artist) {
readed = mmfile_read(fp, (unsigned char *)formatContext->artist, artist_sz);
formatContext->artist[artist_sz] = '\0';
- debug_msg(RELEASE, "----------------------------------- new artist is [%s] \n", formatContext->artist);
+ debug_msg(RELEASE, "----------------------------------- new artist is [%s] ", formatContext->artist);
if (readed != artist_sz) {
- debug_error(DEBUG, "failed to read. ret = %d, in = %d\n", readed, artist_sz);
+ debug_error(DEBUG, "failed to read. ret = %d, in = %d", readed, artist_sz);
mmfile_free(formatContext->artist);
}
}
mmfile_seek(fp, track_offset, SEEK_SET);
readed = mmfile_read(fp, read_buf, _ITUNES_TRACK_NUM_SZ);
if (readed != _ITUNES_TRACK_NUM_SZ) {
- debug_error(DEBUG, "failed to read. ret = %d, in = %d\n", readed, _ITUNES_TRACK_NUM_SZ);
+ debug_error(DEBUG, "failed to read. ret = %d, in = %d", readed, _ITUNES_TRACK_NUM_SZ);
} else {
track_num = mmfile_io_be_uint32(*(int *)read_buf);
if (!formatContext->tagTrackNum) {
memset(read_buf, 0x00, _ITUNES_READ_BUF_SZ);
snprintf((char *)read_buf, sizeof(read_buf), "%d", track_num);
- formatContext->tagTrackNum = mmfile_strdup((const char *)read_buf);
+ formatContext->tagTrackNum = g_strdup((const char *)read_buf);
}
}
}
mmfile_seek(fp, genre_offset, SEEK_SET);
readed = mmfile_read(fp, read_buf, _ITUNES_GENRE_NUM_SZ);
if (readed != _ITUNES_GENRE_NUM_SZ) {
- debug_error(DEBUG, "failed to read. ret = %d, in = %d\n", readed, _ITUNES_GENRE_NUM_SZ);
+ debug_error(DEBUG, "failed to read. ret = %d, in = %d", readed, _ITUNES_GENRE_NUM_SZ);
} else {
genre_index = mmfile_io_be_uint16(*(int *)read_buf);
- debug_msg(RELEASE, "genre index=[%d] \n", genre_index);
+ debug_msg(RELEASE, "genre index=[%d] ", genre_index);
if (genre_index > 0 && genre_index < GENRE_COUNT) {
if (!formatContext->genre) {
memset(read_buf, 0x00, _ITUNES_READ_BUF_SZ);
snprintf((char *)read_buf, sizeof(read_buf), "%s", MpegAudio_Genre[genre_index - 1]);
- debug_msg(RELEASE, "genre string=[%s] \n", read_buf);
- formatContext->genre = mmfile_strdup((const char *)read_buf);
+ debug_msg(RELEASE, "genre string=[%s] ", read_buf);
+ formatContext->genre = g_strdup((const char *)read_buf);
}
}
}
if (cover_sz > 0) {
mmfile_seek(fp, cover_offset, SEEK_SET);
- formatContext->artwork = mmfile_malloc(cover_sz);
+ formatContext->artwork = g_malloc0(cover_sz);
formatContext->artworkSize = cover_sz;
if (cover_type == _ITUNES_COVER_TYPE_JPEG) {
- formatContext->artworkMime = mmfile_strdup("image/jpeg");
+ formatContext->artworkMime = g_strdup("image/jpeg");
} else if (cover_type == _ITUNES_COVER_TYPE_PNG) {
- formatContext->artworkMime = mmfile_strdup("image/png");
+ formatContext->artworkMime = g_strdup("image/png");
/*} else if (cover_type == _ITUNES_COVER_TYPE_TIF) {
- formatContext->artworkMime = mmfile_strdup("image/tif");*/
+ formatContext->artworkMime = g_strdup("image/tif");*/
} else {
debug_warning(DEBUG, "Not proper cover image type, but set to jpeg. cover_type[%d]", cover_type);
- formatContext->artworkMime = mmfile_strdup("image/jpeg");
+ formatContext->artworkMime = g_strdup("image/jpeg");
}
if (formatContext->artwork) {
readed = mmfile_read(fp, formatContext->artwork, cover_sz);
if (readed != cover_sz) {
- debug_error(DEBUG, "failed to read. ret = %d, in = %d\n", readed, cover_sz);
+ debug_error(DEBUG, "failed to read. ret = %d, in = %d", readed, cover_sz);
mmfile_free(formatContext->artwork);
formatContext->artworkSize = 0;
mmfile_free(formatContext->artworkMime);
/* id3 tag box */
readed = mmfile_read(fp, (unsigned char *)&id3v2BoxHeader, MMFILE_MP4_BASIC_BOX_HEADER_LEN);
if (readed != MMFILE_MP4_BASIC_BOX_HEADER_LEN) {
- debug_error(DEBUG, "read id3v2 box header\n");
+ debug_error(DEBUG, "read id3v2 box header");
goto exception;
}
id3v2BoxHeader.type = mmfile_io_le_uint32(id3v2BoxHeader.type);
if (id3v2BoxHeader.type != FOURCC('I', 'D', '3', '2')) {
- debug_warning(DEBUG, "meta type is not id3v2\n");
+ debug_warning(DEBUG, "meta type is not id3v2");
goto exception;
}
readed = mmfile_read(fp, (unsigned char *)&id3v2Box, MMFILE_3GP_ID3V2_BOX_LEN);
if (readed != MMFILE_3GP_ID3V2_BOX_LEN) {
- debug_error(DEBUG, "read id3v2 box\n");
+ debug_error(DEBUG, "read id3v2 box");
goto exception;
}
id3v2Len = id3v2BoxHeader.size - MMFILE_MP4_BASIC_BOX_HEADER_LEN - MMFILE_3GP_ID3V2_BOX_LEN;
- id3v2Box.id3v2Data = mmfile_malloc(id3v2Len);
- if (!id3v2Box.id3v2Data) {
- debug_error(DEBUG, "malloc id3tag data error\n");
- goto exception;
- }
+ id3v2Box.id3v2Data = g_malloc0(id3v2Len);
readed = mmfile_read(fp, (unsigned char *)id3v2Box.id3v2Data, id3v2Len);
if (readed != id3v2Len) {
- debug_error(DEBUG, "read id3tag data error\n");
+ debug_error(DEBUG, "read id3tag data error");
goto exception;
}
/* check id3v2 */
if (!IS_ID3V2_TAG(id3v2Box.id3v2Data)) {
- debug_error(DEBUG, "it is not id3tag\n");
+ debug_error(DEBUG, "it is not id3tag");
goto exception;
}
if (id3v2Box.id3v2Data[3] == 0xFF || id3v2Box.id3v2Data[4] == 0xFF ||
id3v2Box.id3v2Data[6] >= 0x80 || id3v2Box.id3v2Data[7] >= 0x80 ||
id3v2Box.id3v2Data[8] >= 0x80 || id3v2Box.id3v2Data[9] >= 0x80) {
- debug_error(DEBUG, "it is not valid id3tag\n");
+ debug_error(DEBUG, "it is not valid id3tag");
goto exception;
}
tagVersion = id3v2Box.id3v2Data[3];
if (tagVersion > 4) {
- debug_error(DEBUG, "tag vesion is too high\n");
+ debug_error(DEBUG, "tag version is too high");
goto exception;
}
- encSize = mmfile_io_le_uint32((unsigned int)&id3v2Box.id3v2Data[6]);
tagInfo.tagV2Info.tagLen = MP3_TAGv2_HEADER_LEN;
- tagInfo.tagV2Info.tagLen += (((encSize & 0x0000007F) >> 0) | ((encSize & 0x00007F00) >> 1) | ((encSize & 0x007F0000) >> 2) | ((encSize & 0x7F000000) >> 3));
+ tagInfo.tagV2Info.tagLen += (((id3v2Box.id3v2Data[6] & 0x7F) << 21) | ((id3v2Box.id3v2Data[7] & 0x7F) << 14) | ((id3v2Box.id3v2Data[8] & 0x7F) << 7) | ((id3v2Box.id3v2Data[9] & 0x7F)));
tagInfo.tagV2Info.tagVersion = tagVersion;
tagInfo.fileLen = id3v2Len;
/* set id3v2 data to formatContext */
switch (tagVersion) {
- case 2: {
- versionCheck = mm_file_id3tag_parse_v222(&tagInfo, id3v2Box.id3v2Data);
- break;
- }
- case 3: {
- versionCheck = mm_file_id3tag_parse_v223(&tagInfo, id3v2Box.id3v2Data);
- break;
- }
- case 4: {
- versionCheck = mm_file_id3tag_parse_v224(&tagInfo, id3v2Box.id3v2Data);
- break;
- }
+ case 2:
+ versionCheck = mm_file_id3tag_parse_v222(&tagInfo, id3v2Box.id3v2Data, formatContext->extract_artwork);
+ break;
+ case 3:
+ versionCheck = mm_file_id3tag_parse_v223(&tagInfo, id3v2Box.id3v2Data, formatContext->extract_artwork);
+ break;
+ case 4:
+ versionCheck = mm_file_id3tag_parse_v224(&tagInfo, id3v2Box.id3v2Data, formatContext->extract_artwork);
+ break;
case 1:
- default: {
- debug_error(DEBUG, "tag vesion is not support\n");
- versionCheck = false;
- break;
- }
+ default:
+ debug_error(DEBUG, "tag vesion is not support");
+ versionCheck = false;
+ break;
}
if (versionCheck == false) {
- debug_error(DEBUG, "tag parsing is fail\n");
+ debug_error(DEBUG, "tag parsing is fail");
goto exception;
}
- formatContext->title = mmfile_strdup((const char *)tagInfo.tagInfo[AV_ID3TAG_TITLE].value);
- formatContext->artist = mmfile_strdup((const char *)tagInfo.tagInfo[AV_ID3TAG_ARTIST].value);
- formatContext->copyright = mmfile_strdup((const char *)tagInfo.tagInfo[AV_ID3TAG_COPYRIGHT].value);
- formatContext->comment = mmfile_strdup((const char *)tagInfo.tagInfo[AV_ID3TAG_COMMENT].value);
- formatContext->album = mmfile_strdup((const char *)tagInfo.tagInfo[AV_ID3TAG_ALBUM].value);
- formatContext->album_artist = mmfile_strdup((const char *)tagInfo.tagInfo[AV_ID3TAG_ALBUM_ARTIST].value);
- formatContext->year = mmfile_strdup((const char *)tagInfo.tagInfo[AV_ID3TAG_YEAR].value);
- formatContext->genre = mmfile_strdup((const char *)tagInfo.tagInfo[AV_ID3TAG_GENRE].value);
- formatContext->tagTrackNum = mmfile_strdup((const char *)tagInfo.tagInfo[AV_ID3TAG_TRACKNUM].value);
- formatContext->composer = mmfile_strdup((const char *)tagInfo.tagInfo[AV_ID3TAG_COMPOSER].value);
- formatContext->classification = mmfile_strdup((const char *)tagInfo.tagInfo[AV_ID3TAG_CONTENT_GROUP].value);
- formatContext->conductor = mmfile_strdup((const char *)tagInfo.tagInfo[AV_ID3TAG_CONDUCTOR].value);
-
- formatContext->artwork = mmfile_malloc(tagInfo.imageInfo.imageLen);
- if ((tagInfo.imageInfo.imageLen > 0) && formatContext->artwork) {
+ formatContext->title = g_strdup((const char *)tagInfo.tagInfo[AV_ID3TAG_TITLE].value);
+ formatContext->artist = g_strdup((const char *)tagInfo.tagInfo[AV_ID3TAG_ARTIST].value);
+ formatContext->copyright = g_strdup((const char *)tagInfo.tagInfo[AV_ID3TAG_COPYRIGHT].value);
+ formatContext->comment = g_strdup((const char *)tagInfo.tagInfo[AV_ID3TAG_COMMENT].value);
+ formatContext->album = g_strdup((const char *)tagInfo.tagInfo[AV_ID3TAG_ALBUM].value);
+ formatContext->album_artist = g_strdup((const char *)tagInfo.tagInfo[AV_ID3TAG_ALBUM_ARTIST].value);
+ formatContext->year = g_strdup((const char *)tagInfo.tagInfo[AV_ID3TAG_YEAR].value);
+ formatContext->genre = g_strdup((const char *)tagInfo.tagInfo[AV_ID3TAG_GENRE].value);
+ formatContext->tagTrackNum = g_strdup((const char *)tagInfo.tagInfo[AV_ID3TAG_TRACKNUM].value);
+ formatContext->composer = g_strdup((const char *)tagInfo.tagInfo[AV_ID3TAG_COMPOSER].value);
+ formatContext->classification = g_strdup((const char *)tagInfo.tagInfo[AV_ID3TAG_CONTENT_GROUP].value);
+ formatContext->conductor = g_strdup((const char *)tagInfo.tagInfo[AV_ID3TAG_CONDUCTOR].value);
+
+ if (tagInfo.imageInfo.pImageBuf && tagInfo.imageInfo.imageLen > 0) {
formatContext->artworkSize = tagInfo.imageInfo.imageLen;
- memcpy(formatContext->artwork, tagInfo.imageInfo.pImageBuf, tagInfo.imageInfo.imageLen);
+ formatContext->artwork = g_memdup2(tagInfo.imageInfo.pImageBuf, tagInfo.imageInfo.imageLen);
}
mm_file_free_AvFileContentInfo(&tagInfo);
int value_length = 0;
if (!xml_str || !param_name || !strstr(xml_str, param_name)) {
- debug_error(DEBUG, "error: incorrect or non-existing parameter\n");
+ debug_error(DEBUG, "error: incorrect or non-existing parameter");
return MMFILE_UTIL_FAIL;
}
value_end = strchr(value_start, '<');
if (!value_end) {
- debug_error(DEBUG, "error: incorrect XML\n");
+ debug_error(DEBUG, "error: incorrect XML");
return MMFILE_UTIL_FAIL;
}
i++;
while (i < value_length) {
if (value_start[i] < '0' || value_start[i] > '9') {
- debug_error(DEBUG, "error: incorrect value, integer was expected\n");
+ debug_error(DEBUG, "error: incorrect value, integer was expected");
return MMFILE_UTIL_FAIL;
}
i++;
}
if (value_length >= value_length_max || value_length < 1) {
- debug_error(DEBUG, "error: empty XML value or incorrect range\n");
+ debug_error(DEBUG, "error: empty XML value or incorrect range");
+ return MMFILE_UTIL_FAIL;
+ }
+
+ memset(init_view_ret, 0x00, value_length_max);
+ if (g_strlcpy(init_view_ret, value_start, value_length_max) >= value_length_max) {
+ debug_error(DEBUG, "error: truncation occurred");
return MMFILE_UTIL_FAIL;
}
- memset(init_view_ret, 0x00, sizeof(init_view_ret));
- SAFE_STRLCPY(init_view_ret, value_start, sizeof(init_view_ret));
*value = strtol(init_view_ret, &endptr, 10);
if (endptr == init_view_ret) {
- debug_error(DEBUG, "error: no digits were found\n");
+ debug_error(DEBUG, "error: no digits were found");
return MMFILE_UTIL_FAIL;
}
int value_length = 0;
if (!xml_str || !param_name || !strstr(xml_str, param_name)) {
- debug_error(DEBUG, "error: incorrect or non-existing parameter\n");
+ debug_error(DEBUG, "error: incorrect or non-existing parameter");
return MMFILE_UTIL_FAIL;
}
value_end = strchr(value_start, '<');
if (!value_end) {
- debug_error(DEBUG, "error: incorrect XML\n");
+ debug_error(DEBUG, "error: incorrect XML");
return MMFILE_UTIL_FAIL;
}
value_length--;
if (value_length >= value_length_max || value_length < 1) {
- debug_error(DEBUG, "error: empty XML value or incorrect range\n");
+ debug_error(DEBUG, "error: empty XML value or incorrect range");
return MMFILE_UTIL_FAIL;
}
*value = (char*)calloc(value_length, sizeof(char));
if (*value == NULL) {
- debug_error(DEBUG, "error: calloc failed\n");
+ debug_error(DEBUG, "error: calloc failed");
return MMFILE_UTIL_FAIL;
}
strncpy(*value, value_start, value_length);
int value_length = 0;
if (!xml_str || !param_name || !strstr(xml_str, param_name)) {
- debug_error(DEBUG, "error: incorrect or non-existing parameter\n");
+ debug_error(DEBUG, "error: incorrect or non-existing parameter");
return MMFILE_UTIL_FAIL;
}
value_length--;
if (value_length < 1) {
- debug_error(DEBUG, "error: empty XML value or incorrect range\n");
+ debug_error(DEBUG, "error: empty XML value or incorrect range");
return MMFILE_UTIL_FAIL;
}
return MMFILE_UTIL_SUCCESS;
}
-static int g_junk_counter_limit = 0;
-static int GetJunkCounterLimit(void)
-{
- dictionary *dict = NULL;
- int data = 0;
-
- dict = iniparser_load(MM_FILE_INI_PATH);
- if (!dict) {
- debug_error(DEBUG, "%s load failed", MM_FILE_INI_PATH);
- return -1;
- }
-
- data = iniparser_getint(dict, "mm-file-config:junk_counter_limit", 0);
- debug_msg(DEBUG, "mm-file-config:junk_counter_limit= %u", data);
-
- iniparser_freedict(dict);
-
- return data;
-}
-
int ParseSpatialVideoMetadataFromXMLString(const char *xmlStr, MMFileFormatContext *formatContext)
{
const char is_spherical_str[] = "<GSpherical:Spherical>";
int MMFileUtilGetMetaDataFromMKV(MMFileFormatContext *formatContext)
{
MMFileIOHandle *fp = NULL;
- int probe_size = 10000;
+ long long probe_size = 10000;
unsigned char *buffer = NULL;
int ret = 0;
- int i;
+ long long i;
long long file_size = 0;
MMFILE_WEBM_PROJ_V2_BOX v2box = { 0, };
ret = mmfile_open(&fp, formatContext->uriFileName, MMFILE_RDONLY);
if (ret == MMFILE_UTIL_FAIL) {
- debug_error(DEBUG, "error: mmfile_open\n");
+ debug_error(DEBUG, "error: mmfile_open");
goto exit;
}
file_size = mmfile_seek(fp, 0, SEEK_END);
if (file_size == MMFILE_UTIL_FAIL) {
- debug_error(DEBUG, "mmfile operation failed\n");
+ debug_error(DEBUG, "mmfile operation failed");
goto exit;
}
probe_size = (file_size > probe_size) ? probe_size : file_size;
buffer = (unsigned char *)malloc(probe_size * sizeof(unsigned char));
if (!buffer) {
- debug_error(DEBUG, "malloc failed\n");
+ debug_error(DEBUG, "malloc failed");
goto exit;
}
ret = mmfile_seek(fp, 0, SEEK_SET);
if (ret == MMFILE_UTIL_FAIL) {
- debug_error(DEBUG, "mmfile operation failed\n");
+ debug_error(DEBUG, "mmfile operation failed");
goto exit;
}
ret = mmfile_read(fp, buffer, probe_size * sizeof(unsigned char));
if (ret == MMFILE_UTIL_FAIL) {
- debug_error(DEBUG, "mmfile operation failed\n");
+ debug_error(DEBUG, "mmfile operation failed");
goto exit;
}
for (i = 0; i + 3 < probe_size; ++i) {
if (*(unsigned int *)(buffer + i) == FOURCC('e', 'q', 'u', 'i') ||
*(unsigned int *)(buffer + i) == FOURCC('c', 'b', 'm', 'p')) {
- debug_msg(DEBUG, "projection data found at offset %d bytes\n", i);
+ debug_msg(DEBUG, "projection data found at offset %lld bytes", i);
break;
}
}
if (i + 3 == probe_size) {
- debug_msg(DEBUG, "projection info wasn't found\n");
+ debug_msg(DEBUG, "projection info wasn't found");
ret = MMFILE_UTIL_SUCCESS;
goto exit;
}
- if ((i - (int)sizeof(MMFILE_WEBM_PROJ_V2_BOX)) < 0) {
- debug_error(DEBUG, "error: invalid supposed projection info location\n");
+ if ((i - sizeof(MMFILE_WEBM_PROJ_V2_BOX)) < 0) {
+ debug_error(DEBUG, "error: invalid supposed projection info location");
ret = MMFILE_UTIL_FAIL;
goto exit;
}
ret = mmfile_seek(fp, i - sizeof(MMFILE_WEBM_PROJ_V2_BOX), SEEK_SET);
if (ret == MMFILE_UTIL_FAIL) {
- debug_error(DEBUG, "error: failed to seek to the supposed projection info location\n");
+ debug_error(DEBUG, "error: failed to seek to the supposed projection info location");
goto exit;
}
ret = mmfile_read(fp, (unsigned char *)&v2box, sizeof(MMFILE_WEBM_PROJ_V2_BOX));
if (ret == MMFILE_UTIL_FAIL) {
- debug_error(DEBUG, "mmfile operation failed\n");
+ debug_error(DEBUG, "mmfile operation failed");
goto exit;
}
if (v2box.proj_type_box_value == PROJECTION_TYPE_EQUI) {
- debug_msg(DEBUG, "Equirectangular projection is used\n");
+ debug_msg(DEBUG, "Equirectangular projection is used");
ret = mmfile_read(fp, (unsigned char *)&equi, sizeof(MMFILE_WEBM_EQUI_PROJ_V2_BOX));
if (ret == MMFILE_UTIL_FAIL) {
- debug_error(DEBUG, "error: failed to read equirectangular element\n");
+ debug_error(DEBUG, "error: failed to read equirectangular element");
goto exit;
}
if (strncmp((char *)equi.proj_priv_box_name, "equi", 4) == 0) {
formatContext->equiBoundsLeftV2 = mmfile_io_be_uint32(equi.equi_projection_bounds_left);
formatContext->equiBoundsRightV2 = mmfile_io_be_uint32(equi.equi_projection_bounds_right);
} else {
- debug_error(DEBUG, "error: failed to read equirectangular element\n");
+ debug_error(DEBUG, "error: failed to read equirectangular element");
ret = MMFILE_UTIL_SUCCESS;
goto exit;
}
}
if (v2box.proj_type_box_value == PROJECTION_TYPE_CBMP) {
- debug_msg(DEBUG, "Cubemap projection is used\n");
+ debug_msg(DEBUG, "Cubemap projection is used");
ret = mmfile_read(fp, (unsigned char *)&cbmp, sizeof(MMFILE_WEBM_CBMP_PROJ_V2_BOX));
if (ret == MMFILE_UTIL_FAIL) {
- debug_error(DEBUG, "error: failed to read cubemap element\n");
+ debug_error(DEBUG, "error: failed to read cubemap element");
goto exit;
}
if (strncmp((char *)cbmp.proj_priv_box_name, "cbmp", 4) == 0) {
formatContext->cbmpLayoutV2 = mmfile_io_be_uint32(cbmp.cbmp_projection_layout);
formatContext->cbmpPaddingV2 = mmfile_io_be_uint32(cbmp.cbmp_projection_padding);
} else {
- debug_error(DEBUG, "error: failed to read cubemap element\n");
+ debug_error(DEBUG, "error: failed to read cubemap element");
ret = MMFILE_UTIL_FAIL;
goto exit;
}
ret = mmfile_read(fp, (unsigned char *)&pose, sizeof(MMFILE_WEBM_POSE_ELEMENT_V2_BOX));
if (ret == MMFILE_UTIL_FAIL) {
- debug_error(DEBUG, "error: failed to read pose info\n");
+ debug_error(DEBUG, "error: failed to read pose info");
goto exit;
}
if (pose.pose_yaw_element_id == POSE_YAW_ELEMENT_ID) {
formatContext->poseYawV2 = (uint)mmfile_io_be_float32(pose.pose_yaw_element_value);
} else {
- debug_error(DEBUG, "error: failed to pose yaw element\n");
+ debug_error(DEBUG, "error: failed to pose yaw element");
ret = MMFILE_UTIL_FAIL;
goto exit;
}
if (pose.pose_pitch_element_id == POSE_PITCH_ELEMENT_ID) {
formatContext->posePitchV2 = (uint)mmfile_io_be_float32(pose.pose_pitch_element_value);
} else {
- debug_error(DEBUG, "error: failed to pose pitch element\n");
+ debug_error(DEBUG, "error: failed to pose pitch element");
ret = MMFILE_UTIL_FAIL;
goto exit;
}
if (pose.pose_roll_element_id == POSE_ROLL_ELEMENT_ID) {
formatContext->poseRollV2 = (uint)mmfile_io_be_float32(pose.pose_roll_element_value);
} else {
- debug_error(DEBUG, "error: failed to pose roll element\n");
+ debug_error(DEBUG, "error: failed to pose roll element");
ret = MMFILE_UTIL_FAIL;
goto exit;
}
return ret;
}
-EXPORT_API int MMFileUtilGetMetaDataFromMP4(MMFileFormatContext *formatContext)
+int MMFileUtilGetMetaDataFromMP4(MMFileFormatContext *formatContext)
{
MMFileIOHandle *fp = NULL;
int ret = 0;
ret = mmfile_open(&fp, formatContext->uriFileName, MMFILE_RDONLY);
if (ret == MMFILE_UTIL_FAIL) {
- debug_error(DEBUG, "error: mmfile_open\n");
+ debug_error(DEBUG, "error: mmfile_open");
goto exit;
}
basic_header.start_offset = mmfile_tell(fp);
+ if (basic_header.start_offset < 0) {
+ debug_error(DEBUG, "error: mmfile_tell");
+ goto exit;
+ }
if (g_junk_counter_limit == 0)
- g_junk_counter_limit = GetJunkCounterLimit();
+ g_junk_counter_limit = mmfile_get_int_from_ini(MMFILE_INI_JUNKCNTLIMIT, MMFILE_DEFAULT_JUNKCNTLIMIT);
while ((ret != MMFILE_UTIL_FAIL) && ((readed = mmfile_read(fp, (unsigned char *)&basic_header, MMFILE_MP4_BASIC_BOX_HEADER_LEN)) == MMFILE_MP4_BASIC_BOX_HEADER_LEN)) {
basic_header.size = mmfile_io_be_uint32(basic_header.size);
basic_header.type = mmfile_io_le_uint32(basic_header.type);
if (basic_header.size == 0) {
- debug_warning(DEBUG, "header is invalid.\n");
+ debug_warning(DEBUG, "header is invalid.");
basic_header.size = readed;
basic_header.type = 0;
chunk_size = basic_header.size;
switch (basic_header.type) {
case FOURCC('m', 'o', 'o', 'v'): {
- debug_msg(RELEASE, "MPEG4: [moov] SIZE: [%lld]Byte\n", chunk_size);
+ debug_msg(RELEASE, "MPEG4: [moov] SIZE: [%lld]Byte", chunk_size);
moov_end = basic_header.start_offset + chunk_size;
break;
}
case FOURCC('u', 'd', 't', 'a'): {
- debug_msg(RELEASE, "MPEG4: [udat] SIZE: [%lld]Byte\n", chunk_size);
+ debug_msg(RELEASE, "MPEG4: [udat] SIZE: [%lld]Byte", chunk_size);
break;
}
/*/////////////////////////////////////////////////////////////// */
/* Extracting Tag Data // */
/*/////////////////////////////////////////////////////////////// */
case FOURCC('t', 'i', 't', 'l'): {
- debug_msg(RELEASE, "MPEG4: [titl] SIZE: [%lld]Byte\n", chunk_size);
+ debug_msg(RELEASE, "MPEG4: [titl] SIZE: [%lld]Byte", chunk_size);
GetStringFromTextTagBox(formatContext, fp, &basic_header, eMMFILE_3GP_TAG_TITLE);
break;
}
case FOURCC('d', 's', 'c', 'p'): {
- debug_msg(RELEASE, "MPEG4: [dscp] SIZE: [%lld]Byte\n", chunk_size);
+ debug_msg(RELEASE, "MPEG4: [dscp] SIZE: [%lld]Byte", chunk_size);
GetStringFromTextTagBox(formatContext, fp, &basic_header, eMMFILE_3GP_TAG_CAPTION);
break;
}
case FOURCC('c', 'p', 'r', 't'): {
- debug_msg(RELEASE, "MPEG4: [cprt] SIZE: [%lld]Byte\n", chunk_size);
+ debug_msg(RELEASE, "MPEG4: [cprt] SIZE: [%lld]Byte", chunk_size);
GetStringFromTextTagBox(formatContext, fp, &basic_header, eMMFILE_3GP_TAG_COPYRIGHT);
break;
}
case FOURCC('p', 'e', 'r', 'f'): {
- debug_msg(RELEASE, "MPEG4: [perf] SIZE: [%lld]Byte\n", chunk_size);
+ debug_msg(RELEASE, "MPEG4: [perf] SIZE: [%lld]Byte", chunk_size);
GetStringFromTextTagBox(formatContext, fp, &basic_header, eMMFILE_3GP_TAG_PERFORMER);
break;
}
case FOURCC('a', 'u', 't', 'h'): {
- debug_msg(RELEASE, "MPEG4: [auth] SIZE: [%lld]Byte\n", chunk_size);
+ debug_msg(RELEASE, "MPEG4: [auth] SIZE: [%lld]Byte", chunk_size);
GetStringFromTextTagBox(formatContext, fp, &basic_header, eMMFILE_3GP_TAG_AUTHOR);
break;
}
case FOURCC('g', 'n', 'r', 'e'): {
- debug_msg(RELEASE, "MPEG4: [gnre] SIZE: [%lld]Byte\n", chunk_size);
+ debug_msg(RELEASE, "MPEG4: [gnre] SIZE: [%lld]Byte", chunk_size);
GetStringFromTextTagBox(formatContext, fp, &basic_header, eMMFILE_3GP_TAG_GENRE);
break;
}
case FOURCC('a', 'l', 'b', 'm'): {
- debug_msg(RELEASE, "MPEG4: [albm] SIZE: [%lld]Byte\n", chunk_size);
+ debug_msg(RELEASE, "MPEG4: [albm] SIZE: [%lld]Byte", chunk_size);
GetAlbumFromAlbumTagBox(formatContext, fp, &basic_header);
break;
}
case FOURCC('y', 'r', 'r', 'c'): {
- debug_msg(RELEASE, "MPEG4: [yrrc] SIZE: [%lld]Byte\n", chunk_size);
+ debug_msg(RELEASE, "MPEG4: [yrrc] SIZE: [%lld]Byte", chunk_size);
GetYearFromYearTagBox(formatContext, fp, &basic_header);
break;
}
case FOURCC('r', 't', 'n', 'g'): {
- debug_msg(RELEASE, "MPEG4: [rtng] SIZE: [%lld]Byte\n", chunk_size);
+ debug_msg(RELEASE, "MPEG4: [rtng] SIZE: [%lld]Byte", chunk_size);
GetRatingFromRatingTagBox(formatContext, fp, &basic_header); /* not use */
break;
}
case FOURCC('c', 'l', 's', 'f'): {
- debug_msg(RELEASE, "MPEG4: [clsf] SIZE: [%lld]Byte\n", chunk_size);
+ debug_msg(RELEASE, "MPEG4: [clsf] SIZE: [%lld]Byte", chunk_size);
GetClassficationFromClsfTagBox(formatContext, fp, &basic_header);
break;
}
case FOURCC('k', 'y', 'w', 'd'): {
- debug_msg(RELEASE, "MPEG4: [kywd] SIZE: [%lld]Byte\n", chunk_size);
+ debug_msg(RELEASE, "MPEG4: [kywd] SIZE: [%lld]Byte", chunk_size);
ret = mmfile_seek(fp, basic_header.start_offset + chunk_size, SEEK_SET);
break;
}
case FOURCC('l', 'o', 'c', 'i'): {
- debug_msg(RELEASE, "MPEG4: [loci] SIZE: [%lld]Byte\n", chunk_size);
+ debug_msg(RELEASE, "MPEG4: [loci] SIZE: [%lld]Byte", chunk_size);
GetLocationFromLociTagBox(formatContext, fp, &basic_header);
break;
}
/* Check smta in user data field (moov) to be compatible with android */
case FOURCC('s', 'm', 't', 'a'): {
- debug_msg(RELEASE, "MPEG4: [smta] SIZE: [%lld]Byte\n", chunk_size);
+ debug_msg(RELEASE, "MPEG4: [smta] SIZE: [%lld]Byte", chunk_size);
GetSAUTInfoFromSMTATagBox(formatContext, fp, &basic_header);
break;
}
/* Check cdis in user data field (moov) to be compatible with android */
case FOURCC('c', 'd', 'i', 's'): {
- debug_msg(RELEASE, "MPEG4: [smta] SIZE: [%lld]Byte\n", chunk_size);
+ debug_msg(RELEASE, "MPEG4: [smta] SIZE: [%lld]Byte", chunk_size);
GetValueFromCDISTagBox(formatContext, fp, &basic_header);
break;
}
/* Extracting ID3 Tag Data // */
/*/////////////////////////////////////////////////////////////// */
case FOURCC('m', 'e', 't', 'a'): {
- debug_msg(RELEASE, "MPEG4: [meta] SIZE: [%lld]Byte\n", chunk_size);
+ debug_msg(RELEASE, "MPEG4: [meta] SIZE: [%lld]Byte", chunk_size);
GetTagFromMetaBox(formatContext, fp, &basic_header);
break;
}
case FOURCC('t', 'r', 'a', 'k'): {
- debug_msg(RELEASE, "MPEG4: [trak] SIZE: [%lld]Byte\n", chunk_size);
+ debug_msg(RELEASE, "MPEG4: [trak] SIZE: [%lld]Byte", chunk_size);
break;
}
case FOURCC('u', 'u', 'i', 'd'): {
unsigned long uuid[4] = {0, };
- debug_msg(RELEASE, "MPEG4: [uuid] SIZE: [%lld]Byte\n", chunk_size);
+ debug_msg(RELEASE, "MPEG4: [uuid] SIZE: [%lld]Byte", chunk_size);
mmfile_read(fp, (unsigned char *)uuid, sizeof(uuid));
}
#endif
- debug_msg(RELEASE, "Extracting tags from UUID XML string %s\n", str);
+ debug_msg(RELEASE, "Extracting tags from UUID XML string %s", str);
ParseSpatialVideoMetadataFromXMLString(str, formatContext);
}
break;
}
case FOURCC('m', 'd', 'i', 'a'): {
- debug_msg(RELEASE, "MPEG4: [mdia] SIZE: [%lld]Byte\n", chunk_size);
+ debug_msg(RELEASE, "MPEG4: [mdia] SIZE: [%lld]Byte", chunk_size);
break;
}
case FOURCC('m', 'i', 'n', 'f'): {
- debug_msg(RELEASE, "MPEG4: [minf] SIZE: [%lld]Byte\n", chunk_size);
+ debug_msg(RELEASE, "MPEG4: [minf] SIZE: [%lld]Byte", chunk_size);
break;
}
case FOURCC('s', 't', 'b', 'l'): {
- debug_msg(RELEASE, "MPEG4: [stbl] SIZE: [%lld]Byte\n", chunk_size);
+ debug_msg(RELEASE, "MPEG4: [stbl] SIZE: [%lld]Byte", chunk_size);
break;
}
case FOURCC('s', 't', 's', 'd'): {
- debug_msg(RELEASE, "MPEG4: [stsd] SIZE: [%lld]Byte\n", chunk_size);
+ debug_msg(RELEASE, "MPEG4: [stsd] SIZE: [%lld]Byte", chunk_size);
break;
}
case FOURCC('m', 'p', '4', 'a'): {
- debug_msg(RELEASE, "MPEG4: [mp4a] SIZE: [%lld]Byte\n", chunk_size);
+ debug_msg(RELEASE, "MPEG4: [mp4a] SIZE: [%lld]Byte", chunk_size);
GetSA3DInfoFromMP4ATagBox(formatContext, fp, &basic_header);
ret = mmfile_seek(fp, basic_header.start_offset + chunk_size, SEEK_SET);
break;
}
case FOURCC('a', 'v', 'c', '1'): {
- debug_msg(RELEASE, "MPEG4: [avc1] SIZE: [%lld]Byte (offset: %lld)\n", chunk_size, basic_header.start_offset);
+ debug_msg(RELEASE, "MPEG4: [avc1] SIZE: [%lld]Byte (offset: %lld)", chunk_size, basic_header.start_offset);
GetVideoV2MetadataFromAvc1TagBox(formatContext, fp, &basic_header);
break;
}
default: {
- debug_msg(RELEASE, "4CC: Not Support [%c%c%c%c]. So skip it. Size [%lld Byte]\n",
+ debug_msg(RELEASE, "4CC: Not Support [%c%c%c%c]. So skip it. Size [%lld Byte]",
((char *)&basic_header.type)[0], ((char *)&basic_header.type)[1],
((char *)&basic_header.type)[2], ((char *)&basic_header.type)[3], chunk_size);
ret = mmfile_seek(fp, basic_header.start_offset + chunk_size, SEEK_SET);
}
if (ret == MMFILE_UTIL_FAIL) {
- debug_error(DEBUG, "mmfile operation is error\n");
+ debug_error(DEBUG, "mmfile operation is error");
ret = -1;
goto exit;
}
return ret;
}
-static char *get_string(const char *buf, int buf_size, int *bytes_written)
+static bool __get_genre_num(const char *buffer, int *si)
{
- int i = 0, c = 0;
- char *q = NULL;
- char str[512] = {0, };
-
- q = str;
- for (i = 0; i < buf_size; i++) {
- c = buf[i];
- if (c == '\0')
- break;
- if ((q - str) >= (int)sizeof(str) - 1)
- break;
- *q++ = c;
- }
- *q = '\0';
+ int len = strlen(buffer);
+ char *tmp_genre = NULL;
- if (strlen(str) > 0) {
- *bytes_written = strlen(str);
- return strdup(str);
- } else {
- *bytes_written = 0;
- return NULL;
- }
-}
+ /* Genre format: (###), ### */
+ if (len > 6 || len == 0)
+ return false;
-char *rtrimN(char *pStr)
-{
- int pos = 0;
- pos = strlen(pStr) - 1;
- for (; pos >= 0; pos--) {
- if (pStr[pos] == 0x20) {
- pStr[pos] = 0x00;
- } else {
- break;
- }
+ /* Check first c */
+ if (len == 1) {
+ if (!g_ascii_isdigit(buffer[0]))
+ return false;
+ } else {
+ if (!g_ascii_isdigit(buffer[1]))
+ return false;
}
- return strdup(pStr);
-}
+ /* Remove bind () if exist */
+ tmp_genre = g_strdup(buffer);
+ if (g_str_has_prefix(tmp_genre, "(") && g_str_has_suffix(tmp_genre, ")"))
+ tmp_genre[0] = '0';
-bool safe_atoi(char *buffer, int *si)
+ *si = atoi(tmp_genre);
+ g_free(tmp_genre);
-{
- char *end;
- errno = 0;
-
- const long sl = strtol(buffer, &end, 10);
-
- if (end == buffer) {
- debug_error(RELEASE, "not a decimal number");
- return FALSE;
- } else if ('\0' != *end) {
- debug_error(RELEASE, "extra characters at end of input: %s", end);
- return FALSE;
- } else if ((LONG_MIN == sl || LONG_MAX == sl) && (ERANGE == errno)) {
- debug_error(RELEASE, "out of range of type long");
- return FALSE;
- } else if (sl > INT_MAX) {
- debug_error(RELEASE, "greater than INT_MAX");
- return FALSE;
- } else if (sl < INT_MIN) {
- debug_error(RELEASE, "less than INT_MIN");
- return FALSE;
- } else {
- *si = (int)sl;
- }
- return TRUE;
+ return true;
}
static bool make_characterset_array(char ***charset_array)
(*charset_array)[AV_ID3V2_UTF16] = strdup("UCS2");
(*charset_array)[AV_ID3V2_UTF16_BE] = strdup("UTF16-BE");
- (*charset_array)[AV_ID3V2_UTF8] = strdup("UTF-8");
+ (*charset_array)[AV_ID3V2_UTF8] = strdup(MMFILE_CODESET_UTF8);
return true;
}
{
int i = 0;
+ if (!charset_array)
+ return false;
+
for (i = 0; i < AV_ID3V2_MAX; i++) {
if (charset_array[i] != NULL) {
free(charset_array[i]);
}
}
- if (charset_array != NULL) {
- free(charset_array);
- charset_array = NULL;
- }
+ free(charset_array);
+ charset_array = NULL;
return true;
}
{
int i=0;
- for(i = 0; i < AV_ID3TAG_MAX; i++) {
- pInfo->tagInfo[i].length = 0;
+ for(i = 0; i < AV_ID3TAG_MAX; i++)
pInfo->tagInfo[i].value = NULL;
- pInfo->tagInfo[i].marked = false;
- }
pInfo->imageInfo.bURLInfo = false;
pInfo->imageInfo.pImageBuf = NULL;
pInfo->imageInfo.imageLen = 0;
}
-static void _mm_file_id3tag_add_bracket_at_genre(char **genre, int genre_len)
-{
- int int_genre = -1;
- char tmp_genre[6] = {0, };
- int tmp_genre_len = 0;
-
- if (!genre || !(*genre) || genre_len <= 0)
- return;
-
- if (!safe_atoi(*genre, &int_genre)) {
- debug_log(RELEASE, "genre information is not integer [%s]", *genre);
- return;
- }
-
- debug_msg(RELEASE, "genre information is integer [%d]", int_genre);
-
- /* if the value is not kinds of genre, exit */
- if (int_genre < 0 || int_genre >= GENRE_COUNT)
- return;
-
- /* Change int to string with bracket like "(123)"
- * mm_file_id3tag_restore_content_info convert it to string
- */
- memset(tmp_genre, 0, sizeof(tmp_genre));
- snprintf(tmp_genre, sizeof(tmp_genre), "(%d)", int_genre);
-
- tmp_genre_len = strlen(tmp_genre);
- if (tmp_genre_len > 0) {
- *genre = mmfile_realloc(*genre, sizeof(char) * (tmp_genre_len + 1));
- if (*genre)
- SAFE_STRLCPY(*genre, tmp_genre, tmp_genre_len + 1);
- }
-}
-
static void __id3tag_skip_newline(unsigned char *pTagVal, int *nTagLen, int *offset)
{
/* skip newline in text encoding of ID3 tag frame */
*offset += 3;
return AV_ID3V2_UTF16_BE;
} else {
- debug_msg(RELEASE, "id3tag never get here!!\n");
+ debug_msg(RELEASE, "id3tag never get here!!");
return nTextEnc; /* default bypass */
}
} else {
*offset += 2;
return AV_ID3V2_UTF16;
} else {
- debug_msg(RELEASE, "id3tag never get here!!\n");
+ debug_msg(RELEASE, "id3tag never get here!!");
return nTextEnc; /* default bypass */
}
} else if (nTextEnc == AV_ID3V2_UTF8) {
GList *synclyrics_info_list = NULL;
if (nTagLen < MMFILE_SYNC_LYRIC_INFO_MIN_LEN) {
- debug_msg(RELEASE, "failed to get Synchronised lyrics Info realCpyFramNum(%d)\n", nTagLen);
- pInfo->tagInfo[AV_ID3TAG_SYNCLYRICS].length = 0;
+ debug_msg(RELEASE, "failed to get Synchronised lyrics Info realCpyFramNum(%d)", nTagLen);
return;
}
if ((textEncodingType == AV_ID3V2_UTF16) || (textEncodingType == AV_ID3V2_UTF16_BE)) {
- debug_warning(DEBUG, "[%d] not implemented\n", textEncodingType);
+ debug_warning(DEBUG, "[%d] not implemented", textEncodingType);
return;
}
for (idx = 0; idx < nTagLen; idx++) {
if (pTagVal[offset + idx] == 0x00) {
- synclyrics_info = (AvSynclyricsInfo *)mmfile_malloc(sizeof(AvSynclyricsInfo));
- if (synclyrics_info) {
- if (textEncodingType == AV_ID3V2_UTF8) {
- synclyrics_info->lyric_info = mmfile_malloc(copy_len + 1);
- if (synclyrics_info->lyric_info) {
- memset(synclyrics_info->lyric_info, 0, copy_len + 1);
- memcpy(synclyrics_info->lyric_info, pTagVal + copy_start_pos, copy_len);
- synclyrics_info->lyric_info[copy_len] = '\0';
- }
- } else {
- synclyrics_info->lyric_info = mmfile_string_convert((const char *)&pTagVal[copy_start_pos], copy_len, "UTF-8", pCharSet, NULL, NULL);
- }
-
- synclyrics_info->time_info = (unsigned long)pTagVal[offset + idx + 1] << 24 | (unsigned long)pTagVal[offset + idx + 2] << 16 | (unsigned long)pTagVal[offset + idx + 3] << 8 | (unsigned long)pTagVal[offset + idx + 4];
- idx += 4;
- copy_start_pos = offset + idx + 1;
- debug_msg(RELEASE, "[%lu][%s] idx[%d], copy_len[%d] copy_start_pos[%d]", synclyrics_info->time_info, synclyrics_info->lyric_info, idx, copy_len, copy_start_pos);
- copy_len = 0;
- synclyrics_info_list = g_list_append(synclyrics_info_list, synclyrics_info);
- }
+ synclyrics_info = g_new0(AvSynclyricsInfo, 1);
+ if (textEncodingType == AV_ID3V2_UTF8)
+ synclyrics_info->lyric_info = g_memdup2(pTagVal + copy_start_pos, copy_len + 1);
+ else
+ synclyrics_info->lyric_info = mmfile_convert_to_utf8((const char *)&pTagVal[copy_start_pos], copy_len, pCharSet);
+
+ synclyrics_info->time_info = (unsigned long)pTagVal[offset + idx + 1] << 24 | (unsigned long)pTagVal[offset + idx + 2] << 16 | (unsigned long)pTagVal[offset + idx + 3] << 8 | (unsigned long)pTagVal[offset + idx + 4];
+ idx += 4;
+ copy_start_pos = offset + idx + 1;
+ debug_msg(RELEASE, "[%lu][%s] idx[%d], copy_len[%d] copy_start_pos[%d]", synclyrics_info->time_info, synclyrics_info->lyric_info, idx, copy_len, copy_start_pos);
+ copy_len = 0;
+ synclyrics_info_list = g_list_append(synclyrics_info_list, synclyrics_info);
}
copy_len++;
}
pInfo->pSyncLyrics = synclyrics_info_list;
- pInfo->tagInfo[AV_ID3TAG_SYNCLYRICS].length = g_list_length(pInfo->pSyncLyrics);
}
static bool __id3tag_parse_PIC_format(AvFileContentInfo *pInfo, unsigned char *pTagVal, int *offset)
/* get the mime type of Attached PICture, it is text string */
if (pTagVal[*offset] == '\0') {
- debug_msg(RELEASE, "The picture format of PIC is not included\n");
+ debug_msg(RELEASE, "The picture format of PIC is not included");
return false;
}
if (pTagVal[*offset] == '\0') {
pInfo->imageInfo.imgMimetypeLen = 0;
- debug_msg(RELEASE, "The MIME type of APIC is not included\n");
+ debug_msg(RELEASE, "The MIME type of APIC is not included");
return false;
}
}
if ((pTagVal[*offset] != '\0') || (nTagLen <= *offset)) {
- debug_msg(RELEASE, "pTagVal[offset](%d) mimetype is not NULL terminated! realCpyFrameNum - offset(%d)\n",
+ debug_msg(RELEASE, "pTagVal[offset](%d) mimetype is not NULL terminated! realCpyFrameNum - offset(%d)",
pTagVal[*offset], nTagLen - *offset);
return true;
}
(*offset)++;/* end of MIME('\0', 1byte) */
- debug_msg(RELEASE, "after scaning Mime type offset(%d) value!\n", *offset);
+ debug_msg(RELEASE, "after scaning Mime type offset(%d) value!", *offset);
return true;
}
{
/* get the picture type of Attached PICture, it is 1byte(0xff) */
- if (pTagVal[*offset] < AV_ID3V2_PICTURE_TYPE_MAX)
+ if (pTagVal[*offset] < MP3_ID3V2_PICTURE_TYPE_MAX)
pInfo->imageInfo.pictureType = pTagVal[*offset];
else
- debug_msg(RELEASE, "APIC image has invalid picture type(0x%x)\n", pTagVal[*offset]);
+ debug_msg(RELEASE, "APIC image has invalid picture type(0x%x)", pTagVal[*offset]);
(*offset)++;/* PictureType(1byte) */
- debug_msg(RELEASE, "after scaning PictureType(%d) offset(%d) value!\n", pInfo->imageInfo.pictureType, *offset);
+ debug_msg(RELEASE, "after scaning PictureType(%d) offset(%d) value!", pInfo->imageInfo.pictureType, *offset);
}
static void __id3tag_parse_APIC_desc(AvFileContentInfo *pInfo, unsigned char *pTagVal, int nTagLen, const char *pCharSet, int *offset)
int idx = 0;
unsigned int tag_len = 0;
- unsigned int desc_len = 0;
char *tmp_desc = NULL;
if (pTagVal[*offset] == 0x0) {
- pInfo->imageInfo.imgDesLen = 0;
- debug_msg(RELEASE, "The description of APIC is not included!!!\n");
+ debug_msg(RELEASE, "The description of APIC is not included!!!");
return;
}
while (1) {
if (pTagVal[*offset + idx] == '\0') {
if (nTagLen < (*offset + idx)) {
- debug_error(DEBUG, "End of APIC Tag %d %d %d\n", nTagLen, *offset, idx);
+ debug_error(DEBUG, "End of APIC Tag %d %d %d", nTagLen, *offset, idx);
break;
}
/* check end of image description */
tag_len = idx + 1; /* length of description + '\0' */
- tmp_desc = mmfile_calloc(1, sizeof(char) * tag_len);
- if (tmp_desc) {
- memcpy(tmp_desc, pTagVal + *offset, tag_len);
+ tmp_desc = g_memdup2(pTagVal + *offset, tag_len);
- /* convert description */
- pInfo->imageInfo.imageDescription = mmfile_string_convert(tmp_desc, tag_len, "UTF-8", pCharSet, NULL, &desc_len);
- pInfo->imageInfo.imgDesLen = (int)desc_len;
- mmfile_free(tmp_desc);
- debug_msg(RELEASE, "new_desc %s(%d)\n", pInfo->imageInfo.imageDescription, pInfo->imageInfo.imgDesLen);
- }
+ /* convert description */
+ pInfo->imageInfo.imageDescription = mmfile_convert_to_utf8(tmp_desc, tag_len, pCharSet);
+ mmfile_free(tmp_desc);
+ debug_msg(RELEASE, "new_desc %s", pInfo->imageInfo.imageDescription);
*offset += idx;
if ((pTagVal[*offset] != '\0') || (nTagLen <= *offset)) {
- debug_msg(RELEASE, "pTagVal[offset](%d) description is not NULL terminated! realCpyFrameNum - offset(%d)\n",
+ debug_msg(RELEASE, "pTagVal[offset](%d) description is not NULL terminated! realCpyFrameNum - offset(%d)",
pTagVal[*offset], nTagLen - *offset);
return;
}
(*offset)++;
}
- debug_msg(RELEASE, "after scaning APIC description offset(%d) value!\n", *offset);
+ debug_msg(RELEASE, "after scaning APIC description offset(%d) value!", *offset);
if (nTagLen <= *offset) {
- debug_msg(RELEASE, "No APIC image!! realCpyFrameNum(%d) - offset(%d)\n", nTagLen, *offset);
+ debug_msg(RELEASE, "No APIC image!! realCpyFrameNum(%d) - offset(%d)", nTagLen, *offset);
return;
}
pInfo->imageInfo.imageLen = nTagLen - *offset;
- pInfo->imageInfo.pImageBuf = mmfile_malloc(pInfo->imageInfo.imageLen + 1);
-
- if (pInfo->imageInfo.pImageBuf) {
- memcpy(pInfo->imageInfo.pImageBuf, pTagVal + *offset, pInfo->imageInfo.imageLen);
- pInfo->imageInfo.pImageBuf[pInfo->imageInfo.imageLen] = 0;
- }
+ pInfo->imageInfo.pImageBuf = g_memdup2(pTagVal + *offset, pInfo->imageInfo.imageLen);
/* if mimetype is "-->", image date has an URL */
if (IS_INCLUDE_URL(pInfo->imageInfo.imageMIMEType))
debug_fenter(RELEASE);
if (!__id3tag_parse_PIC_format(pInfo, pTagVal, &offset)) {
- debug_msg(RELEASE, "PIC is not valid\n");
+ debug_msg(RELEASE, "PIC is not valid");
return false;
}
debug_fenter(RELEASE);
if (!__id3tag_parse_APIC_mimetype(pInfo, pTagVal, nTagLen, &offset)) {
- debug_msg(RELEASE, "APIC is not valid\n");
+ debug_msg(RELEASE, "APIC is not valid");
return false;
}
return true;
}
-EXPORT_API
-bool mm_file_id3tag_parse_v110(AvFileContentInfo *pInfo, unsigned char *buffer)
+static char * __id3tag_get_v110(const char *buf, ssize_t len, const char *locale)
{
- const char *locale = MMFileUtilGetLocale();
- char *pFullStr = NULL;
+ char *tmp_str = NULL;
- debug_msg(RELEASE, "ID3tag v110--------------------------------------------------------------\n");
+ mm_file_retv_if_fails(buf, NULL);
+ mm_file_retv_if_fails(locale, NULL);
- if (pInfo->tagInfo[AV_ID3TAG_TITLE].marked == false) {
- pFullStr = mmfile_string_convert((const char *)&buffer[3], MP3_ID3_TITLE_LENGTH, "UTF-8", locale, NULL, (unsigned int *)&pInfo->tagInfo[AV_ID3TAG_TITLE].length);
- if (pFullStr != NULL) {
- pInfo->tagInfo[AV_ID3TAG_TITLE].value = rtrimN(pFullStr);
- free(pFullStr);
- }
+ tmp_str = mmfile_convert_to_utf8(buf, len, locale);
- debug_msg(RELEASE, "pInfo->pTitle returned =(%s), pInfo->titleLen(%d)\n", pInfo->tagInfo[AV_ID3TAG_TITLE].value, pInfo->tagInfo[AV_ID3TAG_TITLE].length);
- }
+ /* ID3v1 tag need check length or space. */
+ if (tmp_str && (strlen(tmp_str) == 0 || g_ascii_isspace(tmp_str[0])))
+ mmfile_free(tmp_str);
- if (pInfo->tagInfo[AV_ID3TAG_ARTIST].marked == false) {
- pFullStr = mmfile_string_convert((const char *)&buffer[33], MP3_ID3_ARTIST_LENGTH, "UTF-8", locale, NULL, (unsigned int *)&pInfo->tagInfo[AV_ID3TAG_ARTIST].length);
- if (pFullStr != NULL) {
- pInfo->tagInfo[AV_ID3TAG_ARTIST].value = rtrimN(pFullStr);
- free(pFullStr);
- }
+ return tmp_str;
+}
- debug_msg(RELEASE, "pInfo->pArtist returned =(%s), pInfo->artistLen(%d)\n", pInfo->tagInfo[AV_ID3TAG_ARTIST].value, pInfo->tagInfo[AV_ID3TAG_ARTIST].length);
- }
+bool mm_file_id3tag_parse_v110(AvFileContentInfo *pInfo, unsigned char *buffer)
+{
+ const char *locale = MMFileUtilGetLocale();
- if (pInfo->tagInfo[AV_ID3TAG_ALBUM].marked == false) {
- pFullStr = mmfile_string_convert((const char *)&buffer[63], MP3_ID3_ALBUM_LENGTH, "UTF-8", locale, NULL, (unsigned int *)&pInfo->tagInfo[AV_ID3TAG_ALBUM].length);
- if (pFullStr != NULL) {
- pInfo->tagInfo[AV_ID3TAG_ALBUM].value = rtrimN(pFullStr);
- free(pFullStr);
- }
+ debug_msg(RELEASE, "ID3tag v110--------------------------------------------------------------");
- debug_msg(RELEASE, "pInfo->pAlbum returned =(%s), pInfo->albumLen(%d)\n", pInfo->tagInfo[AV_ID3TAG_ALBUM].value, pInfo->tagInfo[AV_ID3TAG_ALBUM].length);
+ if (!pInfo->tagInfo[AV_ID3TAG_TITLE].value) {
+ pInfo->tagInfo[AV_ID3TAG_TITLE].value = __id3tag_get_v110((const char *)&buffer[3], MP3_ID3_TITLE_LENGTH, locale);
+
+ debug_msg(RELEASE, "pInfo->pTitle returned =(%s)", pInfo->tagInfo[AV_ID3TAG_TITLE].value);
}
- if (pInfo->tagInfo[AV_ID3TAG_YEAR].marked == false) {
+ if (!pInfo->tagInfo[AV_ID3TAG_ARTIST].value) {
+ pInfo->tagInfo[AV_ID3TAG_ARTIST].value = __id3tag_get_v110((const char *)&buffer[33], MP3_ID3_ARTIST_LENGTH, locale);
- pInfo->tagInfo[AV_ID3TAG_YEAR].value = mmfile_string_convert((const char *)&buffer[93], MP3_ID3_YEAR_LENGTH, "UTF-8", locale, NULL, (unsigned int *)&pInfo->tagInfo[AV_ID3TAG_YEAR].length);
+ debug_msg(RELEASE, "pInfo->pArtist returned =(%s)", pInfo->tagInfo[AV_ID3TAG_ARTIST].value);
+ }
- debug_msg(RELEASE, "pInfo->pYear returned =(%s), pInfo->yearLen(%d)\n", pInfo->tagInfo[AV_ID3TAG_YEAR].value, pInfo->tagInfo[AV_ID3TAG_YEAR].length);
+ if (!pInfo->tagInfo[AV_ID3TAG_ALBUM].value) {
+ pInfo->tagInfo[AV_ID3TAG_ALBUM].value = __id3tag_get_v110((const char *)&buffer[63], MP3_ID3_ALBUM_LENGTH, locale);
- if (pInfo->tagInfo[AV_ID3TAG_YEAR].value == NULL) { /*Use same logic with ffmpeg*/
- pInfo->tagInfo[AV_ID3TAG_YEAR].value = get_string((const char *)&buffer[93], MP3_ID3_YEAR_LENGTH, (int *)&pInfo->tagInfo[AV_ID3TAG_YEAR].length);
- debug_msg(RELEASE, "pInfo->pYear returned =(%s), pInfo->yearLen(%d)\n", pInfo->tagInfo[AV_ID3TAG_YEAR].value, pInfo->tagInfo[AV_ID3TAG_YEAR].length);
- }
+ debug_msg(RELEASE, "pInfo->pAlbum returned =(%s)", pInfo->tagInfo[AV_ID3TAG_ALBUM].value);
}
- if (pInfo->tagInfo[AV_ID3TAG_COMMENT].marked == false) {
- pInfo->tagInfo[AV_ID3TAG_COMMENT].value = mmfile_string_convert((const char *)&buffer[97], MP3_ID3_DESCRIPTION_LENGTH, "UTF-8", locale, NULL, (unsigned int *)&pInfo->tagInfo[AV_ID3TAG_COMMENT].length);
- debug_msg(RELEASE, "pInfo->pComment returned =(%s), pInfo->commentLen(%d)\n", pInfo->tagInfo[AV_ID3TAG_COMMENT].value, pInfo->tagInfo[AV_ID3TAG_COMMENT].length);
+ if (!pInfo->tagInfo[AV_ID3TAG_YEAR].value) {
+ pInfo->tagInfo[AV_ID3TAG_YEAR].value = __id3tag_get_v110((const char *)&buffer[93], MP3_ID3_YEAR_LENGTH, locale);
- if (pInfo->tagInfo[AV_ID3TAG_COMMENT].value == NULL) { /*Use same logic with ffmpeg*/
- pInfo->tagInfo[AV_ID3TAG_COMMENT].value = get_string((const char *)&buffer[97], MP3_ID3_DESCRIPTION_LENGTH, (int *)&pInfo->tagInfo[AV_ID3TAG_COMMENT]);
- debug_msg(RELEASE, "pInfo->pComment returned =(%s), pInfo->commentLen(%d)\n", pInfo->tagInfo[AV_ID3TAG_COMMENT].value, pInfo->tagInfo[AV_ID3TAG_COMMENT].length);
- }
+ debug_msg(RELEASE, "pInfo->pYear returned =(%s)", pInfo->tagInfo[AV_ID3TAG_YEAR].value);
}
- if (pInfo->tagInfo[AV_ID3TAG_TRACKNUM].marked == false) {
- pInfo->tagInfo[AV_ID3TAG_TRACKNUM].value = mmfile_malloc(ID3TAG_V110_TRACK_NUM_DIGIT);
- if (pInfo->tagInfo[AV_ID3TAG_TRACKNUM].value != NULL) {
- pInfo->tagInfo[AV_ID3TAG_TRACKNUM].value[ID3TAG_V110_TRACK_NUM_DIGIT - 1] = 0;
- snprintf(pInfo->tagInfo[AV_ID3TAG_TRACKNUM].value, ID3TAG_V110_TRACK_NUM_DIGIT, "%04d", (int)buffer[126]);
- pInfo->tagInfo[AV_ID3TAG_TRACKNUM].length = strlen(pInfo->tagInfo[AV_ID3TAG_TRACKNUM].value);
+ if (!pInfo->tagInfo[AV_ID3TAG_COMMENT].value) {
+ pInfo->tagInfo[AV_ID3TAG_COMMENT].value = __id3tag_get_v110((const char *)&buffer[97], MP3_ID3_DESCRIPTION_LENGTH, locale);
- debug_msg(RELEASE, "pInfo->pTrackNum returned =(%s), pInfo->tracknumLen(%d)\n", pInfo->tagInfo[AV_ID3TAG_TRACKNUM].value, pInfo->tagInfo[AV_ID3TAG_TRACKNUM].length);
- }
+ debug_msg(RELEASE, "pInfo->pComment returned =(%s)", pInfo->tagInfo[AV_ID3TAG_COMMENT].value);
}
- if (pInfo->tagInfo[AV_ID3TAG_GENRE].marked == false) {
- pInfo->genre = buffer[127];
- debug_msg(RELEASE, "pInfo->genre returned genre number (%d)\n", pInfo->genre);
+ if (!pInfo->tagInfo[AV_ID3TAG_TRACKNUM].value) {
+ pInfo->tagInfo[AV_ID3TAG_TRACKNUM].value = g_malloc0(ID3TAG_V110_TRACK_NUM_DIGIT);
+ pInfo->tagInfo[AV_ID3TAG_TRACKNUM].value[ID3TAG_V110_TRACK_NUM_DIGIT - 1] = 0;
+ snprintf(pInfo->tagInfo[AV_ID3TAG_TRACKNUM].value, ID3TAG_V110_TRACK_NUM_DIGIT, "%04d", (int)buffer[126]);
+
+ debug_msg(RELEASE, "pInfo->pTrackNum returned =(%s)", pInfo->tagInfo[AV_ID3TAG_TRACKNUM].value);
}
+ /*ID3V2 genre is stored in pInfo->tagInfo[AV_ID3TAG_GENRE].value */
+ /*pInfo->genre is used when ID3V2 genre is invalid, or empty. */
+ pInfo->genre = buffer[127];
+ debug_msg(RELEASE, "pInfo->genre returned genre number (%d)", pInfo->genre);
+
return true;
}
-static AvID3TagList __get_tag_info_v222(const char *tag)
+static AvID3TagList __get_tag_info_v222(const unsigned char *tag)
{
unsigned int n = 0;
int i = 0;
}
}
- debug_msg(RELEASE, "(%s) This Frame ID currently not Supports!!\n", tag);
+ debug_msg(RELEASE, "(%s) This Frame ID currently not Supports!!", tag);
return AV_ID3TAG_MAX;
}
-static AvID3TagList __get_tag_info_v223(const char *tag)
+static AvID3TagList __get_tag_info_v223(const unsigned char *tag)
{
unsigned int n = 0;
int i = 0;
}
}
- debug_msg(RELEASE, "(%s) This Frame ID currently not Supports!!\n", tag);
+ debug_msg(RELEASE, "(%s) This Frame ID currently not Supports!!", tag);
return AV_ID3TAG_MAX;
}
-EXPORT_API
-bool mm_file_id3tag_parse_v222(AvFileContentInfo *pInfo, unsigned char *buffer)
+
+bool mm_file_id3tag_parse_v222(AvFileContentInfo *pInfo, unsigned char *buffer, bool extract_artwork)
{
- unsigned long taglen = 0;
- unsigned long needToloopv2taglen;
- unsigned long oneFrameLen = 0;
- unsigned long curPos = 0;
- char CompTmp[4];
- unsigned char *pExtContent = NULL;
- unsigned long purelyFramelen = 0;
- unsigned int encodingOffSet = 0;
- int realCpyFrameNum = 0, tmp = 0;
- int textEncodingType = 0;
+ int curPos = MP3_TAGv2_HEADER_LEN;
+ int frameLen = 0;
+ int encOffset = 0;
+ int encType = 0;
char **charset_array = NULL;
AvID3TagList tag_id = AV_ID3TAG_MAX;
- make_characterset_array(&charset_array);
+ if (pInfo->tagV2Info.tagLen <= 0)
+ return false;
+ make_characterset_array(&charset_array);
init_content_info(pInfo);
- taglen = pInfo->tagV2Info.tagLen;
- needToloopv2taglen = taglen - MP3_TAGv2_HEADER_LEN;
- curPos = MP3_TAGv2_HEADER_LEN;
+ debug_msg(RELEASE, "ID3tag v222--------------------------------------------------------------");
- debug_msg(RELEASE, "ID3tag v222--------------------------------------------------------------\n");
-
- while (needToloopv2taglen > MP3_TAGv2_22_TXT_HEADER_LEN) {
- if ((buffer[curPos] < '0' || buffer[curPos] > 'Z') || (buffer[curPos + 1] < '0' || buffer[curPos + 1] > 'Z')
- || (buffer[curPos + 2] < '0' || buffer[curPos + 2] > 'Z'))
+ while (curPos + MP3_TAGv2_22_TXT_HEADER_LEN < pInfo->tagV2Info.tagLen) {
+ if (!g_ascii_isalnum(buffer[curPos]) || !g_ascii_isalnum(buffer[curPos + 1]) || !g_ascii_isalnum(buffer[curPos + 2]))
break;
- memcpy(CompTmp, &buffer[curPos], 3);
-
- CompTmp[3] = 0;
- oneFrameLen = MP3_TAGv2_22_TXT_HEADER_LEN;
- oneFrameLen += (unsigned long)buffer[3 + curPos] << 16 | (unsigned long)buffer[4 + curPos] << 8
- | (unsigned long)buffer[5 + curPos];
-
- if (oneFrameLen > taglen - curPos)
+ tag_id = __get_tag_info_v222(&buffer[curPos]);
+ frameLen = buffer[curPos + 3] << 16 | buffer[curPos + 4] << 8 | buffer[curPos + 5];
+ curPos += MP3_TAGv2_22_TXT_HEADER_LEN;
+ if (curPos + frameLen > pInfo->tagV2Info.tagLen)
break;
- purelyFramelen = oneFrameLen - MP3_TAGv2_22_TXT_HEADER_LEN;
- curPos += oneFrameLen;
-
- tag_id = __get_tag_info_v222(CompTmp);
- if (tag_id != AV_ID3TAG_MAX && !pInfo->tagInfo[tag_id].marked && purelyFramelen > 0) {
- if (buffer[curPos - purelyFramelen] == 0x00) {
- encodingOffSet = 1;
- textEncodingType = AV_ID3V2_ISO_8859;
- } else if (buffer[curPos - purelyFramelen] == 0x01) {
- encodingOffSet = 1;
- textEncodingType = AV_ID3V2_UTF16;
- }
-
- /*in order to deliver valid string to MP */
- while ((buffer[curPos - purelyFramelen + encodingOffSet] < 0x20) && (encodingOffSet < purelyFramelen))
- encodingOffSet++;
-
- if (encodingOffSet < purelyFramelen) {
- realCpyFrameNum = purelyFramelen - encodingOffSet;
- mmfile_free(pExtContent);
- pExtContent = mmfile_malloc(realCpyFrameNum + 3);
-
- if (pExtContent == NULL) {
- debug_error(DEBUG, "out of memory for pExtContent\n");
- continue;
- }
-
- memset(pExtContent, '\0', realCpyFrameNum + 3);
-
- memcpy(pExtContent, &buffer[curPos - purelyFramelen + encodingOffSet], purelyFramelen - encodingOffSet);
-
- if (realCpyFrameNum > 0) {
- switch (tag_id) {
- case AV_ID3TAG_COMMENT:
- /*skip language data! */
- if (realCpyFrameNum > 4) {
- realCpyFrameNum -= 4;
- tmp = 4;
+ if (frameLen <= 0)
+ continue;
- /*pExtContent[tmp+1] value should't have encoding value */
- if (pExtContent[tmp] > 0x20 && (pExtContent[tmp - 1] == 0x00 || pExtContent[tmp - 1] == 0x01)) {
- textEncodingType = __id3tag_get_text_encoding_v222(pExtContent, tmp);
- pInfo->tagInfo[tag_id].value = mmfile_string_convert((const char *)pExtContent, realCpyFrameNum, "UTF-8", charset_array[textEncodingType], NULL, (unsigned int *)&pInfo->tagInfo[tag_id].length);
- pInfo->tagInfo[tag_id].marked = true;
- } else {
- debug_msg(RELEASE, "mmf_file_id3tag_parse_v222: failed to get Comment Info tmp(%d), purelyFramelen - encodingOffSet(%lu)\n", tmp, purelyFramelen - encodingOffSet);
- }
- } else {
- debug_msg(RELEASE, "mmf_file_id3tag_parse_v222: Description info too small to parse realCpyFrameNum(%d)\n", realCpyFrameNum);
- }
- break;
+ if (tag_id == AV_ID3TAG_MAX || pInfo->tagInfo[tag_id].value)
+ goto NEXT;
- case AV_ID3TAG_URL:
- if (realCpyFrameNum > 4) {
- /*skip language data! */
- realCpyFrameNum -= 4;
- tmp = 4;
+ if (buffer[curPos] == 0x00) {
+ encOffset = 1;
+ encType = AV_ID3V2_ISO_8859;
+ } else if (buffer[curPos] == 0x01) {
+ encOffset = 1;
+ encType = AV_ID3V2_UTF16;
+ }
- /*pExtContent[tmp+1] value should't have null value */
- if (pExtContent[tmp] > 0x20 && (pExtContent[tmp - 1] == 0x00 || pExtContent[tmp - 1] == 0x01)) {
- textEncodingType = __id3tag_get_text_encoding_v222(pExtContent, tmp);
-
- pInfo->tagInfo[tag_id].value = mmfile_string_convert((const char *)pExtContent, realCpyFrameNum, "UTF-8", charset_array[textEncodingType], NULL, (unsigned int *)&pInfo->tagInfo[tag_id].length);
- pInfo->tagInfo[tag_id].marked = true;
- } else {
- debug_msg(RELEASE, "mmf_file_id3tag_parse_v222: failed to get URL Info tmp(%d), purelyFramelen - encodingOffSet(%lu)\n", tmp, purelyFramelen - encodingOffSet);
- }
- } else {
- debug_msg(RELEASE, "mmf_file_id3tag_parse_v222: URL info too small to parse realCpyFrameNum(%d)\n", realCpyFrameNum);
- }
- break;
+ /*in order to deliver valid string to MP */
+ while ((buffer[curPos + encOffset] < 0x20) && (encOffset < frameLen))
+ encOffset++;
+ if (frameLen == encOffset) {
+ debug_warning(DEBUG, "warning: invalid frame length %d %d", frameLen, encOffset);
+ goto NEXT;
+ }
- case AV_ID3TAG_PICTURE:
- if ((realCpyFrameNum <= 2000000) && _mm_file_id3tag_parse_PIC(pInfo, pExtContent, realCpyFrameNum, (const char*)charset_array[textEncodingType]))
- pInfo->tagInfo[tag_id].marked = true;
- break;
+ curPos += encOffset;
+ frameLen -= encOffset;
+
+ switch (tag_id) {
+ case AV_ID3TAG_COMMENT:
+ /*
+ https://id3.org/id3v2-00
+ Comment "COM"
+ Frame size $xx xx xx
+ Text encoding $xx
+ Language $xx xx xx
+ Short content description <textstring> $00 (00)
+ The actual text <textstring>
+ */
+ if (frameLen <= 4) {
+ debug_msg(RELEASE, "Too small to parse frameLen(%d)", frameLen);
+ break;
+ }
- default:
- pInfo->tagInfo[tag_id].value = mmfile_string_convert((const char *)pExtContent, realCpyFrameNum, "UTF-8", charset_array[textEncodingType], NULL, (unsigned int *)&pInfo->tagInfo[tag_id].length);
- pInfo->tagInfo[tag_id].marked = true;
+ if (buffer[curPos + 4] > 0x20 && (buffer[curPos + 3] == 0x00 || buffer[curPos + 3] == 0x01)) {
+ encType = __id3tag_get_text_encoding_v222(&buffer[curPos], 4);
+ /*skip language data! */
+ curPos += 4;
+ frameLen -= 4;
+ pInfo->tagInfo[tag_id].value = mmfile_convert_to_utf8((const char *)&buffer[curPos], frameLen, charset_array[encType]);
+ } else {
+ debug_msg(RELEASE, "Failed to get tag: frameLen(%d)", frameLen);
+ }
- if (tag_id == AV_ID3TAG_GENRE)
- _mm_file_id3tag_add_bracket_at_genre(&pInfo->tagInfo[tag_id].value, pInfo->tagInfo[tag_id].length);
- break;
- }
+ break;
- if (pInfo->tagInfo[tag_id].value)
- debug_msg(RELEASE, "[%d] returned = (%s), len = (%d)\n", tag_id, pInfo->tagInfo[tag_id].value, pInfo->tagInfo[tag_id].length);
- }
+ case AV_ID3TAG_PICTURE:
+ if (extract_artwork)
+ _mm_file_id3tag_parse_PIC(pInfo, &buffer[curPos], frameLen, charset_array[encType]);
+ break;
- }
+ default:
+ pInfo->tagInfo[tag_id].value = mmfile_convert_to_utf8((const char *)&buffer[curPos], frameLen, charset_array[encType]);
+ break;
}
- mmfile_free(pExtContent);
- memset(CompTmp, 0, 4);
+ if (pInfo->tagInfo[tag_id].value)
+ debug_msg(RELEASE, "[%d] returned = (%s)", tag_id, pInfo->tagInfo[tag_id].value);
+NEXT:
+ curPos += frameLen;
+ encOffset = 0;
+ encType = 0;
+ }
- if (curPos >= taglen)
- break;
+ release_characterset_array(charset_array);
- needToloopv2taglen -= oneFrameLen;
+ return true;
+}
- oneFrameLen = 0;
- encodingOffSet = 0;
- realCpyFrameNum = 0;
- textEncodingType = 0;
- purelyFramelen = 0;
+static void __get_v223_encoding_info(const unsigned char *buffer,
+ int length,
+ int *offset,
+ unsigned int *type)
+{
+ int _offset = 0;
- }
+ if (!buffer || !offset || !type)
+ return;
- release_characterset_array(charset_array);
+ if (IS_ENCODEDBY_UTF16(buffer)) {
+ *offset = 2;
+ *type = AV_ID3V2_UTF16;
+ return;
+ }
+ if (IS_ENCODEDBY_UTF16_R(buffer)) {
+ *offset = 2;
+ *type = AV_ID3V2_UTF16_BE;
+ return;
+ }
+ if (IS_ENCODEDBY_UTF16(buffer + 1)) {
+ *offset = 3;
+ *type = AV_ID3V2_UTF16;
+ return;
+ }
+ if (IS_ENCODEDBY_UTF16_R(buffer + 1)) {
+ *offset = 3;
+ *type = AV_ID3V2_UTF16_BE;
+ return;
+ }
- if (taglen) {
- return true;
+ if (buffer[0] == 0x00) {
+ *offset = 1;
} else {
- return false;
+ while ((buffer[_offset] < 0x20) && (_offset < length))
+ _offset++;
+ *offset = _offset;
}
+ *type = AV_ID3V2_ISO_8859;
}
-EXPORT_API
-bool mm_file_id3tag_parse_v223(AvFileContentInfo *pInfo, unsigned char *buffer)
+bool mm_file_id3tag_parse_v223(AvFileContentInfo *pInfo, unsigned char *buffer, bool extract_artwork)
{
- unsigned long taglen = 0;
- unsigned long needToloopv2taglen;
- unsigned long oneFrameLen = 0;
- unsigned long curPos = 0;
- char CompTmp[5];
- unsigned char *pExtContent = NULL;
- unsigned long purelyFramelen = 0;
- unsigned int encodingOffSet = 0;
- int realCpyFrameNum = 0, tmp = 0;
- unsigned int textEncodingType = 0;
+ int extendedHeaderLen = 0;
+ int frameLen = 0;
+ int curPos = MP3_TAGv2_HEADER_LEN;
+ int encOffset = 0;
+ unsigned int encType = 0;
char **charset_array = NULL;
AvID3TagList tag_id = AV_ID3TAG_MAX;
char *lang_info = NULL;
- make_characterset_array(&charset_array);
+ if (pInfo->tagV2Info.tagLen <= 0)
+ return false;
+ make_characterset_array(&charset_array);
init_content_info(pInfo);
- taglen = pInfo->tagV2Info.tagLen;
- needToloopv2taglen = taglen - MP3_TAGv2_HEADER_LEN;
- curPos = MP3_TAGv2_HEADER_LEN;
-
- debug_msg(RELEASE, "ID3tag v223--------------------------------------------------------------\n");
-
- /* check Extended Header */
+ debug_msg(RELEASE, "ID3tag v223--------------------------------------------------------------");
if (buffer[5] & 0x40) {
/* if extended header exists, skip it*/
- int extendedHeaderLen = (unsigned long)buffer[10] << 21 | (unsigned long)buffer[11] << 14 | (unsigned long)buffer[12] << 7 | (unsigned long)buffer[13];
-
- debug_msg(RELEASE, "--------------- extendedHeaderLen = %d\n", extendedHeaderLen);
-
- if (extendedHeaderLen > (int)(taglen - curPos)) {
- debug_error(DEBUG, "extended header too long.\n");
+ extendedHeaderLen = buffer[10] << 21 | buffer[11] << 14 | buffer[12] << 7 | buffer[13];
+ debug_msg(RELEASE, "--------------- extendedHeaderLen = %d", extendedHeaderLen);
+ if (extendedHeaderLen > pInfo->tagV2Info.tagLen - MP3_TAGv2_HEADER_LEN) {
+ debug_error(DEBUG, "extended header too long.");
} else {
curPos += extendedHeaderLen;
curPos += 4;
}
}
- while (needToloopv2taglen > MP3_TAGv2_23_TXT_HEADER_LEN) {
- if ((buffer[curPos] < '0' || buffer[curPos] > 'Z') || (buffer[curPos + 1] < '0' || buffer[curPos + 1] > 'Z')
- || (buffer[curPos + 2] < '0' || buffer[curPos + 2] > 'Z') || (buffer[curPos + 3] < '0' || buffer[curPos + 3] > 'Z'))
+ while (curPos + MP3_TAGv2_23_TXT_HEADER_LEN < pInfo->tagV2Info.tagLen) {
+ if (!g_ascii_isalnum(buffer[curPos]) || !g_ascii_isalnum(buffer[curPos + 1]) ||
+ !g_ascii_isalnum(buffer[curPos + 2]) || !g_ascii_isalnum(buffer[curPos + 3]))
break;
- memcpy(CompTmp, &buffer[curPos], 4);
+ tag_id = __get_tag_info_v223(&buffer[curPos]);
+ frameLen = buffer[curPos + 4] << 24 | buffer[curPos + 5] << 16 | buffer[curPos + 6] << 8 | buffer[curPos + 7];
+ curPos += MP3_TAGv2_23_TXT_HEADER_LEN;
+ if (curPos + frameLen > pInfo->tagV2Info.tagLen)
+ break;
- CompTmp[4] = 0;
- oneFrameLen = MP3_TAGv2_23_TXT_HEADER_LEN;
- oneFrameLen += (unsigned long)buffer[4 + curPos] << 24 | (unsigned long)buffer[5 + curPos] << 16
- | (unsigned long)buffer[6 + curPos] << 8 | (unsigned long)buffer[7 + curPos];
+ if (frameLen <= 0)
+ continue;
- debug_msg(RELEASE, "----------------------------------------------------------------------------------------------------\n");
+ if (tag_id == AV_ID3TAG_MAX || pInfo->tagInfo[tag_id].value)
+ goto NEXT;
- if (oneFrameLen > taglen - curPos)
- break;
+ __get_v223_encoding_info(buffer + curPos, frameLen, &encOffset, &encType);
+ if (frameLen <= encOffset) {
+ debug_warning(DEBUG, "warning: invalid frame length %d %d", frameLen, encOffset);
+ goto NEXT;
+ }
- purelyFramelen = oneFrameLen - MP3_TAGv2_23_TXT_HEADER_LEN;
- curPos += oneFrameLen;
-
- tag_id = __get_tag_info_v223(CompTmp);
- if (tag_id != AV_ID3TAG_MAX && !pInfo->tagInfo[tag_id].marked && purelyFramelen > 0) {
- if (IS_ENCODEDBY_UTF16(buffer + (curPos - purelyFramelen))) {
- encodingOffSet = 2;
- debug_msg(RELEASE, "this text string(%s) encoded by UTF16 encodingOffSet(%d)\n", CompTmp, encodingOffSet);
- textEncodingType = AV_ID3V2_UTF16;
- } else if (IS_ENCODEDBY_UTF16_R(buffer + (curPos - purelyFramelen))) {
- encodingOffSet = 2;
- debug_msg(RELEASE, "this text string(%s) encoded by UTF16 encodingOffSet(%d)\n", CompTmp, encodingOffSet);
- textEncodingType = AV_ID3V2_UTF16_BE;
- } else if (IS_ENCODEDBY_UTF16(buffer + (curPos - purelyFramelen + 1))) {
- encodingOffSet = 3;
- debug_msg(RELEASE, "this text string(%s) encoded by UTF16 encodingOffSet(%d)\n", CompTmp, encodingOffSet);
- textEncodingType = AV_ID3V2_UTF16;
- } else if (IS_ENCODEDBY_UTF16_R(buffer + (curPos - purelyFramelen + 1))) {
- encodingOffSet = 3;
- debug_msg(RELEASE, "this text string(%s) encoded by UTF16 encodingOffSet(%d)\n", CompTmp, encodingOffSet);
- textEncodingType = AV_ID3V2_UTF16_BE;
- } else {
- if (buffer[curPos - purelyFramelen + encodingOffSet] == 0x00) {
- debug_msg(RELEASE, "encodingOffset will be set to 1\n");
- encodingOffSet = 1;
- } else {
- debug_msg(RELEASE, "Finding encodingOffset\n");
+ curPos += encOffset;
+ frameLen -= encOffset;
+ encOffset = 0;
- while ((buffer[curPos - purelyFramelen + encodingOffSet] < 0x20) && (encodingOffSet < purelyFramelen)) /* text string encoded by ISO-8859-1 */
- encodingOffSet++;
- }
- textEncodingType = AV_ID3V2_ISO_8859;
- debug_msg(RELEASE, "this text string(%s) encoded by ISO-8859-1 encodingOffSet(%d)\n", CompTmp, encodingOffSet);
+ if (encType != AV_ID3V2_UTF16 && encType != AV_ID3V2_UTF16_BE) {
+ if (tag_id != AV_ID3TAG_COMMENT && tag_id != AV_ID3TAG_UNSYNCLYRICS && tag_id != AV_ID3TAG_SYNCLYRICS) {
+ debug_msg(RELEASE, "get the new text encoding type");
+ encType = buffer[curPos - 1];
}
+ }
- mmfile_free(pExtContent);
-
- if (encodingOffSet < purelyFramelen) {
- realCpyFrameNum = purelyFramelen - encodingOffSet;
- pExtContent = mmfile_malloc(realCpyFrameNum + 3);
+ if (encType > AV_ID3V2_MAX) {
+ debug_msg(DEBUG, "WRONG ENCOIDNG TYPE [%u], TAG ID[%d]", encType, tag_id);
+ goto NEXT;
+ }
- if (pExtContent == NULL) {
- debug_msg(DEBUG, "pExtContent malloc failed\n");
- continue;
- }
+ switch (tag_id) {
+ case AV_ID3TAG_COMMENT:
+ if (frameLen <= 3) {
+ debug_msg(RELEASE, "Description info too small to parse frameLen(%d)", frameLen);
+ break;
+ }
+ frameLen -= 3;
+ encOffset = 3;
- memset(pExtContent, '\0', realCpyFrameNum + 3);
+ if (buffer[curPos] != 0x00 && buffer[curPos] != 0xFF && buffer[curPos] != 0xFE) {
+ debug_msg(RELEASE, "failed to get Comment: frameLen(%d)", frameLen);
+ }
- if (textEncodingType != AV_ID3V2_UTF16 && textEncodingType != AV_ID3V2_UTF16_BE) {
- if (CompTmp[0] == 'T' || (strcmp(CompTmp, "APIC") == 0)) {
- debug_msg(RELEASE, "get the new text ecoding type\n");
- textEncodingType = buffer[curPos - purelyFramelen + encodingOffSet - 1];
- }
- }
+ encType = __id3tag_get_text_encoding_v223(&buffer[curPos], &frameLen, encType, &encOffset);
+ debug_msg(RELEASE, "encOffset(%d) encType(%u), frameLen(%d)", encOffset, encType, frameLen);
+ curPos += encOffset;
+ pInfo->tagInfo[tag_id].value = mmfile_convert_to_utf8((const char *)&buffer[curPos], frameLen, charset_array[encType]);
+ break;
- if (textEncodingType > AV_ID3V2_MAX) {
- debug_msg(DEBUG, "WRONG ENCOIDNG TYPE [%d], FRAME[%s]\n", textEncodingType, (char *)CompTmp);
- continue;
- }
+ case AV_ID3TAG_SYNCLYRICS:
+ if (frameLen <= 5) {
+ debug_msg(RELEASE, "Synchronised lyrics too small to parse frameLen(%d)", frameLen);
+ break;
+ }
+ frameLen -= 5;
+ encOffset = 5;
- memcpy(pExtContent, &buffer[curPos - purelyFramelen + encodingOffSet], purelyFramelen - encodingOffSet);
- if (realCpyFrameNum > 0) {
- switch (tag_id) {
- case AV_ID3TAG_COMMENT:
- if (realCpyFrameNum > 3) {
- realCpyFrameNum -= 3;
- tmp = 3;
-
- /*pExtContent[tmp+1] value should't have encoding value */
- if (pExtContent[tmp] == 0x00 || pExtContent[tmp] == 0xFF || pExtContent[tmp] == 0xFE) {
- textEncodingType = __id3tag_get_text_encoding_v223(pExtContent, &realCpyFrameNum, textEncodingType, &tmp);
-
- debug_msg(RELEASE, "tmp(%d) textEncodingType(%d), realCpyFrameNum(%d)\n", tmp, textEncodingType, realCpyFrameNum);
- pInfo->tagInfo[tag_id].value = mmfile_string_convert((const char *)&pExtContent[tmp], realCpyFrameNum, "UTF-8", charset_array[textEncodingType], NULL, (unsigned int *)&pInfo->tagInfo[tag_id].length);
- pInfo->tagInfo[tag_id].marked= true;
- } else {
- debug_msg(RELEASE, "failed to get Comment Info tmp(%d), purelyFramelen - encodingOffSet(%lu)\n", tmp, purelyFramelen - encodingOffSet);
- }
- } else {
- debug_msg(RELEASE, "Description info too small to parse realCpyFrameNum(%d)\n", realCpyFrameNum);
- }
- break;
+ if (buffer[curPos] != 0x00 && buffer[curPos] != 0xFF && buffer[curPos] != 0xFE) {
+ debug_msg(RELEASE, "failed to get Synchronised lyrics Info curPos(%d), frameLen(%d)", curPos, frameLen);
+ }
+ encType = __id3tag_get_text_encoding_v223(&buffer[curPos], &frameLen, encType, &encOffset);
+ debug_msg(RELEASE, "encOffset(%d) encType(%u), frameLen(%d)", encOffset, encType, frameLen);
+ curPos += encOffset;
+ __id3tag_parse_SYLT(pInfo, buffer, frameLen, charset_array[encType], encType, curPos);
+ break;
- case AV_ID3TAG_SYNCLYRICS:
- if (realCpyFrameNum > 5) {
- realCpyFrameNum -= 5;
- tmp = 5;
+ case AV_ID3TAG_UNSYNCLYRICS:
+ lang_info = strndup((const char *)&buffer[curPos], 3);
- /*pExtContent[tmp+1] value should't have encoding value */
- if (pExtContent[tmp] == 0x00 || pExtContent[tmp] == 0xFF || pExtContent[tmp] == 0xFE) {
- textEncodingType = __id3tag_get_text_encoding_v223(pExtContent, &realCpyFrameNum, textEncodingType, &tmp);
+ if (frameLen <= 3) {
+ debug_msg(RELEASE, "Unsynchronised lyrics too small to parse frameLen(%d)", frameLen);
+ mmfile_free(lang_info);
+ break;
+ }
+ frameLen -= 3;
+ encOffset = 3;
- debug_msg(RELEASE, "tmp(%d) textEncodingType(%d), realCpyFrameNum(%d)\n", tmp, textEncodingType, realCpyFrameNum);
+ if (buffer[curPos] != 0x00 && buffer[curPos] != 0xFF && buffer[curPos] != 0xFE) {
+ debug_msg(RELEASE, "failed to get Unsynchronised lyrics Info curPos(%d), frameLen(%d)", curPos, frameLen);
+ }
+ encType = __id3tag_get_text_encoding_v223(&buffer[curPos], &frameLen, encType, &encOffset);
- __id3tag_parse_SYLT(pInfo, pExtContent, realCpyFrameNum, charset_array[textEncodingType], textEncodingType, tmp);
- pInfo->tagInfo[tag_id].marked= true;
- } else {
- debug_msg(RELEASE, "failed to get Synchronised lyrics Info tmp(%d), purelyFramelen - encodingOffSet(%lu)\n", tmp, purelyFramelen - encodingOffSet);
- }
- } else {
- debug_msg(RELEASE, "Synchronised lyrics too small to parse realCpyFrameNum(%d)\n", realCpyFrameNum);
- }
- break;
-
- case AV_ID3TAG_UNSYNCLYRICS:
- lang_info = strndup((char *)pExtContent, 3);
-
- if (realCpyFrameNum > 3) {
- realCpyFrameNum -= 3;
- tmp = 3;
-
- /*find start of lyrics */
- while (1) {
- if (pExtContent[tmp] == 0x00) {
- if (pExtContent[tmp + 1] == 0x00) {
- realCpyFrameNum -= 2;
- tmp += 2;
- }
- break;
- } else {
- realCpyFrameNum--;
- tmp++;
- }
- }
+ char *char_set = NULL;
- /*pExtContent[tmp+1] value should't have encoding value */
- debug_msg(RELEASE, "tpExtContent[%d] %x\n", tmp, pExtContent[tmp]);
+ debug_msg(RELEASE, "encOffset(%d) encType(%u), frameLen(%d)", encOffset, encType, frameLen);
- if (pExtContent[tmp] == 0x00 || pExtContent[tmp] == 0xFF || pExtContent[tmp] == 0xFE) {
- textEncodingType = __id3tag_get_text_encoding_v223(pExtContent, &realCpyFrameNum, textEncodingType, &tmp);
+ if (encType == AV_ID3V2_ISO_8859) {
+ if (lang_info != NULL && !g_ascii_strcasecmp(lang_info, "KOR")) {
+ char_set = strdup("EUC-KR");
+ } else {
+ char_set = mmfile_get_charset((const char *)&buffer[curPos]);
+ }
+ mmfile_free(lang_info);
+ }
- char *char_set = NULL;
+ curPos += encOffset;
- debug_msg(RELEASE, "tmp(%d) textEncodingType(%d), realCpyFrameNum(%d)\n", tmp, textEncodingType, realCpyFrameNum);
+ if (!char_set) {
+ pInfo->tagInfo[tag_id].value = mmfile_convert_to_utf8((const char *)&buffer[curPos], frameLen, charset_array[encType]);
+ } else {
+ pInfo->tagInfo[tag_id].value = mmfile_convert_to_utf8((const char *)&buffer[curPos], frameLen, char_set);
+ mmfile_free(char_set);
+ }
+ mmfile_free(lang_info);
+ break;
- if (textEncodingType == AV_ID3V2_ISO_8859) {
- if (lang_info != NULL && !g_ascii_strcasecmp(lang_info, "KOR")) {
- char_set = strdup("EUC-KR");
- } else {
- char_set = mmfile_get_charset((const char *)&pExtContent[tmp]);
- }
- mmfile_free(lang_info);
- }
+ case AV_ID3TAG_PICTURE:
+ if (extract_artwork)
+ _mm_file_id3tag_parse_APIC(pInfo, &buffer[curPos], frameLen, charset_array[encType]);
+ break;
- if (char_set == NULL) {
- pInfo->tagInfo[tag_id].value = mmfile_string_convert((const char *)&pExtContent[tmp], realCpyFrameNum, "UTF-8", charset_array[textEncodingType], NULL, (unsigned int *)&pInfo->tagInfo[tag_id].length);
- } else {
- pInfo->tagInfo[tag_id].value = mmfile_string_convert((const char *)&pExtContent[tmp], realCpyFrameNum, "UTF-8", char_set, NULL, (unsigned int *)&pInfo->tagInfo[tag_id].length);
- mmfile_free(char_set);
- }
- pInfo->tagInfo[tag_id].marked= true;
- } else {
- debug_msg(RELEASE, "failed to get Unsynchronised lyrics Info tmp(%d), purelyFramelen - encodingOffSet(%lu)\n", tmp, purelyFramelen - encodingOffSet);
- }
- } else {
- debug_msg(RELEASE, "Unsynchronised lyrics too small to parse realCpyFrameNum(%d)\n", realCpyFrameNum);
- }
- mmfile_free(lang_info);
- break;
-
- case AV_ID3TAG_PICTURE:
- if ((realCpyFrameNum <= 2000000) && _mm_file_id3tag_parse_APIC(pInfo, (unsigned char *)pExtContent, realCpyFrameNum, charset_array[textEncodingType]))
- pInfo->tagInfo[tag_id].marked= true;
- break;
-
- default:
- pInfo->tagInfo[tag_id].value = mmfile_string_convert((const char *)pExtContent, realCpyFrameNum, "UTF-8", charset_array[textEncodingType], NULL, (unsigned int *)&pInfo->tagInfo[tag_id].length);
- pInfo->tagInfo[tag_id].marked= true;
- break;
- }
+ default:
+ pInfo->tagInfo[tag_id].value = mmfile_convert_to_utf8((const char *)&buffer[curPos], frameLen, charset_array[encType]);
+ break;
+ }
- if (pInfo->tagInfo[tag_id].value)
- debug_msg(RELEASE, "[%d] returned = (%s), len = (%d)\n", tag_id, pInfo->tagInfo[tag_id].value, pInfo->tagInfo[tag_id].length);
- }
+ if (pInfo->tagInfo[tag_id].value)
+ debug_msg(RELEASE, "[%d] returned = (%s)", tag_id, pInfo->tagInfo[tag_id].value);
+NEXT:
+ curPos += frameLen;
+ encOffset = 0;
+ encType = 0;
+ }
- } else {
- debug_msg(RELEASE, "All of the pExtContent Values are NULL\n");
- }
- }
+ release_characterset_array(charset_array);
- mmfile_free(pExtContent);
- memset(CompTmp, 0, 4);
+ return true;
+}
- if (curPos >= taglen)
- break;
+static void __get_v224_encoding_info(const unsigned char *buffer,
+ int length,
+ int *offset,
+ unsigned int *type)
+{
+ int _offset = 0;
- needToloopv2taglen -= oneFrameLen;
+ if (!buffer || !offset || !type)
+ return;
- oneFrameLen = 0;
- encodingOffSet = 0;
- realCpyFrameNum = 0;
- textEncodingType = 0;
- purelyFramelen = 0;
+ /*in case of UTF 16 encoding */
+ /*buffer+(position-length) data should '0x01' but in order to expansion, we don't accurately check the value. */
+ if (IS_ENCODEDBY_UTF16(buffer)) {
+ *offset = 2;
+ *type = AV_ID3V2_UTF16;
+ return;
+ }
+ if (IS_ENCODEDBY_UTF16_R(buffer)) {
+ *offset = 2;
+ *type = AV_ID3V2_UTF16_BE;
+ return;
}
- release_characterset_array(charset_array);
+ if (IS_ENCODEDBY_UTF16(buffer + 1)) {
+ *offset = 3;
+ *type = AV_ID3V2_UTF16;
+ return;
+ }
+ if (IS_ENCODEDBY_UTF16_R(buffer + 1)) {
+ *offset = 3;
+ *type = AV_ID3V2_UTF16_BE;
+ return;
+ }
- if (taglen)
- return true;
- else
- return false;
+ /*in case of UTF-16 BE encoding */
+ if (buffer[0] == 0x02) {
+ _offset = 1;
+ while ((buffer[_offset] == '\0') && (_offset < length))
+ _offset++;/*null skip! */
+ *offset = _offset;
+ *type = AV_ID3V2_UTF16_BE;
+ return;
+ }
+ /*in case of UTF8 encoding */
+ if (buffer[0] == 0x03) {
+ _offset = 1;
+ while ((buffer[_offset] == '\0') && (_offset < length))
+ _offset++;/*null skip! */
+ *offset = _offset;
+ *type = AV_ID3V2_UTF8;
+ return;
+ }
+ /*in case of ISO-8859-1 encoding */
+ /*buffer+(position-length) data should 0x00 but in order to expansion, we don't accurately check the value. */
+ _offset = 1;
+ while ((buffer[_offset] < 0x20) && (_offset < length))
+ _offset++;/*less than 0x20 value skip! */
+ *offset = _offset;
+ *type = AV_ID3V2_ISO_8859;
}
-EXPORT_API
-bool mm_file_id3tag_parse_v224(AvFileContentInfo *pInfo, unsigned char *buffer)
+bool mm_file_id3tag_parse_v224(AvFileContentInfo *pInfo, unsigned char *buffer, bool extract_artwork)
{
- unsigned long taglen = 0;
- unsigned long needToloopv2taglen;
- unsigned long oneFrameLen = 0;
- unsigned long curPos = 0;
- char CompTmp[5];
- unsigned char *pExtContent = NULL;
- unsigned long purelyFramelen = 0;
- unsigned int encodingOffSet = 0;
- int realCpyFrameNum = 0, tmp = 0;
- unsigned int textEncodingType = 0;
+ int extendedHeaderLen = 0;
+ int frameLen = 0;
+ int curPos = MP3_TAGv2_HEADER_LEN;
+ int encOffset = 0;
+ unsigned int encType = 0;
char **charset_array = NULL;
AvID3TagList tag_id = AV_ID3TAG_MAX;
- make_characterset_array(&charset_array);
+ if (pInfo->tagV2Info.tagLen <= 0)
+ return false;
+ make_characterset_array(&charset_array);
init_content_info(pInfo);
- taglen = pInfo->tagV2Info.tagLen;
- needToloopv2taglen = taglen - MP3_TAGv2_HEADER_LEN;
- curPos = MP3_TAGv2_HEADER_LEN;
-
- debug_msg(RELEASE, "ID3tag v224--------------------------------------------------------------\n");
-
- /* check Extended Header */
+ debug_msg(RELEASE, "ID3tag v224--------------------------------------------------------------");
if (buffer[5] & 0x40) {
/* if extended header exists, skip it*/
- int extendedHeaderLen = (unsigned long)buffer[10] << 21 | (unsigned long)buffer[11] << 14 | (unsigned long)buffer[12] << 7 | (unsigned long)buffer[13];
-
- debug_msg(RELEASE, "--------------- extendedHeaderLen = %d\n", extendedHeaderLen);
-
- if (extendedHeaderLen > (int)(taglen - curPos)) {
- debug_error(DEBUG, "extended header too long.\n");
+ extendedHeaderLen = buffer[10] << 21 | buffer[11] << 14 | buffer[12] << 7 | buffer[13];
+ debug_msg(RELEASE, "--------------- extendedHeaderLen = %d", extendedHeaderLen);
+ if (extendedHeaderLen > pInfo->tagV2Info.tagLen - MP3_TAGv2_HEADER_LEN) {
+ debug_error(DEBUG, "extended header too long.");
} else {
curPos += extendedHeaderLen;
}
}
- while (needToloopv2taglen > MP3_TAGv2_23_TXT_HEADER_LEN) {
- if ((buffer[curPos] < '0' || buffer[curPos] > 'Z') || (buffer[curPos + 1] < '0' || buffer[curPos + 1] > 'Z')
- || (buffer[curPos + 2] < '0' || buffer[curPos + 2] > 'Z') || (buffer[curPos + 3] < '0' || buffer[curPos + 3] > 'Z'))
+ while (curPos + MP3_TAGv2_23_TXT_HEADER_LEN < pInfo->tagV2Info.tagLen) {
+ if (!g_ascii_isalnum(buffer[curPos]) || !g_ascii_isalnum(buffer[curPos + 1]) ||
+ !g_ascii_isalnum(buffer[curPos + 2]) || !g_ascii_isalnum(buffer[curPos + 3]))
break;
- memcpy(CompTmp, &buffer[curPos], 4);
-
- CompTmp[4] = 0;
- oneFrameLen = MP3_TAGv2_23_TXT_HEADER_LEN;
- oneFrameLen += (unsigned long)buffer[4 + curPos] << 21 | (unsigned long)buffer[5 + curPos] << 14
- | (unsigned long)buffer[6 + curPos] << 7 | (unsigned long)buffer[7 + curPos];
- if (oneFrameLen > taglen - curPos)
+ tag_id = __get_tag_info_v223(&buffer[curPos]);
+ frameLen = buffer[curPos + 4] << 21 | buffer[curPos + 5] << 14 | buffer[curPos + 6] << 7 | buffer[curPos + 7];
+ curPos += MP3_TAGv2_23_TXT_HEADER_LEN;
+ if (curPos + frameLen > pInfo->tagV2Info.tagLen)
break;
- purelyFramelen = oneFrameLen - MP3_TAGv2_23_TXT_HEADER_LEN;
- curPos += oneFrameLen;
-
- debug_msg(RELEASE, "-----------------------------------------------------------------------------------\n");
-
- tag_id = __get_tag_info_v223(CompTmp);
- if (tag_id != AV_ID3TAG_MAX && !pInfo->tagInfo[tag_id].marked && purelyFramelen > 0) {
- /*in case of UTF 16 encoding */
- /*buffer+(curPos-purelyFramelen) data should '0x01' but in order to expansion, we don't accurately check the value. */
- if (IS_ENCODEDBY_UTF16(buffer + (curPos - purelyFramelen))) {
- encodingOffSet = 2;
- textEncodingType = AV_ID3V2_UTF16;
- } else if (IS_ENCODEDBY_UTF16_R(buffer + (curPos - purelyFramelen))) {
- encodingOffSet = 2;
- textEncodingType = AV_ID3V2_UTF16_BE;
- } else if (IS_ENCODEDBY_UTF16(buffer + (curPos - purelyFramelen + 1))) {
- encodingOffSet = 3;
- textEncodingType = AV_ID3V2_UTF16;
- } else if (IS_ENCODEDBY_UTF16_R(buffer + (curPos - purelyFramelen + 1))) {
- encodingOffSet = 3;
- textEncodingType = AV_ID3V2_UTF16_BE;
- } else {
- /*in case of UTF-16 BE encoding */
- if (buffer[curPos - purelyFramelen] == 0x02) {
- encodingOffSet = 1;
- while ((buffer[curPos - purelyFramelen + encodingOffSet] == '\0') && (encodingOffSet < purelyFramelen))
- encodingOffSet++;/*null skip! */
- textEncodingType = AV_ID3V2_UTF16_BE;
- }
- /*in case of UTF8 encoding */
- else if (buffer[curPos - purelyFramelen] == 0x03) {
- encodingOffSet = 1;
- while ((buffer[curPos - purelyFramelen + encodingOffSet] == '\0') && (encodingOffSet < purelyFramelen))
- encodingOffSet++;/*null skip! */
- textEncodingType = AV_ID3V2_UTF8;
- }
- /*in case of ISO-8859-1 encoding */
- else {
- /*buffer+(curPos-purelyFramelen) data should 0x00 but in order to expansion, we don't accurately check the value. */
- encodingOffSet = 1;
- while ((buffer[curPos - purelyFramelen + encodingOffSet] < 0x20) && (encodingOffSet < purelyFramelen))
- encodingOffSet++;/*less than 0x20 value skip! */
- textEncodingType = AV_ID3V2_ISO_8859;
- }
- }
-
- mmfile_free(pExtContent);
-
- if (encodingOffSet < purelyFramelen) {
- realCpyFrameNum = purelyFramelen - encodingOffSet;
- pExtContent = mmfile_malloc(realCpyFrameNum + 3);
-
- if (pExtContent == NULL) {
- debug_error(DEBUG, "out of memoryu for id3tag parse\n");
- continue;
- }
-
- memset(pExtContent, '\0', realCpyFrameNum + 3);
-
- if (textEncodingType != AV_ID3V2_UTF16 && textEncodingType != AV_ID3V2_UTF16_BE) {
- if (CompTmp[0] == 'T' || (strcmp(CompTmp, "APIC") == 0)) {
- debug_msg(RELEASE, "get the new text ecoding type\n");
- textEncodingType = buffer[curPos - purelyFramelen + encodingOffSet - 1];
- }
- }
-
- if (textEncodingType > AV_ID3V2_MAX) {
- debug_msg(DEBUG, "WRONG ENCOIDNG TYPE [%d], FRAME[%s]\n", textEncodingType, (char *)CompTmp);
- continue;
- }
-
- memcpy(pExtContent, &buffer[curPos - purelyFramelen + encodingOffSet], purelyFramelen - encodingOffSet);
-
- if (realCpyFrameNum > 0) {
- switch (tag_id) {
- case AV_ID3TAG_COMMENT:
- if (realCpyFrameNum > 3) {
- realCpyFrameNum -= 3;
- tmp = 3;
-
- textEncodingType = __id3tag_get_text_encoding_v224(pExtContent, &realCpyFrameNum, textEncodingType, &tmp);
- debug_msg(RELEASE, "tmp(%d) textEncodingType(%d), realCpyFrameNum(%d)\n", tmp, textEncodingType, realCpyFrameNum);
-
- pInfo->tagInfo[tag_id].value = mmfile_string_convert((const char *)&pExtContent[tmp], realCpyFrameNum, "UTF-8", charset_array[textEncodingType], NULL, (unsigned int *)&pInfo->tagInfo[tag_id].length);
- pInfo->tagInfo[tag_id].marked= true;
- } else {
- debug_msg(RELEASE, "Description info too small to parse realCpyFrameNum(%d)\n", realCpyFrameNum);
- }
- break;
-
- case AV_ID3TAG_SYNCLYRICS:
- if (realCpyFrameNum > 5) {
- realCpyFrameNum -= 5;
- tmp = 5;
-
- textEncodingType = __id3tag_get_text_encoding_v224(pExtContent, &realCpyFrameNum, textEncodingType, &tmp);
- debug_msg(RELEASE, "tmp(%d) textEncodingType(%d), realCpyFrameNum(%d)\n", tmp, textEncodingType, realCpyFrameNum);
-
- __id3tag_parse_SYLT(pInfo, pExtContent, realCpyFrameNum, charset_array[textEncodingType], textEncodingType, tmp);
- pInfo->tagInfo[tag_id].marked= true;
- } else {
- debug_msg(RELEASE, "SyncLyrics info too small to parse realCpyFrameNum(%d)\n", realCpyFrameNum);
- }
- break;
-
- case AV_ID3TAG_UNSYNCLYRICS:
- if (realCpyFrameNum > 3) {
- realCpyFrameNum -= 3;
- tmp = 3;
+ if (frameLen <= 0)
+ continue;
- textEncodingType = __id3tag_get_text_encoding_v224(pExtContent, &realCpyFrameNum, textEncodingType, &tmp);
- debug_msg(RELEASE, "tmp(%d) textEncodingType(%d), realCpyFrameNum(%d)\n", tmp, textEncodingType, realCpyFrameNum);
+ if (tag_id == AV_ID3TAG_MAX || pInfo->tagInfo[tag_id].value)
+ goto NEXT;
- pInfo->tagInfo[tag_id].value = mmfile_string_convert((const char *)&pExtContent[tmp], realCpyFrameNum, "UTF-8", charset_array[textEncodingType], NULL, (unsigned int *)&pInfo->tagInfo[tag_id].length);
- pInfo->tagInfo[tag_id].marked= true;
- } else {
- debug_msg(RELEASE, "Description info too small to parse realCpyFrameNum(%d)\n", realCpyFrameNum);
- }
- break;
+ __get_v224_encoding_info(buffer + curPos, frameLen, &encOffset, &encType);
+ if (frameLen <= encOffset) {
+ debug_warning(DEBUG, "warning: invalid frame length %d %d", frameLen, encOffset);
+ goto NEXT;
+ }
- case AV_ID3TAG_PICTURE:
- if ((realCpyFrameNum <= 2000000) && _mm_file_id3tag_parse_APIC(pInfo, (unsigned char *)pExtContent, realCpyFrameNum, charset_array[textEncodingType]))
- pInfo->tagInfo[tag_id].marked= true;
- break;
+ curPos += encOffset;
+ frameLen -= encOffset;
+ encOffset = 0;
- default:
- pInfo->tagInfo[tag_id].value = mmfile_string_convert((const char *)pExtContent, realCpyFrameNum, "UTF-8", charset_array[textEncodingType], NULL, (unsigned int *)&pInfo->tagInfo[tag_id].length);
- pInfo->tagInfo[tag_id].marked= true;
- break;
- }
+ if (encType != AV_ID3V2_UTF16 && encType != AV_ID3V2_UTF16_BE) {
+ if (tag_id != AV_ID3TAG_COMMENT && tag_id != AV_ID3TAG_UNSYNCLYRICS && tag_id != AV_ID3TAG_SYNCLYRICS) {
+ debug_msg(RELEASE, "get the new text encoding type");
+ encType = buffer[curPos - 1];
+ }
+ }
- if (pInfo->tagInfo[tag_id].value)
- debug_msg(RELEASE, "[%d] returned = (%s), len = (%d)\n", tag_id, pInfo->tagInfo[tag_id].value, pInfo->tagInfo[tag_id].length);
- }
+ if (encType > AV_ID3V2_MAX) {
+ debug_msg(DEBUG, "WRONG ENCOIDNG TYPE [%u], TAG ID[%d]", encType, tag_id);
+ goto NEXT;
+ }
- } else {
- debug_msg(RELEASE, "mmf_file_id3tag_parse_v224: All of the pExtContent Values are NULL\n");
+ switch (tag_id) {
+ case AV_ID3TAG_COMMENT:
+ /* fall through */
+ case AV_ID3TAG_UNSYNCLYRICS:
+ if (frameLen <= 3) {
+ debug_msg(RELEASE, "Description info too small to parse frameLen(%d)", frameLen);
+ break;
}
+ frameLen -= 3;
+ encOffset = 3;
- }
+ encType = __id3tag_get_text_encoding_v224(&buffer[curPos], &frameLen, encType, &encOffset);
+ debug_msg(RELEASE, "encOffset(%d) encType(%u), frameLen(%d)", encOffset, encType, frameLen);
+ curPos += encOffset;
+ pInfo->tagInfo[tag_id].value = mmfile_convert_to_utf8((const char *)&buffer[curPos], frameLen, charset_array[encType]);
+ break;
- mmfile_free(pExtContent);
- memset(CompTmp, 0, 4);
+ case AV_ID3TAG_SYNCLYRICS:
+ if (frameLen <= 5) {
+ debug_msg(RELEASE, "Synchronised lyrics too small to parse frameLen(%d)", frameLen);
+ break;
+ }
+ frameLen -= 5;
+ encOffset = 5;
- if (curPos >= taglen)
+ encType = __id3tag_get_text_encoding_v224(&buffer[curPos], &frameLen, encType, &encOffset);
+ debug_msg(RELEASE, "encOffset(%d) encType(%u), frameLen(%d)", encOffset, encType, frameLen);
+ curPos += encOffset;
+ __id3tag_parse_SYLT(pInfo, buffer, frameLen, charset_array[encType], encType, curPos);
break;
- needToloopv2taglen -= oneFrameLen;
+ case AV_ID3TAG_PICTURE:
+ if (extract_artwork)
+ _mm_file_id3tag_parse_APIC(pInfo, &buffer[curPos], frameLen, charset_array[encType]);
+ break;
- oneFrameLen = 0;
- encodingOffSet = 0;
- realCpyFrameNum = 0;
- textEncodingType = 0;
- purelyFramelen = 0;
+ default:
+ pInfo->tagInfo[tag_id].value = mmfile_convert_to_utf8((const char *)&buffer[curPos], frameLen, charset_array[encType]);
+ break;
+ }
+ if (pInfo->tagInfo[tag_id].value)
+ debug_msg(RELEASE, "[%d] returned = (%s)", tag_id, pInfo->tagInfo[tag_id].value);
+NEXT:
+ curPos += frameLen;
+ encOffset = 0;
+ encType = 0;
}
release_characterset_array(charset_array);
- if (taglen)
- return true;
- else
- return false;
-
+ return true;
}
-EXPORT_API
+
void mm_file_id3tag_restore_content_info(AvFileContentInfo *pInfo)
{
- char *mpegAudioGenre = NULL/*, *tmpGenreForV1Tag = NULL*/;
- bool bAdditionGenre = false /*, bMpegAudioFrame = false*/;
- int mpegAudioFileLen = 0, idv2IntGenre = GENRE_COUNT - 1/*, tmpinx = 0, tmpinx2=0*/;
+ int genre_id = 0;
/* for Genre Info */
- if (pInfo->tagInfo[AV_ID3TAG_GENRE].marked == false) {
- if (pInfo->bV1tagFound == true) {
- debug_msg(RELEASE, "Genre: %d\n", pInfo->genre);
-
- if (pInfo->genre > GENRE_COUNT - 1)
- pInfo->genre = GENRE_COUNT - 1;
-
- pInfo->tagInfo[AV_ID3TAG_GENRE].value = mmfile_strdup(MpegAudio_Genre[pInfo->genre]);
- if (pInfo->tagInfo[AV_ID3TAG_GENRE].value)
- pInfo->tagInfo[AV_ID3TAG_GENRE].length = strlen(pInfo->tagInfo[AV_ID3TAG_GENRE].value);
- else
- debug_error(RELEASE, "Genre: memory allocation failed.\n");
- } else {
- debug_msg(RELEASE, "Genre was not Found.\n");
- }
- } else {
- debug_msg(RELEASE, "genre size is Zero Or not UTF16 code! genreLen[%d] genre[%s]\n", pInfo->tagInfo[AV_ID3TAG_GENRE].length, pInfo->tagInfo[AV_ID3TAG_GENRE].value);
-
- if (pInfo->tagInfo[AV_ID3TAG_GENRE].value)
- mpegAudioGenre = mmfile_strdup(pInfo->tagInfo[AV_ID3TAG_GENRE].value);
- else
- pInfo->tagInfo[AV_ID3TAG_GENRE].length = 0;
-
- mmfile_free(pInfo->tagInfo[AV_ID3TAG_GENRE].value);
-
- /*tmpinx = 0;*/
- if (!mpegAudioGenre)
+ if (pInfo->tagInfo[AV_ID3TAG_GENRE].value) {
+ /* Check integer */
+ if (!__get_genre_num(pInfo->tagInfo[AV_ID3TAG_GENRE].value, &genre_id)) {
+ debug_msg(RELEASE, "genre information is not integer [%s]", pInfo->tagInfo[AV_ID3TAG_GENRE].value);
return;
-
- /**
- *Genre number
- * (XXX) XXX is 0 - 148
- */
- pInfo->tagInfo[AV_ID3TAG_GENRE].length = strlen(mpegAudioGenre);
- if (pInfo->tagInfo[AV_ID3TAG_GENRE].length >= 3 &&
- mpegAudioGenre[0] == '(' && mpegAudioGenre[pInfo->tagInfo[AV_ID3TAG_GENRE].length - 1] == ')') {
- bAdditionGenre = true;
- for (mpegAudioFileLen = 1; mpegAudioFileLen <= pInfo->tagInfo[AV_ID3TAG_GENRE].length - 2; mpegAudioFileLen++) {
- if (mpegAudioGenre[mpegAudioFileLen] < '0' || mpegAudioGenre[mpegAudioFileLen] > '9') {
- bAdditionGenre = false;
- break;
- }
- }
}
- if (bAdditionGenre == true) {
- idv2IntGenre = atoi(mpegAudioGenre + 1);
-
- if (idv2IntGenre > GENRE_COUNT - 1 || idv2IntGenre < 0)
- idv2IntGenre = GENRE_COUNT - 1;
+ /* If integer, check genre code. */
+ /* If out of range, set UNKNOWN */
+ if (genre_id < 0 || genre_id >= GENRE_COUNT)
+ genre_id = GENRE_COUNT - 1;
- pInfo->tagInfo[AV_ID3TAG_GENRE].value = mmfile_strdup(MpegAudio_Genre[idv2IntGenre]);
- if (pInfo->tagInfo[AV_ID3TAG_GENRE].value)
- pInfo->tagInfo[AV_ID3TAG_GENRE].length = strlen(pInfo->tagInfo[AV_ID3TAG_GENRE].value);
- else
- debug_error(RELEASE, "Genre: memory allocation failed.\n");
+ debug_msg(RELEASE, "genre information is integer [%d]", genre_id);
- debug_msg(RELEASE, "pInfo->tagInfo[AV_ID3TAG_GENRE].value = %s\n", pInfo->tagInfo[AV_ID3TAG_GENRE].value);
- } else if (bAdditionGenre == false && pInfo->tagInfo[AV_ID3TAG_GENRE].length > 0) {
- /**
- * Genre string.
- */
+ g_free(pInfo->tagInfo[AV_ID3TAG_GENRE].value);
+ pInfo->tagInfo[AV_ID3TAG_GENRE].value = g_strdup(MpegAudio_Genre[genre_id]);
+ } else {
+ /* No genre in ID3V2.. So check V1 */
+ if (pInfo->bV1tagFound == true) {
+ debug_msg(RELEASE, "Genre: %d", pInfo->genre);
- /* Give space for NULL character. Hence added "+1" */
- pInfo->tagInfo[AV_ID3TAG_GENRE].value = mmfile_strdup(mpegAudioGenre);
- if (pInfo->tagInfo[AV_ID3TAG_GENRE].value)
- pInfo->tagInfo[AV_ID3TAG_GENRE].length = strlen(pInfo->tagInfo[AV_ID3TAG_GENRE].value);
- else
- debug_error(RELEASE, "Genre: memory allocation failed.\n");
+ /* If out of range, set UNKNOWN */
+ if (pInfo->genre > GENRE_COUNT - 1)
+ pInfo->genre = GENRE_COUNT - 1;
- debug_msg(RELEASE, "pInfo->tagInfo[AV_ID3TAG_GENRE].value = %s, pInfo->tagInfo[AV_ID3TAG_GENRE].length = %d\n", pInfo->tagInfo[AV_ID3TAG_GENRE].value, pInfo->tagInfo[AV_ID3TAG_GENRE].length);
+ pInfo->tagInfo[AV_ID3TAG_GENRE].value = g_strdup(MpegAudio_Genre[pInfo->genre]);
} else {
- debug_msg(RELEASE, "Failed to \"(...)\" value to genre = %s\n", pInfo->tagInfo[AV_ID3TAG_GENRE].value);
+ debug_msg(RELEASE, "Genre was not Found.");
}
- mmfile_free(mpegAudioGenre);
}
-
}
-void mm_file_free_synclyrics_list(GList *synclyrics_list)
+static void __free_synclyrics(gpointer data)
{
- int list_len = 0;
- int idx = 0;
- AvSynclyricsInfo *synclyrics_info = NULL;
+ AvSynclyricsInfo *info = (AvSynclyricsInfo *) data;
- if (synclyrics_list == NULL) {
+ if (!info)
return;
- }
- list_len = g_list_length(synclyrics_list);
- for (idx = 0; idx < list_len; idx++) {
- synclyrics_info = g_list_nth_data(synclyrics_list, idx);
+ mmfile_free(info->lyric_info);
+ mmfile_free(info);
+}
- if (synclyrics_info != NULL) {
- mmfile_free(synclyrics_info->lyric_info);
- mmfile_free(synclyrics_info);
- }
- }
- if (synclyrics_list != NULL) {
- g_list_free(synclyrics_list);
- synclyrics_list = NULL;
- }
+void mm_file_free_synclyrics_list(GList *synclyrics_list)
+{
+ if (!synclyrics_list)
+ return;
- return;
+ g_list_free_full(synclyrics_list, __free_synclyrics);
}
-