Revision 0c468f56 libavformat/mov.c

View differences:

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

  
2290 2289
    for (i = 0; i < s->nb_streams; i++)
2291 2290
        if (s->streams[i]->id == mov->chapter_track) {
......
2304 2303
    for (i = 0; i < st->nb_index_entries; i++) {
2305 2304
        AVIndexEntry *sample = &st->index_entries[i];
2306 2305
        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;
2307 2309

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

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

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

  
2321 2320
        // The samples could theoretically be in any encoding if there's an encd
2322 2321
        // atom following, but in practice are only utf-8 or utf-16, distinguished
2323 2322
        // instead by the presence of a BOM
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;
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));
2337 2328
        }
2338 2329

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

  

Also available in: Unified diff