1 /*****************************************************************************
2 * video_output.c : video output thread
4 * This module describes the programming interface for video output threads.
5 * It includes functions allowing to open a new thread, send pictures to a
6 * thread, and destroy a previously oppened video output thread.
7 *****************************************************************************
8 * Copyright (C) 2000-2007 the VideoLAN team
11 * Authors: Vincent Seguin <seguin@via.ecp.fr>
12 * Gildas Bazin <gbazin@videolan.org>
13 * Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
28 *****************************************************************************/
30 /*****************************************************************************
32 *****************************************************************************/
37 #include <vlc_common.h>
39 #include <stdlib.h> /* free() */
45 #include <vlc_filter.h>
46 #include <vlc_vout_osd.h>
47 #include <vlc_image.h>
50 #include "vout_internal.h"
51 #include "interlacing.h"
52 #include "postprocessing.h"
55 /*****************************************************************************
57 *****************************************************************************/
58 static void *Thread(void *);
59 static void VoutDestructor(vlc_object_t *);
61 /* Maximum delay between 2 displayed pictures.
62 * XXX it is needed for now but should be removed in the long term.
64 #define VOUT_REDISPLAY_DELAY (INT64_C(80000))
67 * Late pictures having a delay higher than this value are thrashed.
69 #define VOUT_DISPLAY_LATE_THRESHOLD (INT64_C(20000))
71 /* Better be in advance when awakening than late... */
72 #define VOUT_MWAIT_TOLERANCE (INT64_C(4000))
75 static int VoutValidateFormat(video_format_t *dst,
76 const video_format_t *src)
78 if (src->i_width <= 0 || src->i_width > 8192 ||
79 src->i_height <= 0 || src->i_height > 8192)
81 if (src->i_sar_num <= 0 || src->i_sar_den <= 0)
85 video_format_Copy(dst, src);
86 dst->i_chroma = vlc_fourcc_GetCodec(VIDEO_ES, src->i_chroma);
87 vlc_ureduce( &dst->i_sar_num, &dst->i_sar_den,
88 src->i_sar_num, src->i_sar_den, 50000 );
89 if (dst->i_sar_num <= 0 || dst->i_sar_den <= 0) {
93 video_format_FixRgb(dst);
96 static void VideoFormatCopyCropAr(video_format_t *dst,
97 const video_format_t *src)
99 video_format_CopyCrop(dst, src);
100 dst->i_sar_num = src->i_sar_num;
101 dst->i_sar_den = src->i_sar_den;
103 static bool VideoFormatIsCropArEqual(video_format_t *dst,
104 const video_format_t *src)
106 return dst->i_sar_num * src->i_sar_den == dst->i_sar_den * src->i_sar_num &&
107 dst->i_x_offset == src->i_x_offset &&
108 dst->i_y_offset == src->i_y_offset &&
109 dst->i_visible_width == src->i_visible_width &&
110 dst->i_visible_height == src->i_visible_height;
113 static vout_thread_t *VoutCreate(vlc_object_t *object,
114 const vout_configuration_t *cfg)
116 video_format_t original;
117 if (VoutValidateFormat(&original, cfg->fmt))
120 /* Allocate descriptor */
121 vout_thread_t *vout = vlc_custom_create(object,
122 sizeof(*vout) + sizeof(*vout->p),
123 VLC_OBJECT_VOUT, "video output");
125 video_format_Clean(&original);
130 vout->p = (vout_thread_sys_t*)&vout[1];
132 vout->p->original = original;
133 vout->p->dpb_size = cfg->dpb_size;
135 vout_control_Init(&vout->p->control);
136 vout_control_PushVoid(&vout->p->control, VOUT_CONTROL_INIT);
138 vout_statistic_Init(&vout->p->statistic);
140 vout_snapshot_Init(&vout->p->snapshot);
142 /* Initialize locks */
143 vlc_mutex_init(&vout->p->picture_lock);
144 vlc_mutex_init(&vout->p->filter.lock);
145 vlc_mutex_init(&vout->p->spu_lock);
147 /* Attach the new object now so we can use var inheritance below */
148 vlc_object_attach(vout, object);
150 /* Initialize subpicture unit */
151 vout->p->spu = spu_Create(vout);
153 /* Take care of some "interface/control" related initialisations */
156 vout->p->title.show = var_GetBool(vout, "video-title-show");
157 vout->p->title.timeout = var_GetInteger(vout, "video-title-timeout");
158 vout->p->title.position = var_GetInteger(vout, "video-title-position");
160 /* Get splitter name if present */
161 char *splitter_name = var_InheritString(vout, "video-splitter");
162 if (splitter_name && *splitter_name) {
163 vout->p->splitter_name = splitter_name;
169 vout_InitInterlacingSupport(vout, vout->p->displayed.is_interlaced);
172 vlc_object_set_destructor(vout, VoutDestructor);
175 if (vlc_clone(&vout->p->thread, Thread, vout,
176 VLC_THREAD_PRIORITY_OUTPUT)) {
177 spu_Destroy(vout->p->spu);
178 vlc_object_release(vout);
182 vout_control_WaitEmpty(&vout->p->control);
185 msg_Err(vout, "video output creation failed");
186 vout_CloseAndRelease(vout);
190 vout->p->input = cfg->input;
192 spu_Attach(vout->p->spu, vout->p->input, true);
197 vout_thread_t *(vout_Request)(vlc_object_t *object,
198 const vout_configuration_t *cfg)
200 vout_thread_t *vout = cfg->vout;
201 if (cfg->change_fmt && !cfg->fmt) {
203 vout_CloseAndRelease(vout);
207 /* If a vout is provided, try reusing it */
209 if (vout->p->input != cfg->input) {
211 spu_Attach(vout->p->spu, vout->p->input, false);
212 vout->p->input = cfg->input;
214 spu_Attach(vout->p->spu, vout->p->input, true);
217 if (cfg->change_fmt) {
218 vout_control_cmd_t cmd;
219 vout_control_cmd_Init(&cmd, VOUT_CONTROL_REINIT);
222 vout_control_Push(&vout->p->control, &cmd);
223 vout_control_WaitEmpty(&vout->p->control);
226 if (!vout->p->dead) {
227 msg_Dbg(object, "reusing provided vout");
230 vout_CloseAndRelease(vout);
232 msg_Warn(object, "cannot reuse provided vout");
234 return VoutCreate(object, cfg);
237 void vout_Close(vout_thread_t *vout)
242 spu_Attach(vout->p->spu, vout->p->input, false);
244 vout_snapshot_End(&vout->p->snapshot);
246 vout_control_PushVoid(&vout->p->control, VOUT_CONTROL_CLEAN);
247 vlc_join(vout->p->thread, NULL);
249 vlc_mutex_lock(&vout->p->spu_lock);
250 spu_Destroy(vout->p->spu);
252 vlc_mutex_unlock(&vout->p->spu_lock);
256 static void VoutDestructor(vlc_object_t *object)
258 vout_thread_t *vout = (vout_thread_t *)object;
260 /* Make sure the vout was stopped first */
261 //assert(!vout->p_module);
263 free(vout->p->splitter_name);
265 /* Destroy the locks */
266 vlc_mutex_destroy(&vout->p->spu_lock);
267 vlc_mutex_destroy(&vout->p->picture_lock);
268 vlc_mutex_destroy(&vout->p->filter.lock);
269 vout_control_Clean(&vout->p->control);
272 vout_statistic_Clean(&vout->p->statistic);
275 vout_snapshot_Clean(&vout->p->snapshot);
277 video_format_Clean(&vout->p->original);
281 void vout_ChangePause(vout_thread_t *vout, bool is_paused, mtime_t date)
283 vout_control_cmd_t cmd;
284 vout_control_cmd_Init(&cmd, VOUT_CONTROL_PAUSE);
285 cmd.u.pause.is_on = is_paused;
286 cmd.u.pause.date = date;
287 vout_control_Push(&vout->p->control, &cmd);
289 vout_control_WaitEmpty(&vout->p->control);
292 void vout_GetResetStatistic(vout_thread_t *vout, int *displayed, int *lost)
294 vout_statistic_GetReset( &vout->p->statistic, displayed, lost );
297 void vout_Flush(vout_thread_t *vout, mtime_t date)
299 vout_control_PushTime(&vout->p->control, VOUT_CONTROL_FLUSH, date);
300 vout_control_WaitEmpty(&vout->p->control);
303 void vout_Reset(vout_thread_t *vout)
305 vout_control_PushVoid(&vout->p->control, VOUT_CONTROL_RESET);
306 vout_control_WaitEmpty(&vout->p->control);
309 bool vout_IsEmpty(vout_thread_t *vout)
311 vlc_mutex_lock(&vout->p->picture_lock);
313 picture_t *picture = picture_fifo_Peek(vout->p->decoder_fifo);
315 picture_Release(picture);
317 vlc_mutex_unlock(&vout->p->picture_lock);
322 void vout_FixLeaks( vout_thread_t *vout )
324 vlc_mutex_lock(&vout->p->picture_lock);
326 picture_t *picture = picture_fifo_Peek(vout->p->decoder_fifo);
328 picture = picture_pool_Get(vout->p->decoder_pool);
332 picture_Release(picture);
333 /* Not all pictures has been displayed yet or some are
335 vlc_mutex_unlock(&vout->p->picture_lock);
339 /* There is no reason that no pictures are available, force one
340 * from the pool, becarefull with it though */
341 msg_Err(vout, "pictures leaked, trying to workaround");
344 picture_pool_NonEmpty(vout->p->decoder_pool, false);
346 vlc_mutex_unlock(&vout->p->picture_lock);
348 void vout_NextPicture(vout_thread_t *vout, mtime_t *duration)
350 vout_control_cmd_t cmd;
351 vout_control_cmd_Init(&cmd, VOUT_CONTROL_STEP);
352 cmd.u.time_ptr = duration;
354 vout_control_Push(&vout->p->control, &cmd);
355 vout_control_WaitEmpty(&vout->p->control);
358 void vout_DisplayTitle(vout_thread_t *vout, const char *title)
361 vout_control_PushString(&vout->p->control, VOUT_CONTROL_OSD_TITLE, title);
364 void vout_PutSubpicture( vout_thread_t *vout, subpicture_t *subpic )
366 vout_control_cmd_t cmd;
367 vout_control_cmd_Init(&cmd, VOUT_CONTROL_SUBPICTURE);
368 cmd.u.subpicture = subpic;
370 vout_control_Push(&vout->p->control, &cmd);
372 int vout_RegisterSubpictureChannel( vout_thread_t *vout )
374 int channel = SPU_DEFAULT_CHANNEL;
376 vlc_mutex_lock(&vout->p->spu_lock);
378 channel = spu_RegisterChannel(vout->p->spu);
379 vlc_mutex_unlock(&vout->p->spu_lock);
383 void vout_FlushSubpictureChannel( vout_thread_t *vout, int channel )
385 vout_control_PushInteger(&vout->p->control, VOUT_CONTROL_FLUSH_SUBPICTURE,
390 * It retreives a picture from the vout or NULL if no pictures are
393 * You MUST call vout_PutPicture or vout_ReleasePicture on it.
395 * You may use vout_HoldPicture(paired with vout_ReleasePicture) to keep a
396 * read-only reference.
398 picture_t *vout_GetPicture(vout_thread_t *vout)
401 vlc_mutex_lock(&vout->p->picture_lock);
402 picture_t *picture = picture_pool_Get(vout->p->decoder_pool);
404 picture_Reset(picture);
405 VideoFormatCopyCropAr(&picture->format, &vout->p->original);
407 vlc_mutex_unlock(&vout->p->picture_lock);
413 * It gives to the vout a picture to be displayed.
415 * The given picture MUST comes from vout_GetPicture.
417 * Becareful, after vout_PutPicture is called, picture_t::p_next cannot be
420 void vout_PutPicture(vout_thread_t *vout, picture_t *picture)
422 vlc_mutex_lock(&vout->p->picture_lock);
424 picture->p_next = NULL;
425 picture_fifo_Push(vout->p->decoder_fifo, picture);
427 vlc_mutex_unlock(&vout->p->picture_lock);
429 vout_control_Wake(&vout->p->control);
433 * It releases a picture retreived by vout_GetPicture.
435 void vout_ReleasePicture(vout_thread_t *vout, picture_t *picture)
437 vlc_mutex_lock(&vout->p->picture_lock);
439 picture_Release(picture);
441 vlc_mutex_unlock(&vout->p->picture_lock);
443 vout_control_Wake(&vout->p->control);
447 * It increment the reference counter of a picture retreived by
450 void vout_HoldPicture(vout_thread_t *vout, picture_t *picture)
452 vlc_mutex_lock(&vout->p->picture_lock);
454 picture_Hold(picture);
456 vlc_mutex_unlock(&vout->p->picture_lock);
460 int vout_GetSnapshot(vout_thread_t *vout,
461 block_t **image_dst, picture_t **picture_dst,
463 const char *type, mtime_t timeout)
465 picture_t *picture = vout_snapshot_Get(&vout->p->snapshot, timeout);
467 msg_Err(vout, "Failed to grab a snapshot");
472 vlc_fourcc_t codec = VLC_CODEC_PNG;
473 if (type && image_Type2Fourcc(type))
474 codec = image_Type2Fourcc(type);
476 const int override_width = var_GetInteger(vout, "snapshot-width");
477 const int override_height = var_GetInteger(vout, "snapshot-height");
479 if (picture_Export(VLC_OBJECT(vout), image_dst, fmt,
480 picture, codec, override_width, override_height)) {
481 msg_Err(vout, "Failed to convert image for snapshot");
482 picture_Release(picture);
487 *picture_dst = picture;
489 picture_Release(picture);
493 /* vout_Control* are usable by anyone at anytime */
494 void vout_ControlChangeFullscreen(vout_thread_t *vout, bool fullscreen)
496 vout_control_PushBool(&vout->p->control, VOUT_CONTROL_FULLSCREEN,
499 void vout_ControlChangeOnTop(vout_thread_t *vout, bool is_on_top)
501 vout_control_PushBool(&vout->p->control, VOUT_CONTROL_ON_TOP,
504 void vout_ControlChangeDisplayFilled(vout_thread_t *vout, bool is_filled)
506 vout_control_PushBool(&vout->p->control, VOUT_CONTROL_DISPLAY_FILLED,
509 void vout_ControlChangeZoom(vout_thread_t *vout, int num, int den)
511 vout_control_PushPair(&vout->p->control, VOUT_CONTROL_ZOOM,
514 void vout_ControlChangeSampleAspectRatio(vout_thread_t *vout,
515 unsigned num, unsigned den)
517 vout_control_PushPair(&vout->p->control, VOUT_CONTROL_ASPECT_RATIO,
520 void vout_ControlChangeCropRatio(vout_thread_t *vout,
521 unsigned num, unsigned den)
523 vout_control_PushPair(&vout->p->control, VOUT_CONTROL_CROP_RATIO,
526 void vout_ControlChangeCropWindow(vout_thread_t *vout,
527 int x, int y, int width, int height)
529 vout_control_cmd_t cmd;
530 vout_control_cmd_Init(&cmd, VOUT_CONTROL_CROP_WINDOW);
531 cmd.u.window.x = __MAX(x, 0);
532 cmd.u.window.y = __MAX(y, 0);
533 cmd.u.window.width = __MAX(width, 0);
534 cmd.u.window.height = __MAX(height, 0);
536 vout_control_Push(&vout->p->control, &cmd);
538 void vout_ControlChangeCropBorder(vout_thread_t *vout,
539 int left, int top, int right, int bottom)
541 vout_control_cmd_t cmd;
542 vout_control_cmd_Init(&cmd, VOUT_CONTROL_CROP_BORDER);
543 cmd.u.border.left = __MAX(left, 0);
544 cmd.u.border.top = __MAX(top, 0);
545 cmd.u.border.right = __MAX(right, 0);
546 cmd.u.border.bottom = __MAX(bottom, 0);
548 vout_control_Push(&vout->p->control, &cmd);
550 void vout_ControlChangeFilters(vout_thread_t *vout, const char *filters)
552 vout_control_PushString(&vout->p->control, VOUT_CONTROL_CHANGE_FILTERS,
555 void vout_ControlChangeSubFilters(vout_thread_t *vout, const char *filters)
557 vout_control_PushString(&vout->p->control, VOUT_CONTROL_CHANGE_SUB_FILTERS,
560 void vout_ControlChangeSubMargin(vout_thread_t *vout, int margin)
562 vout_control_PushInteger(&vout->p->control, VOUT_CONTROL_CHANGE_SUB_MARGIN,
567 static void VoutGetDisplayCfg(vout_thread_t *vout, vout_display_cfg_t *cfg, const char *title)
569 /* Load configuration */
570 cfg->is_fullscreen = var_CreateGetBool(vout, "fullscreen");
571 cfg->display.title = title;
572 const int display_width = var_CreateGetInteger(vout, "width");
573 const int display_height = var_CreateGetInteger(vout, "height");
574 cfg->display.width = display_width > 0 ? display_width : 0;
575 cfg->display.height = display_height > 0 ? display_height : 0;
576 cfg->is_display_filled = var_CreateGetBool(vout, "autoscale");
577 unsigned msar_num, msar_den;
578 if (var_InheritURational(vout, &msar_num, &msar_den, "monitor-par") ||
579 msar_num <= 0 || msar_den <= 0) {
583 cfg->display.sar.num = msar_num;
584 cfg->display.sar.den = msar_den;
585 unsigned zoom_den = 1000;
586 unsigned zoom_num = zoom_den * var_CreateGetFloat(vout, "scale");
587 vlc_ureduce(&zoom_num, &zoom_den, zoom_num, zoom_den, 0);
588 cfg->zoom.num = zoom_num;
589 cfg->zoom.den = zoom_den;
590 cfg->align.vertical = VOUT_DISPLAY_ALIGN_CENTER;
591 cfg->align.horizontal = VOUT_DISPLAY_ALIGN_CENTER;
592 const int align_mask = var_CreateGetInteger(vout, "align");
593 if (align_mask & 0x1)
594 cfg->align.horizontal = VOUT_DISPLAY_ALIGN_LEFT;
595 else if (align_mask & 0x2)
596 cfg->align.horizontal = VOUT_DISPLAY_ALIGN_RIGHT;
597 if (align_mask & 0x4)
598 cfg->align.vertical = VOUT_DISPLAY_ALIGN_TOP;
599 else if (align_mask & 0x8)
600 cfg->align.vertical = VOUT_DISPLAY_ALIGN_BOTTOM;
603 vout_window_t * vout_NewDisplayWindow(vout_thread_t *vout, vout_display_t *vd,
604 const vout_window_cfg_t *cfg)
607 vout_window_cfg_t cfg_override = *cfg;
609 if (!var_InheritBool( vout, "embedded-video"))
610 cfg_override.is_standalone = true;
612 if (vout->p->window.is_unused && vout->p->window.object) {
613 assert(!vout->p->splitter_name);
614 if (!cfg_override.is_standalone == !vout->p->window.cfg.is_standalone &&
615 cfg_override.type == vout->p->window.cfg.type) {
616 /* Reuse the stored window */
617 msg_Dbg(vout, "Reusing previous vout window");
618 vout_window_t *window = vout->p->window.object;
619 if (cfg_override.width != vout->p->window.cfg.width ||
620 cfg_override.height != vout->p->window.cfg.height)
621 vout_window_SetSize(window,
622 cfg_override.width, cfg_override.height);
623 vout->p->window.is_unused = false;
624 vout->p->window.cfg = cfg_override;
628 vout_window_Delete(vout->p->window.object);
629 vout->p->window.is_unused = true;
630 vout->p->window.object = NULL;
633 vout_window_t *window = vout_window_New(VLC_OBJECT(vout), "$window",
637 if (!vout->p->splitter_name) {
638 vout->p->window.is_unused = false;
639 vout->p->window.cfg = cfg_override;
640 vout->p->window.object = window;
645 void vout_DeleteDisplayWindow(vout_thread_t *vout, vout_display_t *vd,
646 vout_window_t *window)
649 if (!vout->p->window.is_unused && vout->p->window.object == window) {
650 vout->p->window.is_unused = true;
651 } else if (vout->p->window.is_unused && vout->p->window.object && !window) {
652 vout_window_Delete(vout->p->window.object);
653 vout->p->window.is_unused = true;
654 vout->p->window.object = NULL;
656 vout_window_Delete(window);
661 static picture_t *VoutVideoFilterInteractiveNewPicture(filter_t *filter)
663 vout_thread_t *vout = (vout_thread_t*)filter->p_owner;
665 picture_t *picture = picture_pool_Get(vout->p->private_pool);
667 picture_Reset(picture);
668 VideoFormatCopyCropAr(&picture->format, &filter->fmt_out.video);
672 static picture_t *VoutVideoFilterStaticNewPicture(filter_t *filter)
674 vout_thread_t *vout = (vout_thread_t*)filter->p_owner;
676 vlc_assert_locked(&vout->p->filter.lock);
677 if (filter_chain_GetLength(vout->p->filter.chain_interactive) == 0)
678 return VoutVideoFilterInteractiveNewPicture(filter);
680 return picture_NewFromFormat(&filter->fmt_out.video);
682 static void VoutVideoFilterDelPicture(filter_t *filter, picture_t *picture)
685 picture_Release(picture);
687 static int VoutVideoFilterStaticAllocationSetup(filter_t *filter, void *data)
689 filter->pf_video_buffer_new = VoutVideoFilterStaticNewPicture;
690 filter->pf_video_buffer_del = VoutVideoFilterDelPicture;
691 filter->p_owner = data; /* vout */
694 static int VoutVideoFilterInteractiveAllocationSetup(filter_t *filter, void *data)
696 filter->pf_video_buffer_new = VoutVideoFilterInteractiveNewPicture;
697 filter->pf_video_buffer_del = VoutVideoFilterDelPicture;
698 filter->p_owner = data; /* vout */
701 static void ThreadFilterFlush(vout_thread_t *vout, bool is_locked)
703 if (vout->p->displayed.current)
704 picture_Release( vout->p->displayed.current );
705 vout->p->displayed.current = NULL;
707 if (vout->p->displayed.next)
708 picture_Release( vout->p->displayed.next );
709 vout->p->displayed.next = NULL;
712 vlc_mutex_lock(&vout->p->filter.lock);
713 filter_chain_VideoFlush(vout->p->filter.chain_static);
714 filter_chain_VideoFlush(vout->p->filter.chain_interactive);
716 vlc_mutex_unlock(&vout->p->filter.lock);
724 static void ThreadChangeFilters(vout_thread_t *vout,
725 const video_format_t *source,
729 ThreadFilterFlush(vout, is_locked);
731 vlc_array_t array_static;
732 vlc_array_t array_interactive;
734 vlc_array_init(&array_static);
735 vlc_array_init(&array_interactive);
736 char *current = filters ? strdup(filters) : NULL;
740 char *next = config_ChainCreate(&name, &cfg, current);
743 vout_filter_t *e = xmalloc(sizeof(*e));
746 if (!strcmp(e->name, "deinterlace") ||
747 !strcmp(e->name, "postproc")) {
748 vlc_array_append(&array_static, e);
750 vlc_array_append(&array_interactive, e);
754 config_ChainDestroy(cfg);
762 vlc_mutex_lock(&vout->p->filter.lock);
764 es_format_t fmt_target;
765 es_format_InitFromVideo(&fmt_target, source ? source : &vout->p->filter.format);
767 es_format_t fmt_current = fmt_target;
769 for (int a = 0; a < 2; a++) {
770 vlc_array_t *array = a == 0 ? &array_static :
772 filter_chain_t *chain = a == 0 ? vout->p->filter.chain_static :
773 vout->p->filter.chain_interactive;
775 filter_chain_Reset(chain, &fmt_current, &fmt_current);
776 for (int i = 0; i < vlc_array_count(array); i++) {
777 vout_filter_t *e = vlc_array_item_at_index(array, i);
778 msg_Dbg(vout, "Adding '%s' as %s", e->name, a == 0 ? "static" : "interactive");
779 if (!filter_chain_AppendFilter(chain, e->name, e->cfg, NULL, NULL)) {
780 msg_Err(vout, "Failed to add filter '%s'", e->name);
781 config_ChainDestroy(e->cfg);
786 fmt_current = *filter_chain_GetFmtOut(chain);
787 vlc_array_clear(array);
789 VideoFormatCopyCropAr(&fmt_target.video, &fmt_current.video);
790 if (!es_format_IsSimilar(&fmt_current, &fmt_target)) {
791 msg_Dbg(vout, "Adding a filter to compensate for format changes");
792 if (!filter_chain_AppendFilter(vout->p->filter.chain_interactive, NULL, NULL,
793 &fmt_current, &fmt_target)) {
794 msg_Err(vout, "Failed to compensate for the format changes, removing all filters");
795 filter_chain_Reset(vout->p->filter.chain_static, &fmt_target, &fmt_target);
796 filter_chain_Reset(vout->p->filter.chain_interactive, &fmt_target, &fmt_target);
800 if (vout->p->filter.configuration != filters) {
801 free(vout->p->filter.configuration);
802 vout->p->filter.configuration = filters ? strdup(filters) : NULL;
805 video_format_Clean(&vout->p->filter.format);
806 video_format_Copy(&vout->p->filter.format, source);
810 vlc_mutex_unlock(&vout->p->filter.lock);
815 static int ThreadDisplayPreparePicture(vout_thread_t *vout, bool reuse, bool is_late_dropped)
819 vlc_mutex_lock(&vout->p->filter.lock);
821 picture_t *picture = filter_chain_VideoFilter(vout->p->filter.chain_static, NULL);
822 assert(!reuse || !picture);
826 if (reuse && vout->p->displayed.decoded) {
827 decoded = picture_Hold(vout->p->displayed.decoded);
829 decoded = picture_fifo_Pop(vout->p->decoder_fifo);
830 if (is_late_dropped && decoded && !decoded->b_force) {
831 const mtime_t predicted = mdate() + 0; /* TODO improve */
832 const mtime_t late = predicted - decoded->date;
833 if (late > VOUT_DISPLAY_LATE_THRESHOLD) {
834 msg_Warn(vout, "picture is too late to be displayed (missing %d ms)", (int)(late/1000));
835 picture_Release(decoded);
838 } else if (late > 0) {
839 msg_Dbg(vout, "picture might be displayed late (missing %d ms)", (int)(late/1000));
843 !VideoFormatIsCropArEqual(&decoded->format, &vout->p->filter.format))
844 ThreadChangeFilters(vout, &decoded->format, vout->p->filter.configuration, true);
850 if (vout->p->displayed.decoded)
851 picture_Release(vout->p->displayed.decoded);
853 vout->p->displayed.decoded = picture_Hold(decoded);
854 vout->p->displayed.timestamp = decoded->date;
855 vout->p->displayed.is_interlaced = !decoded->b_progressive;
856 vout->p->displayed.qtype = decoded->i_qtype;
858 picture = filter_chain_VideoFilter(vout->p->filter.chain_static, decoded);
861 vlc_mutex_unlock(&vout->p->filter.lock);
863 vout_statistic_Update(&vout->p->statistic, 0, lost_count);
867 assert(!vout->p->displayed.next);
868 if (!vout->p->displayed.current)
869 vout->p->displayed.current = picture;
871 vout->p->displayed.next = picture;
875 static int ThreadDisplayRenderPicture(vout_thread_t *vout, bool is_forced)
877 vout_thread_sys_t *sys = vout->p;
878 vout_display_t *vd = vout->p->display.vd;
880 picture_t *torender = picture_Hold(vout->p->displayed.current);
882 vout_chrono_Start(&vout->p->render);
884 vlc_mutex_lock(&vout->p->filter.lock);
885 picture_t *filtered = filter_chain_VideoFilter(vout->p->filter.chain_interactive, torender);
886 vlc_mutex_unlock(&vout->p->filter.lock);
891 if (filtered->date != vout->p->displayed.current->date)
892 msg_Warn(vout, "Unsupported timestamp modifications done by chain_interactive");
895 * Get the subpicture to be displayed
897 const bool do_snapshot = vout_snapshot_IsRequested(&vout->p->snapshot);
898 mtime_t render_subtitle_date;
899 if (vout->p->pause.is_on)
900 render_subtitle_date = vout->p->pause.date;
902 render_subtitle_date = filtered->date > 1 ? filtered->date : mdate();
903 mtime_t render_osd_date = mdate(); /* FIXME wrong */
906 * Get the subpicture to be displayed
908 const bool do_dr_spu = !do_snapshot &&
909 vd->info.subpicture_chromas &&
910 *vd->info.subpicture_chromas != 0;
911 const bool do_early_spu = !do_dr_spu &&
913 sys->display.use_dr ||
915 !vout_IsDisplayFiltered(vd) ||
916 vd->fmt.i_width * vd->fmt.i_height <= vd->source.i_width * vd->source.i_height);
918 const vlc_fourcc_t *subpicture_chromas;
919 video_format_t fmt_spu;
921 fmt_spu = vd->source; /* TODO improve */
922 subpicture_chromas = vd->info.subpicture_chromas;
925 fmt_spu = vd->source;
928 fmt_spu.i_sar_num = vd->cfg->display.sar.num;
929 fmt_spu.i_sar_den = vd->cfg->display.sar.den;
931 subpicture_chromas = NULL;
933 if (vout->p->spu_blend &&
934 vout->p->spu_blend->fmt_out.video.i_chroma != fmt_spu.i_chroma) {
935 filter_DeleteBlend(vout->p->spu_blend);
936 vout->p->spu_blend = NULL;
937 vout->p->spu_blend_chroma = 0;
939 if (!vout->p->spu_blend && vout->p->spu_blend_chroma != fmt_spu.i_chroma) {
940 vout->p->spu_blend_chroma = fmt_spu.i_chroma;
941 vout->p->spu_blend = filter_NewBlend(VLC_OBJECT(vout), &fmt_spu);
942 if (!vout->p->spu_blend)
943 msg_Err(vout, "Failed to create blending filter, OSD/Subtitles will not work");
947 subpicture_t *subpic = spu_Render(vout->p->spu,
948 subpicture_chromas, &fmt_spu,
950 render_subtitle_date, render_osd_date,
956 * - be sure to end up with a direct buffer.
957 * - blend subtitles, and in a fast access buffer
959 bool is_direct = vout->p->decoder_pool == vout->p->display_pool;
960 picture_t *todisplay = filtered;
961 if (do_early_spu && subpic) {
962 todisplay = picture_pool_Get(vout->p->private_pool);
964 VideoFormatCopyCropAr(&todisplay->format, &filtered->format);
965 picture_Copy(todisplay, filtered);
966 if (vout->p->spu_blend)
967 picture_BlendSubpicture(todisplay, vout->p->spu_blend, subpic);
969 picture_Release(filtered);
970 subpicture_Delete(subpic);
978 if (!is_direct && todisplay) {
979 direct = picture_pool_Get(vout->p->display_pool);
981 VideoFormatCopyCropAr(&direct->format, &todisplay->format);
982 picture_Copy(direct, todisplay);
984 picture_Release(todisplay);
991 subpicture_Delete(subpic);
996 * Take a snapshot if requested
999 vout_snapshot_Set(&vout->p->snapshot, &vd->source, direct);
1001 /* Render the direct buffer */
1002 assert(vout_IsDisplayFiltered(vd) == !sys->display.use_dr);
1003 vout_UpdateDisplaySourceProperties(vd, &direct->format);
1004 if (sys->display.use_dr) {
1005 vout_display_Prepare(vd, direct, subpic);
1007 sys->display.filtered = vout_FilterDisplay(vd, direct);
1008 if (sys->display.filtered) {
1009 if (!do_dr_spu && !do_early_spu && vout->p->spu_blend && subpic)
1010 picture_BlendSubpicture(sys->display.filtered, vout->p->spu_blend, subpic);
1011 vout_display_Prepare(vd, sys->display.filtered, do_dr_spu ? subpic : NULL);
1013 if (!do_dr_spu && subpic)
1014 subpicture_Delete(subpic);
1015 if (!sys->display.filtered)
1016 return VLC_EGENERIC;
1019 vout_chrono_Stop(&vout->p->render);
1023 if (((i++)%10) == 0)
1024 msg_Info(vout, "render: avg %d ms var %d ms",
1025 (int)(vout->p->render.avg/1000), (int)(vout->p->render.var/1000));
1029 /* Wait the real date (for rendering jitter) */
1031 mtime_t delay = direct->date - mdate();
1033 msg_Warn(vout, "picture is late (%lld ms)", delay / 1000);
1036 mwait(direct->date);
1038 /* Display the direct buffer returned by vout_RenderPicture */
1039 vout->p->displayed.date = mdate();
1040 vout_display_Display(vd,
1041 sys->display.filtered ? sys->display.filtered
1044 sys->display.filtered = NULL;
1046 vout_statistic_Update(&vout->p->statistic, 1, 0);
1051 static int ThreadDisplayPicture(vout_thread_t *vout,
1052 bool now, mtime_t *deadline)
1054 bool is_late_dropped = vout->p->is_late_dropped && !vout->p->pause.is_on && !now;
1055 bool first = !vout->p->displayed.current;
1056 if (first && ThreadDisplayPreparePicture(vout, true, is_late_dropped)) /* FIXME not sure it is ok */
1057 return VLC_EGENERIC;
1058 if (!vout->p->pause.is_on || now) {
1059 while (!vout->p->displayed.next) {
1060 if (ThreadDisplayPreparePicture(vout, false, is_late_dropped)) {
1066 const mtime_t date = mdate();
1067 const mtime_t render_delay = vout_chrono_GetHigh(&vout->p->render) + VOUT_MWAIT_TOLERANCE;
1069 mtime_t date_next = VLC_TS_INVALID;
1070 if (!vout->p->pause.is_on && vout->p->displayed.next)
1071 date_next = vout->p->displayed.next->date - render_delay;
1073 /* FIXME/XXX we must redisplay the last decoded picture (because
1074 * of potential vout updated, or filters update or SPU update)
1075 * For now a high update period is needed but it coulmd be removed
1077 * - vout module emits events from theselves.
1078 * - *and* SPU is modified to emit an event or a deadline when needed.
1080 * So it will be done latter.
1082 mtime_t date_refresh = VLC_TS_INVALID;
1083 if (vout->p->displayed.date > VLC_TS_INVALID)
1084 date_refresh = vout->p->displayed.date + VOUT_REDISPLAY_DELAY - render_delay;
1087 if (date_next != VLC_TS_INVALID)
1088 drop |= date_next + 0 <= date;
1090 bool refresh = false;
1091 if (date_refresh > VLC_TS_INVALID)
1092 refresh = date_refresh <= date;
1094 if (!first && !refresh && !drop) {
1095 if (date_next != VLC_TS_INVALID && date_refresh != VLC_TS_INVALID)
1096 *deadline = __MIN(date_next, date_refresh);
1097 else if (date_next != VLC_TS_INVALID)
1098 *deadline = date_next;
1099 else if (date_refresh != VLC_TS_INVALID)
1100 *deadline = date_refresh;
1101 return VLC_EGENERIC;
1105 picture_Release(vout->p->displayed.current);
1106 vout->p->displayed.current = vout->p->displayed.next;
1107 vout->p->displayed.next = NULL;
1109 if (!vout->p->displayed.current)
1110 return VLC_EGENERIC;
1112 bool is_forced = now || (!drop && refresh) || vout->p->displayed.current->b_force;
1113 return ThreadDisplayRenderPicture(vout, is_forced);
1116 static void ThreadManage(vout_thread_t *vout,
1118 vout_interlacing_support_t *interlacing,
1119 vout_postprocessing_support_t *postprocessing)
1121 vlc_mutex_lock(&vout->p->picture_lock);
1123 *deadline = VLC_TS_INVALID;
1125 if (ThreadDisplayPicture(vout, false, deadline))
1129 const int picture_qtype = vout->p->displayed.qtype;
1130 const bool picture_interlaced = vout->p->displayed.is_interlaced;
1132 vlc_mutex_unlock(&vout->p->picture_lock);
1134 /* Post processing */
1135 vout_SetPostProcessingState(vout, postprocessing, picture_qtype);
1138 vout_SetInterlacingState(vout, interlacing, picture_interlaced);
1140 vout_ManageWrapper(vout);
1143 static void ThreadDisplaySubpicture(vout_thread_t *vout,
1144 subpicture_t *subpicture)
1146 spu_PutSubpicture(vout->p->spu, subpicture);
1149 static void ThreadFlushSubpicture(vout_thread_t *vout, int channel)
1151 spu_ClearChannel(vout->p->spu, channel);
1154 static void ThreadDisplayOsdTitle(vout_thread_t *vout, const char *string)
1156 if (!vout->p->title.show)
1159 vout_OSDText(vout, SPU_DEFAULT_CHANNEL,
1160 vout->p->title.position, INT64_C(1000) * vout->p->title.timeout,
1164 static void ThreadChangeSubFilters(vout_thread_t *vout, const char *filters)
1166 spu_ChangeFilters(vout->p->spu, filters);
1168 static void ThreadChangeSubMargin(vout_thread_t *vout, int margin)
1170 spu_ChangeMargin(vout->p->spu, margin);
1173 static void ThreadChangePause(vout_thread_t *vout, bool is_paused, mtime_t date)
1175 assert(!vout->p->pause.is_on || !is_paused);
1177 if (vout->p->pause.is_on) {
1178 const mtime_t duration = date - vout->p->pause.date;
1180 if (vout->p->step.timestamp > VLC_TS_INVALID)
1181 vout->p->step.timestamp += duration;
1182 if (vout->p->step.last > VLC_TS_INVALID)
1183 vout->p->step.last += duration;
1184 picture_fifo_OffsetDate(vout->p->decoder_fifo, duration);
1185 if (vout->p->displayed.decoded)
1186 vout->p->displayed.decoded->date += duration;
1187 spu_OffsetSubtitleDate(vout->p->spu, duration);
1189 ThreadFilterFlush(vout, false);
1191 vout->p->step.timestamp = VLC_TS_INVALID;
1192 vout->p->step.last = VLC_TS_INVALID;
1194 vout->p->pause.is_on = is_paused;
1195 vout->p->pause.date = date;
1198 static void ThreadFlush(vout_thread_t *vout, bool below, mtime_t date)
1200 vout->p->step.timestamp = VLC_TS_INVALID;
1201 vout->p->step.last = VLC_TS_INVALID;
1203 ThreadFilterFlush(vout, false); /* FIXME too much */
1205 picture_t *last = vout->p->displayed.decoded;
1207 if (( below && last->date <= date) ||
1208 (!below && last->date >= date)) {
1209 picture_Release(last);
1211 vout->p->displayed.decoded = NULL;
1212 vout->p->displayed.date = VLC_TS_INVALID;
1213 vout->p->displayed.timestamp = VLC_TS_INVALID;
1217 picture_fifo_Flush(vout->p->decoder_fifo, date, below);
1220 static void ThreadReset(vout_thread_t *vout)
1222 ThreadFlush(vout, true, INT64_MAX);
1223 if (vout->p->decoder_pool)
1224 picture_pool_NonEmpty(vout->p->decoder_pool, true);
1225 vout->p->pause.is_on = false;
1226 vout->p->pause.date = mdate();
1229 static void ThreadStep(vout_thread_t *vout, mtime_t *duration)
1233 if (vout->p->step.last <= VLC_TS_INVALID)
1234 vout->p->step.last = vout->p->displayed.timestamp;
1237 if (ThreadDisplayPicture(vout, true, &dummy))
1240 vout->p->step.timestamp = vout->p->displayed.timestamp;
1242 if (vout->p->step.last > VLC_TS_INVALID &&
1243 vout->p->step.timestamp > vout->p->step.last) {
1244 *duration = vout->p->step.timestamp - vout->p->step.last;
1245 vout->p->step.last = vout->p->step.timestamp;
1246 /* TODO advance subpicture by the duration ... */
1250 static void ThreadChangeFullscreen(vout_thread_t *vout, bool fullscreen)
1252 /* FIXME not sure setting "fullscreen" is good ... */
1253 var_SetBool(vout, "fullscreen", fullscreen);
1254 vout_SetDisplayFullscreen(vout->p->display.vd, fullscreen);
1257 static void ThreadChangeOnTop(vout_thread_t *vout, bool is_on_top)
1259 vout_SetWindowState(vout->p->display.vd,
1260 is_on_top ? VOUT_WINDOW_STATE_ABOVE :
1261 VOUT_WINDOW_STATE_NORMAL);
1264 static void ThreadChangeDisplayFilled(vout_thread_t *vout, bool is_filled)
1266 vout_SetDisplayFilled(vout->p->display.vd, is_filled);
1269 static void ThreadChangeZoom(vout_thread_t *vout, int num, int den)
1271 if (num * 10 < den) {
1274 } else if (num > den * 10) {
1278 vout_SetDisplayZoom(vout->p->display.vd, num, den);
1281 static void ThreadChangeAspectRatio(vout_thread_t *vout,
1282 unsigned num, unsigned den)
1284 vout_SetDisplayAspect(vout->p->display.vd, num, den);
1288 static void ThreadExecuteCropWindow(vout_thread_t *vout,
1289 unsigned x, unsigned y,
1290 unsigned width, unsigned height)
1292 vout_SetDisplayCrop(vout->p->display.vd, 0, 0,
1293 x, y, width, height);
1295 static void ThreadExecuteCropBorder(vout_thread_t *vout,
1296 unsigned left, unsigned top,
1297 unsigned right, unsigned bottom)
1299 msg_Err(vout, "ThreadExecuteCropBorder %d.%d %dx%d", left, top, right, bottom);
1300 vout_SetDisplayCrop(vout->p->display.vd, 0, 0,
1301 left, top, -(int)right, -(int)bottom);
1304 static void ThreadExecuteCropRatio(vout_thread_t *vout,
1305 unsigned num, unsigned den)
1307 vout_SetDisplayCrop(vout->p->display.vd, num, den,
1311 static int ThreadStart(vout_thread_t *vout, const vout_display_state_t *state)
1313 vlc_mouse_Init(&vout->p->mouse);
1314 vout->p->decoder_fifo = picture_fifo_New();
1315 vout->p->decoder_pool = NULL;
1316 vout->p->display_pool = NULL;
1317 vout->p->private_pool = NULL;
1319 vout->p->filter.configuration = NULL;
1320 video_format_Copy(&vout->p->filter.format, &vout->p->original);
1321 vout->p->filter.chain_static =
1322 filter_chain_New( vout, "video filter2", true,
1323 VoutVideoFilterStaticAllocationSetup, NULL, vout);
1324 vout->p->filter.chain_interactive =
1325 filter_chain_New( vout, "video filter2", true,
1326 VoutVideoFilterInteractiveAllocationSetup, NULL, vout);
1328 vout_display_state_t state_default;
1330 VoutGetDisplayCfg(vout, &state_default.cfg, vout->p->display.title);
1331 state_default.wm_state = var_CreateGetBool(vout, "video-on-top") ? VOUT_WINDOW_STATE_ABOVE :
1332 VOUT_WINDOW_STATE_NORMAL;
1333 state_default.sar.num = 0;
1334 state_default.sar.den = 0;
1336 state = &state_default;
1339 if (vout_OpenWrapper(vout, vout->p->splitter_name, state))
1340 return VLC_EGENERIC;
1341 if (vout_InitWrapper(vout))
1342 return VLC_EGENERIC;
1343 assert(vout->p->decoder_pool);
1345 vout->p->displayed.current = NULL;
1346 vout->p->displayed.next = NULL;
1347 vout->p->displayed.decoded = NULL;
1348 vout->p->displayed.date = VLC_TS_INVALID;
1349 vout->p->displayed.timestamp = VLC_TS_INVALID;
1350 vout->p->displayed.qtype = QTYPE_NONE;
1351 vout->p->displayed.is_interlaced = false;
1353 vout->p->step.last = VLC_TS_INVALID;
1354 vout->p->step.timestamp = VLC_TS_INVALID;
1356 vout->p->spu_blend_chroma = 0;
1357 vout->p->spu_blend = NULL;
1359 video_format_Print(VLC_OBJECT(vout), "original format", &vout->p->original);
1363 static void ThreadStop(vout_thread_t *vout, vout_display_state_t *state)
1365 if (vout->p->spu_blend)
1366 filter_DeleteBlend(vout->p->spu_blend);
1368 /* Destroy translation tables */
1369 if (vout->p->display.vd) {
1370 if (vout->p->decoder_pool) {
1371 ThreadFlush(vout, true, INT64_MAX);
1372 vout_EndWrapper(vout);
1374 vout_CloseWrapper(vout, state);
1377 /* Destroy the video filters2 */
1378 filter_chain_Delete(vout->p->filter.chain_interactive);
1379 filter_chain_Delete(vout->p->filter.chain_static);
1380 video_format_Clean(&vout->p->filter.format);
1381 free(vout->p->filter.configuration);
1383 if (vout->p->decoder_fifo)
1384 picture_fifo_Delete(vout->p->decoder_fifo);
1385 assert(!vout->p->decoder_pool);
1388 static void ThreadInit(vout_thread_t *vout)
1390 vout->p->window.is_unused = true;
1391 vout->p->window.object = NULL;
1392 vout->p->dead = false;
1393 vout->p->is_late_dropped = var_InheritBool(vout, "drop-late-frames");
1394 vout->p->pause.is_on = false;
1395 vout->p->pause.date = VLC_TS_INVALID;
1397 vout_chrono_Init(&vout->p->render, 5, 10000); /* Arbitrary initial time */
1400 static void ThreadClean(vout_thread_t *vout)
1402 if (vout->p->window.object) {
1403 assert(vout->p->window.is_unused);
1404 vout_window_Delete(vout->p->window.object);
1406 vout_chrono_Clean(&vout->p->render);
1407 vout->p->dead = true;
1408 vout_control_Dead(&vout->p->control);
1411 static int ThreadReinit(vout_thread_t *vout,
1412 const vout_configuration_t *cfg)
1414 video_format_t original;
1415 if (VoutValidateFormat(&original, cfg->fmt)) {
1416 ThreadStop(vout, NULL);
1418 return VLC_EGENERIC;
1420 /* We ignore crop/ar changes at this point, they are dynamically supported */
1421 VideoFormatCopyCropAr(&vout->p->original, &original);
1422 if (video_format_IsSimilar(&original, &vout->p->original)) {
1423 if (cfg->dpb_size <= vout->p->dpb_size)
1425 msg_Warn(vout, "DPB need to be increased");
1428 vout_display_state_t state;
1429 memset(&state, 0, sizeof(state));
1431 ThreadStop(vout, &state);
1433 if (!state.cfg.is_fullscreen) {
1434 state.cfg.display.width = 0;
1435 state.cfg.display.height = 0;
1439 /* FIXME current vout "variables" are not in sync here anymore
1440 * and I am not sure what to do */
1442 vout->p->original = original;
1443 vout->p->dpb_size = cfg->dpb_size;
1444 if (ThreadStart(vout, &state)) {
1446 return VLC_EGENERIC;
1451 /*****************************************************************************
1452 * Thread: video output thread
1453 *****************************************************************************
1454 * Video output thread. This function does only returns when the thread is
1455 * terminated. It handles the pictures arriving in the video heap and the
1456 * display device events.
1457 *****************************************************************************/
1458 static void *Thread(void *object)
1460 vout_thread_t *vout = object;
1462 vout_interlacing_support_t interlacing = {
1463 .is_interlaced = false,
1466 vout_postprocessing_support_t postprocessing = {
1467 .qtype = QTYPE_NONE,
1470 mtime_t deadline = VLC_TS_INVALID;
1472 vout_control_cmd_t cmd;
1474 /* FIXME remove thoses ugly timeouts
1476 while (!vout_control_Pop(&vout->p->control, &cmd, deadline, 100000)) {
1478 case VOUT_CONTROL_INIT:
1480 if (ThreadStart(vout, NULL)) {
1481 ThreadStop(vout, NULL);
1486 case VOUT_CONTROL_CLEAN:
1487 ThreadStop(vout, NULL);
1490 case VOUT_CONTROL_REINIT:
1491 if (ThreadReinit(vout, cmd.u.cfg))
1494 case VOUT_CONTROL_SUBPICTURE:
1495 ThreadDisplaySubpicture(vout, cmd.u.subpicture);
1496 cmd.u.subpicture = NULL;
1498 case VOUT_CONTROL_FLUSH_SUBPICTURE:
1499 ThreadFlushSubpicture(vout, cmd.u.integer);
1501 case VOUT_CONTROL_OSD_TITLE:
1502 ThreadDisplayOsdTitle(vout, cmd.u.string);
1504 case VOUT_CONTROL_CHANGE_FILTERS:
1505 ThreadChangeFilters(vout, NULL, cmd.u.string, false);
1507 case VOUT_CONTROL_CHANGE_SUB_FILTERS:
1508 ThreadChangeSubFilters(vout, cmd.u.string);
1510 case VOUT_CONTROL_CHANGE_SUB_MARGIN:
1511 ThreadChangeSubMargin(vout, cmd.u.integer);
1513 case VOUT_CONTROL_PAUSE:
1514 ThreadChangePause(vout, cmd.u.pause.is_on, cmd.u.pause.date);
1516 case VOUT_CONTROL_FLUSH:
1517 ThreadFlush(vout, false, cmd.u.time);
1519 case VOUT_CONTROL_RESET:
1522 case VOUT_CONTROL_STEP:
1523 ThreadStep(vout, cmd.u.time_ptr);
1525 case VOUT_CONTROL_FULLSCREEN:
1526 ThreadChangeFullscreen(vout, cmd.u.boolean);
1528 case VOUT_CONTROL_ON_TOP:
1529 ThreadChangeOnTop(vout, cmd.u.boolean);
1531 case VOUT_CONTROL_DISPLAY_FILLED:
1532 ThreadChangeDisplayFilled(vout, cmd.u.boolean);
1534 case VOUT_CONTROL_ZOOM:
1535 ThreadChangeZoom(vout, cmd.u.pair.a, cmd.u.pair.b);
1537 case VOUT_CONTROL_ASPECT_RATIO:
1538 ThreadChangeAspectRatio(vout, cmd.u.pair.a, cmd.u.pair.b);
1540 case VOUT_CONTROL_CROP_RATIO:
1541 ThreadExecuteCropRatio(vout, cmd.u.pair.a, cmd.u.pair.b);
1543 case VOUT_CONTROL_CROP_WINDOW:
1544 ThreadExecuteCropWindow(vout,
1545 cmd.u.window.x, cmd.u.window.y,
1546 cmd.u.window.width, cmd.u.window.height);
1548 case VOUT_CONTROL_CROP_BORDER:
1549 ThreadExecuteCropBorder(vout,
1550 cmd.u.border.left, cmd.u.border.top,
1551 cmd.u.border.right, cmd.u.border.bottom);
1556 vout_control_cmd_Clean(&cmd);
1559 ThreadManage(vout, &deadline, &interlacing, &postprocessing);