]> git.sesse.net Git - ffmpeg/commitdiff
avutil: Add functions for allocating opaque contexts for algorithms
authorMartin Storsjö <martin@martin.st>
Thu, 11 Oct 2012 12:08:04 +0000 (15:08 +0300)
committerMartin Storsjö <martin@martin.st>
Thu, 11 Oct 2012 20:35:27 +0000 (23:35 +0300)
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>
doc/APIchanges
libavutil/aes.c
libavutil/aes.h
libavutil/md5.c
libavutil/md5.h
libavutil/sha.c
libavutil/sha.h
libavutil/tree.c
libavutil/tree.h
libavutil/version.h

index 3e933548804ba3848e5f4adbf5a8b7fa3883e8b2..81a2266acb4e18094bca36e32f6e5a526cc1a264 100644 (file)
@@ -13,6 +13,10 @@ libavutil:     2011-04-18
 
 API changes, most recent first:
 
+2012-10-xx - xxxxxxx - lavu 51.43.0 - aes.h, md5.h, sha.h, tree.h
+  Add functions for allocating the opaque contexts for the algorithms,
+  deprecate the context size variables.
+
 2012-10-xx - xxxxxxx - lavf 54.18.0 - avio.h
   Add avio_closep to complement avio_close.
 
index 6803c7190d973153dec30e1d363263f2503c8e83..4656a486345a5f4d4e863a8bbcf05a26b7f6f9d0 100644 (file)
@@ -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
index cf7b462092764561253adf176a3517c17aa553e8..edff275b7ad8e32b67bdd93ed5475e47494d9514 100644 (file)
 
 #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
index ca0e598d2eb41d082dd92c1b14bc5fe5cfd370e6..93a91d7812cc56ddf2b6d9d462a8a6f98d5c4c28 100644 (file)
@@ -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 */
index c5b858a24b9f8fee31b56a3a62e1533fda9b9a04..29e4e7c2ba2de901647f9cd12538be791fff4864 100644 (file)
 
 #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);
index cbe1608a26a25e90bf9fb1bc471137e2152d413f..d5831915c4dcdda7136d520ec01b14d40a2d602e 100644 (file)
@@ -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))))
 
index 8350954c4b4897eac7f67472c536239bdf113d16..4c9a0c90950d116ae8f7e5114ee6198819e12403 100644 (file)
 
 #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.
  *
index 0e68bb75f10348a5bfe3520e4a68d44730aecefb..55dcbc59a78570c8f23940d96aa714336e05c867 100644 (file)
@@ -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])
index 59ea01dbdb049b3b627806a0ada1cb29989a5af4..623280f2b2fafe6c665729e8092102d86b4c86c9 100644 (file)
@@ -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
 
 
 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.
index c802bfe8e8771d7683d942ac6eb7018264f34409..856283598d49697863d736f06b79269a45b296e5 100644 (file)
@@ -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
 
 /**
  * @}