annotate libao2/ao_ivtv.c @ 25414:5c03a9bdf220

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