1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

Merge commit 'e002e3291e6dc7953f843abf56fc14f08f238b21'

* commit 'e002e3291e6dc7953f843abf56fc14f08f238b21':
  Use the new aes/md5/sha/tree allocation functions
  avutil: Add functions for allocating opaque contexts for algorithms
  svq3: fix pointer type warning
  svq3: replace unsafe pointer casting with intreadwrite macros
  parseutils-test: various cleanups

Conflicts:
	doc/APIchanges
	libavcodec/svq3.c
	libavutil/parseutils.c
	libavutil/version.h

Merged-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
Michael Niedermayer 2012-10-12 14:52:34 +02:00
commit f391e405df
18 changed files with 99 additions and 25 deletions

View File

@ -97,6 +97,10 @@ API changes, most recent first:
2012-03-26 - a67d9cf - lavfi 2.66.100 2012-03-26 - a67d9cf - lavfi 2.66.100
Add avfilter_fill_frame_from_{audio_,}buffer_ref() functions. Add avfilter_fill_frame_from_{audio_,}buffer_ref() functions.
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 2012-10-xx - xxxxxxx - lavf 54.18.0 - avio.h
Add avio_closep to complement avio_close. Add avio_closep to complement avio_close.

View File

@ -355,7 +355,7 @@ static av_cold int flac_encode_init(AVCodecContext *avctx)
s->channels, 16); s->channels, 16);
/* initialize MD5 context */ /* initialize MD5 context */
s->md5ctx = av_malloc(av_md5_size); s->md5ctx = av_md5_alloc();
if (!s->md5ctx) if (!s->md5ctx)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
av_md5_init(s->md5ctx); av_md5_init(s->md5ctx);

View File

@ -411,17 +411,17 @@ static inline int svq3_mc_dir(H264Context *h, int size, int mode, int dir,
int32_t mv = pack16to32(mx,my); int32_t mv = pack16to32(mx,my);
if (part_height == 8 && i < 8) { 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) { 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) { 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) { 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);
} }
} }
@ -489,11 +489,11 @@ static int svq3_decode_mb(SVQ3Context *svq3, unsigned int mb_type)
for (m = 0; m < 2; m++) { for (m = 0; m < 2; m++) {
if (s->mb_x > 0 && h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - 1]+6] != -1) { if (s->mb_x > 0 && h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - 1]+6] != -1) {
for (i = 0; i < 4; i++) { 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 { } else {
for (i = 0; i < 4; i++) { 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) { if (s->mb_y > 0) {
@ -501,14 +501,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); 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)) { 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->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]+6] == -1 ||
h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - s->mb_stride ] ] == -1) ? PART_NOT_AVAILABLE : 1; h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - s->mb_stride ] ] == -1) ? PART_NOT_AVAILABLE : 1;
}else }else
h->ref_cache[m][scan8[0] + 4 - 1*8] = PART_NOT_AVAILABLE; h->ref_cache[m][scan8[0] + 4 - 1*8] = PART_NOT_AVAILABLE;
if (s->mb_x > 0) { 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; 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 }else
h->ref_cache[m][scan8[0] - 1 - 1*8] = PART_NOT_AVAILABLE; h->ref_cache[m][scan8[0] - 1 - 1*8] = PART_NOT_AVAILABLE;
@ -660,7 +660,7 @@ static int svq3_decode_mb(SVQ3Context *svq3, unsigned int mb_type)
if (IS_INTRA16x16(mb_type)) { if (IS_INTRA16x16(mb_type)) {
AV_ZERO128(h->mb_luma_dc[0]+0); AV_ZERO128(h->mb_luma_dc[0]+0);
AV_ZERO128(h->mb_luma_dc[0]+8); 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"); av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding intra luma dc\n");
return -1; return -1;
} }

View File

