]> git.sesse.net Git - vlc/blobdiff - src/video_output/display.c
spu: avoid pointless alloc and indirection
[vlc] / src / video_output / display.c
index be379dc58fb4732c0067e843b0b0b689c527db6d..871b15ba8243a9208bd9687a03890b97c61ecb2a 100644 (file)
@@ -6,19 +6,19 @@
  *
  * Authors: 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.
  *****************************************************************************/
 
 /*****************************************************************************
@@ -53,7 +53,7 @@ static void SplitterClose(vout_display_t *vd);
  *****************************************************************************/
 static picture_t *VideoBufferNew(filter_t *filter)
 {
-    vout_display_t *vd = (vout_display_t*)filter->p_owner;
+    vout_display_t *vd = filter->owner.sys;
     const video_format_t *fmt = &filter->fmt_out.video;
 
     assert(vd->fmt.i_chroma == fmt->i_chroma &&
@@ -73,18 +73,11 @@ static void VideoBufferDelete(filter_t *filter, picture_t *picture)
 
 static int  FilterAllocationInit(filter_t *filter, void *vd)
 {
-    filter->pf_video_buffer_new = VideoBufferNew;
-    filter->pf_video_buffer_del = VideoBufferDelete;
-    filter->p_owner             = vd;
-
+    filter->owner.sys              = vd;
+    filter->owner.video.buffer_new = VideoBufferNew;
+    filter->owner.video.buffer_del = VideoBufferDelete;
     return VLC_SUCCESS;
 }
-static void FilterAllocationClean(filter_t *filter)
-{
-    filter->pf_video_buffer_new = NULL;
-    filter->pf_video_buffer_del = NULL;
-    filter->p_owner             = NULL;
-}
 
 /*****************************************************************************
  *
@@ -100,7 +93,7 @@ static vout_display_t *vout_display_New(vlc_object_t *obj,
                                         vout_display_owner_t *owner)
 {
     /* */
-    vout_display_t *vd = vlc_object_create(obj, sizeof(*vd));
+    vout_display_t *vd = vlc_custom_create(obj, sizeof(*vd), "vout display" );
 
     /* */
     video_format_Copy(&vd->source, fmt);
@@ -115,6 +108,7 @@ static vout_display_t *vout_display_New(vlc_object_t *obj,
     vd->info.has_hide_mouse = false;
     vd->info.has_pictures_invalid = false;
     vd->info.has_event_thread = false;
+    vd->info.subpicture_chromas = NULL;
 
     vd->cfg = cfg;
     vd->pool = NULL;
@@ -126,8 +120,6 @@ static vout_display_t *vout_display_New(vlc_object_t *obj,
 
     vd->owner = *owner;
 
-    vlc_object_attach(vd, obj);
-
     if (load_module) {
         vd->module = module_need(vd, "vout display", module, module && *module != '\0');
         if (!vd->module) {
@@ -165,6 +157,7 @@ static int vout_display_Control(vout_display_t *vd, int query, ...)
 
     return result;
 }
+
 static void vout_display_Manage(vout_display_t *vd)
 {
     if (vd->manage)
@@ -197,6 +190,13 @@ void vout_display_GetDefaultDisplaySize(unsigned *width, unsigned *height,
 
     *width  = *width  * cfg->zoom.num / cfg->zoom.den;
     *height = *height * cfg->zoom.num / cfg->zoom.den;
+
+    if (ORIENT_IS_SWAP(source->orientation)) {
+
+        unsigned store = *width;
+        *width = *height;
+        *height = store;
+    }
 }
 
 /* */
@@ -214,6 +214,10 @@ void vout_display_PlacePicture(vout_display_place_t *place,
     unsigned display_width;
     unsigned display_height;
 
+    video_format_t source_rot;
+    video_format_ApplyRotation(&source_rot, source);
+    source = &source_rot;
+
     if (cfg->is_display_filled) {
         display_width  = cfg->display.width;
         display_height = cfg->display.height;
@@ -273,6 +277,62 @@ void vout_display_PlacePicture(vout_display_place_t *place,
     }
 }
 
+void vout_display_SendMouseMovedDisplayCoordinates(vout_display_t *vd, video_orientation_t orient_display, int m_x, int m_y, vout_display_place_t *place)
+{
+    video_format_t source_rot = vd->source;
+    video_format_TransformTo(&source_rot, orient_display);
+
+    if (place->width > 0 && place->height > 0) {
+
+        int x = (int)(source_rot.i_x_offset +
+                            (int64_t)(m_x - place->x) * source_rot.i_visible_width / place->width);
+        int y = (int)(source_rot.i_y_offset +
+                            (int64_t)(m_y - place->y) * source_rot.i_visible_height/ place->height);
+
+        video_transform_t transform = video_format_GetTransform(vd->source.orientation, orient_display);
+
+        int store;
+
+        switch (transform) {
+
+            case TRANSFORM_R90:
+                store = x;
+                x = y;
+                y = vd->source.i_visible_height - store;
+                break;
+            case TRANSFORM_R180:
+                x = vd->source.i_visible_width - x;
+                y = vd->source.i_visible_height - y;
+                break;
+            case TRANSFORM_R270:
+                store = x;
+                x = vd->source.i_visible_width - y;
+                y = store;
+                break;
+            case TRANSFORM_HFLIP:
+                x = vd->source.i_visible_width - x;
+                break;
+            case TRANSFORM_VFLIP:
+                y = vd->source.i_visible_height - y;
+                break;
+            case TRANSFORM_TRANSPOSE:
+                store = x;
+                x = y;
+                y = store;
+                break;
+            case TRANSFORM_ANTI_TRANSPOSE:
+                store = x;
+                x = vd->source.i_visible_width - y;
+                y = vd->source.i_visible_height - store;
+                break;
+            default:
+                break;
+        }
+
+        vout_display_SendEventMouseMoved (vd, x, y);
+    }
+}
+
 struct vout_display_owner_sys_t {
     vout_thread_t   *vout;
     bool            is_wrapper;  /* Is the current display a wrapper */
@@ -301,8 +361,8 @@ struct vout_display_owner_sys_t {
 
     bool ch_zoom;
     struct {
-        int  num;
-        int  den;
+        unsigned num;
+        unsigned den;
     } zoom;
 
     bool ch_wm_state;
@@ -316,10 +376,10 @@ struct vout_display_owner_sys_t {
 
     bool ch_crop;
     struct {
-        unsigned x;
-        unsigned y;
-        unsigned width;
-        unsigned height;
+        int      left;
+        int      top;
+        int      right;
+        int      bottom;
         unsigned num;
         unsigned den;
     } crop;
@@ -399,8 +459,7 @@ static void VoutDisplayCreateRender(vout_display_t *vd)
     msg_Dbg(vd, "A filter to adapt decoder to display is needed");
 
     osys->filters = filter_chain_New(vd, "video filter2", false,
-                                     FilterAllocationInit,
-                                     FilterAllocationClean, vd);
+                                     FilterAllocationInit, NULL, vd);
     assert(osys->filters); /* TODO critical */
 
     /* */
@@ -422,11 +481,7 @@ static void VoutDisplayCreateRender(vout_display_t *vd)
             break;
     }
     if (!filter)
-    {
-        msg_Err(vd, "VoutDisplayCreateRender FAILED");
-        /* TODO */
-        assert(0);
-    }
+        msg_Err(vd, "Failed to adapt decoder format to display");
 }
 
 static void VoutDisplayDestroyRender(vout_display_t *vd)
@@ -542,6 +597,7 @@ static void VoutDisplayEventMouse(vout_display_t *vd, int event, va_list args)
     vlc_mutex_unlock(&osys->lock);
 }
 
+VLC_NORETURN
 static void *VoutDisplayEventKeyDispatch(void *data)
 {
     vout_display_owner_sys_t *osys = data;
@@ -686,7 +742,7 @@ 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), NULL, &cfg_override);
+        return vout_window_New(VLC_OBJECT(osys->vout), "$window", &cfg_override);
     }
 #endif
     return vout_NewDisplayWindow(osys->vout, vd, cfg);
@@ -738,8 +794,7 @@ static void VoutDisplayFitWindow(vout_display_t *vd, bool default_size)
     vlc_mutex_unlock(&osys->lock);
 }
 
-static void VoutDisplayCropRatio(unsigned *x, unsigned *y,
-                                 unsigned *width, unsigned *height,
+static void VoutDisplayCropRatio(int *left, int *top, int *right, int *bottom,
                                  const video_format_t *source,
                                  unsigned num, unsigned den)
 {
@@ -747,21 +802,19 @@ static void VoutDisplayCropRatio(unsigned *x, unsigned *y,
     unsigned scaled_height = (uint64_t)source->i_visible_width  * den * source->i_sar_num / num / source->i_sar_den;
 
     if (scaled_width < source->i_visible_width) {
-        *x      = (source->i_visible_width - scaled_width) / 2;
-        *y      = 0;
-        *width  = scaled_width;
-        *height = source->i_visible_height;
+        *left   = (source->i_visible_width - scaled_width) / 2;
+        *top    = 0;
+        *right  = *left + scaled_width;
+        *bottom = *top  + source->i_visible_height;
     } else {
-        *x      = 0;
-        *y      = (source->i_visible_height - scaled_height) / 2;
-        *width  = source->i_visible_width;
-        *height = scaled_height;
+        *left   = 0;
+        *top    = (source->i_visible_height - scaled_height) / 2;
+        *right  = *left + source->i_visible_width;
+        *bottom = *top  + scaled_height;
     }
-    *x += source->i_x_offset;
-    *y += source->i_y_offset;
 }
 
-void vout_ManageDisplay(vout_display_t *vd, bool allow_reset_pictures)
+bool vout_ManageDisplay(vout_display_t *vd, bool allow_reset_pictures)
 {
     vout_display_owner_sys_t *osys = vd->owner.sys;
 
@@ -784,7 +837,7 @@ void vout_ManageDisplay(vout_display_t *vd, bool allow_reset_pictures)
 
     if (hide_mouse) {
         if (!vd->info.has_hide_mouse) {
-            msg_Dbg(vd, "auto hidding mouse");
+            msg_Dbg(vd, "auto hiding mouse cursor");
             vout_display_Control(vd, VOUT_DISPLAY_HIDE_MOUSE);
         }
         vout_SendEventMouseHidden(osys->vout);
@@ -865,7 +918,7 @@ void vout_ManageDisplay(vout_display_t *vd, bool allow_reset_pictures)
 
             if (!cfg.is_fullscreen != !display_is_fullscreen ||
                 vout_display_Control(vd, VOUT_DISPLAY_CHANGE_DISPLAY_SIZE, &cfg, display_is_forced)) {
-                if (!cfg.is_fullscreen == !display_is_fullscreen)
+                if (!display_is_forced)
                     msg_Err(vd, "Failed to resize display");
 
                 /* We ignore the resized */
@@ -992,28 +1045,36 @@ void vout_ManageDisplay(vout_display_t *vd, bool allow_reset_pictures)
                 video_format_t fmt = osys->source;
                 fmt.i_sar_num = source.i_sar_num;
                 fmt.i_sar_den = source.i_sar_den;
-                VoutDisplayCropRatio(&osys->crop.x, &osys->crop.y,
-                                     &osys->crop.width, &osys->crop.height,
+                VoutDisplayCropRatio(&osys->crop.left,  &osys->crop.top,
+                                     &osys->crop.right, &osys->crop.bottom,
                                      &fmt, crop_num, crop_den);
             }
-
-            source.i_x_offset       = osys->crop.x;
-            source.i_y_offset       = osys->crop.y;
-            source.i_visible_width  = osys->crop.width;
-            source.i_visible_height = osys->crop.height;
-
-            /* */
-            const bool is_valid = source.i_x_offset < source.i_width &&
-                                  source.i_y_offset < source.i_height &&
-                                  source.i_x_offset + source.i_visible_width  <= source.i_width &&
-                                  source.i_y_offset + source.i_visible_height <= source.i_height &&
-                                  source.i_visible_width > 0 && source.i_visible_height > 0;
-
-            if (!is_valid || vout_display_Control(vd, VOUT_DISPLAY_CHANGE_SOURCE_CROP, &source)) {
-                if (is_valid)
-                    msg_Err(vd, "Failed to change source crop TODO implement crop at core");
-                else
-                    msg_Err(vd, "Invalid crop requested");
+            const int right_max  = osys->source.i_x_offset + osys->source.i_visible_width;
+            const int bottom_max = osys->source.i_y_offset + osys->source.i_visible_height;
+            int left   = VLC_CLIP((int)osys->source.i_x_offset + osys->crop.left,
+                                0, right_max - 1);
+            int top    = VLC_CLIP((int)osys->source.i_y_offset + osys->crop.top,
+                                0, bottom_max - 1);
+            int right, bottom;
+            if (osys->crop.right <= 0)
+                right = (int)(osys->source.i_x_offset + osys->source.i_visible_width) + osys->crop.right;
+            else
+                right = (int)osys->source.i_x_offset + osys->crop.right;
+            right = VLC_CLIP(right, left + 1, right_max);
+            if (osys->crop.bottom <= 0)
+                bottom = (int)(osys->source.i_y_offset + osys->source.i_visible_height) + osys->crop.bottom;
+            else
+                bottom = (int)osys->source.i_y_offset + osys->crop.bottom;
+            bottom = VLC_CLIP(bottom, top + 1, bottom_max);
+
+            source.i_x_offset       = left;
+            source.i_y_offset       = top;
+            source.i_visible_width  = right - left;
+            source.i_visible_height = bottom - top;
+            video_format_Print(VLC_OBJECT(vd), "SOURCE ", &osys->source);
+            video_format_Print(VLC_OBJECT(vd), "CROPPED", &source);
+            if (vout_display_Control(vd, VOUT_DISPLAY_CHANGE_SOURCE_CROP, &source)) {
+                msg_Err(vd, "Failed to change source crop TODO implement crop at core");
 
                 source = vd->source;
                 crop_num = osys->crop_saved.num;
@@ -1025,22 +1086,21 @@ void vout_ManageDisplay(vout_display_t *vd, bool allow_reset_pictures)
                 osys->fit_window = 1;
             }
             vd->source = source;
-            osys->crop.x      = source.i_x_offset;
-            osys->crop.y      = source.i_y_offset;
-            osys->crop.width  = source.i_visible_width;
-            osys->crop.height = source.i_visible_height;
+            osys->crop.left   = source.i_x_offset - osys->source.i_x_offset;
+            osys->crop.top    = source.i_y_offset - osys->source.i_y_offset;
+            /* FIXME for right/bottom we should keep the 'type' border vs window */
+            osys->crop.right  = (source.i_x_offset + source.i_visible_width) -
+                                (osys->source.i_x_offset + osys->source.i_visible_width);
+            osys->crop.bottom = (source.i_y_offset + source.i_visible_height) -
+                                (osys->source.i_y_offset + osys->source.i_visible_height);
             osys->crop.num    = crop_num;
             osys->crop.den    = crop_den;
             osys->ch_crop = false;
 
-            /* TODO fix when a ratio is used (complicated). */
-            const unsigned left   = osys->crop.x - osys->source.i_x_offset;
-            const unsigned top    = osys->crop.y - osys->source.i_y_offset;
-            const unsigned right  = osys->source.i_visible_width  - (osys->crop.width  + osys->crop.x);
-            const unsigned bottom = osys->source.i_visible_height - (osys->crop.height + osys->crop.y);
             vout_SendEventSourceCrop(osys->vout,
                                      osys->crop.num, osys->crop.den,
-                                     left, top, right, bottom);
+                                     osys->crop.left, osys->crop.top,
+                                     -osys->crop.right, -osys->crop.bottom);
         }
 
         /* */
@@ -1054,6 +1114,8 @@ void vout_ManageDisplay(vout_display_t *vd, bool allow_reset_pictures)
     }
     if (reset_render)
         VoutDisplayResetRender(vd);
+
+    return reset_render;
 }
 
 bool vout_AreDisplayPicturesInvalid(vout_display_t *vd)
@@ -1079,9 +1141,43 @@ picture_t *vout_FilterDisplay(vout_display_t *vd, picture_t *picture)
     vout_display_owner_sys_t *osys = vd->owner.sys;
 
     assert(osys->filters);
+    if (filter_chain_GetLength(osys->filters) <= 0) {
+        picture_Release(picture);
+        return NULL;
+    }
     return filter_chain_VideoFilter(osys->filters, picture);
 }
 
+void vout_UpdateDisplaySourceProperties(vout_display_t *vd, const video_format_t *source)
+{
+    vout_display_owner_sys_t *osys = vd->owner.sys;
+
+    if (source->i_sar_num * osys->source.i_sar_den !=
+        source->i_sar_den * osys->source.i_sar_num) {
+
+        osys->source.i_sar_num = source->i_sar_num;
+        osys->source.i_sar_den = source->i_sar_den;
+        vlc_ureduce(&osys->source.i_sar_num, &osys->source.i_sar_den,
+                    osys->source.i_sar_num, osys->source.i_sar_den, 0);
+
+        /* FIXME it will override any AR that the user would have forced */
+        osys->ch_sar = true;
+        osys->sar.num = osys->source.i_sar_num;
+        osys->sar.den = osys->source.i_sar_den;
+    }
+    if (source->i_x_offset       != osys->source.i_x_offset ||
+        source->i_y_offset       != osys->source.i_y_offset ||
+        source->i_visible_width  != osys->source.i_visible_width ||
+        source->i_visible_height != osys->source.i_visible_height) {
+
+        video_format_CopyCrop(&osys->source, source);
+
+        /* Force the vout to reapply the current user crop settings over the new decoder
+         * crop settings. */
+        osys->ch_crop = true;
+    }
+}
+
 void vout_SetDisplayFullscreen(vout_display_t *vd, bool is_fullscreen)
 {
     vout_display_owner_sys_t *osys = vd->owner.sys;
@@ -1104,10 +1200,17 @@ void vout_SetDisplayFilled(vout_display_t *vd, bool is_filled)
     }
 }
 
-void vout_SetDisplayZoom(vout_display_t *vd, int num, int den)
+void vout_SetDisplayZoom(vout_display_t *vd, unsigned num, unsigned den)
 {
     vout_display_owner_sys_t *osys = vd->owner.sys;
 
+    if (num > 0 && den > 0) {
+        vlc_ureduce(&num, &den, num, den, 0);
+    } else {
+        num = 1;
+        den = 1;
+    }
+
     if (osys->is_display_filled ||
         osys->zoom.num != num || osys->zoom.den != den) {
         osys->ch_zoom = true;
@@ -1128,10 +1231,20 @@ void vout_SetWindowState(vout_display_t *vd, unsigned state)
     vlc_mutex_unlock(&osys->lock);
 }
 
-void vout_SetDisplayAspect(vout_display_t *vd, unsigned sar_num, unsigned sar_den)
+void vout_SetDisplayAspect(vout_display_t *vd, unsigned dar_num, unsigned dar_den)
 {
     vout_display_owner_sys_t *osys = vd->owner.sys;
 
+    unsigned sar_num, sar_den;
+    if (dar_num > 0 && dar_den > 0) {
+        sar_num = dar_num * osys->source.i_visible_height;
+        sar_den = dar_den * osys->source.i_visible_width;
+        vlc_ureduce(&sar_num, &sar_den, sar_num, sar_den, 0);
+    } else {
+        sar_num = 0;
+        sar_den = 0;
+    }
+
     if (osys->sar.num != sar_num || osys->sar.den != sar_den) {
         osys->ch_sar = true;
         osys->sar.num = sar_num;
@@ -1140,35 +1253,36 @@ void vout_SetDisplayAspect(vout_display_t *vd, unsigned sar_num, unsigned sar_de
 }
 void vout_SetDisplayCrop(vout_display_t *vd,
                          unsigned crop_num, unsigned crop_den,
-                         unsigned x, unsigned y, unsigned width, unsigned height)
+                         unsigned left, unsigned top, int right, int bottom)
 {
     vout_display_owner_sys_t *osys = vd->owner.sys;
 
-    if (osys->crop.x != x || osys->crop.y != y ||
-        osys->crop.width  != width || osys->crop.height != height ||
+    if (osys->crop.left  != (int)left  || osys->crop.top != (int)top ||
+        osys->crop.right != right || osys->crop.bottom != bottom ||
         (crop_num > 0 && crop_den > 0 &&
          (crop_num != osys->crop.num || crop_den != osys->crop.den))) {
 
-        osys->crop.x      = x;
-        osys->crop.y      = y;
-        osys->crop.width  = width;
-        osys->crop.height = height;
+        osys->crop.left   = left;
+        osys->crop.top    = top;
+        osys->crop.right  = right;
+        osys->crop.bottom = bottom;
         osys->crop.num    = crop_num;
         osys->crop.den    = crop_den;
 
         osys->ch_crop = true;
     }
 }
-vout_opengl_t *vout_GetDisplayOpengl(vout_display_t *vd)
+
+struct vlc_gl_t *vout_GetDisplayOpengl(vout_display_t *vd)
 {
-    vout_opengl_t *gl;
+    struct vlc_gl_t *gl;
     if (vout_display_Control(vd, VOUT_DISPLAY_GET_OPENGL, &gl))
         return NULL;
     return gl;
 }
 
 static vout_display_t *DisplayNew(vout_thread_t *vout,
-                                  const video_format_t *source_org,
+                                  const video_format_t *source,
                                   const vout_display_state_t *state,
                                   const char *module,
                                   bool is_wrapper, vout_display_t *wrapper,
@@ -1185,7 +1299,7 @@ static vout_display_t *DisplayNew(vout_thread_t *vout,
     osys->sar_initial.num = state->sar.num;
     osys->sar_initial.den = state->sar.den;
     vout_display_GetDefaultDisplaySize(&cfg->display.width, &cfg->display.height,
-                                       source_org, cfg);
+                                       source, cfg);
 
     osys->vout = vout;
     osys->is_wrapper = is_wrapper;
@@ -1210,7 +1324,7 @@ static vout_display_t *DisplayNew(vout_thread_t *vout,
         cfg_windowed.display.height = 0;
         vout_display_GetDefaultDisplaySize(&osys->width_saved,
                                            &osys->height_saved,
-                                           source_org, &cfg_windowed);
+                                           source, &cfg_windowed);
     }
     osys->zoom.num = cfg->zoom.num;
     osys->zoom.den = cfg->zoom.den;
@@ -1218,25 +1332,18 @@ static vout_display_t *DisplayNew(vout_thread_t *vout,
     osys->fit_window = 0;
     osys->event.fifo = NULL;
 
-    osys->source = *source_org;
-
-    video_format_t source = *source_org;
-
-    source.i_x_offset =
-    osys->crop.x  = 0;
-    source.i_y_offset =
-    osys->crop.y  = 0;
-    source.i_visible_width  =
-    osys->crop.width    = source.i_width;
-    source.i_visible_height =
-    osys->crop.height   = source.i_height;
+    osys->source = *source;
+    osys->crop.left   = 0;
+    osys->crop.top    = 0;
+    osys->crop.right  = 0;
+    osys->crop.bottom = 0;
     osys->crop_saved.num = 0;
     osys->crop_saved.den = 0;
     osys->crop.num = 0;
     osys->crop.den = 0;
 
-    osys->sar.num = osys->sar_initial.num ? osys->sar_initial.num : source.i_sar_num;
-    osys->sar.den = osys->sar_initial.den ? osys->sar_initial.den : source.i_sar_den;
+    osys->sar.num = osys->sar_initial.num ? osys->sar_initial.num : source->i_sar_num;
+    osys->sar.den = osys->sar_initial.den ? osys->sar_initial.den : source->i_sar_den;
 #ifdef ALLOW_DUMMY_VOUT
     vlc_mouse_Init(&osys->vout_mouse);
 #endif
@@ -1251,10 +1358,9 @@ static vout_display_t *DisplayNew(vout_thread_t *vout,
     }
     owner.sys = osys;
 
-    /* */
     vout_display_t *p_display = vout_display_New(VLC_OBJECT(vout),
                                                  module, !is_wrapper,
-                                                 &source, cfg, &owner);
+                                                 source, cfg, &owner);
     if (!p_display) {
         free(osys);
         return NULL;
@@ -1263,16 +1369,11 @@ static vout_display_t *DisplayNew(vout_thread_t *vout,
     VoutDisplayCreateRender(p_display);
 
     /* Setup delayed request */
-    if (osys->sar.num != source_org->i_sar_num ||
-        osys->sar.den != source_org->i_sar_den)
+    if (osys->sar.num != source->i_sar_num ||
+        osys->sar.den != source->i_sar_den)
         osys->ch_sar = true;
     if (osys->wm_state != osys->wm_state_initial)
         osys->ch_wm_state = true;
-    if (osys->crop.x      != source_org->i_x_offset ||
-        osys->crop.y      != source_org->i_y_offset ||
-        osys->crop.width  != source_org->i_visible_width ||
-        osys->crop.height != source_org->i_visible_height)
-        osys->ch_crop = true;
 
     return p_display;
 }
@@ -1372,7 +1473,7 @@ static void SplitterEvent(vout_display_t *vd, int event, va_list args)
         break;
 
     default:
-        msg_Err(vd, "SplitterEvent TODO");
+        msg_Err(vd, "splitter event not implemented: %d", event);
         break;
     }
 }
@@ -1384,11 +1485,14 @@ static picture_pool_t *SplitterPool(vout_display_t *vd, unsigned count)
         sys->pool = picture_pool_NewFromFormat(&vd->fmt, count);
     return sys->pool;
 }
-static void SplitterPrepare(vout_display_t *vd, picture_t *picture)
+static void SplitterPrepare(vout_display_t *vd,
+                            picture_t *picture,
+                            subpicture_t *subpicture)
 {
     vout_display_sys_t *sys = vd->sys;
 
     picture_Hold(picture);
+    assert(!subpicture);
 
     if (video_splitter_Filter(sys->splitter, sys->picture, picture)) {
         for (int i = 0; i < sys->count; i++)
@@ -1401,21 +1505,25 @@ static void SplitterPrepare(vout_display_t *vd, picture_t *picture)
         if (vout_IsDisplayFiltered(sys->display[i]))
             sys->picture[i] = vout_FilterDisplay(sys->display[i], sys->picture[i]);
         if (sys->picture[i])
-            vout_display_Prepare(sys->display[i], sys->picture[i]);
+            vout_display_Prepare(sys->display[i], sys->picture[i], NULL);
     }
 }
-static void SplitterDisplay(vout_display_t *vd, picture_t *picture)
+static void SplitterDisplay(vout_display_t *vd,
+                            picture_t *picture,
+                            subpicture_t *subpicture)
 {
     vout_display_sys_t *sys = vd->sys;
 
+    assert(!subpicture);
     for (int i = 0; i < sys->count; i++) {
         if (sys->picture[i])
-            vout_display_Display(sys->display[i], sys->picture[i]);
+            vout_display_Display(sys->display[i], sys->picture[i], NULL);
     }
     picture_Release(picture);
 }
 static int SplitterControl(vout_display_t *vd, int query, va_list args)
 {
+    (void)vd; (void)query; (void)args;
     return VLC_EGENERIC;
 }
 static void SplitterManage(vout_display_t *vd)
@@ -1561,33 +1669,26 @@ vout_display_t *vout_NewSplitter(vout_thread_t *vout,
 #include "vout_internal.h"
 void vout_SendDisplayEventMouse(vout_thread_t *vout, const vlc_mouse_t *m)
 {
-    vlc_mouse_t tmp;
+    vlc_mouse_t tmp1, tmp2;
 
-    /* The check on p_spu is needed as long as ALLOW_DUMMY_VOUT is defined */
-    if (vout->p->p_spu && spu_ProcessMouse( vout->p->p_spu, m, &vout->p->display.vd->source))
+    /* The check on spu is needed as long as ALLOW_DUMMY_VOUT is defined */
+    if (vout->p->spu && spu_ProcessMouse( vout->p->spu, m, &vout->p->display.vd->source))
         return;
 
-    vlc_mutex_lock( &vout->p->vfilter_lock );
-    if (vout->p->vfilter_chain) {
-        if (!filter_chain_MouseFilter(vout->p->vfilter_chain, &tmp, m))
-            m = &tmp;
+    vlc_mutex_lock( &vout->p->filter.lock );
+    if (vout->p->filter.chain_static && vout->p->filter.chain_interactive) {
+        if (!filter_chain_MouseFilter(vout->p->filter.chain_interactive, &tmp1, m))
+            m = &tmp1;
+        if (!filter_chain_MouseFilter(vout->p->filter.chain_static,      &tmp2, m))
+            m = &tmp2;
     }
-    vlc_mutex_unlock( &vout->p->vfilter_lock );
+    vlc_mutex_unlock( &vout->p->filter.lock );
 
     if (vlc_mouse_HasMoved(&vout->p->mouse, m)) {
         vout_SendEventMouseMoved(vout, m->i_x, m->i_y);
     }
     if (vlc_mouse_HasButton(&vout->p->mouse, m)) {
-        static const int buttons[] = {
-            MOUSE_BUTTON_LEFT,
-            MOUSE_BUTTON_CENTER,
-            MOUSE_BUTTON_RIGHT,
-            MOUSE_BUTTON_WHEEL_UP,
-            MOUSE_BUTTON_WHEEL_DOWN,
-            -1
-        };
-        for (int i = 0; buttons[i] >= 0; i++) {
-            const int button = buttons[i];
+        for (unsigned button = 0; button < MOUSE_BUTTON_MAX; button++) {
             if (vlc_mouse_HasPressed(&vout->p->mouse, m, button))
                 vout_SendEventMousePressed(vout, button);
             else if (vlc_mouse_HasReleased(&vout->p->mouse, m, button))
@@ -1605,14 +1706,15 @@ static void DummyVoutSendDisplayEventMouse(vout_thread_t *vout, vlc_mouse_t *fal
 
     if (!vout->p) {
         p.mouse = *fallback;
-        vlc_mutex_init(&p.vfilter_lock);
-        p.vfilter_chain = NULL;
-        p.p_spu = NULL;
+        vlc_mutex_init(&p.filter.lock);
+        p.filter.chain_static = NULL;
+        p.filter.chain_interactive = NULL;
+        p.spu = NULL;
         vout->p = &p;
     }
     vout_SendDisplayEventMouse(vout, m);
     if (vout->p == &p) {
-        vlc_mutex_destroy(&p.vfilter_lock);
+        vlc_mutex_destroy(&p.filter.lock);
         *fallback = p.mouse;
         vout->p = NULL;
     }