diff options
author | Justin Ruggles <justin.ruggles@gmail.com> | 2011-11-15 15:34:50 -0500 |
---|---|---|
committer | Justin Ruggles <justin.ruggles@gmail.com> | 2011-11-19 10:01:05 -0500 |
commit | f3a29b750a5979ae6847879fba758faf1fae88d0 (patch) | |
tree | 0a5bf0e6822f0adf284a76c5d28ce55e3ad21d24 /libavcodec/utils.c | |
parent | 513b6919555b9e2b0c1f86fd5f02caaa14bcbe69 (diff) | |
download | ffmpeg-f3a29b750a5979ae6847879fba758faf1fae88d0.tar.gz |
avcodec: move some AVCodecContext fields to an internal struct.
A new field, AVCodecContext.internal is used to hold a new struct
AVCodecInternal, which has private fields that are not codec-specific and are
used by general libavcodec functions.
Moved internal_buffer, internal_buffer_count, and is_copy.
Diffstat (limited to 'libavcodec/utils.c')
-rw-r--r-- | libavcodec/utils.c | 88 |
1 files changed, 44 insertions, 44 deletions
diff --git a/libavcodec/utils.c b/libavcodec/utils.c index cd8dce91fc..3e182a1613 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -125,15 +125,6 @@ void avcodec_set_dimensions(AVCodecContext *s, int width, int height){ s->height= -((-height)>>s->lowres); } -typedef struct InternalBuffer{ - int last_pic_num; - uint8_t *base[4]; - uint8_t *data[4]; - int linesize[4]; - int width, height; - enum PixelFormat pix_fmt; -}InternalBuffer; - #define INTERNAL_BUFFER_SIZE (32+1) void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height, int linesize_align[4]){ @@ -250,32 +241,27 @@ int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic){ int h= s->height; InternalBuffer *buf; int *picture_number; + AVCodecInternal *avci = s->internal; if(pic->data[0]!=NULL) { av_log(s, AV_LOG_ERROR, "pic->data[0]!=NULL in avcodec_default_get_buffer\n"); return -1; } - if(s->internal_buffer_count >= INTERNAL_BUFFER_SIZE) { - av_log(s, AV_LOG_ERROR, "internal_buffer_count overflow (missing release_buffer?)\n"); + if(avci->buffer_count >= INTERNAL_BUFFER_SIZE) { + av_log(s, AV_LOG_ERROR, "buffer_count overflow (missing release_buffer?)\n"); return -1; } if(av_image_check_size(w, h, 0, s)) return -1; - if(s->internal_buffer==NULL){ - s->internal_buffer= av_mallocz((INTERNAL_BUFFER_SIZE+1)*sizeof(InternalBuffer)); + if (!avci->buffer) { + avci->buffer = av_mallocz((INTERNAL_BUFFER_SIZE+1) * + sizeof(InternalBuffer)); } -#if 0 - s->internal_buffer= av_fast_realloc( - s->internal_buffer, - &s->internal_buffer_size, - sizeof(InternalBuffer)*FFMAX(99, s->internal_buffer_count+1)/*FIXME*/ - ); -#endif - buf= &((InternalBuffer*)s->internal_buffer)[s->internal_buffer_count]; - picture_number= &(((InternalBuffer*)s->internal_buffer)[INTERNAL_BUFFER_SIZE]).last_pic_num; //FIXME ugly hack + buf = &avci->buffer[avci->buffer_count]; + picture_number = &(avci->buffer[INTERNAL_BUFFER_SIZE]).last_pic_num; //FIXME ugly hack (*picture_number)++; if(buf->base[0] && (buf->width != w || buf->height != h || buf->pix_fmt != s->pix_fmt)){ @@ -366,14 +352,15 @@ int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic){ pic->data[i]= buf->data[i]; pic->linesize[i]= buf->linesize[i]; } - s->internal_buffer_count++; + avci->buffer_count++; if(s->pkt) pic->pkt_pts= s->pkt->pts; else pic->pkt_pts= AV_NOPTS_VALUE; pic->reordered_opaque= s->reordered_opaque; if(s->debug&FF_DEBUG_BUFFERS) - av_log(s, AV_LOG_DEBUG, "default_get_buffer called on pic %p, %d buffers used\n", pic, s->internal_buffer_count); + av_log(s, AV_LOG_DEBUG, "default_get_buffer called on pic %p, %d " + "buffers used\n", pic, avci->buffer_count); return 0; } @@ -381,22 +368,23 @@ int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic){ void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic){ int i; InternalBuffer *buf, *last; + AVCodecInternal *avci = s->internal; assert(pic->type==FF_BUFFER_TYPE_INTERNAL); - assert(s->internal_buffer_count); - - if(s->internal_buffer){ - buf = NULL; /* avoids warning */ - for(i=0; i<s->internal_buffer_count; i++){ //just 3-5 checks so is not worth to optimize - buf= &((InternalBuffer*)s->internal_buffer)[i]; - if(buf->data[0] == pic->data[0]) - break; - } - assert(i < s->internal_buffer_count); - s->internal_buffer_count--; - last = &((InternalBuffer*)s->internal_buffer)[s->internal_buffer_count]; + assert(avci->buffer_count); + + if (avci->buffer) { + buf = NULL; /* avoids warning */ + for (i = 0; i < avci->buffer_count; i++) { //just 3-5 checks so is not worth to optimize + buf = &avci->buffer[i]; + if (buf->data[0] == pic->data[0]) + break; + } + assert(i < avci->buffer_count); + avci->buffer_count--; + last = &avci->buffer[avci->buffer_count]; - FFSWAP(InternalBuffer, *buf, *last); + FFSWAP(InternalBuffer, *buf, *last); } for(i=0; i<4; i++){ @@ -406,7 +394,8 @@ void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic){ //printf("R%X\n", pic->opaque); if(s->debug&FF_DEBUG_BUFFERS) - av_log(s, AV_LOG_DEBUG, "default_release_buffer called on pic %p, %d buffers used\n", pic, s->internal_buffer_count); + av_log(s, AV_LOG_DEBUG, "default_release_buffer called on pic %p, %d " + "buffers used\n", pic, avci->buffer_count); } int avcodec_default_reget_buffer(AVCodecContext *s, AVFrame *pic){ @@ -521,6 +510,12 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, AVCodec *codec, AVD goto end; } + avctx->internal = av_mallocz(sizeof(AVCodecInternal)); + if (!avctx->internal) { + ret = AVERROR(ENOMEM); + goto end; + } + if (codec->priv_data_size > 0) { if(!avctx->priv_data){ avctx->priv_data = av_mallocz(codec->priv_data_size); @@ -670,6 +665,7 @@ end: free_and_end: av_dict_free(&tmp); av_freep(&avctx->priv_data); + av_freep(&avctx->internal); avctx->codec= NULL; goto end; } @@ -844,6 +840,7 @@ av_cold int avcodec_close(AVCodecContext *avctx) avctx->codec->close(avctx); avcodec_default_free_buffers(avctx); avctx->coded_frame = NULL; + av_freep(&avctx->internal); if (avctx->codec && avctx->codec->priv_class) av_opt_free(avctx->priv_data); av_opt_free(avctx); @@ -1109,22 +1106,25 @@ void avcodec_flush_buffers(AVCodecContext *avctx) } void avcodec_default_free_buffers(AVCodecContext *s){ + AVCodecInternal *avci = s->internal; int i, j; - if(s->internal_buffer==NULL) return; + if (!avci->buffer) + return; - if (s->internal_buffer_count) - av_log(s, AV_LOG_WARNING, "Found %i unreleased buffers!\n", s->internal_buffer_count); + if (avci->buffer_count) + av_log(s, AV_LOG_WARNING, "Found %i unreleased buffers!\n", + avci->buffer_count); for(i=0; i<INTERNAL_BUFFER_SIZE; i++){ - InternalBuffer *buf= &((InternalBuffer*)s->internal_buffer)[i]; + InternalBuffer *buf = &avci->buffer[i]; for(j=0; j<4; j++){ av_freep(&buf->base[j]); buf->data[j]= NULL; } } - av_freep(&s->internal_buffer); + av_freep(&avci->buffer); - s->internal_buffer_count=0; + avci->buffer_count=0; } #if FF_API_OLD_FF_PICT_TYPES |