video/out: make draw_image mandatory, remove VOCTRL_DRAW_IMAGE

Remove VOCTRL_DRAW_IMAGE and always set vo_driver.draw_image in VOs.
Make draw_image mandatory: change some VOs (like vo_x11) to support it,
and remove the image-to-slices fallback in vf_vo.

Remove vo_driver.is_new. This member indicated whether draw_image is
supported unconditionally, which is now always the case.

draw_image_pts is a hack until the video filter chain is changed to
include the PTS as field in mp_image. Then vo_vdpau and vo_lavc will
be changed to use draw_image.
This commit is contained in:
wm4 2012-11-04 15:56:04 +01:00
parent 97032f1b58
commit 191bcbd1f2
15 changed files with 62 additions and 93 deletions

View File

@ -135,18 +135,7 @@ static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
{
if (!video_out->config_ok)
return 0;
// first check, maybe the vo/vf plugin implements draw_image using mpi:
if (vo_draw_image(video_out, mpi, pts) >= 0)
return 1;
// nope, fallback to old draw_frame/draw_slice:
if (!(mpi->flags & (MP_IMGFLAG_DIRECT | MP_IMGFLAG_DRAW_CALLBACK))) {
// blit frame:
if (vf->default_caps & VFCAP_ACCEPT_STRIDE)
vo_draw_slice(video_out, mpi->planes, mpi->stride, mpi->w, mpi->h,
0, 0);
// else: out of luck
}
return 1;
return vo_draw_image(video_out, mpi, pts);
}
static void start_slice(struct vf_instance *vf, mp_image_t *mpi)

View File

