annotate libao2/ao_ivtv.c @ 28114:a1451877ff0e

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