[Ffmpeg-devel] Re: [PATCH] seeking in GXF
Michael Niedermayer
michaelni
Mon Jul 31 19:33:03 CEST 2006
Hi
On Mon, Jul 31, 2006 at 05:44:47PM +0200, Reimar D?ffinger wrote:
[...]
> +static void gxf_material_tags(ByteIOContext *pb, int *len, st_info_t *si) {
> + while (*len >= 2) {
> + mat_tag_t tag = get_byte(pb);
> + int tlen = get_byte(pb);
> + *len -= 2;
> + if (tlen > *len)
> + return;
> + *len -= tlen;
> + switch (tag) {
> + case MAT_FIRST_FIELD:
> + if (tlen != 4)
> + break;
> + si->first_field = get_be32(pb);
> + tlen = 0;
> + break;
> + case MAT_LAST_FIELD:
> + if (tlen != 4)
> + break;
> + si->last_field = get_be32(pb);
> + tlen = 0;
> + break;
> + }
> + url_fskip(pb, tlen);
> + }
> +}
somehow i think this is more complex then really needed ...
> +
> +/**
> + * \brief convert fps tag value to AVRational fps
> + * \param fps fps value from tag
> + * \return fps as AVRational, or 0 / 0 if unknown
> + */
> +static AVRational fps_tag2avr(int32_t fps) {
> + static const AVRational map[] = {{0, 0}, {60, 1}, {60000, 1001}, {50, 1},
> + {30, 1}, {30000, 1001}, {25, 1}, {24, 1}, {24000, 1001}};
ff_frame_rate_tab[] in mpeg12data.h
> + if (fps < 0 || fps > 8) fps = 0;
> + return map[fps];
> +}
> +
> +/**
> + * \brief convert UMF attributes flags to AVRational fps
> + * \param fps fps value from flags
> + * \return fps as AVRational, or 0 / 0 if unknown
> + */
> +static AVRational fps_umf2avr(uint32_t flags) {
> + static const AVRational map[] = {{50, 1}, {60000, 1001}, {24, 1},
> + {25, 1}, {30000, 1001}};
> + int idx = ff_log2_tab[(flags & 0x7c0) >> 6];
why dont you use av_log2() ?
[...]
> +
> +/**
> + * \brief read index from FLT packet into stream 0 av_index
> + */
> +static void gxf_read_index(AVFormatContext *s, int pkt_len) {
> + ByteIOContext *pb = &s->pb;
> + AVStream *st = s->streams[0];
> + uint32_t fields_per_map = get_le32(pb);
> + uint32_t map_cnt = get_le32(pb);
> + int i;
> + pkt_len -= 8;
> + if (map_cnt > 1000) {
> + av_log(s, AV_LOG_ERROR, "GXF: too many index entries %u (%x)\n", map_cnt, map_cnt);
> + map_cnt = 1000;
> + }
> + if (pkt_len < 4 * map_cnt) {
> + av_log(s, AV_LOG_ERROR, "GXF: invalid index length\n");
> + url_fskip(pb, pkt_len);
> + return;
> + }
> + pkt_len -= 4 * map_cnt;
> + av_add_index_entry(st, 0, 0, 0, 0, 0);
> + for (i = 0; i < map_cnt; i++)
> + av_add_index_entry(st, get_le32(pb) * 1024, i * fields_per_map + 1, 0, 0, 0);
the multiplications are int and will overflow
[...]
> +static int gxf_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags) {
> + uint64_t pos;
> + uint64_t maxlen = 100 * 1024 * 1024;
> + AVStream *st = s->streams[0];
> + int64_t start_time = s->streams[stream_index]->start_time;
> + int idx;
> + if (timestamp < start_time) timestamp = start_time;
> + idx = av_index_search_timestamp(st, timestamp - start_time,
> + AVSEEK_FLAG_ANY | AVSEEK_FLAG_BACKWARD);
> + if (idx < 0)
> + return -1;
> + pos = st->index_entries[idx].pos;
> + if (idx < st->nb_index_entries - 2)
> + maxlen = st->index_entries[idx + 2].pos - pos;
> + if (maxlen < 200 * 1024) maxlen = 200 * 1024;
FFMAX()
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
In the past you could go to a library and read, borrow or copy any book
Today you'd get arrested for mere telling someone where the library is
More information about the ffmpeg-devel
mailing list