1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
/*
* x11source.h - X11/transcode bridge code, allowing screen capture.
* (C) 2006-2010 - Francesco Romani <fromani -at- gmail -dot- com>
*
* This file is part of transcode, a video stream processing tool.
*
* transcode is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* transcode is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TC_X11SOURCE_H
#define TC_X11SOURCE_H
#include "config.h"
#include <stdint.h>
#include "probe.h"
#include "framebuffer.h"
typedef struct tcX11source_ TCX11Source;
/*
* Quick summary:
*
* this code acts as a bridge to a running X11 server, allowing
* client code to query about picture attributes, from transcode
* point of view, so frame size, frame depth and so on, and allow
* to grab images when requested (ok, that's still needs some work
* to avoid async responses and other X11 quirks).
*
* PLEASE NOTE: Only *LOCAL* X11 connections (NOT NETWORKED)
* are supported.
*
* Quick TODO (approx. priorty sorted):
* - internal refactoring
* - support 15/16 bits color depth.
* - grab pointer too.
* - support useful extensions like Damage/etc. etc.
* - docs for sources
* - user docs
*/
#ifdef HAVE_X11
#include <X11/Xlib.h>
#include <X11/Xutil.h>
# ifdef HAVE_X11_SHM
# include <sys/ipc.h>
# include <sys/shm.h>
# include <X11/extensions/XShm.h>
# endif /* X11_SHM */
#endif /* X11 */
struct tcX11source_ {
#ifdef HAVE_X11
Display *dpy;
int screen;
Window root;
Pixmap pix;
GC gc;
XImage *image;
# ifdef HAVE_X11_SHM
XVisualInfo vis_info;
XShmSegmentInfo shm_info;
# endif /* X11_SHM */
#endif /* X11 */
int width;
int height;
int depth;
int mode;
uint32_t out_fmt; /* TC internal identifier */
int conv_fmt; /* precomputed tcv_convert identifier */
TCVHandle tcvhandle;
int (*acquire_image)(TCX11Source *handle, uint8_t *data, int maxdata);
void (*acquire_cursor)(TCX11Source *handle, uint8_t *data, int maxdata);
int (*fini)(TCX11Source *handle);
};
typedef enum tcx11sourcemode_ TCX11SourceMode;
enum tcx11sourcemode_ {
TC_X11_MODE_PLAIN = 0,
TC_X11_MODE_SHM,
TC_X11_MODE_BEST = 255, /* this MUST be the last one */
};
/*
* tc_x11source_is_display_name:
* check if given name looks like an X11 display ID.
*
* PLEASE NOTE: only LOCAL display are supported (^:[0-9]+\.[0-9]+$)
*
* Parameters:
* name: ID to be verified
* Return Value:
* TC_TRUE: given name looks like an X11 display ID (so it can
* be used as argument for _open, see below).
* TC_FALSE: otherwise.
*/
int tc_x11source_is_display_name(const char *name);
/*
* tc_x11source_probe:
* fetch image parameters through given connection and
* store them into given info structure.
*
* Parameters:
* handle: connection handle to be used for probing.
* info: pointer to a ProbeInfo strucutre which will
* hold probed informations.
* Return Value:
* -1: error on connection, reason will be tc_log_*()'d out.
* 0: succesfull
* 1: wrong (NULL) parameters.
*/
int tc_x11source_probe(TCX11Source *handle, ProbeInfo *info);
/*
* tc_x11source_open:
* connext to given LOCAL X11 display, and prepare ofr later
* probing and/or image acquisition.
*
* Parameters:
* handle: connection handle to be used. (Allocation must
* be handled by caller).
* display: LOCAL X11 display identifier to connect on.
* mode: select X extensions to use, if avalaible.
* format: image (colorspace) format to be used in
* tc_x11source_acquire. Currently only following
* formats are supported:
* TC_CODEC_RGB, TC_CODEC_YUV420P, TC_CODEC_YUV422P
* Return Value:
* -1: error on connection, reason will be tc_log_*()'d out.
* 0: succesfull
* 1: wrong (NULL) parameters.
*/
int tc_x11source_open(TCX11Source *handle, const char *display,
int mode, uint32_t format);
/*
* tc_x11source_close:
* close an X11 connection represented by given handle, and
* releases all acquired resources.
*
* Parameters:
* handle: connection handle to be closed.
* Return Value:
* -1: error on connection, reason will be tc_log_*()'d out.
* 0: succesfull
* 1: wrong (NULL) parameters.
*/
int tc_x11source_close(TCX11Source *handle);
/*
* tc_x11source_acquire:
* grab a screenshot from given X11 source connection, convert
* it in RGB24 format and store it in given buffer, if this buffer
* is large enough to store the full picture.
*
* Parameters:
* handle: connection handle to be used for picture acquisition.
* data: picture buffer
* maxdata: size of picture buffer
* Return Value:
* -1: can't get image data from X11 connection
* 0: image buffer too small, so buffer was left untouched
* >0: size of acquire dimage.
*/
int tc_x11source_acquire(TCX11Source *handle, uint8_t *data, int maxdata);
#endif /* TC_X11SOURCE_H */
|