void mp_get_src_dst_rects(struct mp_log *log, struct mp_vo_opts *opts, int vo_caps, struct mp_image_params *video, int window_w, int window_h, double monitor_par, struct mp_rect *out_src, struct mp_rect *out_dst, struct mp_osd_res *out_osd) { int src_w = video->w; int src_h = video->h; int src_dw, src_dh; mp_image_params_get_dsize(video, &src_dw, &src_dh); if (video->rotate % 180 == 90 && (vo_caps & VO_CAP_ROTATE90)) { MPSWAP(int, src_w, src_h); MPSWAP(int, src_dw, src_dh); } window_w = MPMAX(1, window_w); window_h = MPMAX(1, window_h); struct mp_rect dst = {0, 0, window_w, window_h}; struct mp_rect src = {0, 0, src_w, src_h}; struct mp_osd_res osd = { .w = window_w, .h = window_h, .display_par = monitor_par, }; if (opts->keepaspect) { int scaled_width, scaled_height; aspect_calc_panscan(log, opts, src_w, src_h, src_dw, src_dh, window_w, window_h, monitor_par, &scaled_width, &scaled_height); src_dst_split_scaling(src_w, window_w, scaled_width, opts->unscaled, opts->zoom, opts->align_x, opts->pan_x, &src.x0, &src.x1, &dst.x0, &dst.x1, &osd.ml, &osd.mr); src_dst_split_scaling(src_h, window_h, scaled_height, opts->unscaled, opts->zoom, opts->align_y, opts->pan_y, &src.y0, &src.y1, &dst.y0, &dst.y1, &osd.mt, &osd.mb); } *out_src = src; *out_dst = dst; *out_osd = osd; int sw = src.x1 - src.x0, sh = src.y1 - src.y0; int dw = dst.x1 - dst.x0, dh = dst.y1 - dst.y0; mp_verbose(log, "Window size: %dx%d\n", window_w, window_h); mp_verbose(log, "Video source: %dx%d (%d:%d)\n", video->w, video->h, video->p_w, video->p_h); mp_verbose(log, "Video display: (%d, %d) %dx%d -> (%d, %d) %dx%d\n", src.x0, src.y0, sw, sh, dst.x0, dst.y0, dw, dh); mp_verbose(log, "Video scale: %f/%f\n", (double)dw / sw, (double)dh / sh); mp_verbose(log, "OSD borders: l=%d t=%d r=%d b=%d\n", osd.ml, osd.mt, osd.mr, osd.mb); mp_verbose(log, "Video borders: l=%d t=%d r=%d b=%d\n", dst.x0, dst.y0, window_w - dst.x1, window_h - dst.y1); }
/** * Calculate the appropriate source and destination rectangle to * get a correctly scaled picture, including pan-scan. * Can be extended to take future cropping support into account. * * \param crop specifies the cropping border size in the left, right, top and bottom members, may be NULL * \param borders the border values as e.g. EOSD (ASS) and properly placed DVD highlight support requires, * may be NULL and only left and top are currently valid. */ void calc_src_dst_rects(int src_width, int src_height, struct vo_rect *src, struct vo_rect *dst, struct vo_rect *borders, const struct vo_rect *crop) { static const struct vo_rect no_crop = {0, 0, 0, 0, 0, 0}; int scaled_width = 0; int scaled_height = 0; if (!crop) crop = &no_crop; src_width -= crop->left + crop->right; src_height -= crop->top + crop->bottom; if (src_width < 2) src_width = 2; if (src_height < 2) src_height = 2; dst->left = 0; dst->right = vo_dwidth; dst->top = 0; dst->bottom = vo_dheight; src->left = 0; src->right = src_width; src->top = 0; src->bottom = src_height; if (borders) { borders->left = 0; borders->top = 0; } if (aspect_scaling()) { aspect(&scaled_width, &scaled_height, A_WINZOOM); panscan_calc_windowed(); scaled_width += vo_panscan_x; scaled_height += vo_panscan_y; if (borders) { borders->left = (vo_dwidth - scaled_width ) / 2; borders->top = (vo_dheight - scaled_height) / 2; } src_dst_split_scaling(src_width, vo_dwidth, scaled_width, &src->left, &src->right, &dst->left, &dst->right); src_dst_split_scaling(src_height, vo_dheight, scaled_height, &src->top, &src->bottom, &dst->top, &dst->bottom); } src->left += crop->left; src->right += crop->left; src->top += crop->top; src->bottom += crop->top; src->width = src->right - src->left; src->height = src->bottom - src->top; dst->width = dst->right - dst->left; dst->height = dst->bottom - dst->top; }
struct vo *init_best_video_out(struct MPOpts *opts, struct vo_x11_state *x11, struct mp_fifo *key_fifo, struct input_ctx *input_ctx) { char **vo_list = opts->video_driver_list; int i; struct vo *vo = talloc_ptrtype(NULL, vo); struct vo initial_values = { .opts = opts, .x11 = x11, .key_fifo = key_fifo, .input_ctx = input_ctx, .event_fd = -1, .registered_fd = -1, }; // first try the preferred drivers, with their optional subdevice param: if (vo_list && vo_list[0]) while (vo_list[0][0]) { char *name = strdup(vo_list[0]); vo_subdevice = strchr(name,':'); if (!strcmp(name, "pgm")) mp_tmsg(MSGT_CPLAYER, MSGL_ERR, "The pgm video output driver has been replaced by -vo pnm:pgmyuv.\n"); if (!strcmp(name, "md5")) mp_tmsg(MSGT_CPLAYER, MSGL_ERR, "The md5 video output driver has been replaced by -vo md5sum.\n"); if (vo_subdevice) { vo_subdevice[0] = 0; ++vo_subdevice; } for (i = 0; video_out_drivers[i]; i++) { const struct vo_driver *video_driver = video_out_drivers[i]; const vo_info_t *info = video_driver->info; if (!strcmp(info->short_name, name)) { // name matches, try it *vo = initial_values; vo->driver = video_driver; if (!vo_preinit(vo, vo_subdevice)) { free(name); return vo; // success! } talloc_free_children(vo); } } // continue... free(name); ++vo_list; if (!(vo_list[0])) return NULL; // do NOT fallback to others } // now try the rest... vo_subdevice = NULL; for (i = 0; video_out_drivers[i]; i++) { const struct vo_driver *video_driver = video_out_drivers[i]; *vo = initial_values; vo->driver = video_driver; if (!vo_preinit(vo, vo_subdevice)) return vo; // success! talloc_free_children(vo); } free(vo); return NULL; } static int event_fd_callback(void *ctx, int fd) { struct vo *vo = ctx; vo_check_events(vo); return MP_INPUT_NOTHING; } int vo_config(struct vo *vo, uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format) { struct MPOpts *opts = vo->opts; panscan_init(vo); aspect_save_orig(vo, width, height); aspect_save_prescale(vo, d_width, d_height); if (vo_control(vo, VOCTRL_UPDATE_SCREENINFO, NULL) == VO_TRUE) { aspect(vo, &d_width, &d_height, A_NOZOOM); vo->dx = (int)(opts->vo_screenwidth - d_width) / 2; vo->dy = (int)(opts->vo_screenheight - d_height) / 2; geometry(&vo->dx, &vo->dy, &d_width, &d_height, opts->vo_screenwidth, opts->vo_screenheight); geometry_xy_changed |= xinerama_screen >= 0; vo->dx += xinerama_x; vo->dy += xinerama_y; vo->dwidth = d_width; vo->dheight = d_height; } int ret = vo->driver->config(vo, width, height, d_width, d_height, flags, title, format); vo->config_ok = (ret == 0); vo->config_count += vo->config_ok; if (vo->registered_fd == -1 && vo->event_fd != -1 && vo->config_ok) { mp_input_add_key_fd(vo->input_ctx, vo->event_fd, 1, event_fd_callback, NULL, vo); vo->registered_fd = vo->event_fd; } return ret; } /** * \brief lookup an integer in a table, table must have 0 as the last key * \param key key to search for * \result translation corresponding to key or "to" value of last mapping * if not found. */ int lookup_keymap_table(const struct mp_keymap *map, int key) { while (map->from && map->from != key) map++; return map->to; } /** * \brief helper function for the kind of panscan-scaling that needs a source * and destination rectangle like Direct3D and VDPAU */ static void src_dst_split_scaling(int src_size, int dst_size, int scaled_src_size, int *src_start, int *src_end, int *dst_start, int *dst_end) { if (scaled_src_size > dst_size) { int border = src_size * (scaled_src_size - dst_size) / scaled_src_size; // round to a multiple of 2, this is at least needed for vo_direct3d and ATI cards border = (border / 2 + 1) & ~1; *src_start = border; *src_end = src_size - border; *dst_start = 0; *dst_end = dst_size; } else { *src_start = 0; *src_end = src_size; *dst_start = (dst_size - scaled_src_size) / 2; *dst_end = *dst_start + scaled_src_size; } } /** * Calculate the appropriate source and destination rectangle to * get a correctly scaled picture, including pan-scan. * Can be extended to take future cropping support into account. * * \param crop specifies the cropping border size in the left, right, top and bottom members, may be NULL * \param borders the border values as e.g. EOSD (ASS) and properly placed DVD highlight support requires, * may be NULL and only left and top are currently valid. */ void calc_src_dst_rects(struct vo *vo, int src_width, int src_height, struct vo_rect *src, struct vo_rect *dst, struct vo_rect *borders, const struct vo_rect *crop) { static const struct vo_rect no_crop = {0, 0, 0, 0, 0, 0}; int scaled_width = 0; int scaled_height = 0; if (!crop) crop = &no_crop; src_width -= crop->left + crop->right; src_height -= crop->top + crop->bottom; if (src_width < 2) src_width = 2; if (src_height < 2) src_height = 2; dst->left = 0; dst->right = vo->dwidth; dst->top = 0; dst->bottom = vo->dheight; src->left = 0; src->right = src_width; src->top = 0; src->bottom = src_height; if (borders) { borders->left = 0; borders->top = 0; } if (aspect_scaling()) { aspect(vo, &scaled_width, &scaled_height, A_WINZOOM); panscan_calc_windowed(vo); scaled_width += vo->panscan_x; scaled_height += vo->panscan_y; if (borders) { borders->left = (vo->dwidth - scaled_width ) / 2; borders->top = (vo->dheight - scaled_height) / 2; } src_dst_split_scaling(src_width, vo->dwidth, scaled_width, &src->left, &src->right, &dst->left, &dst->right); src_dst_split_scaling(src_height, vo->dheight, scaled_height, &src->top, &src->bottom, &dst->top, &dst->bottom); } src->left += crop->left; src->right += crop->left; src->top += crop->top; src->bottom += crop->top; src->width = src->right - src->left; src->height = src->bottom - src->top; dst->width = dst->right - dst->left; dst->height = dst->bottom - dst->top; } /** * Generates a mouse movement message if those are enable and sends it * to the "main" MPlayer. * * \param posx new x position of mouse * \param posy new y position of mouse */ void vo_mouse_movement(struct vo *vo, int posx, int posy) { char cmd_str[40]; if (!enable_mouse_movements) return; snprintf(cmd_str, sizeof(cmd_str), "set_mouse_pos %i %i", posx, posy); mp_input_queue_cmd(vo->input_ctx, mp_input_parse_cmd(cmd_str)); }