1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-25 00:02:13 +00:00

mp_image: simplify mp_image_steal_data()

Why was this so complex.
This commit is contained in:
wm4 2016-04-15 15:11:08 +02:00
parent bbaedfd0c5
commit e6cdfdfa74

View File

@ -164,20 +164,12 @@ void mp_image_steal_data(struct mp_image *dst, struct mp_image *src)
assert(dst->imgfmt == src->imgfmt && dst->w == src->w && dst->h == src->h); assert(dst->imgfmt == src->imgfmt && dst->w == src->w && dst->h == src->h);
assert(dst->bufs[0] && src->bufs[0]); assert(dst->bufs[0] && src->bufs[0]);
for (int p = 0; p < MP_MAX_PLANES; p++) { mp_image_destructor(dst); // unref old
dst->planes[p] = src->planes[p]; talloc_free_children(dst);
dst->stride[p] = src->stride[p];
}
mp_image_copy_attributes(dst, src);
for (int p = 0; p < MP_MAX_PLANES; p++) { *dst = *src;
av_buffer_unref(&dst->bufs[p]);
dst->bufs[p] = src->bufs[p]; *src = (struct mp_image){0};
src->bufs[p] = NULL;
}
av_buffer_unref(&dst->hwctx);
dst->hwctx = src->hwctx;
src->hwctx = NULL;
talloc_free(src); talloc_free(src);
} }
@ -752,14 +744,12 @@ struct AVFrame *mp_image_to_av_frame_and_unref(struct mp_image *img)
return NULL; return NULL;
} }
mp_image_copy_fields_to_av_frame(frame, new_ref); mp_image_copy_fields_to_av_frame(frame, new_ref);
for (int p = 0; p < MP_MAX_PLANES; p++) { for (int p = 0; p < MP_MAX_PLANES; p++)
frame->buf[p] = new_ref->bufs[p]; frame->buf[p] = new_ref->bufs[p];
new_ref->bufs[p] = NULL;
}
#if HAVE_AVUTIL_HAS_HWCONTEXT #if HAVE_AVUTIL_HAS_HWCONTEXT
frame->hw_frames_ctx = new_ref->hwctx; frame->hw_frames_ctx = new_ref->hwctx;
#endif #endif
new_ref->hwctx = NULL; *new_ref = (struct mp_image){0};
talloc_free(new_ref); talloc_free(new_ref);
return frame; return frame;
} }