annotate x11grab.c @ 1648:90987914ad57 libavformat

makes the filename member of the URLContext a pointer, so that the structure can be extended in the future without breaking ABI. patch by Ronald S. Bultje % rbultje A ronald P bitfreak P net % Original thread: Date: Jan 1, 2007 6:01 PM Subject: [Ffmpeg-devel] make URLContext->filename a pointer
author gpoirier
date Sun, 14 Jan 2007 22:07:19 +0000
parents e7c247a67e20
children d0a97c73ee97
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
1586
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
28 * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
1585
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
1586
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
32 /**
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
33 * @file x11grab.c
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
34 * X11 frame device demuxer by Clemens Fruhwirth <clemens@endorphin.org>
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
35 * and Edouard Gomez <ed.gomez@free.fr>.
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
36 */
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
37
1580
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
38 #include "avformat.h"
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
39 #include <unistd.h>
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
40 #include <fcntl.h>
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
41 #include <sys/ioctl.h>
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
42 #include <sys/mman.h>
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
43 #include <sys/time.h>
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
44 #define _LINUX_TIME_H 1
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
45 #include <time.h>
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
46 #include <X11/X.h>
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
47 #include <X11/Xlib.h>
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
48 #include <X11/Xlibint.h>
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
49 #include <X11/Xproto.h>
1583
8c0065795c92 RFC 2 stage: First feedback from review comments
gpoirier
parents: 1582
diff changeset
50 #include <X11/Xutil.h>
1580
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
51 #include <sys/ipc.h>
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
52 #include <sys/shm.h>
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
53 #include <X11/extensions/XShm.h>
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
54
1586
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
55 /**
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
56 * X11 Device Demuxer context
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
57 */
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
58 typedef struct x11_grab_s
1581
90a8061c5f83 Adapt the patch to more recent FFmpeg habits
gpoirier
parents: 1580
diff changeset
59 {
1586
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
60 int frame_size; /**< Size in bytes of a grabbed frame */
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
61 AVRational time_base; /**< Time base */
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
62 int64_t time_frame; /**< Current time */
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
63
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
64 int height; /**< Height of the grab frame */
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
65 int width; /**< Width of the grab frame */
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
66 int x_off; /**< Horizontal top-left corner coordinate */
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
67 int y_off; /**< Vertical top-left corner coordinate */
1580
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
68
1586
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
69 Display *dpy; /**< X11 display from which x11grab grabs frames */
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
70 XImage *image; /**< X11 image holding the grab */
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
71 int use_shm; /**< !0 when using XShm extension */
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
72 XShmSegmentInfo shminfo; /**< When using XShm, keeps track of XShm infos */
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
73 } x11_grab_t;
1580
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
74
1586
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
75 /**
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
76 * Initializes the x11 grab device demuxer (public device demuxer API).
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
77 *
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
78 * @param s1 Context from avformat core
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
79 * @param ap Parameters from avformat core
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
80 * @return <ul>
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
81 * <li>ENOMEM no memory left</li>
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
82 * <li>AVERROR_IO other failure case</li>
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
83 * <li>0 success</li>
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
84 * </ul>
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
85 */
1581
90a8061c5f83 Adapt the patch to more recent FFmpeg habits
gpoirier
parents: 1580
diff changeset
86 static int
90a8061c5f83 Adapt the patch to more recent FFmpeg habits
gpoirier
parents: 1580
diff changeset
87 x11grab_read_header(AVFormatContext *s1, AVFormatParameters *ap)
1580
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
88 {
1586
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
89 x11_grab_t *x11grab = s1->priv_data;
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
90 Display *dpy;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
91 AVStream *st = NULL;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
92 int input_pixfmt;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
93 XImage *image;
1586
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
94 int x_off = 0;
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
95 int y_off = 0;
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
96 int use_shm;
1591
5b46490d0435 Allow provision of displaynumber, screennumber, x-offset and y-offset parameters
takis
parents: 1590
diff changeset
97 char *param, *offset;
1580
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
98
1590
ba2244f38a76 dont segv is ap->device is not set, display error message
bcoudurier
parents: 1589
diff changeset
99 if (!ap->device) {
ba2244f38a76 dont segv is ap->device is not set, display error message
bcoudurier
parents: 1589
diff changeset
100 av_log(s1, AV_LOG_ERROR, "AVParameters don't specify any device. Use -vd.\n");
ba2244f38a76 dont segv is ap->device is not set, display error message
bcoudurier
parents: 1589
diff changeset
101 return AVERROR_IO;
ba2244f38a76 dont segv is ap->device is not set, display error message
bcoudurier
parents: 1589
diff changeset
102 }
ba2244f38a76 dont segv is ap->device is not set, display error message
bcoudurier
parents: 1589
diff changeset
103
1591
5b46490d0435 Allow provision of displaynumber, screennumber, x-offset and y-offset parameters
takis
parents: 1590
diff changeset
104 param = strchr(ap->device, ':');
5b46490d0435 Allow provision of displaynumber, screennumber, x-offset and y-offset parameters
takis
parents: 1590
diff changeset
105 if (!param) {
5b46490d0435 Allow provision of displaynumber, screennumber, x-offset and y-offset parameters
takis
parents: 1590
diff changeset
106 av_free(st);
5b46490d0435 Allow provision of displaynumber, screennumber, x-offset and y-offset parameters
takis
parents: 1590
diff changeset
107 return AVERROR_IO;
5b46490d0435 Allow provision of displaynumber, screennumber, x-offset and y-offset parameters
takis
parents: 1590
diff changeset
108 }
5b46490d0435 Allow provision of displaynumber, screennumber, x-offset and y-offset parameters
takis
parents: 1590
diff changeset
109
5b46490d0435 Allow provision of displaynumber, screennumber, x-offset and y-offset parameters
takis
parents: 1590
diff changeset
110 param = av_strdup(param);
5b46490d0435 Allow provision of displaynumber, screennumber, x-offset and y-offset parameters
takis
parents: 1590
diff changeset
111 offset = strchr(param, '+');
5b46490d0435 Allow provision of displaynumber, screennumber, x-offset and y-offset parameters
takis
parents: 1590
diff changeset
112 if (offset) {
5b46490d0435 Allow provision of displaynumber, screennumber, x-offset and y-offset parameters
takis
parents: 1590
diff changeset
113 sscanf(offset, "%d,%d", &x_off, &y_off);
5b46490d0435 Allow provision of displaynumber, screennumber, x-offset and y-offset parameters
takis
parents: 1590
diff changeset
114 *offset= 0;
5b46490d0435 Allow provision of displaynumber, screennumber, x-offset and y-offset parameters
takis
parents: 1590
diff changeset
115 }
5b46490d0435 Allow provision of displaynumber, screennumber, x-offset and y-offset parameters
takis
parents: 1590
diff changeset
116
5b46490d0435 Allow provision of displaynumber, screennumber, x-offset and y-offset parameters
takis
parents: 1590
diff changeset
117 av_log(s1, AV_LOG_INFO, "device: %s -> display: %s x: %d y: %d width: %d height: %d\n", ap->device, param, x_off, y_off, ap->width, ap->height);
5b46490d0435 Allow provision of displaynumber, screennumber, x-offset and y-offset parameters
takis
parents: 1590
diff changeset
118
5b46490d0435 Allow provision of displaynumber, screennumber, x-offset and y-offset parameters
takis
parents: 1590
diff changeset
119 dpy = XOpenDisplay(param);
5b46490d0435 Allow provision of displaynumber, screennumber, x-offset and y-offset parameters
takis
parents: 1590
diff changeset
120 if(!dpy) {
5b46490d0435 Allow provision of displaynumber, screennumber, x-offset and y-offset parameters
takis
parents: 1590
diff changeset
121 av_log(s1, AV_LOG_ERROR, "Could not open X display.\n");
5b46490d0435 Allow provision of displaynumber, screennumber, x-offset and y-offset parameters
takis
parents: 1590
diff changeset
122 return AVERROR_IO;
5b46490d0435 Allow provision of displaynumber, screennumber, x-offset and y-offset parameters
takis
parents: 1590
diff changeset
123 }
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
124
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
125 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
126 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
127 return AVERROR_IO;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
128 }
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
129
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
130 st = av_new_stream(s1, 0);
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
131 if (!st) {
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
132 return -ENOMEM;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
133 }
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
134 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
135
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
136 use_shm = XShmQueryExtension(dpy);
1586
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
137 av_log(s1, AV_LOG_INFO, "shared memory extension %s found\n", use_shm ? "" : "not");
1581
90a8061c5f83 Adapt the patch to more recent FFmpeg habits
gpoirier
parents: 1580
diff changeset
138
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
139 if(use_shm) {
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
140 int scr = XDefaultScreen(dpy);
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
141 image = XShmCreateImage(dpy,
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
142 DefaultVisual(dpy, scr),
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
143 DefaultDepth(dpy, scr),
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
144 ZPixmap,
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
145 NULL,
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
146 &x11grab->shminfo,
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
147 ap->width, ap->height);
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
148 x11grab->shminfo.shmid = shmget(IPC_PRIVATE,
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
149 image->bytes_per_line * image->height,
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
150 IPC_CREAT|0777);
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
151 if (x11grab->shminfo.shmid == -1) {
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
152 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
153 return -ENOMEM;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
154 }
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
155 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
156 x11grab->shminfo.readOnly = False;
1580
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
157
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
158 if (!XShmAttach(dpy, &x11grab->shminfo)) {
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
159 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
160 /* needs some better error subroutine :) */
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
161 return AVERROR_IO;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
162 }
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
163 } else {
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
164 image = XGetImage(dpy, RootWindow(dpy, DefaultScreen(dpy)),
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
165 x_off,y_off,
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
166 ap->width,ap->height,
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
167 AllPlanes, ZPixmap);
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
168 }
1580
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
169
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
170 switch (image->bits_per_pixel) {
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
171 case 8:
1630
e7c247a67e20 typo: pallete --> palette
diego
parents: 1591
diff changeset
172 av_log (s1, AV_LOG_DEBUG, "8 bit palette\n");
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
173 input_pixfmt = PIX_FMT_PAL8;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
174 break;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
175 case 16:
1586
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
176 if ( image->red_mask == 0xf800 &&
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
177 image->green_mask == 0x07e0 &&
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
178 image->blue_mask == 0x001f ) {
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
179 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
180 input_pixfmt = PIX_FMT_RGB565;
1586
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
181 } else if (image->red_mask == 0x7c00 &&
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
182 image->green_mask == 0x03e0 &&
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
183 image->blue_mask == 0x001f ) {
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
184 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
185 input_pixfmt = PIX_FMT_RGB555;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
186 } else {
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
187 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
188 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
189 return AVERROR_IO;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
190 }
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 case 24:
1586
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
193 if ( image->red_mask == 0xff0000 &&
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
194 image->green_mask == 0x00ff00 &&
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
195 image->blue_mask == 0x0000ff ) {
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
196 input_pixfmt = PIX_FMT_BGR24;
1586
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
197 } else if ( image->red_mask == 0x0000ff &&
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
198 image->green_mask == 0x00ff00 &&
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
199 image->blue_mask == 0xff0000 ) {
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
200 input_pixfmt = PIX_FMT_RGB24;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
201 } else {
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
202 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
203 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
204 return AVERROR_IO;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
205 }
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
206 break;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
207 case 32:
1580
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
208 #if 0
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
209 GetColorInfo (image, &c_info);
1586
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
210 if ( c_info.alpha_mask == 0xff000000 && image->green_mask == 0x0000ff00) {
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
211 /* byte order is relevant here, not endianness
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
212 * 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
213 * 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
214 * 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
215 * 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
216 * this matches both ARGB32 and ABGR32 */
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
217 input_pixfmt = PIX_FMT_ARGB32;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
218 } else {
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
219 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
220 return AVERROR_IO;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
221 }
1580
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
222 #endif
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
223 input_pixfmt = PIX_FMT_RGBA32;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
224 break;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
225 default:
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
226 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
227 return -1;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
228 }
1580
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
229
1586
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
230 x11grab->frame_size = ap->width * ap->height * image->bits_per_pixel/8;
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
231 x11grab->dpy = dpy;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
232 x11grab->width = ap->width;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
233 x11grab->height = ap->height;
1586
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
234 x11grab->time_base = ap->time_base;
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
235 x11grab->time_frame = av_gettime() / av_q2d(ap->time_base);
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
236 x11grab->x_off = x_off;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
237 x11grab->y_off = y_off;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
238 x11grab->image = image;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
239 x11grab->use_shm = use_shm;
1580
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
240
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
241 st->codec->codec_type = CODEC_TYPE_VIDEO;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
242 st->codec->codec_id = CODEC_ID_RAWVIDEO;
1586
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
243 st->codec->width = ap->width;
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
244 st->codec->height = ap->height;
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
245 st->codec->pix_fmt = input_pixfmt;
1586
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
246 st->codec->time_base = ap->time_base;
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
247 st->codec->bit_rate = x11grab->frame_size * 1/av_q2d(ap->time_base) * 8;
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
248
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
249 return 0;
1580
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
250 }
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
251
1586
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
252 /**
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
253 * Get pointer coordinates from X11.
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
254 *
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
255 * @param x Integer where horizontal coordinate will be returned
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
256 * @param y Integer where vertical coordinate will be returned
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
257 * @param dpy X11 display from where pointer coordinates are retrieved
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
258 * @param s1 Context used for logging errors if necessary
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
259 */
1581
90a8061c5f83 Adapt the patch to more recent FFmpeg habits
gpoirier
parents: 1580
diff changeset
260 static void
1586
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
261 get_pointer_coordinates(int *x, int *y, Display *dpy, AVFormatContext *s1)
1581
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 Window mrootwindow, childwindow;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
264 int dummy;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
265
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
266 mrootwindow = DefaultRootWindow(dpy);
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
267
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
268 if (XQueryPointer(dpy, mrootwindow, &mrootwindow, &childwindow,
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
269 x, y, &dummy, &dummy, (unsigned int*)&dummy)) {
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
270 } else {
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
271 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
272 *x = -1;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
273 *y = -1;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
274 }
1580
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
275 }
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
276
1586
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
277 /**
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
278 * Mouse painting helper function that applies an 'and' and 'or' mask pair to
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
279 * '*dst' pixel. It actually draws a mouse pointer pixel to grabbed frame.
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
280 *
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
281 * @param dst Destination pixel
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
282 * @param and Part of the mask that must be applied using a bitwise 'and'
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
283 * operator
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
284 * @param or Part of the mask that must be applied using a bitwise 'or'
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
285 * operator
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
286 * @param bits_per_pixel Bits per pixel used in the grabbed image
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
287 */
1585
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
288 static void inline
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
289 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
290 {
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
291 switch (bits_per_pixel) {
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
292 case 32:
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
293 *(uint32_t*)dst = (*(uint32_t*)dst & and) | or;
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
294 break;
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
295 case 16:
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
296 *(uint16_t*)dst = (*(uint16_t*)dst & and) | or;
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
297 break;
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
298 case 8:
1586
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
299 *dst = !!or;
1585
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
300 break;
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
301 }
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
302 }
1582
754781df8033 RFC 1 stage: Improve maintainability of the cursoir painting code
gpoirier
parents: 1581
diff changeset
303
1586
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
304 /**
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
305 * Paints a mouse pointer in an X11 image.
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
306 *
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
307 * @param image Image where to paint the mouse pointer
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
308 * @param s context used to retrieve original grabbing rectangle
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
309 * coordinates
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
310 * @param x Mouse pointer coordinate
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
311 * @param y Mouse pointer coordinate
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
312 */
1581
90a8061c5f83 Adapt the patch to more recent FFmpeg habits
gpoirier
parents: 1580
diff changeset
313 static void
1586
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
314 paint_mouse_pointer(XImage *image, x11_grab_t *s, int x, int y)
1581
90a8061c5f83 Adapt the patch to more recent FFmpeg habits
gpoirier
parents: 1580
diff changeset
315 {
1586
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
316 /* 16x20x1bpp bitmap for the black channel of the mouse pointer */
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
317 static const uint16_t const mousePointerBlack[] =
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
318 {
1587
d977c962f64b Feedback from Karl H. Beckers about mouse cursor
gpoirier
parents: 1586
diff changeset
319 0x0000, 0x0003, 0x0005, 0x0009, 0x0011,
d977c962f64b Feedback from Karl H. Beckers about mouse cursor
gpoirier
parents: 1586
diff changeset
320 0x0021, 0x0041, 0x0081, 0x0101, 0x0201,
d977c962f64b Feedback from Karl H. Beckers about mouse cursor
gpoirier
parents: 1586
diff changeset
321 0x03c1, 0x0049, 0x0095, 0x0093, 0x0120,
d977c962f64b Feedback from Karl H. Beckers about mouse cursor
gpoirier
parents: 1586
diff changeset
322 0x0120, 0x0240, 0x0240, 0x0380, 0x0000
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
323 };
1583
8c0065795c92 RFC 2 stage: First feedback from review comments
gpoirier
parents: 1582
diff changeset
324
1586
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
325 /* 16x20x1bpp bitmap for the white channel of the mouse pointer */
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
326 static const uint16_t const mousePointerWhite[] =
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
327 {
1587
d977c962f64b Feedback from Karl H. Beckers about mouse cursor
gpoirier
parents: 1586
diff changeset
328 0x0000, 0x0000, 0x0002, 0x0006, 0x000e,
d977c962f64b Feedback from Karl H. Beckers about mouse cursor
gpoirier
parents: 1586
diff changeset
329 0x001e, 0x003e, 0x007e, 0x00fe, 0x01fe,
d977c962f64b Feedback from Karl H. Beckers about mouse cursor
gpoirier
parents: 1586
diff changeset
330 0x003e, 0x0036, 0x0062, 0x0060, 0x00c0,
d977c962f64b Feedback from Karl H. Beckers about mouse cursor
gpoirier
parents: 1586
diff changeset
331 0x00c0, 0x0180, 0x0180, 0x0000, 0x0000
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
332 };
1583
8c0065795c92 RFC 2 stage: First feedback from review comments
gpoirier
parents: 1582
diff changeset
333
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
334 int x_off = s->x_off;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
335 int y_off = s->y_off;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
336 int width = s->width;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
337 int height = s->height;
1580
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
338
1586
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
339 if ( x - x_off >= 0 && x < width + x_off
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
340 && y - y_off >= 0 && y < height + y_off) {
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
341 uint8_t *im_data = (uint8_t*)image->data;
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
342 int bytes_per_pixel;
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
343 int line;
1585
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
344 int masks;
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
345
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
346 /* Select correct masks and pixel size */
1586
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
347 if (image->bits_per_pixel == 8) {
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
348 masks = 1;
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
349 } else {
1585
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
350 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
351 }
1586
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
352 bytes_per_pixel = image->bits_per_pixel>>3;
1585
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
353
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
354 /* Shift to right line */
1586
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
355 im_data += image->bytes_per_line * (y - y_off);
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
356 /* Shift to right pixel in the line */
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
357 im_data += bytes_per_pixel * (x - x_off);
1585
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
358
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
359 /* Draw the cursor - proper loop */
1586
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
360 for (line = 0; line < FFMIN(20, (y_off + height) - y); line++) {
1585
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
361 uint8_t *cursor = im_data;
1586
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
362 int column;
1585
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
363 uint16_t bm_b;
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
364 uint16_t bm_w;
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
365
1586
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
366 bm_b = mousePointerBlack[line];
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
367 bm_w = mousePointerWhite[line];
1585
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
368
1586
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
369 for (column = 0; column < FFMIN(16, (x_off + width) - x); column++) {
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
370 apply_masks(cursor, ~(masks*(bm_b&1)), masks*(bm_w&1),
1585
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
371 image->bits_per_pixel);
1586
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
372 cursor += bytes_per_pixel;
1585
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
373 bm_b >>= 1;
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
374 bm_w >>= 1;
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
375 }
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
376 im_data += image->bytes_per_line;
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
377 }
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
378 }
1580
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
379 }
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
380
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
381
1586
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
382 /**
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
383 * Reads new data in the image structure.
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
384 *
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
385 * @param dpy X11 display to grab from
1588
d5d8ba9f1d2f remove trailing whitespace left over
gpoirier
parents: 1587
diff changeset
386 * @param d
1586
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
387 * @param image Image where the grab will be put
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
388 * @param x Top-Left grabbing rectangle horizontal coordinate
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
389 * @param y Top-Left grabbing rectangle vertical coordinate
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
390 * @return 0 if error, !0 if successful
1580
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
391 */
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
392 static int
1586
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
393 xget_zpixmap(Display *dpy, Drawable d, XImage *image, int x, int y)
1580
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
394 {
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
395 xGetImageReply rep;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
396 xGetImageReq *req;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
397 long nbytes;
1581
90a8061c5f83 Adapt the patch to more recent FFmpeg habits
gpoirier
parents: 1580
diff changeset
398
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
399 if (!image) {
1586
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
400 return 0;
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
401 }
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
402
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
403 LockDisplay(dpy);
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
404 GetReq(GetImage, req);
1581
90a8061c5f83 Adapt the patch to more recent FFmpeg habits
gpoirier
parents: 1580
diff changeset
405
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
406 /* 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
407 req->drawable = d;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
408 req->x = x;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
409 req->y = y;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
410 req->width = image->width;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
411 req->height = image->height;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
412 req->planeMask = (unsigned int)AllPlanes;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
413 req->format = ZPixmap;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
414
1586
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
415 if (!_XReply(dpy, (xReply *)&rep, 0, xFalse) || !rep.length) {
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
416 UnlockDisplay(dpy);
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
417 SyncHandle();
1586
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
418 return 0;
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
419 }
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
420
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
421 nbytes = (long)rep.length << 2;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
422 _XReadPad(dpy, image->data, nbytes);
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
423
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
424 UnlockDisplay(dpy);
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
425 SyncHandle();
1586
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
426 return 1;
1580
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
427 }
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
428
1586
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
429 /**
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
430 * Grabs a frame from x11 (public device demuxer API).
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
431 *
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
432 * @param s1 Context from avformat core
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
433 * @param pkt Packet holding the brabbed frame
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
434 * @return frame size in bytes
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
435 */
1585
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
436 static int
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
437 x11grab_read_packet(AVFormatContext *s1, AVPacket *pkt)
1580
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
438 {
1586
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
439 x11_grab_t *s = s1->priv_data;
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
440 Display *dpy = s->dpy;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
441 XImage *image = s->image;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
442 int x_off = s->x_off;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
443 int y_off = s->y_off;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
444
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
445 int64_t curtime, delay;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
446 struct timespec ts;
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 /* Calculate the time of the next frame */
1589
d63bac8be31a fix compilation, use the standard INT64_C macro
bcoudurier
parents: 1588
diff changeset
449 s->time_frame += INT64_C(1000000);
1580
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
450
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
451 /* wait based on the frame rate */
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
452 for(;;) {
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
453 curtime = av_gettime();
1586
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
454 delay = s->time_frame * av_q2d(s->time_base) - curtime;
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
455 if (delay <= 0) {
1589
d63bac8be31a fix compilation, use the standard INT64_C macro
bcoudurier
parents: 1588
diff changeset
456 if (delay < INT64_C(-1000000) * av_q2d(s->time_base)) {
d63bac8be31a fix compilation, use the standard INT64_C macro
bcoudurier
parents: 1588
diff changeset
457 s->time_frame += INT64_C(1000000);
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
458 }
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
459 break;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
460 }
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
461 ts.tv_sec = delay / 1000000;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
462 ts.tv_nsec = (delay % 1000000) * 1000;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
463 nanosleep(&ts, NULL);
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
464 }
1581
90a8061c5f83 Adapt the patch to more recent FFmpeg habits
gpoirier
parents: 1580
diff changeset
465
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
466 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
467 return AVERROR_IO;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
468 }
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
469
1586
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
470 pkt->pts = curtime;
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
471
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
472 if(s->use_shm) {
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
473 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
474 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
475 }
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
476 } else {
1586
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
477 if (!xget_zpixmap(dpy, RootWindow(dpy, DefaultScreen(dpy)), image, x_off, y_off)) {
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
478 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
479 }
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
480 }
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
481
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
482 {
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
483 int pointer_x, pointer_y;
1586
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
484 get_pointer_coordinates(&pointer_x, &pointer_y, dpy, s1);
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
485 paint_mouse_pointer(image, s, pointer_x, pointer_y);
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
486 }
1580
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
487
1582
754781df8033 RFC 1 stage: Improve maintainability of the cursoir painting code
gpoirier
parents: 1581
diff changeset
488
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
489 /* XXX: avoid memcpy */
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
490 memcpy(pkt->data, image->data, s->frame_size);
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
491 return s->frame_size;
1580
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
492 }
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
493
1586
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
494 /**
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
495 * Closes x11 frame grabber (public device demuxer API).
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
496 *
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
497 * @param s1 Context from avformat core
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
498 * @return 0 success, !0 failure
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
499 */
1585
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
500 static int
14c185883eab RFC 5: Mouse cursor painting reduc and more cleanups
gpoirier
parents: 1584
diff changeset
501 x11grab_read_close(AVFormatContext *s1)
1580
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
502 {
1586
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
503 x11_grab_t *x11grab = s1->priv_data;
1582
754781df8033 RFC 1 stage: Improve maintainability of the cursoir painting code
gpoirier
parents: 1581
diff changeset
504
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
505 /* Detach cleanly from shared mem */
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
506 if (x11grab->use_shm) {
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
507 XShmDetach(x11grab->dpy, &x11grab->shminfo);
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
508 shmdt(x11grab->shminfo.shmaddr);
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
509 shmctl(x11grab->shminfo.shmid, IPC_RMID, NULL);
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
510 }
1582
754781df8033 RFC 1 stage: Improve maintainability of the cursoir painting code
gpoirier
parents: 1581
diff changeset
511
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
512 /* Destroy X11 image */
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
513 if (x11grab->image) {
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
514 XDestroyImage(x11grab->image);
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
515 x11grab->image = NULL;
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
516 }
1583
8c0065795c92 RFC 2 stage: First feedback from review comments
gpoirier
parents: 1582
diff changeset
517
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
518 /* Free X11 display */
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
519 XCloseDisplay(x11grab->dpy);
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
520 return 0;
1580
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
521 }
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
522
1586
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
523 /** x11 grabber device demuxer declaration */
1581
90a8061c5f83 Adapt the patch to more recent FFmpeg habits
gpoirier
parents: 1580
diff changeset
524 AVInputFormat x11_grab_device_demuxer =
90a8061c5f83 Adapt the patch to more recent FFmpeg habits
gpoirier
parents: 1580
diff changeset
525 {
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
526 "x11grab",
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
527 "X11grab",
1586
56d6828ab647 RFC 6: Overall cleanups again.
gpoirier
parents: 1585
diff changeset
528 sizeof(x11_grab_t),
1584
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
529 NULL,
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
530 x11grab_read_header,
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
531 x11grab_read_packet,
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
532 x11grab_read_close,
33997fca4b0d RFC 3&4 stage: FFmpeg style aint't my style
gpoirier
parents: 1583
diff changeset
533 .flags = AVFMT_NOFILE,
1580
32bfc91cb541 Original X11 device demuxer patch from Clemens Fruhwirth
gpoirier
parents: 1579
diff changeset
534 };