summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVittorio Giovara <vittorio.giovara@gmail.com>2015-04-27 22:09:19 +0100
committerVittorio Giovara <vittorio.giovara@gmail.com>2015-05-22 15:34:39 +0100
commitd528045558825f01472e9bee873f60c98d661e53 (patch)
treef810347121f457b9d5f175e0a0e249a937da2452
parent6f54dc43cee6b2f5d183acf98b32a3cf8be4a4fc (diff)
mpegvideo: Have ff_mpeg_unref_picture use AVCodecContext directly
This skips setting the memory to 0 but allows for reuse on different contextes. Oracle did not report any unsual activity because of it.
-rw-r--r--libavcodec/mpegvideo.c60
-rw-r--r--libavcodec/mpegvideo.h2
-rw-r--r--libavcodec/mpegvideo_enc.c18
3 files changed, 38 insertions, 42 deletions
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 8311b13c08..6a8c7e0433 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -509,14 +509,14 @@ static int alloc_frame_buffer(MpegEncContext *s, Picture *pic)
s->uvlinesize != pic->f->linesize[1])) {
av_log(s->avctx, AV_LOG_ERROR,
"get_buffer() failed (stride changed)\n");
- ff_mpeg_unref_picture(s, pic);
+ ff_mpeg_unref_picture(s->avctx, pic);
return -1;
}
if (pic->f->linesize[1] != pic->f->linesize[2]) {
av_log(s->avctx, AV_LOG_ERROR,
"get_buffer() failed (uv stride mismatch)\n");
- ff_mpeg_unref_picture(s, pic);
+ ff_mpeg_unref_picture(s->avctx, pic);
return -1;
}
@@ -524,7 +524,7 @@ static int alloc_frame_buffer(MpegEncContext *s, Picture *pic)
(ret = frame_size_alloc(s, pic->f->linesize[0])) < 0) {
av_log(s->avctx, AV_LOG_ERROR,
"get_buffer() failed to allocate context scratch buffers.\n");
- ff_mpeg_unref_picture(s, pic);
+ ff_mpeg_unref_picture(s->avctx, pic);
return ret;
}
@@ -659,7 +659,7 @@ int ff_alloc_picture(MpegEncContext *s, Picture *pic, int shared)
return 0;
fail:
av_log(s->avctx, AV_LOG_ERROR, "Error allocating a picture.\n");
- ff_mpeg_unref_picture(s, pic);
+ ff_mpeg_unref_picture(s->avctx, pic);
ff_free_picture_tables(pic);
return AVERROR(ENOMEM);
}
@@ -667,17 +667,15 @@ fail:
/**
* Deallocate a picture.
*/
-void ff_mpeg_unref_picture(MpegEncContext *s, Picture *pic)
+void ff_mpeg_unref_picture(AVCodecContext *avctx, Picture *pic)
{
- int off = offsetof(Picture, mb_mean) + sizeof(pic->mb_mean);
-
pic->tf.f = pic->f;
/* WM Image / Screen codecs allocate internal buffers with different
* dimensions / colorspaces; ignore user-defined callbacks for these. */
- if (s->codec_id != AV_CODEC_ID_WMV3IMAGE &&
- s->codec_id != AV_CODEC_ID_VC1IMAGE &&
- s->codec_id != AV_CODEC_ID_MSS2)
- ff_thread_release_buffer(s->avctx, &pic->tf);
+ if (avctx->codec->id != AV_CODEC_ID_WMV3IMAGE &&
+ avctx->codec->id != AV_CODEC_ID_VC1IMAGE &&
+ avctx->codec->id != AV_CODEC_ID_MSS2)
+ ff_thread_release_buffer(avctx, &pic->tf);
else if (pic->f)
av_frame_unref(pic->f);
@@ -685,8 +683,6 @@ void ff_mpeg_unref_picture(MpegEncContext *s, Picture *pic)
if (pic->needs_realloc)
ff_free_picture_tables(pic);
-
- memset((uint8_t*)pic + off, 0, sizeof(*pic) - off);
}
static int update_picture_tables(Picture *dst, Picture *src)
@@ -765,7 +761,7 @@ int ff_mpeg_ref_picture(MpegEncContext *s, Picture *dst, Picture *src)
return 0;
fail:
- ff_mpeg_unref_picture(s, dst);
+ ff_mpeg_unref_picture(s->avctx, dst);
return ret;
}
@@ -939,7 +935,7 @@ int ff_mpeg_update_thread_context(AVCodecContext *dst,
s->picture_number = s1->picture_number;
for (i = 0; i < MAX_PICTURE_COUNT; i++) {
- ff_mpeg_unref_picture(s, &s->picture[i]);
+ ff_mpeg_unref_picture(s->avctx, &s->picture[i]);
if (s1->picture[i].f->buf[0] &&
(ret = ff_mpeg_ref_picture(s, &s->picture[i], &s1->picture[i])) < 0)
return ret;
@@ -947,7 +943,7 @@ int ff_mpeg_update_thread_context(AVCodecContext *dst,
#define UPDATE_PICTURE(pic)\
do {\
- ff_mpeg_unref_picture(s, &s->pic);\
+ ff_mpeg_unref_picture(s->avctx, &s->pic);\
if (s1->pic.f->buf[0])\
ret = ff_mpeg_ref_picture(s, &s->pic, &s1->pic);\
else\
@@ -1497,22 +1493,22 @@ void ff_mpv_common_end(MpegEncContext *s)
if (s->picture) {
for (i = 0; i < MAX_PICTURE_COUNT; i++) {
ff_free_picture_tables(&s->picture[i]);
- ff_mpeg_unref_picture(s, &s->picture[i]);
+ ff_mpeg_unref_picture(s->avctx, &s->picture[i]);
av_frame_free(&s->picture[i].f);
}
}
av_freep(&s->picture);
ff_free_picture_tables(&s->last_picture);
- ff_mpeg_unref_picture(s, &s->last_picture);
+ ff_mpeg_unref_picture(s->avctx, &s->last_picture);
av_frame_free(&s->last_picture.f);
ff_free_picture_tables(&s->current_picture);
- ff_mpeg_unref_picture(s, &s->current_picture);
+ ff_mpeg_unref_picture(s->avctx, &s->current_picture);
av_frame_free(&s->current_picture.f);
ff_free_picture_tables(&s->next_picture);
- ff_mpeg_unref_picture(s, &s->next_picture);
+ ff_mpeg_unref_picture(s->avctx, &s->next_picture);
av_frame_free(&s->next_picture.f);
ff_free_picture_tables(&s->new_picture);
- ff_mpeg_unref_picture(s, &s->new_picture);
+ ff_mpeg_unref_picture(s->avctx, &s->new_picture);
av_frame_free(&s->new_picture.f);
free_context_frame(s);
@@ -1623,7 +1619,7 @@ static void release_unused_pictures(MpegEncContext *s)
/* release non reference frames */
for (i = 0; i < MAX_PICTURE_COUNT; i++) {
if (!s->picture[i].reference)
- ff_mpeg_unref_picture(s, &s->picture[i]);
+ ff_mpeg_unref_picture(s->avctx, &s->picture[i]);
}
}
@@ -1663,7 +1659,7 @@ int ff_find_unused_picture(MpegEncContext *s, int shared)
if (s->picture[ret].needs_realloc) {
s->picture[ret].needs_realloc = 0;
ff_free_picture_tables(&s->picture[ret]);
- ff_mpeg_unref_picture(s, &s->picture[ret]);
+ ff_mpeg_unref_picture(s->avctx, &s->picture[ret]);
}
}
return ret;
@@ -1683,7 +1679,7 @@ int ff_mpv_frame_start(MpegEncContext *s, AVCodecContext *avctx)
if (s->pict_type != AV_PICTURE_TYPE_B && s->last_picture_ptr &&
s->last_picture_ptr != s->next_picture_ptr &&
s->last_picture_ptr->f->buf[0]) {
- ff_mpeg_unref_picture(s, s->last_picture_ptr);
+ ff_mpeg_unref_picture(s->avctx, s->last_picture_ptr);
}
/* release forgotten pictures */
@@ -1695,11 +1691,11 @@ int ff_mpv_frame_start(MpegEncContext *s, AVCodecContext *avctx)
if (!(avctx->active_thread_type & FF_THREAD_FRAME))
av_log(avctx, AV_LOG_ERROR,
"releasing zombie picture\n");
- ff_mpeg_unref_picture(s, &s->picture[i]);
+ ff_mpeg_unref_picture(s->avctx, &s->picture[i]);
}
}
- ff_mpeg_unref_picture(s, &s->current_picture);
+ ff_mpeg_unref_picture(s->avctx, &s->current_picture);
release_unused_pictures(s);
@@ -1824,14 +1820,14 @@ int ff_mpv_frame_start(MpegEncContext *s, AVCodecContext *avctx)
}
if (s->last_picture_ptr) {
- ff_mpeg_unref_picture(s, &s->last_picture);
+ ff_mpeg_unref_picture(s->avctx, &s->last_picture);
if (s->last_picture_ptr->f->buf[0] &&
(ret = ff_mpeg_ref_picture(s, &s->last_picture,
s->last_picture_ptr)) < 0)
return ret;
}
if (s->next_picture_ptr) {
- ff_mpeg_unref_picture(s, &s->next_picture);
+ ff_mpeg_unref_picture(s->avctx, &s->next_picture);
if (s->next_picture_ptr->f->buf[0] &&
(ret = ff_mpeg_ref_picture(s, &s->next_picture,
s->next_picture_ptr)) < 0)
@@ -2433,12 +2429,12 @@ void ff_mpeg_flush(AVCodecContext *avctx){
return;
for (i = 0; i < MAX_PICTURE_COUNT; i++)
- ff_mpeg_unref_picture(s, &s->picture[i]);
+ ff_mpeg_unref_picture(s->avctx, &s->picture[i]);
s->current_picture_ptr = s->last_picture_ptr = s->next_picture_ptr = NULL;
- ff_mpeg_unref_picture(s, &s->current_picture);
- ff_mpeg_unref_picture(s, &s->last_picture);
- ff_mpeg_unref_picture(s, &s->next_picture);
+ ff_mpeg_unref_picture(s->avctx, &s->current_picture);
+ ff_mpeg_unref_picture(s->avctx, &s->last_picture);
+ ff_mpeg_unref_picture(s->avctx, &s->next_picture);
s->mb_x= s->mb_y= 0;
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index b8f96302bb..45c8712428 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -864,7 +864,7 @@ void ff_wmv2_encode_mb(MpegEncContext * s,
int motion_x, int motion_y);
int ff_mpeg_ref_picture(MpegEncContext *s, Picture *dst, Picture *src);
-void ff_mpeg_unref_picture(MpegEncContext *s, Picture *picture);
+void ff_mpeg_unref_picture(AVCodecContext *avctx, Picture *picture);
void ff_free_picture_tables(Picture *pic);
#endif /* AVCODEC_MPEGVIDEO_H */
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index a46b685535..116f494fec 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -886,7 +886,7 @@ av_cold int ff_mpv_encode_end(AVCodecContext *avctx)
av_frame_free(&s->tmp_frames[i]);
ff_free_picture_tables(&s->new_picture);
- ff_mpeg_unref_picture(s, &s->new_picture);
+ ff_mpeg_unref_picture(s->avctx, &s->new_picture);
av_freep(&s->avctx->stats_out);
av_freep(&s->ac_stats);
@@ -1370,7 +1370,7 @@ no_output_pic:
s->reordered_input_picture[0]->f->pict_type !=
AV_PICTURE_TYPE_B ? 3 : 0;
- ff_mpeg_unref_picture(s, &s->new_picture);
+ ff_mpeg_unref_picture(s->avctx, &s->new_picture);
if ((ret = ff_mpeg_ref_picture(s, &s->new_picture, s->reordered_input_picture[0])))
return ret;
@@ -1405,14 +1405,14 @@ no_output_pic:
s->new_picture.f->data[i] += INPLACE_OFFSET;
}
}
- ff_mpeg_unref_picture(s, &s->current_picture);
+ ff_mpeg_unref_picture(s->avctx, &s->current_picture);
if ((ret = ff_mpeg_ref_picture(s, &s->current_picture,
s->current_picture_ptr)) < 0)
return ret;
s->picture_number = s->new_picture.f->display_picture_number;
} else {
- ff_mpeg_unref_picture(s, &s->new_picture);
+ ff_mpeg_unref_picture(s->avctx, &s->new_picture);
}
return 0;
}
@@ -1456,7 +1456,7 @@ static void frame_end(MpegEncContext *s)
/* release non-reference frames */
for (i = 0; i < MAX_PICTURE_COUNT; i++) {
if (!s->picture[i].reference)
- ff_mpeg_unref_picture(s, &s->picture[i]);
+ ff_mpeg_unref_picture(s->avctx, &s->picture[i]);
}
}
@@ -1493,13 +1493,13 @@ static int frame_start(MpegEncContext *s)
if (s->pict_type != AV_PICTURE_TYPE_B && s->last_picture_ptr &&
s->last_picture_ptr != s->next_picture_ptr &&
s->last_picture_ptr->f->buf[0]) {
- ff_mpeg_unref_picture(s, s->last_picture_ptr);
+ ff_mpeg_unref_picture(s->avctx, s->last_picture_ptr);
}
s->current_picture_ptr->f->pict_type = s->pict_type;
s->current_picture_ptr->f->key_frame = s->pict_type == AV_PICTURE_TYPE_I;
- ff_mpeg_unref_picture(s, &s->current_picture);
+ ff_mpeg_unref_picture(s->avctx, &s->current_picture);
if ((ret = ff_mpeg_ref_picture(s, &s->current_picture,
s->current_picture_ptr)) < 0)
return ret;
@@ -1511,14 +1511,14 @@ static int frame_start(MpegEncContext *s)
}
if (s->last_picture_ptr) {
- ff_mpeg_unref_picture(s, &s->last_picture);
+ ff_mpeg_unref_picture(s->avctx, &s->last_picture);
if (s->last_picture_ptr->f->buf[0] &&
(ret = ff_mpeg_ref_picture(s, &s->last_picture,
s->last_picture_ptr)) < 0)
return ret;
}
if (s->next_picture_ptr) {
- ff_mpeg_unref_picture(s, &s->next_picture);
+ ff_mpeg_unref_picture(s->avctx, &s->next_picture);
if (s->next_picture_ptr->f->buf[0] &&
(ret = ff_mpeg_ref_picture(s, &s->next_picture,
s->next_picture_ptr)) < 0)