static int preinit(struct vo *vo) { XvPortID xv_p; int busy_ports = 0; unsigned int i; struct xvctx *ctx = vo->priv; int xv_adaptor = ctx->cfg_xv_adaptor; if (!vo_x11_init(vo)) return -1; if (!vo_x11_create_vo_window(vo, NULL, "xv")) goto error; struct vo_x11_state *x11 = vo->x11; /* check for Xvideo extension */ unsigned int ver, rel, req, ev, err; if (Success != XvQueryExtension(x11->display, &ver, &rel, &req, &ev, &err)) { MP_ERR(vo, "Xv not supported by this X11 version/driver\n"); goto error; } /* check for Xvideo support */ if (Success != XvQueryAdaptors(x11->display, DefaultRootWindow(x11->display), &ctx->adaptors, &ctx->ai)) { MP_ERR(vo, "XvQueryAdaptors failed.\n"); goto error; } /* check adaptors */ if (ctx->xv_port) { int port_found; for (port_found = 0, i = 0; !port_found && i < ctx->adaptors; i++) { if ((ctx->ai[i].type & XvInputMask) && (ctx->ai[i].type & XvImageMask)) { for (xv_p = ctx->ai[i].base_id; xv_p < ctx->ai[i].base_id + ctx->ai[i].num_ports; ++xv_p) { if (xv_p == ctx->xv_port) { port_found = 1; break; } } } } if (port_found) { if (XvGrabPort(x11->display, ctx->xv_port, CurrentTime)) ctx->xv_port = 0; } else { MP_WARN(vo, "Invalid port parameter, overriding with port 0.\n"); ctx->xv_port = 0; } } for (i = 0; i < ctx->adaptors && ctx->xv_port == 0; i++) { /* check if adaptor number has been specified */ if (xv_adaptor != -1 && xv_adaptor != i) continue; if ((ctx->ai[i].type & XvInputMask) && (ctx->ai[i].type & XvImageMask)) { for (xv_p = ctx->ai[i].base_id; xv_p < ctx->ai[i].base_id + ctx->ai[i].num_ports; ++xv_p) if (!XvGrabPort(x11->display, xv_p, CurrentTime)) { ctx->xv_port = xv_p; MP_VERBOSE(vo, "Using Xv Adapter #%d (%s)\n", i, ctx->ai[i].name); break; } else { MP_WARN(vo, "Could not grab port %i.\n", (int) xv_p); ++busy_ports; } } } if (!ctx->xv_port) { if (busy_ports) MP_ERR(vo, "Xvideo ports busy.\n"); else MP_ERR(vo, "No Xvideo support found.\n"); goto error; } if (!xv_init_colorkey(vo)) { goto error; // bail out, colorkey setup failed } xv_enable_vsync(vo); xv_get_max_img_dim(vo, &ctx->max_width, &ctx->max_height); ctx->fo = XvListImageFormats(x11->display, ctx->xv_port, (int *) &ctx->formats); MP_WARN(vo, "Warning: this legacy VO has bad quality and performance, " "and will in particular result in blurry OSD and subtitles. " "You should fix your graphic drivers, or not force the xv VO.\n"); return 0; error: uninit(vo); // free resources return -1; }
static void draw_osd(struct vo *vo, struct osd_state *osd) { struct xvctx *ctx = vo->priv; 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, }; osd_draw_on_image(osd, res, osd->vo_pts, 0, &img); } static void wait_for_completion(struct vo *vo, int max_outstanding) { #if HAVE_SHM struct xvctx *ctx = vo->priv; struct vo_x11_state *x11 = vo->x11; if (ctx->Shmem_Flag) { while (x11->ShmCompletionWaitCount > max_outstanding) { if (!ctx->Shm_Warned_Slow) { MP_WARN(vo, "X11 can't keep up! Waiting" " for XShm completion events...\n"); ctx->Shm_Warned_Slow = 1; } mp_sleep_us(1000); vo_x11_check_events(vo); } } #endif } static void flip_page(struct vo *vo) { struct xvctx *ctx = vo->priv; put_xvimage(vo, ctx->xvimage[ctx->current_buf]); /* remember the currently visible buffer */ ctx->current_buf = (ctx->current_buf + 1) % ctx->num_buffers; if (!ctx->Shmem_Flag) XSync(vo->x11->display, False); } static mp_image_t *get_screenshot(struct vo *vo) { struct xvctx *ctx = vo->priv; if (!ctx->original_image) return NULL; return mp_image_new_ref(ctx->original_image); } // Note: redraw_frame() can call this with NULL. static void draw_image(struct vo *vo, mp_image_t *mpi) { struct xvctx *ctx = vo->priv; wait_for_completion(vo, ctx->num_buffers - 1); struct mp_image xv_buffer = get_xv_buffer(vo, ctx->current_buf); if (mpi) { mp_image_copy(&xv_buffer, mpi); } else { mp_image_clear(&xv_buffer, 0, 0, xv_buffer.w, xv_buffer.h); } mp_image_setrefp(&ctx->original_image, mpi); } static int redraw_frame(struct vo *vo) { struct xvctx *ctx = vo->priv; draw_image(vo, ctx->original_image); return true; } static int query_format(struct vo *vo, uint32_t format) { struct xvctx *ctx = vo->priv; uint32_t i; int flag = VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW; int fourcc = find_xv_format(format); if (fourcc) { for (i = 0; i < ctx->formats; i++) { if (ctx->fo[i].id == fourcc) return flag; } } return 0; } static void uninit(struct vo *vo) { struct xvctx *ctx = vo->priv; int i; talloc_free(ctx->original_image); if (ctx->ai) XvFreeAdaptorInfo(ctx->ai); ctx->ai = NULL; if (ctx->fo) { XFree(ctx->fo); ctx->fo = NULL; } for (i = 0; i < ctx->num_buffers; i++) deallocate_xvimage(vo, i); // uninit() shouldn't get called unless initialization went past vo_init() vo_x11_uninit(vo); } static int preinit(struct vo *vo) { XvPortID xv_p; int busy_ports = 0; unsigned int i; struct xvctx *ctx = vo->priv; int xv_adaptor = ctx->cfg_xv_adaptor; if (!vo_x11_init(vo)) return -1; struct vo_x11_state *x11 = vo->x11; /* check for Xvideo extension */ unsigned int ver, rel, req, ev, err; if (Success != XvQueryExtension(x11->display, &ver, &rel, &req, &ev, &err)) { MP_ERR(vo, "Xv not supported by this X11 version/driver\n"); goto error; } /* check for Xvideo support */ if (Success != XvQueryAdaptors(x11->display, DefaultRootWindow(x11->display), &ctx->adaptors, &ctx->ai)) { MP_ERR(vo, "XvQueryAdaptors failed.\n"); goto error; } /* check adaptors */ if (ctx->xv_port) { int port_found; for (port_found = 0, i = 0; !port_found && i < ctx->adaptors; i++) { if ((ctx->ai[i].type & XvInputMask) && (ctx->ai[i].type & XvImageMask)) { for (xv_p = ctx->ai[i].base_id; xv_p < ctx->ai[i].base_id + ctx->ai[i].num_ports; ++xv_p) { if (xv_p == ctx->xv_port) { port_found = 1; break; } } } } if (port_found) { if (XvGrabPort(x11->display, ctx->xv_port, CurrentTime)) ctx->xv_port = 0; } else { MP_WARN(vo, "Invalid port parameter, overriding with port 0.\n"); ctx->xv_port = 0; } } for (i = 0; i < ctx->adaptors && ctx->xv_port == 0; i++) { /* check if adaptor number has been specified */ if (xv_adaptor != -1 && xv_adaptor != i) continue; if ((ctx->ai[i].type & XvInputMask) && (ctx->ai[i].type & XvImageMask)) { for (xv_p = ctx->ai[i].base_id; xv_p < ctx->ai[i].base_id + ctx->ai[i].num_ports; ++xv_p) if (!XvGrabPort(x11->display, xv_p, CurrentTime)) { ctx->xv_port = xv_p; MP_VERBOSE(vo, "Using Xv Adapter #%d (%s)\n", i, ctx->ai[i].name); break; } else { MP_WARN(vo, "Could not grab port %i.\n", (int) xv_p); ++busy_ports; } } } if (!ctx->xv_port) { if (busy_ports) MP_ERR(vo, "Could not find free Xvideo port - maybe another process is already\n"\ "using it. Close all video applications, and try again. If that does\n"\ "not help, see 'mpv -vo help' for other (non-xv) video out drivers.\n"); else MP_ERR(vo, "It seems there is no Xvideo support for your video card available.\n"\ "Run 'xvinfo' to verify its Xv support and read\n"\ "DOCS/HTML/en/video.html#xv!\n"\ "See 'mpv -vo help' for other (non-xv) video out drivers.\n"\ "Try -vo x11.\n"); goto error; } if (!xv_init_colorkey(vo)) { goto error; // bail out, colorkey setup failed } xv_enable_vsync(vo); xv_get_max_img_dim(vo, &ctx->max_width, &ctx->max_height); ctx->fo = XvListImageFormats(x11->display, ctx->xv_port, (int *) &ctx->formats); return 0; error: uninit(vo); // free resources return -1; }
static int preinit(struct vo *vo) { XvPortID xv_p; int busy_ports = 0; unsigned int i; struct xvctx *ctx = vo->priv; int xv_adaptor = ctx->cfg_xv_adaptor; if (!vo_x11_init(vo)) return -1; struct vo_x11_state *x11 = vo->x11; /* check for Xvideo extension */ unsigned int ver, rel, req, ev, err; if (Success != XvQueryExtension(x11->display, &ver, &rel, &req, &ev, &err)) { MP_ERR(vo, "Xv not supported by this X11 version/driver\n"); goto error; } /* check for Xvideo support */ if (Success != XvQueryAdaptors(x11->display, DefaultRootWindow(x11->display), &ctx->adaptors, &ctx->ai)) { MP_ERR(vo, "XvQueryAdaptors failed.\n"); goto error; } /* check adaptors */ if (ctx->xv_port) { int port_found; for (port_found = 0, i = 0; !port_found && i < ctx->adaptors; i++) { if ((ctx->ai[i].type & XvInputMask) && (ctx->ai[i].type & XvImageMask)) { for (xv_p = ctx->ai[i].base_id; xv_p < ctx->ai[i].base_id + ctx->ai[i].num_ports; ++xv_p) { if (xv_p == ctx->xv_port) { port_found = 1; break; } } } } if (port_found) { if (XvGrabPort(x11->display, ctx->xv_port, CurrentTime)) ctx->xv_port = 0; } else { MP_WARN(vo, "Invalid port parameter, overriding with port 0.\n"); ctx->xv_port = 0; } } for (i = 0; i < ctx->adaptors && ctx->xv_port == 0; i++) { /* check if adaptor number has been specified */ if (xv_adaptor != -1 && xv_adaptor != i) continue; if ((ctx->ai[i].type & XvInputMask) && (ctx->ai[i].type & XvImageMask)) { for (xv_p = ctx->ai[i].base_id; xv_p < ctx->ai[i].base_id + ctx->ai[i].num_ports; ++xv_p) if (!XvGrabPort(x11->display, xv_p, CurrentTime)) { ctx->xv_port = xv_p; MP_VERBOSE(vo, "Using Xv Adapter #%d (%s)\n", i, ctx->ai[i].name); break; } else { MP_WARN(vo, "Could not grab port %i.\n", (int) xv_p); ++busy_ports; } } } if (!ctx->xv_port) { if (busy_ports) MP_ERR(vo, "Could not find free Xvideo port - maybe another process is already\n"\ "using it. Close all video applications, and try again. If that does\n"\ "not help, see 'mpv -vo help' for other (non-xv) video out drivers.\n"); else MP_ERR(vo, "It seems there is no Xvideo support for your video card available.\n"\ "Run 'xvinfo' to verify its Xv support and read\n"\ "DOCS/HTML/en/video.html#xv!\n"\ "See 'mpv -vo help' for other (non-xv) video out drivers.\n"\ "Try -vo x11.\n"); goto error; } if (!xv_init_colorkey(vo)) { goto error; // bail out, colorkey setup failed } xv_enable_vsync(vo); xv_get_max_img_dim(vo, &ctx->max_width, &ctx->max_height); ctx->fo = XvListImageFormats(x11->display, ctx->xv_port, (int *) &ctx->formats); return 0; error: uninit(vo); // free resources return -1; }