mirror of https://git.ffmpeg.org/ffmpeg.git
Add frame buffer allocators. aka simplify calls to
AVCodecContext.{get,release}_buffer(). Originally committed as revision 17804 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
parent
63581eb183
commit
34e46c44da
|
@ -164,6 +164,43 @@ void ff_copy_picture(Picture *dst, Picture *src){
|
|||
dst->type= FF_BUFFER_TYPE_COPY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Releases a frame buffer
|
||||
*/
|
||||
static void free_frame_buffer(MpegEncContext *s, Picture *pic)
|
||||
{
|
||||
s->avctx->release_buffer(s->avctx, (AVFrame*)pic);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocates a frame buffer
|
||||
*/
|
||||
static int alloc_frame_buffer(MpegEncContext *s, Picture *pic)
|
||||
{
|
||||
int r;
|
||||
|
||||
r = s->avctx->get_buffer(s->avctx, (AVFrame*)pic);
|
||||
|
||||
if (r<0 || !pic->age || !pic->type || !pic->data[0]) {
|
||||
av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed (%d %d %d %p)\n", r, pic->age, pic->type, pic->data[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (s->linesize && (s->linesize != pic->linesize[0] || s->uvlinesize != pic->linesize[1])) {
|
||||
av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed (stride changed)\n");
|
||||
free_frame_buffer(s, pic);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pic->linesize[1] != pic->linesize[2]) {
|
||||
av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed (uv stride mismatch)\n");
|
||||
free_frame_buffer(s, pic);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* allocates a Picture
|
||||
* The pixels are allocated/set by calling get_buffer() if shared=0
|
||||
|
@ -183,24 +220,8 @@ int alloc_picture(MpegEncContext *s, Picture *pic, int shared){
|
|||
}else{
|
||||
assert(!pic->data[0]);
|
||||
|
||||
r= s->avctx->get_buffer(s->avctx, (AVFrame*)pic);
|
||||
|
||||
if(r<0 || !pic->age || !pic->type || !pic->data[0]){
|
||||
av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed (%d %d %d %p)\n", r, pic->age, pic->type, pic->data[0]);
|
||||
if (alloc_frame_buffer(s, pic) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(s->linesize && (s->linesize != pic->linesize[0] || s->uvlinesize != pic->linesize[1])){
|
||||
av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed (stride changed)\n");
|
||||
s->avctx->release_buffer(s->avctx, (AVFrame*)pic);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(pic->linesize[1] != pic->linesize[2]){
|
||||
av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed (uv stride mismatch)\n");
|
||||
s->avctx->release_buffer(s->avctx, (AVFrame*)pic);
|
||||
return -1;
|
||||
}
|
||||
|
||||
s->linesize = pic->linesize[0];
|
||||
s->uvlinesize= pic->linesize[1];
|
||||
|
@ -249,7 +270,7 @@ int alloc_picture(MpegEncContext *s, Picture *pic, int shared){
|
|||
return 0;
|
||||
fail: //for the CHECKED_ALLOCZ macro
|
||||
if(r>=0)
|
||||
s->avctx->release_buffer(s->avctx, (AVFrame*)pic);
|
||||
free_frame_buffer(s, pic);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -260,7 +281,7 @@ static void free_picture(MpegEncContext *s, Picture *pic){
|
|||
int i;
|
||||
|
||||
if(pic->data[0] && pic->type!=FF_BUFFER_TYPE_SHARED){
|
||||
s->avctx->release_buffer(s->avctx, (AVFrame*)pic);
|
||||
free_frame_buffer(s, pic);
|
||||
}
|
||||
|
||||
av_freep(&pic->mb_var);
|
||||
|
@ -839,7 +860,7 @@ int MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx)
|
|||
/* mark&release old frames */
|
||||
if (s->pict_type != FF_B_TYPE && s->last_picture_ptr && s->last_picture_ptr != s->next_picture_ptr && s->last_picture_ptr->data[0]) {
|
||||
if(s->out_format != FMT_H264 || s->codec_id == CODEC_ID_SVQ3){
|
||||
avctx->release_buffer(avctx, (AVFrame*)s->last_picture_ptr);
|
||||
free_frame_buffer(s, s->last_picture_ptr);
|
||||
|
||||
/* release forgotten pictures */
|
||||
/* if(mpeg124/h263) */
|
||||
|
@ -847,7 +868,7 @@ int MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx)
|
|||
for(i=0; i<MAX_PICTURE_COUNT; i++){
|
||||
if(s->picture[i].data[0] && &s->picture[i] != s->next_picture_ptr && s->picture[i].reference){
|
||||
av_log(avctx, AV_LOG_ERROR, "releasing zombie picture\n");
|
||||
avctx->release_buffer(avctx, (AVFrame*)&s->picture[i]);
|
||||
free_frame_buffer(s, &s->picture[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -858,7 +879,7 @@ alloc:
|
|||
/* release non reference frames */
|
||||
for(i=0; i<MAX_PICTURE_COUNT; i++){
|
||||
if(s->picture[i].data[0] && !s->picture[i].reference /*&& s->picture[i].type!=FF_BUFFER_TYPE_SHARED*/){
|
||||
s->avctx->release_buffer(s->avctx, (AVFrame*)&s->picture[i]);
|
||||
free_frame_buffer(s, &s->picture[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -996,7 +1017,7 @@ void MPV_frame_end(MpegEncContext *s)
|
|||
/* release non-reference frames */
|
||||
for(i=0; i<MAX_PICTURE_COUNT; i++){
|
||||
if(s->picture[i].data[0] && !s->picture[i].reference /*&& s->picture[i].type!=FF_BUFFER_TYPE_SHARED*/){
|
||||
s->avctx->release_buffer(s->avctx, (AVFrame*)&s->picture[i]);
|
||||
free_frame_buffer(s, &s->picture[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2068,7 +2089,7 @@ void ff_mpeg_flush(AVCodecContext *avctx){
|
|||
for(i=0; i<MAX_PICTURE_COUNT; i++){
|
||||
if(s->picture[i].data[0] && ( s->picture[i].type == FF_BUFFER_TYPE_INTERNAL
|
||||
|| s->picture[i].type == FF_BUFFER_TYPE_USER))
|
||||
avctx->release_buffer(avctx, (AVFrame*)&s->picture[i]);
|
||||
free_frame_buffer(s, &s->picture[i]);
|
||||
}
|
||||
s->current_picture_ptr = s->last_picture_ptr = s->next_picture_ptr = NULL;
|
||||
|
||||
|
|
Loading…
Reference in New Issue