In mov demuxer, convert mac encoded strings to utf-8
Originally committed as revision 22365 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
parent
bf35412201
commit
08a186c648
@ -93,6 +93,43 @@ static int mov_metadata_trkn(MOVContext *c, ByteIOContext *pb, unsigned len)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const uint32_t mac_to_unicode[128] = {
|
||||
0x00C4,0x00C5,0x00C7,0x00C9,0x00D1,0x00D6,0x00DC,0x00E1,
|
||||
0x00E0,0x00E2,0x00E4,0x00E3,0x00E5,0x00E7,0x00E9,0x00E8,
|
||||
0x00EA,0x00EB,0x00ED,0x00EC,0x00EE,0x00EF,0x00F1,0x00F3,
|
||||
0x00F2,0x00F4,0x00F6,0x00F5,0x00FA,0x00F9,0x00FB,0x00FC,
|
||||
0x2020,0x00B0,0x00A2,0x00A3,0x00A7,0x2022,0x00B6,0x00DF,
|
||||
0x00AE,0x00A9,0x2122,0x00B4,0x00A8,0x2260,0x00C6,0x00D8,
|
||||
0x221E,0x00B1,0x2264,0x2265,0x00A5,0x00B5,0x2202,0x2211,
|
||||
0x220F,0x03C0,0x222B,0x00AA,0x00BA,0x03A9,0x00E6,0x00F8,
|
||||
0x00BF,0x00A1,0x00AC,0x221A,0x0192,0x2248,0x2206,0x00AB,
|
||||
0x00BB,0x2026,0x00A0,0x00C0,0x00C3,0x00D5,0x0152,0x0153,
|
||||
0x2013,0x2014,0x201C,0x201D,0x2018,0x2019,0x00F7,0x25CA,
|
||||
0x00FF,0x0178,0x2044,0x20AC,0x2039,0x203A,0xFB01,0xFB02,
|
||||
0x2021,0x00B7,0x201A,0x201E,0x2030,0x00C2,0x00CA,0x00C1,
|
||||
0x00CB,0x00C8,0x00CD,0x00CE,0x00CF,0x00CC,0x00D3,0x00D4,
|
||||
0xF8FF,0x00D2,0x00DA,0x00DB,0x00D9,0x0131,0x02C6,0x02DC,
|
||||
0x00AF,0x02D8,0x02D9,0x02DA,0x00B8,0x02DD,0x02DB,0x02C7,
|
||||
};
|
||||
|
||||
static int mov_read_mac_string(MOVContext *c, ByteIOContext *pb, int len,
|
||||
char *dst, int dstlen)
|
||||
{
|
||||
char *p = dst;
|
||||
char *end = dst+dstlen-1;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
uint8_t t, c = get_byte(pb);
|
||||
if (c < 0x80 && p < end)
|
||||
*p++ = c;
|
||||
else
|
||||
PUT_UTF8(mac_to_unicode[c-0x80], t, if (p < end) *p++ = t;);
|
||||
}
|
||||
*p = 0;
|
||||
return p - dst;
|
||||
}
|
||||
|
||||
static int mov_read_udta_string(MOVContext *c, ByteIOContext *pb, MOVAtom atom)
|
||||
{
|
||||
#ifdef MOV_EXPORT_ALL_METADATA
|
||||
@ -100,7 +137,8 @@ static int mov_read_udta_string(MOVContext *c, ByteIOContext *pb, MOVAtom atom)
|
||||
#endif
|
||||
char str[1024], key2[16], language[4] = {0};
|
||||
const char *key = NULL;
|
||||
uint16_t str_size;
|
||||
uint16_t str_size, langcode = 0;
|
||||
uint32_t data_type = 0;
|
||||
int (*parse)(MOVContext*, ByteIOContext*, unsigned) = NULL;
|
||||
|
||||
switch (atom.type) {
|
||||
@ -130,14 +168,15 @@ static int mov_read_udta_string(MOVContext *c, ByteIOContext *pb, MOVAtom atom)
|
||||
int data_size = get_be32(pb);
|
||||
int tag = get_le32(pb);
|
||||
if (tag == MKTAG('d','a','t','a')) {
|
||||
get_be32(pb); // type
|
||||
data_type = get_be32(pb); // type
|
||||
get_be32(pb); // unknown
|
||||
str_size = data_size - 16;
|
||||
atom.size -= 16;
|
||||
} else return 0;
|
||||
} else if (atom.size > 4 && key && !c->itunes_metadata) {
|
||||
str_size = get_be16(pb); // string length
|
||||
ff_mov_lang_to_iso639(get_be16(pb), language);
|
||||
langcode = get_be16(pb);
|
||||
ff_mov_lang_to_iso639(langcode, language);
|
||||
atom.size -= 4;
|
||||
} else
|
||||
str_size = atom.size;
|
||||
@ -159,8 +198,12 @@ static int mov_read_udta_string(MOVContext *c, ByteIOContext *pb, MOVAtom atom)
|
||||
if (parse)
|
||||
parse(c, pb, str_size);
|
||||
else {
|
||||
get_buffer(pb, str, str_size);
|
||||
str[str_size] = 0;
|
||||
if (data_type == 3 || (data_type == 0 && langcode < 0x800)) { // MAC Encoded
|
||||
mov_read_mac_string(c, pb, str_size, str, sizeof(str));
|
||||
} else {
|
||||
get_buffer(pb, str, str_size);
|
||||
str[str_size] = 0;
|
||||
}
|
||||
av_metadata_set(&c->fc->metadata, key, str);
|
||||
if (*language && strcmp(language, "und")) {
|
||||
snprintf(key2, sizeof(key2), "%s-%s", key, language);
|
||||
@ -911,8 +954,7 @@ static int mov_read_stsd(MOVContext *c, ByteIOContext *pb, MOVAtom atom)
|
||||
(format >> 24) & 0xff, st->codec->codec_type);
|
||||
|
||||
if(st->codec->codec_type==CODEC_TYPE_VIDEO) {
|
||||
uint8_t codec_name[32];
|
||||
unsigned int color_depth;
|
||||
unsigned int color_depth, len;
|
||||
int color_greyscale;
|
||||
|
||||
st->codec->codec_id = id;
|
||||
@ -930,19 +972,15 @@ static int mov_read_stsd(MOVContext *c, ByteIOContext *pb, MOVAtom atom)
|
||||
get_be32(pb); /* data size, always 0 */
|
||||
get_be16(pb); /* frames per samples */
|
||||
|
||||
get_buffer(pb, codec_name, 32); /* codec name, pascal string */
|
||||
if (codec_name[0] <= 31) {
|
||||
int i;
|
||||
int pos = 0;
|
||||
for (i = 0; i < codec_name[0] && pos < sizeof(st->codec->codec_name) - 3; i++) {
|
||||
uint8_t tmp;
|
||||
PUT_UTF8(codec_name[i+1], tmp, st->codec->codec_name[pos++] = tmp;)
|
||||
}
|
||||
st->codec->codec_name[pos] = 0;
|
||||
/* codec_tag YV12 triggers an UV swap in rawdec.c */
|
||||
if (!memcmp(st->codec->codec_name, "Planar Y'CbCr 8-bit 4:2:0", 25))
|
||||
st->codec->codec_tag=MKTAG('I', '4', '2', '0');
|
||||
}
|
||||
len = get_byte(pb); /* codec name, pascal string */
|
||||
if (len > 31)
|
||||
len = 31;
|
||||
mov_read_mac_string(c, pb, len, st->codec->codec_name, 32);
|
||||
if (len < 31)
|
||||
url_fskip(pb, 31 - len);
|
||||
/* codec_tag YV12 triggers an UV swap in rawdec.c */
|
||||
if (!memcmp(st->codec->codec_name, "Planar Y'CbCr 8-bit 4:2:0", 25))
|
||||
st->codec->codec_tag=MKTAG('I', '4', '2', '0');
|
||||
|
||||
st->codec->bits_per_coded_sample = get_be16(pb); /* depth */
|
||||
st->codec->color_table_id = get_be16(pb); /* colortable id */
|
||||
|
Loading…
Reference in New Issue
Block a user