@ -87,7 +87,7 @@ static int crypto_open2(URLContext *h, const char *uri, int flags, AVDictionary
av_log(h, AV_LOG_ERROR, "Unable to open input\n"); av_log(h, AV_LOG_ERROR, "Unable to open input\n");
goto err; goto err;
} }
c->aes = av_mallocz(av_aes_size); c->aes = av_aes_alloc();
if (!c->aes) { if (!c->aes) {
ret = AVERROR(ENOMEM); ret = AVERROR(ENOMEM);
goto err; goto err;

View File

@ -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); ff_data_to_hex(cnonce, (const uint8_t*) cnonce_buf, sizeof(cnonce_buf), 1);
cnonce[2*sizeof(cnonce_buf)] = 0; cnonce[2*sizeof(cnonce_buf)] = 0;
md5ctx = av_malloc(av_md5_size); md5ctx = av_md5_alloc();
if (!md5ctx) if (!md5ctx)
return NULL; return NULL;

View File

@ -350,7 +350,7 @@ static int mxf_decrypt_triplet(AVFormatContext *s, AVPacket *pkt, KLVPacket *klv
int index; int index;
if (!mxf->aesc && s->key && s->keylen == 16) { if (!mxf->aesc && s->key && s->keylen == 16) {
mxf->aesc = av_malloc(av_aes_size); mxf->aesc = av_aes_alloc();
if (!mxf->aesc) if (!mxf->aesc)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
av_aes_init(mxf->aesc, s->key, 128, 1); av_aes_init(mxf->aesc, s->key, 128, 1);

View File

@ -139,7 +139,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){ void ff_nut_add_sp(NUTContext *nut, int64_t pos, int64_t back_ptr, int64_t ts){
Syncpoint *sp= av_mallocz(sizeof(Syncpoint)); Syncpoint *sp= av_mallocz(sizeof(Syncpoint));
struct AVTreeNode *node= av_mallocz(av_tree_node_size); struct AVTreeNode *node = av_tree_node_alloc();
nut->sp_count++; nut->sp_count++;

View File

@ -859,7 +859,7 @@ int ff_rtmp_calc_digest(const uint8_t *src, int len, int gap,
uint8_t hmac_buf[64+32] = {0}; uint8_t hmac_buf[64+32] = {0};
int i; int i;
sha = av_mallocz(av_sha_size); sha = av_sha_alloc();
if (!sha) if (!sha)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);

View File

@ -39,7 +39,14 @@ typedef struct AVAES {
int rounds; int rounds;
} AVAES; } AVAES;
#if FF_API_CONTEXT_SIZE
const int av_aes_size= sizeof(AVAES); 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] = { static const uint8_t rcon[10] = {
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36

View File

@ -23,16 +23,26 @@
#include <stdint.h> #include <stdint.h>
#include "attributes.h"
#include "version.h"
/** /**
* @defgroup lavu_aes AES * @defgroup lavu_aes AES
* @ingroup lavu_crypto * @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; struct AVAES;
/**
* Allocate an AVAES context.
*/
struct AVAES *av_aes_alloc(void);
/** /**
* Initialize an AVAES context. * Initialize an AVAES context.
* @param key_bits 128, 192 or 256 * @param key_bits 128, 192 or 256

View File

@ -34,6 +34,7 @@
#include "bswap.h" #include "bswap.h"
#include "intreadwrite.h" #include "intreadwrite.h"
#include "md5.h" #include "md5.h"
#include "mem.h"
typedef struct AVMD5{ typedef struct AVMD5{
uint64_t len; uint64_t len;
@ -41,7 +42,14 @@ typedef struct AVMD5{
uint32_t ABCD[4]; uint32_t ABCD[4];
} AVMD5; } AVMD5;
#if FF_API_CONTEXT_SIZE
const int av_md5_size = sizeof(AVMD5); 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] = { static const uint8_t S[4][4] = {
{ 7, 12, 17, 22 }, /* round 1 */ { 7, 12, 17, 22 }, /* round 1 */

View File

@ -23,16 +23,22 @@
#include <stdint.h> #include <stdint.h>
#include "attributes.h"
#include "version.h"
/** /**
* @defgroup lavu_md5 MD5 * @defgroup lavu_md5 MD5
* @ingroup lavu_crypto * @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;
struct AVMD5 *av_md5_alloc(void);
void av_md5_init(struct AVMD5 *ctx); void av_md5_init(struct AVMD5 *ctx);
void av_md5_update(struct AVMD5 *ctx, const uint8_t *src, const int len); void av_md5_update(struct AVMD5 *ctx, const uint8_t *src, const int len);
void av_md5_final(struct AVMD5 *ctx, uint8_t *dst); void av_md5_final(struct AVMD5 *ctx, uint8_t *dst);

View File

@ -690,7 +690,7 @@ int main(void)
printf("Testing av_parse_video_rate()\n"); printf("Testing av_parse_video_rate()\n");
{ {
int i; int i;
const char *rates[] = { static const char *const rates[] = {
"-inf", "-inf",
"inf", "inf",
"nan", "nan",
@ -720,7 +720,7 @@ int main(void)
for (i = 0; i < FF_ARRAY_ELEMS(rates); i++) { for (i = 0; i < FF_ARRAY_ELEMS(rates); i++) {
int ret; int ret;
AVRational q = (AVRational){0, 0}; AVRational q = { 0, 0 };
ret = av_parse_video_rate(&q, rates[i]); ret = av_parse_video_rate(&q, rates[i]);
printf("'%s' -> %d/%d %s\n", printf("'%s' -> %d/%d %s\n",
rates[i], q.num, q.den, ret ? "ERROR" : "OK"); rates[i], q.num, q.den, ret ? "ERROR" : "OK");
@ -731,7 +731,7 @@ int main(void)
{ {
int i; int i;
uint8_t rgba[4]; uint8_t rgba[4];
const char *color_names[] = { static const char *const color_names[] = {
"bikeshed", "bikeshed",
"RaNdOm", "RaNdOm",
"foo", "foo",
@ -774,7 +774,8 @@ int main(void)
for (i = 0; i < FF_ARRAY_ELEMS(color_names); i++) { for (i = 0; i < FF_ARRAY_ELEMS(color_names); i++) {
if (av_parse_color(rgba, color_names[i], -1, NULL) >= 0) 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]);
else else
printf("%s -> error\n", color_names[i]); printf("%s -> error\n", color_names[i]);
} }

View File

@ -26,6 +26,7 @@
#include "bswap.h" #include "bswap.h"
#include "sha.h" #include "sha.h"
#include "intreadwrite.h" #include "intreadwrite.h"
#include "mem.h"
/** hash context */ /** hash context */
typedef struct AVSHA { typedef struct AVSHA {
@ -37,7 +38,14 @@ typedef struct AVSHA {
void (*transform)(uint32_t *state, const uint8_t buffer[64]); void (*transform)(uint32_t *state, const uint8_t buffer[64]);
} AVSHA; } AVSHA;
#if FF_API_CONTEXT_SIZE
const int av_sha_size = sizeof(AVSHA); 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)))) #define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits))))

View File

@ -23,16 +23,26 @@
#include <stdint.h> #include <stdint.h>
#include "attributes.h"
#include "version.h"
/** /**
* @defgroup lavu_sha SHA * @defgroup lavu_sha SHA
* @ingroup lavu_crypto * @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; struct AVSHA;
/**
* Allocate an AVSHA context.
*/
struct AVSHA *av_sha_alloc(void);
/** /**
* Initialize SHA-1 or SHA-2 hashing. * Initialize SHA-1 or SHA-2 hashing.
* *

View File

@ -28,7 +28,14 @@ typedef struct AVTreeNode {
int state; int state;
} AVTreeNode; } AVTreeNode;
#if FF_API_CONTEXT_SIZE
const int av_tree_node_size = sizeof(AVTreeNode); 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, void *av_tree_find(const AVTreeNode *t, void *key,
int (*cmp)(void *key, const void *b), void *next[2]) int (*cmp)(void *key, const void *b), void *next[2])
@ -213,7 +220,7 @@ int main (void)
} }
av_log(NULL, AV_LOG_ERROR, "inserting %4d\n", j); av_log(NULL, AV_LOG_ERROR, "inserting %4d\n", j);
if (!node) if (!node)
node = av_mallocz(av_tree_node_size); node = av_tree_node_alloc();
av_tree_insert(&root, (void *) (j + 1), cmp, &node); av_tree_insert(&root, (void *) (j + 1), cmp, &node);
j = av_lfg_get(&prng) % 86294; j = av_lfg_get(&prng) % 86294;

View File

@ -27,6 +27,9 @@
#ifndef AVUTIL_TREE_H #ifndef AVUTIL_TREE_H
#define AVUTIL_TREE_H #define AVUTIL_TREE_H
#include "attributes.h"
#include "version.h"
/** /**
* @addtogroup lavu_tree AVTree * @addtogroup lavu_tree AVTree
* @ingroup lavu_data * @ingroup lavu_data
@ -40,7 +43,14 @@
struct AVTreeNode; 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. * Find an element.

View File

@ -39,7 +39,7 @@
*/ */
#define LIBAVUTIL_VERSION_MAJOR 51 #define LIBAVUTIL_VERSION_MAJOR 51
#define LIBAVUTIL_VERSION_MINOR 74 #define LIBAVUTIL_VERSION_MINOR 75
#define LIBAVUTIL_VERSION_MICRO 100 #define LIBAVUTIL_VERSION_MICRO 100
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
@ -84,6 +84,9 @@
#ifndef FF_API_PIX_FMT #ifndef FF_API_PIX_FMT
#define FF_API_PIX_FMT (LIBAVUTIL_VERSION_MAJOR < 52) #define FF_API_PIX_FMT (LIBAVUTIL_VERSION_MAJOR < 52)
#endif #endif
#ifndef FF_API_CONTEXT_SIZE
#define FF_API_CONTEXT_SIZE (LIBAVUTIL_VERSION_MAJOR < 52)
#endif
/** /**
* @} * @}