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)
78 add_integer("vmem-height", 200, NULL, T_HEIGHT, LT_HEIGHT, false)
79 add_integer("vmem-pitch", 640, NULL, T_PITCH, LT_PITCH, false)
80 add_string("vmem-chroma", "RV16", NULL, T_CHROMA, LT_CHROMA, true)
81 add_string("vmem-lock", "0", NULL, T_LOCK, LT_LOCK, true)
82 add_string("vmem-unlock", "0", NULL, T_UNLOCK, LT_UNLOCK, true)
83 add_string("vmem-data", "0", NULL, T_DATA, LT_DATA, true)
85 set_callbacks(Open, Close)
88 /*****************************************************************************
90 *****************************************************************************/
91 struct picture_sys_t {
92 void (*lock)(void *sys, void **plane);
93 void (*unlock)(void *sys);
97 struct vout_display_sys_t {
101 static picture_pool_t *Pool (vout_display_t *, unsigned);
102 static void Display(vout_display_t *, picture_t *);
103 static int Control(vout_display_t *, int, va_list);
104 static void Manage (vout_display_t *);
106 static int Lock(picture_t *);
107 static void Unlock(picture_t *);
109 /*****************************************************************************
110 * Open: allocates video thread
111 *****************************************************************************
112 * This function allocates and initializes a vout method.
113 *****************************************************************************/
114 static int Open(vlc_object_t *object)
116 vout_display_t *vd = (vout_display_t *)object;
119 char *chroma_format = var_CreateGetString(vd, "vmem-chroma");
120 const vlc_fourcc_t chroma = vlc_fourcc_GetCodecFromString(VIDEO_ES, chroma_format);
123 msg_Err(vd, "vmem-chroma should be 4 characters long");
131 tmp = var_CreateGetString(vd, "vmem-lock");
132 cfg.lock = (void (*)(void *, void **))(intptr_t)atoll(tmp);
135 tmp = var_CreateGetString(vd, "vmem-unlock");
136 cfg.unlock = (void (*)(void *))(intptr_t)atoll(tmp);
139 tmp = var_CreateGetString(vd, "vmem-data");
140 cfg.sys = (void *)(intptr_t)atoll(tmp);
143 /* lock and unlock are mandatory */
144 if (!cfg.lock || !cfg.unlock) {
145 msg_Err(vd, "Invalid lock or unlock callbacks");
150 video_format_t fmt = vd->fmt;
152 fmt.i_chroma = chroma;
153 fmt.i_width = var_CreateGetInteger(vd, "vmem-width");
154 fmt.i_height = var_CreateGetInteger(vd, "vmem-height");
156 /* Define the bitmasks */
159 case VLC_CODEC_RGB15:
160 fmt.i_rmask = 0x001f;
161 fmt.i_gmask = 0x03e0;
162 fmt.i_bmask = 0x7c00;
164 case VLC_CODEC_RGB16:
165 fmt.i_rmask = 0x001f;
166 fmt.i_gmask = 0x07e0;
167 fmt.i_bmask = 0xf800;
169 case VLC_CODEC_RGB24:
170 fmt.i_rmask = 0xff0000;
171 fmt.i_gmask = 0x00ff00;
172 fmt.i_bmask = 0x0000ff;
174 case VLC_CODEC_RGB32:
175 fmt.i_rmask = 0xff0000;
176 fmt.i_gmask = 0x00ff00;
177 fmt.i_bmask = 0x0000ff;
187 vout_display_sys_t *sys;
188 vd->sys = sys = calloc(1, sizeof(*sys));
193 const int pitch = var_CreateGetInteger(vd, "vmem-pitch");
194 picture_resource_t rsc;
195 rsc.p_sys = malloc(sizeof(*rsc.p_sys));
197 for (int i = 0; i < PICTURE_PLANE_MAX; i++) {
198 /* vmem-lock is responsible for the allocation */
199 rsc.p[i].p_pixels = NULL;
200 rsc.p[i].i_lines = fmt.i_height;
201 rsc.p[i].i_pitch = pitch;
203 picture_t *picture = picture_NewFromResource(&fmt, &rsc);
211 picture_pool_configuration_t pool;
212 memset(&pool, 0, sizeof(pool));
213 pool.picture_count = 1;
214 pool.picture = &picture;
216 pool.unlock = Unlock;
217 sys->pool = picture_pool_NewExtended(&pool);
219 picture_Release(picture);
225 vout_display_info_t info = vd->info;
226 info.has_hide_mouse = true;
233 vd->display = Display;
234 vd->control = Control;
238 vout_display_SendEventFullscreen(vd, false);
239 vout_display_SendEventDisplaySize(vd, fmt.i_width, fmt.i_height, false);
243 static void Close(vlc_object_t *object)
245 vout_display_t *vd = (vout_display_t *)object;
246 vout_display_sys_t *sys = vd->sys;
248 picture_pool_Delete(sys->pool);
253 static picture_pool_t *Pool(vout_display_t *vd, unsigned count)
256 return vd->sys->pool;
259 static void Display(vout_display_t *vd, picture_t *picture)
262 assert(!picture_IsReferenced(picture));
263 picture_Release(picture);
265 static int Control(vout_display_t *vd, int query, va_list args)
268 case VOUT_DISPLAY_CHANGE_FULLSCREEN:
269 case VOUT_DISPLAY_CHANGE_DISPLAY_SIZE: {
270 const vout_display_cfg_t *cfg = va_arg(args, const vout_display_cfg_t *);
271 if (cfg->display.width != vd->fmt.i_width ||
272 cfg->display.height != vd->fmt.i_height)
274 if (cfg->is_fullscreen)
282 static void Manage(vout_display_t *vd)
288 static int Lock(picture_t *picture)
290 picture_sys_t *sys = picture->p_sys;
292 void *planes[PICTURE_PLANE_MAX];
293 sys->lock(sys->sys, planes);
295 for (int i = 0; i < picture->i_planes; i++)
296 picture->p[i].p_pixels = planes[i];
300 static void Unlock(picture_t *picture)
302 picture_sys_t *sys = picture->p_sys;
304 sys->unlock(sys->sys);