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"
50 #include "libmpdemux/mpeg_packetizer.h"
52 #define DEFAULT_MPEG_DECODER "/dev/video16"
53 #define IVTV_VO_HDR "VO: [ivtv]"
57 static vo_mpegpes_t
*pes
;
60 static int output
= -1;
61 static char *device
= NULL
;
63 static const opt_t subopts
[] = {
64 {"output", OPT_ARG_INT
, &output
, int_non_neg
},
65 {"device", OPT_ARG_MSTRZ
, &device
, NULL
},
69 static const vo_info_t info
=
71 "IVTV MPEG Video Decoder TV-Out",
76 const LIBVO_EXTERN (ivtv
)
81 ivtv_reset (int blank_screen
)
83 struct ivtv_cfg_stop_decode sd
;
84 struct ivtv_cfg_start_decode sd1
;
88 flags
|= IVTV_STOP_FL_HIDE_FRAME
;
91 if (ioctl (ivtv_fd
, IVTV_IOC_STOP_DECODE
, &sd
) < 0)
93 mp_msg (MSGT_VO
, MSGL_ERR
,
94 "IVTV_IOC_STOP_DECODE: %s\n", strerror (errno
));
99 sd1
.muted_audio_frames
= 0;
101 if (ioctl (ivtv_fd
, IVTV_IOC_START_DECODE
, &sd1
) < 0)
103 mp_msg (MSGT_VO
, MSGL_ERR
,
104 "IVTV_IOC_START_DECODE: %s\n", strerror (errno
));
112 ivtv_write (const unsigned char *data
, int len
)
117 return write (ivtv_fd
, data
, len
);
120 /* video out functions */
123 config (uint32_t width
, uint32_t height
,
124 uint32_t d_width
, uint32_t d_height
,
125 uint32_t fullscreen
, char *title
, uint32_t format
)
131 preinit (const char *arg
)
133 struct v4l2_output vout
;
136 if (subopt_parse (arg
, subopts
) != 0)
138 mp_msg (MSGT_VO
, MSGL_FATAL
,
139 "\n-vo ivtv command line help:\n"
140 "Example: mplayer -vo ivtv:device=/dev/video16:output=2\n"
142 " device=/dev/videoX\n"
143 " Name of the MPEG decoder device file.\n"
145 " V4L2 id of the TV output.\n"
151 device
= strdup (DEFAULT_MPEG_DECODER
);
153 ivtv_fd
= open (device
, O_RDWR
);
157 mp_msg (MSGT_VO
, MSGL_FATAL
, "%s %s\n", IVTV_VO_HDR
, strerror (errno
));
161 /* list available outputs */
164 mp_msg (MSGT_VO
, MSGL_INFO
, "%s Available video outputs: ", IVTV_VO_HDR
);
165 while (ioctl (ivtv_fd
, VIDIOC_ENUMOUTPUT
, &vout
) >= 0)
168 mp_msg (MSGT_VO
, MSGL_INFO
, "'#%d, %s' ", vout
.index
, vout
.name
);
173 mp_msg (MSGT_VO
, MSGL_INFO
, "none\n");
178 mp_msg (MSGT_VO
, MSGL_INFO
, "\n");
180 /* set user specified output */
183 if (ioctl (ivtv_fd
, VIDIOC_S_OUTPUT
, &output
) < 0)
185 mp_msg (MSGT_VO
, MSGL_ERR
,
186 "%s can't set output (%s)\n", IVTV_VO_HDR
, strerror (errno
));
192 /* display device name */
193 mp_msg (MSGT_VO
, MSGL_INFO
, "%s using %s\n", IVTV_VO_HDR
, device
);
196 /* display current video output */
197 if (ioctl (ivtv_fd
, VIDIOC_G_OUTPUT
, &output
) == 0)
200 if (ioctl (ivtv_fd
, VIDIOC_ENUMOUTPUT
, &vout
) < 0)
202 mp_msg (MSGT_VO
, MSGL_ERR
,
203 "%s can't get output (%s).\n", IVTV_VO_HDR
, strerror (errno
));
207 mp_msg (MSGT_VO
, MSGL_INFO
,
208 "%s video output: %s\n", IVTV_VO_HDR
, vout
.name
);
212 mp_msg (MSGT_VO
, MSGL_ERR
,
213 "%s can't get output (%s).\n", IVTV_VO_HDR
, strerror (errno
));
230 draw_frame (uint8_t * src
[])
232 pes
= (vo_mpegpes_t
*) src
[0];
245 send_mpeg_pes_packet (pes
->data
, pes
->size
, pes
->id
,
246 pes
->timestamp
? pes
->timestamp
: vo_pts
, 2,
249 /* ensure flip_page() won't be called twice */
254 draw_slice (uint8_t *image
[], int stride
[], int w
, int h
, int x
, int y
)
280 query_format (uint32_t format
)
282 if (format
!= IMGFMT_MPEGPES
)
285 return VFCAP_CSP_SUPPORTED
| VFCAP_CSP_SUPPORTED_BY_HW
| VFCAP_TIMER
;
289 control (uint32_t request
, void *data
)
295 return ivtv_reset (0);
298 return ivtv_reset (1);
300 case VOCTRL_QUERY_FORMAT
:
301 return query_format (*((uint32_t*) data
));