1 /*
2 * Copyright (c) 2013 Jeff Moguillansky
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 /**
22 * @file
23 * XVideo output device
24 *
25 * TODO:
26 * - add support to more formats
27 */
28
29 #include <X11/Xlib.h>
30 #include <X11/extensions/Xv.h>
31 #include <X11/extensions/XShm.h>
32 #include <X11/extensions/Xvlib.h>
33 #include <sys/shm.h>
34
40
44
50 int dest_x,
dest_y;
/**< display area position */
51 unsigned int dest_w, dest_h;
/**< display area dimensions */
52
55
63
65 {
69
75 };
76
78 {
80 int i;
81 for (i = 0; m->
tag; m = &tag_codec_map[++i]) {
84 }
85 return 0;
86 }
87
89 {
99 }
100 return 0;
101 }
102
104 {
106 unsigned int num_adaptors;
107 XvAdaptorInfo *ai;
108 XvImageFormatValues *fv;
109 XColor fgcolor;
110 XWindowAttributes window_attrs;
111 int num_formats = 0, j,
tag, ret;
113
119 }
120
123 "Unsupported pixel format '%s', only yuv420p, uyvy422, yuyv422 are currently supported\n",
126 }
128
133 }
134
146 }
147 }
152 0, 0, 0);
157 }
158 }
163 } else
165
166 if (XvQueryAdaptors(xv->
display, DefaultRootWindow(xv->
display), &num_adaptors, &ai) != Success) {
169 }
170 if (!num_adaptors) {
173 }
175 XvFreeAdaptorInfo(ai);
176
178 if (!fv) {
181 }
182 for (j = 0; j < num_formats; j++) {
183 if (fv[j].id == tag) {
184 break;
185 }
186 }
187 XFree(fv);
188
189 if (j >= num_formats) {
191 "Device does not support pixel format %s, aborting\n",
195 }
196
203 IPC_CREAT | 0777);
207
211
212 XGetWindowAttributes(xv->
display, xv->
window, &window_attrs);
213 fgcolor.red = fgcolor.green = fgcolor.blue = 0;
214 fgcolor.flags = DoRed | DoGreen | DoBlue;
215 XAllocColor(xv->
display, window_attrs.colormap, &fgcolor);
216 XSetForeground(xv->
display, xv->
gc, fgcolor.pixel);
217 //force display area recalculation at first frame
219
220 return 0;
223 return ret;
224 }
225
227 {
229 AVRational sar, dar;
/* sample and display aspect ratios */
232
233 /* compute overlay width and height from the codec context information */
236
237 /* we suppose the screen has a 1/1 sample aspect ratio */
238 /* fit in the window */
240 /* fit in width */
246 } else {
247 /* fit in height */
253 }
254 }
255
257 {
259 XWindowAttributes window_attrs;
260
261 XGetWindowAttributes(xv->
display, xv->
window, &window_attrs);
264 xv->
dest_w = window_attrs.width;
265 xv->
dest_h = window_attrs.height;
268 rect[0].width = rect[1].width = xv->
dest_x;
269 rect[0].height = rect[1].height = window_attrs.height;
270 rect[0].y = rect[1].y = 0;
271 rect[0].x = 0;
274 }
276 rect[0].width = rect[1].width = window_attrs.width;
277 rect[0].height = rect[1].height = xv->
dest_y;
278 rect[0].x = rect[1].x = 0;
279 rect[0].y = 0;
282 }
283 }
284
290 }
291 return 0;
292 }
293
295 int linesize[4])
296 {
300 img->data + img->offsets[0],
301 img->data + img->offsets[1],
302 img->data + img->offsets[2]
303 };
304
305 /* Check messages. Window might get closed. */
307 XEvent event;
308 while (XPending(xv->
display)) {
309 XNextEvent(xv->
display, &event);
310 if (event.type == ClientMessage && event.xclient.data.l[0] == xv->
wm_delete_message) {
313 }
314 }
315 }
316
320 }
321
323 {
326 int linesize[4];
327
331 }
332
335 {
336 /* xv_write_header() should have accepted only supported formats */
338 return 0;
340 }
341
343 {
344 switch(type) {
347 default:
348 break;
349 }
351 }
352
353 #define OFFSET(x) offsetof(XVContext, x)
362
363 };
364
371 };
372
385 .priv_class = &xv_class,
386 };
packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
This structure describes decoded (raw) audio or video data.
static void compute_display_area(AVFormatContext *s)
ptrdiff_t const GLvoid * data
static const AVOption options[]
#define LIBAVUTIL_VERSION_INT
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
int av_image_fill_arrays(uint8_t *dst_data[4], int dst_linesize[4], const uint8_t *src, enum AVPixelFormat pix_fmt, int width, int height, int align)
Setup the data pointers and linesizes based on the specified image parameters and the provided array...
unsigned int dest_h
display area dimensions
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
static int xv_write_header(AVFormatContext *s)
static int xv_repaint(AVFormatContext *s)
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
static int xv_write_frame(AVFormatContext *s, int stream_index, AVFrame **frame, unsigned flags)
XShmSegmentInfo yuv_shminfo
int dest_y
display area position
static int xv_get_tag_from_format(enum AVPixelFormat format)
AVStream ** streams
A list of all streams in the file.
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
#define AV_OPT_FLAG_ENCODING_PARAM
a generic parameter which can be set by the user for muxing or encoding
Main libavdevice API header.
static const AVClass xv_class
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
enum AVPixelFormat image_format
static int xv_write_packet(AVFormatContext *s, AVPacket *pkt)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
void av_image_copy(uint8_t *dst_data[4], int dst_linesizes[4], const uint8_t *src_data[4], const int src_linesizes[4], enum AVPixelFormat pix_fmt, int width, int height)
Copy image in src_data to dst_data.
AVCodecContext * codec
Codec context associated with this stream.
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
char filename[1024]
input or output filename
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
int width
picture width / height.
static int write_trailer(AVFormatContext *s1)
static int xv_write_trailer(AVFormatContext *s)
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
enum AVMediaType codec_type
char * av_strdup(const char *s)
Duplicate the string s.
main external API structure.
static const char * format
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
static const XVTagFormatMap tag_codec_map[]
static const char * window_title
Describe the class of an AVClass context structure.
static int xv_control_message(AVFormatContext *s, int type, void *data, size_t data_size)
rational number numerator/denominator
offset must point to two consecutive integers
AVOutputFormat ff_xv_muxer
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
void * priv_data
Format private data.
static int write_picture(AVFormatContext *s, uint8_t *input_data[4], int linesize[4])
static void write_header(FFV1Context *f)
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.
#define MKTAG(a, b, c, d)
#define AVERROR_EXTERNAL
Generic error in an external library.
AVPixelFormat
Pixel format.
This structure stores compressed data.
static int write_packet(AVFormatContext *s1, AVPacket *pkt)