1 /*
2 * Copyright (c) 2011 Stefano Sabatini
3 * Copyright (c) 2009 Giliard B. de Freitas <giliarde@gmail.com>
4 * Copyright (C) 2002 Gunnar Monell <gmo@linux.nu>
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 /**
24 * @file
25 * Linux framebuffer input device,
26 * inspired by code from fbgrab.c by Gunnar Monell.
27 * @see http://linux-fbdev.sourceforge.net/
28 */
29
30 #include <unistd.h>
31 #include <fcntl.h>
32 #include <sys/ioctl.h>
33 #include <sys/mman.h>
35 #include <linux/fb.h>
36
48
50 AVClass *
class;
///< class for private options
54
55 int fd;
///< framebuffer device file descriptor
57 int frame_linesize;
///< linesize of the output frame, it is assumed to be constant
59
60 struct fb_var_screeninfo
varinfo;
///< variable info;
61 struct fb_fix_screeninfo
fixinfo;
///< fixed info;
62
63 uint8_t *
data;
///< framebuffer data
65
67 {
72 const char* device;
73
77
78 /* NONBLOCK is ignored by the fbdev driver, only set for consistency */
81
84 else
86
90 "Could not open framebuffer device '%s': %s\n",
93 }
94
95 if (ioctl(fbdev->
fd, FBIOGET_VSCREENINFO, &fbdev->
varinfo) < 0) {
100 }
101
102 if (ioctl(fbdev->
fd, FBIOGET_FSCREENINFO, &fbdev->
fixinfo) < 0) {
107 }
108
113 "Framebuffer pixel format not supported.\n");
115 }
116
123 fbdev->
data = mmap(
NULL, fbdev->
fixinfo.smem_len, PROT_READ, MAP_SHARED, fbdev->
fd, 0);
124 if (fbdev->
data == MAP_FAILED) {
128 }
129
138
140 "w:%d h:%d bpp:%d pixfmt:%s fps:%d/%d bit_rate:%"PRId64"\n",
145 return 0;
146
150 }
151
153 {
156 struct timespec ts;
158 uint8_t *pin, *pout;
159
162
163 /* wait based on the frame rate */
164 while (1) {
168 "time_frame:%"PRId64" curtime:%"PRId64" delay:%"PRId64"\n",
170 if (delay <= 0) {
172 break;
173 }
176 ts.tv_sec = delay / 1000000;
177 ts.tv_nsec = (delay % 1000000) * 1000;
178 while (nanosleep(&ts, &ts) < 0 && errno == EINTR);
179 }
180
183
184 /* refresh fbdev->varinfo, visible data position may change at each call */
185 if (ioctl(fbdev->
fd, FBIOGET_VSCREENINFO, &fbdev->
varinfo) < 0) {
188 }
189
191
192 /* compute visible data offset */
196
199 pin += fbdev->
fixinfo.line_length;
201 }
202
204 }
205
207 {
209
212
213 return 0;
214 }
215
217 {
219 }
220
221 #define OFFSET(x) offsetof(FBDevContext, x)
222 #define DEC AV_OPT_FLAG_DECODING_PARAM
226 };
227
234 };
235
246 };