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 char *splitter_name = var_InheritString(vout, "video-splitter");
158 if (splitter_name && *splitter_name) {
159 vout->p->splitter_name = splitter_name;
165 vout_InitInterlacingSupport(vout, vout->p->displayed.is_interlaced);
168 vlc_object_set_destructor(vout, VoutDestructor);
171 if (vlc_clone(&vout->p->thread, Thread, vout,
172 VLC_THREAD_PRIORITY_OUTPUT)) {
173 spu_Destroy(vout->p->spu);
174 vlc_object_release(vout);
178 vout_control_WaitEmpty(&vout->p->control);
181 msg_Err(vout, "video output creation failed");
182 vout_CloseAndRelease(vout);
186 vout->p->input = cfg->input;
188 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");
225 vout_IntfReinit(vout);
228 vout_CloseAndRelease(vout);
230 msg_Warn(object, "cannot reuse provided vout");
232 return VoutCreate(object, cfg);
235 void vout_Close(vout_thread_t *vout)
240 spu_Attach(vout->p->spu, vout->p->input, false);
242 vout_snapshot_End(&vout->p->snapshot);
244 vout_control_PushVoid(&vout->p->control, VOUT_CONTROL_CLEAN);
245 vlc_join(vout->p->thread, NULL);
247 vlc_mutex_lock(&vout->p->spu_lock);
248 spu_Destroy(vout->p->spu);
250 vlc_mutex_unlock(&vout->p->spu_lock);
254 static void VoutDestructor(vlc_object_t *object)
256 vout_thread_t *vout = (vout_thread_t *)object;
258 /* Make sure the vout was stopped first */
259 //assert(!vout->p_module);
261 free(vout->p->splitter_name);
263 /* Destroy the locks */
264 vlc_mutex_destroy(&vout->p->spu_lock);
265 vlc_mutex_destroy(&vout->p->picture_lock);
266 vlc_mutex_destroy(&vout->p->filter.lock);
267 vout_control_Clean(&vout->p->control);
270 vout_statistic_Clean(&vout->p->statistic);
273 vout_snapshot_Clean(&vout->p->snapshot);
275 video_format_Clean(&vout->p->original);
279 void vout_ChangePause(vout_thread_t *vout, bool is_paused, mtime_t date)
281 vout_control_cmd_t cmd;
282 vout_control_cmd_Init(&cmd, VOUT_CONTROL_PAUSE);
283 cmd.u.pause.is_on = is_paused;
284 cmd.u.pause.date = date;
285 vout_control_Push(&vout->p->control, &cmd);
287 vout_control_WaitEmpty(&vout->p->control);
290 void vout_GetResetStatistic(vout_thread_t *vout, int *displayed, int *lost)
292 vout_statistic_GetReset( &vout->p->statistic, displayed, lost );
295 void vout_Flush(vout_thread_t *vout, mtime_t date)
297 vout_control_PushTime(&vout->p->control, VOUT_CONTROL_FLUSH, date);
298 vout_control_WaitEmpty(&vout->p->control);
301 void vout_Reset(vout_thread_t *vout)
303 vout_control_PushVoid(&vout->p->control, VOUT_CONTROL_RESET);
304 vout_control_WaitEmpty(&vout->p->control);
307 bool vout_IsEmpty(vout_thread_t *vout)
309 vlc_mutex_lock(&vout->p->picture_lock);
311 picture_t *picture = picture_fifo_Peek(vout->p->decoder_fifo);
313 picture_Release(picture);
315 vlc_mutex_unlock(&vout->p->picture_lock);
320 void vout_FixLeaks( 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 = picture_pool_Get(vout->p->decoder_pool);
330 picture_Release(picture);
331 /* Not all pictures has been displayed yet or some are
333 vlc_mutex_unlock(&vout->p->picture_lock);
337 /* There is no reason that no pictures are available, force one
338 * from the pool, becarefull with it though */
339 msg_Err(vout, "pictures leaked, trying to workaround");
342 picture_pool_NonEmpty(vout->p->decoder_pool, false);
344 vlc_mutex_unlock(&vout->p->picture_lock);
346 void vout_NextPicture(vout_thread_t *vout, mtime_t *duration)
348 vout_control_cmd_t cmd;
349 vout_control_cmd_Init(&cmd, VOUT_CONTROL_STEP);
350 cmd.u.time_ptr = duration;
352 vout_control_Push(&vout->p->control, &cmd);
353 vout_control_WaitEmpty(&vout->p->control);
356 void vout_DisplayTitle(vout_thread_t *vout, const char *title)
359 vout_control_PushString(&vout->p->control, VOUT_CONTROL_OSD_TITLE, title);
362 void vout_PutSubpicture( vout_thread_t *vout, subpicture_t *subpic )
364 vout_control_cmd_t cmd;
365 vout_control_cmd_Init(&cmd, VOUT_CONTROL_SUBPICTURE);
366 cmd.u.subpicture = subpic;
368 vout_control_Push(&vout->p->control, &cmd);
370 int vout_RegisterSubpictureChannel( vout_thread_t *vout )
372 int channel = SPU_DEFAULT_CHANNEL;
374 vlc_mutex_lock(&vout->p->spu_lock);
376 channel = spu_RegisterChannel(vout->p->spu);
377 vlc_mutex_unlock(&vout->p->spu_lock);
381 void vout_FlushSubpictureChannel( vout_thread_t *vout, int channel )
383 vout_control_PushInteger(&vout->p->control, VOUT_CONTROL_FLUSH_SUBPICTURE,
388 * It retreives a picture from the vout or NULL if no pictures are
391 * You MUST call vout_PutPicture or vout_ReleasePicture on it.
393 * You may use vout_HoldPicture(paired with vout_ReleasePicture) to keep a
394 * read-only reference.
396 picture_t *vout_GetPicture(vout_thread_t *vout)
399 vlc_mutex_lock(&vout->p->picture_lock);
400 picture_t *picture = picture_pool_Get(vout->p->decoder_pool);
402 picture_Reset(picture);
403 VideoFormatCopyCropAr(&picture->format, &vout->p->original);
405 vlc_mutex_unlock(&vout->p->picture_lock);
411 * It gives to the vout a picture to be displayed.
413 * The given picture MUST comes from vout_GetPicture.
415 * Becareful, after vout_PutPicture is called, picture_t::p_next cannot be
418 void vout_PutPicture(vout_thread_t *vout, picture_t *picture)
420 vlc_mutex_lock(&vout->p->picture_lock);
422 picture->p_next = NULL;
423 picture_fifo_Push(vout->p->decoder_fifo, picture);
425 vlc_mutex_unlock(&vout->p->picture_lock);
427 vout_control_Wake(&vout->p->control);
431 * It releases a picture retreived by vout_GetPicture.
433 void vout_ReleasePicture(vout_thread_t *vout, picture_t *picture)
435 vlc_mutex_lock(&vout->p->picture_lock);
437 picture_Release(picture);
439 vlc_mutex_unlock(&vout->p->picture_lock);
441 vout_control_Wake(&vout->p->control);
445 * It increment the reference counter of a picture retreived by
448 void vout_HoldPicture(vout_thread_t *vout, picture_t *picture)
450 vlc_mutex_lock(&vout->p->picture_lock);
452 picture_Hold(picture);
454 vlc_mutex_unlock(&vout->p->picture_lock);
458 int vout_GetSnapshot(vout_thread_t *vout,
459 block_t **image_dst, picture_t **picture_dst,
461 const char *type, mtime_t timeout)
463 picture_t *picture = vout_snapshot_Get(&vout->p->snapshot, timeout);
465 msg_Err(vout, "Failed to grab a snapshot");
470 vlc_fourcc_t codec = VLC_CODEC_PNG;
471 if (type && image_Type2Fourcc(type))
472 codec = image_Type2Fourcc(type);
474 const int override_width = var_InheritInteger(vout, "snapshot-width");
475 const int override_height = var_InheritInteger(vout, "snapshot-height");
477 if (picture_Export(VLC_OBJECT(vout), image_dst, fmt,
478 picture, codec, override_width, override_height)) {
479 msg_Err(vout, "Failed to convert image for snapshot");
480 picture_Release(picture);
485 *picture_dst = picture;
487 picture_Release(picture);
491 void vout_ChangeAspectRatio( vout_thread_t *p_vout,
492 unsigned int i_num, unsigned int i_den )
494 vout_ControlChangeSampleAspectRatio( p_vout, i_num, i_den );
497 /* vout_Control* are usable by anyone at anytime */
498 void vout_ControlChangeFullscreen(vout_thread_t *vout, bool fullscreen)
500 vout_control_PushBool(&vout->p->control, VOUT_CONTROL_FULLSCREEN,
503 void vout_ControlChangeWindowState(vout_thread_t *vout, unsigned st)
505 vout_control_PushInteger(&vout->p->control, VOUT_CONTROL_WINDOW_STATE, st);
507 void vout_ControlChangeDisplayFilled(vout_thread_t *vout, bool is_filled)
509 vout_control_PushBool(&vout->p->control, VOUT_CONTROL_DISPLAY_FILLED,
512 void vout_ControlChangeZoom(vout_thread_t *vout, int num, int den)
514 vout_control_PushPair(&vout->p->control, VOUT_CONTROL_ZOOM,
517 void vout_ControlChangeSampleAspectRatio(vout_thread_t *vout,
518 unsigned num, unsigned den)
520 vout_control_PushPair(&vout->p->control, VOUT_CONTROL_ASPECT_RATIO,
523 void vout_ControlChangeCropRatio(vout_thread_t *vout,
524 unsigned num, unsigned den)
526 vout_control_PushPair(&vout->p->control, VOUT_CONTROL_CROP_RATIO,
529 void vout_ControlChangeCropWindow(vout_thread_t *vout,
530 int x, int y, int width, int height)
532 vout_control_cmd_t cmd;
533 vout_control_cmd_Init(&cmd, VOUT_CONTROL_CROP_WINDOW);
534 cmd.u.window.x = __MAX(x, 0);
535 cmd.u.window.y = __MAX(y, 0);
536 cmd.u.window.width = __MAX(width, 0);
537 cmd.u.window.height = __MAX(height, 0);
539 vout_control_Push(&vout->p->control, &cmd);
541 void vout_ControlChangeCropBorder(vout_thread_t *vout,
542 int left, int top, int right, int bottom)
544 vout_control_cmd_t cmd;
545 vout_control_cmd_Init(&cmd, VOUT_CONTROL_CROP_BORDER);
546 cmd.u.border.left = __MAX(left, 0);
547 cmd.u.border.top = __MAX(top, 0);
548 cmd.u.border.right = __MAX(right, 0);
549 cmd.u.border.bottom = __MAX(bottom, 0);
551 vout_control_Push(&vout->p->control, &cmd);
553 void vout_ControlChangeFilters(vout_thread_t *vout, const char *filters)
555 vout_control_PushString(&vout->p->control, VOUT_CONTROL_CHANGE_FILTERS,
558 void vout_ControlChangeSubSources(vout_thread_t *vout, const char *filters)
560 vout_control_PushString(&vout->p->control, VOUT_CONTROL_CHANGE_SUB_SOURCES,
563 void vout_ControlChangeSubFilters(vout_thread_t *vout, const char *filters)
565 vout_control_PushString(&vout->p->control, VOUT_CONTROL_CHANGE_SUB_FILTERS,
568 void vout_ControlChangeSubMargin(vout_thread_t *vout, int margin)
570 vout_control_PushInteger(&vout->p->control, VOUT_CONTROL_CHANGE_SUB_MARGIN,
575 static void VoutGetDisplayCfg(vout_thread_t *vout, vout_display_cfg_t *cfg, const char *title)
577 /* Load configuration */
578 cfg->is_fullscreen = var_CreateGetBool(vout, "fullscreen")
579 || var_InheritBool(vout, "video-wallpaper");
580 cfg->display.title = title;
581 const int display_width = var_CreateGetInteger(vout, "width");
582 const int display_height = var_CreateGetInteger(vout, "height");
583 cfg->display.width = display_width > 0 ? display_width : 0;
584 cfg->display.height = display_height > 0 ? display_height : 0;
585 cfg->is_display_filled = var_CreateGetBool(vout, "autoscale");
586 unsigned msar_num, msar_den;
587 if (var_InheritURational(vout, &msar_num, &msar_den, "monitor-par") ||
588 msar_num <= 0 || msar_den <= 0) {
592 cfg->display.sar.num = msar_num;
593 cfg->display.sar.den = msar_den;
594 unsigned zoom_den = 1000;
595 unsigned zoom_num = zoom_den * var_CreateGetFloat(vout, "scale");
596 vlc_ureduce(&zoom_num, &zoom_den, zoom_num, zoom_den, 0);
597 cfg->zoom.num = zoom_num;
598 cfg->zoom.den = zoom_den;
599 cfg->align.vertical = VOUT_DISPLAY_ALIGN_CENTER;
600 cfg->align.horizontal = VOUT_DISPLAY_ALIGN_CENTER;
601 const int align_mask = var_CreateGetInteger(vout, "align");
602 if (align_mask & 0x1)
603 cfg->align.horizontal = VOUT_DISPLAY_ALIGN_LEFT;
604 else if (align_mask & 0x2)
605 cfg->align.horizontal = VOUT_DISPLAY_ALIGN_RIGHT;
606 if (align_mask & 0x4)
607 cfg->align.vertical = VOUT_DISPLAY_ALIGN_TOP;
608 else if (align_mask & 0x8)
609 cfg->align.vertical = VOUT_DISPLAY_ALIGN_BOTTOM;
612 vout_window_t * vout_NewDisplayWindow(vout_thread_t *vout, vout_display_t *vd,
613 const vout_window_cfg_t *cfg)
616 vout_window_cfg_t cfg_override = *cfg;
618 if (!var_InheritBool( vout, "embedded-video"))
619 cfg_override.is_standalone = true;
621 if (vout->p->window.is_unused && vout->p->window.object) {
622 assert(!vout->p->splitter_name);
623 if (!cfg_override.is_standalone == !vout->p->window.cfg.is_standalone &&
624 cfg_override.type == vout->p->window.cfg.type) {
625 /* Reuse the stored window */
626 msg_Dbg(vout, "Reusing previous vout window");
627 vout_window_t *window = vout->p->window.object;
628 if (cfg_override.width != vout->p->window.cfg.width ||
629 cfg_override.height != vout->p->window.cfg.height)
630 vout_window_SetSize(window,
631 cfg_override.width, cfg_override.height);
632 vout->p->window.is_unused = false;
633 vout->p->window.cfg = cfg_override;
637 vout_window_Delete(vout->p->window.object);
638 vout->p->window.is_unused = true;
639 vout->p->window.object = NULL;
642 vout_window_t *window = vout_window_New(VLC_OBJECT(vout), "$window",
646 if (!vout->p->splitter_name) {
647 vout->p->window.is_unused = false;
648 vout->p->window.cfg = cfg_override;
649 vout->p->window.object = window;
654 void vout_DeleteDisplayWindow(vout_thread_t *vout, vout_display_t *vd,
655 vout_window_t *window)
658 if (!vout->p->window.is_unused && vout->p->window.object == window) {
659 vout->p->window.is_unused = true;
660 } else if (vout->p->window.is_unused && vout->p->window.object && !window) {
661 vout_window_Delete(vout->p->window.object);
662 vout->p->window.is_unused = true;
663 vout->p->window.object = NULL;
665 vout_window_Delete(window);
670 static picture_t *VoutVideoFilterInteractiveNewPicture(filter_t *filter)
672 vout_thread_t *vout = (vout_thread_t*)filter->p_owner;
674 picture_t *picture = picture_pool_Get(vout->p->private_pool);
676 picture_Reset(picture);
677 VideoFormatCopyCropAr(&picture->format, &filter->fmt_out.video);
681 static picture_t *VoutVideoFilterStaticNewPicture(filter_t *filter)
683 vout_thread_t *vout = (vout_thread_t*)filter->p_owner;
685 vlc_assert_locked(&vout->p->filter.lock);
686 if (filter_chain_GetLength(vout->p->filter.chain_interactive) == 0)
687 return VoutVideoFilterInteractiveNewPicture(filter);
689 return picture_NewFromFormat(&filter->fmt_out.video);
691 static void VoutVideoFilterDelPicture(filter_t *filter, picture_t *picture)
694 picture_Release(picture);
696 static int VoutVideoFilterStaticAllocationSetup(filter_t *filter, void *data)
698 filter->pf_video_buffer_new = VoutVideoFilterStaticNewPicture;
699 filter->pf_video_buffer_del = VoutVideoFilterDelPicture;
700 filter->p_owner = data; /* vout */
703 static int VoutVideoFilterInteractiveAllocationSetup(filter_t *filter, void *data)
705 filter->pf_video_buffer_new = VoutVideoFilterInteractiveNewPicture;
706 filter->pf_video_buffer_del = VoutVideoFilterDelPicture;
707 filter->p_owner = data; /* vout */
710 static void ThreadFilterFlush(vout_thread_t *vout, bool is_locked)
712 if (vout->p->displayed.current)
713 picture_Release( vout->p->displayed.current );
714 vout->p->displayed.current = NULL;
716 if (vout->p->displayed.next)
717 picture_Release( vout->p->displayed.next );
718 vout->p->displayed.next = NULL;
721 vlc_mutex_lock(&vout->p->filter.lock);
722 filter_chain_VideoFlush(vout->p->filter.chain_static);
723 filter_chain_VideoFlush(vout->p->filter.chain_interactive);
725 vlc_mutex_unlock(&vout->p->filter.lock);
733 static void ThreadChangeFilters(vout_thread_t *vout,
734 const video_format_t *source,
738 ThreadFilterFlush(vout, is_locked);
740 vlc_array_t array_static;
741 vlc_array_t array_interactive;
743 vlc_array_init(&array_static);
744 vlc_array_init(&array_interactive);
745 char *current = filters ? strdup(filters) : NULL;
749 char *next = config_ChainCreate(&name, &cfg, current);
752 vout_filter_t *e = xmalloc(sizeof(*e));
755 if (!strcmp(e->name, "deinterlace") ||
756 !strcmp(e->name, "postproc")) {
757 vlc_array_append(&array_static, e);
759 vlc_array_append(&array_interactive, e);
763 config_ChainDestroy(cfg);
771 vlc_mutex_lock(&vout->p->filter.lock);
773 es_format_t fmt_target;
774 es_format_InitFromVideo(&fmt_target, source ? source : &vout->p->filter.format);
776 es_format_t fmt_current = fmt_target;
778 for (int a = 0; a < 2; a++) {
779 vlc_array_t *array = a == 0 ? &array_static :
781 filter_chain_t *chain = a == 0 ? vout->p->filter.chain_static :
782 vout->p->filter.chain_interactive;
784 filter_chain_Reset(chain, &fmt_current, &fmt_current);
785 for (int i = 0; i < vlc_array_count(array); i++) {
786 vout_filter_t *e = vlc_array_item_at_index(array, i);
787 msg_Dbg(vout, "Adding '%s' as %s", e->name, a == 0 ? "static" : "interactive");
788 if (!filter_chain_AppendFilter(chain, e->name, e->cfg, NULL, NULL)) {
789 msg_Err(vout, "Failed to add filter '%s'", e->name);
790 config_ChainDestroy(e->cfg);
795 fmt_current = *filter_chain_GetFmtOut(chain);
796 vlc_array_clear(array);
798 VideoFormatCopyCropAr(&fmt_target.video, &fmt_current.video);
799 if (!es_format_IsSimilar(&fmt_current, &fmt_target)) {
800 msg_Dbg(vout, "Adding a filter to compensate for format changes");
801 if (!filter_chain_AppendFilter(vout->p->filter.chain_interactive, NULL, NULL,
802 &fmt_current, &fmt_target)) {
803 msg_Err(vout, "Failed to compensate for the format changes, removing all filters");
804 filter_chain_Reset(vout->p->filter.chain_static, &fmt_target, &fmt_target);
805 filter_chain_Reset(vout->p->filter.chain_interactive, &fmt_target, &fmt_target);
809 if (vout->p->filter.configuration != filters) {
810 free(vout->p->filter.configuration);
811 vout->p->filter.configuration = filters ? strdup(filters) : NULL;
814 video_format_Clean(&vout->p->filter.format);
815 video_format_Copy(&vout->p->filter.format, source);
819 vlc_mutex_unlock(&vout->p->filter.lock);
824 static int ThreadDisplayPreparePicture(vout_thread_t *vout, bool reuse, bool frame_by_frame)
826 bool is_late_dropped = vout->p->is_late_dropped && !vout->p->pause.is_on && !frame_by_frame;
828 vlc_mutex_lock(&vout->p->filter.lock);
830 picture_t *picture = filter_chain_VideoFilter(vout->p->filter.chain_static, NULL);
831 assert(!reuse || !picture);
835 if (reuse && vout->p->displayed.decoded) {
836 decoded = picture_Hold(vout->p->displayed.decoded);
838 decoded = picture_fifo_Pop(vout->p->decoder_fifo);
840 if (is_late_dropped && !decoded->b_force) {
841 const mtime_t predicted = mdate() + 0; /* TODO improve */
842 const mtime_t late = predicted - decoded->date;
843 if (late > VOUT_DISPLAY_LATE_THRESHOLD) {
844 msg_Warn(vout, "picture is too late to be displayed (missing %"PRId64" ms)", late/1000);
845 picture_Release(decoded);
846 vout_statistic_AddLost(&vout->p->statistic, 1);
848 } else if (late > 0) {
849 msg_Dbg(vout, "picture might be displayed late (missing %"PRId64" ms)", late/1000);
852 if (!VideoFormatIsCropArEqual(&decoded->format, &vout->p->filter.format))
853 ThreadChangeFilters(vout, &decoded->format, vout->p->filter.configuration, true);
861 if (vout->p->displayed.decoded)
862 picture_Release(vout->p->displayed.decoded);
864 vout->p->displayed.decoded = picture_Hold(decoded);
865 vout->p->displayed.timestamp = decoded->date;
866 vout->p->displayed.is_interlaced = !decoded->b_progressive;
868 picture = filter_chain_VideoFilter(vout->p->filter.chain_static, decoded);
871 vlc_mutex_unlock(&vout->p->filter.lock);
876 assert(!vout->p->displayed.next);
877 if (!vout->p->displayed.current)
878 vout->p->displayed.current = picture;
880 vout->p->displayed.next = picture;
884 static int ThreadDisplayRenderPicture(vout_thread_t *vout, bool is_forced)
886 vout_thread_sys_t *sys = vout->p;
887 vout_display_t *vd = vout->p->display.vd;
889 picture_t *torender = picture_Hold(vout->p->displayed.current);
891 vout_chrono_Start(&vout->p->render);
893 vlc_mutex_lock(&vout->p->filter.lock);
894 picture_t *filtered = filter_chain_VideoFilter(vout->p->filter.chain_interactive, torender);
895 vlc_mutex_unlock(&vout->p->filter.lock);
900 if (filtered->date != vout->p->displayed.current->date)
901 msg_Warn(vout, "Unsupported timestamp modifications done by chain_interactive");
904 * Get the subpicture to be displayed
906 const bool do_snapshot = vout_snapshot_IsRequested(&vout->p->snapshot);
907 mtime_t render_subtitle_date;
908 if (vout->p->pause.is_on)
909 render_subtitle_date = vout->p->pause.date;
911 render_subtitle_date = filtered->date > 1 ? filtered->date : mdate();
912 mtime_t render_osd_date = mdate(); /* FIXME wrong */
915 * Get the subpicture to be displayed
917 const bool do_dr_spu = !do_snapshot &&
918 vd->info.subpicture_chromas &&
919 *vd->info.subpicture_chromas != 0;
920 const bool do_early_spu = !do_dr_spu &&
922 sys->display.use_dr ||
924 !vout_IsDisplayFiltered(vd) ||
925 vd->fmt.i_width * vd->fmt.i_height <= vd->source.i_width * vd->source.i_height);
927 const vlc_fourcc_t *subpicture_chromas;
928 video_format_t fmt_spu;
930 vout_display_place_t place;
931 vout_display_PlacePicture(&place, &vd->source, vd->cfg, false);
933 fmt_spu = vd->source;
934 if (fmt_spu.i_width * fmt_spu.i_height < place.width * place.height) {
935 fmt_spu.i_sar_num = vd->cfg->display.sar.num;
936 fmt_spu.i_sar_den = vd->cfg->display.sar.den;
938 fmt_spu.i_visible_width = place.width;
940 fmt_spu.i_visible_height = place.height;
942 subpicture_chromas = vd->info.subpicture_chromas;
945 fmt_spu = vd->source;
948 fmt_spu.i_sar_num = vd->cfg->display.sar.num;
949 fmt_spu.i_sar_den = vd->cfg->display.sar.den;
951 subpicture_chromas = NULL;
953 if (vout->p->spu_blend &&
954 vout->p->spu_blend->fmt_out.video.i_chroma != fmt_spu.i_chroma) {
955 filter_DeleteBlend(vout->p->spu_blend);
956 vout->p->spu_blend = NULL;
957 vout->p->spu_blend_chroma = 0;
959 if (!vout->p->spu_blend && vout->p->spu_blend_chroma != fmt_spu.i_chroma) {
960 vout->p->spu_blend_chroma = fmt_spu.i_chroma;
961 vout->p->spu_blend = filter_NewBlend(VLC_OBJECT(vout), &fmt_spu);
962 if (!vout->p->spu_blend)
963 msg_Err(vout, "Failed to create blending filter, OSD/Subtitles will not work");
967 subpicture_t *subpic = spu_Render(vout->p->spu,
968 subpicture_chromas, &fmt_spu,
970 render_subtitle_date, render_osd_date,
976 * - be sure to end up with a direct buffer.
977 * - blend subtitles, and in a fast access buffer
979 bool is_direct = vout->p->decoder_pool == vout->p->display_pool;
980 picture_t *todisplay = filtered;
981 if (do_early_spu && subpic) {
982 picture_t *blent = picture_pool_Get(vout->p->private_pool);
984 VideoFormatCopyCropAr(&blent->format, &filtered->format);
985 picture_Copy(blent, filtered);
986 if (vout->p->spu_blend
987 && picture_BlendSubpicture(blent, vout->p->spu_blend, subpic)) {
988 picture_Release(todisplay);
991 picture_Release(blent);
993 subpicture_Delete(subpic);
997 assert(vout_IsDisplayFiltered(vd) == !sys->display.use_dr);
998 if (sys->display.use_dr && !is_direct) {
999 picture_t *direct = picture_pool_Get(vout->p->display_pool);
1001 picture_Release(todisplay);
1003 subpicture_Delete(subpic);
1004 return VLC_EGENERIC;
1007 /* The display uses direct rendering (no conversion), but its pool of
1008 * pictures is not usable by the decoder (too few, too slow or
1009 * subject to invalidation...). Since there are no filters, copying
1010 * pictures from the decoder to the output is unavoidable. */
1011 VideoFormatCopyCropAr(&direct->format, &todisplay->format);
1012 picture_Copy(direct, todisplay);
1013 picture_Release(todisplay);
1018 * Take a snapshot if requested
1021 vout_snapshot_Set(&vout->p->snapshot, &vd->source, todisplay);
1023 /* Render the direct buffer */
1024 vout_UpdateDisplaySourceProperties(vd, &todisplay->format);
1025 if (sys->display.use_dr) {
1026 vout_display_Prepare(vd, todisplay, subpic);
1028 sys->display.filtered = vout_FilterDisplay(vd, todisplay);
1029 if (sys->display.filtered) {
1030 if (!do_dr_spu && !do_early_spu && vout->p->spu_blend && subpic)
1031 picture_BlendSubpicture(sys->display.filtered, vout->p->spu_blend, subpic);
1032 vout_display_Prepare(vd, sys->display.filtered, do_dr_spu ? subpic : NULL);
1034 if (!do_dr_spu && subpic)
1036 subpicture_Delete(subpic);
1039 if (!sys->display.filtered)
1040 return VLC_EGENERIC;
1043 vout_chrono_Stop(&vout->p->render);
1047 if (((i++)%10) == 0)
1048 msg_Info(vout, "render: avg %d ms var %d ms",
1049 (int)(vout->p->render.avg/1000), (int)(vout->p->render.var/1000));
1053 /* Wait the real date (for rendering jitter) */
1055 mtime_t delay = direct->date - mdate();
1057 msg_Warn(vout, "picture is late (%lld ms)", delay / 1000);
1060 mwait(todisplay->date);
1062 /* Display the direct buffer returned by vout_RenderPicture */
1063 vout->p->displayed.date = mdate();
1064 vout_display_Display(vd,
1065 sys->display.filtered ? sys->display.filtered
1068 sys->display.filtered = NULL;
1070 vout_statistic_AddDisplayed(&vout->p->statistic, 1);
1075 static int ThreadDisplayPicture(vout_thread_t *vout, mtime_t *deadline)
1077 bool frame_by_frame = !deadline;
1078 bool paused = vout->p->pause.is_on;
1079 bool first = !vout->p->displayed.current;
1082 if (ThreadDisplayPreparePicture(vout, true, frame_by_frame)) /* FIXME not sure it is ok */
1083 return VLC_EGENERIC;
1085 if (!paused || frame_by_frame)
1086 while (!vout->p->displayed.next && !ThreadDisplayPreparePicture(vout, false, frame_by_frame))
1089 const mtime_t date = mdate();
1090 const mtime_t render_delay = vout_chrono_GetHigh(&vout->p->render) + VOUT_MWAIT_TOLERANCE;
1092 bool drop_next_frame = frame_by_frame;
1093 mtime_t date_next = VLC_TS_INVALID;
1094 if (!paused && vout->p->displayed.next) {
1095 date_next = vout->p->displayed.next->date - render_delay;
1096 if (date_next /* + 0 FIXME */ <= date)
1097 drop_next_frame = true;
1100 /* FIXME/XXX we must redisplay the last decoded picture (because
1101 * of potential vout updated, or filters update or SPU update)
1102 * For now a high update period is needed but it could be removed
1104 * - vout module emits events from theselves.
1105 * - *and* SPU is modified to emit an event or a deadline when needed.
1107 * So it will be done later.
1109 bool refresh = false;
1111 mtime_t date_refresh = VLC_TS_INVALID;
1112 if (vout->p->displayed.date > VLC_TS_INVALID) {
1113 date_refresh = vout->p->displayed.date + VOUT_REDISPLAY_DELAY - render_delay;
1114 refresh = date_refresh <= date;
1117 if (!first && !refresh && !drop_next_frame) {
1118 if (!frame_by_frame) {
1119 if (date_refresh != VLC_TS_INVALID)
1120 *deadline = date_refresh;
1121 if (date_next != VLC_TS_INVALID && date_next < *deadline)
1122 *deadline = date_next;
1124 return VLC_EGENERIC;
1127 if (drop_next_frame) {
1128 picture_Release(vout->p->displayed.current);
1129 vout->p->displayed.current = vout->p->displayed.next;
1130 vout->p->displayed.next = NULL;
1133 if (!vout->p->displayed.current)
1134 return VLC_EGENERIC;
1136 /* display the picture immediately */
1137 bool is_forced = frame_by_frame || (!drop_next_frame && refresh) || vout->p->displayed.current->b_force;
1138 return ThreadDisplayRenderPicture(vout, is_forced);
1141 static void ThreadDisplaySubpicture(vout_thread_t *vout,
1142 subpicture_t *subpicture)
1144 spu_PutSubpicture(vout->p->spu, subpicture);
1147 static void ThreadFlushSubpicture(vout_thread_t *vout, int channel)
1149 spu_ClearChannel(vout->p->spu, channel);
1152 static void ThreadDisplayOsdTitle(vout_thread_t *vout, const char *string)
1154 if (!vout->p->title.show)
1157 vout_OSDText(vout, SPU_DEFAULT_CHANNEL,
1158 vout->p->title.position, INT64_C(1000) * vout->p->title.timeout,
1162 static void ThreadChangeSubSources(vout_thread_t *vout, const char *filters)
1164 spu_ChangeSources(vout->p->spu, filters);
1167 static void ThreadChangeSubFilters(vout_thread_t *vout, const char *filters)
1169 spu_ChangeFilters(vout->p->spu, filters);
1172 static void ThreadChangeSubMargin(vout_thread_t *vout, int margin)
1174 spu_ChangeMargin(vout->p->spu, margin);
1177 static void ThreadChangePause(vout_thread_t *vout, bool is_paused, mtime_t date)
1179 assert(!vout->p->pause.is_on || !is_paused);
1181 if (vout->p->pause.is_on) {
1182 const mtime_t duration = date - vout->p->pause.date;
1184 if (vout->p->step.timestamp > VLC_TS_INVALID)
1185 vout->p->step.timestamp += duration;
1186 if (vout->p->step.last > VLC_TS_INVALID)
1187 vout->p->step.last += duration;
1188 picture_fifo_OffsetDate(vout->p->decoder_fifo, duration);
1189 if (vout->p->displayed.decoded)
1190 vout->p->displayed.decoded->date += duration;
1191 spu_OffsetSubtitleDate(vout->p->spu, duration);
1193 ThreadFilterFlush(vout, false);
1195 vout->p->step.timestamp = VLC_TS_INVALID;
1196 vout->p->step.last = VLC_TS_INVALID;
1198 vout->p->pause.is_on = is_paused;
1199 vout->p->pause.date = date;
1202 static void ThreadFlush(vout_thread_t *vout, bool below, mtime_t date)
1204 vout->p->step.timestamp = VLC_TS_INVALID;
1205 vout->p->step.last = VLC_TS_INVALID;
1207 ThreadFilterFlush(vout, false); /* FIXME too much */
1209 picture_t *last = vout->p->displayed.decoded;
1211 if (( below && last->date <= date) ||
1212 (!below && last->date >= date)) {
1213 picture_Release(last);
1215 vout->p->displayed.decoded = NULL;
1216 vout->p->displayed.date = VLC_TS_INVALID;
1217 vout->p->displayed.timestamp = VLC_TS_INVALID;
1221 picture_fifo_Flush(vout->p->decoder_fifo, date, below);
1224 static void ThreadReset(vout_thread_t *vout)
1226 ThreadFlush(vout, true, INT64_MAX);
1227 if (vout->p->decoder_pool)
1228 picture_pool_NonEmpty(vout->p->decoder_pool, true);
1229 vout->p->pause.is_on = false;
1230 vout->p->pause.date = mdate();
1233 static void ThreadStep(vout_thread_t *vout, mtime_t *duration)
1237 if (vout->p->step.last <= VLC_TS_INVALID)
1238 vout->p->step.last = vout->p->displayed.timestamp;
1240 if (ThreadDisplayPicture(vout, NULL))
1243 vout->p->step.timestamp = vout->p->displayed.timestamp;
1245 if (vout->p->step.last > VLC_TS_INVALID &&
1246 vout->p->step.timestamp > vout->p->step.last) {
1247 *duration = vout->p->step.timestamp - vout->p->step.last;
1248 vout->p->step.last = vout->p->step.timestamp;
1249 /* TODO advance subpicture by the duration ... */
1253 static void ThreadChangeFullscreen(vout_thread_t *vout, bool fullscreen)
1255 vout_SetDisplayFullscreen(vout->p->display.vd, fullscreen);
1258 static void ThreadChangeWindowState(vout_thread_t *vout, unsigned state)
1260 vout_SetWindowState(vout->p->display.vd, state);
1263 static void ThreadChangeDisplayFilled(vout_thread_t *vout, bool is_filled)
1265 vout_SetDisplayFilled(vout->p->display.vd, is_filled);
1268 static void ThreadChangeZoom(vout_thread_t *vout, int num, int den)
1270 if (num * 10 < den) {
1273 } else if (num > den * 10) {
1277 vout_SetDisplayZoom(vout->p->display.vd, num, den);
1280 static void ThreadChangeAspectRatio(vout_thread_t *vout,
1281 unsigned num, unsigned den)
1283 vout_SetDisplayAspect(vout->p->display.vd, num, den);
1287 static void ThreadExecuteCropWindow(vout_thread_t *vout,
1288 unsigned x, unsigned y,
1289 unsigned width, unsigned height)
1291 vout_SetDisplayCrop(vout->p->display.vd, 0, 0,
1292 x, y, width, height);
1294 static void ThreadExecuteCropBorder(vout_thread_t *vout,
1295 unsigned left, unsigned top,
1296 unsigned right, unsigned bottom)
1298 msg_Err(vout, "ThreadExecuteCropBorder %d.%d %dx%d", left, top, right, bottom);
1299 vout_SetDisplayCrop(vout->p->display.vd, 0, 0,
1300 left, top, -(int)right, -(int)bottom);
1303 static void ThreadExecuteCropRatio(vout_thread_t *vout,
1304 unsigned num, unsigned den)
1306 vout_SetDisplayCrop(vout->p->display.vd, num, den,
1310 static int ThreadStart(vout_thread_t *vout, const vout_display_state_t *state)
1312 vlc_mouse_Init(&vout->p->mouse);
1313 vout->p->decoder_fifo = picture_fifo_New();
1314 vout->p->decoder_pool = NULL;
1315 vout->p->display_pool = NULL;
1316 vout->p->private_pool = NULL;
1318 vout->p->filter.configuration = NULL;
1319 video_format_Copy(&vout->p->filter.format, &vout->p->original);
1320 vout->p->filter.chain_static =
1321 filter_chain_New( vout, "video filter2", true,
1322 VoutVideoFilterStaticAllocationSetup, NULL, vout);
1323 vout->p->filter.chain_interactive =
1324 filter_chain_New( vout, "video filter2", true,
1325 VoutVideoFilterInteractiveAllocationSetup, NULL, vout);
1327 vout_display_state_t state_default;
1329 var_Create(vout, "video-wallpaper", VLC_VAR_BOOL|VLC_VAR_DOINHERIT);
1330 VoutGetDisplayCfg(vout, &state_default.cfg, vout->p->display.title);
1332 bool below = var_InheritBool(vout, "video-wallpaper");
1333 bool above = var_CreateGetBool(vout, "video-on-top");
1335 state_default.wm_state = below ? VOUT_WINDOW_STATE_BELOW
1336 : above ? VOUT_WINDOW_STATE_ABOVE
1337 : VOUT_WINDOW_STATE_NORMAL;
1338 state_default.sar.num = 0;
1339 state_default.sar.den = 0;
1341 state = &state_default;
1344 if (vout_OpenWrapper(vout, vout->p->splitter_name, state))
1345 return VLC_EGENERIC;
1346 if (vout_InitWrapper(vout))
1347 return VLC_EGENERIC;
1348 assert(vout->p->decoder_pool);
1350 vout->p->displayed.current = NULL;
1351 vout->p->displayed.next = NULL;
1352 vout->p->displayed.decoded = NULL;
1353 vout->p->displayed.date = VLC_TS_INVALID;
1354 vout->p->displayed.timestamp = VLC_TS_INVALID;
1355 vout->p->displayed.is_interlaced = false;
1357 vout->p->step.last = VLC_TS_INVALID;
1358 vout->p->step.timestamp = VLC_TS_INVALID;
1360 vout->p->spu_blend_chroma = 0;
1361 vout->p->spu_blend = NULL;
1363 video_format_Print(VLC_OBJECT(vout), "original format", &vout->p->original);
1367 static void ThreadStop(vout_thread_t *vout, vout_display_state_t *state)
1369 if (vout->p->spu_blend)
1370 filter_DeleteBlend(vout->p->spu_blend);
1372 /* Destroy translation tables */
1373 if (vout->p->display.vd) {
1374 if (vout->p->decoder_pool) {
1375 ThreadFlush(vout, true, INT64_MAX);
1376 vout_EndWrapper(vout);
1378 vout_CloseWrapper(vout, state);
1381 /* Destroy the video filters2 */
1382 filter_chain_Delete(vout->p->filter.chain_interactive);
1383 filter_chain_Delete(vout->p->filter.chain_static);
1384 video_format_Clean(&vout->p->filter.format);
1385 free(vout->p->filter.configuration);
1387 if (vout->p->decoder_fifo)
1388 picture_fifo_Delete(vout->p->decoder_fifo);
1389 assert(!vout->p->decoder_pool);
1392 static void ThreadInit(vout_thread_t *vout)
1394 vout->p->window.is_unused = true;
1395 vout->p->window.object = NULL;
1396 vout->p->dead = false;
1397 vout->p->is_late_dropped = var_InheritBool(vout, "drop-late-frames");
1398 vout->p->pause.is_on = false;
1399 vout->p->pause.date = VLC_TS_INVALID;
1401 vout_chrono_Init(&vout->p->render, 5, 10000); /* Arbitrary initial time */
1404 static void ThreadClean(vout_thread_t *vout)
1406 if (vout->p->window.object) {
1407 assert(vout->p->window.is_unused);
1408 vout_window_Delete(vout->p->window.object);
1410 vout_chrono_Clean(&vout->p->render);
1411 vout->p->dead = true;
1412 vout_control_Dead(&vout->p->control);
1415 static int ThreadReinit(vout_thread_t *vout,
1416 const vout_configuration_t *cfg)
1418 video_format_t original;
1419 if (VoutValidateFormat(&original, cfg->fmt)) {
1420 ThreadStop(vout, NULL);
1422 return VLC_EGENERIC;
1424 /* We ignore crop/ar changes at this point, they are dynamically supported */
1425 VideoFormatCopyCropAr(&vout->p->original, &original);
1426 if (video_format_IsSimilar(&original, &vout->p->original)) {
1427 if (cfg->dpb_size <= vout->p->dpb_size)
1429 msg_Warn(vout, "DPB need to be increased");
1432 vout_display_state_t state;
1433 memset(&state, 0, sizeof(state));
1435 ThreadStop(vout, &state);
1437 if (!state.cfg.is_fullscreen) {
1438 state.cfg.display.width = 0;
1439 state.cfg.display.height = 0;
1443 /* FIXME current vout "variables" are not in sync here anymore
1444 * and I am not sure what to do */
1446 vout->p->original = original;
1447 vout->p->dpb_size = cfg->dpb_size;
1448 if (ThreadStart(vout, &state)) {
1450 return VLC_EGENERIC;
1455 static int ThreadControl(vout_thread_t *vout, vout_control_cmd_t cmd)
1458 case VOUT_CONTROL_INIT:
1460 if (!ThreadStart(vout, NULL))
1462 case VOUT_CONTROL_CLEAN:
1463 ThreadStop(vout, NULL);
1466 case VOUT_CONTROL_REINIT:
1467 if (ThreadReinit(vout, cmd.u.cfg))
1470 case VOUT_CONTROL_SUBPICTURE:
1471 ThreadDisplaySubpicture(vout, cmd.u.subpicture);
1472 cmd.u.subpicture = NULL;
1474 case VOUT_CONTROL_FLUSH_SUBPICTURE:
1475 ThreadFlushSubpicture(vout, cmd.u.integer);
1477 case VOUT_CONTROL_OSD_TITLE:
1478 ThreadDisplayOsdTitle(vout, cmd.u.string);
1480 case VOUT_CONTROL_CHANGE_FILTERS:
1481 ThreadChangeFilters(vout, NULL, cmd.u.string, false);
1483 case VOUT_CONTROL_CHANGE_SUB_SOURCES:
1484 ThreadChangeSubSources(vout, cmd.u.string);
1486 case VOUT_CONTROL_CHANGE_SUB_FILTERS:
1487 ThreadChangeSubFilters(vout, cmd.u.string);
1489 case VOUT_CONTROL_CHANGE_SUB_MARGIN:
1490 ThreadChangeSubMargin(vout, cmd.u.integer);
1492 case VOUT_CONTROL_PAUSE:
1493 ThreadChangePause(vout, cmd.u.pause.is_on, cmd.u.pause.date);
1495 case VOUT_CONTROL_FLUSH:
1496 ThreadFlush(vout, false, cmd.u.time);
1498 case VOUT_CONTROL_RESET:
1501 case VOUT_CONTROL_STEP:
1502 ThreadStep(vout, cmd.u.time_ptr);
1504 case VOUT_CONTROL_FULLSCREEN:
1505 ThreadChangeFullscreen(vout, cmd.u.boolean);
1507 case VOUT_CONTROL_WINDOW_STATE:
1508 ThreadChangeWindowState(vout, cmd.u.integer);
1510 case VOUT_CONTROL_DISPLAY_FILLED:
1511 ThreadChangeDisplayFilled(vout, cmd.u.boolean);
1513 case VOUT_CONTROL_ZOOM:
1514 ThreadChangeZoom(vout, cmd.u.pair.a, cmd.u.pair.b);
1516 case VOUT_CONTROL_ASPECT_RATIO:
1517 ThreadChangeAspectRatio(vout, cmd.u.pair.a, cmd.u.pair.b);
1519 case VOUT_CONTROL_CROP_RATIO:
1520 ThreadExecuteCropRatio(vout, cmd.u.pair.a, cmd.u.pair.b);
1522 case VOUT_CONTROL_CROP_WINDOW:
1523 ThreadExecuteCropWindow(vout,
1524 cmd.u.window.x, cmd.u.window.y,
1525 cmd.u.window.width, cmd.u.window.height);
1527 case VOUT_CONTROL_CROP_BORDER:
1528 ThreadExecuteCropBorder(vout,
1529 cmd.u.border.left, cmd.u.border.top,
1530 cmd.u.border.right, cmd.u.border.bottom);
1535 vout_control_cmd_Clean(&cmd);
1539 /*****************************************************************************
1540 * Thread: video output thread
1541 *****************************************************************************
1542 * Video output thread. This function does only returns when the thread is
1543 * terminated. It handles the pictures arriving in the video heap and the
1544 * display device events.
1545 *****************************************************************************/
1546 static void *Thread(void *object)
1548 vout_thread_t *vout = object;
1549 vout_thread_sys_t *sys = vout->p;
1551 vout_interlacing_support_t interlacing = {
1552 .is_interlaced = false,
1556 mtime_t deadline = VLC_TS_INVALID;
1558 vout_control_cmd_t cmd;
1559 /* FIXME remove thoses ugly timeouts */
1560 while (!vout_control_Pop(&sys->control, &cmd, deadline, 100000))
1561 if (ThreadControl(vout, cmd))
1564 vlc_mutex_lock(&sys->picture_lock);
1566 deadline = VLC_TS_INVALID;
1567 while (!ThreadDisplayPicture(vout, &deadline))
1570 const bool picture_interlaced = sys->displayed.is_interlaced;
1572 vlc_mutex_unlock(&sys->picture_lock);
1574 vout_SetInterlacingState(vout, &interlacing, picture_interlaced);
1575 vout_ManageWrapper(vout);