comparison x11grab.c @ 1574:6b8f97401a34 libavformat

RFC 2 stage: First feedback from review comments - License is GPL, simplify the license header to make it clear - Add myself to license header, clarify who did what - Use 64 bit PTS - Move mouse bitmaps to the mouse cursor painting function. Make them const again - Properly detach X11 from the shared memory segment on close - Destroy X11 image on close
author gpoirier
date Tue, 12 Dec 2006 22:32:06 +0000
parents b5c9220c2dcf
children 003fede0eb67
comparison
equal deleted inserted replaced
1573:b5c9220c2dcf 1574:6b8f97401a34
1 /* 1 /*
2 * X11 video grab interface 2 * X11 video grab interface
3 * Copyright (C) 2006 Clemens Fruhwirth 3 *
4 * 4 * This file is part of FFmpeg.
5 * A quick note on licensing. This file is a mixture of LGPL code 5 *
6 * (ffmpeg) and GPL code (xvidcap). The result is a file that must 6 * FFmpeg integration:
7 * abid both licenses. As they are compatible and GPL is more 7 * Copyright (C) 2006 Clemens Fruhwirth <clemens@endorphin.org>
8 * strict, this code has an "effective" GPL license. 8 * Edouard Gomez <ed.gomez@free.fr>
9 * 9 *
10 * This file contains code from grab.c: 10 * This file contains code from grab.c:
11 * Copyright (c) 2000, 2001 Fabrice Bellard 11 * Copyright (c) 2000-2001 Fabrice Bellard
12 *
13 * This library is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU Lesser General Public
15 * License as published by the Free Software Foundation; either
16 * version 2 of the License, or (at your option) any later version.
17 *
18 * This library is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * Lesser General Public License for more details.
22 *
23 * You should have received a copy of the GNU Lesser General Public
24 * License along with this library; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 * 12 *
27 * This file contains code from the xvidcap project: 13 * This file contains code from the xvidcap project:
28 * Copyright (C) 1997-98 Rasca, Berlin 14 * Copyright (C) 1997-1998 Rasca, Berlin
29 * Copyright (C) 2003,04 Karl H. Beckers, Frankfurt 15 * 2003-2004 Karl H. Beckers, Frankfurt
30 * 16 *
31 * This program is free software; you can redistribute it and/or modify 17 * FFmpeg is free software; you can redistribute it and/or modify
32 * it under the terms of the GNU General Public License as published by 18 * it under the terms of the GNU General Public License as published by
33 * the Free Software Foundation; either version 2 of the License, or 19 * the Free Software Foundation; either version 2 of the License, or
34 * (at your option) any later version. 20 * (at your option) any later version.
35 * 21 *
36 * This program is distributed in the hope that it will be useful, 22 * FFmpeg is distributed in the hope that it will be useful,
37 * but WITHOUT ANY WARRANTY; without even the implied warranty of 23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
38 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
39 * GNU General Public License for more details. 25 * GNU General Public License for more details.
40 * 26 *
41 * You should have received a copy of the GNU General Public License 27 * You should have received a copy of the GNU Lesser General Public
42 * along with this program; if not, write to the Free Software 28 * License along with FFmpeg; if not, write to the Free Software
43 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 29 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
44 */ 30 */
45 31
46 #include "avformat.h" 32 #include "avformat.h"
47 #include <unistd.h> 33 #include <unistd.h>
48 #include <fcntl.h> 34 #include <fcntl.h>
112 98
113 st = av_new_stream(s1, 0); 99 st = av_new_stream(s1, 0);
114 if (!st) { 100 if (!st) {
115 return -ENOMEM; 101 return -ENOMEM;
116 } 102 }
117 av_set_pts_info(st, 48, 1, 1000000); /* 48 bits pts in us */ 103 av_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */
118 104
119 use_shm = XShmQueryExtension(dpy); 105 use_shm = XShmQueryExtension(dpy);
120 av_log(s1, AV_LOG_INFO, "shared memory extension %s\n", use_shm ? "found" : "not found"); 106 av_log(s1, AV_LOG_INFO, "shared memory extension %s\n", use_shm ? "found" : "not found");
121 107
122 if(use_shm) { 108 if(use_shm) {
123 int scr = XDefaultScreen(dpy); 109 int scr = XDefaultScreen(dpy);
124 image = XShmCreateImage(dpy, 110 image = XShmCreateImage(dpy,
125 DefaultVisual(dpy,scr), 111 DefaultVisual(dpy, scr),
126 DefaultDepth(dpy,scr), 112 DefaultDepth(dpy, scr),
127 ZPixmap, 113 ZPixmap,
128 NULL, 114 NULL,
129 &x11grab->shminfo, 115 &x11grab->shminfo,
130 ap->width, ap->height); 116 ap->width, ap->height);
131 x11grab->shminfo.shmid = shmget(IPC_PRIVATE, 117 x11grab->shminfo.shmid = shmget(IPC_PRIVATE,
234 return 0; 220 return 0;
235 fail: 221 fail:
236 av_free(st); 222 av_free(st);
237 return AVERROR_IO; 223 return AVERROR_IO;
238 } 224 }
239
240 static uint16_t mousePointerBlack[] =
241 {
242 0, 49152, 40960, 36864, 34816, 33792, 33280, 33024, 32896, 32832,
243 33728, 37376, 43264, 51456, 1152, 1152, 576, 576, 448, 0
244 };
245
246 static uint16_t mousePointerWhite[] =
247 {
248 0, 0, 16384, 24576, 28672, 30720, 31744, 32256, 32512, 32640, 31744,
249 27648, 17920, 1536, 768, 768, 384, 384, 0, 0
250 };
251 225
252 static void 226 static void
253 getCurrentPointer(AVFormatContext *s1, X11Grab *s, int *x, int *y) 227 getCurrentPointer(AVFormatContext *s1, X11Grab *s, int *x, int *y)
254 { 228 {
255 Window mrootwindow, childwindow; 229 Window mrootwindow, childwindow;
298 } while (0) 272 } while (0)
299 273
300 static void 274 static void
301 paintMousePointer(AVFormatContext *s1, X11Grab *s, int *x, int *y, XImage *image) 275 paintMousePointer(AVFormatContext *s1, X11Grab *s, int *x, int *y, XImage *image)
302 { 276 {
277 static const uint16_t const mousePointerBlack[] =
278 {
279 0, 49152, 40960, 36864, 34816,
280 33792, 33280, 33024, 32896, 32832,
281 33728, 37376, 43264, 51456, 1152,
282 1152, 576, 576, 448, 0
283 };
284
285 static const uint16_t const mousePointerWhite[] =
286 {
287 0, 0, 16384, 24576, 28672,
288 30720, 31744, 32256, 32512, 32640,
289 31744, 27648, 17920, 1536, 768,
290 768, 384, 384, 0, 0
291 };
292
303 int x_off = s->x_off; 293 int x_off = s->x_off;
304 int y_off = s->y_off; 294 int y_off = s->y_off;
305 int width = s->width; 295 int width = s->width;
306 int height = s->height; 296 int height = s->height;
307 297