diff --git a/libavcodec/dfa.c b/libavcodec/dfa.c index ae184d7b5f6ebdec1b36704fba7fabd054ecffa1..1598f47c6c314a7dce0e2598cbd83560d30190de 100644 --- a/libavcodec/dfa.c +++ b/libavcodec/dfa.c @@ -24,7 +24,7 @@ #include "bytestream.h" #include "libavutil/imgutils.h" -#include "libavutil/lzo.h" // for av_memcpy_backptr +#include "libavutil/mem.h" typedef struct DfaContext { AVFrame pic; diff --git a/libavcodec/eatgv.c b/libavcodec/eatgv.c index 404238b6ef34ce9d37ceef463e270f5dfe810833..170eeb10d54cae8b4d01039df070159b71bdcb0a 100644 --- a/libavcodec/eatgv.c +++ b/libavcodec/eatgv.c @@ -31,8 +31,8 @@ #include "avcodec.h" #define BITSTREAM_READER_LE #include "get_bits.h" -#include "libavutil/lzo.h" #include "libavutil/imgutils.h" +#include "libavutil/mem.h" #define EA_PREAMBLE_SIZE 8 #define kVGT_TAG MKTAG('k', 'V', 'G', 'T') diff --git a/libavcodec/g723_1.c b/libavcodec/g723_1.c index 5c213da64cfac30fb28f1e2caf98c5a62adc34d5..342c63473dfab565593dfc0b4dbb616af2caa0b2 100644 --- a/libavcodec/g723_1.c +++ b/libavcodec/g723_1.c @@ -27,7 +27,7 @@ #define BITSTREAM_READER_LE #include "libavutil/audioconvert.h" -#include "libavutil/lzo.h" +#include "libavutil/mem.h" #include "libavutil/opt.h" #include "avcodec.h" #include "get_bits.h" diff --git a/libavcodec/lcldec.c b/libavcodec/lcldec.c index 6b101ae6d1b69c4c454012c1480753c486821a74..c80d0fe30e80acf90fc9d6df4a779126a8806df3 100644 --- a/libavcodec/lcldec.c +++ b/libavcodec/lcldec.c @@ -41,10 +41,10 @@ #include <stdio.h> #include <stdlib.h> +#include "libavutil/mem.h" #include "avcodec.h" #include "bytestream.h" #include "lcl.h" -#include "libavutil/lzo.h" #if CONFIG_ZLIB_DECODER #include <zlib.h> diff --git a/libavcodec/wmavoice.c b/libavcodec/wmavoice.c index 63caad2440cfc91aae70247b334f3c7f81d859d8..466d1ec495321cf798654f57352b233b6a652f66 100644 --- a/libavcodec/wmavoice.c +++ b/libavcodec/wmavoice.c @@ -29,6 +29,7 @@ #include <math.h> +#include "libavutil/mem.h" #include "dsputil.h" #include "avcodec.h" #include "get_bits.h" @@ -38,7 +39,6 @@ #include "acelp_vectors.h" #include "acelp_filters.h" #include "lsp.h" -#include "libavutil/lzo.h" #include "dct.h" #include "rdft.h" #include "sinewin.h" diff --git a/libavcodec/xan.c b/libavcodec/xan.c index 586320b55ef73445e2051cc34f430ba95339075c..e6bfc0da068bc604fba5f17d49c8d1c32f0bea2a 100644 --- a/libavcodec/xan.c +++ b/libavcodec/xan.c @@ -33,12 +33,11 @@ #include <string.h> #include "libavutil/intreadwrite.h" +#include "libavutil/mem.h" #include "avcodec.h" #include "bytestream.h" #define BITSTREAM_READER_LE #include "get_bits.h" -// for av_memcpy_backptr -#include "libavutil/lzo.h" #define RUNTIME_GAMMA 0 diff --git a/libavcodec/xxan.c b/libavcodec/xxan.c index b06d314d0f1363c26d5e2b28dc49b112d5476f9a..2a5a8ca6312e647af2446d167e4201aadc7e3f25 100644 --- a/libavcodec/xxan.c +++ b/libavcodec/xxan.c @@ -22,11 +22,10 @@ #include "avcodec.h" #include "libavutil/intreadwrite.h" +#include "libavutil/mem.h" #include "bytestream.h" #define BITSTREAM_READER_LE #include "get_bits.h" -// for av_memcpy_backptr -#include "libavutil/lzo.h" typedef struct XanContext { AVCodecContext *avctx; diff --git a/libavutil/lzo.c b/libavutil/lzo.c index c17d32f3625dc488d037073d6e28f03eec58040e..eff3cd2333cbfb990892da28b0a512f6390ce12d 100644 --- a/libavutil/lzo.c +++ b/libavutil/lzo.c @@ -100,8 +100,6 @@ static inline void copy(LZOContext *c, int cnt) c->out = dst + cnt; } -static inline void memcpy_backptr(uint8_t *dst, int back, int cnt); - /** * @brief Copies previously decoded bytes to current position. * @param back how many bytes back we start @@ -122,50 +120,10 @@ static inline void copy_backptr(LZOContext *c, int back, int cnt) cnt = FFMAX(c->out_end - dst, 0); c->error |= AV_LZO_OUTPUT_FULL; } - memcpy_backptr(dst, back, cnt); + av_memcpy_backptr(dst, back, cnt); c->out = dst + cnt; } -static inline void memcpy_backptr(uint8_t *dst, int back, int cnt) -{ - const uint8_t *src = &dst[-back]; - if (back == 1) { - memset(dst, *src, cnt); - } else { - if (cnt >= 4) { - AV_COPY16U(dst, src); - AV_COPY16U(dst + 2, src + 2); - src += 4; - dst += 4; - cnt -= 4; - } - if (cnt >= 8) { - AV_COPY16U(dst, src); - AV_COPY16U(dst + 2, src + 2); - AV_COPY16U(dst + 4, src + 4); - AV_COPY16U(dst + 6, src + 6); - src += 8; - dst += 8; - cnt -= 8; - } - if (cnt > 0) { - int blocklen = back; - while (cnt > blocklen) { - memcpy(dst, src, blocklen); - dst += blocklen; - cnt -= blocklen; - blocklen <<= 1; - } - memcpy(dst, src, cnt); - } - } -} - -void av_memcpy_backptr(uint8_t *dst, int back, int cnt) -{ - memcpy_backptr(dst, back, cnt); -} - int av_lzo1x_decode(void *out, int *outlen, const void *in, int *inlen) { int state = 0; diff --git a/libavutil/lzo.h b/libavutil/lzo.h index a84b9bd15db12dd154bce56e59815e2637d91d67..9d7e8f1dc10a6d57a63e038bebd133b3069ea18b 100644 --- a/libavutil/lzo.h +++ b/libavutil/lzo.h @@ -59,17 +59,6 @@ */ int av_lzo1x_decode(void *out, int *outlen, const void *in, int *inlen); -/** - * @brief deliberately overlapping memcpy implementation - * @param dst destination buffer - * @param back how many bytes back we start (the initial size of the overlapping window) - * @param cnt number of bytes to copy, must be >= 0 - * - * cnt > back is valid, this will copy the bytes we just copied, - * thus creating a repeating pattern with a period length of back. - */ -void av_memcpy_backptr(uint8_t *dst, int back, int cnt); - /** * @} */ diff --git a/libavutil/mem.c b/libavutil/mem.c index 16c1adb014f28657a3b91b1b2acacaa7f5e67b3f..feba3163b04fd89a3224c520ad9a6aaad51f2e28 100644 --- a/libavutil/mem.c +++ b/libavutil/mem.c @@ -27,6 +27,7 @@ #include "config.h" #include <limits.h> +#include <stdint.h> #include <stdlib.h> #include <string.h> #if HAVE_MALLOC_H @@ -34,6 +35,7 @@ #endif #include "avutil.h" +#include "intreadwrite.h" #include "mem.h" /* here we can use OS-dependent allocation functions */ @@ -177,3 +179,38 @@ char *av_strdup(const char *s) } return ptr; } + +void av_memcpy_backptr(uint8_t *dst, int back, int cnt) +{ + const uint8_t *src = &dst[-back]; + if (back == 1) { + memset(dst, *src, cnt); + } else { + if (cnt >= 4) { + AV_COPY16U(dst, src); + AV_COPY16U(dst + 2, src + 2); + src += 4; + dst += 4; + cnt -= 4; + } + if (cnt >= 8) { + AV_COPY16U(dst, src); + AV_COPY16U(dst + 2, src + 2); + AV_COPY16U(dst + 4, src + 4); + AV_COPY16U(dst + 6, src + 6); + src += 8; + dst += 8; + cnt -= 8; + } + if (cnt > 0) { + int blocklen = back; + while (cnt > blocklen) { + memcpy(dst, src, blocklen); + dst += blocklen; + cnt -= blocklen; + blocklen <<= 1; + } + memcpy(dst, src, cnt); + } + } +} diff --git a/libavutil/mem.h b/libavutil/mem.h index 4f14f27a91ec932b1f93df3806ccff36d93f9249..8f4722447d396be39a44f7d6e4ce80b4cc913b45 100644 --- a/libavutil/mem.h +++ b/libavutil/mem.h @@ -27,6 +27,7 @@ #define AVUTIL_MEM_H #include <limits.h> +#include <stdint.h> #include "attributes.h" #include "avutil.h" @@ -164,6 +165,17 @@ char *av_strdup(const char *s) av_malloc_attrib; */ void av_freep(void *ptr); +/** + * @brief deliberately overlapping memcpy implementation + * @param dst destination buffer + * @param back how many bytes back we start (the initial size of the overlapping window) + * @param cnt number of bytes to copy, must be >= 0 + * + * cnt > back is valid, this will copy the bytes we just copied, + * thus creating a repeating pattern with a period length of back. + */ +void av_memcpy_backptr(uint8_t *dst, int back, int cnt); + /** * @} */