summaryrefslogtreecommitdiff
path: root/libavcodec/mpegvideo.c
diff options
context:
space:
mode:
authorGwenole Beauchesne <gbeauchesne@splitted-desktop.com>2009-03-04 08:47:29 +0000
committerGwenole Beauchesne <gbeauchesne@splitted-desktop.com>2009-03-04 08:47:29 +0000
commit34e46c44dafd32a7519382f0647b8afab88d57a7 (patch)
treeb79d0bfb7e408950458e4395c3d47edd9cdc7ab0 /libavcodec/mpegvideo.c
parent63581eb1836d928b319720143f48a9bd13d5537d (diff)
Add frame buffer allocators. aka simplify calls to
AVCodecContext.{get,release}_buffer(). Originally committed as revision 17804 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec/mpegvideo.c')
-rw-r--r--libavcodec/mpegvideo.c69
1 files changed, 45 insertions, 24 deletions
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 8dc34883e3..43f2f1ff1d 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -165,6 +165,43 @@ void ff_copy_picture(Picture *dst, Picture *src){
}
/**
+ * 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;