Commit 3ab77000 authored by Janne Grunau's avatar Janne Grunau

mpegvideo: claim ownership of referenced pictures

Under certain conditions pictures could be released before they were
returned with frame-threading. Broken mv computation in the upcoming
rv34 frame-threading patch was caused by this.

To prevent contexts from running out of available pictures the loop
releasing "unused" pictures has to be run for B frames too.
parent 17ce5291
...@@ -1170,25 +1170,26 @@ int MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx) ...@@ -1170,25 +1170,26 @@ int MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx)
s->codec_id == CODEC_ID_SVQ3); s->codec_id == CODEC_ID_SVQ3);
/* mark & release old frames */ /* mark & release old frames */
if (s->pict_type != AV_PICTURE_TYPE_B && s->last_picture_ptr && if (s->out_format != FMT_H264 || s->codec_id == CODEC_ID_SVQ3) {
s->last_picture_ptr != s->next_picture_ptr && if (s->pict_type != AV_PICTURE_TYPE_B && s->last_picture_ptr &&
s->last_picture_ptr->f.data[0]) { s->last_picture_ptr != s->next_picture_ptr &&
if (s->out_format != FMT_H264 || s->codec_id == CODEC_ID_SVQ3) { s->last_picture_ptr->f.data[0]) {
if (s->last_picture_ptr->owner2 == s) if (s->last_picture_ptr->owner2 == s)
free_frame_buffer(s, s->last_picture_ptr); free_frame_buffer(s, s->last_picture_ptr);
}
/* release forgotten pictures */ /* release forgotten pictures */
/* if (mpeg124/h263) */ /* if (mpeg124/h263) */
if (!s->encoding) { if (!s->encoding) {
for (i = 0; i < s->picture_count; i++) { for (i = 0; i < s->picture_count; i++) {
if (s->picture[i].owner2 == s && s->picture[i].f.data[0] && if (s->picture[i].owner2 == s && s->picture[i].f.data[0] &&
&s->picture[i] != s->next_picture_ptr && &s->picture[i] != s->last_picture_ptr &&
s->picture[i].f.reference) { &s->picture[i] != s->next_picture_ptr &&
if (!(avctx->active_thread_type & FF_THREAD_FRAME)) s->picture[i].f.reference) {
av_log(avctx, AV_LOG_ERROR, if (!(avctx->active_thread_type & FF_THREAD_FRAME))
"releasing zombie picture\n"); av_log(avctx, AV_LOG_ERROR,
free_frame_buffer(s, &s->picture[i]); "releasing zombie picture\n");
} free_frame_buffer(s, &s->picture[i]);
} }
} }
} }
...@@ -1295,6 +1296,14 @@ int MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx) ...@@ -1295,6 +1296,14 @@ int MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx)
if (s->next_picture_ptr) if (s->next_picture_ptr)
ff_copy_picture(&s->next_picture, s->next_picture_ptr); ff_copy_picture(&s->next_picture, s->next_picture_ptr);
if (HAVE_THREADS && (avctx->active_thread_type & FF_THREAD_FRAME) &&
(s->out_format != FMT_H264 || s->codec_id == CODEC_ID_SVQ3)) {
if (s->next_picture_ptr)
s->next_picture_ptr->owner2 = s;
if (s->last_picture_ptr)
s->last_picture_ptr->owner2 = s;
}
assert(s->pict_type == AV_PICTURE_TYPE_I || (s->last_picture_ptr && assert(s->pict_type == AV_PICTURE_TYPE_I || (s->last_picture_ptr &&
s->last_picture_ptr->f.data[0])); s->last_picture_ptr->f.data[0]));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment