]> git.sesse.net Git - vlc/blobdiff - modules/video_output/sdl.c
Fix deinterlacing of packed YUV formats.
[vlc] / modules / video_output / sdl.c
index 17448a0e7634a2ae21c93718916ccff4d4a94f55..4206a318aba4a9e05b7d4188e05e9303bff2f5c8 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * sdl.c: SDL video output display method
  *****************************************************************************
- * Copyright (C) 1998-2009 the VideoLAN team
+ * Copyright (C) 1998-2009 VLC authors and VideoLAN
  * $Id$
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
@@ -9,19 +9,19 @@
  *          Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr>
  *          Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * 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 General Public License for more details.
+ * 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 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.
+ * 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.
  *****************************************************************************/
 
 /*****************************************************************************
 
 #include <SDL.h>
 
+#if !defined(_WIN32) && !defined(__OS2__)
+# ifdef X_DISPLAY_MISSING
+#  error Xlib required due to XInitThreads
+# endif
+# include <vlc_xlib.h>
+#endif
+
 /*****************************************************************************
  * Module descriptor
  *****************************************************************************/
@@ -56,9 +63,9 @@ vlc_module_begin()
     set_category(CAT_VIDEO)
     set_subcategory(SUBCAT_VIDEO_VOUT)
     set_description(N_("Simple DirectMedia Layer video output"))
-    set_capability("vout display", 60)
+    set_capability("vout display", 70)
     add_shortcut("sdl")
-    add_string("sdl-chroma", NULL, NULL, CHROMA_TEXT, CHROMA_LONGTEXT, true)
+    add_string("sdl-chroma", NULL, CHROMA_TEXT, CHROMA_LONGTEXT, true)
     add_obsolete_string("sdl-video-driver") /* obsolete since 1.1.0 */
     set_callbacks(Open, Close)
 #if defined(__i386__) || defined(__x86_64__)
@@ -72,7 +79,7 @@ vlc_module_end()
  * Local prototypes
  *****************************************************************************/
 static picture_pool_t *Pool  (vout_display_t *, unsigned);
-static void           Display(vout_display_t *, picture_t *);
+static void           PictureDisplay(vout_display_t *, picture_t *, subpicture_t *);
 static int            Control(vout_display_t *, int, va_list);
 static void           Manage(vout_display_t *);
 
@@ -109,6 +116,13 @@ static int Open(vlc_object_t *object)
     vout_display_t *vd = (vout_display_t *)object;
     vout_display_sys_t *sys;
 
+    if (vout_display_IsWindowed(vd))
+        return VLC_EGENERIC;
+#if !defined(_WIN32) && !defined(__OS2__)
+    if (!vlc_xlib_init (object))
+        return VLC_EGENERIC;
+#endif
+
     /* XXX: check for conflicts with the SDL audio output */
     vlc_mutex_lock(&sdl_lock);
 
@@ -126,14 +140,12 @@ static int Open(vlc_object_t *object)
 
     /* */
     int sdl_flags = SDL_INIT_VIDEO;
-#ifndef WIN32
+#ifndef _WIN32
     /* Win32 SDL implementation doesn't support SDL_INIT_EVENTTHREAD yet*/
     sdl_flags |= SDL_INIT_EVENTTHREAD;
 #endif
-#ifndef NDEBUG
     /* In debug mode you may want vlc to dump a core instead of staying stuck */
     sdl_flags |= SDL_INIT_NOPARACHUTE;
-#endif
 
     /* Initialize library */
     if (SDL_Init(sdl_flags) < 0) {
@@ -154,7 +166,8 @@ static int Open(vlc_object_t *object)
     sys->desktop_height = SDL_GetVideoInfo()->current_h;
 
     /* */
-    video_format_t fmt = vd->fmt;
+    video_format_t fmt;
+    video_format_ApplyRotation(&fmt, &vd->fmt);
 
     /* */
     vout_display_info_t info = vd->info;
@@ -180,7 +193,6 @@ static int Open(vlc_object_t *object)
         msg_Err(vd, "no video mode available");
         goto error;
     }
-    vout_display_DeleteWindow(vd, NULL);
 
     sys->display = SDL_SetVideoMode(display_width, display_height,
                                     sys->display_bpp, sys->display_flags);
@@ -194,7 +206,7 @@ static int Open(vlc_object_t *object)
 
     /* */
     vlc_fourcc_t forced_chroma = 0;
-    char *psz_chroma = var_CreateGetNonEmptyString(vd, "sdl-chroma");
+    char *psz_chroma = var_InheritString(vd, "sdl-chroma");
     if (psz_chroma) {
         forced_chroma = vlc_fourcc_GetCodecFromString(VIDEO_ES, psz_chroma);
         if (forced_chroma)
@@ -205,7 +217,7 @@ static int Open(vlc_object_t *object)
 
     /* Try to open an overlay if requested */
     sys->overlay = NULL;
-    const bool is_overlay = var_CreateGetBool(vd, "overlay");
+    const bool is_overlay = var_InheritBool(vd, "overlay");
     if (is_overlay) {
         static const struct
         {
@@ -326,12 +338,12 @@ static int Open(vlc_object_t *object)
 
     vd->pool    = Pool;
     vd->prepare = NULL;
-    vd->display = Display;
+    vd->display = PictureDisplay;
     vd->control = Control;
     vd->manage  = Manage;
 
     /* */
-    vout_display_SendEventDisplaySize(vd, display_width, display_height, vd->cfg->is_fullscreen);
+    vout_display_SendEventDisplaySize(vd, display_width, display_height);
     return VLC_SUCCESS;
 
 error:
@@ -359,7 +371,7 @@ static void Close(vlc_object_t *object)
     vout_display_sys_t *sys = vd->sys;
 
     if (sys->pool)
-        picture_pool_Delete(sys->pool);
+        picture_pool_Release(sys->pool);
 
     if (sys->overlay) {
         SDL_LockYUVOverlay(sys->overlay);
@@ -426,7 +438,7 @@ static picture_pool_t *Pool(vout_display_t *vd, unsigned count)
 /**
  * Display a picture
  */
-static void Display(vout_display_t *vd, picture_t *p_pic)
+static void PictureDisplay(vout_display_t *vd, picture_t *p_pic, subpicture_t *p_subpicture)
 {
     vout_display_sys_t *sys = vd->sys;
 
@@ -445,6 +457,7 @@ static void Display(vout_display_t *vd, picture_t *p_pic)
     }
 
     picture_Release(p_pic);
+    VLC_UNUSED(p_subpicture);
 }
 
 
@@ -481,24 +494,17 @@ static int Control(vout_display_t *vd, int query, va_list args)
         return VLC_SUCCESS;
     }
     case VOUT_DISPLAY_CHANGE_FULLSCREEN: {
-        vout_display_cfg_t cfg = *va_arg(args, const vout_display_cfg_t *);
+        bool fs = va_arg(args, int);
 
         /* Fix flags */
         sys->display_flags &= ~(SDL_FULLSCREEN | SDL_RESIZABLE);
-        sys->display_flags |= cfg.is_fullscreen ? SDL_FULLSCREEN : SDL_RESIZABLE;
+        sys->display_flags |= fs ? SDL_FULLSCREEN : SDL_RESIZABLE;
 
-        if (cfg.is_fullscreen) {
-            cfg.display.width = sys->desktop_width;
-            cfg.display.height = sys->desktop_height;
-        }
-
-        if (sys->overlay) {
-            sys->display = SDL_SetVideoMode(cfg.display.width, cfg.display.height,
+        if (sys->overlay)
+            sys->display = SDL_SetVideoMode(sys->desktop_width, sys->desktop_height,
                                             sys->display_bpp, sys->display_flags);
 
-            vout_display_PlacePicture(&sys->place, &vd->source, &cfg, !sys->overlay);
-        }
-        vout_display_SendEventDisplaySize(vd, cfg.display.width, cfg.display.height, cfg.is_fullscreen);
+        vout_display_SendEventDisplaySize(vd, sys->desktop_width, sys->desktop_height);
         return VLC_SUCCESS;
     }
     case VOUT_DISPLAY_CHANGE_ZOOM:
@@ -531,7 +537,7 @@ static int Control(vout_display_t *vd, int query, va_list args)
 
         /* */
         if (sys->pool)
-            picture_pool_Delete(sys->pool);
+            picture_pool_Release(sys->pool);
         sys->pool = NULL;
 
         vout_display_PlacePicture(&sys->place, &vd->source, vd->cfg, !sys->overlay);
@@ -627,16 +633,16 @@ static void Manage(vout_display_t *vd)
             if (sys->place.width <= 0 || sys->place.height <= 0)
                 break;
 
-            const int x = (int64_t)(event.motion.x - sys->place.x) * vd->source.i_width  / sys->place.width;
-            const int y = (int64_t)(event.motion.y - sys->place.y) * vd->source.i_height / sys->place.height;
-
             SDL_ShowCursor(1);
-            vout_display_SendEventMouseMoved(vd, x, y);
+
+            vout_display_SendMouseMovedDisplayCoordinates(vd, ORIENT_NORMAL,
+                                                          event.motion.x, event.motion.y,
+                                                          &sys->place);
             break;
         }
 
         case SDL_VIDEORESIZE:
-            vout_display_SendEventDisplaySize(vd, event.resize.w, event.resize.h, vd->cfg->is_fullscreen);
+            vout_display_SendEventDisplaySize(vd, event.resize.w, event.resize.h);
             break;
 
         default: