[vlc-commits] vout: dispatch window events to the display events handler
Rémi Denis-Courmont
git at videolan.org
Thu Oct 16 19:26:02 CEST 2014
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Oct 12 12:38:30 2014 +0300| [787a60ad75896b8bee1c24eb1e4708a8df017971] | committer: Rémi Denis-Courmont
vout: dispatch window events to the display events handler
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=787a60ad75896b8bee1c24eb1e4708a8df017971
---
src/Makefile.am | 1 +
src/video_output/display.c | 32 +++++++++----
src/video_output/video_output.c | 6 +--
src/video_output/window.c | 100 +++++++++++++++++++++++++++++++++++++++
src/video_output/window.h | 25 ++++++++++
5 files changed, 152 insertions(+), 12 deletions(-)
diff --git a/src/Makefile.am b/src/Makefile.am
index 4472271..505b69f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -412,6 +412,7 @@ SOURCES_libvlc_common = \
video_output/video_widgets.c \
video_output/vout_subpictures.c \
video_output/window.c \
+ video_output/window.h \
video_output/opengl.c \
video_output/vout_intf.c \
video_output/vout_internal.h \
diff --git a/src/video_output/display.c b/src/video_output/display.c
index cdd4b35..e428fe7 100644
--- a/src/video_output/display.c
+++ b/src/video_output/display.c
@@ -39,6 +39,7 @@
#include <libvlc.h>
#include "display.h"
+#include "window.h"
#include "event.h"
@@ -734,6 +735,7 @@ static void VoutDisplayEvent(vout_display_t *vd, int event, va_list args)
static vout_window_t *VoutDisplayNewWindow(vout_display_t *vd, const vout_window_cfg_t *cfg)
{
vout_display_owner_sys_t *osys = vd->owner.sys;
+ vout_window_t *window;
#ifdef ALLOW_DUMMY_VOUT
if (!osys->vout->p) {
@@ -742,25 +744,31 @@ static vout_window_t *VoutDisplayNewWindow(vout_display_t *vd, const vout_window
if (!var_InheritBool(osys->vout, "embedded-video"))
cfg_override.is_standalone = true;
- return vout_window_New(VLC_OBJECT(osys->vout), "$window",
- &cfg_override, NULL);
+ window = vout_display_window_New(osys->vout, &cfg_override);
}
+ else
#endif
- return vout_NewDisplayWindow(osys->vout, cfg);
+ window = vout_NewDisplayWindow(osys->vout, cfg);
+
+ if (window != NULL)
+ vout_display_window_Attach(window, vd);
+ return window;
}
static void VoutDisplayDelWindow(vout_display_t *vd, vout_window_t *window)
{
vout_display_owner_sys_t *osys = vd->owner.sys;
+ if (window != NULL)
+ vout_display_window_Detach(window);
#ifdef ALLOW_DUMMY_VOUT
if (!osys->vout->p) {
if( window)
- vout_window_Delete(window);
- return;
+ vout_display_window_Delete(window);
}
#endif
- vout_DeleteDisplayWindow(osys->vout, window);
+ else
+ vout_DeleteDisplayWindow(osys->vout, window);
}
static void VoutDisplayFitWindow(vout_display_t *vd, bool default_size)
@@ -1434,17 +1442,23 @@ struct video_splitter_owner_t {
static vout_window_t *SplitterNewWindow(vout_display_t *vd, const vout_window_cfg_t *cfg_ptr)
{
vout_display_owner_sys_t *osys = vd->owner.sys;
+ vout_window_t *window;
vout_window_cfg_t cfg = *cfg_ptr;
cfg.is_standalone = true;
- return vout_window_New(VLC_OBJECT(osys->vout), "$window", &cfg, NULL);
+ window = vout_display_window_New(osys->vout, &cfg);
+ if (window != NULL)
+ vout_display_window_Attach(window, vd);
+ return window;
}
static void SplitterDelWindow(vout_display_t *vd, vout_window_t *window)
{
- if (window != NULL)
- vout_window_Delete(window);
+ if (window != NULL) {
+ vout_display_window_Detach(window);
+ vout_display_window_Delete(window);
+ }
(void) vd;
}
diff --git a/src/video_output/video_output.c b/src/video_output/video_output.c
index 730ce88..197096b 100644
--- a/src/video_output/video_output.c
+++ b/src/video_output/video_output.c
@@ -50,6 +50,7 @@
#include "vout_internal.h"
#include "interlacing.h"
#include "display.h"
+#include "window.h"
/*****************************************************************************
* Local prototypes
@@ -173,8 +174,7 @@ static vout_thread_t *VoutCreate(vlc_object_t *object,
.height = cfg->fmt->i_visible_height,
};
- vout->p->window = vout_window_New(VLC_OBJECT(vout), "$window", &wcfg,
- NULL);
+ vout->p->window = vout_display_window_New(vout, &wcfg);
} else
vout->p->window = NULL;
@@ -642,7 +642,7 @@ vout_window_t * vout_NewDisplayWindow(vout_thread_t *vout,
void vout_DeleteDisplayWindow(vout_thread_t *vout, vout_window_t *window)
{
if (window == NULL && vout->p->window != NULL) {
- vout_window_Delete(vout->p->window);
+ vout_display_window_Delete(vout->p->window);
vout->p->window = NULL;
}
assert(vout->p->window == window);
diff --git a/src/video_output/window.c b/src/video_output/window.c
index 841e046..e906043 100644
--- a/src/video_output/window.c
+++ b/src/video_output/window.c
@@ -111,3 +111,103 @@ void vout_window_Delete(vout_window_t *window)
vlc_module_unload(w->module, vout_window_stop, window);
vlc_object_release(window);
}
+
+/* Video output display integration */
+#include <vlc_vout_display.h>
+#include "window.h"
+
+typedef struct vout_display_window
+{
+ vout_display_t *vd;
+ unsigned width;
+ unsigned height;
+
+ vlc_mutex_t lock;
+} vout_display_window_t;
+
+static void vout_display_window_ResizeNotify(vout_window_t *window,
+ unsigned width, unsigned height)
+{
+ vout_display_window_t *state = window->owner.sys;
+
+ msg_Dbg(window, "resized to %ux%u", width, height);
+ vlc_mutex_lock(&state->lock);
+ state->width = width;
+ state->height = height;
+
+ if (state->vd != NULL)
+ vout_display_SendEventDisplaySize(state->vd, width, height);
+ vlc_mutex_unlock(&state->lock);
+}
+
+/**
+ * Creates a video window, initially without any attached display.
+ */
+vout_window_t *vout_display_window_New(vout_thread_t *vout,
+ const vout_window_cfg_t *cfg)
+{
+ vout_display_window_t *state = malloc(sizeof (*state));
+ if (state == NULL)
+ return NULL;
+
+ state->vd = NULL;
+ state->width = cfg->width;
+ state->height = cfg->height;
+ vlc_mutex_init(&state->lock);
+
+ vout_window_owner_t owner = {
+ .sys = state,
+ .resized = vout_display_window_ResizeNotify,
+ };
+ vout_window_t *window;
+
+ window = vout_window_New((vlc_object_t *)vout, "$window", cfg, &owner);
+ if (window == NULL) {
+ vlc_mutex_destroy(&state->lock);
+ free(state);
+ }
+ return window;
+}
+
+/**
+ * Attaches a window to a display. Window events will be dispatched to the
+ * display until they are detached.
+ */
+void vout_display_window_Attach(vout_window_t *window, vout_display_t *vd)
+{
+ vout_display_window_t *state = window->owner.sys;
+
+ vlc_mutex_lock(&state->lock);
+ state->vd = vd;
+
+ vout_display_SendEventDisplaySize(vd, state->width, state->height);
+ vlc_mutex_unlock(&state->lock);
+}
+
+/**
+ * Detaches a window from a display. Window events will no longer be dispatched
+ * (except those that do not need a display).
+ */
+void vout_display_window_Detach(vout_window_t *window)
+{
+ vout_display_window_t *state = window->owner.sys;
+
+ vlc_mutex_lock(&state->lock);
+ state->vd = NULL;
+ vlc_mutex_unlock(&state->lock);
+}
+
+/**
+ * Destroys a video window.
+ * \note The window must be detached.
+ */
+void vout_display_window_Delete(vout_window_t *window)
+{
+ vout_display_window_t *state = window->owner.sys;
+
+ vout_window_Delete(window);
+
+ assert(state->vd == NULL);
+ vlc_mutex_destroy(&state->lock);
+ free(state);
+}
diff --git a/src/video_output/window.h b/src/video_output/window.h
new file mode 100644
index 0000000..ba8989d
--- /dev/null
+++ b/src/video_output/window.h
@@ -0,0 +1,25 @@
+/*****************************************************************************
+ * window.h: window managment for VLC video output
+ *****************************************************************************
+ * Copyright © 2014 Rémi Denis-Courmont
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+vout_window_t *vout_display_window_New(vout_thread_t *,
+ const vout_window_cfg_t *);
+void vout_display_window_Attach(vout_window_t *, vout_display_t *);
+void vout_display_window_Detach(vout_window_t *);
+void vout_display_window_Delete(vout_window_t *);
More information about the vlc-commits
mailing list