From 90cd5aa8c8950406b335dfb34c01b0fdae833da9 Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 17 Jun 2014 23:05:50 +0200 Subject: vo: make draw_image and vo_queue_image transfer image ownership Basically a cosmetic change. This is probably more intuitive. --- player/video.c | 1 - video/out/gl_video.c | 5 +++-- video/out/vo.c | 5 ++--- video/out/vo.h | 3 +-- video/out/vo_caca.c | 1 + video/out/vo_corevideo.c | 1 + video/out/vo_direct3d.c | 7 +++++-- video/out/vo_image.c | 4 +--- video/out/vo_lavc.c | 27 +++++++++++++++------------ video/out/vo_null.c | 1 + video/out/vo_opengl_old.c | 2 ++ video/out/vo_sdl.c | 4 +++- video/out/vo_vaapi.c | 4 +++- video/out/vo_vdpau.c | 3 ++- video/out/vo_wayland.c | 6 +++++- video/out/vo_x11.c | 5 ++++- video/out/vo_xv.c | 5 ++++- 17 files changed, 53 insertions(+), 31 deletions(-) diff --git a/player/video.c b/player/video.c index e0aeaadf9e..59484088d6 100644 --- a/player/video.c +++ b/player/video.c @@ -503,7 +503,6 @@ static int video_output_image(struct MPContext *mpctx, double endpts, struct mp_image *img = vf_read_output_frame(vf); if (img) { vo_queue_image(vo, img); - talloc_free(img); return 1; } diff --git a/video/out/gl_video.c b/video/out/gl_video.c index b7a597654e..832f39cfe0 100644 --- a/video/out/gl_video.c +++ b/video/out/gl_video.c @@ -1726,8 +1726,8 @@ void gl_video_upload_image(struct gl_video *p, struct mp_image *mpi) p->osd_pts = mpi->pts; if (p->hwdec_active) { - mp_image_setrefp(&vimg->hwimage, mpi); - p->have_image = !!vimg->hwimage; + vimg->hwimage = mpi; + p->have_image = true; return; } @@ -1765,6 +1765,7 @@ void gl_video_upload_image(struct gl_video *p, struct mp_image *mpi) gl->BindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); p->have_image = true; + talloc_free(mpi); } struct mp_image *gl_video_download_image(struct gl_video *p) diff --git a/video/out/vo.c b/video/out/vo.c index 1af050f050..b41f281aad 100644 --- a/video/out/vo.c +++ b/video/out/vo.c @@ -287,7 +287,6 @@ void vo_queue_image(struct vo *vo, struct mp_image *mpi) if (!vo->config_ok) return; assert(mp_image_params_equals(vo->params, &mpi->params)); - mpi = mp_image_new_ref(mpi); if (vo->driver->filter_image && mpi) mpi = vo->driver->filter_image(vo, mpi); if (!mpi) { @@ -333,7 +332,6 @@ static void shift_queue(struct vo *vo) { if (!vo->num_video_queue) return; - talloc_free(vo->video_queue[0]); vo->num_video_queue--; for (int n = 0; n < vo->num_video_queue; n++) vo->video_queue[n] = vo->video_queue[n + 1]; @@ -342,8 +340,9 @@ static void shift_queue(struct vo *vo) void vo_new_frame_imminent(struct vo *vo) { assert(vo->num_video_queue > 0); - vo->driver->draw_image(vo, vo->video_queue[0]); + struct mp_image *img = vo->video_queue[0]; shift_queue(vo); + vo->driver->draw_image(vo, img); vo->hasframe = true; } diff --git a/video/out/vo.h b/video/out/vo.h index 3d10171ed2..c07c071d44 100644 --- a/video/out/vo.h +++ b/video/out/vo.h @@ -194,8 +194,7 @@ struct vo_driver { /* * Render the given frame to the VO's backbuffer. This operation will be * followed by a draw_osd and a flip_page[_timed] call. - * mpi belongs to the caller; if the VO needs it longer, it has to create - * a new reference to mpi. + * mpi belongs to the VO; the VO must free it eventually. * * This also should draw the OSD. */ diff --git a/video/out/vo_caca.c b/video/out/vo_caca.c index 6cd0187ef4..00b9e23123 100644 --- a/video/out/vo_caca.c +++ b/video/out/vo_caca.c @@ -115,6 +115,7 @@ static void draw_image(struct vo *vo, mp_image_t *mpi) memcpy_pic(priv->dither_buffer, mpi->planes[0], priv->image_width * depth, priv->image_height, priv->image_width * depth, mpi->stride[0]); caca_dither_bitmap(priv->canvas, 0, 0, priv->screen_w, priv->screen_h, priv->dither, priv->dither_buffer); + talloc_free(mpi); } static void flip_page(struct vo *vo) diff --git a/video/out/vo_corevideo.c b/video/out/vo_corevideo.c index 423fbcc6cb..4bd67aaec5 100644 --- a/video/out/vo_corevideo.c +++ b/video/out/vo_corevideo.c @@ -197,6 +197,7 @@ static void draw_image(struct vo *vo, struct mp_image *mpi) p->vo_pts = mpi->pts; p->fns.prepare_texture(vo, mpi); do_render(vo); + talloc_free(mpi); } static void uninit(struct vo *vo) diff --git a/video/out/vo_direct3d.c b/video/out/vo_direct3d.c index c65620f1d2..927730d517 100644 --- a/video/out/vo_direct3d.c +++ b/video/out/vo_direct3d.c @@ -1397,11 +1397,11 @@ static void draw_image(struct vo *vo, mp_image_t *mpi) { d3d_priv *priv = vo->priv; if (!priv->d3d_device) - return; + goto done; struct mp_image buffer; if (!get_video_buffer(priv, &buffer)) - return; + goto done; mp_image_copy(&buffer, mpi); @@ -1417,6 +1417,9 @@ static void draw_image(struct vo *vo, mp_image_t *mpi) priv->osd_pts = mpi->pts; d3d_draw_frame(priv); + +done: + talloc_free(mpi); } static mp_image_t *get_screenshot(d3d_priv *priv) diff --git a/video/out/vo_image.c b/video/out/vo_image.c index db4337b97e..bec5ea9fd0 100644 --- a/video/out/vo_image.c +++ b/video/out/vo_image.c @@ -76,9 +76,7 @@ static void draw_image(struct vo *vo, mp_image_t *mpi) { struct priv *p = vo->priv; - mp_image_setrefp(&p->current, mpi); - if (!p->current) - return; + p->current = mpi; struct mp_osd_res dim = osd_res_from_image_params(vo->params); osd_draw_on_image(vo->osd, dim, mpi->pts, OSD_DRAW_SUB_ONLY, p->current); diff --git a/video/out/vo_lavc.c b/video/out/vo_lavc.c index a387cd6457..da327b61ad 100644 --- a/video/out/vo_lavc.c +++ b/video/out/vo_lavc.c @@ -291,10 +291,10 @@ static void draw_image_unlocked(struct vo *vo, mp_image_t *mpi) double pts = mpi ? mpi->pts : MP_NOPTS_VALUE; if (!vc) - return; + goto done; if (!encode_lavc_start(ectx)) { MP_WARN(vo, "NOTE: skipped initial video frame (probably because audio is not there yet)\n"); - return; + goto done; } if (pts == MP_NOPTS_VALUE) { if (mpi) @@ -467,9 +467,9 @@ static void draw_image_unlocked(struct vo *vo, mp_image_t *mpi) if (vc->lastframeipts != AV_NOPTS_VALUE && vc->lastdisplaycount != 1) MP_INFO(vo, "Frame at pts %d got displayed %d times\n", (int) vc->lastframeipts, vc->lastdisplaycount); - mp_image_setrefp(&vc->lastimg, mpi); - if (!vc->lastimg) - MP_ERR(vo, "Out of memory\n"); + talloc_free(vc->lastimg); + vc->lastimg = mpi; + mpi = NULL; vc->lastimg_wants_osd = true; vc->lastframeipts = vc->lastipts = frameipts; @@ -484,19 +484,22 @@ static void draw_image_unlocked(struct vo *vo, mp_image_t *mpi) vc->lastimg_wants_osd = false; } } -} -static void draw_image(struct vo *vo, mp_image_t *mpi) -{ - struct priv *vc = vo->priv; - pthread_mutex_lock(&vo->encode_lavc_ctx->lock); - draw_image_unlocked(vo, mpi); if (vc->lastimg && vc->lastimg_wants_osd && vo->params) { struct mp_osd_res dim = osd_res_from_image_params(vo->params); - osd_draw_on_image(vo->osd, dim, mpi->pts, OSD_DRAW_SUB_ONLY, + osd_draw_on_image(vo->osd, dim, vc->lastimg->pts, OSD_DRAW_SUB_ONLY, vc->lastimg); } + +done: + talloc_free(mpi); +} + +static void draw_image(struct vo *vo, mp_image_t *mpi) +{ + pthread_mutex_lock(&vo->encode_lavc_ctx->lock); + draw_image_unlocked(vo, mpi); pthread_mutex_unlock(&vo->encode_lavc_ctx->lock); } diff --git a/video/out/vo_null.c b/video/out/vo_null.c index 8d8d95d065..2259e50c48 100644 --- a/video/out/vo_null.c +++ b/video/out/vo_null.c @@ -32,6 +32,7 @@ static void draw_image(struct vo *vo, mp_image_t *mpi) { + talloc_free(mpi); } static void flip_page(struct vo *vo) diff --git a/video/out/vo_opengl_old.c b/video/out/vo_opengl_old.c index 16da97cc35..d9c7e8baed 100644 --- a/video/out/vo_opengl_old.c +++ b/video/out/vo_opengl_old.c @@ -2003,6 +2003,8 @@ static void draw_image(struct vo *vo, mp_image_t *mpi) } do_render(vo); + + talloc_free(mpi); } static mp_image_t *get_screenshot(struct vo *vo) diff --git a/video/out/vo_sdl.c b/video/out/vo_sdl.c index 21b99dcf81..40d70950f3 100644 --- a/video/out/vo_sdl.c +++ b/video/out/vo_sdl.c @@ -853,6 +853,7 @@ static void draw_image(struct vo *vo, mp_image_t *mpi) vc->osd_pts = mpi->pts; if (SDL_LockTexture(vc->tex, NULL, &pixels, &pitch)) { MP_ERR(vo, "SDL_LockTexture failed\n"); + talloc_free(mpi); return; } @@ -880,7 +881,8 @@ static void draw_image(struct vo *vo, mp_image_t *mpi) SDL_UnlockTexture(vc->tex); - mp_image_setrefp(&vc->ssmpi, mpi); + talloc_free(vc->ssmpi); + vc->ssmpi = mpi; } SDL_Rect src, dst; diff --git a/video/out/vo_vaapi.c b/video/out/vo_vaapi.c index c1c34370fd..caf383c3f4 100644 --- a/video/out/vo_vaapi.c +++ b/video/out/vo_vaapi.c @@ -280,13 +280,15 @@ static void draw_image(struct vo *vo, struct mp_image *mpi) struct mp_image *dst = p->swdec_surfaces[p->output_surface]; if (!dst || va_surface_upload(dst, mpi) < 0) { MP_WARN(vo, "Could not upload surface.\n"); + talloc_free(mpi); return; } mp_image_copy_attributes(dst, mpi); mpi = dst; } - mp_image_setrefp(&p->output_surfaces[p->output_surface], mpi); + talloc_free(p->output_surfaces[p->output_surface]); + p->output_surfaces[p->output_surface] = mpi; draw_osd(vo); } diff --git a/video/out/vo_vdpau.c b/video/out/vo_vdpau.c index 9e5807e320..56a52d613f 100644 --- a/video/out/vo_vdpau.c +++ b/video/out/vo_vdpau.c @@ -847,7 +847,8 @@ static void draw_image(struct vo *vo, struct mp_image *mpi) { struct vdpctx *vc = vo->priv; - mp_image_setrefp(&vc->current_image, mpi); + talloc_free(vc->current_image); + vc->current_image = mpi; if (status_ok(vo)) video_to_output_surface(vo); diff --git a/video/out/vo_wayland.c b/video/out/vo_wayland.c index f41c75f114..be51ec55de 100644 --- a/video/out/vo_wayland.c +++ b/video/out/vo_wayland.c @@ -658,6 +658,7 @@ static void draw_image(struct vo *vo, mp_image_t *mpi) if (!buf) { MP_VERBOSE(p->wl, "can't draw, back buffer is busy\n"); + talloc_free(mpi); return; } @@ -678,7 +679,10 @@ static void draw_image(struct vo *vo, mp_image_t *mpi) struct mp_image img = buffer_get_mp_image(p, &p->video_bufpool, buf); mp_sws_scale(p->sws, &img, &src); - mp_image_setrefp(&p->original_image, mpi); + if (mpi != p->original_image) { + talloc_free(p->original_image); + p->original_image = mpi; + } buffer_finalise_back(buf); draw_osd(vo); diff --git a/video/out/vo_x11.c b/video/out/vo_x11.c index ab188bee6f..53a4fb03f7 100644 --- a/video/out/vo_x11.c +++ b/video/out/vo_x11.c @@ -483,7 +483,10 @@ static void draw_image(struct vo *vo, mp_image_t *mpi) osd_draw_on_image(vo->osd, p->osd, mpi ? mpi->pts : 0, 0, &img); - mp_image_setrefp(&p->original_image, mpi); + if (mpi != p->original_image) { + talloc_free(p->original_image); + p->original_image = mpi; + } } static int redraw_frame(struct vo *vo) diff --git a/video/out/vo_xv.c b/video/out/vo_xv.c index 870c3a1082..3e139b68b2 100644 --- a/video/out/vo_xv.c +++ b/video/out/vo_xv.c @@ -672,7 +672,10 @@ static void draw_image(struct vo *vo, mp_image_t *mpi) struct mp_osd_res res = osd_res_from_image_params(vo->params); osd_draw_on_image(vo->osd, res, mpi ? mpi->pts : 0, 0, &xv_buffer); - mp_image_setrefp(&ctx->original_image, mpi); + if (mpi != ctx->original_image) { + talloc_free(ctx->original_image); + ctx->original_image = mpi; + } } static int redraw_frame(struct vo *vo) -- cgit v1.2.3