The function is used elsewhere and does not belong with the LZO code.
---
This might or might not need some version bump ifdefs since a public
function's declaration is moved from one header to another.

 libavcodec/dfa.c      |    3 ++-
 libavcodec/eatgv.c    |    2 +-
 libavcodec/g723_1.c   |    2 +-
 libavcodec/lcldec.c   |    1 +
 libavcodec/wmavoice.c |    2 +-
 libavcodec/xan.c      |    3 +--
 libavcodec/xxan.c     |    3 +--
 libavutil/lzo.c       |   48 ++----------------------------------------------
 libavutil/lzo.h       |   11 -----------
 libavutil/mem.c       |   49 +++++++++++++++++++++++++++++++++++++++++++++++++
 libavutil/mem.h       |   12 ++++++++++++
 11 files changed, 71 insertions(+), 65 deletions(-)

diff --git a/libavcodec/dfa.c b/libavcodec/dfa.c
index 39f0f64..fb751f6 100644
--- a/libavcodec/dfa.c
+++ b/libavcodec/dfa.c
@@ -24,7 +24,8 @@
 #include "bytestream.h"
 
 #include "libavutil/imgutils.h"
-#include "libavutil/lzo.h" // for av_memcpy_backptr
+#include "libavutil/lzo.h"
+#include "libavutil/mem.h"
 
 typedef struct DfaContext {
     AVFrame pic;
diff --git a/libavcodec/eatgv.c b/libavcodec/eatgv.c
index b29c994..3f1bfce 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 3d4fa46..cfdfd0f 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 0de7410..855e1b1 100644
--- a/libavcodec/lcldec.c
+++ b/libavcodec/lcldec.c
@@ -45,6 +45,7 @@
 #include "bytestream.h"
 #include "lcl.h"
 #include "libavutil/lzo.h"
+#include "libavutil/mem.h"
 
 #if CONFIG_ZLIB_DECODER
 #include <zlib.h>
diff --git a/libavcodec/wmavoice.c b/libavcodec/wmavoice.c
index 2ed79a6..41ec194 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 586320b..e6bfc0d 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 b06d314..2a5a8ca 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 0d1ec55..92f736b 100644
--- a/libavutil/lzo.c
+++ b/libavutil/lzo.c
@@ -19,6 +19,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include <stdint.h>
 #include <string.h>
 
 #include "avutil.h"
@@ -74,13 +75,10 @@ static inline int get_len(LZOContext *c, int x, int mask)
 //#define UNALIGNED_LOADSTORE
 #define BUILTIN_MEMCPY
 #ifdef UNALIGNED_LOADSTORE
-#define COPY2(d, s) *(uint16_t *)(d) = *(uint16_t *)(s);
 #define COPY4(d, s) *(uint32_t *)(d) = *(uint32_t *)(s);
 #elif defined(BUILTIN_MEMCPY)
-#define COPY2(d, s) memcpy(d, s, 2);
 #define COPY4(d, s) memcpy(d, s, 4);
 #else
-#define COPY2(d, s) (d)[0] = (s)[0]; (d)[1] = (s)[1];
 #define COPY4(d, s) (d)[0] = (s)[0]; (d)[1] = (s)[1]; (d)[2] = (s)[2]; (d)[3] 
= (s)[3];
 #endif
 
@@ -112,8 +110,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
@@ -134,50 +130,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 {
-#ifdef OUTBUF_PADDED
-        COPY2(dst, src);
-        COPY2(dst + 2, src + 2);
-        src += 4;
-        dst += 4;
-        cnt -= 4;
-        if (cnt > 0) {
-            COPY2(dst, src);
-            COPY2(dst + 2, src + 2);
-            COPY2(dst + 4, src + 4);
-            COPY2(dst + 6, src + 6);
-            src += 8;
-            dst += 8;
-            cnt -= 8;
-        }
-#endif
-        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 8f28fe1..3afd516 100644
--- a/libavutil/lzo.h
+++ b/libavutil/lzo.h
@@ -60,17 +60,6 @@
 int av_lzo1x_decode(void *out, int *outlen, const void *in, int *inlen);
 
 /**
- * @brief deliberately overlapping memcpy implementation
- * @param dst destination buffer; must be padded with 12 additional bytes
- * @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 16c1adb..4695c06 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
@@ -177,3 +178,51 @@ char *av_strdup(const char *s)
     }
     return ptr;
 }
+
+// Define if we may write up to 12 bytes beyond the output buffer.
+#define OUTBUF_PADDED 1
+
+//#define UNALIGNED_LOADSTORE
+#define BUILTIN_MEMCPY
+#ifdef UNALIGNED_LOADSTORE
+#define COPY2(d, s) *(uint16_t *)(d) = *(uint16_t *)(s);
+#elif defined(BUILTIN_MEMCPY)
+#define COPY2(d, s) memcpy(d, s, 2);
+#else
+#define COPY2(d, s) (d)[0] = (s)[0]; (d)[1] = (s)[1];
+#endif
+
+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 {
+#ifdef OUTBUF_PADDED
+        COPY2(dst, src);
+        COPY2(dst + 2, src + 2);
+        src += 4;
+        dst += 4;
+        cnt -= 4;
+        if (cnt > 0) {
+            COPY2(dst, src);
+            COPY2(dst + 2, src + 2);
+            COPY2(dst + 4, src + 4);
+            COPY2(dst + 6, src + 6);
+            src += 8;
+            dst += 8;
+            cnt -= 8;
+        }
+#endif
+        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 4f14f27..41b139d 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"
@@ -165,6 +166,17 @@ char *av_strdup(const char *s) av_malloc_attrib;
 void av_freep(void *ptr);
 
 /**
+ * @brief deliberately overlapping memcpy implementation
+ * @param dst destination buffer; must be padded with 12 additional bytes
+ * @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);
+
+/**
  * @}
  */
 
-- 
1.7.1

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

Reply via email to