Revision ab561df9 libavformat/mov.c

View differences:

libavformat/mov.c
151 151

  
152 152
/* map numeric codes from mdhd atom to ISO 639 */
153 153
/* cf. QTFileFormat.pdf p253, qtff.pdf p205 */
154
/* http://developer.apple.com/documentation/mac/Text/Text-368.html */
155
/* deprecated by putting the code as 3*5bit ascii */
154 156
static const char *mov_mdhd_language_map[] = { 
155 157
/* 0-9 */
156 158
"eng", "fra", "ger", "ita", "dut", "sve", "spa", "dan", "por", "nor", 
......
353 355
#define print_atom(a,b)
354 356
#endif
355 357

  
356
const char *ff_mov_lang_to_iso639(int code)
358
static int ff_mov_lang_to_iso639(int code, char *to)
357 359
{
360
    int i;
361
    /* is it the mangled iso code? */
362
    /* see http://www.geocities.com/xhelmboyx/quicktime/formats/mp4-layout.txt */
363
    if (code > 138) {
364
        for (i = 2; i >= 0; i--) {
365
            to[i] = 0x60 + (code & 0x1f);
366
            code >>= 5;
367
        }
368
        return 1;
369
    }
370
    /* old fashion apple lang code */
358 371
    if (code >= (sizeof(mov_mdhd_language_map)/sizeof(char *)))
359
        return NULL;
372
        return 0;
360 373
    if (!mov_mdhd_language_map[code])
361
        return NULL;
362
    return mov_mdhd_language_map[code];
374
        return 0;
375
    strncpy(to, mov_mdhd_language_map[code], 4);
376
    return 1;
363 377
}
364 378

  
365
extern int ff_mov_iso639_to_lang(const char *lang); /* for movenc.c */
366
int ff_mov_iso639_to_lang(const char *lang)
379
extern int ff_mov_iso639_to_lang(const char *lang, int mp4); /* for movenc.c */
380
int ff_mov_iso639_to_lang(const char *lang, int mp4)
367 381
{
368
    int i;
369
    for (i = 0; i < (sizeof(mov_mdhd_language_map)/sizeof(char *)); i++) {
382
    int i, code = 0;
383
    
384
    /* old way, only for QT? */
385
    for (i = 0; !mp4 && (i < (sizeof(mov_mdhd_language_map)/sizeof(char *))); i++) {
370 386
        if (mov_mdhd_language_map[i] && !strcmp(lang, mov_mdhd_language_map[i]))
371 387
            return i;
372 388
    }
373
    return -1;
389
    /* XXX:can we do that in mov too? */
390
    if (!mp4)
391
        return 0;
392
    /* handle undefined as such */
393
    if (lang[0] == '\0')
394
        lang = "und";
395
    /* 5bit ascii */
396
    for (i = 0; i < 3; i++) {
397
        unsigned char c = (unsigned char)lang[i];
398
        if (c < 0x60)
399
            return 0;
400
        if (c > 0x60 + 0x1f)
401
            return 0;
402
        code <<= 5;
403
        code |= (c - 0x60);
404
    }
405
    return code;
374 406
}
375 407

  
376 408
static int mov_read_leaf(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
......
675 707
{
676 708
    int version;
677 709
    int lang;
678
    const char *iso639;
679 710
    print_atom("mdhd", atom);
680 711

  
681 712
    version = get_byte(pb); /* version */
......
697 728
    c->fc->streams[c->fc->nb_streams-1]->duration = (version==1)?get_be64(pb):get_be32(pb); /* duration */
698 729

  
699 730
    lang = get_be16(pb); /* language */
700
    iso639 = ff_mov_lang_to_iso639(lang);
701
    if (iso639)
702
        strncpy(c->fc->streams[c->fc->nb_streams-1]->language, iso639, 4);
731
    ff_mov_lang_to_iso639(lang, c->fc->streams[c->fc->nb_streams-1]->language);
703 732
    get_be16(pb); /* quality */
704 733

  
705 734
    return 0;

Also available in: Unified diff