demux: avi: invalidate skipped chunks
[vlc.git] / modules / video_output / vmem.c
blobd0ff7160c195f0bee5d95b972d5fdb915d46f60b
1 /*****************************************************************************
2 * vmem.c: memory video driver for vlc
3 *****************************************************************************
4 * Copyright (C) 2008 VLC authors and VideoLAN
5 * Copyright (C) 2010 RĂ©mi Denis-Courmont
7 * Authors: Sam Hocevar <sam@zoy.org>
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.
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.
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 *****************************************************************************/
24 /*****************************************************************************
25 * Preamble
26 *****************************************************************************/
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
32 #include <assert.h>
34 #include <vlc_common.h>
35 #include <vlc_plugin.h>
36 #include <vlc_vout_display.h>
37 #include <vlc_picture_pool.h>
39 /*****************************************************************************
40 * Module descriptor
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 static int Open (vlc_object_t *);
56 static void Close(vlc_object_t *);
58 vlc_module_begin()
59 set_description(N_("Video memory output"))
60 set_shortname(N_("Video memory"))
62 set_category(CAT_VIDEO)
63 set_subcategory(SUBCAT_VIDEO_VOUT)
64 set_capability("vout display", 0)
66 add_integer("vmem-width", 320, T_WIDTH, LT_WIDTH, false)
67 change_private()
68 add_integer("vmem-height", 200, T_HEIGHT, LT_HEIGHT, false)
69 change_private()
70 add_integer("vmem-pitch", 640, T_PITCH, LT_PITCH, false)
71 change_private()
72 add_string("vmem-chroma", "RV16", T_CHROMA, LT_CHROMA, true)
73 change_private()
74 add_obsolete_string("vmem-lock") /* obsoleted since 1.1.1 */
75 add_obsolete_string("vmem-unlock") /* obsoleted since 1.1.1 */
76 add_obsolete_string("vmem-data") /* obsoleted since 1.1.1 */
78 set_callbacks(Open, Close)
79 vlc_module_end()
81 /*****************************************************************************
82 * Local prototypes
83 *****************************************************************************/
84 struct picture_sys_t {
85 void *id;
88 /* NOTE: the callback prototypes must match those of LibVLC */
89 struct vout_display_sys_t {
90 picture_pool_t *pool;
92 void *opaque;
93 void *pic_opaque;
94 void *(*lock)(void *sys, void **plane);
95 void (*unlock)(void *sys, void *id, void *const *plane);
96 void (*display)(void *sys, void *id);
97 void (*cleanup)(void *sys);
99 unsigned pitches[PICTURE_PLANE_MAX];
100 unsigned lines[PICTURE_PLANE_MAX];
103 typedef unsigned (*vlc_format_cb)(void **, char *, unsigned *, unsigned *,
104 unsigned *, unsigned *);
106 static picture_pool_t *Pool (vout_display_t *, unsigned);
107 static void Prepare(vout_display_t *, picture_t *, subpicture_t *);
108 static void Display(vout_display_t *, picture_t *, subpicture_t *);
109 static int Control(vout_display_t *, int, va_list);
111 /*****************************************************************************
112 * Open: allocates video thread
113 *****************************************************************************
114 * This function allocates and initializes a vout method.
115 *****************************************************************************/
116 static int Open(vlc_object_t *object)
118 vout_display_t *vd = (vout_display_t *)object;
119 vout_display_sys_t *sys = malloc(sizeof(*sys));
120 if (unlikely(!sys))
121 return VLC_ENOMEM;
123 /* Get the callbacks */
124 vlc_format_cb setup = var_InheritAddress(vd, "vmem-setup");
126 sys->lock = var_InheritAddress(vd, "vmem-lock");
127 if (sys->lock == NULL) {
128 msg_Err(vd, "missing lock callback");
129 free(sys);
130 return VLC_EGENERIC;
132 sys->unlock = var_InheritAddress(vd, "vmem-unlock");
133 sys->display = var_InheritAddress(vd, "vmem-display");
134 sys->cleanup = var_InheritAddress(vd, "vmem-cleanup");
135 sys->opaque = var_InheritAddress(vd, "vmem-data");
136 sys->pool = NULL;
138 /* Define the video format */
139 video_format_t fmt;
140 video_format_ApplyRotation(&fmt, &vd->fmt);
142 if (setup != NULL) {
143 char chroma[5];
145 memcpy(chroma, &fmt.i_chroma, 4);
146 chroma[4] = '\0';
147 memset(sys->pitches, 0, sizeof(sys->pitches));
148 memset(sys->lines, 0, sizeof(sys->lines));
150 if (setup(&sys->opaque, chroma, &fmt.i_width, &fmt.i_height,
151 sys->pitches, sys->lines) == 0) {
152 msg_Err(vd, "video format setup failure (no pictures)");
153 free(sys);
154 return VLC_EGENERIC;
156 fmt.i_chroma = vlc_fourcc_GetCodecFromString(VIDEO_ES, chroma);
158 } else {
159 char *chroma = var_InheritString(vd, "vmem-chroma");
160 fmt.i_chroma = vlc_fourcc_GetCodecFromString(VIDEO_ES, chroma);
161 free(chroma);
163 fmt.i_width = var_InheritInteger(vd, "vmem-width");
164 fmt.i_height = var_InheritInteger(vd, "vmem-height");
165 sys->pitches[0] = var_InheritInteger(vd, "vmem-pitch");
166 sys->lines[0] = fmt.i_height;
167 for (size_t i = 1; i < PICTURE_PLANE_MAX; i++)
169 sys->pitches[i] = sys->pitches[0];
170 sys->lines[i] = sys->lines[0];
172 sys->cleanup = NULL;
174 fmt.i_x_offset = fmt.i_y_offset = 0;
175 fmt.i_visible_width = fmt.i_width;
176 fmt.i_visible_height = fmt.i_height;
178 if (!fmt.i_chroma) {
179 msg_Err(vd, "vmem-chroma should be 4 characters long");
180 free(sys);
181 return VLC_EGENERIC;
184 /* Define the bitmasks */
185 switch (fmt.i_chroma)
187 case VLC_CODEC_RGB15:
188 fmt.i_rmask = 0x001f;
189 fmt.i_gmask = 0x03e0;
190 fmt.i_bmask = 0x7c00;
191 break;
192 case VLC_CODEC_RGB16:
193 fmt.i_rmask = 0x001f;
194 fmt.i_gmask = 0x07e0;
195 fmt.i_bmask = 0xf800;
196 break;
197 case VLC_CODEC_RGB24:
198 case VLC_CODEC_RGB32:
199 fmt.i_rmask = 0xff0000;
200 fmt.i_gmask = 0x00ff00;
201 fmt.i_bmask = 0x0000ff;
202 break;
203 default:
204 fmt.i_rmask = 0;
205 fmt.i_gmask = 0;
206 fmt.i_bmask = 0;
207 break;
210 /* */
211 vout_display_info_t info = vd->info;
212 info.has_hide_mouse = true;
214 /* */
215 vd->sys = sys;
216 vd->fmt = fmt;
217 vd->info = info;
218 vd->pool = Pool;
219 vd->prepare = Prepare;
220 vd->display = Display;
221 vd->control = Control;
222 vd->manage = NULL;
224 /* */
225 vout_display_SendEventDisplaySize(vd, fmt.i_width, fmt.i_height);
226 vout_display_DeleteWindow(vd, NULL);
227 return VLC_SUCCESS;
230 static void Close(vlc_object_t *object)
232 vout_display_t *vd = (vout_display_t *)object;
233 vout_display_sys_t *sys = vd->sys;
235 if (sys->cleanup)
236 sys->cleanup(sys->opaque);
237 if (sys->pool)
238 picture_pool_Release(sys->pool);
239 free(sys);
242 static picture_pool_t *Pool(vout_display_t *vd, unsigned count)
244 vout_display_sys_t *sys = vd->sys;
246 if (sys->pool == NULL)
247 sys->pool = picture_pool_NewFromFormat(&vd->fmt, count);
248 return sys->pool;
251 static void Prepare(vout_display_t *vd, picture_t *pic, subpicture_t *subpic)
253 vout_display_sys_t *sys = vd->sys;
254 picture_resource_t rsc = { .p_sys = NULL };
255 void *planes[PICTURE_PLANE_MAX];
257 sys->pic_opaque = sys->lock(sys->opaque, planes);
259 for (unsigned i = 0; i < PICTURE_PLANE_MAX; i++) {
260 rsc.p[i].p_pixels = planes[i];
261 rsc.p[i].i_lines = sys->lines[i];
262 rsc.p[i].i_pitch = sys->pitches[i];
265 picture_t *locked = picture_NewFromResource(&vd->fmt, &rsc);
266 if (likely(locked != NULL)) {
267 picture_CopyPixels(locked, pic);
268 picture_Release(locked);
271 if (sys->unlock != NULL)
272 sys->unlock(sys->opaque, sys->pic_opaque, planes);
274 (void) subpic;
277 static void Display(vout_display_t *vd, picture_t *pic, subpicture_t *subpic)
279 vout_display_sys_t *sys = vd->sys;
281 if (sys->display != NULL)
282 sys->display(sys->opaque, sys->pic_opaque);
284 picture_Release(pic);
285 VLC_UNUSED(subpic);
288 static int Control(vout_display_t *vd, int query, va_list args)
290 (void) vd; (void) query; (void) args;
291 return VLC_EGENERIC;