aboutsummaryrefslogtreecommitdiffstats
path: root/libavutil
diff options
context:
space:
mode:
authorDiego Biurrun <diego@biurrun.de>2012-10-18 19:27:51 +0200
committerDiego Biurrun <diego@biurrun.de>2012-10-25 11:36:57 +0200
commit5bac2d0c3020587a03cb14e8b6a664a0b92f26c2 (patch)
tree08c6ccffd567aabf43301cc5d3dee357580d3eed /libavutil
parenta6e9d6497739b7b60e3284f03b27883514bbc94a (diff)
downloadffmpeg-5bac2d0c3020587a03cb14e8b6a664a0b92f26c2.tar.gz
avutil: Move memcpy_backptr() to mem.c
The function is used elsewhere and does not belong with the LZO code.
Diffstat (limited to 'libavutil')
-rw-r--r--libavutil/lzo.c44
-rw-r--r--libavutil/lzo.h11
-rw-r--r--libavutil/mem.c37
-rw-r--r--libavutil/mem.h12
4 files changed, 50 insertions, 54 deletions
diff --git a/libavutil/lzo.c b/libavutil/lzo.c
index c17d32f362..eff3cd2333 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 a84b9bd15d..9d7e8f1dc1 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
- * @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 16c1adb014..feba3163b0 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 4f14f27a91..8f4722447d 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
+ * @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);
+
+/**
* @}
*/