]> git.sesse.net Git - vlc/blob - modules/misc/dummy/vout.c
Lua_ext: fix race condition.
[vlc] / modules / misc / dummy / vout.c
1 /*****************************************************************************
2  * vout.c: Dummy video output display method for testing purposes
3  *****************************************************************************
4  * Copyright (C) 2000-2009 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Samuel Hocevar <sam@zoy.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #include <vlc_common.h>
33 #include <vlc_vout_display.h>
34 #include "dummy.h"
35
36 /*****************************************************************************
37  * Local prototypes
38  *****************************************************************************/
39 struct vout_display_sys_t {
40     picture_pool_t *pool;
41 };
42 static picture_pool_t *Pool(vout_display_t *, unsigned count);
43 static void            Display(vout_display_t *, picture_t *);
44 static void            DisplayStat(vout_display_t *, picture_t *);
45 static int             Control(vout_display_t *, int, va_list);
46 static void            Manage (vout_display_t *);
47
48 /*****************************************************************************
49  * OpenVideo: activates dummy vout display method
50  *****************************************************************************/
51 static int OpenVideoCommon(vlc_object_t *object, bool display_stat)
52 {
53     vout_display_t *vd = (vout_display_t *)object;
54     vout_display_sys_t *sys;
55
56     vd->sys = sys = calloc(1, sizeof(*sys));
57     if (!sys)
58         return VLC_EGENERIC;
59     sys->pool = NULL;
60
61     /* p_vd->info is not modified */
62
63     char *chroma = var_CreateGetNonEmptyString(vd, "dummy-chroma");
64     if (chroma) {
65         vlc_fourcc_t fcc = vlc_fourcc_GetCodecFromString(VIDEO_ES, chroma);
66         if (fcc != 0) {
67             msg_Dbg(vd, "forcing chroma 0x%.8x (%4.4s)", fcc, (char*)&fcc);
68             vd->fmt.i_chroma = fcc;
69         }
70         free(chroma);
71     }
72     vd->pool    = Pool;
73     vd->prepare = NULL;
74     vd->display = display_stat ? DisplayStat : Display;
75     vd->control = Control;
76     vd->manage  = Manage;
77
78     return VLC_SUCCESS;
79 }
80 int OpenVideo(vlc_object_t *object)
81 {
82     return OpenVideoCommon(object, false);
83 }
84 int OpenVideoStat(vlc_object_t *object)
85 {
86     return OpenVideoCommon(object, true);
87 }
88
89 void CloseVideo(vlc_object_t *object)
90 {
91     vout_display_t *vd = (vout_display_t *)object;
92     vout_display_sys_t *sys = vd->sys;
93
94     if (sys->pool)
95         picture_pool_Delete(sys->pool);
96     free(sys);
97 }
98
99 static picture_pool_t *Pool(vout_display_t *vd, unsigned count)
100 {
101     vout_display_sys_t *sys = vd->sys;
102     if (!sys->pool)
103         sys->pool = picture_pool_NewFromFormat(&vd->fmt, count);
104     return sys->pool;
105 }
106
107 static void Display(vout_display_t *vd, picture_t *picture)
108 {
109     VLC_UNUSED(vd);
110     picture_Release(picture);
111 }
112
113 static void DisplayStat(vout_display_t *vd, picture_t *picture)
114 {
115     VLC_UNUSED(vd);
116     if (vd->fmt.i_width*vd->fmt.i_height >= sizeof(mtime_t)) {
117         mtime_t date;
118         memcpy(&date, picture->p->p_pixels, sizeof(date));
119         msg_Dbg(vd, "VOUT got %"PRIu64" ms offset",
120                 (mdate() - date) / 1000 );
121     }
122     picture_Release(picture);
123 }
124
125 static int Control(vout_display_t *vd, int query, va_list args)
126 {
127     VLC_UNUSED(vd);
128     VLC_UNUSED(query);
129     VLC_UNUSED(args);
130     return VLC_SUCCESS;
131 }
132
133 static void Manage(vout_display_t *vd)
134 {
135     VLC_UNUSED(vd);
136 }