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"
54 /*****************************************************************************
56 *****************************************************************************/
57 static void *Thread(void *);
58 static void VoutDestructor(vlc_object_t *);
60 /* Maximum delay between 2 displayed pictures.
61 * XXX it is needed for now but should be removed in the long term.
63 #define VOUT_REDISPLAY_DELAY (INT64_C(80000))
66 * Late pictures having a delay higher than this value are thrashed.
68 #define VOUT_DISPLAY_LATE_THRESHOLD (INT64_C(20000))
70 /* Better be in advance when awakening than late... */
71 #define VOUT_MWAIT_TOLERANCE (INT64_C(4000))
74 static int VoutValidateFormat(video_format_t *dst,
75 const video_format_t *src)
77 if (src->i_width <= 0 || src->i_width > 8192 ||
78 src->i_height <= 0 || src->i_height > 8192)
80 if (src->i_sar_num <= 0 || src->i_sar_den <= 0)
84 video_format_Copy(dst, src);
85 dst->i_chroma = vlc_fourcc_GetCodec(VIDEO_ES, src->i_chroma);
86 vlc_ureduce( &dst->i_sar_num, &dst->i_sar_den,
87 src->i_sar_num, src->i_sar_den, 50000 );
88 if (dst->i_sar_num <= 0 || dst->i_sar_den <= 0) {
92 video_format_FixRgb(dst);
95 static void VideoFormatCopyCropAr(video_format_t *dst,
96 const video_format_t *src)
98 video_format_CopyCrop(dst, src);
99 dst->i_sar_num = src->i_sar_num;
100 dst->i_sar_den = src->i_sar_den;
102 static bool VideoFormatIsCropArEqual(video_format_t *dst,
103 const video_format_t *src)
105 return dst->i_sar_num * src->i_sar_den == dst->i_sar_den * src->i_sar_num &&
106 dst->i_x_offset == src->i_x_offset &&
107 dst->i_y_offset == src->i_y_offset &&
108 dst->i_visible_width == src->i_visible_width &&
109 dst->i_visible_height == src->i_visible_height;
112 static vout_thread_t *VoutCreate(vlc_object_t *object,
113 const vout_configuration_t *cfg)
115 video_format_t original;
116 if (VoutValidateFormat(&original, cfg->fmt))
119 /* Allocate descriptor */
120 vout_thread_t *vout = vlc_custom_create(object,
121 sizeof(*vout) + sizeof(*vout->p),
124 video_format_Clean(&original);
129 vout->p = (vout_thread_sys_t*)&vout[1];
131 vout->p->original = original;
132 vout->p->dpb_size = cfg->dpb_size;
134 vout_control_Init(&vout->p->control);
135 vout_control_PushVoid(&vout->p->control, VOUT_CONTROL_INIT);
137 vout_statistic_Init(&vout->p->statistic);
139 vout_snapshot_Init(&vout->p->snapshot);
141 /* Initialize locks */
142 vlc_mutex_init(&vout->p->picture_lock);
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->p->window = vout_window_New(VLC_OBJECT(vout), "$window", &wcfg);
178 vout->p->window = NULL;
181 vlc_object_set_destructor(vout, VoutDestructor);
184 if (vlc_clone(&vout->p->thread, Thread, vout,
185 VLC_THREAD_PRIORITY_OUTPUT)) {
186 spu_Destroy(vout->p->spu);
187 vlc_object_release(vout);
191 vout_control_WaitEmpty(&vout->p->control);
194 msg_Err(vout, "video output creation failed");
195 vout_CloseAndRelease(vout);
199 vout->p->input = cfg->input;
201 spu_Attach(vout->p->spu, vout->p->input, true);
207 vout_thread_t *vout_Request(vlc_object_t *object,
208 const vout_configuration_t *cfg)
210 vout_thread_t *vout = cfg->vout;
211 if (cfg->change_fmt && !cfg->fmt) {
213 vout_CloseAndRelease(vout);
217 /* If a vout is provided, try reusing it */
219 if (vout->p->input != cfg->input) {
221 spu_Attach(vout->p->spu, vout->p->input, false);
222 vout->p->input = cfg->input;
224 spu_Attach(vout->p->spu, vout->p->input, true);
227 if (cfg->change_fmt) {
228 vout_control_cmd_t cmd;
229 vout_control_cmd_Init(&cmd, VOUT_CONTROL_REINIT);
232 vout_control_Push(&vout->p->control, &cmd);
233 vout_control_WaitEmpty(&vout->p->control);
236 if (!vout->p->dead) {
237 msg_Dbg(object, "reusing provided vout");
238 vout_IntfReinit(vout);
241 vout_CloseAndRelease(vout);
243 msg_Warn(object, "cannot reuse provided vout");
245 return VoutCreate(object, cfg);
248 void vout_Close(vout_thread_t *vout)
253 spu_Attach(vout->p->spu, vout->p->input, false);
255 vout_snapshot_End(&vout->p->snapshot);
257 vout_control_PushVoid(&vout->p->control, VOUT_CONTROL_CLEAN);
258 vlc_join(vout->p->thread, NULL);
260 vlc_mutex_lock(&vout->p->spu_lock);
261 spu_Destroy(vout->p->spu);
263 vlc_mutex_unlock(&vout->p->spu_lock);
267 static void VoutDestructor(vlc_object_t *object)
269 vout_thread_t *vout = (vout_thread_t *)object;
271 /* Make sure the vout was stopped first */
272 //assert(!vout->p_module);
274 free(vout->p->splitter_name);
276 /* Destroy the locks */
277 vlc_mutex_destroy(&vout->p->spu_lock);
278 vlc_mutex_destroy(&vout->p->picture_lock);
279 vlc_mutex_destroy(&vout->p->filter.lock);
280 vout_control_Clean(&vout->p->control);
283 vout_statistic_Clean(&vout->p->statistic);
286 vout_snapshot_Clean(&vout->p->snapshot);
288 video_format_Clean(&vout->p->original);
292 void vout_ChangePause(vout_thread_t *vout, bool is_paused, mtime_t date)
294 vout_control_cmd_t cmd;
295 vout_control_cmd_Init(&cmd, VOUT_CONTROL_PAUSE);
296 cmd.u.pause.is_on = is_paused;
297 cmd.u.pause.date = date;
298 vout_control_Push(&vout->p->control, &cmd);
300 vout_control_WaitEmpty(&vout->p->control);
303 void vout_GetResetStatistic(vout_thread_t *vout, int *displayed, int *lost)
305 vout_statistic_GetReset( &vout->p->statistic, displayed, lost );
308 void vout_Flush(vout_thread_t *vout, mtime_t date)
310 vout_control_PushTime(&vout->p->control, VOUT_CONTROL_FLUSH, date);
311 vout_control_WaitEmpty(&vout->p->control);
314 void vout_Reset(vout_thread_t *vout)
316 vout_control_PushVoid(&vout->p->control, VOUT_CONTROL_RESET);
317 vout_control_WaitEmpty(&vout->p->control);
320 bool vout_IsEmpty(vout_thread_t *vout)
322 vlc_mutex_lock(&vout->p->picture_lock);
324 picture_t *picture = picture_fifo_Peek(vout->p->decoder_fifo);
326 picture_Release(picture);
328 vlc_mutex_unlock(&vout->p->picture_lock);
333 void vout_FixLeaks( vout_thread_t *vout )
335 vlc_mutex_lock(&vout->p->picture_lock);
337 picture_t *picture = picture_fifo_Peek(vout->p->decoder_fifo);
339 picture = picture_pool_Get(vout->p->decoder_pool);
343 picture_Release(picture);
344 /* Not all pictures has been displayed yet or some are
346 vlc_mutex_unlock(&vout->p->picture_lock);
350 /* There is no reason that no pictures are available, force one
351 * from the pool, becarefull with it though */
352 msg_Err(vout, "pictures leaked, trying to workaround");
355 picture_pool_NonEmpty(vout->p->decoder_pool, false);
357 vlc_mutex_unlock(&vout->p->picture_lock);
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 vout_ReleasePicture on it.
406 * You may use vout_HoldPicture(paired with vout_ReleasePicture) to keep a
407 * read-only reference.
409 picture_t *vout_GetPicture(vout_thread_t *vout)
412 vlc_mutex_lock(&vout->p->picture_lock);
413 picture_t *picture = picture_pool_Get(vout->p->decoder_pool);
415 picture_Reset(picture);
416 VideoFormatCopyCropAr(&picture->format, &vout->p->original);
418 vlc_mutex_unlock(&vout->p->picture_lock);
424 * It gives to the vout a picture to be displayed.
426 * The given picture MUST comes from vout_GetPicture.
428 * Becareful, after vout_PutPicture is called, picture_t::p_next cannot be
431 void vout_PutPicture(vout_thread_t *vout, picture_t *picture)
433 vlc_mutex_lock(&vout->p->picture_lock);
435 picture->p_next = NULL;
436 picture_fifo_Push(vout->p->decoder_fifo, picture);
438 vlc_mutex_unlock(&vout->p->picture_lock);
440 vout_control_Wake(&vout->p->control);
444 * It releases a picture retreived by vout_GetPicture.
446 void vout_ReleasePicture(vout_thread_t *vout, picture_t *picture)
448 vlc_mutex_lock(&vout->p->picture_lock);
450 picture_Release(picture);
452 vlc_mutex_unlock(&vout->p->picture_lock);
454 vout_control_Wake(&vout->p->control);
458 * It increment the reference counter of a picture retreived by
461 void vout_HoldPicture(vout_thread_t *vout, picture_t *picture)
463 vlc_mutex_lock(&vout->p->picture_lock);
465 picture_Hold(picture);
467 vlc_mutex_unlock(&vout->p->picture_lock);
471 int vout_GetSnapshot(vout_thread_t *vout,
472 block_t **image_dst, picture_t **picture_dst,
474 const char *type, mtime_t timeout)
476 picture_t *picture = vout_snapshot_Get(&vout->p->snapshot, timeout);
478 msg_Err(vout, "Failed to grab a snapshot");
483 vlc_fourcc_t codec = VLC_CODEC_PNG;
484 if (type && image_Type2Fourcc(type))
485 codec = image_Type2Fourcc(type);
487 const int override_width = var_InheritInteger(vout, "snapshot-width");
488 const int override_height = var_InheritInteger(vout, "snapshot-height");
490 if (picture_Export(VLC_OBJECT(vout), image_dst, fmt,
491 picture, codec, override_width, override_height)) {
492 msg_Err(vout, "Failed to convert image for snapshot");
493 picture_Release(picture);
498 *picture_dst = picture;
500 picture_Release(picture);
504 void vout_ChangeAspectRatio( vout_thread_t *p_vout,
505 unsigned int i_num, unsigned int i_den )
507 vout_ControlChangeSampleAspectRatio( p_vout, i_num, i_den );
510 /* vout_Control* are usable by anyone at anytime */
511 void vout_ControlChangeFullscreen(vout_thread_t *vout, bool fullscreen)
513 vout_control_PushBool(&vout->p->control, VOUT_CONTROL_FULLSCREEN,
516 void vout_ControlChangeWindowState(vout_thread_t *vout, unsigned st)
518 vout_control_PushInteger(&vout->p->control, VOUT_CONTROL_WINDOW_STATE, st);
520 void vout_ControlChangeDisplayFilled(vout_thread_t *vout, bool is_filled)
522 vout_control_PushBool(&vout->p->control, VOUT_CONTROL_DISPLAY_FILLED,
525 void vout_ControlChangeZoom(vout_thread_t *vout, int num, int den)
527 vout_control_PushPair(&vout->p->control, VOUT_CONTROL_ZOOM,
530 void vout_ControlChangeSampleAspectRatio(vout_thread_t *vout,
531 unsigned num, unsigned den)
533 vout_control_PushPair(&vout->p->control, VOUT_CONTROL_ASPECT_RATIO,
536 void vout_ControlChangeCropRatio(vout_thread_t *vout,
537 unsigned num, unsigned den)
539 vout_control_PushPair(&vout->p->control, VOUT_CONTROL_CROP_RATIO,
542 void vout_ControlChangeCropWindow(vout_thread_t *vout,
543 int x, int y, int width, int height)
545 vout_control_cmd_t cmd;
546 vout_control_cmd_Init(&cmd, VOUT_CONTROL_CROP_WINDOW);
547 cmd.u.window.x = __MAX(x, 0);
548 cmd.u.window.y = __MAX(y, 0);
549 cmd.u.window.width = __MAX(width, 0);
550 cmd.u.window.height = __MAX(height, 0);
552 vout_control_Push(&vout->p->control, &cmd);
554 void vout_ControlChangeCropBorder(vout_thread_t *vout,
555 int left, int top, int right, int bottom)
557 vout_control_cmd_t cmd;
558 vout_control_cmd_Init(&cmd, VOUT_CONTROL_CROP_BORDER);
559 cmd.u.border.left = __MAX(left, 0);
560 cmd.u.border.top = __MAX(top, 0);
561 cmd.u.border.right = __MAX(right, 0);
562 cmd.u.border.bottom = __MAX(bottom, 0);
564 vout_control_Push(&vout->p->control, &cmd);
566 void vout_ControlChangeFilters(vout_thread_t *vout, const char *filters)
568 vout_control_PushString(&vout->p->control, VOUT_CONTROL_CHANGE_FILTERS,
571 void vout_ControlChangeSubSources(vout_thread_t *vout, const char *filters)
573 vout_control_PushString(&vout->p->control, VOUT_CONTROL_CHANGE_SUB_SOURCES,
576 void vout_ControlChangeSubFilters(vout_thread_t *vout, const char *filters)
578 vout_control_PushString(&vout->p->control, VOUT_CONTROL_CHANGE_SUB_FILTERS,
581 void vout_ControlChangeSubMargin(vout_thread_t *vout, int margin)
583 vout_control_PushInteger(&vout->p->control, VOUT_CONTROL_CHANGE_SUB_MARGIN,
588 static void VoutGetDisplayCfg(vout_thread_t *vout, vout_display_cfg_t *cfg, const char *title)
590 /* Load configuration */
591 cfg->is_fullscreen = var_CreateGetBool(vout, "fullscreen")
592 || var_InheritBool(vout, "video-wallpaper");
593 cfg->display.title = title;
594 const int display_width = var_CreateGetInteger(vout, "width");
595 const int display_height = var_CreateGetInteger(vout, "height");
596 cfg->display.width = display_width > 0 ? display_width : 0;
597 cfg->display.height = display_height > 0 ? display_height : 0;
598 cfg->is_display_filled = var_CreateGetBool(vout, "autoscale");
599 unsigned msar_num, msar_den;
600 if (var_InheritURational(vout, &msar_num, &msar_den, "monitor-par") ||
601 msar_num <= 0 || msar_den <= 0) {
605 cfg->display.sar.num = msar_num;
606 cfg->display.sar.den = msar_den;
607 unsigned zoom_den = 1000;
608 unsigned zoom_num = zoom_den * var_CreateGetFloat(vout, "scale");
609 vlc_ureduce(&zoom_num, &zoom_den, zoom_num, zoom_den, 0);
610 cfg->zoom.num = zoom_num;
611 cfg->zoom.den = zoom_den;
612 cfg->align.vertical = VOUT_DISPLAY_ALIGN_CENTER;
613 cfg->align.horizontal = VOUT_DISPLAY_ALIGN_CENTER;
614 const int align_mask = var_CreateGetInteger(vout, "align");
615 if (align_mask & 0x1)
616 cfg->align.horizontal = VOUT_DISPLAY_ALIGN_LEFT;
617 else if (align_mask & 0x2)
618 cfg->align.horizontal = VOUT_DISPLAY_ALIGN_RIGHT;
619 if (align_mask & 0x4)
620 cfg->align.vertical = VOUT_DISPLAY_ALIGN_TOP;
621 else if (align_mask & 0x8)
622 cfg->align.vertical = VOUT_DISPLAY_ALIGN_BOTTOM;
625 vout_window_t * vout_NewDisplayWindow(vout_thread_t *vout,
626 const vout_window_cfg_t *cfg)
628 vout_window_t *window = vout->p->window;
630 assert(vout->p->splitter_name == NULL);
634 if (cfg->type != VOUT_WINDOW_TYPE_INVALID && cfg->type != window->type)
637 vout_window_SetSize(window, cfg->width, cfg->height);
641 void vout_DeleteDisplayWindow(vout_thread_t *vout, vout_window_t *window)
643 if (window == NULL && vout->p->window != NULL) {
644 vout_window_Delete(vout->p->window);
645 vout->p->window = NULL;
647 assert(vout->p->window == window);
651 static picture_t *VoutVideoFilterInteractiveNewPicture(filter_t *filter)
653 vout_thread_t *vout = filter->owner.sys;
655 picture_t *picture = picture_pool_Get(vout->p->private_pool);
657 picture_Reset(picture);
658 VideoFormatCopyCropAr(&picture->format, &filter->fmt_out.video);
663 static picture_t *VoutVideoFilterStaticNewPicture(filter_t *filter)
665 vout_thread_t *vout = filter->owner.sys;
667 vlc_assert_locked(&vout->p->filter.lock);
668 if (filter_chain_GetLength(vout->p->filter.chain_interactive) == 0)
669 return VoutVideoFilterInteractiveNewPicture(filter);
671 return picture_NewFromFormat(&filter->fmt_out.video);
674 static void VoutVideoFilterDelPicture(filter_t *filter, picture_t *picture)
677 picture_Release(picture);
680 static void ThreadFilterFlush(vout_thread_t *vout, bool is_locked)
682 if (vout->p->displayed.current)
683 picture_Release( vout->p->displayed.current );
684 vout->p->displayed.current = NULL;
686 if (vout->p->displayed.next)
687 picture_Release( vout->p->displayed.next );
688 vout->p->displayed.next = NULL;
691 vlc_mutex_lock(&vout->p->filter.lock);
692 filter_chain_VideoFlush(vout->p->filter.chain_static);
693 filter_chain_VideoFlush(vout->p->filter.chain_interactive);
695 vlc_mutex_unlock(&vout->p->filter.lock);
703 static void ThreadChangeFilters(vout_thread_t *vout,
704 const video_format_t *source,
708 ThreadFilterFlush(vout, is_locked);
710 vlc_array_t array_static;
711 vlc_array_t array_interactive;
713 vlc_array_init(&array_static);
714 vlc_array_init(&array_interactive);
715 char *current = filters ? strdup(filters) : NULL;
719 char *next = config_ChainCreate(&name, &cfg, current);
722 vout_filter_t *e = xmalloc(sizeof(*e));
725 if (!strcmp(e->name, "deinterlace") ||
726 !strcmp(e->name, "postproc")) {
727 vlc_array_append(&array_static, e);
729 vlc_array_append(&array_interactive, e);
733 config_ChainDestroy(cfg);
741 vlc_mutex_lock(&vout->p->filter.lock);
743 es_format_t fmt_target;
744 es_format_InitFromVideo(&fmt_target, source ? source : &vout->p->filter.format);
746 es_format_t fmt_current = fmt_target;
748 for (int a = 0; a < 2; a++) {
749 vlc_array_t *array = a == 0 ? &array_static :
751 filter_chain_t *chain = a == 0 ? vout->p->filter.chain_static :
752 vout->p->filter.chain_interactive;
754 filter_chain_Reset(chain, &fmt_current, &fmt_current);
755 for (int i = 0; i < vlc_array_count(array); i++) {
756 vout_filter_t *e = vlc_array_item_at_index(array, i);
757 msg_Dbg(vout, "Adding '%s' as %s", e->name, a == 0 ? "static" : "interactive");
758 if (!filter_chain_AppendFilter(chain, e->name, e->cfg, NULL, NULL)) {
759 msg_Err(vout, "Failed to add filter '%s'", e->name);
760 config_ChainDestroy(e->cfg);
765 fmt_current = *filter_chain_GetFmtOut(chain);
766 vlc_array_clear(array);
769 if (!es_format_IsSimilar(&fmt_current, &fmt_target)) {
770 msg_Dbg(vout, "Adding a filter to compensate for format changes");
771 if (!filter_chain_AppendFilter(vout->p->filter.chain_interactive, NULL, NULL,
772 &fmt_current, &fmt_target)) {
773 msg_Err(vout, "Failed to compensate for the format changes, removing all filters");
774 filter_chain_Reset(vout->p->filter.chain_static, &fmt_target, &fmt_target);
775 filter_chain_Reset(vout->p->filter.chain_interactive, &fmt_target, &fmt_target);
779 es_format_Clean(&fmt_target);
781 if (vout->p->filter.configuration != filters) {
782 free(vout->p->filter.configuration);
783 vout->p->filter.configuration = filters ? strdup(filters) : NULL;
786 video_format_Clean(&vout->p->filter.format);
787 video_format_Copy(&vout->p->filter.format, source);
791 vlc_mutex_unlock(&vout->p->filter.lock);
796 static int ThreadDisplayPreparePicture(vout_thread_t *vout, bool reuse, bool frame_by_frame)
798 bool is_late_dropped = vout->p->is_late_dropped && !vout->p->pause.is_on && !frame_by_frame;
800 vlc_mutex_lock(&vout->p->filter.lock);
802 picture_t *picture = filter_chain_VideoFilter(vout->p->filter.chain_static, NULL);
803 assert(!reuse || !picture);
807 if (reuse && vout->p->displayed.decoded) {
808 decoded = picture_Hold(vout->p->displayed.decoded);
810 decoded = picture_fifo_Pop(vout->p->decoder_fifo);
812 if (is_late_dropped && !decoded->b_force) {
813 const mtime_t predicted = mdate() + 0; /* TODO improve */
814 const mtime_t late = predicted - decoded->date;
815 if (late > VOUT_DISPLAY_LATE_THRESHOLD) {
816 msg_Warn(vout, "picture is too late to be displayed (missing %"PRId64" ms)", late/1000);
817 picture_Release(decoded);
818 vout_statistic_AddLost(&vout->p->statistic, 1);
820 } else if (late > 0) {
821 msg_Dbg(vout, "picture might be displayed late (missing %"PRId64" ms)", late/1000);
824 if (!VideoFormatIsCropArEqual(&decoded->format, &vout->p->filter.format))
825 ThreadChangeFilters(vout, &decoded->format, vout->p->filter.configuration, true);
833 if (vout->p->displayed.decoded)
834 picture_Release(vout->p->displayed.decoded);
836 vout->p->displayed.decoded = picture_Hold(decoded);
837 vout->p->displayed.timestamp = decoded->date;
838 vout->p->displayed.is_interlaced = !decoded->b_progressive;
840 picture = filter_chain_VideoFilter(vout->p->filter.chain_static, decoded);
843 vlc_mutex_unlock(&vout->p->filter.lock);
848 assert(!vout->p->displayed.next);
849 if (!vout->p->displayed.current)
850 vout->p->displayed.current = picture;
852 vout->p->displayed.next = picture;
856 static int ThreadDisplayRenderPicture(vout_thread_t *vout, bool is_forced)
858 vout_thread_sys_t *sys = vout->p;
859 vout_display_t *vd = vout->p->display.vd;
861 picture_t *torender = picture_Hold(vout->p->displayed.current);
863 vout_chrono_Start(&vout->p->render);
865 vlc_mutex_lock(&vout->p->filter.lock);
866 picture_t *filtered = filter_chain_VideoFilter(vout->p->filter.chain_interactive, torender);
867 vlc_mutex_unlock(&vout->p->filter.lock);
872 if (filtered->date != vout->p->displayed.current->date)
873 msg_Warn(vout, "Unsupported timestamp modifications done by chain_interactive");
876 * Get the subpicture to be displayed
878 const bool do_snapshot = vout_snapshot_IsRequested(&vout->p->snapshot);
879 mtime_t render_subtitle_date;
880 if (vout->p->pause.is_on)
881 render_subtitle_date = vout->p->pause.date;
883 render_subtitle_date = filtered->date > 1 ? filtered->date : mdate();
884 mtime_t render_osd_date = mdate(); /* FIXME wrong */
887 * Get the subpicture to be displayed
889 const bool do_dr_spu = !do_snapshot &&
890 vd->info.subpicture_chromas &&
891 *vd->info.subpicture_chromas != 0;
893 //FIXME: Denying do_early_spu if vd->source.orientation != ORIENT_NORMAL
894 //will have the effect that snapshots miss the subpictures. We do this
895 //because there is currently no way to transform subpictures to match
897 const bool do_early_spu = !do_dr_spu &&
898 vd->source.orientation == ORIENT_NORMAL &&
900 sys->display.use_dr ||
902 !vout_IsDisplayFiltered(vd) ||
903 vd->fmt.i_width * vd->fmt.i_height <= vd->source.i_width * vd->source.i_height);
905 const vlc_fourcc_t *subpicture_chromas;
906 video_format_t fmt_spu;
908 vout_display_place_t place;
909 vout_display_PlacePicture(&place, &vd->source, vd->cfg, false);
911 fmt_spu = vd->source;
912 if (fmt_spu.i_width * fmt_spu.i_height < place.width * place.height) {
913 fmt_spu.i_sar_num = vd->cfg->display.sar.num;
914 fmt_spu.i_sar_den = vd->cfg->display.sar.den;
916 fmt_spu.i_visible_width = place.width;
918 fmt_spu.i_visible_height = place.height;
920 subpicture_chromas = vd->info.subpicture_chromas;
923 fmt_spu = vd->source;
926 fmt_spu.i_sar_num = vd->cfg->display.sar.num;
927 fmt_spu.i_sar_den = vd->cfg->display.sar.den;
929 subpicture_chromas = NULL;
931 if (vout->p->spu_blend &&
932 vout->p->spu_blend->fmt_out.video.i_chroma != fmt_spu.i_chroma) {
933 filter_DeleteBlend(vout->p->spu_blend);
934 vout->p->spu_blend = NULL;
935 vout->p->spu_blend_chroma = 0;
937 if (!vout->p->spu_blend && vout->p->spu_blend_chroma != fmt_spu.i_chroma) {
938 vout->p->spu_blend_chroma = fmt_spu.i_chroma;
939 vout->p->spu_blend = filter_NewBlend(VLC_OBJECT(vout), &fmt_spu);
940 if (!vout->p->spu_blend)
941 msg_Err(vout, "Failed to create blending filter, OSD/Subtitles will not work");
945 video_format_t fmt_spu_rot;
946 video_format_ApplyRotation(&fmt_spu_rot, &fmt_spu);
947 subpicture_t *subpic = spu_Render(vout->p->spu,
948 subpicture_chromas, &fmt_spu_rot,
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 picture_t *blent = picture_pool_Get(vout->p->private_pool);
964 VideoFormatCopyCropAr(&blent->format, &filtered->format);
965 picture_Copy(blent, filtered);
966 if (vout->p->spu_blend
967 && picture_BlendSubpicture(blent, vout->p->spu_blend, subpic)) {
968 picture_Release(todisplay);
971 picture_Release(blent);
973 subpicture_Delete(subpic);
977 assert(vout_IsDisplayFiltered(vd) == !sys->display.use_dr);
978 if (sys->display.use_dr && !is_direct) {
979 picture_t *direct = picture_pool_Get(vout->p->display_pool);
981 picture_Release(todisplay);
983 subpicture_Delete(subpic);
987 /* The display uses direct rendering (no conversion), but its pool of
988 * pictures is not usable by the decoder (too few, too slow or
989 * subject to invalidation...). Since there are no filters, copying
990 * pictures from the decoder to the output is unavoidable. */
991 VideoFormatCopyCropAr(&direct->format, &todisplay->format);
992 picture_Copy(direct, todisplay);
993 picture_Release(todisplay);
998 * Take a snapshot if requested
1001 vout_snapshot_Set(&vout->p->snapshot, &vd->source, todisplay);
1003 /* Render the direct buffer */
1004 vout_UpdateDisplaySourceProperties(vd, &todisplay->format);
1005 if (sys->display.use_dr) {
1006 vout_display_Prepare(vd, todisplay, subpic);
1008 sys->display.filtered = vout_FilterDisplay(vd, todisplay);
1009 if (sys->display.filtered) {
1010 if (!do_dr_spu && !do_early_spu && vout->p->spu_blend && subpic)
1011 picture_BlendSubpicture(sys->display.filtered, vout->p->spu_blend, subpic);
1012 vout_display_Prepare(vd, sys->display.filtered, do_dr_spu ? subpic : NULL);
1014 if (!do_dr_spu && subpic)
1016 subpicture_Delete(subpic);
1019 if (!sys->display.filtered)
1020 return VLC_EGENERIC;
1023 vout_chrono_Stop(&vout->p->render);
1027 if (((i++)%10) == 0)
1028 msg_Info(vout, "render: avg %d ms var %d ms",
1029 (int)(vout->p->render.avg/1000), (int)(vout->p->render.var/1000));
1033 /* Wait the real date (for rendering jitter) */
1035 mtime_t delay = direct->date - mdate();
1037 msg_Warn(vout, "picture is late (%lld ms)", delay / 1000);
1040 mwait(todisplay->date);
1042 /* Display the direct buffer returned by vout_RenderPicture */
1043 vout->p->displayed.date = mdate();
1044 vout_display_Display(vd,
1045 sys->display.filtered ? sys->display.filtered
1048 sys->display.filtered = NULL;
1050 vout_statistic_AddDisplayed(&vout->p->statistic, 1);
1055 static int ThreadDisplayPicture(vout_thread_t *vout, mtime_t *deadline)
1057 bool frame_by_frame = !deadline;
1058 bool paused = vout->p->pause.is_on;
1059 bool first = !vout->p->displayed.current;
1062 if (ThreadDisplayPreparePicture(vout, true, frame_by_frame)) /* FIXME not sure it is ok */
1063 return VLC_EGENERIC;
1065 if (!paused || frame_by_frame)
1066 while (!vout->p->displayed.next && !ThreadDisplayPreparePicture(vout, false, frame_by_frame))
1069 const mtime_t date = mdate();
1070 const mtime_t render_delay = vout_chrono_GetHigh(&vout->p->render) + VOUT_MWAIT_TOLERANCE;
1072 bool drop_next_frame = frame_by_frame;
1073 mtime_t date_next = VLC_TS_INVALID;
1074 if (!paused && vout->p->displayed.next) {
1075 date_next = vout->p->displayed.next->date - render_delay;
1076 if (date_next /* + 0 FIXME */ <= date)
1077 drop_next_frame = true;
1080 /* FIXME/XXX we must redisplay the last decoded picture (because
1081 * of potential vout updated, or filters update or SPU update)
1082 * For now a high update period is needed but it could be removed
1084 * - vout module emits events from theselves.
1085 * - *and* SPU is modified to emit an event or a deadline when needed.
1087 * So it will be done later.
1089 bool refresh = false;
1091 mtime_t date_refresh = VLC_TS_INVALID;
1092 if (vout->p->displayed.date > VLC_TS_INVALID) {
1093 date_refresh = vout->p->displayed.date + VOUT_REDISPLAY_DELAY - render_delay;
1094 refresh = date_refresh <= date;
1096 bool force_refresh = !drop_next_frame && refresh;
1098 if (!first && !refresh && !drop_next_frame) {
1099 if (!frame_by_frame) {
1100 if (date_refresh != VLC_TS_INVALID)
1101 *deadline = date_refresh;
1102 if (date_next != VLC_TS_INVALID && date_next < *deadline)
1103 *deadline = date_next;
1105 return VLC_EGENERIC;
1108 if (drop_next_frame) {
1109 picture_Release(vout->p->displayed.current);
1110 vout->p->displayed.current = vout->p->displayed.next;
1111 vout->p->displayed.next = NULL;
1114 if (!vout->p->displayed.current)
1115 return VLC_EGENERIC;
1117 /* display the picture immediately */
1118 bool is_forced = frame_by_frame || force_refresh || vout->p->displayed.current->b_force;
1119 int ret = ThreadDisplayRenderPicture(vout, is_forced);
1120 return force_refresh ? VLC_EGENERIC : ret;
1123 static void ThreadDisplaySubpicture(vout_thread_t *vout,
1124 subpicture_t *subpicture)
1126 spu_PutSubpicture(vout->p->spu, subpicture);
1129 static void ThreadFlushSubpicture(vout_thread_t *vout, int channel)
1131 spu_ClearChannel(vout->p->spu, channel);
1134 static void ThreadDisplayOsdTitle(vout_thread_t *vout, const char *string)
1136 if (!vout->p->title.show)
1139 vout_OSDText(vout, SPU_DEFAULT_CHANNEL,
1140 vout->p->title.position, INT64_C(1000) * vout->p->title.timeout,
1144 static void ThreadChangeSubSources(vout_thread_t *vout, const char *filters)
1146 spu_ChangeSources(vout->p->spu, filters);
1149 static void ThreadChangeSubFilters(vout_thread_t *vout, const char *filters)
1151 spu_ChangeFilters(vout->p->spu, filters);
1154 static void ThreadChangeSubMargin(vout_thread_t *vout, int margin)
1156 spu_ChangeMargin(vout->p->spu, margin);
1159 static void ThreadChangePause(vout_thread_t *vout, bool is_paused, mtime_t date)
1161 assert(!vout->p->pause.is_on || !is_paused);
1163 if (vout->p->pause.is_on) {
1164 const mtime_t duration = date - vout->p->pause.date;
1166 if (vout->p->step.timestamp > VLC_TS_INVALID)
1167 vout->p->step.timestamp += duration;
1168 if (vout->p->step.last > VLC_TS_INVALID)
1169 vout->p->step.last += duration;
1170 picture_fifo_OffsetDate(vout->p->decoder_fifo, duration);
1171 if (vout->p->displayed.decoded)
1172 vout->p->displayed.decoded->date += duration;
1173 spu_OffsetSubtitleDate(vout->p->spu, duration);
1175 ThreadFilterFlush(vout, false);
1177 vout->p->step.timestamp = VLC_TS_INVALID;
1178 vout->p->step.last = VLC_TS_INVALID;
1180 vout->p->pause.is_on = is_paused;
1181 vout->p->pause.date = date;
1184 static void ThreadFlush(vout_thread_t *vout, bool below, mtime_t date)
1186 vout->p->step.timestamp = VLC_TS_INVALID;
1187 vout->p->step.last = VLC_TS_INVALID;
1189 ThreadFilterFlush(vout, false); /* FIXME too much */
1191 picture_t *last = vout->p->displayed.decoded;
1193 if (( below && last->date <= date) ||
1194 (!below && last->date >= date)) {
1195 picture_Release(last);
1197 vout->p->displayed.decoded = NULL;
1198 vout->p->displayed.date = VLC_TS_INVALID;
1199 vout->p->displayed.timestamp = VLC_TS_INVALID;
1203 picture_fifo_Flush(vout->p->decoder_fifo, date, below);
1206 static void ThreadReset(vout_thread_t *vout)
1208 ThreadFlush(vout, true, INT64_MAX);
1209 if (vout->p->decoder_pool)
1210 picture_pool_NonEmpty(vout->p->decoder_pool, true);
1211 vout->p->pause.is_on = false;
1212 vout->p->pause.date = mdate();
1215 static void ThreadStep(vout_thread_t *vout, mtime_t *duration)
1219 if (vout->p->step.last <= VLC_TS_INVALID)
1220 vout->p->step.last = vout->p->displayed.timestamp;
1222 if (ThreadDisplayPicture(vout, NULL))
1225 vout->p->step.timestamp = vout->p->displayed.timestamp;
1227 if (vout->p->step.last > VLC_TS_INVALID &&
1228 vout->p->step.timestamp > vout->p->step.last) {
1229 *duration = vout->p->step.timestamp - vout->p->step.last;
1230 vout->p->step.last = vout->p->step.timestamp;
1231 /* TODO advance subpicture by the duration ... */
1235 static void ThreadChangeFullscreen(vout_thread_t *vout, bool fullscreen)
1237 vout_SetDisplayFullscreen(vout->p->display.vd, fullscreen);
1240 static void ThreadChangeWindowState(vout_thread_t *vout, unsigned state)
1242 vout_SetWindowState(vout->p->display.vd, state);
1245 static void ThreadChangeDisplayFilled(vout_thread_t *vout, bool is_filled)
1247 vout_SetDisplayFilled(vout->p->display.vd, is_filled);
1250 static void ThreadChangeZoom(vout_thread_t *vout, int num, int den)
1252 if (num * 10 < den) {
1255 } else if (num > den * 10) {
1259 vout_SetDisplayZoom(vout->p->display.vd, num, den);
1262 static void ThreadChangeAspectRatio(vout_thread_t *vout,
1263 unsigned num, unsigned den)
1265 vout_SetDisplayAspect(vout->p->display.vd, num, den);
1269 static void ThreadExecuteCropWindow(vout_thread_t *vout,
1270 unsigned x, unsigned y,
1271 unsigned width, unsigned height)
1273 vout_SetDisplayCrop(vout->p->display.vd, 0, 0,
1274 x, y, width, height);
1276 static void ThreadExecuteCropBorder(vout_thread_t *vout,
1277 unsigned left, unsigned top,
1278 unsigned right, unsigned bottom)
1280 msg_Err(vout, "ThreadExecuteCropBorder %d.%d %dx%d", left, top, right, bottom);
1281 vout_SetDisplayCrop(vout->p->display.vd, 0, 0,
1282 left, top, -(int)right, -(int)bottom);
1285 static void ThreadExecuteCropRatio(vout_thread_t *vout,
1286 unsigned num, unsigned den)
1288 vout_SetDisplayCrop(vout->p->display.vd, num, den,
1292 static int ThreadStart(vout_thread_t *vout, const vout_display_state_t *state)
1294 vlc_mouse_Init(&vout->p->mouse);
1295 vout->p->decoder_fifo = picture_fifo_New();
1296 vout->p->decoder_pool = NULL;
1297 vout->p->display_pool = NULL;
1298 vout->p->private_pool = NULL;
1300 vout->p->filter.configuration = NULL;
1301 video_format_Copy(&vout->p->filter.format, &vout->p->original);
1303 filter_owner_t owner = {
1306 .buffer_new = VoutVideoFilterStaticNewPicture,
1307 .buffer_del = VoutVideoFilterDelPicture,
1310 vout->p->filter.chain_static =
1311 filter_chain_NewVideo( vout, true, &owner );
1313 owner.video.buffer_new = VoutVideoFilterInteractiveNewPicture;
1314 vout->p->filter.chain_interactive =
1315 filter_chain_NewVideo( vout, true, &owner );
1317 vout_display_state_t state_default;
1319 var_Create(vout, "video-wallpaper", VLC_VAR_BOOL|VLC_VAR_DOINHERIT);
1320 VoutGetDisplayCfg(vout, &state_default.cfg, vout->p->display.title);
1322 bool below = var_InheritBool(vout, "video-wallpaper");
1323 bool above = var_CreateGetBool(vout, "video-on-top");
1325 state_default.wm_state = below ? VOUT_WINDOW_STATE_BELOW
1326 : above ? VOUT_WINDOW_STATE_ABOVE
1327 : VOUT_WINDOW_STATE_NORMAL;
1328 state_default.sar.num = 0;
1329 state_default.sar.den = 0;
1331 state = &state_default;
1334 if (vout_OpenWrapper(vout, vout->p->splitter_name, state))
1335 return VLC_EGENERIC;
1336 if (vout_InitWrapper(vout))
1337 return VLC_EGENERIC;
1338 assert(vout->p->decoder_pool);
1340 vout->p->displayed.current = NULL;
1341 vout->p->displayed.next = NULL;
1342 vout->p->displayed.decoded = NULL;
1343 vout->p->displayed.date = VLC_TS_INVALID;
1344 vout->p->displayed.timestamp = VLC_TS_INVALID;
1345 vout->p->displayed.is_interlaced = false;
1347 vout->p->step.last = VLC_TS_INVALID;
1348 vout->p->step.timestamp = VLC_TS_INVALID;
1350 vout->p->spu_blend_chroma = 0;
1351 vout->p->spu_blend = NULL;
1353 video_format_Print(VLC_OBJECT(vout), "original format", &vout->p->original);
1357 static void ThreadStop(vout_thread_t *vout, vout_display_state_t *state)
1359 if (vout->p->spu_blend)
1360 filter_DeleteBlend(vout->p->spu_blend);
1362 /* Destroy translation tables */
1363 if (vout->p->display.vd) {
1364 if (vout->p->decoder_pool) {
1365 ThreadFlush(vout, true, INT64_MAX);
1366 vout_EndWrapper(vout);
1368 vout_CloseWrapper(vout, state);
1371 /* Destroy the video filters2 */
1372 filter_chain_Delete(vout->p->filter.chain_interactive);
1373 filter_chain_Delete(vout->p->filter.chain_static);
1374 video_format_Clean(&vout->p->filter.format);
1375 free(vout->p->filter.configuration);
1377 if (vout->p->decoder_fifo)
1378 picture_fifo_Delete(vout->p->decoder_fifo);
1379 assert(!vout->p->decoder_pool);
1382 static void ThreadInit(vout_thread_t *vout)
1384 vout->p->dead = false;
1385 vout->p->is_late_dropped = var_InheritBool(vout, "drop-late-frames");
1386 vout->p->pause.is_on = false;
1387 vout->p->pause.date = VLC_TS_INVALID;
1389 vout_chrono_Init(&vout->p->render, 5, 10000); /* Arbitrary initial time */
1392 static void ThreadClean(vout_thread_t *vout)
1394 if (vout->p->window != NULL)
1395 vout_window_Delete(vout->p->window);
1396 vout_chrono_Clean(&vout->p->render);
1397 vout->p->dead = true;
1398 vout_control_Dead(&vout->p->control);
1401 static int ThreadReinit(vout_thread_t *vout,
1402 const vout_configuration_t *cfg)
1404 video_format_t original;
1405 if (VoutValidateFormat(&original, cfg->fmt)) {
1406 ThreadStop(vout, NULL);
1408 return VLC_EGENERIC;
1410 /* We ignore crop/ar changes at this point, they are dynamically supported */
1411 VideoFormatCopyCropAr(&vout->p->original, &original);
1412 if (video_format_IsSimilar(&original, &vout->p->original)) {
1413 if (cfg->dpb_size <= vout->p->dpb_size)
1415 msg_Warn(vout, "DPB need to be increased");
1418 vout_display_state_t state;
1419 memset(&state, 0, sizeof(state));
1421 ThreadStop(vout, &state);
1423 if (!state.cfg.is_fullscreen) {
1424 state.cfg.display.width = 0;
1425 state.cfg.display.height = 0;
1430 /* FIXME current vout "variables" are not in sync here anymore
1431 * and I am not sure what to do */
1432 if (state.cfg.display.sar.num <= 0 || state.cfg.display.sar.den <= 0) {
1433 state.cfg.display.sar.num = 1;
1434 state.cfg.display.sar.den = 1;
1436 if (state.cfg.zoom.num <= 0 || state.cfg.zoom.den <= 0) {
1437 state.cfg.zoom.num = 1;
1438 state.cfg.zoom.den = 1;
1441 vout->p->original = original;
1442 vout->p->dpb_size = cfg->dpb_size;
1443 if (ThreadStart(vout, &state)) {
1445 return VLC_EGENERIC;
1450 static int ThreadControl(vout_thread_t *vout, vout_control_cmd_t cmd)
1453 case VOUT_CONTROL_INIT:
1455 if (!ThreadStart(vout, NULL))
1457 case VOUT_CONTROL_CLEAN:
1458 ThreadStop(vout, NULL);
1461 case VOUT_CONTROL_REINIT:
1462 if (ThreadReinit(vout, cmd.u.cfg))
1465 case VOUT_CONTROL_SUBPICTURE:
1466 ThreadDisplaySubpicture(vout, cmd.u.subpicture);
1467 cmd.u.subpicture = NULL;
1469 case VOUT_CONTROL_FLUSH_SUBPICTURE:
1470 ThreadFlushSubpicture(vout, cmd.u.integer);
1472 case VOUT_CONTROL_OSD_TITLE:
1473 ThreadDisplayOsdTitle(vout, cmd.u.string);
1475 case VOUT_CONTROL_CHANGE_FILTERS:
1476 ThreadChangeFilters(vout, NULL, cmd.u.string, false);
1478 case VOUT_CONTROL_CHANGE_SUB_SOURCES:
1479 ThreadChangeSubSources(vout, cmd.u.string);
1481 case VOUT_CONTROL_CHANGE_SUB_FILTERS:
1482 ThreadChangeSubFilters(vout, cmd.u.string);
1484 case VOUT_CONTROL_CHANGE_SUB_MARGIN:
1485 ThreadChangeSubMargin(vout, cmd.u.integer);
1487 case VOUT_CONTROL_PAUSE:
1488 ThreadChangePause(vout, cmd.u.pause.is_on, cmd.u.pause.date);
1490 case VOUT_CONTROL_FLUSH:
1491 ThreadFlush(vout, false, cmd.u.time);
1493 case VOUT_CONTROL_RESET:
1496 case VOUT_CONTROL_STEP:
1497 ThreadStep(vout, cmd.u.time_ptr);
1499 case VOUT_CONTROL_FULLSCREEN:
1500 ThreadChangeFullscreen(vout, cmd.u.boolean);
1502 case VOUT_CONTROL_WINDOW_STATE:
1503 ThreadChangeWindowState(vout, cmd.u.integer);
1505 case VOUT_CONTROL_DISPLAY_FILLED:
1506 ThreadChangeDisplayFilled(vout, cmd.u.boolean);
1508 case VOUT_CONTROL_ZOOM:
1509 ThreadChangeZoom(vout, cmd.u.pair.a, cmd.u.pair.b);
1511 case VOUT_CONTROL_ASPECT_RATIO:
1512 ThreadChangeAspectRatio(vout, cmd.u.pair.a, cmd.u.pair.b);
1514 case VOUT_CONTROL_CROP_RATIO:
1515 ThreadExecuteCropRatio(vout, cmd.u.pair.a, cmd.u.pair.b);
1517 case VOUT_CONTROL_CROP_WINDOW:
1518 ThreadExecuteCropWindow(vout,
1519 cmd.u.window.x, cmd.u.window.y,
1520 cmd.u.window.width, cmd.u.window.height);
1522 case VOUT_CONTROL_CROP_BORDER:
1523 ThreadExecuteCropBorder(vout,
1524 cmd.u.border.left, cmd.u.border.top,
1525 cmd.u.border.right, cmd.u.border.bottom);
1530 vout_control_cmd_Clean(&cmd);
1534 /*****************************************************************************
1535 * Thread: video output thread
1536 *****************************************************************************
1537 * Video output thread. This function does only returns when the thread is
1538 * terminated. It handles the pictures arriving in the video heap and the
1539 * display device events.
1540 *****************************************************************************/
1541 static void *Thread(void *object)
1543 vout_thread_t *vout = object;
1544 vout_thread_sys_t *sys = vout->p;
1546 vout_interlacing_support_t interlacing = {
1547 .is_interlaced = false,
1551 mtime_t deadline = VLC_TS_INVALID;
1553 vout_control_cmd_t cmd;
1554 /* FIXME remove thoses ugly timeouts */
1555 while (!vout_control_Pop(&sys->control, &cmd, deadline, 100000))
1556 if (ThreadControl(vout, cmd))
1559 vlc_mutex_lock(&sys->picture_lock);
1561 deadline = VLC_TS_INVALID;
1562 while (!ThreadDisplayPicture(vout, &deadline))
1565 const bool picture_interlaced = sys->displayed.is_interlaced;
1567 vlc_mutex_unlock(&sys->picture_lock);
1569 vout_SetInterlacingState(vout, &interlacing, picture_interlaced);
1570 vout_ManageWrapper(vout);