[vlc-devel] [PATCH 13/14] vout: add support for forcing stereo 3D mode

Felix Abecassis felix.abecassis at gmail.com
Tue Sep 9 19:08:32 CEST 2014


---
 src/Makefile.am                 |   2 +
 src/video_output/stereo3d.c     | 106 ++++++++++++++++++++++++++++++++++++++++
 src/video_output/stereo3d.h     |  28 +++++++++++
 src/video_output/video_output.c |   2 +
 4 files changed, 138 insertions(+)
 create mode 100644 src/video_output/stereo3d.c
 create mode 100644 src/video_output/stereo3d.h

diff --git a/src/Makefile.am b/src/Makefile.am
index cdddc8d..12822c5 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -402,6 +402,8 @@ SOURCES_libvlc_common = \
 	video_output/snapshot.c \
 	video_output/snapshot.h \
 	video_output/statistic.h \
+	video_output/stereo3d.h \
+	video_output/stereo3d.c \
 	video_output/video_output.c \
 	video_output/video_text.c \
 	video_output/video_epg.c \
diff --git a/src/video_output/stereo3d.c b/src/video_output/stereo3d.c
new file mode 100644
index 0000000..b047cab
--- /dev/null
+++ b/src/video_output/stereo3d.c
@@ -0,0 +1,106 @@
+/*****************************************************************************
+ * stereo3d.c
+ *****************************************************************************
+ * Copyright (C) 2014 the VideoLAN team
+ *
+ * Authors: Felix Abecassis <felix.abecassis at gmail.com>
+ *
+ * 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.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+#include <assert.h>
+
+#include <vlc_common.h>
+#include <vlc_vout.h>
+
+#include "stereo3d.h"
+#include "control.h"
+#include "vout_internal.h"
+
+static int StereoRestart (vlc_object_t *obj, const char *varname,
+                          vlc_value_t oldval, vlc_value_t newval, void *data);
+
+void vout_InitStereo3DSupport(vout_thread_t *vout, video_format_t *fmt)
+{
+    var_Create(vout, "stereo3d-mode", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE | VLC_VAR_DOINHERIT);
+
+    vlc_value_t txt;
+    txt.psz_string = _("Stereo 3D mode");
+    var_Change (vout, "stereo3d-mode", VLC_VAR_SETTEXT, &txt, NULL);
+
+    const module_config_t *cfg = config_FindConfig(VLC_OBJECT(vout), "stereo3d-mode");
+    var_Change(vout, "stereo3d-mode", VLC_VAR_CLEARCHOICES, NULL, NULL);
+    if (cfg) {
+        for (int i = 0; i < cfg->list_count; ++i) {
+            vlc_value_t val = { .i_int = cfg->list.i[i] };
+            vlc_value_t text = { .psz_string = vlc_gettext(cfg->list_text[i]) };
+            var_Change(vout, "stereo3d-mode", VLC_VAR_ADDCHOICE, &val, &text);
+        }
+    }
+
+    if (fmt) {
+        if (fmt->stereo.flags & VLC_STEREO3D_SWAP_EYES)
+            var_SetInteger(vout, "stereo3d-mode", -fmt->stereo.mode);
+        else
+            var_SetInteger(vout, "stereo3d-mode", fmt->stereo.mode);
+    }
+    var_AddCallback (vout, "stereo3d-mode", StereoRestart, NULL);
+}
+
+static int StereoRestart (vlc_object_t *obj, const char *varname,
+                          vlc_value_t oldval, vlc_value_t newval, void *data)
+{
+    VLC_UNUSED(varname); VLC_UNUSED(oldval); VLC_UNUSED(data);
+
+    vout_thread_t *vout = (vout_thread_t *)obj;
+
+    video_format_t original = vout->p->filter.format;
+    video_format_t fmt = original;
+    if (newval.i_int < 0) {
+        fmt.stereo.mode = -newval.i_int;
+        fmt.stereo.flags = VLC_STEREO3D_SWAP_EYES;
+    }
+    else {
+        fmt.stereo.mode = newval.i_int;
+        fmt.stereo.flags = 0;
+    }
+
+    if (fmt.stereo.mode == original.stereo.mode) {
+        /* Only the stereo flag changed: no need to restart the vout. */
+        vout_display_t *vd = vout->p->display.vd;
+        vd->fmt.stereo.flags = fmt.stereo.flags;
+        return 0;
+    }
+
+    vout_configuration_t cfg = {
+        .vout       = vout,
+        .input      = VLC_OBJECT(vout->p->input),
+        .change_fmt = true,
+        .fmt        = &fmt,
+        .dpb_size   = vout->p->dpb_size,
+    };
+
+    vout_control_cmd_t cmd;
+    vout_control_cmd_Init(&cmd, VOUT_CONTROL_REINIT);
+    cmd.u.cfg = &cfg;
+
+    vout_control_Push(&vout->p->control, &cmd);
+    vout_control_WaitEmpty(&vout->p->control);
+
+    return 0;
+}
diff --git a/src/video_output/stereo3d.h b/src/video_output/stereo3d.h
new file mode 100644
index 0000000..2c3b3a0
--- /dev/null
+++ b/src/video_output/stereo3d.h
@@ -0,0 +1,28 @@
+/*****************************************************************************
+ * stereo3d.h
+ *****************************************************************************
+ * Copyright (C) 2014 the VideoLAN team
+ *
+ * Authors: Felix Abecassis <felix.abecassis at gmail.com>
+ *
+ * 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.
+ *****************************************************************************/
+
+#ifndef LIBVLC_VOUT_STEREO3D_H_
+# define LIBVLC_VOUT_STEREO3D_H_
+
+void vout_InitStereo3DSupport(vout_thread_t *vout, video_format_t *fmt);
+
+#endif
diff --git a/src/video_output/video_output.c b/src/video_output/video_output.c
index ec57207..5c725e6 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 "stereo3d.h"
 
 /*****************************************************************************
  * Local prototypes
@@ -163,6 +164,7 @@ static vout_thread_t *VoutCreate(vlc_object_t *object,
 
     /* */
     vout_InitInterlacingSupport(vout, vout->p->displayed.is_interlaced);
+    vout_InitStereo3DSupport(vout, &original);
 
     /* */
     vlc_object_set_destructor(vout, VoutDestructor);
-- 
1.9.1




More information about the vlc-devel mailing list