]> git.sesse.net Git - vlc/blob - modules/video_output/vdummy.c
230a717ef80145343d3208d9d830e9860c122074
[vlc] / modules / video_output / vdummy.c
1 /*****************************************************************************
2  * vdummy.c: Dummy video output display method for testing purposes
3  *****************************************************************************
4  * Copyright (C) 2000-2009 VLC authors and VideoLAN
5  * $Id$
6  *
7  * Authors: Samuel Hocevar <sam@zoy.org>
8  *
9  * This program is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * 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_plugin.h>
34 #include <vlc_vout_display.h>
35
36 #define CHROMA_TEXT N_("Dummy image chroma format")
37 #define CHROMA_LONGTEXT N_( \
38     "Force the dummy video output to create images using a specific chroma " \
39     "format instead of trying to improve performances by using the most " \
40     "efficient one.")
41
42 static int OpenDummy( vlc_object_t * );
43 static int OpenStats( vlc_object_t * );
44 static void Close( vlc_object_t * );
45
46 vlc_module_begin ()
47     set_shortname( N_("Dummy") )
48     set_description( N_("Dummy video output") )
49     set_capability( "vout display", 0 )
50     set_callbacks( OpenDummy, Close )
51     add_shortcut( "dummy" )
52
53     set_category( CAT_VIDEO )
54     set_subcategory( SUBCAT_VIDEO_VOUT )
55     add_string( "dummy-chroma", NULL, CHROMA_TEXT, CHROMA_LONGTEXT, true )
56
57     add_submodule ()
58     set_description( N_("Statistics video output") )
59     set_capability( "vout display", 0 )
60     add_shortcut( "stats" )
61     set_callbacks( OpenStats, Close )
62 vlc_module_end ()
63
64
65 /*****************************************************************************
66  * Local prototypes
67  *****************************************************************************/
68 struct vout_display_sys_t {
69     picture_pool_t *pool;
70 };
71 static picture_pool_t *Pool(vout_display_t *, unsigned count);
72 static void            Display(vout_display_t *, picture_t *, subpicture_t *);
73 static void            DisplayStat(vout_display_t *, picture_t *, subpicture_t *);
74 static int             Control(vout_display_t *, int, va_list);
75
76 /*****************************************************************************
77  * OpenVideo: activates dummy vout display method
78  *****************************************************************************/
79 static int Open(vlc_object_t *object,
80                 void (*display)(vout_display_t *, picture_t *, subpicture_t *))
81 {
82     vout_display_t *vd = (vout_display_t *)object;
83     vout_display_sys_t *sys;
84
85     vd->sys = sys = calloc(1, sizeof(*sys));
86     if (!sys)
87         return VLC_EGENERIC;
88     sys->pool = NULL;
89
90     /* p_vd->info is not modified */
91
92     char *chroma = var_InheritString(vd, "dummy-chroma");
93     if (chroma) {
94         vlc_fourcc_t fcc = vlc_fourcc_GetCodecFromString(VIDEO_ES, chroma);
95         if (fcc != 0) {
96             msg_Dbg(vd, "forcing chroma 0x%.8x (%4.4s)", fcc, (char*)&fcc);
97             vd->fmt.i_chroma = fcc;
98         }
99         free(chroma);
100     }
101     vd->pool    = Pool;
102     vd->prepare = NULL;
103     vd->display = display;
104     vd->control = Control;
105     vd->manage  = NULL;
106
107     vout_display_DeleteWindow(vd, NULL);
108
109     return VLC_SUCCESS;
110 }
111
112 static int OpenDummy(vlc_object_t *object)
113 {
114     return Open(object, Display);
115 }
116
117 static int OpenStats(vlc_object_t *object)
118 {
119     return Open(object, DisplayStat);
120 }
121
122 static void Close(vlc_object_t *object)
123 {
124     vout_display_t *vd = (vout_display_t *)object;
125     vout_display_sys_t *sys = vd->sys;
126
127     if (sys->pool)
128         picture_pool_Delete(sys->pool);
129     free(sys);
130 }
131
132 static picture_pool_t *Pool(vout_display_t *vd, unsigned count)
133 {
134     vout_display_sys_t *sys = vd->sys;
135     if (!sys->pool)
136         sys->pool = picture_pool_NewFromFormat(&vd->fmt, count);
137     return sys->pool;
138 }
139
140 static void Display(vout_display_t *vd, picture_t *picture, subpicture_t *subpicture)
141 {
142     VLC_UNUSED(vd);
143     VLC_UNUSED(subpicture);
144     picture_Release(picture);
145 }
146
147 static void DisplayStat(vout_display_t *vd, picture_t *picture, subpicture_t *subpicture)
148 {
149     VLC_UNUSED(vd);
150     VLC_UNUSED(subpicture);
151     if (vd->fmt.i_width*vd->fmt.i_height >= sizeof(mtime_t)) {
152         mtime_t date;
153         memcpy(&date, picture->p->p_pixels, sizeof(date));
154         msg_Dbg(vd, "VOUT got %"PRIu64" ms offset",
155                 (mdate() - date) / 1000 );
156     }
157     picture_Release(picture);
158 }
159
160 static int Control(vout_display_t *vd, int query, va_list args)
161 {
162     VLC_UNUSED(vd);
163     VLC_UNUSED(query);
164     VLC_UNUSED(args);
165     return VLC_SUCCESS;
166 }