2 * Copyright (C) 2006 Benjamin Zores
3 * Video output for WinTV PVR-150/250/350 (a.k.a IVTV) cards.
4 * TV-Out through hardware MPEG decoder.
5 * Based on some old code from ivtv driver authors.
6 * See http://ivtvdriver.org/index.php/Main_Page for more details on the
7 * cards supported by the ivtv driver.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
30 #include <sys/types.h>
32 #include <sys/ioctl.h>
37 #include <linux/types.h>
38 #include <linux/videodev2.h>
39 #include <linux/ivtv.h>
40 #include <linux/ioctl.h>
43 #include "subopt-helper.h"
44 #include "video_out.h"
45 #include "video_out_internal.h"
46 #include "libmpdemux/mpeg_packetizer.h"
48 #define DEFAULT_MPEG_DECODER "/dev/video16"
49 #define IVTV_VO_HDR "VO: [ivtv]"
53 static vo_mpegpes_t
*pes
;
56 static int output
= -1;
57 static char *device
= NULL
;
59 static opt_t subopts
[] = {
60 {"output", OPT_ARG_INT
, &output
, (opt_test_f
)int_non_neg
},
61 {"device", OPT_ARG_MSTRZ
, &device
, NULL
},
65 static const vo_info_t info
=
67 "IVTV MPEG Video Decoder TV-Out",
72 const LIBVO_EXTERN (ivtv
)
77 ivtv_reset (int blank_screen
)
79 struct ivtv_cfg_stop_decode sd
;
80 struct ivtv_cfg_start_decode sd1
;
84 flags
|= IVTV_STOP_FL_HIDE_FRAME
;
87 if (ioctl (ivtv_fd
, IVTV_IOC_STOP_DECODE
, &sd
) < 0)
89 mp_msg (MSGT_VO
, MSGL_ERR
,
90 "IVTV_IOC_STOP_DECODE: %s\n", strerror (errno
));
95 sd1
.muted_audio_frames
= 0;
97 if (ioctl (ivtv_fd
, IVTV_IOC_START_DECODE
, &sd1
) < 0)
99 mp_msg (MSGT_VO
, MSGL_ERR
,
100 "IVTV_IOC_START_DECODE: %s\n", strerror (errno
));
108 ivtv_write (unsigned char *data
, int len
)
113 return write (ivtv_fd
, data
, len
);
116 /* video out functions */
119 config (uint32_t width
, uint32_t height
,
120 uint32_t d_width
, uint32_t d_height
,
121 uint32_t fullscreen
, char *title
, uint32_t format
)
127 preinit (const char *arg
)
129 struct v4l2_output vout
;
132 if (subopt_parse (arg
, subopts
) != 0)
134 mp_msg (MSGT_VO
, MSGL_FATAL
,
135 "\n-vo ivtv command line help:\n"
136 "Example: mplayer -vo ivtv:device=/dev/video16:output=2\n"
138 " device=/dev/videoX\n"
139 " Name of the MPEG decoder device file.\n"
141 " V4L2 id of the TV output.\n"
147 device
= strdup (DEFAULT_MPEG_DECODER
);
149 ivtv_fd
= open (device
, O_RDWR
);
153 mp_msg (MSGT_VO
, MSGL_FATAL
, "%s %s\n", IVTV_VO_HDR
, strerror (errno
));
157 /* list available outputs */
160 mp_msg (MSGT_VO
, MSGL_INFO
, "%s Available video outputs: ", IVTV_VO_HDR
);
161 while (ioctl (ivtv_fd
, VIDIOC_ENUMOUTPUT
, &vout
) >= 0)
164 mp_msg (MSGT_VO
, MSGL_INFO
, "'#%d, %s' ", vout
.index
, vout
.name
);
169 mp_msg (MSGT_VO
, MSGL_INFO
, "none\n");
174 mp_msg (MSGT_VO
, MSGL_INFO
, "\n");
176 /* set user specified output */
179 if (ioctl (ivtv_fd
, VIDIOC_S_OUTPUT
, &output
) < 0)
181 mp_msg (MSGT_VO
, MSGL_ERR
,
182 "%s can't set output (%s)\n", IVTV_VO_HDR
, strerror (errno
));
188 /* display device name */
189 mp_msg (MSGT_VO
, MSGL_INFO
, "%s using %s\n", IVTV_VO_HDR
, device
);
192 /* display current video output */
193 if (ioctl (ivtv_fd
, VIDIOC_G_OUTPUT
, &output
) == 0)
196 if (ioctl (ivtv_fd
, VIDIOC_ENUMOUTPUT
, &vout
) < 0)
198 mp_msg (MSGT_VO
, MSGL_ERR
,
199 "%s can't get output (%s).\n", IVTV_VO_HDR
, strerror (errno
));
203 mp_msg (MSGT_VO
, MSGL_INFO
,
204 "%s video output: %s\n", IVTV_VO_HDR
, vout
.name
);
208 mp_msg (MSGT_VO
, MSGL_ERR
,
209 "%s can't get output (%s).\n", IVTV_VO_HDR
, strerror (errno
));
226 draw_frame (uint8_t * src
[])
228 pes
= (vo_mpegpes_t
*) src
[0];
241 send_mpeg_pes_packet (pes
->data
, pes
->size
, pes
->id
,
242 pes
->timestamp
? pes
->timestamp
: vo_pts
, 2,
245 /* ensure flip_page() won't be called twice */
250 draw_slice (uint8_t *image
[], int stride
[], int w
, int h
, int x
, int y
)
276 query_format (uint32_t format
)
278 if (format
!= IMGFMT_MPEGPES
)
281 return VFCAP_CSP_SUPPORTED
| VFCAP_CSP_SUPPORTED_BY_HW
| VFCAP_TIMER
;
285 control (uint32_t request
, void *data
, ...)
291 return ivtv_reset (0);
294 return ivtv_reset (1);
296 case VOCTRL_QUERY_FORMAT
:
297 return query_format (*((uint32_t*) data
));