summaryrefslogtreecommitdiff
path: root/libavutil
diff options
context:
space:
mode:
authorMartin Storsjö <martin@martin.st>2012-10-11 15:08:04 +0300
committerMartin Storsjö <martin@martin.st>2012-10-11 23:35:27 +0300
commit9a92aea27bad2f5603ca85e0d0716c679a6b686c (patch)
treea38dae27b4c15cc4a75c0a3745351b8c5b3fd122 /libavutil
parentfb32f31af76ce784c86c59c86c28e5653e223610 (diff)
avutil: Add functions for allocating opaque contexts for algorithms
The current API where the plain size is exposed is not of much use - in most cases it is allocated dynamically anyway. If allocated e.g. on the stack via an uint8_t array, there's no guarantee that the struct's members are aligned properly (unless the array is overallocated and the opaque pointer within it manually aligned to some unspecified alignment). Signed-off-by: Martin Storsjö <martin@martin.st>
Diffstat (limited to 'libavutil')
-rw-r--r--libavutil/aes.c7
-rw-r--r--libavutil/aes.h12
-rw-r--r--libavutil/md5.c8
-rw-r--r--libavutil/md5.h8
-rw-r--r--libavutil/sha.c8
-rw-r--r--libavutil/sha.h12
-rw-r--r--libavutil/tree.c7
-rw-r--r--libavutil/tree.h12
-rw-r--r--libavutil/version.h5
9 files changed, 74 insertions, 5 deletions
diff --git a/libavutil/aes.c b/libavutil/aes.c
index 6803c7190d..4656a48634 100644
--- a/libavutil/aes.c
+++ b/libavutil/aes.c
@@ -39,7 +39,14 @@ typedef struct AVAES {
int rounds;
} AVAES;
+#if FF_API_CONTEXT_SIZE
const int av_aes_size= sizeof(AVAES);
+#endif
+
+struct AVAES *av_aes_alloc(void)
+{
+ return av_mallocz(sizeof(struct AVAES));
+}
static const uint8_t rcon[10] = {
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36
diff --git a/libavutil/aes.h b/libavutil/aes.h
index cf7b462092..edff275b7a 100644
--- a/libavutil/aes.h
+++ b/libavutil/aes.h
@@ -23,17 +23,27 @@
#include <stdint.h>
+#include "attributes.h"
+#include "version.h"
+
/**
* @defgroup lavu_aes AES
* @ingroup lavu_crypto
* @{
*/
-extern const int av_aes_size;
+#if FF_API_CONTEXT_SIZE
+extern attribute_deprecated const int av_aes_size;
+#endif
struct AVAES;
/**
+ * Allocate an AVAES context.
+ */
+struct AVAES *av_aes_alloc(void);
+
+/**
* Initialize an AVAES context.
* @param key_bits 128, 192 or 256
* @param decrypt 0 for encryption, 1 for decryption
diff --git a/libavutil/md5.c b/libavutil/md5.c
index ca0e598d2e..93a91d7812 100644
--- a/libavutil/md5.c
+++ b/libavutil/md5.c
@@ -34,6 +34,7 @@
#include "bswap.h"
#include "intreadwrite.h"
#include "md5.h"
+#include "mem.h"
typedef struct AVMD5{
uint64_t len;
@@ -41,7 +42,14 @@ typedef struct AVMD5{
uint32_t ABCD[4];
} AVMD5;
+#if FF_API_CONTEXT_SIZE
const int av_md5_size = sizeof(AVMD5);
+#endif
+
+struct AVMD5 *av_md5_alloc(void)
+{
+ return av_mallocz(sizeof(struct AVMD5));
+}
static const uint8_t S[4][4] = {
{ 7, 12, 17, 22 }, /* round 1 */
diff --git a/libavutil/md5.h b/libavutil/md5.h
index c5b858a24b..29e4e7c2ba 100644
--- a/libavutil/md5.h
+++ b/libavutil/md5.h
@@ -23,16 +23,22 @@
#include <stdint.h>
+#include "attributes.h"
+#include "version.h"
+
/**
* @defgroup lavu_md5 MD5
* @ingroup lavu_crypto
* @{
*/
-extern const int av_md5_size;
+#if FF_API_CONTEXT_SIZE
+extern attribute_deprecated const int av_md5_size;
+#endif
struct AVMD5;
+struct AVMD5 *av_md5_alloc(void);
void av_md5_init(struct AVMD5 *ctx);
void av_md5_update(struct AVMD5 *ctx, const uint8_t *src, const int len);
void av_md5_final(struct AVMD5 *ctx, uint8_t *dst);
diff --git a/libavutil/sha.c b/libavutil/sha.c
index cbe1608a26..d5831915c4 100644
--- a/libavutil/sha.c
+++ b/libavutil/sha.c
@@ -26,6 +26,7 @@
#include "bswap.h"
#include "sha.h"
#include "intreadwrite.h"
+#include "mem.h"
/** hash context */
typedef struct AVSHA {
@@ -37,7 +38,14 @@ typedef struct AVSHA {
void (*transform)(uint32_t *state, const uint8_t buffer[64]);
} AVSHA;
+#if FF_API_CONTEXT_SIZE
const int av_sha_size = sizeof(AVSHA);
+#endif
+
+struct AVSHA *av_sha_alloc(void)
+{
+ return av_mallocz(sizeof(struct AVSHA));
+}
#define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits))))
diff --git a/libavutil/sha.h b/libavutil/sha.h
index 8350954c4b..4c9a0c9095 100644
--- a/libavutil/sha.h
+++ b/libavutil/sha.h
@@ -23,17 +23,27 @@
#include <stdint.h>
+#include "attributes.h"
+#include "version.h"
+
/**
* @defgroup lavu_sha SHA
* @ingroup lavu_crypto
* @{
*/
-extern const int av_sha_size;
+#if FF_API_CONTEXT_SIZE
+extern attribute_deprecated const int av_sha_size;
+#endif
struct AVSHA;
/**
+ * Allocate an AVSHA context.
+ */
+struct AVSHA *av_sha_alloc(void);
+
+/**
* Initialize SHA-1 or SHA-2 hashing.
*
* @param context pointer to the function context (of size av_sha_size)
diff --git a/libavutil/tree.c b/libavutil/tree.c
index 0e68bb75f1..55dcbc59a7 100644
--- a/libavutil/tree.c
+++ b/libavutil/tree.c
@@ -28,7 +28,14 @@ typedef struct AVTreeNode {
int state;
} AVTreeNode;
+#if FF_API_CONTEXT_SIZE
const int av_tree_node_size = sizeof(AVTreeNode);
+#endif
+
+struct AVTreeNode *av_tree_node_alloc(void)
+{
+ return av_mallocz(sizeof(struct AVTreeNode));
+}
void *av_tree_find(const AVTreeNode *t, void *key,
int (*cmp)(void *key, const void *b), void *next[2])
diff --git a/libavutil/tree.h b/libavutil/tree.h
index 59ea01dbdb..623280f2b2 100644
--- a/libavutil/tree.h
+++ b/libavutil/tree.h
@@ -27,6 +27,9 @@
#ifndef AVUTIL_TREE_H
#define AVUTIL_TREE_H
+#include "attributes.h"
+#include "version.h"
+
/**
* @addtogroup lavu_tree AVTree
* @ingroup lavu_data
@@ -40,7 +43,14 @@
struct AVTreeNode;
-extern const int av_tree_node_size;
+#if FF_API_CONTEXT_SIZE
+extern attribute_deprecated const int av_tree_node_size;
+#endif
+
+/**
+ * Allocate an AVTreeNode.
+ */
+struct AVTreeNode *av_tree_node_alloc(void);
/**
* Find an element.
diff --git a/libavutil/version.h b/libavutil/version.h
index c802bfe8e8..856283598d 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -37,7 +37,7 @@
*/
#define LIBAVUTIL_VERSION_MAJOR 51
-#define LIBAVUTIL_VERSION_MINOR 42
+#define LIBAVUTIL_VERSION_MINOR 43
#define LIBAVUTIL_VERSION_MICRO 0
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
@@ -76,6 +76,9 @@
#ifndef FF_API_PIX_FMT
#define FF_API_PIX_FMT (LIBAVUTIL_VERSION_MAJOR < 52)
#endif
+#ifndef FF_API_CONTEXT_SIZE
+#define FF_API_CONTEXT_SIZE (LIBAVUTIL_VERSION_MAJOR < 52)
+#endif
/**
* @}