mirror of https://github.com/mpv-player/mpv
video/out: don't access aspdat in VOs
vo->aspdat is basically an outdated version of vo->params, plus some weirdness. Get rid of it, which will allow further cleanups and which will make multithreading easier (less state to care about). Also, simplify some VO code by using mp_image_set_attributes() instead of caring about display size, colorspace, etc. manually. Add the function osd_res_from_image_params(), which is often needed in the case OSD renders into an image.
This commit is contained in:
parent
302e8ff464
commit
4de73fd5c1
15
sub/osd.c
15
sub/osd.c
|
@ -386,6 +386,21 @@ void osd_draw_on_image_p(struct osd_state *osd, struct mp_osd_res res,
|
|||
&draw_on_image, &closure);
|
||||
}
|
||||
|
||||
// Setup the OSD resolution to render into an image with the given parameters.
|
||||
// The interesting part about this is that OSD has to compensate the aspect
|
||||
// ratio if the image does not have a 1:1 pixel aspect ratio.
|
||||
struct mp_osd_res osd_res_from_image_params(const struct mp_image_params *p)
|
||||
{
|
||||
double sar = (double)p->w / p->h;
|
||||
double dar = (double)p->d_w / p->d_h;
|
||||
|
||||
return (struct mp_osd_res) {
|
||||
.w = p->w,
|
||||
.h = p->h,
|
||||
.display_par = sar / dar,
|
||||
};
|
||||
}
|
||||
|
||||
void osd_changed(struct osd_state *osd, int new_value)
|
||||
{
|
||||
pthread_mutex_lock(&osd->lock);
|
||||
|
|
|
@ -200,6 +200,9 @@ void osd_draw_on_image_p(struct osd_state *osd, struct mp_osd_res res,
|
|||
double video_pts, int draw_flags,
|
||||
struct mp_image_pool *pool, struct mp_image *dest);
|
||||
|
||||
struct mp_image_params;
|
||||
struct mp_osd_res osd_res_from_image_params(const struct mp_image_params *p);
|
||||
|
||||
void osd_object_get_scale_factor(struct osd_state *osd, int obj,
|
||||
double *sw, double *sh);
|
||||
|
||||
|
|
|
@ -279,7 +279,7 @@ static int get_image_fmt(struct vo *vo, CVPixelBufferRef pbuf)
|
|||
static mp_image_t *get_screenshot(struct vo *vo, CVPixelBufferRef pbuf)
|
||||
{
|
||||
int img_fmt = get_image_fmt(vo, pbuf);
|
||||
if (img_fmt < 0) return NULL;
|
||||
if (img_fmt < 0 || !vo->params) return NULL;
|
||||
|
||||
struct priv *p = vo->priv;
|
||||
CVPixelBufferLockBaseAddress(pbuf, 0);
|
||||
|
@ -295,8 +295,7 @@ static mp_image_t *get_screenshot(struct vo *vo, CVPixelBufferRef pbuf)
|
|||
img.stride[0] = stride;
|
||||
|
||||
struct mp_image *image = mp_image_new_copy(&img);
|
||||
mp_image_set_display_size(image, vo->aspdat.prew, vo->aspdat.preh);
|
||||
mp_image_set_colorspace_details(image, &p->colorspace);
|
||||
mp_image_set_attributes(image, vo->params);
|
||||
CVPixelBufferUnlockBaseAddress(pbuf, 0);
|
||||
|
||||
return image;
|
||||
|
|
|
@ -1432,15 +1432,15 @@ static mp_image_t *get_screenshot(d3d_priv *priv)
|
|||
if (!priv->have_image)
|
||||
return NULL;
|
||||
|
||||
if (!priv->vo->params)
|
||||
return NULL;
|
||||
|
||||
struct mp_image buffer;
|
||||
if (!get_video_buffer(priv, &buffer))
|
||||
return NULL;
|
||||
|
||||
struct mp_image *image = mp_image_new_copy(&buffer);
|
||||
mp_image_set_display_size(image, priv->vo->aspdat.prew,
|
||||
priv->vo->aspdat.preh);
|
||||
|
||||
mp_image_set_colorspace_details(image, &priv->colorspace);
|
||||
mp_image_set_attributes(image, priv->vo->params);
|
||||
|
||||
d3d_unlock_video_objects(priv);
|
||||
return image;
|
||||
|
|
|
@ -87,16 +87,7 @@ static void draw_osd(struct vo *vo, struct osd_state *osd)
|
|||
{
|
||||
struct priv *p = vo->priv;
|
||||
|
||||
struct aspect_data asp = vo->aspdat;
|
||||
double sar = (double)asp.orgw / asp.orgh;
|
||||
double dar = (double)asp.prew / asp.preh;
|
||||
|
||||
struct mp_osd_res dim = {
|
||||
.w = asp.orgw,
|
||||
.h = asp.orgh,
|
||||
.display_par = sar / dar,
|
||||
};
|
||||
|
||||
struct mp_osd_res dim = osd_res_from_image_params(vo->params);
|
||||
osd_draw_on_image(osd, dim, osd_get_vo_pts(osd), OSD_DRAW_SUB_ONLY, p->current);
|
||||
}
|
||||
|
||||
|
|
|
@ -487,16 +487,8 @@ static void draw_osd(struct vo *vo, struct osd_state *osd)
|
|||
{
|
||||
struct priv *vc = vo->priv;
|
||||
|
||||
if (vc->lastimg && vc->lastimg_wants_osd) {
|
||||
struct aspect_data asp = vo->aspdat;
|
||||
double sar = (double)asp.orgw / asp.orgh;
|
||||
double dar = (double)asp.prew / asp.preh;
|
||||
|
||||
struct mp_osd_res dim = {
|
||||
.w = asp.orgw,
|
||||
.h = asp.orgh,
|
||||
.display_par = sar / dar,
|
||||
};
|
||||
if (vc->lastimg && vc->lastimg_wants_osd && vo->params) {
|
||||
struct mp_osd_res dim = osd_res_from_image_params(vo->params);
|
||||
|
||||
mp_image_set_colorspace_details(vc->lastimg, &vc->colorspace);
|
||||
|
||||
|
|
|
@ -1458,11 +1458,7 @@ static void draw_osd(struct vo *vo, struct osd_state *osd)
|
|||
struct mp_osd_res res = p->osd_res;
|
||||
|
||||
if (p->scaled_osd) {
|
||||
res = (struct mp_osd_res) {
|
||||
.w = p->image_width,
|
||||
.h = p->image_height,
|
||||
.display_par = 1.0 / vo->aspdat.par,
|
||||
};
|
||||
res = osd_res_from_image_params(vo->params);
|
||||
gl->MatrixMode(GL_MODELVIEW);
|
||||
gl->PushMatrix();
|
||||
// Setup image space -> screen space (assumes osd_res in screen space)
|
||||
|
@ -2009,6 +2005,9 @@ static mp_image_t *get_screenshot(struct vo *vo)
|
|||
struct gl_priv *p = vo->priv;
|
||||
GL *gl = p->gl;
|
||||
|
||||
if (!vo->params)
|
||||
return NULL;
|
||||
|
||||
mp_image_t *image = mp_image_alloc(p->image_format, p->texture_width,
|
||||
p->texture_height);
|
||||
|
||||
|
@ -2025,9 +2024,7 @@ static mp_image_t *get_screenshot(struct vo *vo)
|
|||
gl->ActiveTexture(GL_TEXTURE0);
|
||||
}
|
||||
mp_image_set_size(image, p->image_width, p->image_height);
|
||||
mp_image_set_display_size(image, vo->aspdat.prew, vo->aspdat.preh);
|
||||
|
||||
mp_image_set_colorspace_details(image, &p->colorspace);
|
||||
mp_image_set_attributes(image, vo->params);
|
||||
|
||||
return image;
|
||||
}
|
||||
|
|
|
@ -420,11 +420,7 @@ static void draw_osd(struct vo *vo, struct osd_state *osd)
|
|||
if (!p->osd_format.fourcc)
|
||||
return;
|
||||
|
||||
struct mp_osd_res vid_res = {
|
||||
.w = p->image_params.w,
|
||||
.h = p->image_params.h,
|
||||
.display_par = 1.0 / vo->aspdat.par,
|
||||
};
|
||||
struct mp_osd_res vid_res = osd_res_from_image_params(vo->params);
|
||||
|
||||
struct mp_osd_res *res;
|
||||
if (p->osd_screen) {
|
||||
|
|
|
@ -1239,6 +1239,9 @@ static struct mp_image *get_screenshot(struct vo *vo)
|
|||
VdpStatus vdp_st;
|
||||
struct vdp_functions *vdp = vc->vdp;
|
||||
|
||||
if (!vo->params)
|
||||
return NULL;
|
||||
|
||||
if (vc->screenshot_surface == VDP_INVALID_HANDLE) {
|
||||
vdp_st = vdp->output_surface_create(vc->vdp_device,
|
||||
OUTPUT_RGBA_FORMAT,
|
||||
|
@ -1253,7 +1256,7 @@ static struct mp_image *get_screenshot(struct vo *vo)
|
|||
struct mp_image *image = read_output_surface(vo, vc->screenshot_surface,
|
||||
vc->vid_width, vc->vid_height);
|
||||
|
||||
mp_image_set_display_size(image, vo->aspdat.prew, vo->aspdat.preh);
|
||||
mp_image_set_display_size(image, vo->params->d_w, vo->params->d_h);
|
||||
|
||||
return image;
|
||||
}
|
||||
|
|
|
@ -616,12 +616,7 @@ static void draw_osd(struct vo *vo, struct osd_state *osd)
|
|||
|
||||
struct mp_image img = get_xv_buffer(vo, ctx->current_buf);
|
||||
|
||||
struct mp_osd_res res = {
|
||||
.w = ctx->image_width,
|
||||
.h = ctx->image_height,
|
||||
.display_par = 1.0 / vo->aspdat.par,
|
||||
};
|
||||
|
||||
struct mp_osd_res res = osd_res_from_image_params(vo->params);
|
||||
osd_draw_on_image(osd, res, osd_get_vo_pts(osd), 0, &img);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue