2 * video output for V4L2 hardware MPEG decoders
4 * Copyright (C) 2007 Benjamin Zores
6 * This file is part of MPlayer.
8 * MPlayer is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * MPlayer 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
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 #include <sys/types.h>
31 #include <sys/ioctl.h>
36 #include <linux/types.h>
37 #include <linux/videodev2.h>
38 #include <linux/ioctl.h>
41 #include "subopt-helper.h"
42 #include "video_out.h"
43 #include "video_out_internal.h"
44 #include "libmpdemux/mpeg_packetizer.h"
47 #define DEFAULT_MPEG_DECODER "/dev/video16"
48 #define V4L2_VO_HDR "VO: [v4l2]"
51 static vo_mpegpes_t
*pes
;
54 static int output
= -1;
55 static char *device
= NULL
;
57 static const opt_t subopts
[] = {
58 {"output", OPT_ARG_INT
, &output
, int_non_neg
},
59 {"device", OPT_ARG_MSTRZ
, &device
, NULL
},
63 static const vo_info_t info
=
65 "V4L2 MPEG Video Decoder Output",
70 const LIBVO_EXTERN (v4l2
)
73 v4l2_write (const unsigned char *data
, int len
)
78 return write (v4l2_fd
, data
, len
);
81 /* video out functions */
84 config (uint32_t width
, uint32_t height
,
85 uint32_t d_width
, uint32_t d_height
,
86 uint32_t fullscreen
, char *title
, uint32_t format
)
92 preinit (const char *arg
)
94 struct v4l2_output vout
;
95 struct v4l2_ext_controls ctrls
;
98 if (subopt_parse (arg
, subopts
) != 0)
100 mp_msg (MSGT_VO
, MSGL_FATAL
,
101 "\n-vo v4l2 command line help:\n"
102 "Example: mplayer -vo v4l2:device=/dev/video16:output=2\n"
104 " device=/dev/videoX\n"
105 " Name of the MPEG decoder device file.\n"
107 " V4L2 id of the TV output.\n"
113 device
= strdup (DEFAULT_MPEG_DECODER
);
115 v4l2_fd
= open (device
, O_RDWR
);
119 mp_msg (MSGT_VO
, MSGL_FATAL
, "%s %s\n", V4L2_VO_HDR
, strerror (errno
));
123 /* check for device hardware MPEG decoding capability */
124 ctrls
.ctrl_class
= V4L2_CTRL_CLASS_MPEG
;
126 ctrls
.controls
= NULL
;
128 if (ioctl (v4l2_fd
, VIDIOC_G_EXT_CTRLS
, &ctrls
) < 0)
131 mp_msg (MSGT_OPEN
, MSGL_FATAL
, "%s %s\n", V4L2_VO_HDR
, strerror (errno
));
135 /* list available outputs */
138 mp_msg (MSGT_VO
, MSGL_INFO
, "%s Available video outputs: ", V4L2_VO_HDR
);
139 while (ioctl (v4l2_fd
, VIDIOC_ENUMOUTPUT
, &vout
) >= 0)
142 mp_msg (MSGT_VO
, MSGL_INFO
, "'#%d, %s' ", vout
.index
, vout
.name
);
147 mp_msg (MSGT_VO
, MSGL_INFO
, "none\n");
152 mp_msg (MSGT_VO
, MSGL_INFO
, "\n");
154 /* set user specified output */
157 if (ioctl (v4l2_fd
, VIDIOC_S_OUTPUT
, &output
) < 0)
159 mp_msg (MSGT_VO
, MSGL_ERR
,
160 "%s can't set output (%s)\n", V4L2_VO_HDR
, strerror (errno
));
166 /* display device name */
167 mp_msg (MSGT_VO
, MSGL_INFO
, "%s using %s\n", V4L2_VO_HDR
, device
);
170 /* display current video output */
171 if (ioctl (v4l2_fd
, VIDIOC_G_OUTPUT
, &output
) == 0)
174 if (ioctl (v4l2_fd
, VIDIOC_ENUMOUTPUT
, &vout
) < 0)
176 mp_msg (MSGT_VO
, MSGL_ERR
,
177 "%s can't get output (%s).\n", V4L2_VO_HDR
, strerror (errno
));
181 mp_msg (MSGT_VO
, MSGL_INFO
,
182 "%s video output: %s\n", V4L2_VO_HDR
, vout
.name
);
186 mp_msg (MSGT_VO
, MSGL_ERR
,
187 "%s can't get output (%s).\n", V4L2_VO_HDR
, strerror (errno
));
201 draw_frame (uint8_t * src
[])
203 pes
= (vo_mpegpes_t
*) src
[0];
216 send_mpeg_pes_packet (pes
->data
, pes
->size
, pes
->id
,
217 pes
->timestamp
? pes
->timestamp
: vo_pts
, 2,
220 /* ensure flip_page() won't be called twice */
225 draw_slice (uint8_t *image
[], int stride
[], int w
, int h
, int x
, int y
)
248 query_format (uint32_t format
)
250 if (format
!= IMGFMT_MPEGPES
)
253 return VFCAP_CSP_SUPPORTED
| VFCAP_CSP_SUPPORTED_BY_HW
| VFCAP_TIMER
;
257 control (uint32_t request
, void *data
)
261 case VOCTRL_QUERY_FORMAT
:
262 return query_format (*((uint32_t*) data
));