Mercurial > mplayer.hg
comparison libao2/ao_v4l2.c @ 23905:fb63124c7920
v4l2 audio/video outputs for linux 2.6.22+ kernels (outputs formerly known as ivtv)
author | ben |
---|---|
date | Sun, 29 Jul 2007 19:20:55 +0000 |
parents | |
children | 0f42fb42843c |
comparison
equal
deleted
inserted
replaced
23904:545aef4edc84 | 23905:fb63124c7920 |
---|---|
1 /* | |
2 * Copyright (C) 2007 Benjamin Zores | |
3 * Audio output for V4L2 hardware MPEG decoders. | |
4 * | |
5 * This program is free software; you can redistribute it and/or modify | |
6 * it under the terms of the GNU General Public License as published by | |
7 * the Free Software Foundation; either version 2 of the License, or | |
8 * (at your option) any later version. | |
9 * | |
10 * This program is distributed in the hope that it will be useful, | |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 * GNU General Public License for more details. | |
14 * | |
15 * You should have received a copy of the GNU General Public License | |
16 * along with this program; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
18 * | |
19 * WARNING: you need to force -ac hwmpa for audio output to work. | |
20 */ | |
21 | |
22 #include <inttypes.h> | |
23 | |
24 #include "config.h" | |
25 | |
26 #include "mp_msg.h" | |
27 #include "help_mp.h" | |
28 | |
29 #include "audio_out.h" | |
30 #include "audio_out_internal.h" | |
31 #include "libaf/af_format.h" | |
32 #include "libmpdemux/mpeg_packetizer.h" | |
33 | |
34 #define MPEG_AUDIO_ID 0x1C0 | |
35 | |
36 static int freq = 0; | |
37 | |
38 static ao_info_t info = | |
39 { | |
40 "V4L2 MPEG Audio Decoder output", | |
41 "v4l2", | |
42 "Benjamin Zores", | |
43 "" | |
44 }; | |
45 | |
46 LIBAO_EXTERN (v4l2) | |
47 | |
48 /* to set/get/query special features/parameters */ | |
49 static int | |
50 control (int cmd,void *arg) | |
51 { | |
52 return CONTROL_UNKNOWN; | |
53 } | |
54 | |
55 /* open & setup audio device */ | |
56 static int | |
57 init (int rate, int channels, int format, int flags) | |
58 { | |
59 extern int v4l2_fd; | |
60 | |
61 if (v4l2_fd < 0) | |
62 return 0; | |
63 | |
64 if (format != AF_FORMAT_MPEG2) | |
65 { | |
66 mp_msg (MSGT_AO, MSGL_FATAL, | |
67 "AO: [v4l2] can only handle MPEG audio streams.\n"); | |
68 return 0; | |
69 } | |
70 | |
71 ao_data.outburst = 2048; | |
72 ao_data.samplerate = rate; | |
73 ao_data.channels = channels; | |
74 ao_data.format = AF_FORMAT_MPEG2; | |
75 ao_data.buffersize = 2048; | |
76 ao_data.bps = rate * 2 * 2; | |
77 ao_data.pts = 0; | |
78 freq = rate; | |
79 | |
80 /* check for supported audio rate */ | |
81 if (rate != 32000 || rate != 41000 || rate != 48000) | |
82 { | |
83 mp_msg (MSGT_AO, MSGL_ERR, MSGTR_AO_MPEGPES_UnsupSamplerate, rate); | |
84 rate = 48000; | |
85 } | |
86 | |
87 return 1; | |
88 } | |
89 | |
90 /* close audio device */ | |
91 static void | |
92 uninit (int immed) | |
93 { | |
94 /* nothing to do */ | |
95 } | |
96 | |
97 /* stop playing and empty buffers (for seeking/pause) */ | |
98 static void | |
99 reset (void) | |
100 { | |
101 /* nothing to do */ | |
102 } | |
103 | |
104 /* stop playing, keep buffers (for pause) */ | |
105 static void | |
106 audio_pause (void) | |
107 { | |
108 reset (); | |
109 } | |
110 | |
111 /* resume playing, after audio_pause() */ | |
112 static void | |
113 audio_resume (void) | |
114 { | |
115 /* nothing to do */ | |
116 } | |
117 | |
118 /* how many bytes can be played without blocking */ | |
119 static int | |
120 get_space (void) | |
121 { | |
122 extern int vo_pts; | |
123 float x; | |
124 int y; | |
125 | |
126 x = (float) (vo_pts - ao_data.pts) / 90000.0; | |
127 if (x <= 0) | |
128 return 0; | |
129 | |
130 y = freq * 4 * x; | |
131 y /= ao_data.outburst; | |
132 y *= ao_data.outburst; | |
133 | |
134 if (y > 32000) | |
135 y = 32000; | |
136 | |
137 return y; | |
138 } | |
139 | |
140 /* number of bytes played */ | |
141 static int | |
142 play (void *data, int len, int flags) | |
143 { | |
144 extern int v4l2_write (unsigned char *data, int len); | |
145 | |
146 if (ao_data.format != AF_FORMAT_MPEG2) | |
147 return 0; | |
148 | |
149 send_mpeg_pes_packet (data, len, MPEG_AUDIO_ID, ao_data.pts, 2, v4l2_write); | |
150 | |
151 return len; | |
152 } | |
153 | |
154 /* delay in seconds between first and last sample in buffer */ | |
155 static float | |
156 get_delay (void) | |
157 { | |
158 return 0.0; | |
159 } |