[FFmpeg-devel,2/3] lavf/aviobuf: make AVSEEK_SIZE usable from outside.

Submitted by Nicolas George on July 19, 2019, 12:23 p.m.

Details

Message ID 20190719122354.32460-2-george@nsup.org
State Accepted
Commit 6e1a2dc11236fb04acf35bde647872eb4f3ded9c
Headers show

Commit Message

Nicolas George July 19, 2019, 12:23 p.m.
Signed-off-by: Nicolas George <george@nsup.org>
---
 libavformat/aviobuf.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Michael Niedermayer July 19, 2019, 7:08 p.m.
On Fri, Jul 19, 2019 at 02:23:53PM +0200, Nicolas George wrote:
> Signed-off-by: Nicolas George <george@nsup.org>
> ---
>  libavformat/aviobuf.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
> index 6a5cd97b0a..750326f62d 100644
> --- a/libavformat/aviobuf.c
> +++ b/libavformat/aviobuf.c
> @@ -255,6 +255,9 @@ int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
>      if(!s)
>          return AVERROR(EINVAL);
>  
> +    if ((whence & AVSEEK_SIZE))

redundant ()

> +        return s->seek ? s->seek(s->opaque, offset, AVSEEK_SIZE) : AVERROR(ENOSYS);
> +

seems like a good idea

Thanks

[...]
Nicolas George July 19, 2019, 9:49 p.m.
Michael Niedermayer (12019-07-19):
> > +    if ((whence & AVSEEK_SIZE))
> redundant ()

I use it as a marker that it is not a mistake for &&. IIRC, gcc (with
some options) warns about "if (a & b)" but accepts "if ((a & b))", and
that is the preferred way. We already have a few instances in the code
base, not all of them mine.

Regards,
Hendrik Leppkes July 19, 2019, 10 p.m.
On Fri, Jul 19, 2019 at 11:49 PM Nicolas George <george@nsup.org> wrote:
>
> Michael Niedermayer (12019-07-19):
> > > +    if ((whence & AVSEEK_SIZE))
> > redundant ()
>
> I use it as a marker that it is not a mistake for &&. IIRC, gcc (with
> some options) warns about "if (a & b)" but accepts "if ((a & b))", and
> that is the preferred way. We already have a few instances in the code
> base, not all of them mine.
>

That seems like a particularly dumb compiler "feature". Checking
bitmasks for a set bit seems like a rather standard if condition.

- Hendril
Nicolas George July 19, 2019, 10:08 p.m.
Hendrik Leppkes (12019-07-20):
> That seems like a particularly dumb compiler "feature". Checking
> bitmasks for a set bit seems like a rather standard if condition.

Maybe, to each their own, but it saved me a few times, so personally I
like it, especially since the double-parentheses is an
obvious and unobtrusive way of silencing it.

(Personally I would prefer explicitly "!= 0", but that is not FFmpeg's
coding style.)

Regards,
Michael Niedermayer July 19, 2019, 10:59 p.m.
On Fri, Jul 19, 2019 at 11:49:04PM +0200, Nicolas George wrote:
> Michael Niedermayer (12019-07-19):
> > > +    if ((whence & AVSEEK_SIZE))
> > redundant ()
> 
> I use it as a marker that it is not a mistake for &&. IIRC, gcc (with
> some options) warns about "if (a & b)" but accepts "if ((a & b))", and
> that is the preferred way. We already have a few instances in the code
> base, not all of them mine.

ok, just mentioned it as i thought it was unintended.
If the () is intended, ignore my comment

thx

[...]

Patch hide | download patch | download mbox

diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index 6a5cd97b0a..750326f62d 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -255,6 +255,9 @@  int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
     if(!s)
         return AVERROR(EINVAL);
 
+    if ((whence & AVSEEK_SIZE))
+        return s->seek ? s->seek(s->opaque, offset, AVSEEK_SIZE) : AVERROR(ENOSYS);
+
     buffer_size = s->buf_end - s->buffer;
     // pos is the absolute position that the beginning of s->buffer corresponds to in the file
     pos = s->pos - (s->write_flag ? 0 : buffer_size);