From 5ccca31a51f80544c84449e343c650dbc5a1216b Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 3 Aug 2012 05:55:02 +0200 Subject: [PATCH] VO: don't keep a persistent X11 connection across VOs The player kept a single persistent instance of X11-related state shared by all X-using VOs. This has no obvious benefit; even if a new VO instance initializes a new X connection that shouldn't cause noticeable overhead. Remove the shared instance and initialize X state per VO. This reduces X-specific code outside the VOs using it. --- libvo/video_out.c | 4 +--- libvo/video_out.h | 3 +-- libvo/vo_x11.c | 6 ++---- libvo/vo_xv.c | 14 +++++++------- libvo/x11_common.c | 18 +++++++++++------- mp_core.h | 1 - mplayer.c | 15 +++------------ 7 files changed, 25 insertions(+), 36 deletions(-) diff --git a/libvo/video_out.c b/libvo/video_out.c index 2dff638637..f657e0edcc 100644 --- a/libvo/video_out.c +++ b/libvo/video_out.c @@ -331,8 +331,7 @@ void list_video_out(void) mp_msg(MSGT_GLOBAL, MSGL_INFO,"\n"); } -struct vo *init_best_video_out(struct MPOpts *opts, struct vo_x11_state *x11, - struct mp_fifo *key_fifo, +struct vo *init_best_video_out(struct MPOpts *opts, struct mp_fifo *key_fifo, struct input_ctx *input_ctx) { char **vo_list = opts->video_driver_list; @@ -340,7 +339,6 @@ struct vo *init_best_video_out(struct MPOpts *opts, struct vo_x11_state *x11, 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, diff --git a/libvo/video_out.h b/libvo/video_out.h index e2f37252ab..f863791f89 100644 --- a/libvo/video_out.h +++ b/libvo/video_out.h @@ -286,8 +286,7 @@ struct vo { } aspdat; }; -struct vo *init_best_video_out(struct MPOpts *opts, struct vo_x11_state *x11, - struct mp_fifo *key_fifo, +struct vo *init_best_video_out(struct MPOpts *opts, struct mp_fifo *key_fifo, struct input_ctx *input_ctx); int vo_config(struct vo *vo, uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, diff --git a/libvo/vo_x11.c b/libvo/vo_x11.c index 9be47c9d8a..03f73debe0 100644 --- a/libvo/vo_x11.c +++ b/libvo/vo_x11.c @@ -611,10 +611,8 @@ static int query_format(uint32_t format) static void uninit(void) { - if (!myximage) - return; - - freeMyXImage(); + if (myximage) + freeMyXImage(); #ifdef CONFIG_XF86VM vo_vm_close(); diff --git a/libvo/vo_xv.c b/libvo/vo_xv.c index 5bbcfc4d0a..e737754726 100644 --- a/libvo/vo_xv.c +++ b/libvo/vo_xv.c @@ -595,9 +595,13 @@ static int preinit(struct vo *vo, const char *arg) strarg_t ck_method_arg = { 0, NULL }; struct xvctx *ctx = talloc_zero(vo, struct xvctx); vo->priv = ctx; - struct vo_x11_state *x11 = vo->x11; int xv_adaptor = -1; + if (!vo_init(vo)) + return -1; + + struct vo_x11_state *x11 = vo->x11; + const opt_t subopts[] = { /* name arg type arg var test */ @@ -611,16 +615,12 @@ static int preinit(struct vo *vo, const char *arg) x11->xv_port = 0; /* parse suboptions */ - if (subopt_parse(arg, subopts) != 0) { - return -1; - } + if (subopt_parse(arg, subopts) != 0) + goto error; /* modify colorkey settings according to the given options */ xv_setup_colorkeyhandling(vo, ck_method_arg.str, ck_src_arg.str); - if (!vo_init(vo)) - return -1; - /* check for Xvideo extension */ unsigned int ver, rel, req, ev, err; if (Success != XvQueryExtension(x11->display, &ver, &rel, &req, &ev, &err)) { diff --git a/libvo/x11_common.c b/libvo/x11_common.c index 316b820036..b41e30e07b 100644 --- a/libvo/x11_common.c +++ b/libvo/x11_common.c @@ -381,7 +381,6 @@ void update_xinerama_info(struct vo *vo) { int vo_init(struct vo *vo) { struct MPOpts *opts = vo->opts; - struct vo_x11_state *x11 = vo->x11; // int mScreen; int depth, bpp; unsigned int mask; @@ -394,15 +393,14 @@ int vo_init(struct vo *vo) XWindowAttributes attribs; char *dispName; + assert(vo->x11 == NULL); + + vo->x11 = vo_x11_init_state(); + struct vo_x11_state *x11 = vo->x11; + if (vo_rootwin) WinID = 0; // use root window - if (x11->depthonscreen) - { - saver_off(x11->display); - return 1; // already called - } - XSetErrorHandler(x11_errorhandler); #if 0 @@ -420,6 +418,8 @@ int vo_init(struct vo *vo) { mp_msg(MSGT_VO, MSGL_ERR, "vo: couldn't open the X11 display (%s)!\n", dispName); + talloc_free(x11); + vo->x11 = NULL; return 0; } x11->screen = DefaultScreen(x11->display); // screen ID @@ -522,6 +522,8 @@ int vo_init(struct vo *vo) void vo_uninit(struct vo_x11_state *x11) { + if (!x11) + return; if (!x11->display) { mp_msg(MSGT_VO, MSGL_V, @@ -763,6 +765,8 @@ void vo_x11_uninit(struct vo *vo) x11->last_video_height = 0; x11->size_changed_during_fs = false; } + vo_uninit(x11); + vo->x11 = NULL; } static int check_resize(struct vo *vo) diff --git a/mp_core.h b/mp_core.h index 60cbc7c56b..655926a31d 100644 --- a/mp_core.h +++ b/mp_core.h @@ -86,7 +86,6 @@ struct chapter { typedef struct MPContext { struct MPOpts opts; struct m_config *mconfig; - struct vo_x11_state *x11_state; struct mp_fifo *key_fifo; struct input_ctx *input; struct osd_state *osd; diff --git a/mplayer.c b/mplayer.c index e0afd4ec65..f33cc70253 100644 --- a/mplayer.c +++ b/mplayer.c @@ -690,9 +690,6 @@ void exit_player_with_rc(struct MPContext *mpctx, enum exit_reason how, int rc) #if defined(__MINGW32__) || defined(__CYGWIN__) timeEndPeriod(1); #endif -#ifdef CONFIG_X11 - vo_uninit(mpctx->x11_state); // Close the X11 connection (if any is open). -#endif current_module = "uninit_input"; mp_input_uninit(mpctx->input); @@ -2618,8 +2615,7 @@ int reinit_video_chain(struct MPContext *mpctx) //shouldn't we set dvideo->id=-2 when we fail? //if((mpctx->video_out->preinit(vo_subdevice))!=0){ - if (!(mpctx->video_out = init_best_video_out(opts, mpctx->x11_state, - mpctx->key_fifo, + if (!(mpctx->video_out = init_best_video_out(opts, mpctx->key_fifo, mpctx->input))) { mp_tmsg(MSGT_CPLAYER, MSGL_FATAL, "Error opening/initializing " "the selected video_out (-vo) device.\n"); @@ -3478,10 +3474,8 @@ static void run_playloop(struct MPContext *mpctx) vo_check_events(vo); #ifdef CONFIG_X11 - if (stop_xscreensaver) { - current_module = "stop_xscreensaver"; - xscreensaver_heartbeat(mpctx->x11_state); - } + if (stop_xscreensaver && vo->x11) + xscreensaver_heartbeat(vo->x11); #endif if (heartbeat_cmd) { static unsigned last_heartbeat; @@ -3922,9 +3916,6 @@ int main(int argc, char *argv[]) mp_msg_init(); init_libav(); -#ifdef CONFIG_X11 - mpctx->x11_state = vo_x11_init_state(); -#endif struct MPOpts *opts = &mpctx->opts; set_default_mplayer_options(opts); // Create the config context and register the options -- 2.11.4.GIT