From 68e360a83c5b9dc21fd20cb477b171beab598ee7 Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Thu, 11 Oct 2012 14:15:10 +0100 Subject: parseutils-test: various cleanups - make tables static const - remove useless use of compound literal - break long lines - fix a comma/semicolon typo Signed-off-by: Mans Rullgard --- libavutil/parseutils.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/libavutil/parseutils.c b/libavutil/parseutils.c index 23fa80c01b..28aa9c9521 100644 --- a/libavutil/parseutils.c +++ b/libavutil/parseutils.c @@ -650,7 +650,7 @@ int main(void) printf("Testing av_parse_video_rate()\n"); { int i; - const char *rates[] = { + static const char *const rates[] = { "-inf", "inf", "nan", @@ -680,8 +680,8 @@ int main(void) for (i = 0; i < FF_ARRAY_ELEMS(rates); i++) { int ret; - AVRational q = (AVRational){0, 0}; - ret = av_parse_video_rate(&q, rates[i]), + AVRational q = { 0, 0 }; + ret = av_parse_video_rate(&q, rates[i]); printf("'%s' -> %d/%d %s\n", rates[i], q.num, q.den, ret ? "ERROR" : "OK"); } @@ -691,7 +691,7 @@ int main(void) { int i; uint8_t rgba[4]; - const char *color_names[] = { + static const char *const color_names[] = { "foo", "red", "Red ", @@ -732,7 +732,8 @@ int main(void) for (i = 0; i < FF_ARRAY_ELEMS(color_names); i++) { if (av_parse_color(rgba, color_names[i], -1, NULL) >= 0) - printf("%s -> R(%d) G(%d) B(%d) A(%d)\n", color_names[i], rgba[0], rgba[1], rgba[2], rgba[3]); + printf("%s -> R(%d) G(%d) B(%d) A(%d)\n", + color_names[i], rgba[0], rgba[1], rgba[2], rgba[3]); } } -- cgit v1.2.3 From 366b72f149a7b6a024ff5edd09ed5ae160755753 Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Thu, 11 Oct 2012 16:08:22 +0100 Subject: svq3: replace unsafe pointer casting with intreadwrite macros Signed-off-by: Mans Rullgard --- libavcodec/svq3.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/libavcodec/svq3.c b/libavcodec/svq3.c index c4d5a1bc59..6099e77f7a 100644 --- a/libavcodec/svq3.c +++ b/libavcodec/svq3.c @@ -409,17 +409,17 @@ static inline int svq3_mc_dir(H264Context *h, int size, int mode, int dir, int32_t mv = pack16to32(mx,my); if (part_height == 8 && i < 8) { - *(int32_t *) h->mv_cache[dir][scan8[k] + 1*8] = mv; + AV_WN32A(h->mv_cache[dir][scan8[k] + 1*8], mv); if (part_width == 8 && j < 8) { - *(int32_t *) h->mv_cache[dir][scan8[k] + 1 + 1*8] = mv; + AV_WN32A(h->mv_cache[dir][scan8[k] + 1 + 1*8], mv); } } if (part_width == 8 && j < 8) { - *(int32_t *) h->mv_cache[dir][scan8[k] + 1] = mv; + AV_WN32A(h->mv_cache[dir][scan8[k] + 1], mv); } if (part_width == 4 || part_height == 4) { - *(int32_t *) h->mv_cache[dir][scan8[k]] = mv; + AV_WN32A(h->mv_cache[dir][scan8[k]], mv); } } @@ -487,11 +487,11 @@ static int svq3_decode_mb(SVQ3Context *svq3, unsigned int mb_type) for (m = 0; m < 2; m++) { if (s->mb_x > 0 && h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - 1]+6] != -1) { for (i = 0; i < 4; i++) { - *(uint32_t *) h->mv_cache[m][scan8[0] - 1 + i*8] = *(uint32_t *) s->current_picture.f.motion_val[m][b_xy - 1 + i*h->b_stride]; + AV_COPY32(h->mv_cache[m][scan8[0] - 1 + i*8], s->current_picture.f.motion_val[m][b_xy - 1 + i*h->b_stride]); } } else { for (i = 0; i < 4; i++) { - *(uint32_t *) h->mv_cache[m][scan8[0] - 1 + i*8] = 0; + AV_ZERO32(h->mv_cache[m][scan8[0] - 1 + i*8]); } } if (s->mb_y > 0) { @@ -499,14 +499,14 @@ static int svq3_decode_mb(SVQ3Context *svq3, unsigned int mb_type) memset(&h->ref_cache[m][scan8[0] - 1*8], (h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - s->mb_stride]] == -1) ? PART_NOT_AVAILABLE : 1, 4); if (s->mb_x < (s->mb_width - 1)) { - *(uint32_t *) h->mv_cache[m][scan8[0] + 4 - 1*8] = *(uint32_t *) s->current_picture.f.motion_val[m][b_xy - h->b_stride + 4]; + AV_COPY32(h->mv_cache[m][scan8[0] + 4 - 1*8], s->current_picture.f.motion_val[m][b_xy - h->b_stride + 4]); h->ref_cache[m][scan8[0] + 4 - 1*8] = (h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - s->mb_stride + 1]+6] == -1 || h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - s->mb_stride ] ] == -1) ? PART_NOT_AVAILABLE : 1; }else h->ref_cache[m][scan8[0] + 4 - 1*8] = PART_NOT_AVAILABLE; if (s->mb_x > 0) { - *(uint32_t *) h->mv_cache[m][scan8[0] - 1 - 1*8] = *(uint32_t *) s->current_picture.f.motion_val[m][b_xy - h->b_stride - 1]; + AV_COPY32(h->mv_cache[m][scan8[0] - 1 - 1*8], s->current_picture.f.motion_val[m][b_xy - h->b_stride - 1]); h->ref_cache[m][scan8[0] - 1 - 1*8] = (h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - s->mb_stride - 1]+3] == -1) ? PART_NOT_AVAILABLE : 1; }else h->ref_cache[m][scan8[0] - 1 - 1*8] = PART_NOT_AVAILABLE; -- cgit v1.2.3 From fb32f31af76ce784c86c59c86c28e5653e223610 Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Thu, 11 Oct 2012 17:39:47 +0100 Subject: svq3: fix pointer type warning Fixes: libavcodec/svq3.c:661:9: warning: passing argument 2 of 'svq3_decode_block' from incompatible pointer type libavcodec/svq3.c:208:19: note: expected 'DCTELEM *' but argument is of type 'DCTELEM (*)[32]' Signed-off-by: Mans Rullgard --- libavcodec/svq3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/svq3.c b/libavcodec/svq3.c index 6099e77f7a..bc1a77a459 100644 --- a/libavcodec/svq3.c +++ b/libavcodec/svq3.c @@ -658,7 +658,7 @@ static int svq3_decode_mb(SVQ3Context *svq3, unsigned int mb_type) if (IS_INTRA16x16(mb_type)) { AV_ZERO128(h->mb_luma_dc[0]+0); AV_ZERO128(h->mb_luma_dc[0]+8); - if (svq3_decode_block(&s->gb, h->mb_luma_dc, 0, 1)){ + if (svq3_decode_block(&s->gb, h->mb_luma_dc[0], 0, 1)){ av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding intra luma dc\n"); return -1; } -- cgit v1.2.3 From 9a92aea27bad2f5603ca85e0d0716c679a6b686c Mon Sep 17 00:00:00 2001 From: Martin Storsjö Date: Thu, 11 Oct 2012 15:08:04 +0300 Subject: avutil: Add functions for allocating opaque contexts for algorithms MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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ö --- doc/APIchanges | 4 ++++ libavutil/aes.c | 7 +++++++ libavutil/aes.h | 12 +++++++++++- libavutil/md5.c | 8 ++++++++ libavutil/md5.h | 8 +++++++- libavutil/sha.c | 8 ++++++++ libavutil/sha.h | 12 +++++++++++- libavutil/tree.c | 7 +++++++ libavutil/tree.h | 12 +++++++++++- libavutil/version.h | 5 ++++- 10 files changed, 78 insertions(+), 5 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index 3e93354880..81a2266acb 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -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. 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,16 +23,26 @@ #include +#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 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 +#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,16 +23,26 @@ #include +#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. * 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 /** * @} -- cgit v1.2.3 From e002e3291e6dc7953f843abf56fc14f08f238b21 Mon Sep 17 00:00:00 2001 From: Martin Storsjö Date: Thu, 11 Oct 2012 15:10:45 +0300 Subject: Use the new aes/md5/sha/tree allocation functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Storsjö --- libavcodec/flacenc.c | 2 +- libavformat/crypto.c | 2 +- libavformat/httpauth.c | 2 +- libavformat/mxfdec.c | 2 +- libavformat/nut.c | 2 +- libavformat/rtmpproto.c | 2 +- libavutil/tree.c | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/libavcodec/flacenc.c b/libavcodec/flacenc.c index 122d485631..b135e4a4e5 100644 --- a/libavcodec/flacenc.c +++ b/libavcodec/flacenc.c @@ -354,7 +354,7 @@ static av_cold int flac_encode_init(AVCodecContext *avctx) s->channels, 16); /* initialize MD5 context */ - s->md5ctx = av_malloc(av_md5_size); + s->md5ctx = av_md5_alloc(); if (!s->md5ctx) return AVERROR(ENOMEM); av_md5_init(s->md5ctx); diff --git a/libavformat/crypto.c b/libavformat/crypto.c index 93c9f23f68..3bc33f2bb9 100644 --- a/libavformat/crypto.c +++ b/libavformat/crypto.c @@ -87,7 +87,7 @@ static int crypto_open(URLContext *h, const char *uri, int flags) av_log(h, AV_LOG_ERROR, "Unable to open input\n"); goto err; } - c->aes = av_mallocz(av_aes_size); + c->aes = av_aes_alloc(); if (!c->aes) { ret = AVERROR(ENOMEM); goto err; diff --git a/libavformat/httpauth.c b/libavformat/httpauth.c index 4ec8ac2599..774ee2134f 100644 --- a/libavformat/httpauth.c +++ b/libavformat/httpauth.c @@ -159,7 +159,7 @@ static char *make_digest_auth(HTTPAuthState *state, const char *username, ff_data_to_hex(cnonce, (const uint8_t*) cnonce_buf, sizeof(cnonce_buf), 1); cnonce[2*sizeof(cnonce_buf)] = 0; - md5ctx = av_malloc(av_md5_size); + md5ctx = av_md5_alloc(); if (!md5ctx) return NULL; diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c index 25d18f4829..8595d72083 100644 --- a/libavformat/mxfdec.c +++ b/libavformat/mxfdec.c @@ -340,7 +340,7 @@ static int mxf_decrypt_triplet(AVFormatContext *s, AVPacket *pkt, KLVPacket *klv int index; if (!mxf->aesc && s->key && s->keylen == 16) { - mxf->aesc = av_malloc(av_aes_size); + mxf->aesc = av_aes_alloc(); if (!mxf->aesc) return AVERROR(ENOMEM); av_aes_init(mxf->aesc, s->key, 128, 1); diff --git a/libavformat/nut.c b/libavformat/nut.c index 4e46b984b4..6a68e28173 100644 --- a/libavformat/nut.c +++ b/libavformat/nut.c @@ -116,7 +116,7 @@ int ff_nut_sp_pts_cmp(const Syncpoint *a, const Syncpoint *b){ void ff_nut_add_sp(NUTContext *nut, int64_t pos, int64_t back_ptr, int64_t ts){ Syncpoint *sp= av_mallocz(sizeof(Syncpoint)); - struct AVTreeNode *node= av_mallocz(av_tree_node_size); + struct AVTreeNode *node = av_tree_node_alloc(); sp->pos= pos; sp->back_ptr= back_ptr; diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c index d04f3a70a4..a5bc246e31 100644 --- a/libavformat/rtmpproto.c +++ b/libavformat/rtmpproto.c @@ -859,7 +859,7 @@ int ff_rtmp_calc_digest(const uint8_t *src, int len, int gap, uint8_t hmac_buf[64+32] = {0}; int i; - sha = av_mallocz(av_sha_size); + sha = av_sha_alloc(); if (!sha) return AVERROR(ENOMEM); diff --git a/libavutil/tree.c b/libavutil/tree.c index 55dcbc59a7..fd51a74916 100644 --- a/libavutil/tree.c +++ b/libavutil/tree.c @@ -220,7 +220,7 @@ int main (void) } av_log(NULL, AV_LOG_ERROR, "inserting %4d\n", j); if (!node) - node = av_mallocz(av_tree_node_size); + node = av_tree_node_alloc(); av_tree_insert(&root, (void *) (j + 1), cmp, &node); j = av_lfg_get(&prng) % 86294; -- cgit v1.2.3