1 /*****************************************************************************
2 * vmem.c: memory video driver for vlc
3 *****************************************************************************
4 * Copyright (C) 2008 the VideoLAN team
7 * Authors: Sam Hocevar <sam@zoy.org>
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.
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.
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 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
34 #include <vlc_common.h>
35 #include <vlc_plugin.h>
36 #include <vlc_vout_display.h>
37 #include <vlc_picture_pool.h>
39 /*****************************************************************************
41 *****************************************************************************/
42 #define T_WIDTH N_("Width")
43 #define LT_WIDTH N_("Video memory buffer width.")
45 #define T_HEIGHT N_("Height")
46 #define LT_HEIGHT N_("Video memory buffer height.")
48 #define T_PITCH N_("Pitch")
49 #define LT_PITCH N_("Video memory buffer pitch in bytes.")
51 #define T_CHROMA N_("Chroma")
52 #define LT_CHROMA N_("Output chroma for the memory image as a 4-character " \
53 "string, eg. \"RV32\".")
55 #define T_LOCK N_("Lock function")
56 #define LT_LOCK N_("Address of the locking callback function. This " \
57 "function must fill in valid plane memory address " \
58 "information for use by the video renderer.")
60 #define T_UNLOCK N_("Unlock function")
61 #define LT_UNLOCK N_("Address of the unlocking callback function")
63 #define T_DATA N_("Callback data")
64 #define LT_DATA N_("Data for the locking and unlocking functions")
66 static int Open (vlc_object_t *);
67 static void Close(vlc_object_t *);
70 set_description(N_("Video memory output"))
71 set_shortname(N_("Video memory"))
73 set_category(CAT_VIDEO)
74 set_subcategory(SUBCAT_VIDEO_VOUT)
75 set_capability("vout display", 0)
77 add_integer("vmem-width", 320, NULL, T_WIDTH, LT_WIDTH, false)
79 add_integer("vmem-height", 200, NULL, T_HEIGHT, LT_HEIGHT, false)
81 add_integer("vmem-pitch", 640, NULL, T_PITCH, LT_PITCH, false)
83 add_string("vmem-chroma", "RV16", NULL, T_CHROMA, LT_CHROMA, true)
85 add_string("vmem-lock", "0", NULL, T_LOCK, LT_LOCK, true)
87 add_string("vmem-unlock", "0", NULL, T_UNLOCK, LT_UNLOCK, true)
89 add_string("vmem-data", "0", NULL, T_DATA, LT_DATA, true)
92 set_callbacks(Open, Close)
95 /*****************************************************************************
97 *****************************************************************************/
98 struct picture_sys_t {
99 void (*lock)(void *sys, void **plane);
100 void (*unlock)(void *sys);
104 struct vout_display_sys_t {
105 picture_pool_t *pool;
108 static picture_pool_t *Pool (vout_display_t *, unsigned);
109 static void Display(vout_display_t *, picture_t *);
110 static int Control(vout_display_t *, int, va_list);
111 static void Manage (vout_display_t *);
113 static int Lock(picture_t *);
114 static void Unlock(picture_t *);
116 /*****************************************************************************
117 * Open: allocates video thread
118 *****************************************************************************
119 * This function allocates and initializes a vout method.
120 *****************************************************************************/
121 static int Open(vlc_object_t *object)
123 vout_display_t *vd = (vout_display_t *)object;
126 char *chroma_format = var_InheritString(vd, "vmem-chroma");
127 const vlc_fourcc_t chroma = vlc_fourcc_GetCodecFromString(VIDEO_ES, chroma_format);
130 msg_Err(vd, "vmem-chroma should be 4 characters long");
138 tmp = var_CreateGetString(vd, "vmem-lock");
139 cfg.lock = (void (*)(void *, void **))(intptr_t)atoll(tmp);
142 tmp = var_CreateGetString(vd, "vmem-unlock");
143 cfg.unlock = (void (*)(void *))(intptr_t)atoll(tmp);
146 tmp = var_CreateGetString(vd, "vmem-data");
147 cfg.sys = (void *)(intptr_t)atoll(tmp);
150 /* lock and unlock are mandatory */
151 if (!cfg.lock || !cfg.unlock) {
152 msg_Err(vd, "Invalid lock or unlock callbacks");
157 video_format_t fmt = vd->fmt;
159 fmt.i_chroma = chroma;
160 fmt.i_width = var_InheritInteger(vd, "vmem-width");
161 fmt.i_height = var_InheritInteger(vd, "vmem-height");
163 /* Define the bitmasks */
166 case VLC_CODEC_RGB15:
167 fmt.i_rmask = 0x001f;
168 fmt.i_gmask = 0x03e0;
169 fmt.i_bmask = 0x7c00;
171 case VLC_CODEC_RGB16:
172 fmt.i_rmask = 0x001f;
173 fmt.i_gmask = 0x07e0;
174 fmt.i_bmask = 0xf800;
176 case VLC_CODEC_RGB24:
177 fmt.i_rmask = 0xff0000;
178 fmt.i_gmask = 0x00ff00;
179 fmt.i_bmask = 0x0000ff;
181 case VLC_CODEC_RGB32:
182 fmt.i_rmask = 0xff0000;
183 fmt.i_gmask = 0x00ff00;
184 fmt.i_bmask = 0x0000ff;
194 vout_display_sys_t *sys;
195 vd->sys = sys = calloc(1, sizeof(*sys));
200 const int pitch = var_InheritInteger(vd, "vmem-pitch");
201 picture_resource_t rsc;
202 rsc.p_sys = malloc(sizeof(*rsc.p_sys));
204 for (int i = 0; i < PICTURE_PLANE_MAX; i++) {
205 /* vmem-lock is responsible for the allocation */
206 rsc.p[i].p_pixels = NULL;
207 rsc.p[i].i_lines = fmt.i_height;
208 rsc.p[i].i_pitch = pitch;
210 picture_t *picture = picture_NewFromResource(&fmt, &rsc);
218 picture_pool_configuration_t pool;
219 memset(&pool, 0, sizeof(pool));
220 pool.picture_count = 1;
221 pool.picture = &picture;
223 pool.unlock = Unlock;
224 sys->pool = picture_pool_NewExtended(&pool);
226 picture_Release(picture);
232 vout_display_info_t info = vd->info;
233 info.has_hide_mouse = true;
240 vd->display = Display;
241 vd->control = Control;
245 vout_display_SendEventFullscreen(vd, false);
246 vout_display_SendEventDisplaySize(vd, fmt.i_width, fmt.i_height, false);
250 static void Close(vlc_object_t *object)
252 vout_display_t *vd = (vout_display_t *)object;
253 vout_display_sys_t *sys = vd->sys;
255 picture_pool_Delete(sys->pool);
260 static picture_pool_t *Pool(vout_display_t *vd, unsigned count)
263 return vd->sys->pool;
266 static void Display(vout_display_t *vd, picture_t *picture)
269 assert(!picture_IsReferenced(picture));
270 picture_Release(picture);
272 static int Control(vout_display_t *vd, int query, va_list args)
275 case VOUT_DISPLAY_CHANGE_FULLSCREEN:
276 case VOUT_DISPLAY_CHANGE_DISPLAY_SIZE: {
277 const vout_display_cfg_t *cfg = va_arg(args, const vout_display_cfg_t *);
278 if (cfg->display.width != vd->fmt.i_width ||
279 cfg->display.height != vd->fmt.i_height)
281 if (cfg->is_fullscreen)
289 static void Manage(vout_display_t *vd)
295 static int Lock(picture_t *picture)
297 picture_sys_t *sys = picture->p_sys;
299 void *planes[PICTURE_PLANE_MAX];
300 sys->lock(sys->sys, planes);
302 for (int i = 0; i < picture->i_planes; i++)
303 picture->p[i].p_pixels = planes[i];
307 static void Unlock(picture_t *picture)
309 picture_sys_t *sys = picture->p_sys;
311 sys->unlock(sys->sys);