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 VLC authors and VideoLAN
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 it
16 * under the terms of the GNU Lesser General Public License as published by
17 * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
25 * You should have received a copy of the GNU Lesser General Public License
26 * along with this program; if not, write to the Free Software Foundation,
27 * 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"
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->filter.lock);
144 vlc_mutex_init(&vout->p->spu_lock);
146 /* Initialize subpicture unit */
147 vout->p->spu = spu_Create(vout);
149 /* Take care of some "interface/control" related initialisations */
152 vout->p->title.show = var_InheritBool(vout, "video-title-show");
153 vout->p->title.timeout = var_InheritInteger(vout, "video-title-timeout");
154 vout->p->title.position = var_InheritInteger(vout, "video-title-position");
156 /* Get splitter name if present */
157 vout->p->splitter_name = var_InheritString(vout, "video-splitter");
160 vout_InitInterlacingSupport(vout, vout->p->displayed.is_interlaced);
163 if (vout->p->splitter_name == NULL) {
164 vout_window_cfg_t wcfg = {
165 .is_standalone = !var_InheritBool(vout, "embedded-video"),
166 .type = VOUT_WINDOW_TYPE_INVALID,
167 // TODO: take pixel A/R, crop and zoom into account
169 .x = var_InheritInteger(vout, "video-x"),
170 .y = var_InheritInteger(vout, "video-y"),
172 .width = cfg->fmt->i_visible_width,
173 .height = cfg->fmt->i_visible_height,
176 vout_window_t *window = vout_display_window_New(vout, &wcfg);
179 if (var_InheritBool(vout, "fullscreen"))
180 vout_window_SetFullScreen(window, true);
181 if (var_InheritBool(vout, "video-wallpaper"))
182 vout_window_SetState(window, VOUT_WINDOW_STATE_BELOW);
183 else if (var_InheritBool(vout, "video-on-top"))
184 vout_window_SetState(window, VOUT_WINDOW_STATE_ABOVE);
186 vout->p->window = window;
188 vout->p->window = NULL;
191 vlc_object_set_destructor(vout, VoutDestructor);
194 if (vlc_clone(&vout->p->thread, Thread, vout,
195 VLC_THREAD_PRIORITY_OUTPUT)) {
196 spu_Destroy(vout->p->spu);
197 vlc_object_release(vout);
201 vout_control_WaitEmpty(&vout->p->control);
204 msg_Err(vout, "video output creation failed");
205 vout_CloseAndRelease(vout);
209 vout->p->input = cfg->input;
211 spu_Attach(vout->p->spu, vout->p->input, true);
217 vout_thread_t *vout_Request(vlc_object_t *object,
218 const vout_configuration_t *cfg)
220 vout_thread_t *vout = cfg->vout;
221 if (cfg->change_fmt && !cfg->fmt) {
223 vout_CloseAndRelease(vout);
227 /* If a vout is provided, try reusing it */
229 if (vout->p->input != cfg->input) {
231 spu_Attach(vout->p->spu, vout->p->input, false);
232 vout->p->input = cfg->input;
234 spu_Attach(vout->p->spu, vout->p->input, true);
237 if (cfg->change_fmt) {
238 vout_control_cmd_t cmd;
239 vout_control_cmd_Init(&cmd, VOUT_CONTROL_REINIT);
242 vout_control_Push(&vout->p->control, &cmd);
243 vout_control_WaitEmpty(&vout->p->control);
246 if (!vout->p->dead) {
247 msg_Dbg(object, "reusing provided vout");
248 vout_IntfReinit(vout);
251 vout_CloseAndRelease(vout);
253 msg_Warn(object, "cannot reuse provided vout");
255 return VoutCreate(object, cfg);
258 void vout_Close(vout_thread_t *vout)
263 spu_Attach(vout->p->spu, vout->p->input, false);
265 vout_snapshot_End(&vout->p->snapshot);
267 vout_control_PushVoid(&vout->p->control, VOUT_CONTROL_CLEAN);
268 vlc_join(vout->p->thread, NULL);
270 vlc_mutex_lock(&vout->p->spu_lock);
271 spu_Destroy(vout->p->spu);
273 vlc_mutex_unlock(&vout->p->spu_lock);
277 static void VoutDestructor(vlc_object_t *object)
279 vout_thread_t *vout = (vout_thread_t *)object;
281 /* Make sure the vout was stopped first */
282 //assert(!vout->p_module);
284 free(vout->p->splitter_name);
286 /* Destroy the locks */
287 vlc_mutex_destroy(&vout->p->spu_lock);
288 vlc_mutex_destroy(&vout->p->filter.lock);
289 vout_control_Clean(&vout->p->control);
292 vout_statistic_Clean(&vout->p->statistic);
295 vout_snapshot_Clean(&vout->p->snapshot);
297 video_format_Clean(&vout->p->original);
301 void vout_ChangePause(vout_thread_t *vout, bool is_paused, mtime_t date)
303 vout_control_cmd_t cmd;
304 vout_control_cmd_Init(&cmd, VOUT_CONTROL_PAUSE);
305 cmd.u.pause.is_on = is_paused;
306 cmd.u.pause.date = date;
307 vout_control_Push(&vout->p->control, &cmd);
309 vout_control_WaitEmpty(&vout->p->control);
312 void vout_GetResetStatistic(vout_thread_t *vout, int *displayed, int *lost)
314 vout_statistic_GetReset( &vout->p->statistic, displayed, lost );
317 void vout_Flush(vout_thread_t *vout, mtime_t date)
319 vout_control_PushTime(&vout->p->control, VOUT_CONTROL_FLUSH, date);
320 vout_control_WaitEmpty(&vout->p->control);
323 void vout_Reset(vout_thread_t *vout)
325 vout_control_PushVoid(&vout->p->control, VOUT_CONTROL_RESET);
326 vout_control_WaitEmpty(&vout->p->control);
329 bool vout_IsEmpty(vout_thread_t *vout)
331 picture_t *picture = picture_fifo_Peek(vout->p->decoder_fifo);
333 picture_Release(picture);
338 void vout_FixLeaks( vout_thread_t *vout )
340 picture_t *picture = picture_fifo_Peek(vout->p->decoder_fifo);
341 if (picture != NULL) {
342 picture_Release(picture);
343 return; /* Not all pictures has been displayed yet */
347 picture = picture_pool_Get(vout->p->decoder_pool);
350 picture_Release(picture); /* Not all pictures are referenced */
352 /* There are no reasons that no pictures are available, force one
353 * from the pool, be careful with it though */
354 msg_Err(vout, "pictures leaked, trying to workaround");
355 picture_pool_NonEmpty(vout->p->decoder_pool);
359 void vout_NextPicture(vout_thread_t *vout, mtime_t *duration)
361 vout_control_cmd_t cmd;
362 vout_control_cmd_Init(&cmd, VOUT_CONTROL_STEP);
363 cmd.u.time_ptr = duration;
365 vout_control_Push(&vout->p->control, &cmd);
366 vout_control_WaitEmpty(&vout->p->control);
369 void vout_DisplayTitle(vout_thread_t *vout, const char *title)
372 vout_control_PushString(&vout->p->control, VOUT_CONTROL_OSD_TITLE, title);
375 void vout_PutSubpicture( vout_thread_t *vout, subpicture_t *subpic )
377 vout_control_cmd_t cmd;
378 vout_control_cmd_Init(&cmd, VOUT_CONTROL_SUBPICTURE);
379 cmd.u.subpicture = subpic;
381 vout_control_Push(&vout->p->control, &cmd);
383 int vout_RegisterSubpictureChannel( vout_thread_t *vout )
385 int channel = SPU_DEFAULT_CHANNEL;
387 vlc_mutex_lock(&vout->p->spu_lock);
389 channel = spu_RegisterChannel(vout->p->spu);
390 vlc_mutex_unlock(&vout->p->spu_lock);
394 void vout_FlushSubpictureChannel( vout_thread_t *vout, int channel )
396 vout_control_PushInteger(&vout->p->control, VOUT_CONTROL_FLUSH_SUBPICTURE,
401 * It retreives a picture from the vout or NULL if no pictures are
404 * You MUST call vout_PutPicture or picture_Release on it.
406 * You may use picture_Hold() (paired with picture_Release()) to keep a
407 * read-only reference.
409 picture_t *vout_GetPicture(vout_thread_t *vout)
411 picture_t *picture = picture_pool_Get(vout->p->decoder_pool);
413 picture_Reset(picture);
414 VideoFormatCopyCropAr(&picture->format, &vout->p->original);
421 * It gives to the vout a picture to be displayed.
423 * The given picture MUST comes from vout_GetPicture.
425 * Becareful, after vout_PutPicture is called, picture_t::p_next cannot be
428 void vout_PutPicture(vout_thread_t *vout, picture_t *picture)
430 picture->p_next = NULL;
431 picture_fifo_Push(vout->p->decoder_fifo, picture);
433 vout_control_Wake(&vout->p->control);
437 int vout_GetSnapshot(vout_thread_t *vout,
438 block_t **image_dst, picture_t **picture_dst,
440 const char *type, mtime_t timeout)
442 picture_t *picture = vout_snapshot_Get(&vout->p->snapshot, timeout);
444 msg_Err(vout, "Failed to grab a snapshot");
449 vlc_fourcc_t codec = VLC_CODEC_PNG;
450 if (type && image_Type2Fourcc(type))
451 codec = image_Type2Fourcc(type);
453 const int override_width = var_InheritInteger(vout, "snapshot-width");
454 const int override_height = var_InheritInteger(vout, "snapshot-height");
456 if (picture_Export(VLC_OBJECT(vout), image_dst, fmt,
457 picture, codec, override_width, override_height)) {
458 msg_Err(vout, "Failed to convert image for snapshot");
459 picture_Release(picture);
464 *picture_dst = picture;
466 picture_Release(picture);
470 void vout_ChangeAspectRatio( vout_thread_t *p_vout,
471 unsigned int i_num, unsigned int i_den )
473 vout_ControlChangeSampleAspectRatio( p_vout, i_num, i_den );
476 /* vout_Control* are usable by anyone at anytime */
477 void vout_ControlChangeFullscreen(vout_thread_t *vout, bool fullscreen)
479 vout_control_PushBool(&vout->p->control, VOUT_CONTROL_FULLSCREEN,
482 void vout_ControlChangeWindowState(vout_thread_t *vout, unsigned st)
484 vout_control_PushInteger(&vout->p->control, VOUT_CONTROL_WINDOW_STATE, st);
486 void vout_ControlChangeDisplayFilled(vout_thread_t *vout, bool is_filled)
488 vout_control_PushBool(&vout->p->control, VOUT_CONTROL_DISPLAY_FILLED,
491 void vout_ControlChangeZoom(vout_thread_t *vout, int num, int den)
493 vout_control_PushPair(&vout->p->control, VOUT_CONTROL_ZOOM,
496 void vout_ControlChangeSampleAspectRatio(vout_thread_t *vout,
497 unsigned num, unsigned den)
499 vout_control_PushPair(&vout->p->control, VOUT_CONTROL_ASPECT_RATIO,
502 void vout_ControlChangeCropRatio(vout_thread_t *vout,
503 unsigned num, unsigned den)
505 vout_control_PushPair(&vout->p->control, VOUT_CONTROL_CROP_RATIO,
508 void vout_ControlChangeCropWindow(vout_thread_t *vout,
509 int x, int y, int width, int height)
511 vout_control_cmd_t cmd;
512 vout_control_cmd_Init(&cmd, VOUT_CONTROL_CROP_WINDOW);
513 cmd.u.window.x = __MAX(x, 0);
514 cmd.u.window.y = __MAX(y, 0);
515 cmd.u.window.width = __MAX(width, 0);
516 cmd.u.window.height = __MAX(height, 0);
518 vout_control_Push(&vout->p->control, &cmd);
520 void vout_ControlChangeCropBorder(vout_thread_t *vout,
521 int left, int top, int right, int bottom)
523 vout_control_cmd_t cmd;
524 vout_control_cmd_Init(&cmd, VOUT_CONTROL_CROP_BORDER);
525 cmd.u.border.left = __MAX(left, 0);
526 cmd.u.border.top = __MAX(top, 0);
527 cmd.u.border.right = __MAX(right, 0);
528 cmd.u.border.bottom = __MAX(bottom, 0);
530 vout_control_Push(&vout->p->control, &cmd);
532 void vout_ControlChangeFilters(vout_thread_t *vout, const char *filters)
534 vout_control_PushString(&vout->p->control, VOUT_CONTROL_CHANGE_FILTERS,
537 void vout_ControlChangeSubSources(vout_thread_t *vout, const char *filters)
539 vout_control_PushString(&vout->p->control, VOUT_CONTROL_CHANGE_SUB_SOURCES,
542 void vout_ControlChangeSubFilters(vout_thread_t *vout, const char *filters)
544 vout_control_PushString(&vout->p->control, VOUT_CONTROL_CHANGE_SUB_FILTERS,
547 void vout_ControlChangeSubMargin(vout_thread_t *vout, int margin)
549 vout_control_PushInteger(&vout->p->control, VOUT_CONTROL_CHANGE_SUB_MARGIN,
554 static void VoutGetDisplayCfg(vout_thread_t *vout, vout_display_cfg_t *cfg, const char *title)
556 /* Load configuration */
557 cfg->is_fullscreen = var_CreateGetBool(vout, "fullscreen")
558 || var_InheritBool(vout, "video-wallpaper");
559 cfg->display.title = title;
560 const int display_width = var_CreateGetInteger(vout, "width");
561 const int display_height = var_CreateGetInteger(vout, "height");
562 cfg->display.width = display_width > 0 ? display_width : 0;
563 cfg->display.height = display_height > 0 ? display_height : 0;
564 cfg->is_display_filled = var_CreateGetBool(vout, "autoscale");
565 unsigned msar_num, msar_den;
566 if (var_InheritURational(vout, &msar_num, &msar_den, "monitor-par") ||
567 msar_num <= 0 || msar_den <= 0) {
571 cfg->display.sar.num = msar_num;
572 cfg->display.sar.den = msar_den;
573 unsigned zoom_den = 1000;
574 unsigned zoom_num = zoom_den * var_CreateGetFloat(vout, "zoom");
575 vlc_ureduce(&zoom_num, &zoom_den, zoom_num, zoom_den, 0);
576 cfg->zoom.num = zoom_num;
577 cfg->zoom.den = zoom_den;
578 cfg->align.vertical = VOUT_DISPLAY_ALIGN_CENTER;
579 cfg->align.horizontal = VOUT_DISPLAY_ALIGN_CENTER;
580 const int align_mask = var_CreateGetInteger(vout, "align");
581 if (align_mask & 0x1)
582 cfg->align.horizontal = VOUT_DISPLAY_ALIGN_LEFT;
583 else if (align_mask & 0x2)
584 cfg->align.horizontal = VOUT_DISPLAY_ALIGN_RIGHT;
585 if (align_mask & 0x4)
586 cfg->align.vertical = VOUT_DISPLAY_ALIGN_TOP;
587 else if (align_mask & 0x8)
588 cfg->align.vertical = VOUT_DISPLAY_ALIGN_BOTTOM;
591 vout_window_t *vout_NewDisplayWindow(vout_thread_t *vout, unsigned type)
593 vout_window_t *window = vout->p->window;
595 assert(vout->p->splitter_name == NULL);
599 if (type != VOUT_WINDOW_TYPE_INVALID && type != window->type)
604 void vout_DeleteDisplayWindow(vout_thread_t *vout, vout_window_t *window)
606 if (window == NULL && vout->p->window != NULL) {
607 vout_display_window_Delete(vout->p->window);
608 vout->p->window = NULL;
610 assert(vout->p->window == window);
613 void vout_SetDisplayWindowSize(vout_thread_t *vout,
614 unsigned width, unsigned height)
616 vout_window_t *window = vout->p->window;
619 /* Request a resize of the window. If it fails, there is nothing to do.
620 * If it succeeds, the window will emit a resize event later. */
621 vout_window_SetSize(window, width, height);
623 if (vout->p->display.vd != NULL)
624 /* Force a resize of window-less display. This is not allowed to fail,
625 * although the display is allowed to ignore the size anyway. */
626 /* FIXME: remove this, fix MSW and OS/2 window providers */
627 vout_display_SendEventDisplaySize(vout->p->display.vd, width, height);
631 static picture_t *VoutVideoFilterInteractiveNewPicture(filter_t *filter)
633 vout_thread_t *vout = filter->owner.sys;
635 picture_t *picture = picture_pool_Get(vout->p->private_pool);
637 picture_Reset(picture);
638 VideoFormatCopyCropAr(&picture->format, &filter->fmt_out.video);
643 static picture_t *VoutVideoFilterStaticNewPicture(filter_t *filter)
645 vout_thread_t *vout = filter->owner.sys;
647 vlc_assert_locked(&vout->p->filter.lock);
648 if (filter_chain_GetLength(vout->p->filter.chain_interactive) == 0)
649 return VoutVideoFilterInteractiveNewPicture(filter);
651 return picture_NewFromFormat(&filter->fmt_out.video);
654 static void ThreadFilterFlush(vout_thread_t *vout, bool is_locked)
656 if (vout->p->displayed.current)
657 picture_Release( vout->p->displayed.current );
658 vout->p->displayed.current = NULL;
660 if (vout->p->displayed.next)
661 picture_Release( vout->p->displayed.next );
662 vout->p->displayed.next = NULL;
665 vlc_mutex_lock(&vout->p->filter.lock);
666 filter_chain_VideoFlush(vout->p->filter.chain_static);
667 filter_chain_VideoFlush(vout->p->filter.chain_interactive);
669 vlc_mutex_unlock(&vout->p->filter.lock);
677 static void ThreadChangeFilters(vout_thread_t *vout,
678 const video_format_t *source,
682 ThreadFilterFlush(vout, is_locked);
684 vlc_array_t array_static;
685 vlc_array_t array_interactive;
687 vlc_array_init(&array_static);
688 vlc_array_init(&array_interactive);
689 char *current = filters ? strdup(filters) : NULL;
693 char *next = config_ChainCreate(&name, &cfg, current);
696 vout_filter_t *e = xmalloc(sizeof(*e));
699 if (!strcmp(e->name, "deinterlace") ||
700 !strcmp(e->name, "postproc")) {
701 vlc_array_append(&array_static, e);
703 vlc_array_append(&array_interactive, e);
707 config_ChainDestroy(cfg);
715 vlc_mutex_lock(&vout->p->filter.lock);
717 es_format_t fmt_target;
718 es_format_InitFromVideo(&fmt_target, source ? source : &vout->p->filter.format);
720 es_format_t fmt_current = fmt_target;
722 for (int a = 0; a < 2; a++) {
723 vlc_array_t *array = a == 0 ? &array_static :
725 filter_chain_t *chain = a == 0 ? vout->p->filter.chain_static :
726 vout->p->filter.chain_interactive;
728 filter_chain_Reset(chain, &fmt_current, &fmt_current);
729 for (int i = 0; i < vlc_array_count(array); i++) {
730 vout_filter_t *e = vlc_array_item_at_index(array, i);
731 msg_Dbg(vout, "Adding '%s' as %s", e->name, a == 0 ? "static" : "interactive");
732 if (!filter_chain_AppendFilter(chain, e->name, e->cfg, NULL, NULL)) {
733 msg_Err(vout, "Failed to add filter '%s'", e->name);
734 config_ChainDestroy(e->cfg);
739 fmt_current = *filter_chain_GetFmtOut(chain);
740 vlc_array_clear(array);
743 if (!es_format_IsSimilar(&fmt_current, &fmt_target)) {
744 msg_Dbg(vout, "Adding a filter to compensate for format changes");
745 if (!filter_chain_AppendFilter(vout->p->filter.chain_interactive, NULL, NULL,
746 &fmt_current, &fmt_target)) {
747 msg_Err(vout, "Failed to compensate for the format changes, removing all filters");
748 filter_chain_Reset(vout->p->filter.chain_static, &fmt_target, &fmt_target);
749 filter_chain_Reset(vout->p->filter.chain_interactive, &fmt_target, &fmt_target);
753 es_format_Clean(&fmt_target);
755 if (vout->p->filter.configuration != filters) {
756 free(vout->p->filter.configuration);
757 vout->p->filter.configuration = filters ? strdup(filters) : NULL;
760 video_format_Clean(&vout->p->filter.format);
761 video_format_Copy(&vout->p->filter.format, source);
765 vlc_mutex_unlock(&vout->p->filter.lock);
770 static int ThreadDisplayPreparePicture(vout_thread_t *vout, bool reuse, bool frame_by_frame)
772 bool is_late_dropped = vout->p->is_late_dropped && !vout->p->pause.is_on && !frame_by_frame;
774 vlc_mutex_lock(&vout->p->filter.lock);
776 picture_t *picture = filter_chain_VideoFilter(vout->p->filter.chain_static, NULL);
777 assert(!reuse || !picture);
781 if (reuse && vout->p->displayed.decoded) {
782 decoded = picture_Hold(vout->p->displayed.decoded);
784 decoded = picture_fifo_Pop(vout->p->decoder_fifo);
786 if (is_late_dropped && !decoded->b_force) {
787 const mtime_t predicted = mdate() + 0; /* TODO improve */
788 const mtime_t late = predicted - decoded->date;
789 if (late > VOUT_DISPLAY_LATE_THRESHOLD) {
790 msg_Warn(vout, "picture is too late to be displayed (missing %"PRId64" ms)", late/1000);
791 picture_Release(decoded);
792 vout_statistic_AddLost(&vout->p->statistic, 1);
794 } else if (late > 0) {
795 msg_Dbg(vout, "picture might be displayed late (missing %"PRId64" ms)", late/1000);
798 if (!VideoFormatIsCropArEqual(&decoded->format, &vout->p->filter.format))
799 ThreadChangeFilters(vout, &decoded->format, vout->p->filter.configuration, true);
807 if (vout->p->displayed.decoded)
808 picture_Release(vout->p->displayed.decoded);
810 vout->p->displayed.decoded = picture_Hold(decoded);
811 vout->p->displayed.timestamp = decoded->date;
812 vout->p->displayed.is_interlaced = !decoded->b_progressive;
814 picture = filter_chain_VideoFilter(vout->p->filter.chain_static, decoded);
817 vlc_mutex_unlock(&vout->p->filter.lock);
822 assert(!vout->p->displayed.next);
823 if (!vout->p->displayed.current)
824 vout->p->displayed.current = picture;
826 vout->p->displayed.next = picture;
830 static int ThreadDisplayRenderPicture(vout_thread_t *vout, bool is_forced)
832 vout_thread_sys_t *sys = vout->p;
833 vout_display_t *vd = vout->p->display.vd;
835 picture_t *torender = picture_Hold(vout->p->displayed.current);
837 vout_chrono_Start(&vout->p->render);
839 vlc_mutex_lock(&vout->p->filter.lock);
840 picture_t *filtered = filter_chain_VideoFilter(vout->p->filter.chain_interactive, torender);
841 vlc_mutex_unlock(&vout->p->filter.lock);
846 if (filtered->date != vout->p->displayed.current->date)
847 msg_Warn(vout, "Unsupported timestamp modifications done by chain_interactive");
850 * Get the subpicture to be displayed
852 const bool do_snapshot = vout_snapshot_IsRequested(&vout->p->snapshot);
853 mtime_t render_subtitle_date;
854 if (vout->p->pause.is_on)
855 render_subtitle_date = vout->p->pause.date;
857 render_subtitle_date = filtered->date > 1 ? filtered->date : mdate();
858 mtime_t render_osd_date = mdate(); /* FIXME wrong */
861 * Get the subpicture to be displayed
863 const bool do_dr_spu = !do_snapshot &&
864 vd->info.subpicture_chromas &&
865 *vd->info.subpicture_chromas != 0;
867 //FIXME: Denying do_early_spu if vd->source.orientation != ORIENT_NORMAL
868 //will have the effect that snapshots miss the subpictures. We do this
869 //because there is currently no way to transform subpictures to match
871 const bool do_early_spu = !do_dr_spu &&
872 vd->source.orientation == ORIENT_NORMAL &&
874 sys->display.use_dr ||
876 !vout_IsDisplayFiltered(vd) ||
877 vd->fmt.i_width * vd->fmt.i_height <= vd->source.i_width * vd->source.i_height);
879 const vlc_fourcc_t *subpicture_chromas;
880 video_format_t fmt_spu;
882 vout_display_place_t place;
883 vout_display_PlacePicture(&place, &vd->source, vd->cfg, false);
885 fmt_spu = vd->source;
886 if (fmt_spu.i_width * fmt_spu.i_height < place.width * place.height) {
887 fmt_spu.i_sar_num = vd->cfg->display.sar.num;
888 fmt_spu.i_sar_den = vd->cfg->display.sar.den;
890 fmt_spu.i_visible_width = place.width;
892 fmt_spu.i_visible_height = place.height;
894 subpicture_chromas = vd->info.subpicture_chromas;
897 fmt_spu = vd->source;
900 fmt_spu.i_sar_num = vd->cfg->display.sar.num;
901 fmt_spu.i_sar_den = vd->cfg->display.sar.den;
903 subpicture_chromas = NULL;
905 if (vout->p->spu_blend &&
906 vout->p->spu_blend->fmt_out.video.i_chroma != fmt_spu.i_chroma) {
907 filter_DeleteBlend(vout->p->spu_blend);
908 vout->p->spu_blend = NULL;
909 vout->p->spu_blend_chroma = 0;
911 if (!vout->p->spu_blend && vout->p->spu_blend_chroma != fmt_spu.i_chroma) {
912 vout->p->spu_blend_chroma = fmt_spu.i_chroma;
913 vout->p->spu_blend = filter_NewBlend(VLC_OBJECT(vout), &fmt_spu);
914 if (!vout->p->spu_blend)
915 msg_Err(vout, "Failed to create blending filter, OSD/Subtitles will not work");
919 video_format_t fmt_spu_rot;
920 video_format_ApplyRotation(&fmt_spu_rot, &fmt_spu);
921 subpicture_t *subpic = spu_Render(vout->p->spu,
922 subpicture_chromas, &fmt_spu_rot,
924 render_subtitle_date, render_osd_date,
930 * - be sure to end up with a direct buffer.
931 * - blend subtitles, and in a fast access buffer
933 bool is_direct = vout->p->decoder_pool == vout->p->display_pool;
934 picture_t *todisplay = filtered;
935 if (do_early_spu && subpic) {
936 picture_t *blent = picture_pool_Get(vout->p->private_pool);
938 VideoFormatCopyCropAr(&blent->format, &filtered->format);
939 picture_Copy(blent, filtered);
940 if (vout->p->spu_blend
941 && picture_BlendSubpicture(blent, vout->p->spu_blend, subpic)) {
942 picture_Release(todisplay);
945 picture_Release(blent);
947 subpicture_Delete(subpic);
951 assert(vout_IsDisplayFiltered(vd) == !sys->display.use_dr);
952 if (sys->display.use_dr && !is_direct) {
953 picture_t *direct = picture_pool_Get(vout->p->display_pool);
955 picture_Release(todisplay);
957 subpicture_Delete(subpic);
961 /* The display uses direct rendering (no conversion), but its pool of
962 * pictures is not usable by the decoder (too few, too slow or
963 * subject to invalidation...). Since there are no filters, copying
964 * pictures from the decoder to the output is unavoidable. */
965 VideoFormatCopyCropAr(&direct->format, &todisplay->format);
966 picture_Copy(direct, todisplay);
967 picture_Release(todisplay);
972 * Take a snapshot if requested
975 vout_snapshot_Set(&vout->p->snapshot, &vd->source, todisplay);
977 /* Render the direct buffer */
978 vout_UpdateDisplaySourceProperties(vd, &todisplay->format);
979 if (sys->display.use_dr) {
980 vout_display_Prepare(vd, todisplay, subpic);
982 sys->display.filtered = vout_FilterDisplay(vd, todisplay);
983 if (sys->display.filtered) {
984 if (!do_dr_spu && !do_early_spu && vout->p->spu_blend && subpic)
985 picture_BlendSubpicture(sys->display.filtered, vout->p->spu_blend, subpic);
986 vout_display_Prepare(vd, sys->display.filtered, do_dr_spu ? subpic : NULL);
988 if (!do_dr_spu && subpic)
990 subpicture_Delete(subpic);
993 if (!sys->display.filtered)
997 vout_chrono_Stop(&vout->p->render);
1001 if (((i++)%10) == 0)
1002 msg_Info(vout, "render: avg %d ms var %d ms",
1003 (int)(vout->p->render.avg/1000), (int)(vout->p->render.var/1000));
1007 /* Wait the real date (for rendering jitter) */
1009 mtime_t delay = direct->date - mdate();
1011 msg_Warn(vout, "picture is late (%lld ms)", delay / 1000);
1014 mwait(todisplay->date);
1016 /* Display the direct buffer returned by vout_RenderPicture */
1017 vout->p->displayed.date = mdate();
1018 vout_display_Display(vd,
1019 sys->display.filtered ? sys->display.filtered
1022 sys->display.filtered = NULL;
1024 vout_statistic_AddDisplayed(&vout->p->statistic, 1);
1029 static int ThreadDisplayPicture(vout_thread_t *vout, mtime_t *deadline)
1031 bool frame_by_frame = !deadline;
1032 bool paused = vout->p->pause.is_on;
1033 bool first = !vout->p->displayed.current;
1036 if (ThreadDisplayPreparePicture(vout, true, frame_by_frame)) /* FIXME not sure it is ok */
1037 return VLC_EGENERIC;
1039 if (!paused || frame_by_frame)
1040 while (!vout->p->displayed.next && !ThreadDisplayPreparePicture(vout, false, frame_by_frame))
1043 const mtime_t date = mdate();
1044 const mtime_t render_delay = vout_chrono_GetHigh(&vout->p->render) + VOUT_MWAIT_TOLERANCE;
1046 bool drop_next_frame = frame_by_frame;
1047 mtime_t date_next = VLC_TS_INVALID;
1048 if (!paused && vout->p->displayed.next) {
1049 date_next = vout->p->displayed.next->date - render_delay;
1050 if (date_next /* + 0 FIXME */ <= date)
1051 drop_next_frame = true;
1054 /* FIXME/XXX we must redisplay the last decoded picture (because
1055 * of potential vout updated, or filters update or SPU update)
1056 * For now a high update period is needed but it could be removed
1058 * - vout module emits events from theselves.
1059 * - *and* SPU is modified to emit an event or a deadline when needed.
1061 * So it will be done later.
1063 bool refresh = false;
1065 mtime_t date_refresh = VLC_TS_INVALID;
1066 if (vout->p->displayed.date > VLC_TS_INVALID) {
1067 date_refresh = vout->p->displayed.date + VOUT_REDISPLAY_DELAY - render_delay;
1068 refresh = date_refresh <= date;
1070 bool force_refresh = !drop_next_frame && refresh;
1072 if (!first && !refresh && !drop_next_frame) {
1073 if (!frame_by_frame) {
1074 if (date_refresh != VLC_TS_INVALID)
1075 *deadline = date_refresh;
1076 if (date_next != VLC_TS_INVALID && date_next < *deadline)
1077 *deadline = date_next;
1079 return VLC_EGENERIC;
1082 if (drop_next_frame) {
1083 picture_Release(vout->p->displayed.current);
1084 vout->p->displayed.current = vout->p->displayed.next;
1085 vout->p->displayed.next = NULL;
1088 if (!vout->p->displayed.current)
1089 return VLC_EGENERIC;
1091 /* display the picture immediately */
1092 bool is_forced = frame_by_frame || force_refresh || vout->p->displayed.current->b_force;
1093 int ret = ThreadDisplayRenderPicture(vout, is_forced);
1094 return force_refresh ? VLC_EGENERIC : ret;
1097 static void ThreadDisplaySubpicture(vout_thread_t *vout,
1098 subpicture_t *subpicture)
1100 spu_PutSubpicture(vout->p->spu, subpicture);
1103 static void ThreadFlushSubpicture(vout_thread_t *vout, int channel)
1105 spu_ClearChannel(vout->p->spu, channel);
1108 static void ThreadDisplayOsdTitle(vout_thread_t *vout, const char *string)
1110 if (!vout->p->title.show)
1113 vout_OSDText(vout, SPU_DEFAULT_CHANNEL,
1114 vout->p->title.position, INT64_C(1000) * vout->p->title.timeout,
1118 static void ThreadChangeSubSources(vout_thread_t *vout, const char *filters)
1120 spu_ChangeSources(vout->p->spu, filters);
1123 static void ThreadChangeSubFilters(vout_thread_t *vout, const char *filters)
1125 spu_ChangeFilters(vout->p->spu, filters);
1128 static void ThreadChangeSubMargin(vout_thread_t *vout, int margin)
1130 spu_ChangeMargin(vout->p->spu, margin);
1133 static void ThreadChangePause(vout_thread_t *vout, bool is_paused, mtime_t date)
1135 assert(!vout->p->pause.is_on || !is_paused);
1137 if (vout->p->pause.is_on) {
1138 const mtime_t duration = date - vout->p->pause.date;
1140 if (vout->p->step.timestamp > VLC_TS_INVALID)
1141 vout->p->step.timestamp += duration;
1142 if (vout->p->step.last > VLC_TS_INVALID)
1143 vout->p->step.last += duration;
1144 picture_fifo_OffsetDate(vout->p->decoder_fifo, duration);
1145 if (vout->p->displayed.decoded)
1146 vout->p->displayed.decoded->date += duration;
1147 spu_OffsetSubtitleDate(vout->p->spu, duration);
1149 ThreadFilterFlush(vout, false);
1151 vout->p->step.timestamp = VLC_TS_INVALID;
1152 vout->p->step.last = VLC_TS_INVALID;
1154 vout->p->pause.is_on = is_paused;
1155 vout->p->pause.date = date;
1158 static void ThreadFlush(vout_thread_t *vout, bool below, mtime_t date)
1160 vout->p->step.timestamp = VLC_TS_INVALID;
1161 vout->p->step.last = VLC_TS_INVALID;
1163 ThreadFilterFlush(vout, false); /* FIXME too much */
1165 picture_t *last = vout->p->displayed.decoded;
1167 if (( below && last->date <= date) ||
1168 (!below && last->date >= date)) {
1169 picture_Release(last);
1171 vout->p->displayed.decoded = NULL;
1172 vout->p->displayed.date = VLC_TS_INVALID;
1173 vout->p->displayed.timestamp = VLC_TS_INVALID;
1177 picture_fifo_Flush(vout->p->decoder_fifo, date, below);
1180 static void ThreadReset(vout_thread_t *vout)
1182 ThreadFlush(vout, true, INT64_MAX);
1183 if (vout->p->decoder_pool) {
1184 unsigned count, leaks;
1186 if (vout->p->private_pool != NULL) {
1187 count = picture_pool_GetSize(vout->p->private_pool);
1188 picture_pool_Release(vout->p->private_pool);
1191 leaks = picture_pool_Reset(vout->p->decoder_pool);
1193 msg_Err(vout, "%u picture(s) leaked by decoder", leaks);
1195 if (vout->p->private_pool != NULL) {
1196 vout->p->private_pool = picture_pool_Reserve(vout->p->decoder_pool,
1198 if (vout->p->private_pool == NULL)
1202 vout->p->pause.is_on = false;
1203 vout->p->pause.date = mdate();
1206 static void ThreadStep(vout_thread_t *vout, mtime_t *duration)
1210 if (vout->p->step.last <= VLC_TS_INVALID)
1211 vout->p->step.last = vout->p->displayed.timestamp;
1213 if (ThreadDisplayPicture(vout, NULL))
1216 vout->p->step.timestamp = vout->p->displayed.timestamp;
1218 if (vout->p->step.last > VLC_TS_INVALID &&
1219 vout->p->step.timestamp > vout->p->step.last) {
1220 *duration = vout->p->step.timestamp - vout->p->step.last;
1221 vout->p->step.last = vout->p->step.timestamp;
1222 /* TODO advance subpicture by the duration ... */
1226 static void ThreadChangeFullscreen(vout_thread_t *vout, bool fullscreen)
1228 vout_window_t *window = vout->p->window;
1231 vout_window_SetFullScreen(window, fullscreen);
1233 if (vout->p->display.vd != NULL)
1234 vout_display_SendEvent(vout->p->display.vd,
1235 VOUT_DISPLAY_EVENT_FULLSCREEN, fullscreen);
1238 static void ThreadChangeWindowState(vout_thread_t *vout, unsigned state)
1240 vout_window_t *window = vout->p->window;
1243 vout_window_SetState(window, state);
1244 #if defined(_WIN32) || defined(__OS2__)
1245 else /* FIXME: remove this event */
1246 if (vout->p->display.vd != NULL)
1247 vout_display_SendEvent(vout->p->display.vd,
1248 VOUT_DISPLAY_EVENT_WINDOW_STATE, state);
1252 static void ThreadChangeDisplayFilled(vout_thread_t *vout, bool is_filled)
1254 vout_SetDisplayFilled(vout->p->display.vd, is_filled);
1257 static void ThreadChangeZoom(vout_thread_t *vout, int num, int den)
1259 if (num * 10 < den) {
1262 } else if (num > den * 10) {
1266 vout_SetDisplayZoom(vout->p->display.vd, num, den);
1269 static void ThreadChangeAspectRatio(vout_thread_t *vout,
1270 unsigned num, unsigned den)
1272 vout_SetDisplayAspect(vout->p->display.vd, num, den);
1276 static void ThreadExecuteCropWindow(vout_thread_t *vout,
1277 unsigned x, unsigned y,
1278 unsigned width, unsigned height)
1280 vout_SetDisplayCrop(vout->p->display.vd, 0, 0,
1281 x, y, width, height);
1283 static void ThreadExecuteCropBorder(vout_thread_t *vout,
1284 unsigned left, unsigned top,
1285 unsigned right, unsigned bottom)
1287 msg_Err(vout, "ThreadExecuteCropBorder %d.%d %dx%d", left, top, right, bottom);
1288 vout_SetDisplayCrop(vout->p->display.vd, 0, 0,
1289 left, top, -(int)right, -(int)bottom);
1292 static void ThreadExecuteCropRatio(vout_thread_t *vout,
1293 unsigned num, unsigned den)
1295 vout_SetDisplayCrop(vout->p->display.vd, num, den,
1299 static int ThreadStart(vout_thread_t *vout, const vout_display_state_t *state)
1301 vlc_mouse_Init(&vout->p->mouse);
1302 vout->p->decoder_fifo = picture_fifo_New();
1303 vout->p->decoder_pool = NULL;
1304 vout->p->display_pool = NULL;
1305 vout->p->private_pool = NULL;
1307 vout->p->filter.configuration = NULL;
1308 video_format_Copy(&vout->p->filter.format, &vout->p->original);
1310 filter_owner_t owner = {
1313 .buffer_new = VoutVideoFilterStaticNewPicture,
1316 vout->p->filter.chain_static =
1317 filter_chain_NewVideo( vout, true, &owner );
1319 owner.video.buffer_new = VoutVideoFilterInteractiveNewPicture;
1320 vout->p->filter.chain_interactive =
1321 filter_chain_NewVideo( vout, true, &owner );
1323 vout_display_state_t state_default;
1325 VoutGetDisplayCfg(vout, &state_default.cfg, vout->p->display.title);
1327 #if defined(_WIN32) || defined(__OS2__)
1328 bool below = var_InheritBool(vout, "video-wallpaper");
1329 bool above = var_InheritBool(vout, "video-on-top");
1331 state_default.wm_state = below ? VOUT_WINDOW_STATE_BELOW
1332 : above ? VOUT_WINDOW_STATE_ABOVE
1333 : VOUT_WINDOW_STATE_NORMAL;
1335 state_default.sar.num = 0;
1336 state_default.sar.den = 0;
1338 state = &state_default;
1341 if (vout_OpenWrapper(vout, vout->p->splitter_name, state))
1342 return VLC_EGENERIC;
1343 if (vout_InitWrapper(vout))
1344 return VLC_EGENERIC;
1345 assert(vout->p->decoder_pool);
1347 vout->p->displayed.current = NULL;
1348 vout->p->displayed.next = NULL;
1349 vout->p->displayed.decoded = NULL;
1350 vout->p->displayed.date = VLC_TS_INVALID;
1351 vout->p->displayed.timestamp = VLC_TS_INVALID;
1352 vout->p->displayed.is_interlaced = false;
1354 vout->p->step.last = VLC_TS_INVALID;
1355 vout->p->step.timestamp = VLC_TS_INVALID;
1357 vout->p->spu_blend_chroma = 0;
1358 vout->p->spu_blend = NULL;
1360 video_format_Print(VLC_OBJECT(vout), "original format", &vout->p->original);
1364 static void ThreadStop(vout_thread_t *vout, vout_display_state_t *state)
1366 if (vout->p->spu_blend)
1367 filter_DeleteBlend(vout->p->spu_blend);
1369 /* Destroy translation tables */
1370 if (vout->p->display.vd) {
1371 if (vout->p->decoder_pool) {
1372 ThreadFlush(vout, true, INT64_MAX);
1373 vout_EndWrapper(vout);
1375 vout_CloseWrapper(vout, state);
1378 /* Destroy the video filters2 */
1379 filter_chain_Delete(vout->p->filter.chain_interactive);
1380 filter_chain_Delete(vout->p->filter.chain_static);
1381 video_format_Clean(&vout->p->filter.format);
1382 free(vout->p->filter.configuration);
1384 if (vout->p->decoder_fifo)
1385 picture_fifo_Delete(vout->p->decoder_fifo);
1386 assert(!vout->p->decoder_pool);
1389 static void ThreadInit(vout_thread_t *vout)
1391 vout->p->dead = false;
1392 vout->p->is_late_dropped = var_InheritBool(vout, "drop-late-frames");
1393 vout->p->pause.is_on = false;
1394 vout->p->pause.date = VLC_TS_INVALID;
1396 vout_chrono_Init(&vout->p->render, 5, 10000); /* Arbitrary initial time */
1399 static void ThreadClean(vout_thread_t *vout)
1401 if (vout->p->window != NULL)
1402 vout_window_Delete(vout->p->window);
1403 vout_chrono_Clean(&vout->p->render);
1404 vout->p->dead = true;
1405 vout_control_Dead(&vout->p->control);
1408 static int ThreadReinit(vout_thread_t *vout,
1409 const vout_configuration_t *cfg)
1411 video_format_t original;
1412 if (VoutValidateFormat(&original, cfg->fmt)) {
1413 ThreadStop(vout, NULL);
1415 return VLC_EGENERIC;
1417 /* We ignore crop/ar changes at this point, they are dynamically supported */
1418 VideoFormatCopyCropAr(&vout->p->original, &original);
1419 if (video_format_IsSimilar(&original, &vout->p->original)) {
1420 if (cfg->dpb_size <= vout->p->dpb_size) {
1421 video_format_Clean(&original);
1424 msg_Warn(vout, "DPB need to be increased");
1427 vout_display_state_t state;
1428 memset(&state, 0, sizeof(state));
1430 ThreadStop(vout, &state);
1432 if (!state.cfg.is_fullscreen) {
1433 state.cfg.display.width = 0;
1434 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 */
1441 if (state.cfg.display.sar.num <= 0 || state.cfg.display.sar.den <= 0) {
1442 state.cfg.display.sar.num = 1;
1443 state.cfg.display.sar.den = 1;
1445 if (state.cfg.zoom.num <= 0 || state.cfg.zoom.den <= 0) {
1446 state.cfg.zoom.num = 1;
1447 state.cfg.zoom.den = 1;
1450 vout->p->original = original;
1451 vout->p->dpb_size = cfg->dpb_size;
1452 if (ThreadStart(vout, &state)) {
1454 return VLC_EGENERIC;
1459 static int ThreadControl(vout_thread_t *vout, vout_control_cmd_t cmd)
1462 case VOUT_CONTROL_INIT:
1464 if (!ThreadStart(vout, NULL))
1466 case VOUT_CONTROL_CLEAN:
1467 ThreadStop(vout, NULL);
1470 case VOUT_CONTROL_REINIT:
1471 if (ThreadReinit(vout, cmd.u.cfg))
1474 case VOUT_CONTROL_SUBPICTURE:
1475 ThreadDisplaySubpicture(vout, cmd.u.subpicture);
1476 cmd.u.subpicture = NULL;
1478 case VOUT_CONTROL_FLUSH_SUBPICTURE:
1479 ThreadFlushSubpicture(vout, cmd.u.integer);
1481 case VOUT_CONTROL_OSD_TITLE:
1482 ThreadDisplayOsdTitle(vout, cmd.u.string);
1484 case VOUT_CONTROL_CHANGE_FILTERS:
1485 ThreadChangeFilters(vout, NULL, cmd.u.string, false);
1487 case VOUT_CONTROL_CHANGE_SUB_SOURCES:
1488 ThreadChangeSubSources(vout, cmd.u.string);
1490 case VOUT_CONTROL_CHANGE_SUB_FILTERS:
1491 ThreadChangeSubFilters(vout, cmd.u.string);
1493 case VOUT_CONTROL_CHANGE_SUB_MARGIN:
1494 ThreadChangeSubMargin(vout, cmd.u.integer);
1496 case VOUT_CONTROL_PAUSE:
1497 ThreadChangePause(vout, cmd.u.pause.is_on, cmd.u.pause.date);
1499 case VOUT_CONTROL_FLUSH:
1500 ThreadFlush(vout, false, cmd.u.time);
1502 case VOUT_CONTROL_RESET:
1505 case VOUT_CONTROL_STEP:
1506 ThreadStep(vout, cmd.u.time_ptr);
1508 case VOUT_CONTROL_FULLSCREEN:
1509 ThreadChangeFullscreen(vout, cmd.u.boolean);
1511 case VOUT_CONTROL_WINDOW_STATE:
1512 ThreadChangeWindowState(vout, cmd.u.integer);
1514 case VOUT_CONTROL_DISPLAY_FILLED:
1515 ThreadChangeDisplayFilled(vout, cmd.u.boolean);
1517 case VOUT_CONTROL_ZOOM:
1518 ThreadChangeZoom(vout, cmd.u.pair.a, cmd.u.pair.b);
1520 case VOUT_CONTROL_ASPECT_RATIO:
1521 ThreadChangeAspectRatio(vout, cmd.u.pair.a, cmd.u.pair.b);
1523 case VOUT_CONTROL_CROP_RATIO:
1524 ThreadExecuteCropRatio(vout, cmd.u.pair.a, cmd.u.pair.b);
1526 case VOUT_CONTROL_CROP_WINDOW:
1527 ThreadExecuteCropWindow(vout,
1528 cmd.u.window.x, cmd.u.window.y,
1529 cmd.u.window.width, cmd.u.window.height);
1531 case VOUT_CONTROL_CROP_BORDER:
1532 ThreadExecuteCropBorder(vout,
1533 cmd.u.border.left, cmd.u.border.top,
1534 cmd.u.border.right, cmd.u.border.bottom);
1539 vout_control_cmd_Clean(&cmd);
1543 /*****************************************************************************
1544 * Thread: video output thread
1545 *****************************************************************************
1546 * Video output thread. This function does only returns when the thread is
1547 * terminated. It handles the pictures arriving in the video heap and the
1548 * display device events.
1549 *****************************************************************************/
1550 static void *Thread(void *object)
1552 vout_thread_t *vout = object;
1553 vout_thread_sys_t *sys = vout->p;
1555 vout_interlacing_support_t interlacing = {
1556 .is_interlaced = false,
1560 mtime_t deadline = VLC_TS_INVALID;
1562 vout_control_cmd_t cmd;
1563 /* FIXME remove thoses ugly timeouts */
1564 while (!vout_control_Pop(&sys->control, &cmd, deadline, 100000))
1565 if (ThreadControl(vout, cmd))
1568 deadline = VLC_TS_INVALID;
1569 while (!ThreadDisplayPicture(vout, &deadline))
1572 const bool picture_interlaced = sys->displayed.is_interlaced;
1574 vout_SetInterlacingState(vout, &interlacing, picture_interlaced);
1575 vout_ManageWrapper(vout);