annotate libvo/vo_v4l2.c @ 26107:610397af3388

synced with r26138
author Gabrov
date Sat, 01 Mar 2008 12:35:07 +0000
parents c9e9ac2008c2
children 2a34d9fa52ab
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
23905
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
1 /*
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
2 * Copyright (C) 2007 Benjamin Zores
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
3 * Video output for V4L2 hardware MPEG decoders.
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
4 *
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
5 * This program is free software; you can redistribute it and/or modify
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
7 * the Free Software Foundation; either version 2 of the License, or
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
8 * (at your option) any later version.
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
9 *
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
13 * GNU General Public License for more details.
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
14 *
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
16 * along with this program; if not, write to the Free Software Foundation,
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
18 */
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
19
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
20 #include "config.h"
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
21
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
22 #include <stdio.h>
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
23 #include <stdlib.h>
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
24 #include <string.h>
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
25 #include <errno.h>
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
26 #include <sys/types.h>
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
27 #include <sys/stat.h>
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
28 #include <sys/ioctl.h>
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
29 #include <fcntl.h>
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
30 #include <unistd.h>
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
31 #include <stdlib.h>
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
32 #include <inttypes.h>
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
33 #include <linux/types.h>
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
34 #include <linux/videodev2.h>
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
35 #include <linux/ioctl.h>
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
36
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
37 #include "mp_msg.h"
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
38 #include "subopt-helper.h"
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
39 #include "video_out.h"
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
40 #include "video_out_internal.h"
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
41 #include "libmpdemux/mpeg_packetizer.h"
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
42
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
43 #define DEFAULT_MPEG_DECODER "/dev/video16"
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
44 #define V4L2_VO_HDR "VO: [v4l2]"
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
45
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
46 int v4l2_fd = -1;
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
47 static vo_mpegpes_t *pes;
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
48
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
49 /* suboptions */
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
50 static int output = -1;
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
51 static char *device = NULL;
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
52
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
53 static opt_t subopts[] = {
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
54 {"output", OPT_ARG_INT, &output, (opt_test_f)int_non_neg},
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
55 {"device", OPT_ARG_MSTRZ, &device, NULL},
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
56 {NULL}
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
57 };
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
58
25216
3aee342be929 Make vo info structs const
reimar
parents: 23905
diff changeset
59 static const vo_info_t info =
23905
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
60 {
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
61 "V4L2 MPEG Video Decoder Output",
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
62 "v4l2",
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
63 "Benjamin Zores",
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
64 ""
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
65 };
25220
c9e9ac2008c2 Mark the vo_functions_t definitions as const where possible.
reimar
parents: 25216
diff changeset
66 const LIBVO_EXTERN (v4l2)
23905
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
67
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
68 int
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
69 v4l2_write (unsigned char *data, int len)
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
70 {
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
71 if (v4l2_fd < 0)
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
72 return 0;
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
73
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
74 return write (v4l2_fd, data, len);
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
75 }
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
76
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
77 /* video out functions */
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
78
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
79 static int
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
80 config (uint32_t width, uint32_t height,
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
81 uint32_t d_width, uint32_t d_height,
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
82 uint32_t fullscreen, char *title, uint32_t format)
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
83 {
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
84 return 0;
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
85 }
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
86
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
87 static int
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
88 preinit (const char *arg)
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
89 {
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
90 struct v4l2_output vout;
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
91 struct v4l2_ext_controls ctrls;
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
92 int err;
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
93
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
94 if (subopt_parse (arg, subopts) != 0)
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
95 {
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
96 mp_msg (MSGT_VO, MSGL_FATAL,
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
97 "\n-vo v4l2 command line help:\n"
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
98 "Example: mplayer -vo v4l2:device=/dev/video16:output=2\n"
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
99 "\nOptions:\n"
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
100 " device=/dev/videoX\n"
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
101 " Name of the MPEG decoder device file.\n"
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
102 " output=<0-...>\n"
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
103 " V4L2 id of the TV output.\n"
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
104 "\n" );
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
105 return -1;
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
106 }
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
107
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
108 if (!device)
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
109 device = strdup (DEFAULT_MPEG_DECODER);
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
110
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
111 v4l2_fd = open (device, O_RDWR);
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
112 if (v4l2_fd < 0)
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
113 {
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
114 free (device);
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
115 mp_msg (MSGT_VO, MSGL_FATAL, "%s %s\n", V4L2_VO_HDR, strerror (errno));
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
116 return -1;
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
117 }
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
118
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
119 /* check for device hardware MPEG decoding capability */
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
120 ctrls.ctrl_class = V4L2_CTRL_CLASS_MPEG;
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
121 ctrls.count = 0;
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
122 ctrls.controls = NULL;
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
123
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
124 if (ioctl (v4l2_fd, VIDIOC_G_EXT_CTRLS, &ctrls) < 0)
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
125 {
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
126 free (device);
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
127 mp_msg (MSGT_OPEN, MSGL_FATAL, "%s %s\n", V4L2_VO_HDR, strerror (errno));
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
128 return -1;
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
129 }
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
130
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
131 /* list available outputs */
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
132 vout.index = 0;
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
133 err = 1;
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
134 mp_msg (MSGT_VO, MSGL_INFO, "%s Available video outputs: ", V4L2_VO_HDR);
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
135 while (ioctl (v4l2_fd, VIDIOC_ENUMOUTPUT, &vout) >= 0)
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
136 {
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
137 err = 0;
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
138 mp_msg (MSGT_VO, MSGL_INFO, "'#%d, %s' ", vout.index, vout.name);
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
139 vout.index++;
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
140 }
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
141 if (err)
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
142 {
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
143 mp_msg (MSGT_VO, MSGL_INFO, "none\n");
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
144 free (device);
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
145 return -1;
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
146 }
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
147 else
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
148 mp_msg (MSGT_VO, MSGL_INFO, "\n");
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
149
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
150 /* set user specified output */
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
151 if (output != -1)
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
152 {
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
153 if (ioctl (v4l2_fd, VIDIOC_S_OUTPUT, &output) < 0)
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
154 {
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
155 mp_msg (MSGT_VO, MSGL_ERR,
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
156 "%s can't set output (%s)\n", V4L2_VO_HDR, strerror (errno));
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
157 free (device);
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
158 return -1;
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
159 }
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
160 }
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
161
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
162 /* display device name */
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
163 mp_msg (MSGT_VO, MSGL_INFO, "%s using %s\n", V4L2_VO_HDR, device);
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
164 free (device);
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
165
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
166 /* display current video output */
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
167 if (ioctl (v4l2_fd, VIDIOC_G_OUTPUT, &output) == 0)
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
168 {
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
169 vout.index = output;
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
170 if (ioctl (v4l2_fd, VIDIOC_ENUMOUTPUT, &vout) < 0)
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
171 {
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
172 mp_msg (MSGT_VO, MSGL_ERR,
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
173 "%s can't get output (%s).\n", V4L2_VO_HDR, strerror (errno));
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
174 return -1;
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
175 }
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
176 else
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
177 mp_msg (MSGT_VO, MSGL_INFO,
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
178 "%s video output: %s\n", V4L2_VO_HDR, vout.name);
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
179 }
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
180 else
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
181 {
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
182 mp_msg (MSGT_VO, MSGL_ERR,
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
183 "%s can't get output (%s).\n", V4L2_VO_HDR, strerror (errno));
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
184 return -1;
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
185 }
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
186
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
187 return 0;
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
188 }
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
189
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
190 static void
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
191 draw_osd (void)
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
192 {
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
193 /* do nothing */
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
194 }
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
195
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
196 static int
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
197 draw_frame (uint8_t * src[])
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
198 {
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
199 pes = (vo_mpegpes_t *) src[0];
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
200 return 0;
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
201 }
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
202
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
203 static void
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
204 flip_page (void)
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
205 {
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
206 if (v4l2_fd < 0)
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
207 return;
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
208
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
209 if (!pes)
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
210 return;
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
211
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
212 send_mpeg_pes_packet (pes->data, pes->size, pes->id,
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
213 pes->timestamp ? pes->timestamp : vo_pts, 2,
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
214 v4l2_write);
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
215
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
216 /* ensure flip_page() won't be called twice */
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
217 pes = NULL;
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
218 }
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
219
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
220 static int
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
221 draw_slice (uint8_t *image[], int stride[], int w, int h, int x, int y)
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
222 {
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
223 return 0;
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
224 }
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
225
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
226 static void
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
227 uninit (void)
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
228 {
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
229 if (v4l2_fd < 0)
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
230 return;
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
231
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
232 /* close device */
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
233 close (v4l2_fd);
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
234 v4l2_fd = -1;
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
235 }
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
236
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
237 static void
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
238 check_events (void)
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
239 {
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
240 /* do nothing */
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
241 }
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
242
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
243 static int
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
244 query_format (uint32_t format)
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
245 {
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
246 if (format != IMGFMT_MPEGPES)
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
247 return 0;
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
248
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
249 return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_TIMER;
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
250 }
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
251
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
252 static int
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
253 control (uint32_t request, void *data, ...)
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
254 {
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
255 switch (request)
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
256 {
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
257 case VOCTRL_QUERY_FORMAT:
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
258 return query_format (*((uint32_t*) data));
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
259 }
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
260
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
261 return VO_NOTIMPL;
fb63124c7920 v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
ben
parents:
diff changeset
262 }