@ -159,6 +159,15 @@ int vo_control(struct vo *vo, uint32_t request, void *data)
return vo->driver->control(vo, request, data);
}
static void draw_image_pts(struct vo *vo, struct mp_image *mpi, double pts)
{
if (vo->driver->draw_image_pts) {
vo->driver->draw_image_pts(vo, mpi, pts);
} else {
vo->driver->draw_image(vo, mpi);
}
}
// Return -1 if driver appears not to support a draw_image interface,
// 0 otherwise (whether the driver actually drew something or not).
int vo_draw_image(struct vo *vo, struct mp_image *mpi, double pts)
@ -166,18 +175,12 @@ int vo_draw_image(struct vo *vo, struct mp_image *mpi, double pts)
if (!vo->config_ok)
return 0;
if (vo->driver->buffer_frames) {
vo->driver->draw_image(vo, mpi, pts);
draw_image_pts(vo, mpi, pts);
return 0;
}
vo->frame_loaded = true;
vo->next_pts = pts;
// Guaranteed to support at least DRAW_IMAGE later
if (vo->driver->is_new) {
vo->waiting_mpi = mpi;
return 0;
}
if (vo_control(vo, VOCTRL_DRAW_IMAGE, mpi) == VO_NOTIMPL)
return -1;
vo->waiting_mpi = mpi;
return 0;
}
@ -217,12 +220,10 @@ int vo_draw_slice(struct vo *vo, uint8_t *src[], int stride[], int w, int h, int
void vo_new_frame_imminent(struct vo *vo)
{
if (!vo->driver->is_new)
return;
if (vo->driver->buffer_frames)
vo_control(vo, VOCTRL_NEWFRAME, NULL);
else {
vo_control(vo, VOCTRL_DRAW_IMAGE, vo->waiting_mpi);
draw_image_pts(vo, vo->waiting_mpi, vo->next_pts);
vo->waiting_mpi = NULL;
}
}

View File

@ -48,7 +48,6 @@ enum mp_voctrl {
VOCTRL_RESUME,
/* libmpcodecs direct rendering */
VOCTRL_GET_IMAGE,
VOCTRL_DRAW_IMAGE,
VOCTRL_GET_PANSCAN,
VOCTRL_SET_PANSCAN,
VOCTRL_SET_EQUALIZER, // struct voctrl_set_equalizer_args
@ -144,8 +143,6 @@ struct osd_state;
struct mp_image;
struct vo_driver {
// Driver uses new API
bool is_new;
// Driver buffers or adds (deinterlace) frames and will keep track
// of pts values itself
bool buffer_frames;
@ -176,7 +173,8 @@ struct vo_driver {
*/
int (*control)(struct vo *vo, uint32_t request, void *data);
void (*draw_image)(struct vo *vo, struct mp_image *mpi, double pts);
void (*draw_image)(struct vo *vo, struct mp_image *mpi);
void (*draw_image_pts)(struct vo *vo, struct mp_image *mpi, double pts);
/*
* Get extra frames from the VO, such as those added by VDPAU

View File

@ -164,12 +164,11 @@ static int config(struct vo *vo, uint32_t width, uint32_t height,
return resize();
}
static uint32_t draw_image(struct vo *vo, mp_image_t *mpi)
static void draw_image(struct vo *vo, mp_image_t *mpi)
{
assert(mpi->stride[0] == image_width * 3);
caca_dither_bitmap(canvas, 0, 0, screen_w, screen_h, dither,
mpi->planes[0]);
return true;
}
static int draw_slice(struct vo *vo, uint8_t *src[], int stride[], int w, int h,
@ -369,15 +368,12 @@ static int control(struct vo *vo, uint32_t request, void *data)
switch (request) {
case VOCTRL_QUERY_FORMAT:
return query_format(*((uint32_t *)data));
case VOCTRL_DRAW_IMAGE:
return draw_image(vo, data);
default:
return VO_NOTIMPL;
}
}
const struct vo_driver video_out_caca = {
.is_new = false,
.info = &(const vo_info_t) {
"libcaca",
"caca",
@ -387,6 +383,7 @@ const struct vo_driver video_out_caca = {
.preinit = preinit,
.config = config,
.control = control,
.draw_image = draw_image,
.draw_slice = draw_slice,
.draw_osd = draw_osd,
.flip_page = flip_page,

View File

@ -219,7 +219,7 @@ static void flip_page(struct vo *vo)
p->mpglctx->gl->Clear(GL_COLOR_BUFFER_BIT);
}
static uint32_t draw_image(struct vo *vo, mp_image_t *mpi)
static void draw_image(struct vo *vo, mp_image_t *mpi)
{
struct priv *p = vo->priv;
CVReturn error;
@ -240,7 +240,6 @@ static uint32_t draw_image(struct vo *vo, mp_image_t *mpi)
}
do_render(vo);
return VO_TRUE;
}
static int query_format(struct vo *vo, uint32_t format)
@ -386,8 +385,6 @@ static int control(struct vo *vo, uint32_t request, void *data)
{
struct priv *p = vo->priv;
switch (request) {
case VOCTRL_DRAW_IMAGE:
return draw_image(vo, data);
case VOCTRL_QUERY_FORMAT:
return query_format(vo, *(uint32_t*)data);
case VOCTRL_ONTOP:
@ -438,7 +435,6 @@ static int control(struct vo *vo, uint32_t request, void *data)
}
const struct vo_driver video_out_corevideo = {
.is_new = true,
.info = &(const vo_info_t) {
"Mac OS X Core Video",
"corevideo",
@ -448,6 +444,7 @@ const struct vo_driver video_out_corevideo = {
.preinit = preinit,
.config = config,
.control = control,
.draw_image = draw_image,
.draw_osd = draw_osd,
.flip_page = flip_page,
.check_events = check_events,

View File

@ -868,7 +868,7 @@ static void uninit_d3d(d3d_priv *priv)
priv->d3d_handle = NULL;
}
static uint32_t d3d_upload_and_render_frame_texture(d3d_priv *priv,
static void d3d_upload_and_render_frame_texture(d3d_priv *priv,
mp_image_t *mpi)
{
if (!(mpi->flags & MP_IMGFLAG_DRAW_CALLBACK))
@ -880,20 +880,19 @@ static uint32_t d3d_upload_and_render_frame_texture(d3d_priv *priv,
d3dtex_update(priv, &priv->planes[n].texture);
}
return d3d_draw_frame(priv);
d3d_draw_frame(priv);
}
/** @brief Render a frame on the screen.
* @param mpi mpi structure with the decoded frame inside
* @return VO_TRUE on success, VO_ERROR on failure
*/
static uint32_t d3d_upload_and_render_frame(d3d_priv *priv, mp_image_t *mpi)
static void draw_image(struct vo *vo, mp_image_t *mpi)
{
d3d_priv *priv = vo->priv;
if (!priv->d3d_device)
return VO_TRUE;
return;
if (priv->use_textures)
return d3d_upload_and_render_frame_texture(priv, mpi);
if (priv->use_textures) {
d3d_upload_and_render_frame_texture(priv, mpi);
return;
}
if (mpi->flags & MP_IMGFLAG_DRAW_CALLBACK)
goto skip_upload;
@ -908,7 +907,7 @@ static uint32_t d3d_upload_and_render_frame(d3d_priv *priv, mp_image_t *mpi)
if (FAILED(IDirect3DSurface9_LockRect(priv->d3d_surface,
&priv->locked_rect, NULL, 0))) {
mp_msg(MSGT_VO, MSGL_ERR, "<vo_direct3d>Surface lock failed.\n");
return VO_ERROR;
return;
}
}
@ -918,7 +917,7 @@ static uint32_t d3d_upload_and_render_frame(d3d_priv *priv, mp_image_t *mpi)
skip_upload:
d3d_unlock_video_objects(priv);
return d3d_draw_frame(priv);
d3d_draw_frame(priv);
}
static uint32_t d3d_draw_frame(d3d_priv *priv)
@ -1447,8 +1446,6 @@ static int control(struct vo *vo, uint32_t request, void *data)
switch (request) {
case VOCTRL_QUERY_FORMAT:
return query_format(priv, *(uint32_t*) data);
case VOCTRL_DRAW_IMAGE:
return d3d_upload_and_render_frame(priv, data);
case VOCTRL_FULLSCREEN:
vo_w32_fullscreen(vo);
resize_d3d(priv);
@ -2062,7 +2059,6 @@ static void draw_osd(struct vo *vo, struct osd_state *osd)
#define AUTHOR "Georgi Petrov (gogothebee) <gogothebee@gmail.com> and others"
const struct vo_driver video_out_direct3d = {
.is_new = true,
.info = &(const vo_info_t) {
"Direct3D 9 Renderer",
"direct3d",
@ -2072,6 +2068,7 @@ const struct vo_driver video_out_direct3d = {
.preinit = preinit_standard,
.config = config,
.control = control,
.draw_image = draw_image,
.draw_slice = draw_slice,
.draw_osd = draw_osd,
.flip_page = flip_page,
@ -2080,7 +2077,6 @@ const struct vo_driver video_out_direct3d = {
};
const struct vo_driver video_out_direct3d_shaders = {
.is_new = true,
.info = &(const vo_info_t) {
"Direct3D 9 Renderer (using shaders for YUV conversion)",
"direct3d_shaders",
@ -2090,6 +2086,7 @@ const struct vo_driver video_out_direct3d_shaders = {
.preinit = preinit_shaders,
.config = config,
.control = control,
.draw_image = draw_image,
.draw_slice = draw_slice,
.draw_osd = draw_osd,
.flip_page = flip_page,

View File

@ -96,7 +96,7 @@ static void flip_page(struct vo *vo)
{
}
static uint32_t draw_image(struct vo *vo, mp_image_t *mpi)
static void draw_image(struct vo *vo, mp_image_t *mpi)
{
struct priv *p = vo->priv;
@ -118,8 +118,6 @@ static uint32_t draw_image(struct vo *vo, mp_image_t *mpi)
talloc_free(t);
(p->frame)++;
return VO_TRUE;
}
static int query_format(struct vo *vo, uint32_t fmt)
@ -150,8 +148,6 @@ static int control(struct vo *vo, uint32_t request, void *data)
switch (request) {
case VOCTRL_QUERY_FORMAT:
return query_format(vo, *(uint32_t *)data);
case VOCTRL_DRAW_IMAGE:
return draw_image(vo, data);
case VOCTRL_SET_YUV_COLORSPACE:
p->colorspace = *(struct mp_csp_details *)data;
return true;
@ -170,7 +166,6 @@ static int control(struct vo *vo, uint32_t request, void *data)
const struct vo_driver video_out_image =
{
.is_new = true,
.info = &(const vo_info_t) {
"Write video frames to image files",
"image",
@ -189,6 +184,7 @@ const struct vo_driver video_out_image =
.preinit = preinit,
.config = config,
.control = control,
.draw_image = draw_image,
.draw_osd = draw_osd,
.flip_page = flip_page,
.check_events = check_events,

View File

@ -514,9 +514,6 @@ static int control(struct vo *vo, uint32_t request, void *data)
switch (request) {
case VOCTRL_QUERY_FORMAT:
return query_format(vo, *((uint32_t *)data));
case VOCTRL_DRAW_IMAGE:
draw_image(vo, (mp_image_t *)data, vo->next_pts);
return 0;
case VOCTRL_SET_YUV_COLORSPACE:
vc->colorspace = *(struct mp_csp_details *)data;
if (vc->stream) {
@ -534,7 +531,6 @@ static int control(struct vo *vo, uint32_t request, void *data)
}
const struct vo_driver video_out_lavc = {
.is_new = true,
.buffer_frames = false,
.info = &(const struct vo_info_s){
"video encoding using libavcodec",
@ -547,6 +543,7 @@ const struct vo_driver video_out_lavc = {
.control = control,
.uninit = uninit,
.check_events = check_events,
.draw_image_pts = draw_image,
.draw_osd = draw_osd,
.flip_page_timed = flip_page_timed,
};

View File

@ -36,6 +36,10 @@ static int draw_slice(struct vo *vo, uint8_t *image[], int stride[],
return 0;
}
static void draw_image(struct vo *vo, mp_image_t *mpi)
{
}
static void draw_osd(struct vo *vo, struct osd_state *osd)
{
}
@ -85,7 +89,6 @@ static int control(struct vo *vo, uint32_t request, void *data)
}
const struct vo_driver video_out_null = {
.is_new = false,
.info = &(const vo_info_t) {
"Null video output",
"null",
@ -95,6 +98,7 @@ const struct vo_driver video_out_null = {
.preinit = preinit,
.config = config,
.control = control,
.draw_image = draw_image,
.draw_slice = draw_slice,
.draw_osd = draw_osd,
.flip_page = flip_page,

View File

@ -1298,8 +1298,9 @@ static uint32_t get_image(struct vo *vo, mp_image_t *mpi)
return VO_TRUE;
}
static uint32_t draw_image(struct gl_priv *p, mp_image_t *mpi)
static void draw_image(struct vo *vo, mp_image_t *mpi)
{
struct gl_priv *p = vo->priv;
GL *gl = p->gl;
int n;
@ -1348,7 +1349,6 @@ static uint32_t draw_image(struct gl_priv *p, mp_image_t *mpi)
gl->BindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
skip_upload:
do_render(p);
return VO_TRUE;
}
static mp_image_t *get_screenshot(struct gl_priv *p)
@ -1737,8 +1737,6 @@ static int control(struct vo *vo, uint32_t request, void *data)
switch (request) {
case VOCTRL_QUERY_FORMAT:
return query_format(*(uint32_t *)data);
case VOCTRL_DRAW_IMAGE:
return draw_image(p, data);
case VOCTRL_ONTOP:
if (!p->glctx->ontop)
break;
@ -2252,7 +2250,6 @@ err_out:
}
const struct vo_driver video_out_opengl = {
.is_new = true,
.info = &(const vo_info_t) {
"Extended OpenGL Renderer",
"opengl",
@ -2262,6 +2259,7 @@ const struct vo_driver video_out_opengl = {
.preinit = preinit,
.config = config,
.control = control,
.draw_image = draw_image,
.draw_slice = draw_slice,
.draw_osd = draw_osd,
.flip_page = flip_page,
@ -2270,7 +2268,6 @@ const struct vo_driver video_out_opengl = {
};
const struct vo_driver video_out_opengl_hq = {
.is_new = true,
.info = &(const vo_info_t) {
"Extended OpenGL Renderer (high quality rendering preset)",
"opengl-hq",
@ -2280,6 +2277,7 @@ const struct vo_driver video_out_opengl_hq = {
.preinit = preinit,
.config = config,
.control = control,
.draw_image = draw_image,
.draw_slice = draw_slice,
.draw_osd = draw_osd,
.flip_page = flip_page,

View File

@ -709,7 +709,7 @@ static void clear_border(struct vo *vo, uint8_t *dst, int start, int stride,
memset(dst, value, stride * bottom_border);
}
static uint32_t draw_image(struct vo *vo, mp_image_t *mpi)
static void draw_image(struct vo *vo, mp_image_t *mpi)
{
struct gl_priv *p = vo->priv;
GL *gl = p->gl;
@ -809,7 +809,6 @@ static uint32_t draw_image(struct vo *vo, mp_image_t *mpi)
}
skip_upload:
do_render(vo);
return VO_TRUE;
}
static mp_image_t *get_screenshot(struct vo *vo)
@ -1084,8 +1083,6 @@ static int control(struct vo *vo, uint32_t request, void *data)
switch (request) {
case VOCTRL_QUERY_FORMAT:
return query_format(vo, *(uint32_t *)data);
case VOCTRL_DRAW_IMAGE:
return draw_image(vo, data);
case VOCTRL_ONTOP:
if (!p->glctx->ontop)
break;
@ -1166,7 +1163,6 @@ static int control(struct vo *vo, uint32_t request, void *data)
}
const struct vo_driver video_out_opengl_old = {
.is_new = true,
.info = &(const vo_info_t) {
"OpenGL",
"opengl-old",
@ -1176,6 +1172,7 @@ const struct vo_driver video_out_opengl_old = {
.preinit = preinit,
.config = config,
.control = control,
.draw_image = draw_image,
.draw_slice = draw_slice,
.draw_osd = draw_osd,
.flip_page = flip_page,

View File

@ -825,7 +825,7 @@ static int query_format(struct vo *vo, uint32_t format)
return 0;
}
static void draw_image(struct vo *vo, mp_image_t *mpi, double pts)
static void draw_image(struct vo *vo, mp_image_t *mpi)
{
struct priv *vc = vo->priv;
void *pixels;
@ -997,8 +997,6 @@ static int control(struct vo *vo, uint32_t request, void *data)
switch (request) {
case VOCTRL_QUERY_FORMAT:
return query_format(vo, *((uint32_t *)data));
case VOCTRL_DRAW_IMAGE:
draw_image(vo, (mp_image_t *)data, vo->next_pts);
return 0;
case VOCTRL_FULLSCREEN:
set_fullscreen(vo, !vo_fs);
@ -1008,7 +1006,7 @@ static int control(struct vo *vo, uint32_t request, void *data)
case VOCTRL_RESUME:
return vc->int_pause = 0;
case VOCTRL_REDRAW_FRAME:
draw_image(vo, NULL, MP_NOPTS_VALUE);
draw_image(vo, NULL);
return 1;
case VOCTRL_UPDATE_SCREENINFO:
update_screeninfo(vo);
@ -1042,7 +1040,6 @@ static int control(struct vo *vo, uint32_t request, void *data)
#define OPT_BASE_STRUCT struct priv
const struct vo_driver video_out_sdl = {
.is_new = true,
.info = &(const vo_info_t) {
"SDL 2.0 Renderer",
"sdl",
@ -1060,6 +1057,7 @@ const struct vo_driver video_out_sdl = {
.preinit = preinit,
.config = config,
.control = control,
.draw_image = draw_image,
.uninit = uninit,
.check_events = check_events,
.draw_osd = draw_osd,

View File

@ -1608,8 +1608,6 @@ static int control(struct vo *vo, uint32_t request, void *data)
return query_format(*(uint32_t *)data);
case VOCTRL_GET_IMAGE:
return get_image(vo, data);
case VOCTRL_DRAW_IMAGE:
abort(); // draw_image() should get called directly
case VOCTRL_BORDER:
vo_x11_border(vo);
checked_resize(vo);
@ -1680,7 +1678,6 @@ static int control(struct vo *vo, uint32_t request, void *data)
#define OPT_BASE_STRUCT struct vdpctx
const struct vo_driver video_out_vdpau = {
.is_new = true,
.buffer_frames = true,
.info = &(const struct vo_info_s){
"VDPAU with X11",
@ -1691,7 +1688,7 @@ const struct vo_driver video_out_vdpau = {
.preinit = preinit,
.config = config,
.control = control,
.draw_image = draw_image,
.draw_image_pts = draw_image,
.get_buffered_frame = set_next_frame_info,
.draw_slice = draw_slice,
.draw_osd = draw_osd,

View File

@ -523,6 +523,11 @@ static int draw_slice(struct vo *vo, uint8_t *src[], int stride[], int w, int h,
return 0;
}
static void draw_image(struct vo *vo, mp_image_t *mpi)
{
draw_slice(vo, mpi->planes, mpi->stride, mpi->w, mpi->h, 0, 0);
}
static int query_format(struct vo *vo, uint32_t format)
{
mp_msg(MSGT_VO, MSGL_DBG2,
@ -627,7 +632,6 @@ static int control(struct vo *vo, uint32_t request, void *data)
}
const struct vo_driver video_out_x11 = {
.is_new = false,
.info = &(const vo_info_t) {
"X11 ( XImage/Shm )",
"x11",
@ -647,6 +651,7 @@ const struct vo_driver video_out_x11 = {
.preinit = preinit,
.config = config,
.control = control,
.draw_image = draw_image,
.draw_slice = draw_slice,
.draw_osd = draw_osd,
.flip_page = flip_page,

View File

@ -441,7 +441,7 @@ static mp_image_t *get_screenshot(struct vo *vo)
return res;
}
static uint32_t draw_image(struct vo *vo, mp_image_t *mpi)
static void draw_image(struct vo *vo, mp_image_t *mpi)
{
struct xvctx *ctx = vo->priv;
@ -455,12 +455,12 @@ static uint32_t draw_image(struct vo *vo, mp_image_t *mpi)
ctx->xvimage[ctx->current_buf]->offsets[0], mpi->planes[0],
mpi->w * (mpi->bpp / 8), mpi->h,
ctx->xvimage[ctx->current_buf]->pitches[0], mpi->stride[0]);
else
return false;
else {
mp_msg(MSGT_VO, MSGL_ERR, "[VO_XV] Couldn't draw image.\n");
return;
}
mp_draw_sub_backup_reset(ctx->osd_backup);
return true;
}
static int query_format(struct xvctx *ctx, uint32_t format)
@ -642,8 +642,6 @@ static int control(struct vo *vo, uint32_t request, void *data)
return (ctx->is_paused = 0);
case VOCTRL_QUERY_FORMAT:
return query_format(ctx, *((uint32_t *) data));
case VOCTRL_DRAW_IMAGE:
return draw_image(vo, data);
case VOCTRL_GET_PANSCAN:
return VO_TRUE;
case VOCTRL_FULLSCREEN:
@ -691,11 +689,11 @@ static int control(struct vo *vo, uint32_t request, void *data)
}
const struct vo_driver video_out_xv = {
.is_new = 1,
.info = &info,
.preinit = preinit,
.config = config,
.control = control,
.draw_image = draw_image,
.draw_slice = draw_slice,
.draw_osd = draw_osd,
.flip_page = flip_page,