On 02/05/2012 11:20 AM, Aneesh Dogra wrote:

> 
> Signed-off-by: Aneesh Dogra <lionane...@gmail.com>
> ---
>  libavcodec/bytestream.h |   89 
> +++++++++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 89 insertions(+), 0 deletions(-)
> @@ -158,6 +200,36 @@ static av_always_inline int 
> bytestream2_seek(GetByteContext *g, int offset,
>      return bytestream2_tell(g);
>  }
>  
> +static av_always_inline int bytestream2_seek_p(PutByteContext *p, int offset,
> +                                               int whence)
> +{
> +    p->eof = 0;
> +    switch (whence) {
> +    case SEEK_CUR:
> +        if (p->buffer_end - p->buffer < offset)
> +            p->eof = 1;
> +        offset = av_clip(offset, -(p->buffer - p->buffer_start),
> +                         p->buffer_end - p->buffer);
> +        p->buffer += offset;
> +        break;
> +    case SEEK_END:
> +        if (p->buffer_end - p->buffer_start < -offset)
> +            p->eof = 1;


We don't need to set the eof flag if the seek is before the beginning,
only if it's after the end. So just check if offset > 0.

> @@ -168,6 +240,23 @@ static av_always_inline unsigned int 
> bytestream2_get_buffer(GetByteContext *g,
>      return size2;
>  }
>  
> +static av_always_inline void bytestream2_put_buffer(PutByteContext *p, const 
> uint8_t *src, unsigned int size)
> +{
> +    int size2;
> +    if (p->eof)
> +        return;
> +    size2 = FFMIN(p->buffer_end - p->buffer, size);
> +    if (size2 != size)
> +        p->eof = 1;
> +    memcpy(p->buffer, src, size2);
> +    p->buffer += size2;
> +}


It might be useful for this to return the actual number of bytes written.

-Justin
_______________________________________________
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to