[FFmpeg-devel] [PATCH] Seeking and resync support in nuv demuxer

Michael Niedermayer michaelni
Sat May 24 21:53:35 CEST 2008


On Sat, May 24, 2008 at 01:28:42PM +0200, elupus wrote:

[...]
> Index: nuv.c
> ===================================================================
> --- nuv.c	(revision 12279)
> +++ nuv.c	(working copy)
> @@ -209,9 +209,14 @@
>                  ret = av_new_packet(pkt, copyhdrsize + size);
>                  if (ret < 0)
>                      return ret;
> -                pkt->pos = url_ftell(pb) - copyhdrsize;
> +                pkt->pos = url_ftell(pb) - HDRSIZE;
>                  pkt->pts = AV_RL32(&hdr[4]);
>                  pkt->stream_index = ctx->v_id;
> +                if(hdr[2] == 0) {
> +                  AVStream *st = s->streams[pkt->stream_index];
> +                  pkt->flags |= PKT_FLAG_KEY;
> +                  av_add_index_entry(st, pkt->pos, pkt->pts, size + HDRSIZE, 0, AVINDEX_KEYFRAME);
> +                }
>                  memcpy(pkt->data, hdr, copyhdrsize);
>                  ret = get_buffer(pb, pkt->data + copyhdrsize, size);
>                  return ret;

The change to pkt->pos should also be in a seperate patch :)
besides the indention i already mentioned ...


[...]
> +/**
> + * \brief attempts to read a timestamp from stream at the given stream position
> + * \return timestamp if successfull and AV_NOPTS_VALUE if failure
> + */
> +static int64_t nuv_read_dts(AVFormatContext *s, int stream_index,
> +                               int64_t *ppos, int64_t pos_limit)
> +{
> +    NUVContext *ctx = s->priv_data;
> +    ByteIOContext *pb = s->pb;
> +    uint8_t hdr[HDRSIZE];
> +    frametype_t frametype;
> +    int size, ret;
> +    int64_t pos, dts;
> +
> +    ret = url_fseek(pb, *ppos, SEEK_SET);
> +    if (ret < 0)
> +        return AV_NOPTS_VALUE;
> +
> +    if (!nuv_valid_position(s, *ppos) && !nuv_resync(s, pos_limit))
> +        return AV_NOPTS_VALUE;
> +
> +    while (!url_feof(pb) && url_ftell(pb) < pos_limit) {
> +        if (get_buffer(pb, hdr, HDRSIZE) <= 0)
> +            return AV_NOPTS_VALUE;
> +        frametype = hdr[0];
> +        size = PKTSIZE(AV_RL32(&hdr[8]));
> +        switch (frametype) {
> +            case NUV_AUDIO:
> +            case NUV_VIDEO:
> +                pos = url_ftell(s->pb) - HDRSIZE;
> +                dts = AV_RL32(&hdr[4]);
> +                // TODO - add general support in av_gen_search, so it adds positions after reading timestamps
> +                av_add_index_entry(s->streams[frametype == NUV_VIDEO ? ctx->v_id : ctx->a_id]
> +                                 , pos, dts, size + HDRSIZE, 0, hdr[2] == 0 ? AVINDEX_KEYFRAME : 0);
> +

> +                if ((frametype == NUV_VIDEO && stream_index == ctx->v_id) ||
> +                    (frametype == NUV_VIDEO && stream_index == ctx->a_id)) {

are both supposed to be VIDEO ?


> +                    *ppos = pos;
> +                    return dts;
> +                }

> +                url_fskip(pb, size);
> +                break;
> +            case NUV_SEEKP:
> +                break;
> +            default:
> +                url_fskip(pb, size);
> +                break;

duplicate


> +        }
> +    }

> +    return AV_NOPTS_VALUE;
> +
> +
> +}

are the empty lines intended?


[...
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

It is dangerous to be right in matters on which the established authorities
are wrong. -- Voltaire
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20080524/24f00400/attachment.pgp>



More information about the ffmpeg-devel mailing list