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),
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 /* Initialize subpicture unit */
148 vout->p->spu = spu_Create(vout);
150 /* Take care of some "interface/control" related initialisations */
153 vout->p->title.show = var_GetBool(vout, "video-title-show");
154 vout->p->title.timeout = var_GetInteger(vout, "video-title-timeout");
155 vout->p->title.position = var_GetInteger(vout, "video-title-position");
157 /* Get splitter name if present */
158 char *splitter_name = var_InheritString(vout, "video-splitter");
159 if (splitter_name && *splitter_name) {
160 vout->p->splitter_name = splitter_name;
166 vout_InitInterlacingSupport(vout, vout->p->displayed.is_interlaced);
169 vlc_object_set_destructor(vout, VoutDestructor);
172 if (vlc_clone(&vout->p->thread, Thread, vout,
173 VLC_THREAD_PRIORITY_OUTPUT)) {
174 spu_Destroy(vout->p->spu);
175 vlc_object_release(vout);
179 vout_control_WaitEmpty(&vout->p->control);
182 msg_Err(vout, "video output creation failed");
183 vout_CloseAndRelease(vout);
187 vout->p->input = cfg->input;
189 spu_Attach(vout->p->spu, vout->p->input, true);
194 vout_thread_t *(vout_Request)(vlc_object_t *object,
195 const vout_configuration_t *cfg)
197 vout_thread_t *vout = cfg->vout;
198 if (cfg->change_fmt && !cfg->fmt) {
200 vout_CloseAndRelease(vout);
204 /* If a vout is provided, try reusing it */
206 if (vout->p->input != cfg->input) {
208 spu_Attach(vout->p->spu, vout->p->input, false);
209 vout->p->input = cfg->input;
211 spu_Attach(vout->p->spu, vout->p->input, true);
214 if (cfg->change_fmt) {
215 vout_control_cmd_t cmd;
216 vout_control_cmd_Init(&cmd, VOUT_CONTROL_REINIT);
219 vout_control_Push(&vout->p->control, &cmd);
220 vout_control_WaitEmpty(&vout->p->control);
223 if (!vout->p->dead) {
224 msg_Dbg(object, "reusing provided vout");
227 vout_CloseAndRelease(vout);
229 msg_Warn(object, "cannot reuse provided vout");
231 return VoutCreate(object, cfg);
234 void vout_Close(vout_thread_t *vout)
239 spu_Attach(vout->p->spu, vout->p->input, false);
241 vout_snapshot_End(&vout->p->snapshot);
243 vout_control_PushVoid(&vout->p->control, VOUT_CONTROL_CLEAN);
244 vlc_join(vout->p->thread, NULL);
246 vlc_mutex_lock(&vout->p->spu_lock);
247 spu_Destroy(vout->p->spu);
249 vlc_mutex_unlock(&vout->p->spu_lock);
253 static void VoutDestructor(vlc_object_t *object)
255 vout_thread_t *vout = (vout_thread_t *)object;
257 /* Make sure the vout was stopped first */
258 //assert(!vout->p_module);
260 free(vout->p->splitter_name);
262 /* Destroy the locks */
263 vlc_mutex_destroy(&vout->p->spu_lock);
264 vlc_mutex_destroy(&vout->p->picture_lock);
265 vlc_mutex_destroy(&vout->p->filter.lock);
266 vout_control_Clean(&vout->p->control);
269 vout_statistic_Clean(&vout->p->statistic);
272 vout_snapshot_Clean(&vout->p->snapshot);
274 video_format_Clean(&vout->p->original);
278 void vout_ChangePause(vout_thread_t *vout, bool is_paused, mtime_t date)
280 vout_control_cmd_t cmd;
281 vout_control_cmd_Init(&cmd, VOUT_CONTROL_PAUSE);
282 cmd.u.pause.is_on = is_paused;
283 cmd.u.pause.date = date;
284 vout_control_Push(&vout->p->control, &cmd);
286 vout_control_WaitEmpty(&vout->p->control);
289 void vout_GetResetStatistic(vout_thread_t *vout, int *displayed, int *lost)
291 vout_statistic_GetReset( &vout->p->statistic, displayed, lost );
294 void vout_Flush(vout_thread_t *vout, mtime_t date)
296 vout_control_PushTime(&vout->p->control, VOUT_CONTROL_FLUSH, date);
297 vout_control_WaitEmpty(&vout->p->control);
300 void vout_Reset(vout_thread_t *vout)
302 vout_control_PushVoid(&vout->p->control, VOUT_CONTROL_RESET);
303 vout_control_WaitEmpty(&vout->p->control);
306 bool vout_IsEmpty(vout_thread_t *vout)
308 vlc_mutex_lock(&vout->p->picture_lock);
310 picture_t *picture = picture_fifo_Peek(vout->p->decoder_fifo);
312 picture_Release(picture);
314 vlc_mutex_unlock(&vout->p->picture_lock);
319 void vout_FixLeaks( vout_thread_t *vout )
321 vlc_mutex_lock(&vout->p->picture_lock);
323 picture_t *picture = picture_fifo_Peek(vout->p->decoder_fifo);
325 picture = picture_pool_Get(vout->p->decoder_pool);
329 picture_Release(picture);
330 /* Not all pictures has been displayed yet or some are
332 vlc_mutex_unlock(&vout->p->picture_lock);
336 /* There is no reason that no pictures are available, force one
337 * from the pool, becarefull with it though */
338 msg_Err(vout, "pictures leaked, trying to workaround");
341 picture_pool_NonEmpty(vout->p->decoder_pool, false);
343 vlc_mutex_unlock(&vout->p->picture_lock);
345 void vout_NextPicture(vout_thread_t *vout, mtime_t *duration)
347 vout_control_cmd_t cmd;
348 vout_control_cmd_Init(&cmd, VOUT_CONTROL_STEP);
349 cmd.u.time_ptr = duration;
351 vout_control_Push(&vout->p->control, &cmd);
352 vout_control_WaitEmpty(&vout->p->control);
355 void vout_DisplayTitle(vout_thread_t *vout, const char *title)
358 vout_control_PushString(&vout->p->control, VOUT_CONTROL_OSD_TITLE, title);
361 void vout_PutSubpicture( vout_thread_t *vout, subpicture_t *subpic )
363 vout_control_cmd_t cmd;
364 vout_control_cmd_Init(&cmd, VOUT_CONTROL_SUBPICTURE);
365 cmd.u.subpicture = subpic;
367 vout_control_Push(&vout->p->control, &cmd);
369 int vout_RegisterSubpictureChannel( vout_thread_t *vout )
371 int channel = SPU_DEFAULT_CHANNEL;
373 vlc_mutex_lock(&vout->p->spu_lock);
375 channel = spu_RegisterChannel(vout->p->spu);
376 vlc_mutex_unlock(&vout->p->spu_lock);
380 void vout_FlushSubpictureChannel( vout_thread_t *vout, int channel )
382 vout_control_PushInteger(&vout->p->control, VOUT_CONTROL_FLUSH_SUBPICTURE,
387 * It retreives a picture from the vout or NULL if no pictures are
390 * You MUST call vout_PutPicture or vout_ReleasePicture on it.
392 * You may use vout_HoldPicture(paired with vout_ReleasePicture) to keep a
393 * read-only reference.
395 picture_t *vout_GetPicture(vout_thread_t *vout)
398 vlc_mutex_lock(&vout->p->picture_lock);
399 picture_t *picture = picture_pool_Get(vout->p->decoder_pool);
401 picture_Reset(picture);
402 VideoFormatCopyCropAr(&picture->format, &vout->p->original);
404 vlc_mutex_unlock(&vout->p->picture_lock);
410 * It gives to the vout a picture to be displayed.
412 * The given picture MUST comes from vout_GetPicture.
414 * Becareful, after vout_PutPicture is called, picture_t::p_next cannot be
417 void vout_PutPicture(vout_thread_t *vout, picture_t *picture)
419 vlc_mutex_lock(&vout->p->picture_lock);
421 picture->p_next = NULL;
422 picture_fifo_Push(vout->p->decoder_fifo, picture);
424 vlc_mutex_unlock(&vout->p->picture_lock);
426 vout_control_Wake(&vout->p->control);
430 * It releases a picture retreived by vout_GetPicture.
432 void vout_ReleasePicture(vout_thread_t *vout, picture_t *picture)
434 vlc_mutex_lock(&vout->p->picture_lock);
436 picture_Release(picture);
438 vlc_mutex_unlock(&vout->p->picture_lock);
440 vout_control_Wake(&vout->p->control);
444 * It increment the reference counter of a picture retreived by
447 void vout_HoldPicture(vout_thread_t *vout, picture_t *picture)
449 vlc_mutex_lock(&vout->p->picture_lock);
451 picture_Hold(picture);
453 vlc_mutex_unlock(&vout->p->picture_lock);
457 int vout_GetSnapshot(vout_thread_t *vout,
458 block_t **image_dst, picture_t **picture_dst,
460 const char *type, mtime_t timeout)
462 picture_t *picture = vout_snapshot_Get(&vout->p->snapshot, timeout);
464 msg_Err(vout, "Failed to grab a snapshot");
469 vlc_fourcc_t codec = VLC_CODEC_PNG;
470 if (type && image_Type2Fourcc(type))
471 codec = image_Type2Fourcc(type);
473 const int override_width = var_GetInteger(vout, "snapshot-width");
474 const int override_height = var_GetInteger(vout, "snapshot-height");
476 if (picture_Export(VLC_OBJECT(vout), image_dst, fmt,
477 picture, codec, override_width, override_height)) {
478 msg_Err(vout, "Failed to convert image for snapshot");
479 picture_Release(picture);
484 *picture_dst = picture;
486 picture_Release(picture);
490 /* vout_Control* are usable by anyone at anytime */
491 void vout_ControlChangeFullscreen(vout_thread_t *vout, bool fullscreen)
493 vout_control_PushBool(&vout->p->control, VOUT_CONTROL_FULLSCREEN,
496 void vout_ControlChangeOnTop(vout_thread_t *vout, bool is_on_top)
498 vout_control_PushBool(&vout->p->control, VOUT_CONTROL_ON_TOP,
501 void vout_ControlChangeDisplayFilled(vout_thread_t *vout, bool is_filled)
503 vout_control_PushBool(&vout->p->control, VOUT_CONTROL_DISPLAY_FILLED,
506 void vout_ControlChangeZoom(vout_thread_t *vout, int num, int den)
508 vout_control_PushPair(&vout->p->control, VOUT_CONTROL_ZOOM,
511 void vout_ControlChangeSampleAspectRatio(vout_thread_t *vout,
512 unsigned num, unsigned den)
514 vout_control_PushPair(&vout->p->control, VOUT_CONTROL_ASPECT_RATIO,
517 void vout_ControlChangeCropRatio(vout_thread_t *vout,
518 unsigned num, unsigned den)
520 vout_control_PushPair(&vout->p->control, VOUT_CONTROL_CROP_RATIO,
523 void vout_ControlChangeCropWindow(vout_thread_t *vout,
524 int x, int y, int width, int height)
526 vout_control_cmd_t cmd;
527 vout_control_cmd_Init(&cmd, VOUT_CONTROL_CROP_WINDOW);
528 cmd.u.window.x = __MAX(x, 0);
529 cmd.u.window.y = __MAX(y, 0);
530 cmd.u.window.width = __MAX(width, 0);
531 cmd.u.window.height = __MAX(height, 0);
533 vout_control_Push(&vout->p->control, &cmd);
535 void vout_ControlChangeCropBorder(vout_thread_t *vout,
536 int left, int top, int right, int bottom)
538 vout_control_cmd_t cmd;
539 vout_control_cmd_Init(&cmd, VOUT_CONTROL_CROP_BORDER);
540 cmd.u.border.left = __MAX(left, 0);
541 cmd.u.border.top = __MAX(top, 0);
542 cmd.u.border.right = __MAX(right, 0);
543 cmd.u.border.bottom = __MAX(bottom, 0);
545 vout_control_Push(&vout->p->control, &cmd);
547 void vout_ControlChangeFilters(vout_thread_t *vout, const char *filters)
549 vout_control_PushString(&vout->p->control, VOUT_CONTROL_CHANGE_FILTERS,
552 void vout_ControlChangeSubSources(vout_thread_t *vout, const char *filters)
554 vout_control_PushString(&vout->p->control, VOUT_CONTROL_CHANGE_SUB_SOURCES,
557 void vout_ControlChangeSubFilters(vout_thread_t *vout, const char *filters)
559 vout_control_PushString(&vout->p->control, VOUT_CONTROL_CHANGE_SUB_FILTERS,
562 void vout_ControlChangeSubMargin(vout_thread_t *vout, int margin)
564 vout_control_PushInteger(&vout->p->control, VOUT_CONTROL_CHANGE_SUB_MARGIN,
569 static void VoutGetDisplayCfg(vout_thread_t *vout, vout_display_cfg_t *cfg, const char *title)
571 /* Load configuration */
572 cfg->is_fullscreen = var_CreateGetBool(vout, "fullscreen");
573 cfg->display.title = title;
574 const int display_width = var_CreateGetInteger(vout, "width");
575 const int display_height = var_CreateGetInteger(vout, "height");
576 cfg->display.width = display_width > 0 ? display_width : 0;
577 cfg->display.height = display_height > 0 ? display_height : 0;
578 cfg->is_display_filled = var_CreateGetBool(vout, "autoscale");
579 unsigned msar_num, msar_den;
580 if (var_InheritURational(vout, &msar_num, &msar_den, "monitor-par") ||
581 msar_num <= 0 || msar_den <= 0) {
585 cfg->display.sar.num = msar_num;
586 cfg->display.sar.den = msar_den;
587 unsigned zoom_den = 1000;
588 unsigned zoom_num = zoom_den * var_CreateGetFloat(vout, "scale");
589 vlc_ureduce(&zoom_num, &zoom_den, zoom_num, zoom_den, 0);
590 cfg->zoom.num = zoom_num;
591 cfg->zoom.den = zoom_den;
592 cfg->align.vertical = VOUT_DISPLAY_ALIGN_CENTER;
593 cfg->align.horizontal = VOUT_DISPLAY_ALIGN_CENTER;
594 const int align_mask = var_CreateGetInteger(vout, "align");
595 if (align_mask & 0x1)
596 cfg->align.horizontal = VOUT_DISPLAY_ALIGN_LEFT;
597 else if (align_mask & 0x2)
598 cfg->align.horizontal = VOUT_DISPLAY_ALIGN_RIGHT;
599 if (align_mask & 0x4)
600 cfg->align.vertical = VOUT_DISPLAY_ALIGN_TOP;
601 else if (align_mask & 0x8)
602 cfg->align.vertical = VOUT_DISPLAY_ALIGN_BOTTOM;
605 vout_window_t * vout_NewDisplayWindow(vout_thread_t *vout, vout_display_t *vd,
606 const vout_window_cfg_t *cfg)
609 vout_window_cfg_t cfg_override = *cfg;
611 if (!var_InheritBool( vout, "embedded-video"))
612 cfg_override.is_standalone = true;
614 if (vout->p->window.is_unused && vout->p->window.object) {
615 assert(!vout->p->splitter_name);
616 if (!cfg_override.is_standalone == !vout->p->window.cfg.is_standalone &&
617 cfg_override.type == vout->p->window.cfg.type) {
618 /* Reuse the stored window */
619 msg_Dbg(vout, "Reusing previous vout window");
620 vout_window_t *window = vout->p->window.object;
621 if (cfg_override.width != vout->p->window.cfg.width ||
622 cfg_override.height != vout->p->window.cfg.height)
623 vout_window_SetSize(window,
624 cfg_override.width, cfg_override.height);
625 vout->p->window.is_unused = false;
626 vout->p->window.cfg = cfg_override;
630 vout_window_Delete(vout->p->window.object);
631 vout->p->window.is_unused = true;
632 vout->p->window.object = NULL;
635 vout_window_t *window = vout_window_New(VLC_OBJECT(vout), "$window",
639 if (!vout->p->splitter_name) {
640 vout->p->window.is_unused = false;
641 vout->p->window.cfg = cfg_override;
642 vout->p->window.object = window;
647 void vout_DeleteDisplayWindow(vout_thread_t *vout, vout_display_t *vd,
648 vout_window_t *window)
651 if (!vout->p->window.is_unused && vout->p->window.object == window) {
652 vout->p->window.is_unused = true;
653 } else if (vout->p->window.is_unused && vout->p->window.object && !window) {
654 vout_window_Delete(vout->p->window.object);
655 vout->p->window.is_unused = true;
656 vout->p->window.object = NULL;
658 vout_window_Delete(window);
663 static picture_t *VoutVideoFilterInteractiveNewPicture(filter_t *filter)
665 vout_thread_t *vout = (vout_thread_t*)filter->p_owner;
667 picture_t *picture = picture_pool_Get(vout->p->private_pool);
669 picture_Reset(picture);
670 VideoFormatCopyCropAr(&picture->format, &filter->fmt_out.video);
674 static picture_t *VoutVideoFilterStaticNewPicture(filter_t *filter)
676 vout_thread_t *vout = (vout_thread_t*)filter->p_owner;
678 vlc_assert_locked(&vout->p->filter.lock);
679 if (filter_chain_GetLength(vout->p->filter.chain_interactive) == 0)
680 return VoutVideoFilterInteractiveNewPicture(filter);
682 return picture_NewFromFormat(&filter->fmt_out.video);
684 static void VoutVideoFilterDelPicture(filter_t *filter, picture_t *picture)
687 picture_Release(picture);
689 static int VoutVideoFilterStaticAllocationSetup(filter_t *filter, void *data)
691 filter->pf_video_buffer_new = VoutVideoFilterStaticNewPicture;
692 filter->pf_video_buffer_del = VoutVideoFilterDelPicture;
693 filter->p_owner = data; /* vout */
696 static int VoutVideoFilterInteractiveAllocationSetup(filter_t *filter, void *data)
698 filter->pf_video_buffer_new = VoutVideoFilterInteractiveNewPicture;
699 filter->pf_video_buffer_del = VoutVideoFilterDelPicture;
700 filter->p_owner = data; /* vout */
703 static void ThreadFilterFlush(vout_thread_t *vout, bool is_locked)
705 if (vout->p->displayed.current)
706 picture_Release( vout->p->displayed.current );
707 vout->p->displayed.current = NULL;
709 if (vout->p->displayed.next)
710 picture_Release( vout->p->displayed.next );
711 vout->p->displayed.next = NULL;
714 vlc_mutex_lock(&vout->p->filter.lock);
715 filter_chain_VideoFlush(vout->p->filter.chain_static);
716 filter_chain_VideoFlush(vout->p->filter.chain_interactive);
718 vlc_mutex_unlock(&vout->p->filter.lock);
726 static void ThreadChangeFilters(vout_thread_t *vout,
727 const video_format_t *source,
731 ThreadFilterFlush(vout, is_locked);
733 vlc_array_t array_static;
734 vlc_array_t array_interactive;
736 vlc_array_init(&array_static);
737 vlc_array_init(&array_interactive);
738 char *current = filters ? strdup(filters) : NULL;
742 char *next = config_ChainCreate(&name, &cfg, current);
745 vout_filter_t *e = xmalloc(sizeof(*e));
748 if (!strcmp(e->name, "deinterlace") ||
749 !strcmp(e->name, "postproc")) {
750 vlc_array_append(&array_static, e);
752 vlc_array_append(&array_interactive, e);
756 config_ChainDestroy(cfg);
764 vlc_mutex_lock(&vout->p->filter.lock);
766 es_format_t fmt_target;
767 es_format_InitFromVideo(&fmt_target, source ? source : &vout->p->filter.format);
769 es_format_t fmt_current = fmt_target;
771 for (int a = 0; a < 2; a++) {
772 vlc_array_t *array = a == 0 ? &array_static :
774 filter_chain_t *chain = a == 0 ? vout->p->filter.chain_static :
775 vout->p->filter.chain_interactive;
777 filter_chain_Reset(chain, &fmt_current, &fmt_current);
778 for (int i = 0; i < vlc_array_count(array); i++) {
779 vout_filter_t *e = vlc_array_item_at_index(array, i);
780 msg_Dbg(vout, "Adding '%s' as %s", e->name, a == 0 ? "static" : "interactive");
781 if (!filter_chain_AppendFilter(chain, e->name, e->cfg, NULL, NULL)) {
782 msg_Err(vout, "Failed to add filter '%s'", e->name);
783 config_ChainDestroy(e->cfg);
788 fmt_current = *filter_chain_GetFmtOut(chain);
789 vlc_array_clear(array);
791 VideoFormatCopyCropAr(&fmt_target.video, &fmt_current.video);
792 if (!es_format_IsSimilar(&fmt_current, &fmt_target)) {
793 msg_Dbg(vout, "Adding a filter to compensate for format changes");
794 if (!filter_chain_AppendFilter(vout->p->filter.chain_interactive, NULL, NULL,
795 &fmt_current, &fmt_target)) {
796 msg_Err(vout, "Failed to compensate for the format changes, removing all filters");
797 filter_chain_Reset(vout->p->filter.chain_static, &fmt_target, &fmt_target);
798 filter_chain_Reset(vout->p->filter.chain_interactive, &fmt_target, &fmt_target);
802 if (vout->p->filter.configuration != filters) {
803 free(vout->p->filter.configuration);
804 vout->p->filter.configuration = filters ? strdup(filters) : NULL;
807 video_format_Clean(&vout->p->filter.format);
808 video_format_Copy(&vout->p->filter.format, source);
812 vlc_mutex_unlock(&vout->p->filter.lock);
817 static int ThreadDisplayPreparePicture(vout_thread_t *vout, bool reuse, bool is_late_dropped)
821 vlc_mutex_lock(&vout->p->filter.lock);
823 picture_t *picture = filter_chain_VideoFilter(vout->p->filter.chain_static, NULL);
824 assert(!reuse || !picture);
828 if (reuse && vout->p->displayed.decoded) {
829 decoded = picture_Hold(vout->p->displayed.decoded);
831 decoded = picture_fifo_Pop(vout->p->decoder_fifo);
832 if (is_late_dropped && decoded && !decoded->b_force) {
833 const mtime_t predicted = mdate() + 0; /* TODO improve */
834 const mtime_t late = predicted - decoded->date;
835 if (late > VOUT_DISPLAY_LATE_THRESHOLD) {
836 msg_Warn(vout, "picture is too late to be displayed (missing %d ms)", (int)(late/1000));
837 picture_Release(decoded);
840 } else if (late > 0) {
841 msg_Dbg(vout, "picture might be displayed late (missing %d ms)", (int)(late/1000));
845 !VideoFormatIsCropArEqual(&decoded->format, &vout->p->filter.format))
846 ThreadChangeFilters(vout, &decoded->format, vout->p->filter.configuration, true);
852 if (vout->p->displayed.decoded)
853 picture_Release(vout->p->displayed.decoded);
855 vout->p->displayed.decoded = picture_Hold(decoded);
856 vout->p->displayed.timestamp = decoded->date;
857 vout->p->displayed.is_interlaced = !decoded->b_progressive;
858 vout->p->displayed.qtype = decoded->i_qtype;
860 picture = filter_chain_VideoFilter(vout->p->filter.chain_static, decoded);
863 vlc_mutex_unlock(&vout->p->filter.lock);
865 vout_statistic_Update(&vout->p->statistic, 0, lost_count);
869 assert(!vout->p->displayed.next);
870 if (!vout->p->displayed.current)
871 vout->p->displayed.current = picture;
873 vout->p->displayed.next = picture;
877 static int ThreadDisplayRenderPicture(vout_thread_t *vout, bool is_forced)
879 vout_thread_sys_t *sys = vout->p;
880 vout_display_t *vd = vout->p->display.vd;
882 picture_t *torender = picture_Hold(vout->p->displayed.current);
884 vout_chrono_Start(&vout->p->render);
886 vlc_mutex_lock(&vout->p->filter.lock);
887 picture_t *filtered = filter_chain_VideoFilter(vout->p->filter.chain_interactive, torender);
888 vlc_mutex_unlock(&vout->p->filter.lock);
893 if (filtered->date != vout->p->displayed.current->date)
894 msg_Warn(vout, "Unsupported timestamp modifications done by chain_interactive");
897 * Get the subpicture to be displayed
899 const bool do_snapshot = vout_snapshot_IsRequested(&vout->p->snapshot);
900 mtime_t render_subtitle_date;
901 if (vout->p->pause.is_on)
902 render_subtitle_date = vout->p->pause.date;
904 render_subtitle_date = filtered->date > 1 ? filtered->date : mdate();
905 mtime_t render_osd_date = mdate(); /* FIXME wrong */
908 * Get the subpicture to be displayed
910 const bool do_dr_spu = !do_snapshot &&
911 vd->info.subpicture_chromas &&
912 *vd->info.subpicture_chromas != 0;
913 const bool do_early_spu = !do_dr_spu &&
915 sys->display.use_dr ||
917 !vout_IsDisplayFiltered(vd) ||
918 vd->fmt.i_width * vd->fmt.i_height <= vd->source.i_width * vd->source.i_height);
920 const vlc_fourcc_t *subpicture_chromas;
921 video_format_t fmt_spu;
923 vout_display_place_t place;
924 vout_display_PlacePicture(&place, &vd->source, vd->cfg, false);
926 fmt_spu = vd->source;
927 if (fmt_spu.i_width * fmt_spu.i_height < place.width * place.height) {
928 fmt_spu.i_sar_num = vd->cfg->display.sar.num;
929 fmt_spu.i_sar_den = vd->cfg->display.sar.den;
931 fmt_spu.i_visible_width = place.width;
933 fmt_spu.i_visible_height = place.height;
935 subpicture_chromas = vd->info.subpicture_chromas;
938 fmt_spu = vd->source;
941 fmt_spu.i_sar_num = vd->cfg->display.sar.num;
942 fmt_spu.i_sar_den = vd->cfg->display.sar.den;
944 subpicture_chromas = NULL;
946 if (vout->p->spu_blend &&
947 vout->p->spu_blend->fmt_out.video.i_chroma != fmt_spu.i_chroma) {
948 filter_DeleteBlend(vout->p->spu_blend);
949 vout->p->spu_blend = NULL;
950 vout->p->spu_blend_chroma = 0;
952 if (!vout->p->spu_blend && vout->p->spu_blend_chroma != fmt_spu.i_chroma) {
953 vout->p->spu_blend_chroma = fmt_spu.i_chroma;
954 vout->p->spu_blend = filter_NewBlend(VLC_OBJECT(vout), &fmt_spu);
955 if (!vout->p->spu_blend)
956 msg_Err(vout, "Failed to create blending filter, OSD/Subtitles will not work");
960 subpicture_t *subpic = spu_Render(vout->p->spu,
961 subpicture_chromas, &fmt_spu,
963 render_subtitle_date, render_osd_date,
969 * - be sure to end up with a direct buffer.
970 * - blend subtitles, and in a fast access buffer
972 bool is_direct = vout->p->decoder_pool == vout->p->display_pool;
973 picture_t *todisplay = filtered;
974 if (do_early_spu && subpic) {
975 todisplay = picture_pool_Get(vout->p->private_pool);
977 VideoFormatCopyCropAr(&todisplay->format, &filtered->format);
978 picture_Copy(todisplay, filtered);
979 if (vout->p->spu_blend)
980 picture_BlendSubpicture(todisplay, vout->p->spu_blend, subpic);
982 picture_Release(filtered);
983 subpicture_Delete(subpic);
991 if (!is_direct && todisplay) {
992 direct = picture_pool_Get(vout->p->display_pool);
994 VideoFormatCopyCropAr(&direct->format, &todisplay->format);
995 picture_Copy(direct, todisplay);
997 picture_Release(todisplay);
1004 subpicture_Delete(subpic);
1005 return VLC_EGENERIC;
1009 * Take a snapshot if requested
1012 vout_snapshot_Set(&vout->p->snapshot, &vd->source, direct);
1014 /* Render the direct buffer */
1015 assert(vout_IsDisplayFiltered(vd) == !sys->display.use_dr);
1016 vout_UpdateDisplaySourceProperties(vd, &direct->format);
1017 if (sys->display.use_dr) {
1018 vout_display_Prepare(vd, direct, subpic);
1020 sys->display.filtered = vout_FilterDisplay(vd, direct);
1021 if (sys->display.filtered) {
1022 if (!do_dr_spu && !do_early_spu && vout->p->spu_blend && subpic)
1023 picture_BlendSubpicture(sys->display.filtered, vout->p->spu_blend, subpic);
1024 vout_display_Prepare(vd, sys->display.filtered, do_dr_spu ? subpic : NULL);
1026 if (!do_dr_spu && subpic)
1027 subpicture_Delete(subpic);
1028 if (!sys->display.filtered)
1029 return VLC_EGENERIC;
1032 vout_chrono_Stop(&vout->p->render);
1036 if (((i++)%10) == 0)
1037 msg_Info(vout, "render: avg %d ms var %d ms",
1038 (int)(vout->p->render.avg/1000), (int)(vout->p->render.var/1000));
1042 /* Wait the real date (for rendering jitter) */
1044 mtime_t delay = direct->date - mdate();
1046 msg_Warn(vout, "picture is late (%lld ms)", delay / 1000);
1049 mwait(direct->date);
1051 /* Display the direct buffer returned by vout_RenderPicture */
1052 vout->p->displayed.date = mdate();
1053 vout_display_Display(vd,
1054 sys->display.filtered ? sys->display.filtered
1057 sys->display.filtered = NULL;
1059 vout_statistic_Update(&vout->p->statistic, 1, 0);
1064 static int ThreadDisplayPicture(vout_thread_t *vout,
1065 bool now, mtime_t *deadline)
1067 bool is_late_dropped = vout->p->is_late_dropped && !vout->p->pause.is_on && !now;
1068 bool first = !vout->p->displayed.current;
1069 if (first && ThreadDisplayPreparePicture(vout, true, is_late_dropped)) /* FIXME not sure it is ok */
1070 return VLC_EGENERIC;
1071 if (!vout->p->pause.is_on || now) {
1072 while (!vout->p->displayed.next) {
1073 if (ThreadDisplayPreparePicture(vout, false, is_late_dropped)) {
1079 const mtime_t date = mdate();
1080 const mtime_t render_delay = vout_chrono_GetHigh(&vout->p->render) + VOUT_MWAIT_TOLERANCE;
1082 mtime_t date_next = VLC_TS_INVALID;
1083 if (!vout->p->pause.is_on && vout->p->displayed.next)
1084 date_next = vout->p->displayed.next->date - render_delay;
1086 /* FIXME/XXX we must redisplay the last decoded picture (because
1087 * of potential vout updated, or filters update or SPU update)
1088 * For now a high update period is needed but it coulmd be removed
1090 * - vout module emits events from theselves.
1091 * - *and* SPU is modified to emit an event or a deadline when needed.
1093 * So it will be done latter.
1095 mtime_t date_refresh = VLC_TS_INVALID;
1096 if (vout->p->displayed.date > VLC_TS_INVALID)
1097 date_refresh = vout->p->displayed.date + VOUT_REDISPLAY_DELAY - render_delay;
1100 if (date_next != VLC_TS_INVALID)
1101 drop |= date_next + 0 <= date;
1103 bool refresh = false;
1104 if (date_refresh > VLC_TS_INVALID)
1105 refresh = date_refresh <= date;
1107 if (!first && !refresh && !drop) {
1108 if (date_next != VLC_TS_INVALID && date_refresh != VLC_TS_INVALID)
1109 *deadline = __MIN(date_next, date_refresh);
1110 else if (date_next != VLC_TS_INVALID)
1111 *deadline = date_next;
1112 else if (date_refresh != VLC_TS_INVALID)
1113 *deadline = date_refresh;
1114 return VLC_EGENERIC;
1118 picture_Release(vout->p->displayed.current);
1119 vout->p->displayed.current = vout->p->displayed.next;
1120 vout->p->displayed.next = NULL;
1122 if (!vout->p->displayed.current)
1123 return VLC_EGENERIC;
1125 bool is_forced = now || (!drop && refresh) || vout->p->displayed.current->b_force;
1126 return ThreadDisplayRenderPicture(vout, is_forced);
1129 static void ThreadManage(vout_thread_t *vout,
1131 vout_interlacing_support_t *interlacing,
1132 vout_postprocessing_support_t *postprocessing)
1134 vlc_mutex_lock(&vout->p->picture_lock);
1136 *deadline = VLC_TS_INVALID;
1138 if (ThreadDisplayPicture(vout, false, deadline))
1142 const int picture_qtype = vout->p->displayed.qtype;
1143 const bool picture_interlaced = vout->p->displayed.is_interlaced;
1145 vlc_mutex_unlock(&vout->p->picture_lock);
1147 /* Post processing */
1148 vout_SetPostProcessingState(vout, postprocessing, picture_qtype);
1151 vout_SetInterlacingState(vout, interlacing, picture_interlaced);
1153 vout_ManageWrapper(vout);
1156 static void ThreadDisplaySubpicture(vout_thread_t *vout,
1157 subpicture_t *subpicture)
1159 spu_PutSubpicture(vout->p->spu, subpicture);
1162 static void ThreadFlushSubpicture(vout_thread_t *vout, int channel)
1164 spu_ClearChannel(vout->p->spu, channel);
1167 static void ThreadDisplayOsdTitle(vout_thread_t *vout, const char *string)
1169 if (!vout->p->title.show)
1172 vout_OSDText(vout, SPU_DEFAULT_CHANNEL,
1173 vout->p->title.position, INT64_C(1000) * vout->p->title.timeout,
1177 static void ThreadChangeSubSources(vout_thread_t *vout, const char *filters)
1179 spu_ChangeSources(vout->p->spu, filters);
1182 static void ThreadChangeSubFilters(vout_thread_t *vout, const char *filters)
1184 spu_ChangeFilters(vout->p->spu, filters);
1187 static void ThreadChangeSubMargin(vout_thread_t *vout, int margin)
1189 spu_ChangeMargin(vout->p->spu, margin);
1192 static void ThreadChangePause(vout_thread_t *vout, bool is_paused, mtime_t date)
1194 assert(!vout->p->pause.is_on || !is_paused);
1196 if (vout->p->pause.is_on) {
1197 const mtime_t duration = date - vout->p->pause.date;
1199 if (vout->p->step.timestamp > VLC_TS_INVALID)
1200 vout->p->step.timestamp += duration;
1201 if (vout->p->step.last > VLC_TS_INVALID)
1202 vout->p->step.last += duration;
1203 picture_fifo_OffsetDate(vout->p->decoder_fifo, duration);
1204 if (vout->p->displayed.decoded)
1205 vout->p->displayed.decoded->date += duration;
1206 spu_OffsetSubtitleDate(vout->p->spu, duration);
1208 ThreadFilterFlush(vout, false);
1210 vout->p->step.timestamp = VLC_TS_INVALID;
1211 vout->p->step.last = VLC_TS_INVALID;
1213 vout->p->pause.is_on = is_paused;
1214 vout->p->pause.date = date;
1217 static void ThreadFlush(vout_thread_t *vout, bool below, mtime_t date)
1219 vout->p->step.timestamp = VLC_TS_INVALID;
1220 vout->p->step.last = VLC_TS_INVALID;
1222 ThreadFilterFlush(vout, false); /* FIXME too much */
1224 picture_t *last = vout->p->displayed.decoded;
1226 if (( below && last->date <= date) ||
1227 (!below && last->date >= date)) {
1228 picture_Release(last);
1230 vout->p->displayed.decoded = NULL;
1231 vout->p->displayed.date = VLC_TS_INVALID;
1232 vout->p->displayed.timestamp = VLC_TS_INVALID;
1236 picture_fifo_Flush(vout->p->decoder_fifo, date, below);
1239 static void ThreadReset(vout_thread_t *vout)
1241 ThreadFlush(vout, true, INT64_MAX);
1242 if (vout->p->decoder_pool)
1243 picture_pool_NonEmpty(vout->p->decoder_pool, true);
1244 vout->p->pause.is_on = false;
1245 vout->p->pause.date = mdate();
1248 static void ThreadStep(vout_thread_t *vout, mtime_t *duration)
1252 if (vout->p->step.last <= VLC_TS_INVALID)
1253 vout->p->step.last = vout->p->displayed.timestamp;
1256 if (ThreadDisplayPicture(vout, true, &dummy))
1259 vout->p->step.timestamp = vout->p->displayed.timestamp;
1261 if (vout->p->step.last > VLC_TS_INVALID &&
1262 vout->p->step.timestamp > vout->p->step.last) {
1263 *duration = vout->p->step.timestamp - vout->p->step.last;
1264 vout->p->step.last = vout->p->step.timestamp;
1265 /* TODO advance subpicture by the duration ... */
1269 static void ThreadChangeFullscreen(vout_thread_t *vout, bool fullscreen)
1271 /* FIXME not sure setting "fullscreen" is good ... */
1272 var_SetBool(vout, "fullscreen", fullscreen);
1273 vout_SetDisplayFullscreen(vout->p->display.vd, fullscreen);
1276 static void ThreadChangeOnTop(vout_thread_t *vout, bool is_on_top)
1278 vout_SetWindowState(vout->p->display.vd,
1279 is_on_top ? VOUT_WINDOW_STATE_ABOVE :
1280 VOUT_WINDOW_STATE_NORMAL);
1283 static void ThreadChangeDisplayFilled(vout_thread_t *vout, bool is_filled)
1285 vout_SetDisplayFilled(vout->p->display.vd, is_filled);
1288 static void ThreadChangeZoom(vout_thread_t *vout, int num, int den)
1290 if (num * 10 < den) {
1293 } else if (num > den * 10) {
1297 vout_SetDisplayZoom(vout->p->display.vd, num, den);
1300 static void ThreadChangeAspectRatio(vout_thread_t *vout,
1301 unsigned num, unsigned den)
1303 vout_SetDisplayAspect(vout->p->display.vd, num, den);
1307 static void ThreadExecuteCropWindow(vout_thread_t *vout,
1308 unsigned x, unsigned y,
1309 unsigned width, unsigned height)
1311 vout_SetDisplayCrop(vout->p->display.vd, 0, 0,
1312 x, y, width, height);
1314 static void ThreadExecuteCropBorder(vout_thread_t *vout,
1315 unsigned left, unsigned top,
1316 unsigned right, unsigned bottom)
1318 msg_Err(vout, "ThreadExecuteCropBorder %d.%d %dx%d", left, top, right, bottom);
1319 vout_SetDisplayCrop(vout->p->display.vd, 0, 0,
1320 left, top, -(int)right, -(int)bottom);
1323 static void ThreadExecuteCropRatio(vout_thread_t *vout,
1324 unsigned num, unsigned den)
1326 vout_SetDisplayCrop(vout->p->display.vd, num, den,
1330 static int ThreadStart(vout_thread_t *vout, const vout_display_state_t *state)
1332 vlc_mouse_Init(&vout->p->mouse);
1333 vout->p->decoder_fifo = picture_fifo_New();
1334 vout->p->decoder_pool = NULL;
1335 vout->p->display_pool = NULL;
1336 vout->p->private_pool = NULL;
1338 vout->p->filter.configuration = NULL;
1339 video_format_Copy(&vout->p->filter.format, &vout->p->original);
1340 vout->p->filter.chain_static =
1341 filter_chain_New( vout, "video filter2", true,
1342 VoutVideoFilterStaticAllocationSetup, NULL, vout);
1343 vout->p->filter.chain_interactive =
1344 filter_chain_New( vout, "video filter2", true,
1345 VoutVideoFilterInteractiveAllocationSetup, NULL, vout);
1347 vout_display_state_t state_default;
1349 VoutGetDisplayCfg(vout, &state_default.cfg, vout->p->display.title);
1350 state_default.wm_state = var_CreateGetBool(vout, "video-on-top") ? VOUT_WINDOW_STATE_ABOVE :
1351 VOUT_WINDOW_STATE_NORMAL;
1352 state_default.sar.num = 0;
1353 state_default.sar.den = 0;
1355 state = &state_default;
1358 if (vout_OpenWrapper(vout, vout->p->splitter_name, state))
1359 return VLC_EGENERIC;
1360 if (vout_InitWrapper(vout))
1361 return VLC_EGENERIC;
1362 assert(vout->p->decoder_pool);
1364 vout->p->displayed.current = NULL;
1365 vout->p->displayed.next = NULL;
1366 vout->p->displayed.decoded = NULL;
1367 vout->p->displayed.date = VLC_TS_INVALID;
1368 vout->p->displayed.timestamp = VLC_TS_INVALID;
1369 vout->p->displayed.qtype = QTYPE_NONE;
1370 vout->p->displayed.is_interlaced = false;
1372 vout->p->step.last = VLC_TS_INVALID;
1373 vout->p->step.timestamp = VLC_TS_INVALID;
1375 vout->p->spu_blend_chroma = 0;
1376 vout->p->spu_blend = NULL;
1378 video_format_Print(VLC_OBJECT(vout), "original format", &vout->p->original);
1382 static void ThreadStop(vout_thread_t *vout, vout_display_state_t *state)
1384 if (vout->p->spu_blend)
1385 filter_DeleteBlend(vout->p->spu_blend);
1387 /* Destroy translation tables */
1388 if (vout->p->display.vd) {
1389 if (vout->p->decoder_pool) {
1390 ThreadFlush(vout, true, INT64_MAX);
1391 vout_EndWrapper(vout);
1393 vout_CloseWrapper(vout, state);
1396 /* Destroy the video filters2 */
1397 filter_chain_Delete(vout->p->filter.chain_interactive);
1398 filter_chain_Delete(vout->p->filter.chain_static);
1399 video_format_Clean(&vout->p->filter.format);
1400 free(vout->p->filter.configuration);
1402 if (vout->p->decoder_fifo)
1403 picture_fifo_Delete(vout->p->decoder_fifo);
1404 assert(!vout->p->decoder_pool);
1407 static void ThreadInit(vout_thread_t *vout)
1409 vout->p->window.is_unused = true;
1410 vout->p->window.object = NULL;
1411 vout->p->dead = false;
1412 vout->p->is_late_dropped = var_InheritBool(vout, "drop-late-frames");
1413 vout->p->pause.is_on = false;
1414 vout->p->pause.date = VLC_TS_INVALID;
1416 vout_chrono_Init(&vout->p->render, 5, 10000); /* Arbitrary initial time */
1419 static void ThreadClean(vout_thread_t *vout)
1421 if (vout->p->window.object) {
1422 assert(vout->p->window.is_unused);
1423 vout_window_Delete(vout->p->window.object);
1425 vout_chrono_Clean(&vout->p->render);
1426 vout->p->dead = true;
1427 vout_control_Dead(&vout->p->control);
1430 static int ThreadReinit(vout_thread_t *vout,
1431 const vout_configuration_t *cfg)
1433 video_format_t original;
1434 if (VoutValidateFormat(&original, cfg->fmt)) {
1435 ThreadStop(vout, NULL);
1437 return VLC_EGENERIC;
1439 /* We ignore crop/ar changes at this point, they are dynamically supported */
1440 VideoFormatCopyCropAr(&vout->p->original, &original);
1441 if (video_format_IsSimilar(&original, &vout->p->original)) {
1442 if (cfg->dpb_size <= vout->p->dpb_size)
1444 msg_Warn(vout, "DPB need to be increased");
1447 vout_display_state_t state;
1448 memset(&state, 0, sizeof(state));
1450 ThreadStop(vout, &state);
1452 if (!state.cfg.is_fullscreen) {
1453 state.cfg.display.width = 0;
1454 state.cfg.display.height = 0;
1458 /* FIXME current vout "variables" are not in sync here anymore
1459 * and I am not sure what to do */
1461 vout->p->original = original;
1462 vout->p->dpb_size = cfg->dpb_size;
1463 if (ThreadStart(vout, &state)) {
1465 return VLC_EGENERIC;
1470 /*****************************************************************************
1471 * Thread: video output thread
1472 *****************************************************************************
1473 * Video output thread. This function does only returns when the thread is
1474 * terminated. It handles the pictures arriving in the video heap and the
1475 * display device events.
1476 *****************************************************************************/
1477 static void *Thread(void *object)
1479 vout_thread_t *vout = object;
1481 vout_interlacing_support_t interlacing = {
1482 .is_interlaced = false,
1485 vout_postprocessing_support_t postprocessing = {
1486 .qtype = QTYPE_NONE,
1489 mtime_t deadline = VLC_TS_INVALID;
1491 vout_control_cmd_t cmd;
1493 /* FIXME remove thoses ugly timeouts
1495 while (!vout_control_Pop(&vout->p->control, &cmd, deadline, 100000)) {
1497 case VOUT_CONTROL_INIT:
1499 if (ThreadStart(vout, NULL)) {
1500 ThreadStop(vout, NULL);
1505 case VOUT_CONTROL_CLEAN:
1506 ThreadStop(vout, NULL);
1509 case VOUT_CONTROL_REINIT:
1510 if (ThreadReinit(vout, cmd.u.cfg))
1513 case VOUT_CONTROL_SUBPICTURE:
1514 ThreadDisplaySubpicture(vout, cmd.u.subpicture);
1515 cmd.u.subpicture = NULL;
1517 case VOUT_CONTROL_FLUSH_SUBPICTURE:
1518 ThreadFlushSubpicture(vout, cmd.u.integer);
1520 case VOUT_CONTROL_OSD_TITLE:
1521 ThreadDisplayOsdTitle(vout, cmd.u.string);
1523 case VOUT_CONTROL_CHANGE_FILTERS:
1524 ThreadChangeFilters(vout, NULL, cmd.u.string, false);
1526 case VOUT_CONTROL_CHANGE_SUB_SOURCES:
1527 ThreadChangeSubSources(vout, cmd.u.string);
1529 case VOUT_CONTROL_CHANGE_SUB_FILTERS:
1530 ThreadChangeSubFilters(vout, cmd.u.string);
1532 case VOUT_CONTROL_CHANGE_SUB_MARGIN:
1533 ThreadChangeSubMargin(vout, cmd.u.integer);
1535 case VOUT_CONTROL_PAUSE:
1536 ThreadChangePause(vout, cmd.u.pause.is_on, cmd.u.pause.date);
1538 case VOUT_CONTROL_FLUSH:
1539 ThreadFlush(vout, false, cmd.u.time);
1541 case VOUT_CONTROL_RESET:
1544 case VOUT_CONTROL_STEP:
1545 ThreadStep(vout, cmd.u.time_ptr);
1547 case VOUT_CONTROL_FULLSCREEN:
1548 ThreadChangeFullscreen(vout, cmd.u.boolean);
1550 case VOUT_CONTROL_ON_TOP:
1551 ThreadChangeOnTop(vout, cmd.u.boolean);
1553 case VOUT_CONTROL_DISPLAY_FILLED:
1554 ThreadChangeDisplayFilled(vout, cmd.u.boolean);
1556 case VOUT_CONTROL_ZOOM:
1557 ThreadChangeZoom(vout, cmd.u.pair.a, cmd.u.pair.b);
1559 case VOUT_CONTROL_ASPECT_RATIO:
1560 ThreadChangeAspectRatio(vout, cmd.u.pair.a, cmd.u.pair.b);
1562 case VOUT_CONTROL_CROP_RATIO:
1563 ThreadExecuteCropRatio(vout, cmd.u.pair.a, cmd.u.pair.b);
1565 case VOUT_CONTROL_CROP_WINDOW:
1566 ThreadExecuteCropWindow(vout,
1567 cmd.u.window.x, cmd.u.window.y,
1568 cmd.u.window.width, cmd.u.window.height);
1570 case VOUT_CONTROL_CROP_BORDER:
1571 ThreadExecuteCropBorder(vout,
1572 cmd.u.border.left, cmd.u.border.top,
1573 cmd.u.border.right, cmd.u.border.bottom);
1578 vout_control_cmd_Clean(&cmd);
1581 ThreadManage(vout, &deadline, &interlacing, &postprocessing);