2 * video output for WinTV PVR-150/250/350 (a.k.a IVTV) cards
3 * TV-Out through hardware MPEG decoder
4 * Based on some old code from ivtv driver authors.
5 * See http://ivtvdriver.org/index.php/Main_Page for more details on the
6 * cards supported by the ivtv driver.
8 * Copyright (C) 2006 Benjamin Zores
10 * This file is part of MPlayer.
12 * MPlayer is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * MPlayer is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License along
23 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
33 #include <sys/types.h>
35 #include <sys/ioctl.h>
40 #include <linux/types.h>
41 #include <linux/videodev2.h>
42 #include <linux/ivtv.h>
43 #include <linux/ioctl.h>
46 #include "subopt-helper.h"
47 #include "video_out.h"
48 #include "video_out_internal.h"
49 #include "libmpdemux/mpeg_packetizer.h"
51 #define DEFAULT_MPEG_DECODER "/dev/video16"
52 #define IVTV_VO_HDR "VO: [ivtv]"
56 static vo_mpegpes_t
*pes
;
59 static int output
= -1;
60 static char *device
= NULL
;
62 static const opt_t subopts
[] = {
63 {"output", OPT_ARG_INT
, &output
, int_non_neg
},
64 {"device", OPT_ARG_MSTRZ
, &device
, NULL
},
68 static const vo_info_t info
=
70 "IVTV MPEG Video Decoder TV-Out",
75 const LIBVO_EXTERN (ivtv
)
80 ivtv_reset (int blank_screen
)
82 struct ivtv_cfg_stop_decode sd
;
83 struct ivtv_cfg_start_decode sd1
;
87 flags
|= IVTV_STOP_FL_HIDE_FRAME
;
90 if (ioctl (ivtv_fd
, IVTV_IOC_STOP_DECODE
, &sd
) < 0)
92 mp_msg (MSGT_VO
, MSGL_ERR
,
93 "IVTV_IOC_STOP_DECODE: %s\n", strerror (errno
));
98 sd1
.muted_audio_frames
= 0;
100 if (ioctl (ivtv_fd
, IVTV_IOC_START_DECODE
, &sd1
) < 0)
102 mp_msg (MSGT_VO
, MSGL_ERR
,
103 "IVTV_IOC_START_DECODE: %s\n", strerror (errno
));
111 ivtv_write (const unsigned char *data
, int len
)
116 return write (ivtv_fd
, data
, len
);
119 /* video out functions */
122 config (uint32_t width
, uint32_t height
,
123 uint32_t d_width
, uint32_t d_height
,
124 uint32_t fullscreen
, char *title
, uint32_t format
)
130 preinit (const char *arg
)
132 struct v4l2_output vout
;
135 if (subopt_parse (arg
, subopts
) != 0)
137 mp_msg (MSGT_VO
, MSGL_FATAL
,
138 "\n-vo ivtv command line help:\n"
139 "Example: mplayer -vo ivtv:device=/dev/video16:output=2\n"
141 " device=/dev/videoX\n"
142 " Name of the MPEG decoder device file.\n"
144 " V4L2 id of the TV output.\n"
150 device
= strdup (DEFAULT_MPEG_DECODER
);
152 ivtv_fd
= open (device
, O_RDWR
);
156 mp_msg (MSGT_VO
, MSGL_FATAL
, "%s %s\n", IVTV_VO_HDR
, strerror (errno
));
160 /* list available outputs */
163 mp_msg (MSGT_VO
, MSGL_INFO
, "%s Available video outputs: ", IVTV_VO_HDR
);
164 while (ioctl (ivtv_fd
, VIDIOC_ENUMOUTPUT
, &vout
) >= 0)
167 mp_msg (MSGT_VO
, MSGL_INFO
, "'#%d, %s' ", vout
.index
, vout
.name
);
172 mp_msg (MSGT_VO
, MSGL_INFO
, "none\n");
177 mp_msg (MSGT_VO
, MSGL_INFO
, "\n");
179 /* set user specified output */
182 if (ioctl (ivtv_fd
, VIDIOC_S_OUTPUT
, &output
) < 0)
184 mp_msg (MSGT_VO
, MSGL_ERR
,
185 "%s can't set output (%s)\n", IVTV_VO_HDR
, strerror (errno
));
191 /* display device name */
192 mp_msg (MSGT_VO
, MSGL_INFO
, "%s using %s\n", IVTV_VO_HDR
, device
);
195 /* display current video output */
196 if (ioctl (ivtv_fd
, VIDIOC_G_OUTPUT
, &output
) == 0)
199 if (ioctl (ivtv_fd
, VIDIOC_ENUMOUTPUT
, &vout
) < 0)
201 mp_msg (MSGT_VO
, MSGL_ERR
,
202 "%s can't get output (%s).\n", IVTV_VO_HDR
, strerror (errno
));
206 mp_msg (MSGT_VO
, MSGL_INFO
,
207 "%s video output: %s\n", IVTV_VO_HDR
, vout
.name
);
211 mp_msg (MSGT_VO
, MSGL_ERR
,
212 "%s can't get output (%s).\n", IVTV_VO_HDR
, strerror (errno
));
229 draw_frame (uint8_t * src
[])
231 pes
= (vo_mpegpes_t
*) src
[0];
244 send_mpeg_pes_packet (pes
->data
, pes
->size
, pes
->id
,
245 pes
->timestamp
? pes
->timestamp
: vo_pts
, 2,
248 /* ensure flip_page() won't be called twice */
253 draw_slice (uint8_t *image
[], int stride
[], int w
, int h
, int x
, int y
)
279 query_format (uint32_t format
)
281 if (format
!= IMGFMT_MPEGPES
)
284 return VFCAP_CSP_SUPPORTED
| VFCAP_CSP_SUPPORTED_BY_HW
| VFCAP_TIMER
;
288 control (uint32_t request
, void *data
)
294 return ivtv_reset (0);
297 return ivtv_reset (1);
299 case VOCTRL_QUERY_FORMAT
:
300 return query_format (*((uint32_t*) data
));