On 2012-02-01 14:14:40 +0000, Måns Rullgård wrote:
> Janne Grunau <[email protected]> writes:
[...]
> > +void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
> > +{
> > + uint8_t **p = ptr;
> > + if (min_size > SIZE_MAX - FF_INPUT_BUFFER_PADDING_SIZE) {
> > + *p = NULL;
> > + *size = 0;
> > + return;
> > + }
> > + av_fast_malloc(ptr, size, min_size + FF_INPUT_BUFFER_PADDING_SIZE);
> > + if (*p)
> > + memset(*p + min_size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
> > +}
>
> There might be a strict aliasing problem writing the pointer as void*
> (in av_fast_malloc) and reading it as uint8_t*.
I'm not sure either but nothing prevents us from using p for
av_fast_malloc().
Janne
---8<---
Wrapper around av_fast_malloc() that keeps FF_INPUT_BUFFER_PADDING_SIZE
zero-padded bytes at the end of the used buffer.
Based on a patch by Reimar Döffinger <[email protected]>.
---
doc/APIchanges | 5 +++++
libavcodec/avcodec.h | 9 +++++++++
libavcodec/utils.c | 13 +++++++++++++
libavcodec/version.h | 2 +-
4 files changed, 28 insertions(+), 1 deletions(-)
diff --git a/doc/APIchanges b/doc/APIchanges
index 0d4cb59..60c16f4 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -13,6 +13,11 @@ libavutil: 2011-04-18
API changes, most recent first:
+2012-02-xx - xxxxxxx - lavc 54.2.0
+ Add av_fast_padded_malloc() as alternative for av_realloc() when aligned
+ memory is required. The buffer will always have FF_INPUT_BUFFER_PADDING_SIZE
+ zero-padded bytes at the end.
+
2012-01-31 - xxxxxxx - lavf 54.01.0
Add avformat_get_riff_video_tags() and avformat_get_riff_audio_tags().
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 85bb599..b06cf0d 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -4097,6 +4097,15 @@ void *av_fast_realloc(void *ptr, unsigned int *size,
size_t min_size);
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size);
/**
+ * Allocate a buffer with padding, reusing the given one if large enough.
+ *
+ * Same behaviour av_fast_malloc but the buffer has additional
+ * FF_INPUT_PADDING_SIZE at the end which will always memset to 0.
+ *
+ */
+void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size);
+
+/**
* Copy image src to dst. Wraps av_picture_data_copy() above.
*/
void av_picture_copy(AVPicture *dst, const AVPicture *src,
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index fa60953..c8e6efd 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -80,6 +80,19 @@ void av_fast_malloc(void *ptr, unsigned int *size, size_t
min_size)
*size= min_size;
}
+void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
+{
+ uint8_t **p = ptr;
+ if (min_size > SIZE_MAX - FF_INPUT_BUFFER_PADDING_SIZE) {
+ *p = NULL;
+ *size = 0;
+ return;
+ }
+ av_fast_malloc(p, size, min_size + FF_INPUT_BUFFER_PADDING_SIZE);
+ if (*p)
+ memset(*p + min_size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
+}
+
/* encoder management */
static AVCodec *first_avcodec = NULL;
diff --git a/libavcodec/version.h b/libavcodec/version.h
index c8ed77e..346310d 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -21,7 +21,7 @@
#define AVCODEC_VERSION_H
#define LIBAVCODEC_VERSION_MAJOR 54
-#define LIBAVCODEC_VERSION_MINOR 0
+#define LIBAVCODEC_VERSION_MINOR 2
#define LIBAVCODEC_VERSION_MICRO 0
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
--
1.7.8.4
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel