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