annotate x11grab.c @ 1585:14c185883eab libavformat

RFC 5: Mouse cursor painting reduc and more cleanups - License is for FFmpeg, not "this program" - Rewrite mouse cursor painting functions - Cosmetic on 2 function declarations (patch by Edouard Gomez)
author gpoirier
date Wed, 13 Dec 2006 08:49:34 +0000
parents 33997fca4b0d
children 56d6828ab647
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1580
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
1 /*
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
2 * X11 video grab interface
1581
90a8061c5f83 Adapt the patch to more recent FFmpeg habits
gpoirier
parents: 1580
diff changeset
3 *
1583
8c0065795c92 RFC 2 stage: First feedback from review comments
gpoirier
parents: 1582
diff changeset
4 * This file is part of FFmpeg.
1580
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
5 *
1583
8c0065795c92 RFC 2 stage: First feedback from review comments
gpoirier
parents: 1582
diff changeset
6 * FFmpeg integration:
8c0065795c92 RFC 2 stage: First feedback from review comments
gpoirier
parents: 1582
diff changeset
7 * Copyright (C) 2006 Clemens Fruhwirth <clemens@endorphin.org>
8c0065795c92 RFC 2 stage: First feedback from review comments
gpoirier
parents: 1582
diff changeset
8 * Edouard Gomez <ed.gomez@free.fr>
1580
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
9 *
1583
8c0065795c92 RFC 2 stage: First feedback from review comments
gpoirier
parents: 1582
diff changeset
10 * This file contains code from grab.c:
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
11 * Copyright (c) 2000-2001 Fabrice Bellard
1580
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
12 *
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
13 * This file contains code from the xvidcap project:
1583
8c0065795c92 RFC 2 stage: First feedback from review comments
gpoirier
parents: 1582
diff changeset
14 * Copyright (C) 1997-1998 Rasca, Berlin
8c0065795c92 RFC 2 stage: First feedback from review comments
gpoirier
parents: 1582
diff changeset
15 * 2003-2004 Karl H. Beckers, Frankfurt
1580
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
16 *
1583
8c0065795c92 RFC 2 stage: First feedback from review comments
gpoirier
parents: 1582
diff changeset
17 * FFmpeg is free software; you can redistribute it and/or modify
1580
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
18 * it under the terms of the GNU General Public License as published by
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
19 * the Free Software Foundation; either version 2 of the License, or
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
20 * (at your option) any later version.
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
21 *
1583
8c0065795c92 RFC 2 stage: First feedback from review comments
gpoirier
parents: 1582
diff changeset
22 * FFmpeg is distributed in the hope that it will be useful,
1580
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
25 * GNU General Public License for more details.
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
26 *
1585
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
27 * You should have received a copy of the GNU General Public License along
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
28 * with this program; if not, write to the Free Software Foundation, Inc.,
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
29 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1580
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
30 */
1581
90a8061c5f83 Adapt the patch to more recent FFmpeg habits
gpoirier
parents: 1580
diff changeset
31
1580
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
32 #include "avformat.h"
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
33 #include <unistd.h>
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
34 #include <fcntl.h>
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
35 #include <sys/ioctl.h>
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
36 #include <sys/mman.h>
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
37 #include <sys/time.h>
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
38 #define _LINUX_TIME_H 1
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
39 #include <time.h>
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
40 #include <X11/X.h>
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
41 #include <X11/Xlib.h>
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
42 #include <X11/Xlibint.h>
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
43 #include <X11/Xproto.h>
1583
8c0065795c92 RFC 2 stage: First feedback from review comments
gpoirier
parents: 1582
diff changeset
44 #include <X11/Xutil.h>
1580
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
45 #include <sys/ipc.h>
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
46 #include <sys/shm.h>
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
47 #include <X11/extensions/XShm.h>
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
48
1581
90a8061c5f83 Adapt the patch to more recent FFmpeg habits
gpoirier
parents: 1580
diff changeset
49 typedef struct
90a8061c5f83 Adapt the patch to more recent FFmpeg habits
gpoirier
parents: 1580
diff changeset
50 {
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
51 Display *dpy;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
52 int frame_format;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
53 int frame_size;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
54 int frame_rate;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
55 int frame_rate_base;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
56 int64_t time_frame;
1580
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
57
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
58 int height;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
59 int width;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
60 int x_off;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
61 int y_off;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
62 XImage *image;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
63 int use_shm;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
64 XShmSegmentInfo shminfo;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
65 int mouse_wanted;
1580
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
66 } X11Grab;
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
67
1581
90a8061c5f83 Adapt the patch to more recent FFmpeg habits
gpoirier
parents: 1580
diff changeset
68 static int
90a8061c5f83 Adapt the patch to more recent FFmpeg habits
gpoirier
parents: 1580
diff changeset
69 x11grab_read_header(AVFormatContext *s1, AVFormatParameters *ap)
1580
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
70 {
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
71 X11Grab *x11grab = s1->priv_data;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
72 Display *dpy;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
73 AVStream *st = NULL;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
74 int width, height;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
75 int frame_rate, frame_rate_base, frame_size;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
76 int input_pixfmt;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
77 XImage *image;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
78 int x_off=0; int y_off = 0;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
79 int use_shm;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
80
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
81 dpy = XOpenDisplay(NULL);
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
82 if(!dpy) {
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
83 goto fail;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
84 }
1580
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
85
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
86 sscanf(ap->device, "x11:%d,%d", &x_off, &y_off);
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
87 av_log(s1, AV_LOG_INFO, "device: %s -> x: %d y: %d width: %d height: %d\n", ap->device, x_off, y_off, ap->width, ap->height);
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
88
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
89 if (!ap || ap->width <= 0 || ap->height <= 0 || ap->time_base.den <= 0) {
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
90 av_log(s1, AV_LOG_ERROR, "AVParameters don't have any video size. Use -s.\n");
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
91 return AVERROR_IO;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
92 }
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
93
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
94 width = ap->width;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
95 height = ap->height;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
96 frame_rate = ap->time_base.den;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
97 frame_rate_base = ap->time_base.num;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
98
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
99 st = av_new_stream(s1, 0);
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
100 if (!st) {
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
101 return -ENOMEM;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
102 }
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
103 av_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */
1580
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
104
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
105 use_shm = XShmQueryExtension(dpy);
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
106 av_log(s1, AV_LOG_INFO, "shared memory extension %s\n", use_shm ? "found" : "not found");
1581
90a8061c5f83 Adapt the patch to more recent FFmpeg habits
gpoirier
parents: 1580
diff changeset
107
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
108 if(use_shm) {
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
109 int scr = XDefaultScreen(dpy);
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
110 image = XShmCreateImage(dpy,
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
111 DefaultVisual(dpy, scr),
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
112 DefaultDepth(dpy, scr),
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
113 ZPixmap,
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
114 NULL,
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
115 &x11grab->shminfo,
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
116 ap->width, ap->height);
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
117 x11grab->shminfo.shmid = shmget(IPC_PRIVATE,
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
118 image->bytes_per_line * image->height,
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
119 IPC_CREAT|0777);
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
120 if (x11grab->shminfo.shmid == -1) {
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
121 av_log(s1, AV_LOG_ERROR, "Fatal: Can't get shared memory!\n");
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
122 return -ENOMEM;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
123 }
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
124 x11grab->shminfo.shmaddr = image->data = shmat(x11grab->shminfo.shmid, 0, 0);
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
125 x11grab->shminfo.readOnly = False;
1580
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
126
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
127 if (!XShmAttach(dpy, &x11grab->shminfo)) {
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
128 av_log(s1, AV_LOG_ERROR, "Fatal: Failed to attach shared memory!\n");
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
129 /* needs some better error subroutine :) */
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
130 return AVERROR_IO;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
131 }
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
132 } else {
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
133 image = XGetImage(dpy, RootWindow(dpy, DefaultScreen(dpy)),
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
134 x_off,y_off,
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
135 ap->width,ap->height,
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
136 AllPlanes, ZPixmap);
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
137 }
1580
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
138
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
139 switch (image->bits_per_pixel) {
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
140 case 8:
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
141 av_log (s1, AV_LOG_DEBUG, "8 bit pallete\n");
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
142 input_pixfmt = PIX_FMT_PAL8;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
143 break;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
144 case 16:
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
145 if ( image->red_mask == 0xF800 && image->green_mask == 0x07E0
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
146 && image->blue_mask == 0x1F ) {
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
147 av_log (s1, AV_LOG_DEBUG, "16 bit RGB565\n");
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
148 input_pixfmt = PIX_FMT_RGB565;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
149 } else if ( image->red_mask == 0x7C00 &&
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
150 image->green_mask == 0x03E0 &&
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
151 image->blue_mask == 0x1F ) {
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
152 av_log(s1, AV_LOG_DEBUG, "16 bit RGB555\n");
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
153 input_pixfmt = PIX_FMT_RGB555;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
154 } else {
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
155 av_log(s1, AV_LOG_ERROR, "RGB ordering at image depth %i not supported ... aborting\n", image->bits_per_pixel);
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
156 av_log(s1, AV_LOG_ERROR, "color masks: r 0x%.6lx g 0x%.6lx b 0x%.6lx\n", image->red_mask, image->green_mask, image->blue_mask);
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
157 return AVERROR_IO;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
158 }
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
159 break;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
160 case 24:
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
161 if ( image->red_mask == 0xFF0000 &&
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
162 image->green_mask == 0xFF00
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
163 && image->blue_mask == 0xFF ) {
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
164 input_pixfmt = PIX_FMT_BGR24;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
165 } else if ( image->red_mask == 0xFF && image->green_mask == 0xFF00
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
166 && image->blue_mask == 0xFF0000 ) {
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
167 input_pixfmt = PIX_FMT_RGB24;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
168 } else {
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
169 av_log(s1, AV_LOG_ERROR,"rgb ordering at image depth %i not supported ... aborting\n", image->bits_per_pixel);
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
170 av_log(s1, AV_LOG_ERROR, "color masks: r 0x%.6lx g 0x%.6lx b 0x%.6lx\n", image->red_mask, image->green_mask, image->blue_mask);
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
171 return AVERROR_IO;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
172 }
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
173 break;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
174 case 32:
1580
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
175 #if 0
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
176 GetColorInfo (image, &c_info);
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
177 if ( c_info.alpha_mask == 0xFF000000 && image->green_mask == 0xFF00 ) {
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
178 /* byte order is relevant here, not endianness
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
179 * endianness is handled by avcodec, but atm no such thing
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
180 * as having ABGR, instead of ARGB in a word. Since we
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
181 * need this for Solaris/SPARC, but need to do the conversion
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
182 * for every frame we do it outside of this loop, cf. below
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
183 * this matches both ARGB32 and ABGR32 */
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
184 input_pixfmt = PIX_FMT_ARGB32;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
185 } else {
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
186 av_log(s1, AV_LOG_ERROR,"image depth %i not supported ... aborting\n", image->bits_per_pixel);
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
187 return AVERROR_IO;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
188 }
1580
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
189 #endif
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
190 input_pixfmt = PIX_FMT_RGBA32;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
191 break;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
192 default:
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
193 av_log(s1, AV_LOG_ERROR, "image depth %i not supported ... aborting\n", image->bits_per_pixel);
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
194 return -1;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
195 }
1580
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
196
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
197 frame_size = width * height * image->bits_per_pixel/8;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
198 x11grab->frame_size = frame_size;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
199 x11grab->dpy = dpy;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
200 x11grab->width = ap->width;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
201 x11grab->height = ap->height;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
202 x11grab->frame_rate = frame_rate;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
203 x11grab->frame_rate_base = frame_rate_base;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
204 x11grab->time_frame = av_gettime() * frame_rate / frame_rate_base;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
205 x11grab->x_off = x_off;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
206 x11grab->y_off = y_off;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
207 x11grab->image = image;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
208 x11grab->use_shm = use_shm;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
209 x11grab->mouse_wanted = 1;
1580
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
210
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
211 st->codec->codec_type = CODEC_TYPE_VIDEO;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
212 st->codec->codec_id = CODEC_ID_RAWVIDEO;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
213 st->codec->width = width;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
214 st->codec->height = height;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
215 st->codec->pix_fmt = input_pixfmt;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
216 st->codec->time_base.den = frame_rate;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
217 st->codec->time_base.num = frame_rate_base;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
218 st->codec->bit_rate = frame_size * 1/av_q2d(st->codec->time_base) * 8;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
219
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
220 return 0;
1581
90a8061c5f83 Adapt the patch to more recent FFmpeg habits
gpoirier
parents: 1580
diff changeset
221 fail:
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
222 av_free(st);
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
223 return AVERROR_IO;
1580
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
224 }
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
225
1581
90a8061c5f83 Adapt the patch to more recent FFmpeg habits
gpoirier
parents: 1580
diff changeset
226 static void
90a8061c5f83 Adapt the patch to more recent FFmpeg habits
gpoirier
parents: 1580
diff changeset
227 getCurrentPointer(AVFormatContext *s1, X11Grab *s, int *x, int *y)
90a8061c5f83 Adapt the patch to more recent FFmpeg habits
gpoirier
parents: 1580
diff changeset
228 {
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
229 Window mrootwindow, childwindow;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
230 int dummy;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
231 Display *dpy = s->dpy;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
232
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
233 mrootwindow = DefaultRootWindow(dpy);
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
234
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
235 if (XQueryPointer(dpy, mrootwindow, &mrootwindow, &childwindow,
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
236 x, y, &dummy, &dummy, (unsigned int*)&dummy)) {
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
237 } else {
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
238 av_log(s1, AV_LOG_INFO, "couldn't find mouse pointer\n");
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
239 *x = -1;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
240 *y = -1;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
241 }
1580
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
242 }
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
243
1585
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
244 static void inline
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
245 apply_masks(uint8_t *dst, int and, int or, int bits_per_pixel)
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
246 {
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
247 switch (bits_per_pixel) {
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
248 case 32:
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
249 *(uint32_t*)dst = (*(uint32_t*)dst & and) | or;
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
250 break;
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
251 case 16:
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
252 *(uint16_t*)dst = (*(uint16_t*)dst & and) | or;
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
253 break;
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
254 case 8:
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
255 *dst = (or) ? 1 : 0;
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
256 break;
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
257 }
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
258 }
1582
754781df8033 RFC 1 stage: Improve maintainability of the cursoir painting code
gpoirier
parents: 1581
diff changeset
259
1581
90a8061c5f83 Adapt the patch to more recent FFmpeg habits
gpoirier
parents: 1580
diff changeset
260 static void
90a8061c5f83 Adapt the patch to more recent FFmpeg habits
gpoirier
parents: 1580
diff changeset
261 paintMousePointer(AVFormatContext *s1, X11Grab *s, int *x, int *y, XImage *image)
90a8061c5f83 Adapt the patch to more recent FFmpeg habits
gpoirier
parents: 1580
diff changeset
262 {
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
263 static const uint16_t const mousePointerBlack[] =
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
264 {
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
265 0, 49152, 40960, 36864, 34816,
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
266 33792, 33280, 33024, 32896, 32832,
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
267 33728, 37376, 43264, 51456, 1152,
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
268 1152, 576, 576, 448, 0
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
269 };
1583
8c0065795c92 RFC 2 stage: First feedback from review comments
gpoirier
parents: 1582
diff changeset
270
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
271 static const uint16_t const mousePointerWhite[] =
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
272 {
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
273 0, 0, 16384, 24576, 28672,
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
274 30720, 31744, 32256, 32512, 32640,
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
275 31744, 27648, 17920, 1536, 768,
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
276 768, 384, 384, 0, 0
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
277 };
1583
8c0065795c92 RFC 2 stage: First feedback from review comments
gpoirier
parents: 1582
diff changeset
278
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
279 int x_off = s->x_off;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
280 int y_off = s->y_off;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
281 int width = s->width;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
282 int height = s->height;
1580
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
283
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
284 if ( (*x - x_off) >= 0 && *x < (width + x_off)
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
285 && (*y - y_off) >= 0 && *y < (height + y_off) ) {
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
286 int line;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
287 uint8_t *im_data = (uint8_t*)image->data;
1585
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
288 const uint16_t *black;
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
289 const uint16_t *white;
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
290 int masks;
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
291 int onepixel;
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
292
1585
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
293 /* Select correct pointer pixels */
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
294 if (s->mouse_wanted == 1) {
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
295 /* Normal pointer */
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
296 black = mousePointerBlack;
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
297 white = mousePointerWhite;
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
298 } else {
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
299 /* Inverted pointer */
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
300 black = mousePointerWhite;
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
301 white = mousePointerBlack;
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
302 }
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
303
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
304 /* Select correct masks and pixel size */
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
305 switch (image->bits_per_pixel) {
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
306 case 32:
1585
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
307 masks = (image->red_mask|image->green_mask|image->blue_mask);
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
308 onepixel = 4;
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
309 break;
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
310 case 24:
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
311 /* XXX: Though the code seems to support 24bit images, the
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
312 * apply_masks lacks support for 24bit */
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
313 masks = (image->red_mask|image->green_mask|image->blue_mask);
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
314 onepixel = 3;
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
315 break;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
316 case 16:
1585
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
317 masks = (image->red_mask|image->green_mask|image->blue_mask);
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
318 onepixel = 2;
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
319 break;
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
320 case 8:
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
321 masks = 1;
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
322 onepixel = 1;
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
323 break;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
324 default:
1585
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
325 /* Shut up gcc */
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
326 masks = 0;
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
327 onepixel = 0;
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
328 }
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
329
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
330 /* Shift to right line */
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
331 im_data += (image->bytes_per_line * (*y - y_off));
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
332 /* Shift to right pixel */
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
333 im_data += (image->bits_per_pixel / 8 * (*x - x_off));
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
334
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
335 /* Draw the cursor - proper loop */
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
336 for (line = 0; line < min(20, (y_off + height) - *y); line++) {
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
337 uint8_t *cursor = im_data;
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
338 int width_cursor;
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
339 uint16_t bm_b;
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
340 uint16_t bm_w;
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
341
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
342 bm_b = black[line];
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
343 bm_w = white[line];
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
344
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
345 for (width_cursor=0;
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
346 width_cursor < 16 && (width_cursor + *x) < (width + x_off);
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
347 width_cursor++) {
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
348 apply_masks(cursor,
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
349 ~(masks*(bm_b&1)), masks*(bm_w&1),
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
350 image->bits_per_pixel);
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
351 cursor += onepixel;
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
352 bm_b >>= 1;
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
353 bm_w >>= 1;
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
354 }
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
355 im_data += image->bytes_per_line;
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
356 }
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
357 }
1580
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
358 }
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
359
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
360
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
361 /*
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
362 * just read new data in the image structure, the image
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
363 * structure inclusive the data area must be allocated before
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
364 */
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
365 static int
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
366 XGetZPixmap(Display *dpy, Drawable d, XImage *image, int x, int y)
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
367 {
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
368 xGetImageReply rep;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
369 xGetImageReq *req;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
370 long nbytes;
1581
90a8061c5f83 Adapt the patch to more recent FFmpeg habits
gpoirier
parents: 1580
diff changeset
371
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
372 if (!image) {
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
373 return False;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
374 }
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
375
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
376 LockDisplay(dpy);
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
377 GetReq(GetImage, req);
1581
90a8061c5f83 Adapt the patch to more recent FFmpeg habits
gpoirier
parents: 1580
diff changeset
378
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
379 /* First set up the standard stuff in the request */
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
380 req->drawable = d;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
381 req->x = x;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
382 req->y = y;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
383 req->width = image->width;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
384 req->height = image->height;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
385 req->planeMask = (unsigned int)AllPlanes;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
386 req->format = ZPixmap;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
387
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
388 if (!_XReply(dpy, (xReply *) &rep, 0, xFalse) || !rep.length) {
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
389 UnlockDisplay(dpy);
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
390 SyncHandle();
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
391 return False;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
392 }
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
393
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
394 nbytes = (long)rep.length << 2;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
395 _XReadPad(dpy, image->data, nbytes);
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
396
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
397 UnlockDisplay(dpy);
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
398 SyncHandle();
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
399 return True;
1580
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
400 }
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
401
1585
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
402 static int
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
403 x11grab_read_packet(AVFormatContext *s1, AVPacket *pkt)
1580
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
404 {
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
405 X11Grab *s = s1->priv_data;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
406 Display *dpy = s->dpy;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
407 XImage *image = s->image;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
408 int x_off = s->x_off;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
409 int y_off = s->y_off;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
410
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
411 int64_t curtime, delay;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
412 struct timespec ts;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
413
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
414 /* Calculate the time of the next frame */
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
415 s->time_frame += int64_t_C(1000000);
1580
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
416
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
417 /* wait based on the frame rate */
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
418 for(;;) {
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
419 curtime = av_gettime();
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
420 delay = s->time_frame * s->frame_rate_base / s->frame_rate - curtime;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
421 if (delay <= 0) {
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
422 if (delay < int64_t_C(-1000000) * s->frame_rate_base / s->frame_rate) {
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
423 s->time_frame += int64_t_C(1000000);
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
424 }
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
425 break;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
426 }
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
427 ts.tv_sec = delay / 1000000;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
428 ts.tv_nsec = (delay % 1000000) * 1000;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
429 nanosleep(&ts, NULL);
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
430 }
1581
90a8061c5f83 Adapt the patch to more recent FFmpeg habits
gpoirier
parents: 1580
diff changeset
431
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
432 if (av_new_packet(pkt, s->frame_size) < 0) {
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
433 return AVERROR_IO;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
434 }
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
435
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
436 pkt->pts = curtime & ((1LL << 48) - 1);
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
437
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
438 if(s->use_shm) {
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
439 if (!XShmGetImage(dpy, RootWindow(dpy, DefaultScreen(dpy)), image, x_off, y_off, AllPlanes)) {
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
440 av_log (s1, AV_LOG_INFO, "XShmGetImage() failed\n");
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
441 }
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
442 } else {
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
443 if (!XGetZPixmap(dpy, RootWindow(dpy, DefaultScreen(dpy)), image, x_off, y_off)) {
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
444 av_log (s1, AV_LOG_INFO, "XGetZPixmap() failed\n");
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
445 }
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
446 }
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
447
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
448 {
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
449 int pointer_x, pointer_y;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
450 getCurrentPointer(s1, s, &pointer_x, &pointer_y);
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
451 paintMousePointer(s1, s, &pointer_x, &pointer_y, image);
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
452 }
1580
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
453
1582
754781df8033 RFC 1 stage: Improve maintainability of the cursoir painting code
gpoirier
parents: 1581
diff changeset
454
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
455 /* XXX: avoid memcpy */
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
456 memcpy(pkt->data, image->data, s->frame_size);
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
457 return s->frame_size;
1580
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
458 }
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
459
1585
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
460 static int
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
461 x11grab_read_close(AVFormatContext *s1)
1580
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
462 {
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
463 X11Grab *x11grab = s1->priv_data;
1582
754781df8033 RFC 1 stage: Improve maintainability of the cursoir painting code
gpoirier
parents: 1581
diff changeset
464
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
465 /* Detach cleanly from shared mem */
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
466 if (x11grab->use_shm) {
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
467 XShmDetach(x11grab->dpy, &x11grab->shminfo);
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
468 shmdt(x11grab->shminfo.shmaddr);
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
469 shmctl(x11grab->shminfo.shmid, IPC_RMID, NULL);
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
470 }
1582
754781df8033 RFC 1 stage: Improve maintainability of the cursoir painting code
gpoirier
parents: 1581
diff changeset
471
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
472 /* Destroy X11 image */
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
473 if (x11grab->image) {
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
474 XDestroyImage(x11grab->image);
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
475 x11grab->image = NULL;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
476 }
1583
8c0065795c92 RFC 2 stage: First feedback from review comments
gpoirier
parents: 1582
diff changeset
477
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
478 /* Free X11 display */
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
479 XCloseDisplay(x11grab->dpy);
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
480 return 0;
1580
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
481 }
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
482
1581
90a8061c5f83 Adapt the patch to more recent FFmpeg habits
gpoirier
parents: 1580
diff changeset
483 AVInputFormat x11_grab_device_demuxer =
90a8061c5f83 Adapt the patch to more recent FFmpeg habits
gpoirier
parents: 1580
diff changeset
484 {
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
485 "x11grab",
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
486 "X11grab",
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
487 sizeof(X11Grab),
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
488 NULL,
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
489 x11grab_read_header,
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
490 x11grab_read_packet,
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
491 x11grab_read_close,
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
492 .flags = AVFMT_NOFILE,
1580
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
493 };