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"
46 #define DEFAULT_MPEG_DECODER "/dev/video16"
47 #define V4L2_VO_HDR "VO: [v4l2]"
50 static vo_mpegpes_t
*pes
;
53 static int output
= -1;
54 static char *device
= NULL
;
56 static opt_t subopts
[] = {
57 {"output", OPT_ARG_INT
, &output
, (opt_test_f
)int_non_neg
},
58 {"device", OPT_ARG_MSTRZ
, &device
, NULL
},
62 static const vo_info_t info
=
64 "V4L2 MPEG Video Decoder Output",
69 const LIBVO_EXTERN (v4l2
)
72 v4l2_write (unsigned char *data
, int len
)
77 return write (v4l2_fd
, data
, len
);
80 /* video out functions */
83 config (uint32_t width
, uint32_t height
,
84 uint32_t d_width
, uint32_t d_height
,
85 uint32_t fullscreen
, char *title
, uint32_t format
)
91 preinit (const char *arg
)
93 struct v4l2_output vout
;
94 struct v4l2_ext_controls ctrls
;
97 if (subopt_parse (arg
, subopts
) != 0)
99 mp_msg (MSGT_VO
, MSGL_FATAL
,
100 "\n-vo v4l2 command line help:\n"
101 "Example: mplayer -vo v4l2:device=/dev/video16:output=2\n"
103 " device=/dev/videoX\n"
104 " Name of the MPEG decoder device file.\n"
106 " V4L2 id of the TV output.\n"
112 device
= strdup (DEFAULT_MPEG_DECODER
);
114 v4l2_fd
= open (device
, O_RDWR
);
118 mp_msg (MSGT_VO
, MSGL_FATAL
, "%s %s\n", V4L2_VO_HDR
, strerror (errno
));
122 /* check for device hardware MPEG decoding capability */
123 ctrls
.ctrl_class
= V4L2_CTRL_CLASS_MPEG
;
125 ctrls
.controls
= NULL
;
127 if (ioctl (v4l2_fd
, VIDIOC_G_EXT_CTRLS
, &ctrls
) < 0)
130 mp_msg (MSGT_OPEN
, MSGL_FATAL
, "%s %s\n", V4L2_VO_HDR
, strerror (errno
));
134 /* list available outputs */
137 mp_msg (MSGT_VO
, MSGL_INFO
, "%s Available video outputs: ", V4L2_VO_HDR
);
138 while (ioctl (v4l2_fd
, VIDIOC_ENUMOUTPUT
, &vout
) >= 0)
141 mp_msg (MSGT_VO
, MSGL_INFO
, "'#%d, %s' ", vout
.index
, vout
.name
);
146 mp_msg (MSGT_VO
, MSGL_INFO
, "none\n");
151 mp_msg (MSGT_VO
, MSGL_INFO
, "\n");
153 /* set user specified output */
156 if (ioctl (v4l2_fd
, VIDIOC_S_OUTPUT
, &output
) < 0)
158 mp_msg (MSGT_VO
, MSGL_ERR
,
159 "%s can't set output (%s)\n", V4L2_VO_HDR
, strerror (errno
));
165 /* display device name */
166 mp_msg (MSGT_VO
, MSGL_INFO
, "%s using %s\n", V4L2_VO_HDR
, device
);
169 /* display current video output */
170 if (ioctl (v4l2_fd
, VIDIOC_G_OUTPUT
, &output
) == 0)
173 if (ioctl (v4l2_fd
, VIDIOC_ENUMOUTPUT
, &vout
) < 0)
175 mp_msg (MSGT_VO
, MSGL_ERR
,
176 "%s can't get output (%s).\n", V4L2_VO_HDR
, strerror (errno
));
180 mp_msg (MSGT_VO
, MSGL_INFO
,
181 "%s video output: %s\n", V4L2_VO_HDR
, vout
.name
);
185 mp_msg (MSGT_VO
, MSGL_ERR
,
186 "%s can't get output (%s).\n", V4L2_VO_HDR
, strerror (errno
));
200 draw_frame (uint8_t * src
[])
202 pes
= (vo_mpegpes_t
*) src
[0];
215 send_mpeg_pes_packet (pes
->data
, pes
->size
, pes
->id
,
216 pes
->timestamp
? pes
->timestamp
: vo_pts
, 2,
219 /* ensure flip_page() won't be called twice */
224 draw_slice (uint8_t *image
[], int stride
[], int w
, int h
, int x
, int y
)
247 query_format (uint32_t format
)
249 if (format
!= IMGFMT_MPEGPES
)
252 return VFCAP_CSP_SUPPORTED
| VFCAP_CSP_SUPPORTED_BY_HW
| VFCAP_TIMER
;
256 control (uint32_t request
, void *data
)
260 case VOCTRL_QUERY_FORMAT
:
261 return query_format (*((uint32_t*) data
));