Revision bc1aebcd

View differences:

libavformat/mov.c
2284 2284
    AVStream *st = NULL;
2285 2285
    MOVStreamContext *sc;
2286 2286
    int64_t cur_pos;
2287
    int i;
2287
    uint8_t *title = NULL;
2288
    int i, len, i8, i16;
2288 2289

  
2289 2290
    for (i = 0; i < s->nb_streams; i++)
2290 2291
        if (s->streams[i]->id == mov->chapter_track) {
......
2303 2304
    for (i = 0; i < st->nb_index_entries; i++) {
2304 2305
        AVIndexEntry *sample = &st->index_entries[i];
2305 2306
        int64_t end = i+1 < st->nb_index_entries ? st->index_entries[i+1].timestamp : st->duration;
2306
        uint8_t title[512];
2307
        uint16_t ch;
2308
        int len;
2309 2307

  
2310 2308
        if (url_fseek(sc->pb, sample->pos, SEEK_SET) != sample->pos) {
2311 2309
            av_log(s, AV_LOG_ERROR, "Chapter %d not found in file\n", i);
2312 2310
            goto finish;
2313 2311
        }
2314 2312

  
2313
        title = av_malloc(sample->size+2);
2314
        get_buffer(sc->pb, title, sample->size);
2315

  
2315 2316
        // the first two bytes are the length of the title
2316
        len = get_be16(sc->pb);
2317
        len = AV_RB16(title);
2317 2318
        if (len > sample->size-2)
2318 2319
            continue;
2319 2320

  
2320 2321
        // The samples could theoretically be in any encoding if there's an encd
2321 2322
        // atom following, but in practice are only utf-8 or utf-16, distinguished
2322 2323
        // instead by the presence of a BOM
2323
        if ((ch = get_be16(sc->pb)) == 0xfeff)
2324
            avio_get_str16be(sc->pb, len, title, sizeof(title));
2325
        else {
2326
            AV_WB16(title, ch);
2327
            get_buffer(sc->pb, title + sizeof(ch), sizeof(title) - sizeof(ch));
2324
        if (AV_RB16(title+2) == 0xfeff) {
2325
            uint8_t *utf8 = av_malloc(2*len+3);
2326

  
2327
            i8 = i16 = 0;
2328
            while (i16 < len) {
2329
                uint32_t ch;
2330
                uint8_t tmp;
2331
                GET_UTF16(ch, i16 < len ? AV_RB16(title + (i16+=2)) : 0, break;)
2332
                PUT_UTF8(ch, tmp, if (i8 < 2*len) utf8[2+i8++] = tmp;)
2333
            }
2334
            utf8[2+i8] = 0;
2335
            av_freep(&title);
2336
            title = utf8;
2328 2337
        }
2329 2338

  
2330
        ff_new_chapter(s, i, st->time_base, sample->timestamp, end, title);
2339
        ff_new_chapter(s, i, st->time_base, sample->timestamp, end, title+2);
2340
        av_freep(&title);
2331 2341
    }
2332 2342
finish:
2343
    av_free(title);
2333 2344
    url_fseek(sc->pb, cur_pos, SEEK_SET);
2334 2345
}
2335 2346

  

Also available in: Unified diff