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

Reimar Döffinger Reimar.Doeffinger
Wed May 28 21:55:30 CEST 2008


On Wed, May 28, 2008 at 02:10:24AM +0200, elupus wrote:
> +/**
> + * \brief looks for the string RTjjjjjjjjjj in the stream too resync reading
> + * \return TRUE if the syncword is found.
> + */
> +static int nuv_resync(AVFormatContext *s, int64_t pos_limit) {
> +    ByteIOContext *pb = s->pb;
> +    int i;
> +    char c;
> +
> +    c = get_byte(pb);
> +    while(!url_feof(pb) && url_ftell(pb) < pos_limit) {
> +        if(c != 'R') {
> +            c = get_byte(pb);
> +            continue;
> +        }
> +        c = get_byte(pb);
> +        if(c != 'T')
> +            continue;
> +
> +        for(i=0;i<10;i++) {
> +            c = get_byte(pb);
> +            if(c != 'j')
> +                break;
> +        }
> +        if(i==10)
> +            return 1;

Just a quick comment: IMO you really should use the "standard" way to
search for a pattern:
use a uint32_t and shift in each character and compare against MKTAG(...).
On match, for comparing the remaining 'j' you can then each time read in
and compare a full 4 bytes, so no need for an extra loop.

Greetings,
Reimar D?ffinger




More information about the ffmpeg-devel mailing list