]> git.sesse.net Git - vlc/blob - modules/misc/dummy/vout.c
e85e22f03e3d67b1780a6c2b8fbb9b883cfcccde
[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     picture_pool_Delete(sys->pool);
95     free(sys);
96 }
97
98 static picture_pool_t *Pool(vout_display_t *vd, unsigned count)
99 {
100     vout_display_sys_t *sys = vd->sys;
101     if (!sys->pool)
102         sys->pool = picture_pool_NewFromFormat(&vd->fmt, count);
103     return sys->pool;
104 }
105
106 static void Display(vout_display_t *vd, picture_t *picture)
107 {
108     VLC_UNUSED(vd);
109     picture_Release(picture);
110 }
111
112 static void DisplayStat(vout_display_t *vd, picture_t *picture)
113 {
114     VLC_UNUSED(vd);
115     if (vd->fmt.i_width*vd->fmt.i_height >= sizeof(mtime_t)) {
116         mtime_t date;
117         memcpy(&date, picture->p->p_pixels, sizeof(date));
118         msg_Dbg(vd, "VOUT got %"PRIu64" ms offset",
119                 (mdate() - date) / 1000 );
120     }
121     picture_Release(picture);
122 }
123
124 static int Control(vout_display_t *vd, int query, va_list args)
125 {
126     VLC_UNUSED(vd);
127     VLC_UNUSED(query);
128     VLC_UNUSED(args);
129     return VLC_SUCCESS;
130 }
131
132 static void Manage(vout_display_t *vd)
133 {
134     VLC_UNUSED(vd);
135 }