Fix vf_tcdump's compilation
[mplayer/kovensky.git] / libvo / vo_ivtv.c
blobd39edcbcea67a4ba7a3ed38c65fc41d55371c462
1 /*
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.
27 #include "config.h"
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <errno.h>
33 #include <sys/types.h>
34 #include <sys/stat.h>
35 #include <sys/ioctl.h>
36 #include <fcntl.h>
37 #include <unistd.h>
38 #include <stdlib.h>
39 #include <inttypes.h>
40 #include <linux/types.h>
41 #include <linux/videodev2.h>
42 #include <linux/ivtv.h>
43 #include <linux/ioctl.h>
45 #include "mp_msg.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]"
54 /* ivtv private */
55 int ivtv_fd = -1;
56 static vo_mpegpes_t *pes;
58 /* suboptions */
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},
65 {NULL}
68 static const vo_info_t info =
70 "IVTV MPEG Video Decoder TV-Out",
71 "ivtv",
72 "Benjamin Zores",
75 const LIBVO_EXTERN (ivtv)
77 /* ivtv internals */
79 static uint32_t
80 ivtv_reset (int blank_screen)
82 struct ivtv_cfg_stop_decode sd;
83 struct ivtv_cfg_start_decode sd1;
84 int flags = 0;
86 if (blank_screen)
87 flags |= IVTV_STOP_FL_HIDE_FRAME;
88 sd.flags = flags;
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));
94 return 1;
97 sd1.gop_offset = 0;
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));
104 return 1;
107 return 0;
111 ivtv_write (const unsigned char *data, int len)
113 if (ivtv_fd < 0)
114 return 0;
116 return write (ivtv_fd, data, len);
119 /* video out functions */
121 static int
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)
126 return 0;
129 static int
130 preinit (const char *arg)
132 struct v4l2_output vout;
133 int err;
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"
140 "\nOptions:\n"
141 " device=/dev/videoX\n"
142 " Name of the MPEG decoder device file.\n"
143 " output=<0-...>\n"
144 " V4L2 id of the TV output.\n"
145 "\n" );
146 return -1;
149 if (!device)
150 device = strdup (DEFAULT_MPEG_DECODER);
152 ivtv_fd = open (device, O_RDWR);
153 if (ivtv_fd < 0)
155 free (device);
156 mp_msg (MSGT_VO, MSGL_FATAL, "%s %s\n", IVTV_VO_HDR, strerror (errno));
157 return -1;
160 /* list available outputs */
161 vout.index = 0;
162 err = 1;
163 mp_msg (MSGT_VO, MSGL_INFO, "%s Available video outputs: ", IVTV_VO_HDR);
164 while (ioctl (ivtv_fd, VIDIOC_ENUMOUTPUT, &vout) >= 0)
166 err = 0;
167 mp_msg (MSGT_VO, MSGL_INFO, "'#%d, %s' ", vout.index, vout.name);
168 vout.index++;
170 if (err)
172 mp_msg (MSGT_VO, MSGL_INFO, "none\n");
173 free (device);
174 return -1;
176 else
177 mp_msg (MSGT_VO, MSGL_INFO, "\n");
179 /* set user specified output */
180 if (output != -1)
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));
186 free (device);
187 return -1;
191 /* display device name */
192 mp_msg (MSGT_VO, MSGL_INFO, "%s using %s\n", IVTV_VO_HDR, device);
193 free (device);
195 /* display current video output */
196 if (ioctl (ivtv_fd, VIDIOC_G_OUTPUT, &output) == 0)
198 vout.index = output;
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));
203 return -1;
205 else
206 mp_msg (MSGT_VO, MSGL_INFO,
207 "%s video output: %s\n", IVTV_VO_HDR, vout.name);
209 else
211 mp_msg (MSGT_VO, MSGL_ERR,
212 "%s can't get output (%s).\n", IVTV_VO_HDR, strerror (errno));
213 return -1;
216 /* clear output */
217 ivtv_reset (1);
219 return 0;
222 static void
223 draw_osd (void)
225 /* do nothing */
228 static int
229 draw_frame (uint8_t * src[])
231 pes = (vo_mpegpes_t *) src[0];
232 return 0;
235 static void
236 flip_page (void)
238 if (ivtv_fd < 0)
239 return;
241 if (!pes)
242 return;
244 send_mpeg_pes_packet (pes->data, pes->size, pes->id,
245 pes->timestamp ? pes->timestamp : vo_pts, 2,
246 ivtv_write);
248 /* ensure flip_page() won't be called twice */
249 pes = NULL;
252 static int
253 draw_slice (uint8_t *image[], int stride[], int w, int h, int x, int y)
255 return 0;
258 static void
259 uninit (void)
261 if (ivtv_fd < 0)
262 return;
264 /* clear output */
265 ivtv_reset (1);
267 /* close device */
268 close (ivtv_fd);
269 ivtv_fd = -1;
272 static void
273 check_events (void)
275 /* do nothing */
278 static int
279 query_format (uint32_t format)
281 if (format != IMGFMT_MPEGPES)
282 return 0;
284 return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_TIMER;
287 static int
288 control (uint32_t request, void *data)
290 switch (request)
292 case VOCTRL_PAUSE:
293 case VOCTRL_RESUME:
294 return ivtv_reset (0);
296 case VOCTRL_RESET:
297 return ivtv_reset (1);
299 case VOCTRL_QUERY_FORMAT:
300 return query_format (*((uint32_t*) data));
303 return VO_NOTIMPL;