mirror of
https://github.com/mpv-player/mpv.git
synced 2024-09-20 12:02:23 +02:00
vo: make draw_image and vo_queue_image transfer image ownership
Basically a cosmetic change. This is probably more intuitive.
This commit is contained in:
parent
84eebc6e4e
commit
90cd5aa8c8
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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.
|
||||
*/
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
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, vc->lastimg->pts, OSD_DRAW_SUB_ONLY,
|
||||
vc->lastimg);
|
||||
}
|
||||
|
||||
done:
|
||||
talloc_free(mpi);
|
||||
}
|
||||
|
||||
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,
|
||||
vc->lastimg);
|
||||
}
|
||||
pthread_mutex_unlock(&vo->encode_lavc_ctx->lock);
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user