Message ID | 20200224123739.31154-2-anton@khirnov.net |
---|---|
State | New |
Headers | show |
Series | [FFmpeg-devel,01/12] fifo: uninline av_fifo_peek2() on the next major bump | expand |
Context | Check | Description |
---|---|---|
andriy/ffmpeg-patchwork | success | Make fate finished |
On 2/24/2020 9:37 AM, Anton Khirnov wrote: > Inline public functions should be avoided unless absolutely necessary, > and no such necessity exists in this code. > --- > libavutil/fifo.c | 13 +++++++++++++ > libavutil/fifo.h | 5 +++++ > 2 files changed, 18 insertions(+) > > diff --git a/libavutil/fifo.c b/libavutil/fifo.c > index 1060aedf13..0baaadc521 100644 > --- a/libavutil/fifo.c > +++ b/libavutil/fifo.c > @@ -23,6 +23,7 @@ > #include "avassert.h" > #include "common.h" > #include "fifo.h" > +#include "version.h" > > static AVFifoBuffer *fifo_alloc_common(void *buffer, size_t size) > { > @@ -238,3 +239,15 @@ void av_fifo_drain(AVFifoBuffer *f, int size) > f->rptr -= f->end - f->buffer; > f->rndx += size; > } > + > +#if LIBAVUTIL_VERSION_MAJOR >= 57 > +uint8_t *av_fifo_peek2(const AVFifoBuffer *f, int offs); > +{ > + uint8_t *ptr = f->rptr + offs; > + if (ptr >= f->end) > + ptr = f->buffer + (ptr - f->end); > + else if (ptr < f->buffer) > + ptr = f->end - (f->buffer - ptr); > + return ptr; > +} > +#endif > diff --git a/libavutil/fifo.h b/libavutil/fifo.h > index dc7bc6f0dd..8cd964ef45 100644 > --- a/libavutil/fifo.h > +++ b/libavutil/fifo.h > @@ -27,6 +27,7 @@ > #include <stdint.h> > #include "avutil.h" > #include "attributes.h" > +#include "version.h" > > typedef struct AVFifoBuffer { > uint8_t *buffer; > @@ -166,6 +167,7 @@ void av_fifo_drain(AVFifoBuffer *f, int size); > * point outside to the buffer data. > * The used buffer size can be checked with av_fifo_size(). > */ > +#if LIBAVUTIL_VERSION_MAJOR < 57 > static inline uint8_t *av_fifo_peek2(const AVFifoBuffer *f, int offs) > { > uint8_t *ptr = f->rptr + offs; > @@ -175,5 +177,8 @@ static inline uint8_t *av_fifo_peek2(const AVFifoBuffer *f, int offs) > ptr = f->end - (f->buffer - ptr); > return ptr; > } > +#else > +uint8_t *av_fifo_peek2(const AVFifoBuffer *f, int offs); > +#endif This patch will need a following one after the bump to remove dead code, so IMO might as well just do this in one commit after the bump and save all the ifdeffery. > > #endif /* AVUTIL_FIFO_H */ >
Quoting James Almer (2020-02-25 22:28:57) > On 2/24/2020 9:37 AM, Anton Khirnov wrote: > > This patch will need a following one after the bump to remove dead code, > so IMO might as well just do this in one commit after the bump and save > all the ifdeffery. Sure, that makes sense.
diff --git a/libavutil/fifo.c b/libavutil/fifo.c index 1060aedf13..0baaadc521 100644 --- a/libavutil/fifo.c +++ b/libavutil/fifo.c @@ -23,6 +23,7 @@ #include "avassert.h" #include "common.h" #include "fifo.h" +#include "version.h" static AVFifoBuffer *fifo_alloc_common(void *buffer, size_t size) { @@ -238,3 +239,15 @@ void av_fifo_drain(AVFifoBuffer *f, int size) f->rptr -= f->end - f->buffer; f->rndx += size; } + +#if LIBAVUTIL_VERSION_MAJOR >= 57 +uint8_t *av_fifo_peek2(const AVFifoBuffer *f, int offs); +{ + uint8_t *ptr = f->rptr + offs; + if (ptr >= f->end) + ptr = f->buffer + (ptr - f->end); + else if (ptr < f->buffer) + ptr = f->end - (f->buffer - ptr); + return ptr; +} +#endif diff --git a/libavutil/fifo.h b/libavutil/fifo.h index dc7bc6f0dd..8cd964ef45 100644 --- a/libavutil/fifo.h +++ b/libavutil/fifo.h @@ -27,6 +27,7 @@ #include <stdint.h> #include "avutil.h" #include "attributes.h" +#include "version.h" typedef struct AVFifoBuffer { uint8_t *buffer; @@ -166,6 +167,7 @@ void av_fifo_drain(AVFifoBuffer *f, int size); * point outside to the buffer data. * The used buffer size can be checked with av_fifo_size(). */ +#if LIBAVUTIL_VERSION_MAJOR < 57 static inline uint8_t *av_fifo_peek2(const AVFifoBuffer *f, int offs) { uint8_t *ptr = f->rptr + offs; @@ -175,5 +177,8 @@ static inline uint8_t *av_fifo_peek2(const AVFifoBuffer *f, int offs) ptr = f->end - (f->buffer - ptr); return ptr; } +#else +uint8_t *av_fifo_peek2(const AVFifoBuffer *f, int offs); +#endif #endif /* AVUTIL_FIFO_H */