Merge remote-tracking branch 'qatar/master'
* qatar/master: swscale: Fix stack alignment for SSE avcodec: move some AVCodecContext fields to an internal struct. avcodec: use av_opt_set() instead of deprecated av_set_string3() avcodec: fix some const warnings avcodec: remove pointless AVOption, internal_buffer_count imgutils: Fix illegal read. Conflicts: doc/APIchanges libavcodec/avcodec.h libavcodec/version.h Merged-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
@@ -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]){
|
||||
@@ -267,32 +258,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)){
|
||||
@@ -383,7 +369,7 @@ 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;
|
||||
@@ -399,7 +385,8 @@ int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic){
|
||||
pic->format = s->pix_fmt;
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -407,22 +394,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);
|
||||
assert(avci->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];
|
||||
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++){
|
||||
@@ -432,7 +420,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){
|
||||
@@ -556,6 +545,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);
|
||||
@@ -721,6 +716,7 @@ end:
|
||||
free_and_end:
|
||||
av_dict_free(&tmp);
|
||||
av_freep(&avctx->priv_data);
|
||||
av_freep(&avctx->internal);
|
||||
avctx->codec= NULL;
|
||||
goto end;
|
||||
}
|
||||
@@ -945,6 +941,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);
|
||||
@@ -1223,22 +1220,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
|
||||
|
Reference in New Issue
Block a user