[FFmpeg-devel] [PATCH] Add ff_h263_find_resync_marker() function (take 2)

Michael Niedermayer michaelni
Tue Feb 24 16:30:32 CET 2009


On Tue, Feb 24, 2009 at 03:53:26PM +0100, Gwenole Beauchesne wrote:
> On Tue, 24 Feb 2009, Michael Niedermayer wrote:
>
>> On Tue, Feb 24, 2009 at 06:30:53AM +0100, Gwenole Beauchesne wrote:
>>> Le 23 f?vr. 09 ? 23:14, Michael Niedermayer a ?crit :
>>>
>>>>>> either way duplicating the resync code is not ok
>>>>>
>>>>> I had hoped you'd have an idea how to factorize it. ;-)
>>>>
>>>> The first thing i see is that ff_h263_resync() is not designed
>>>> to skip slices, its not fast at that, rather its designed to skip a
>>>> few
>>>> bytes after a slice has been decoded.
>>>
>>> Would that be OK to traverse the slice at a byte level as the
>>
>> yes
>
> Attached. Rationale: resync_marker is byte-aligned, and something non-zero 
> following the 16-bit 0 value obviously does contain the '1' bit terminator.

> diff --git a/libavcodec/h263.c b/libavcodec/h263.c
> index b02b0ad..9e43dcc 100644
> --- a/libavcodec/h263.c
> +++ b/libavcodec/h263.c
> @@ -3293,6 +3293,26 @@ void ff_mpeg4_clean_buffers(MpegEncContext *s)
>  }
>  
>  /**
> + * finds the next resync_marker
> + * @param p pointer to buffer to scan
> + * @param end pointer to the end of the buffer
> + * @return pointer to the next resync_marker, or \p end if none was found
> + */
> +const uint8_t *ff_h263_find_resync_marker(const uint8_t *restrict p, const uint8_t * restrict end)
> +{
> +    uint16_t m = 0xffff;
> +
> +    assert(p < end);

> +    if (p + 2 < end) {

the if() is useless, the for checks this already


> +        for (p += 2; p < end; p++) {
> +            if ((m = (m << 8) | p[0]) == 0 && p + 1 < end && p[1])
> +                return p - 1;
> +        }

your code does more than twice as much as needed
try something like:

end-=2;
p++;
for(;p<end; p+=2){
    if(!*p){
        if     (!p[-1] && p[1]) return p - 1
        else if(!p[ 1] && p[2]) return p;
    }
}


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

There will always be a question for which you do not know the correct awnser.
-------------- 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/20090224/1ae185fe/attachment.pgp>



More information about the ffmpeg-devel mailing list