mirror of https://git.ffmpeg.org/ffmpeg.git
mov: simplify mov_read_chapters() by using avio_get_str16be
It probably also fixes a memleak or two.
Signed-off-by: Janne Grunau <janne-ffmpeg@jannau.net>
(cherry picked from commit c34461b35b
)
This commit is contained in:
parent
24519edf64
commit
0c468f5684
|
@ -2284,8 +2284,7 @@ static void mov_read_chapters(AVFormatContext *s)
|
||||||
AVStream *st = NULL;
|
AVStream *st = NULL;
|
||||||
MOVStreamContext *sc;
|
MOVStreamContext *sc;
|
||||||
int64_t cur_pos;
|
int64_t cur_pos;
|
||||||
uint8_t *title = NULL;
|
int i;
|
||||||
int i, len, i8, i16;
|
|
||||||
|
|
||||||
for (i = 0; i < s->nb_streams; i++)
|
for (i = 0; i < s->nb_streams; i++)
|
||||||
if (s->streams[i]->id == mov->chapter_track) {
|
if (s->streams[i]->id == mov->chapter_track) {
|
||||||
|
@ -2304,43 +2303,33 @@ static void mov_read_chapters(AVFormatContext *s)
|
||||||
for (i = 0; i < st->nb_index_entries; i++) {
|
for (i = 0; i < st->nb_index_entries; i++) {
|
||||||
AVIndexEntry *sample = &st->index_entries[i];
|
AVIndexEntry *sample = &st->index_entries[i];
|
||||||
int64_t end = i+1 < st->nb_index_entries ? st->index_entries[i+1].timestamp : st->duration;
|
int64_t end = i+1 < st->nb_index_entries ? st->index_entries[i+1].timestamp : st->duration;
|
||||||
|
uint8_t title[512];
|
||||||
|
uint16_t ch;
|
||||||
|
int len;
|
||||||
|
|
||||||
if (url_fseek(sc->pb, sample->pos, SEEK_SET) != sample->pos) {
|
if (url_fseek(sc->pb, sample->pos, SEEK_SET) != sample->pos) {
|
||||||
av_log(s, AV_LOG_ERROR, "Chapter %d not found in file\n", i);
|
av_log(s, AV_LOG_ERROR, "Chapter %d not found in file\n", i);
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
|
||||||
title = av_malloc(sample->size+2);
|
|
||||||
get_buffer(sc->pb, title, sample->size);
|
|
||||||
|
|
||||||
// the first two bytes are the length of the title
|
// the first two bytes are the length of the title
|
||||||
len = AV_RB16(title);
|
len = get_be16(sc->pb);
|
||||||
if (len > sample->size-2)
|
if (len > sample->size-2)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// The samples could theoretically be in any encoding if there's an encd
|
// The samples could theoretically be in any encoding if there's an encd
|
||||||
// atom following, but in practice are only utf-8 or utf-16, distinguished
|
// atom following, but in practice are only utf-8 or utf-16, distinguished
|
||||||
// instead by the presence of a BOM
|
// instead by the presence of a BOM
|
||||||
if (AV_RB16(title+2) == 0xfeff) {
|
if ((ch = get_be16(sc->pb)) == 0xfeff)
|
||||||
uint8_t *utf8 = av_malloc(2*len+3);
|
avio_get_str16be(sc->pb, len, title, sizeof(title));
|
||||||
|
else {
|
||||||
i8 = i16 = 0;
|
AV_WB16(title, ch);
|
||||||
while (i16 < len) {
|
get_buffer(sc->pb, title + sizeof(ch), sizeof(title) - sizeof(ch));
|
||||||
uint32_t ch;
|
|
||||||
uint8_t tmp;
|
|
||||||
GET_UTF16(ch, i16 < len ? AV_RB16(title + (i16+=2)) : 0, break;)
|
|
||||||
PUT_UTF8(ch, tmp, if (i8 < 2*len) utf8[2+i8++] = tmp;)
|
|
||||||
}
|
|
||||||
utf8[2+i8] = 0;
|
|
||||||
av_freep(&title);
|
|
||||||
title = utf8;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ff_new_chapter(s, i, st->time_base, sample->timestamp, end, title+2);
|
ff_new_chapter(s, i, st->time_base, sample->timestamp, end, title);
|
||||||
av_freep(&title);
|
|
||||||
}
|
}
|
||||||
finish:
|
finish:
|
||||||
av_free(title);
|
|
||||||
url_fseek(sc->pb, cur_pos, SEEK_SET);
|
url_fseek(sc->pb, cur_pos, SEEK_SET);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue