codecs.conf, mp_taglists: Support FFmpeg LATM decoding
[mplayer/greg.git] / libvo / vo_ivtv.c
blobd74570115958e38e0747989021788f81f9b1fef2
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 "vo_ivtv.h"
50 #include "libmpdemux/mpeg_packetizer.h"
52 #define DEFAULT_MPEG_DECODER "/dev/video16"
53 #define IVTV_VO_HDR "VO: [ivtv]"
55 /* ivtv private */
56 int ivtv_fd = -1;
57 static vo_mpegpes_t *pes;
59 /* suboptions */
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},
66 {NULL}
69 static const vo_info_t info =
71 "IVTV MPEG Video Decoder TV-Out",
72 "ivtv",
73 "Benjamin Zores",
76 const LIBVO_EXTERN (ivtv)
78 /* ivtv internals */
80 static uint32_t
81 ivtv_reset (int blank_screen)
83 struct ivtv_cfg_stop_decode sd;
84 struct ivtv_cfg_start_decode sd1;
85 int flags = 0;
87 if (blank_screen)
88 flags |= IVTV_STOP_FL_HIDE_FRAME;
89 sd.flags = flags;
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));
95 return 1;
98 sd1.gop_offset = 0;
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));
105 return 1;
108 return 0;
112 ivtv_write (const unsigned char *data, int len)
114 if (ivtv_fd < 0)
115 return 0;
117 return write (ivtv_fd, data, len);
120 /* video out functions */
122 static int
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)
127 return 0;
130 static int
131 preinit (const char *arg)
133 struct v4l2_output vout;
134 int err;
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"
141 "\nOptions:\n"
142 " device=/dev/videoX\n"
143 " Name of the MPEG decoder device file.\n"
144 " output=<0-...>\n"
145 " V4L2 id of the TV output.\n"
146 "\n" );
147 return -1;
150 if (!device)
151 device = strdup (DEFAULT_MPEG_DECODER);
153 ivtv_fd = open (device, O_RDWR);
154 if (ivtv_fd < 0)
156 free (device);
157 mp_msg (MSGT_VO, MSGL_FATAL, "%s %s\n", IVTV_VO_HDR, strerror (errno));
158 return -1;
161 /* list available outputs */
162 vout.index = 0;
163 err = 1;
164 mp_msg (MSGT_VO, MSGL_INFO, "%s Available video outputs: ", IVTV_VO_HDR);
165 while (ioctl (ivtv_fd, VIDIOC_ENUMOUTPUT, &vout) >= 0)
167 err = 0;
168 mp_msg (MSGT_VO, MSGL_INFO, "'#%d, %s' ", vout.index, vout.name);
169 vout.index++;
171 if (err)
173 mp_msg (MSGT_VO, MSGL_INFO, "none\n");
174 free (device);
175 return -1;
177 else
178 mp_msg (MSGT_VO, MSGL_INFO, "\n");
180 /* set user specified output */
181 if (output != -1)
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));
187 free (device);
188 return -1;
192 /* display device name */
193 mp_msg (MSGT_VO, MSGL_INFO, "%s using %s\n", IVTV_VO_HDR, device);
194 free (device);
196 /* display current video output */
197 if (ioctl (ivtv_fd, VIDIOC_G_OUTPUT, &output) == 0)
199 vout.index = output;
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));
204 return -1;
206 else
207 mp_msg (MSGT_VO, MSGL_INFO,
208 "%s video output: %s\n", IVTV_VO_HDR, vout.name);
210 else
212 mp_msg (MSGT_VO, MSGL_ERR,
213 "%s can't get output (%s).\n", IVTV_VO_HDR, strerror (errno));
214 return -1;
217 /* clear output */
218 ivtv_reset (1);
220 return 0;
223 static void
224 draw_osd (void)
226 /* do nothing */
229 static int
230 draw_frame (uint8_t * src[])
232 pes = (vo_mpegpes_t *) src[0];
233 return 0;
236 static void
237 flip_page (void)
239 if (ivtv_fd < 0)
240 return;
242 if (!pes)
243 return;
245 send_mpeg_pes_packet (pes->data, pes->size, pes->id,
246 pes->timestamp ? pes->timestamp : vo_pts, 2,
247 ivtv_write);
249 /* ensure flip_page() won't be called twice */
250 pes = NULL;
253 static int
254 draw_slice (uint8_t *image[], int stride[], int w, int h, int x, int y)
256 return 0;
259 static void
260 uninit (void)
262 if (ivtv_fd < 0)
263 return;
265 /* clear output */
266 ivtv_reset (1);
268 /* close device */
269 close (ivtv_fd);
270 ivtv_fd = -1;
273 static void
274 check_events (void)
276 /* do nothing */
279 static int
280 query_format (uint32_t format)
282 if (format != IMGFMT_MPEGPES)
283 return 0;
285 return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_TIMER;
288 static int
289 control (uint32_t request, void *data)
291 switch (request)
293 case VOCTRL_PAUSE:
294 case VOCTRL_RESUME:
295 return ivtv_reset (0);
297 case VOCTRL_RESET:
298 return ivtv_reset (1);
300 case VOCTRL_QUERY_FORMAT:
301 return query_format (*((uint32_t*) data));
304 return VO_NOTIMPL;