1 /*
2 * Copyright (c) 2013 Lukasz Marek
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include <unistd.h>
22 #include <fcntl.h>
23 #include <sys/ioctl.h>
24 #include <sys/mman.h>
25 #include <linux/fb.h>
33
34 typedef struct {
35 AVClass *
class;
///< class for private options
36 int xoffset;
///< x coordinate of top left corner
37 int yoffset;
///< y coordinate of top left corner
38 struct fb_var_screeninfo varinfo; ///< framebuffer variable info
39 struct fb_fix_screeninfo fixinfo; ///< framebuffer fixed info
40 int fd; ///< framebuffer device file descriptor
43
45 {
48 int ret,
flags = O_RDWR;
49 const char* device;
50
54 }
55
58 else
60
64 "Could not open framebuffer device '%s': %s\n",
66 return ret;
67 }
68
69 if (ioctl(fbdev->
fd, FBIOGET_VSCREENINFO, &fbdev->
varinfo) < 0) {
73 }
74
75 if (ioctl(fbdev->
fd, FBIOGET_FSCREENINFO, &fbdev->
fixinfo) < 0) {
79 }
80
86 }
87
88 fbdev->
data = mmap(
NULL, fbdev->
fixinfo.smem_len, PROT_WRITE, MAP_SHARED, fbdev->
fd, 0);
89 if (fbdev->
data == MAP_FAILED) {
93 }
94
95 return 0;
98 return ret;
99 }
100
102 {
106 int disp_height;
107 int bytes_to_copy;
110 int video_width = par->
width;
111 int video_height = par->
height;
113 int src_line_size = video_width * bytes_per_pixel;
114 int i;
115
116 if (ioctl(fbdev->
fd, FBIOGET_VSCREENINFO, &fbdev->
varinfo) < 0)
119
121
122 if (fb_pix_fmt != video_pix_fmt) {
126 }
127
129 bytes_to_copy =
FFMIN(fbdev->
varinfo.xres, video_width) * bytes_per_pixel;
130
133 bytes_per_pixel * fbdev->
varinfo.xoffset +
135
138 if (-fbdev->
xoffset >= video_width)
//nothing to display
139 return 0;
140 bytes_to_copy += fbdev->
xoffset * bytes_per_pixel;
141 pin -= fbdev->
xoffset * bytes_per_pixel;
142 } else {
145 if (diff >= video_width) //nothing to display
146 return 0;
147 bytes_to_copy -= diff * bytes_per_pixel;
148 }
149 pout += bytes_per_pixel * fbdev->
xoffset;
150 }
151 }
152
155 if (-fbdev->
yoffset >= video_height)
//nothing to display
156 return 0;
158 pin -= fbdev->
yoffset * src_line_size;
159 } else {
162 if (diff >= video_height) //nothing to display
163 return 0;
165 }
167 }
168 }
169
170 for (i = 0; i < disp_height; i++) {
171 memcpy(pout, pin, bytes_to_copy);
172 pout += fbdev->
fixinfo.line_length;
173 pin += src_line_size;
174 }
175
176 return 0;
177 }
178
180 {
184 return 0;
185 }
186
188 {
190 }
191
192 #define OFFSET(x) offsetof(FBDevContext, x)
193 #define ENC AV_OPT_FLAG_ENCODING_PARAM
195 {
"xoffset",
"set x coordinate of top left corner",
OFFSET(xoffset),
AV_OPT_TYPE_INT, {.i64 = 0}, INT_MIN, INT_MAX,
ENC },
196 {
"yoffset",
"set y coordinate of top left corner",
OFFSET(yoffset),
AV_OPT_TYPE_INT, {.i64 = 0}, INT_MIN, INT_MAX,
ENC },
198 };
199
206 };
207
219 .priv_class = &fbdev_class,
220 };
static enum AVPixelFormat pix_fmt
ptrdiff_t const GLvoid * data
#define AV_LOG_WARNING
Something somehow does not look correct.
#define LIBAVUTIL_VERSION_INT
Memory handling functions.
const char * ff_fbdev_default_device()
This struct describes the properties of an encoded stream.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
struct fb_var_screeninfo varinfo
variable info;
AVStream ** streams
A list of all streams in the file.
int avpriv_open(const char *filename, int flags,...)
A wrapper for open() setting O_CLOEXEC.
AVOutputFormat ff_fbdev_muxer
Main libavdevice API header.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
enum AVMediaType codec_type
General type of the encoded data.
static const AVOption options[]
struct fb_fix_screeninfo fixinfo
fixed info;
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
char filename[1024]
input or output filename
int yoffset
y coordinate of top left corner
static int write_trailer(AVFormatContext *s1)
static av_cold int fbdev_write_header(AVFormatContext *h)
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
int xoffset
x coordinate of top left corner
static av_cold int fbdev_write_trailer(AVFormatContext *h)
int ff_fbdev_get_device_list(AVDeviceInfoList *device_list)
static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost)
Describe the class of an AVClass context structure.
static int fbdev_get_device_list(AVFormatContext *s, AVDeviceInfoList *device_list)
static int fbdev_write_packet(AVFormatContext *h, AVPacket *pkt)
static int get_device_list(AVOpenCLDeviceList *device_list)
enum AVPixelFormat ff_get_pixfmt_from_fb_varinfo(struct fb_var_screeninfo *varinfo)
static av_always_inline int diff(const uint32_t a, const uint32_t b)
void * priv_data
Format private data.
static const AVClass fbdev_class
static void write_header(FFV1Context *f)
int bits_per_coded_sample
The number of bits per sample in the codedwords.
uint8_t * data
framebuffer data
AVCodecParameters * codecpar
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
AVPixelFormat
Pixel format.
This structure stores compressed data.
int fd
framebuffer device file descriptor