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->picture_lock);
144 vlc_mutex_init(&vout->p->filter.lock);
145 vlc_mutex_init(&vout->p->spu_lock);
147 /* Initialize subpicture unit */
148 vout->p->spu = spu_Create(vout);
150 /* Take care of some "interface/control" related initialisations */
153 vout->p->title.show = var_InheritBool(vout, "video-title-show");
154 vout->p->title.timeout = var_InheritInteger(vout, "video-title-timeout");
155 vout->p->title.position = var_InheritInteger(vout, "video-title-position");
157 /* Get splitter name if present */
158 vout->p->splitter_name = var_InheritString(vout, "video-splitter");
161 vout_InitInterlacingSupport(vout, vout->p->displayed.is_interlaced);
164 if (vout->p->splitter_name == NULL) {
165 vout_window_cfg_t wcfg = {
166 .is_standalone = !var_InheritBool(vout, "embedded-video"),
167 .type = VOUT_WINDOW_TYPE_INVALID,
168 // TODO: take pixel A/R, crop and zoom into account
170 .x = var_InheritInteger(vout, "video-x"),
171 .y = var_InheritInteger(vout, "video-y"),
173 .width = cfg->fmt->i_visible_width,
174 .height = cfg->fmt->i_visible_height,
177 vout_window_t *window = vout_display_window_New(vout, &wcfg);
180 if (var_InheritBool(vout, "video-wallpaper"))
181 vout_window_SetState(window, VOUT_WINDOW_STATE_BELOW);
182 else if (var_InheritBool(vout, "video-on-top"))
183 vout_window_SetState(window, VOUT_WINDOW_STATE_ABOVE);
185 vout->p->window = window;
187 vout->p->window = NULL;
190 vlc_object_set_destructor(vout, VoutDestructor);
193 if (vlc_clone(&vout->p->thread, Thread, vout,
194 VLC_THREAD_PRIORITY_OUTPUT)) {
195 spu_Destroy(vout->p->spu);
196 vlc_object_release(vout);
200 vout_control_WaitEmpty(&vout->p->control);
203 msg_Err(vout, "video output creation failed");
204 vout_CloseAndRelease(vout);
208 vout->p->input = cfg->input;
210 spu_Attach(vout->p->spu, vout->p->input, true);
216 vout_thread_t *vout_Request(vlc_object_t *object,
217 const vout_configuration_t *cfg)
219 vout_thread_t *vout = cfg->vout;
220 if (cfg->change_fmt && !cfg->fmt) {
222 vout_CloseAndRelease(vout);
226 /* If a vout is provided, try reusing it */
228 if (vout->p->input != cfg->input) {
230 spu_Attach(vout->p->spu, vout->p->input, false);
231 vout->p->input = cfg->input;
233 spu_Attach(vout->p->spu, vout->p->input, true);
236 if (cfg->change_fmt) {
237 vout_control_cmd_t cmd;
238 vout_control_cmd_Init(&cmd, VOUT_CONTROL_REINIT);
241 vout_control_Push(&vout->p->control, &cmd);
242 vout_control_WaitEmpty(&vout->p->control);
245 if (!vout->p->dead) {
246 msg_Dbg(object, "reusing provided vout");
247 vout_IntfReinit(vout);
250 vout_CloseAndRelease(vout);
252 msg_Warn(object, "cannot reuse provided vout");
254 return VoutCreate(object, cfg);
257 void vout_Close(vout_thread_t *vout)
262 spu_Attach(vout->p->spu, vout->p->input, false);
264 vout_snapshot_End(&vout->p->snapshot);
266 vout_control_PushVoid(&vout->p->control, VOUT_CONTROL_CLEAN);
267 vlc_join(vout->p->thread, NULL);
269 vlc_mutex_lock(&vout->p->spu_lock);
270 spu_Destroy(vout->p->spu);
272 vlc_mutex_unlock(&vout->p->spu_lock);
276 static void VoutDestructor(vlc_object_t *object)
278 vout_thread_t *vout = (vout_thread_t *)object;
280 /* Make sure the vout was stopped first */
281 //assert(!vout->p_module);
283 free(vout->p->splitter_name);
285 /* Destroy the locks */
286 vlc_mutex_destroy(&vout->p->spu_lock);
287 vlc_mutex_destroy(&vout->p->picture_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 vlc_mutex_lock(&vout->p->picture_lock);
333 picture_t *picture = picture_fifo_Peek(vout->p->decoder_fifo);
335 picture_Release(picture);
337 vlc_mutex_unlock(&vout->p->picture_lock);
342 void vout_FixLeaks( vout_thread_t *vout )
344 vlc_mutex_lock(&vout->p->picture_lock);
346 picture_t *picture = picture_fifo_Peek(vout->p->decoder_fifo);
348 picture = picture_pool_Get(vout->p->decoder_pool);
352 picture_Release(picture);
353 /* Not all pictures has been displayed yet or some are
355 vlc_mutex_unlock(&vout->p->picture_lock);
359 /* There is no reason that no pictures are available, force one
360 * from the pool, becarefull with it though */
361 msg_Err(vout, "pictures leaked, trying to workaround");
364 picture_pool_NonEmpty(vout->p->decoder_pool, false);
366 vlc_mutex_unlock(&vout->p->picture_lock);
368 void vout_NextPicture(vout_thread_t *vout, mtime_t *duration)
370 vout_control_cmd_t cmd;
371 vout_control_cmd_Init(&cmd, VOUT_CONTROL_STEP);
372 cmd.u.time_ptr = duration;
374 vout_control_Push(&vout->p->control, &cmd);
375 vout_control_WaitEmpty(&vout->p->control);
378 void vout_DisplayTitle(vout_thread_t *vout, const char *title)
381 vout_control_PushString(&vout->p->control, VOUT_CONTROL_OSD_TITLE, title);
384 void vout_PutSubpicture( vout_thread_t *vout, subpicture_t *subpic )
386 vout_control_cmd_t cmd;
387 vout_control_cmd_Init(&cmd, VOUT_CONTROL_SUBPICTURE);
388 cmd.u.subpicture = subpic;
390 vout_control_Push(&vout->p->control, &cmd);
392 int vout_RegisterSubpictureChannel( vout_thread_t *vout )
394 int channel = SPU_DEFAULT_CHANNEL;
396 vlc_mutex_lock(&vout->p->spu_lock);
398 channel = spu_RegisterChannel(vout->p->spu);
399 vlc_mutex_unlock(&vout->p->spu_lock);
403 void vout_FlushSubpictureChannel( vout_thread_t *vout, int channel )
405 vout_control_PushInteger(&vout->p->control, VOUT_CONTROL_FLUSH_SUBPICTURE,
410 * It retreives a picture from the vout or NULL if no pictures are
413 * You MUST call vout_PutPicture or vout_ReleasePicture on it.
415 * You may use vout_HoldPicture(paired with vout_ReleasePicture) to keep a
416 * read-only reference.
418 picture_t *vout_GetPicture(vout_thread_t *vout)
421 vlc_mutex_lock(&vout->p->picture_lock);
422 picture_t *picture = picture_pool_Get(vout->p->decoder_pool);
424 picture_Reset(picture);
425 VideoFormatCopyCropAr(&picture->format, &vout->p->original);
427 vlc_mutex_unlock(&vout->p->picture_lock);
433 * It gives to the vout a picture to be displayed.
435 * The given picture MUST comes from vout_GetPicture.
437 * Becareful, after vout_PutPicture is called, picture_t::p_next cannot be
440 void vout_PutPicture(vout_thread_t *vout, picture_t *picture)
442 vlc_mutex_lock(&vout->p->picture_lock);
444 picture->p_next = NULL;
445 picture_fifo_Push(vout->p->decoder_fifo, picture);
447 vlc_mutex_unlock(&vout->p->picture_lock);
449 vout_control_Wake(&vout->p->control);
453 * It releases a picture retreived by vout_GetPicture.
455 void vout_ReleasePicture(vout_thread_t *vout, picture_t *picture)
457 vlc_mutex_lock(&vout->p->picture_lock);
459 picture_Release(picture);
461 vlc_mutex_unlock(&vout->p->picture_lock);
463 vout_control_Wake(&vout->p->control);
467 * It increment the reference counter of a picture retreived by
470 void vout_HoldPicture(vout_thread_t *vout, picture_t *picture)
472 vlc_mutex_lock(&vout->p->picture_lock);
474 picture_Hold(picture);
476 vlc_mutex_unlock(&vout->p->picture_lock);
480 int vout_GetSnapshot(vout_thread_t *vout,
481 block_t **image_dst, picture_t **picture_dst,
483 const char *type, mtime_t timeout)
485 picture_t *picture = vout_snapshot_Get(&vout->p->snapshot, timeout);
487 msg_Err(vout, "Failed to grab a snapshot");
492 vlc_fourcc_t codec = VLC_CODEC_PNG;
493 if (type && image_Type2Fourcc(type))
494 codec = image_Type2Fourcc(type);
496 const int override_width = var_InheritInteger(vout, "snapshot-width");
497 const int override_height = var_InheritInteger(vout, "snapshot-height");
499 if (picture_Export(VLC_OBJECT(vout), image_dst, fmt,
500 picture, codec, override_width, override_height)) {
501 msg_Err(vout, "Failed to convert image for snapshot");
502 picture_Release(picture);
507 *picture_dst = picture;
509 picture_Release(picture);
513 void vout_ChangeAspectRatio( vout_thread_t *p_vout,
514 unsigned int i_num, unsigned int i_den )
516 vout_ControlChangeSampleAspectRatio( p_vout, i_num, i_den );
519 /* vout_Control* are usable by anyone at anytime */
520 void vout_ControlChangeFullscreen(vout_thread_t *vout, bool fullscreen)
522 vout_control_PushBool(&vout->p->control, VOUT_CONTROL_FULLSCREEN,
525 void vout_ControlChangeWindowState(vout_thread_t *vout, unsigned st)
527 vout_control_PushInteger(&vout->p->control, VOUT_CONTROL_WINDOW_STATE, st);
529 void vout_ControlChangeDisplayFilled(vout_thread_t *vout, bool is_filled)
531 vout_control_PushBool(&vout->p->control, VOUT_CONTROL_DISPLAY_FILLED,
534 void vout_ControlChangeZoom(vout_thread_t *vout, int num, int den)
536 vout_control_PushPair(&vout->p->control, VOUT_CONTROL_ZOOM,
539 void vout_ControlChangeSampleAspectRatio(vout_thread_t *vout,
540 unsigned num, unsigned den)
542 vout_control_PushPair(&vout->p->control, VOUT_CONTROL_ASPECT_RATIO,
545 void vout_ControlChangeCropRatio(vout_thread_t *vout,
546 unsigned num, unsigned den)
548 vout_control_PushPair(&vout->p->control, VOUT_CONTROL_CROP_RATIO,
551 void vout_ControlChangeCropWindow(vout_thread_t *vout,
552 int x, int y, int width, int height)
554 vout_control_cmd_t cmd;
555 vout_control_cmd_Init(&cmd, VOUT_CONTROL_CROP_WINDOW);
556 cmd.u.window.x = __MAX(x, 0);
557 cmd.u.window.y = __MAX(y, 0);
558 cmd.u.window.width = __MAX(width, 0);
559 cmd.u.window.height = __MAX(height, 0);
561 vout_control_Push(&vout->p->control, &cmd);
563 void vout_ControlChangeCropBorder(vout_thread_t *vout,
564 int left, int top, int right, int bottom)
566 vout_control_cmd_t cmd;
567 vout_control_cmd_Init(&cmd, VOUT_CONTROL_CROP_BORDER);
568 cmd.u.border.left = __MAX(left, 0);
569 cmd.u.border.top = __MAX(top, 0);
570 cmd.u.border.right = __MAX(right, 0);
571 cmd.u.border.bottom = __MAX(bottom, 0);
573 vout_control_Push(&vout->p->control, &cmd);
575 void vout_ControlChangeFilters(vout_thread_t *vout, const char *filters)
577 vout_control_PushString(&vout->p->control, VOUT_CONTROL_CHANGE_FILTERS,
580 void vout_ControlChangeSubSources(vout_thread_t *vout, const char *filters)
582 vout_control_PushString(&vout->p->control, VOUT_CONTROL_CHANGE_SUB_SOURCES,
585 void vout_ControlChangeSubFilters(vout_thread_t *vout, const char *filters)
587 vout_control_PushString(&vout->p->control, VOUT_CONTROL_CHANGE_SUB_FILTERS,
590 void vout_ControlChangeSubMargin(vout_thread_t *vout, int margin)
592 vout_control_PushInteger(&vout->p->control, VOUT_CONTROL_CHANGE_SUB_MARGIN,
597 static void VoutGetDisplayCfg(vout_thread_t *vout, vout_display_cfg_t *cfg, const char *title)
599 /* Load configuration */
600 cfg->is_fullscreen = var_CreateGetBool(vout, "fullscreen")
601 || var_InheritBool(vout, "video-wallpaper");
602 cfg->display.title = title;
603 const int display_width = var_CreateGetInteger(vout, "width");
604 const int display_height = var_CreateGetInteger(vout, "height");
605 cfg->display.width = display_width > 0 ? display_width : 0;
606 cfg->display.height = display_height > 0 ? display_height : 0;
607 cfg->is_display_filled = var_CreateGetBool(vout, "autoscale");
608 unsigned msar_num, msar_den;
609 if (var_InheritURational(vout, &msar_num, &msar_den, "monitor-par") ||
610 msar_num <= 0 || msar_den <= 0) {
614 cfg->display.sar.num = msar_num;
615 cfg->display.sar.den = msar_den;
616 unsigned zoom_den = 1000;
617 unsigned zoom_num = zoom_den * var_CreateGetFloat(vout, "scale");
618 vlc_ureduce(&zoom_num, &zoom_den, zoom_num, zoom_den, 0);
619 cfg->zoom.num = zoom_num;
620 cfg->zoom.den = zoom_den;
621 cfg->align.vertical = VOUT_DISPLAY_ALIGN_CENTER;
622 cfg->align.horizontal = VOUT_DISPLAY_ALIGN_CENTER;
623 const int align_mask = var_CreateGetInteger(vout, "align");
624 if (align_mask & 0x1)
625 cfg->align.horizontal = VOUT_DISPLAY_ALIGN_LEFT;
626 else if (align_mask & 0x2)
627 cfg->align.horizontal = VOUT_DISPLAY_ALIGN_RIGHT;
628 if (align_mask & 0x4)
629 cfg->align.vertical = VOUT_DISPLAY_ALIGN_TOP;
630 else if (align_mask & 0x8)
631 cfg->align.vertical = VOUT_DISPLAY_ALIGN_BOTTOM;
634 vout_window_t * vout_NewDisplayWindow(vout_thread_t *vout,
635 const vout_window_cfg_t *cfg)
637 vout_window_t *window = vout->p->window;
639 assert(vout->p->splitter_name == NULL);
643 if (cfg->type != VOUT_WINDOW_TYPE_INVALID && cfg->type != window->type)
646 vout_window_SetSize(window, cfg->width, cfg->height);
650 void vout_DeleteDisplayWindow(vout_thread_t *vout, vout_window_t *window)
652 if (window == NULL && vout->p->window != NULL) {
653 vout_display_window_Delete(vout->p->window);
654 vout->p->window = NULL;
656 assert(vout->p->window == window);
659 void vout_SetDisplayWindowSize(vout_thread_t *vout,
660 unsigned width, unsigned height)
662 vout_window_t *window = vout->p->window;
665 /* Request a resize of the window. If it fails, there is nothing to do.
666 * If it succeeds, the window will emit a resize event later. */
667 vout_window_SetSize(window, width, height);
669 if (vout->p->display.vd != NULL)
670 /* Force a resize of window-less display. This is not allowed to fail,
671 * although the display is allowed to ignore the size anyway. */
672 /* FIXME: remove this, fix MSW and OS/2 window providers */
673 vout_display_SendEventDisplaySize(vout->p->display.vd, width, height);
677 static picture_t *VoutVideoFilterInteractiveNewPicture(filter_t *filter)
679 vout_thread_t *vout = filter->owner.sys;
681 picture_t *picture = picture_pool_Get(vout->p->private_pool);
683 picture_Reset(picture);
684 VideoFormatCopyCropAr(&picture->format, &filter->fmt_out.video);
689 static picture_t *VoutVideoFilterStaticNewPicture(filter_t *filter)
691 vout_thread_t *vout = filter->owner.sys;
693 vlc_assert_locked(&vout->p->filter.lock);
694 if (filter_chain_GetLength(vout->p->filter.chain_interactive) == 0)
695 return VoutVideoFilterInteractiveNewPicture(filter);
697 return picture_NewFromFormat(&filter->fmt_out.video);
700 static void VoutVideoFilterDelPicture(filter_t *filter, picture_t *picture)
703 picture_Release(picture);
706 static void ThreadFilterFlush(vout_thread_t *vout, bool is_locked)
708 if (vout->p->displayed.current)
709 picture_Release( vout->p->displayed.current );
710 vout->p->displayed.current = NULL;
712 if (vout->p->displayed.next)
713 picture_Release( vout->p->displayed.next );
714 vout->p->displayed.next = NULL;
717 vlc_mutex_lock(&vout->p->filter.lock);
718 filter_chain_VideoFlush(vout->p->filter.chain_static);
719 filter_chain_VideoFlush(vout->p->filter.chain_interactive);
721 vlc_mutex_unlock(&vout->p->filter.lock);
729 static void ThreadChangeFilters(vout_thread_t *vout,
730 const video_format_t *source,
734 ThreadFilterFlush(vout, is_locked);
736 vlc_array_t array_static;
737 vlc_array_t array_interactive;
739 vlc_array_init(&array_static);
740 vlc_array_init(&array_interactive);
741 char *current = filters ? strdup(filters) : NULL;
745 char *next = config_ChainCreate(&name, &cfg, current);
748 vout_filter_t *e = xmalloc(sizeof(*e));
751 if (!strcmp(e->name, "deinterlace") ||
752 !strcmp(e->name, "postproc")) {
753 vlc_array_append(&array_static, e);
755 vlc_array_append(&array_interactive, e);
759 config_ChainDestroy(cfg);
767 vlc_mutex_lock(&vout->p->filter.lock);
769 es_format_t fmt_target;
770 es_format_InitFromVideo(&fmt_target, source ? source : &vout->p->filter.format);
772 es_format_t fmt_current = fmt_target;
774 for (int a = 0; a < 2; a++) {
775 vlc_array_t *array = a == 0 ? &array_static :
777 filter_chain_t *chain = a == 0 ? vout->p->filter.chain_static :
778 vout->p->filter.chain_interactive;
780 filter_chain_Reset(chain, &fmt_current, &fmt_current);
781 for (int i = 0; i < vlc_array_count(array); i++) {
782 vout_filter_t *e = vlc_array_item_at_index(array, i);
783 msg_Dbg(vout, "Adding '%s' as %s", e->name, a == 0 ? "static" : "interactive");
784 if (!filter_chain_AppendFilter(chain, e->name, e->cfg, NULL, NULL)) {
785 msg_Err(vout, "Failed to add filter '%s'", e->name);
786 config_ChainDestroy(e->cfg);
791 fmt_current = *filter_chain_GetFmtOut(chain);
792 vlc_array_clear(array);
795 if (!es_format_IsSimilar(&fmt_current, &fmt_target)) {
796 msg_Dbg(vout, "Adding a filter to compensate for format changes");
797 if (!filter_chain_AppendFilter(vout->p->filter.chain_interactive, NULL, NULL,
798 &fmt_current, &fmt_target)) {
799 msg_Err(vout, "Failed to compensate for the format changes, removing all filters");
800 filter_chain_Reset(vout->p->filter.chain_static, &fmt_target, &fmt_target);
801 filter_chain_Reset(vout->p->filter.chain_interactive, &fmt_target, &fmt_target);
805 es_format_Clean(&fmt_target);
807 if (vout->p->filter.configuration != filters) {
808 free(vout->p->filter.configuration);
809 vout->p->filter.configuration = filters ? strdup(filters) : NULL;
812 video_format_Clean(&vout->p->filter.format);
813 video_format_Copy(&vout->p->filter.format, source);
817 vlc_mutex_unlock(&vout->p->filter.lock);
822 static int ThreadDisplayPreparePicture(vout_thread_t *vout, bool reuse, bool frame_by_frame)
824 bool is_late_dropped = vout->p->is_late_dropped && !vout->p->pause.is_on && !frame_by_frame;
826 vlc_mutex_lock(&vout->p->filter.lock);
828 picture_t *picture = filter_chain_VideoFilter(vout->p->filter.chain_static, NULL);
829 assert(!reuse || !picture);
833 if (reuse && vout->p->displayed.decoded) {
834 decoded = picture_Hold(vout->p->displayed.decoded);
836 decoded = picture_fifo_Pop(vout->p->decoder_fifo);
838 if (is_late_dropped && !decoded->b_force) {
839 const mtime_t predicted = mdate() + 0; /* TODO improve */
840 const mtime_t late = predicted - decoded->date;
841 if (late > VOUT_DISPLAY_LATE_THRESHOLD) {
842 msg_Warn(vout, "picture is too late to be displayed (missing %"PRId64" ms)", late/1000);
843 picture_Release(decoded);
844 vout_statistic_AddLost(&vout->p->statistic, 1);
846 } else if (late > 0) {
847 msg_Dbg(vout, "picture might be displayed late (missing %"PRId64" ms)", late/1000);
850 if (!VideoFormatIsCropArEqual(&decoded->format, &vout->p->filter.format))
851 ThreadChangeFilters(vout, &decoded->format, vout->p->filter.configuration, true);
859 if (vout->p->displayed.decoded)
860 picture_Release(vout->p->displayed.decoded);
862 vout->p->displayed.decoded = picture_Hold(decoded);
863 vout->p->displayed.timestamp = decoded->date;
864 vout->p->displayed.is_interlaced = !decoded->b_progressive;
866 picture = filter_chain_VideoFilter(vout->p->filter.chain_static, decoded);
869 vlc_mutex_unlock(&vout->p->filter.lock);
874 assert(!vout->p->displayed.next);
875 if (!vout->p->displayed.current)
876 vout->p->displayed.current = picture;
878 vout->p->displayed.next = picture;
882 static int ThreadDisplayRenderPicture(vout_thread_t *vout, bool is_forced)
884 vout_thread_sys_t *sys = vout->p;
885 vout_display_t *vd = vout->p->display.vd;
887 picture_t *torender = picture_Hold(vout->p->displayed.current);
889 vout_chrono_Start(&vout->p->render);
891 vlc_mutex_lock(&vout->p->filter.lock);
892 picture_t *filtered = filter_chain_VideoFilter(vout->p->filter.chain_interactive, torender);
893 vlc_mutex_unlock(&vout->p->filter.lock);
898 if (filtered->date != vout->p->displayed.current->date)
899 msg_Warn(vout, "Unsupported timestamp modifications done by chain_interactive");
902 * Get the subpicture to be displayed
904 const bool do_snapshot = vout_snapshot_IsRequested(&vout->p->snapshot);
905 mtime_t render_subtitle_date;
906 if (vout->p->pause.is_on)
907 render_subtitle_date = vout->p->pause.date;
909 render_subtitle_date = filtered->date > 1 ? filtered->date : mdate();
910 mtime_t render_osd_date = mdate(); /* FIXME wrong */
913 * Get the subpicture to be displayed
915 const bool do_dr_spu = !do_snapshot &&
916 vd->info.subpicture_chromas &&
917 *vd->info.subpicture_chromas != 0;
919 //FIXME: Denying do_early_spu if vd->source.orientation != ORIENT_NORMAL
920 //will have the effect that snapshots miss the subpictures. We do this
921 //because there is currently no way to transform subpictures to match
923 const bool do_early_spu = !do_dr_spu &&
924 vd->source.orientation == ORIENT_NORMAL &&
926 sys->display.use_dr ||
928 !vout_IsDisplayFiltered(vd) ||
929 vd->fmt.i_width * vd->fmt.i_height <= vd->source.i_width * vd->source.i_height);
931 const vlc_fourcc_t *subpicture_chromas;
932 video_format_t fmt_spu;
934 vout_display_place_t place;
935 vout_display_PlacePicture(&place, &vd->source, vd->cfg, false);
937 fmt_spu = vd->source;
938 if (fmt_spu.i_width * fmt_spu.i_height < place.width * place.height) {
939 fmt_spu.i_sar_num = vd->cfg->display.sar.num;
940 fmt_spu.i_sar_den = vd->cfg->display.sar.den;
942 fmt_spu.i_visible_width = place.width;
944 fmt_spu.i_visible_height = place.height;
946 subpicture_chromas = vd->info.subpicture_chromas;
949 fmt_spu = vd->source;
952 fmt_spu.i_sar_num = vd->cfg->display.sar.num;
953 fmt_spu.i_sar_den = vd->cfg->display.sar.den;
955 subpicture_chromas = NULL;
957 if (vout->p->spu_blend &&
958 vout->p->spu_blend->fmt_out.video.i_chroma != fmt_spu.i_chroma) {
959 filter_DeleteBlend(vout->p->spu_blend);
960 vout->p->spu_blend = NULL;
961 vout->p->spu_blend_chroma = 0;
963 if (!vout->p->spu_blend && vout->p->spu_blend_chroma != fmt_spu.i_chroma) {
964 vout->p->spu_blend_chroma = fmt_spu.i_chroma;
965 vout->p->spu_blend = filter_NewBlend(VLC_OBJECT(vout), &fmt_spu);
966 if (!vout->p->spu_blend)
967 msg_Err(vout, "Failed to create blending filter, OSD/Subtitles will not work");
971 video_format_t fmt_spu_rot;
972 video_format_ApplyRotation(&fmt_spu_rot, &fmt_spu);
973 subpicture_t *subpic = spu_Render(vout->p->spu,
974 subpicture_chromas, &fmt_spu_rot,
976 render_subtitle_date, render_osd_date,
982 * - be sure to end up with a direct buffer.
983 * - blend subtitles, and in a fast access buffer
985 bool is_direct = vout->p->decoder_pool == vout->p->display_pool;
986 picture_t *todisplay = filtered;
987 if (do_early_spu && subpic) {
988 picture_t *blent = picture_pool_Get(vout->p->private_pool);
990 VideoFormatCopyCropAr(&blent->format, &filtered->format);
991 picture_Copy(blent, filtered);
992 if (vout->p->spu_blend
993 && picture_BlendSubpicture(blent, vout->p->spu_blend, subpic)) {
994 picture_Release(todisplay);
997 picture_Release(blent);
999 subpicture_Delete(subpic);
1003 assert(vout_IsDisplayFiltered(vd) == !sys->display.use_dr);
1004 if (sys->display.use_dr && !is_direct) {
1005 picture_t *direct = picture_pool_Get(vout->p->display_pool);
1007 picture_Release(todisplay);
1009 subpicture_Delete(subpic);
1010 return VLC_EGENERIC;
1013 /* The display uses direct rendering (no conversion), but its pool of
1014 * pictures is not usable by the decoder (too few, too slow or
1015 * subject to invalidation...). Since there are no filters, copying
1016 * pictures from the decoder to the output is unavoidable. */
1017 VideoFormatCopyCropAr(&direct->format, &todisplay->format);
1018 picture_Copy(direct, todisplay);
1019 picture_Release(todisplay);
1024 * Take a snapshot if requested
1027 vout_snapshot_Set(&vout->p->snapshot, &vd->source, todisplay);
1029 /* Render the direct buffer */
1030 vout_UpdateDisplaySourceProperties(vd, &todisplay->format);
1031 if (sys->display.use_dr) {
1032 vout_display_Prepare(vd, todisplay, subpic);
1034 sys->display.filtered = vout_FilterDisplay(vd, todisplay);
1035 if (sys->display.filtered) {
1036 if (!do_dr_spu && !do_early_spu && vout->p->spu_blend && subpic)
1037 picture_BlendSubpicture(sys->display.filtered, vout->p->spu_blend, subpic);
1038 vout_display_Prepare(vd, sys->display.filtered, do_dr_spu ? subpic : NULL);
1040 if (!do_dr_spu && subpic)
1042 subpicture_Delete(subpic);
1045 if (!sys->display.filtered)
1046 return VLC_EGENERIC;
1049 vout_chrono_Stop(&vout->p->render);
1053 if (((i++)%10) == 0)
1054 msg_Info(vout, "render: avg %d ms var %d ms",
1055 (int)(vout->p->render.avg/1000), (int)(vout->p->render.var/1000));
1059 /* Wait the real date (for rendering jitter) */
1061 mtime_t delay = direct->date - mdate();
1063 msg_Warn(vout, "picture is late (%lld ms)", delay / 1000);
1066 mwait(todisplay->date);
1068 /* Display the direct buffer returned by vout_RenderPicture */
1069 vout->p->displayed.date = mdate();
1070 vout_display_Display(vd,
1071 sys->display.filtered ? sys->display.filtered
1074 sys->display.filtered = NULL;
1076 vout_statistic_AddDisplayed(&vout->p->statistic, 1);
1081 static int ThreadDisplayPicture(vout_thread_t *vout, mtime_t *deadline)
1083 bool frame_by_frame = !deadline;
1084 bool paused = vout->p->pause.is_on;
1085 bool first = !vout->p->displayed.current;
1088 if (ThreadDisplayPreparePicture(vout, true, frame_by_frame)) /* FIXME not sure it is ok */
1089 return VLC_EGENERIC;
1091 if (!paused || frame_by_frame)
1092 while (!vout->p->displayed.next && !ThreadDisplayPreparePicture(vout, false, frame_by_frame))
1095 const mtime_t date = mdate();
1096 const mtime_t render_delay = vout_chrono_GetHigh(&vout->p->render) + VOUT_MWAIT_TOLERANCE;
1098 bool drop_next_frame = frame_by_frame;
1099 mtime_t date_next = VLC_TS_INVALID;
1100 if (!paused && vout->p->displayed.next) {
1101 date_next = vout->p->displayed.next->date - render_delay;
1102 if (date_next /* + 0 FIXME */ <= date)
1103 drop_next_frame = true;
1106 /* FIXME/XXX we must redisplay the last decoded picture (because
1107 * of potential vout updated, or filters update or SPU update)
1108 * For now a high update period is needed but it could be removed
1110 * - vout module emits events from theselves.
1111 * - *and* SPU is modified to emit an event or a deadline when needed.
1113 * So it will be done later.
1115 bool refresh = false;
1117 mtime_t date_refresh = VLC_TS_INVALID;
1118 if (vout->p->displayed.date > VLC_TS_INVALID) {
1119 date_refresh = vout->p->displayed.date + VOUT_REDISPLAY_DELAY - render_delay;
1120 refresh = date_refresh <= date;
1122 bool force_refresh = !drop_next_frame && refresh;
1124 if (!first && !refresh && !drop_next_frame) {
1125 if (!frame_by_frame) {
1126 if (date_refresh != VLC_TS_INVALID)
1127 *deadline = date_refresh;
1128 if (date_next != VLC_TS_INVALID && date_next < *deadline)
1129 *deadline = date_next;
1131 return VLC_EGENERIC;
1134 if (drop_next_frame) {
1135 picture_Release(vout->p->displayed.current);
1136 vout->p->displayed.current = vout->p->displayed.next;
1137 vout->p->displayed.next = NULL;
1140 if (!vout->p->displayed.current)
1141 return VLC_EGENERIC;
1143 /* display the picture immediately */
1144 bool is_forced = frame_by_frame || force_refresh || vout->p->displayed.current->b_force;
1145 int ret = ThreadDisplayRenderPicture(vout, is_forced);
1146 return force_refresh ? VLC_EGENERIC : ret;
1149 static void ThreadDisplaySubpicture(vout_thread_t *vout,
1150 subpicture_t *subpicture)
1152 spu_PutSubpicture(vout->p->spu, subpicture);
1155 static void ThreadFlushSubpicture(vout_thread_t *vout, int channel)
1157 spu_ClearChannel(vout->p->spu, channel);
1160 static void ThreadDisplayOsdTitle(vout_thread_t *vout, const char *string)
1162 if (!vout->p->title.show)
1165 vout_OSDText(vout, SPU_DEFAULT_CHANNEL,
1166 vout->p->title.position, INT64_C(1000) * vout->p->title.timeout,
1170 static void ThreadChangeSubSources(vout_thread_t *vout, const char *filters)
1172 spu_ChangeSources(vout->p->spu, filters);
1175 static void ThreadChangeSubFilters(vout_thread_t *vout, const char *filters)
1177 spu_ChangeFilters(vout->p->spu, filters);
1180 static void ThreadChangeSubMargin(vout_thread_t *vout, int margin)
1182 spu_ChangeMargin(vout->p->spu, margin);
1185 static void ThreadChangePause(vout_thread_t *vout, bool is_paused, mtime_t date)
1187 assert(!vout->p->pause.is_on || !is_paused);
1189 if (vout->p->pause.is_on) {
1190 const mtime_t duration = date - vout->p->pause.date;
1192 if (vout->p->step.timestamp > VLC_TS_INVALID)
1193 vout->p->step.timestamp += duration;
1194 if (vout->p->step.last > VLC_TS_INVALID)
1195 vout->p->step.last += duration;
1196 picture_fifo_OffsetDate(vout->p->decoder_fifo, duration);
1197 if (vout->p->displayed.decoded)
1198 vout->p->displayed.decoded->date += duration;
1199 spu_OffsetSubtitleDate(vout->p->spu, duration);
1201 ThreadFilterFlush(vout, false);
1203 vout->p->step.timestamp = VLC_TS_INVALID;
1204 vout->p->step.last = VLC_TS_INVALID;
1206 vout->p->pause.is_on = is_paused;
1207 vout->p->pause.date = date;
1210 static void ThreadFlush(vout_thread_t *vout, bool below, mtime_t date)
1212 vout->p->step.timestamp = VLC_TS_INVALID;
1213 vout->p->step.last = VLC_TS_INVALID;
1215 ThreadFilterFlush(vout, false); /* FIXME too much */
1217 picture_t *last = vout->p->displayed.decoded;
1219 if (( below && last->date <= date) ||
1220 (!below && last->date >= date)) {
1221 picture_Release(last);
1223 vout->p->displayed.decoded = NULL;
1224 vout->p->displayed.date = VLC_TS_INVALID;
1225 vout->p->displayed.timestamp = VLC_TS_INVALID;
1229 picture_fifo_Flush(vout->p->decoder_fifo, date, below);
1232 static void ThreadReset(vout_thread_t *vout)
1234 ThreadFlush(vout, true, INT64_MAX);
1235 if (vout->p->decoder_pool)
1236 picture_pool_NonEmpty(vout->p->decoder_pool, true);
1237 vout->p->pause.is_on = false;
1238 vout->p->pause.date = mdate();
1241 static void ThreadStep(vout_thread_t *vout, mtime_t *duration)
1245 if (vout->p->step.last <= VLC_TS_INVALID)
1246 vout->p->step.last = vout->p->displayed.timestamp;
1248 if (ThreadDisplayPicture(vout, NULL))
1251 vout->p->step.timestamp = vout->p->displayed.timestamp;
1253 if (vout->p->step.last > VLC_TS_INVALID &&
1254 vout->p->step.timestamp > vout->p->step.last) {
1255 *duration = vout->p->step.timestamp - vout->p->step.last;
1256 vout->p->step.last = vout->p->step.timestamp;
1257 /* TODO advance subpicture by the duration ... */
1261 static void ThreadChangeFullscreen(vout_thread_t *vout, bool fullscreen)
1263 vout_SetDisplayFullscreen(vout->p->display.vd, fullscreen);
1266 static void ThreadChangeWindowState(vout_thread_t *vout, unsigned state)
1268 vout_window_t *window = vout->p->window;
1271 vout_window_SetState(window, state);
1272 #if defined(_WIN32) || defined(__OS2__)
1273 else /* FIXME: remove this event */
1274 if (vout->p->display.vd != NULL)
1275 vout_display_SendEvent(vout->p->display.vd,
1276 VOUT_DISPLAY_EVENT_WINDOW_STATE, state);
1280 static void ThreadChangeDisplayFilled(vout_thread_t *vout, bool is_filled)
1282 vout_SetDisplayFilled(vout->p->display.vd, is_filled);
1285 static void ThreadChangeZoom(vout_thread_t *vout, int num, int den)
1287 if (num * 10 < den) {
1290 } else if (num > den * 10) {
1294 vout_SetDisplayZoom(vout->p->display.vd, num, den);
1297 static void ThreadChangeAspectRatio(vout_thread_t *vout,
1298 unsigned num, unsigned den)
1300 vout_SetDisplayAspect(vout->p->display.vd, num, den);
1304 static void ThreadExecuteCropWindow(vout_thread_t *vout,
1305 unsigned x, unsigned y,
1306 unsigned width, unsigned height)
1308 vout_SetDisplayCrop(vout->p->display.vd, 0, 0,
1309 x, y, width, height);
1311 static void ThreadExecuteCropBorder(vout_thread_t *vout,
1312 unsigned left, unsigned top,
1313 unsigned right, unsigned bottom)
1315 msg_Err(vout, "ThreadExecuteCropBorder %d.%d %dx%d", left, top, right, bottom);
1316 vout_SetDisplayCrop(vout->p->display.vd, 0, 0,
1317 left, top, -(int)right, -(int)bottom);
1320 static void ThreadExecuteCropRatio(vout_thread_t *vout,
1321 unsigned num, unsigned den)
1323 vout_SetDisplayCrop(vout->p->display.vd, num, den,
1327 static int ThreadStart(vout_thread_t *vout, const vout_display_state_t *state)
1329 vlc_mouse_Init(&vout->p->mouse);
1330 vout->p->decoder_fifo = picture_fifo_New();
1331 vout->p->decoder_pool = NULL;
1332 vout->p->display_pool = NULL;
1333 vout->p->private_pool = NULL;
1335 vout->p->filter.configuration = NULL;
1336 video_format_Copy(&vout->p->filter.format, &vout->p->original);
1338 filter_owner_t owner = {
1341 .buffer_new = VoutVideoFilterStaticNewPicture,
1342 .buffer_del = VoutVideoFilterDelPicture,
1345 vout->p->filter.chain_static =
1346 filter_chain_NewVideo( vout, true, &owner );
1348 owner.video.buffer_new = VoutVideoFilterInteractiveNewPicture;
1349 vout->p->filter.chain_interactive =
1350 filter_chain_NewVideo( vout, true, &owner );
1352 vout_display_state_t state_default;
1354 VoutGetDisplayCfg(vout, &state_default.cfg, vout->p->display.title);
1356 #if defined(_WIN32) || defined(__OS2__)
1357 bool below = var_InheritBool(vout, "video-wallpaper");
1358 bool above = var_InheritBool(vout, "video-on-top");
1360 state_default.wm_state = below ? VOUT_WINDOW_STATE_BELOW
1361 : above ? VOUT_WINDOW_STATE_ABOVE
1362 : VOUT_WINDOW_STATE_NORMAL;
1364 state_default.sar.num = 0;
1365 state_default.sar.den = 0;
1367 state = &state_default;
1370 if (vout_OpenWrapper(vout, vout->p->splitter_name, state))
1371 return VLC_EGENERIC;
1372 if (vout_InitWrapper(vout))
1373 return VLC_EGENERIC;
1374 assert(vout->p->decoder_pool);
1376 vout->p->displayed.current = NULL;
1377 vout->p->displayed.next = NULL;
1378 vout->p->displayed.decoded = NULL;
1379 vout->p->displayed.date = VLC_TS_INVALID;
1380 vout->p->displayed.timestamp = VLC_TS_INVALID;
1381 vout->p->displayed.is_interlaced = false;
1383 vout->p->step.last = VLC_TS_INVALID;
1384 vout->p->step.timestamp = VLC_TS_INVALID;
1386 vout->p->spu_blend_chroma = 0;
1387 vout->p->spu_blend = NULL;
1389 video_format_Print(VLC_OBJECT(vout), "original format", &vout->p->original);
1393 static void ThreadStop(vout_thread_t *vout, vout_display_state_t *state)
1395 if (vout->p->spu_blend)
1396 filter_DeleteBlend(vout->p->spu_blend);
1398 /* Destroy translation tables */
1399 if (vout->p->display.vd) {
1400 if (vout->p->decoder_pool) {
1401 ThreadFlush(vout, true, INT64_MAX);
1402 vout_EndWrapper(vout);
1404 vout_CloseWrapper(vout, state);
1407 /* Destroy the video filters2 */
1408 filter_chain_Delete(vout->p->filter.chain_interactive);
1409 filter_chain_Delete(vout->p->filter.chain_static);
1410 video_format_Clean(&vout->p->filter.format);
1411 free(vout->p->filter.configuration);
1413 if (vout->p->decoder_fifo)
1414 picture_fifo_Delete(vout->p->decoder_fifo);
1415 assert(!vout->p->decoder_pool);
1418 static void ThreadInit(vout_thread_t *vout)
1420 vout->p->dead = false;
1421 vout->p->is_late_dropped = var_InheritBool(vout, "drop-late-frames");
1422 vout->p->pause.is_on = false;
1423 vout->p->pause.date = VLC_TS_INVALID;
1425 vout_chrono_Init(&vout->p->render, 5, 10000); /* Arbitrary initial time */
1428 static void ThreadClean(vout_thread_t *vout)
1430 if (vout->p->window != NULL)
1431 vout_window_Delete(vout->p->window);
1432 vout_chrono_Clean(&vout->p->render);
1433 vout->p->dead = true;
1434 vout_control_Dead(&vout->p->control);
1437 static int ThreadReinit(vout_thread_t *vout,
1438 const vout_configuration_t *cfg)
1440 video_format_t original;
1441 if (VoutValidateFormat(&original, cfg->fmt)) {
1442 ThreadStop(vout, NULL);
1444 return VLC_EGENERIC;
1446 /* We ignore crop/ar changes at this point, they are dynamically supported */
1447 VideoFormatCopyCropAr(&vout->p->original, &original);
1448 if (video_format_IsSimilar(&original, &vout->p->original)) {
1449 if (cfg->dpb_size <= vout->p->dpb_size)
1451 msg_Warn(vout, "DPB need to be increased");
1454 vout_display_state_t state;
1455 memset(&state, 0, sizeof(state));
1457 ThreadStop(vout, &state);
1459 if (!state.cfg.is_fullscreen) {
1460 state.cfg.display.width = 0;
1461 state.cfg.display.height = 0;
1466 /* FIXME current vout "variables" are not in sync here anymore
1467 * and I am not sure what to do */
1468 if (state.cfg.display.sar.num <= 0 || state.cfg.display.sar.den <= 0) {
1469 state.cfg.display.sar.num = 1;
1470 state.cfg.display.sar.den = 1;
1472 if (state.cfg.zoom.num <= 0 || state.cfg.zoom.den <= 0) {
1473 state.cfg.zoom.num = 1;
1474 state.cfg.zoom.den = 1;
1477 vout->p->original = original;
1478 vout->p->dpb_size = cfg->dpb_size;
1479 if (ThreadStart(vout, &state)) {
1481 return VLC_EGENERIC;
1486 static int ThreadControl(vout_thread_t *vout, vout_control_cmd_t cmd)
1489 case VOUT_CONTROL_INIT:
1491 if (!ThreadStart(vout, NULL))
1493 case VOUT_CONTROL_CLEAN:
1494 ThreadStop(vout, NULL);
1497 case VOUT_CONTROL_REINIT:
1498 if (ThreadReinit(vout, cmd.u.cfg))
1501 case VOUT_CONTROL_SUBPICTURE:
1502 ThreadDisplaySubpicture(vout, cmd.u.subpicture);
1503 cmd.u.subpicture = NULL;
1505 case VOUT_CONTROL_FLUSH_SUBPICTURE:
1506 ThreadFlushSubpicture(vout, cmd.u.integer);
1508 case VOUT_CONTROL_OSD_TITLE:
1509 ThreadDisplayOsdTitle(vout, cmd.u.string);
1511 case VOUT_CONTROL_CHANGE_FILTERS:
1512 ThreadChangeFilters(vout, NULL, cmd.u.string, false);
1514 case VOUT_CONTROL_CHANGE_SUB_SOURCES:
1515 ThreadChangeSubSources(vout, cmd.u.string);
1517 case VOUT_CONTROL_CHANGE_SUB_FILTERS:
1518 ThreadChangeSubFilters(vout, cmd.u.string);
1520 case VOUT_CONTROL_CHANGE_SUB_MARGIN:
1521 ThreadChangeSubMargin(vout, cmd.u.integer);
1523 case VOUT_CONTROL_PAUSE:
1524 ThreadChangePause(vout, cmd.u.pause.is_on, cmd.u.pause.date);
1526 case VOUT_CONTROL_FLUSH:
1527 ThreadFlush(vout, false, cmd.u.time);
1529 case VOUT_CONTROL_RESET:
1532 case VOUT_CONTROL_STEP:
1533 ThreadStep(vout, cmd.u.time_ptr);
1535 case VOUT_CONTROL_FULLSCREEN:
1536 ThreadChangeFullscreen(vout, cmd.u.boolean);
1538 case VOUT_CONTROL_WINDOW_STATE:
1539 ThreadChangeWindowState(vout, cmd.u.integer);
1541 case VOUT_CONTROL_DISPLAY_FILLED:
1542 ThreadChangeDisplayFilled(vout, cmd.u.boolean);
1544 case VOUT_CONTROL_ZOOM:
1545 ThreadChangeZoom(vout, cmd.u.pair.a, cmd.u.pair.b);
1547 case VOUT_CONTROL_ASPECT_RATIO:
1548 ThreadChangeAspectRatio(vout, cmd.u.pair.a, cmd.u.pair.b);
1550 case VOUT_CONTROL_CROP_RATIO:
1551 ThreadExecuteCropRatio(vout, cmd.u.pair.a, cmd.u.pair.b);
1553 case VOUT_CONTROL_CROP_WINDOW:
1554 ThreadExecuteCropWindow(vout,
1555 cmd.u.window.x, cmd.u.window.y,
1556 cmd.u.window.width, cmd.u.window.height);
1558 case VOUT_CONTROL_CROP_BORDER:
1559 ThreadExecuteCropBorder(vout,
1560 cmd.u.border.left, cmd.u.border.top,
1561 cmd.u.border.right, cmd.u.border.bottom);
1566 vout_control_cmd_Clean(&cmd);
1570 /*****************************************************************************
1571 * Thread: video output thread
1572 *****************************************************************************
1573 * Video output thread. This function does only returns when the thread is
1574 * terminated. It handles the pictures arriving in the video heap and the
1575 * display device events.
1576 *****************************************************************************/
1577 static void *Thread(void *object)
1579 vout_thread_t *vout = object;
1580 vout_thread_sys_t *sys = vout->p;
1582 vout_interlacing_support_t interlacing = {
1583 .is_interlaced = false,
1587 mtime_t deadline = VLC_TS_INVALID;
1589 vout_control_cmd_t cmd;
1590 /* FIXME remove thoses ugly timeouts */
1591 while (!vout_control_Pop(&sys->control, &cmd, deadline, 100000))
1592 if (ThreadControl(vout, cmd))
1595 vlc_mutex_lock(&sys->picture_lock);
1597 deadline = VLC_TS_INVALID;
1598 while (!ThreadDisplayPicture(vout, &deadline))
1601 const bool picture_interlaced = sys->displayed.is_interlaced;
1603 vlc_mutex_unlock(&sys->picture_lock);
1605 vout_SetInterlacingState(vout, &interlacing, picture_interlaced);
1606 vout_ManageWrapper(vout);