x11_common: always free x11 context struct on exit
[mplayer/glamo.git] / libao2 / ao_ivtv.c
blob6b6bb8816c677e0fcd9df2e9d439633c7ef20c0b
1 /*
2 * audio output for WinTV PVR-150/250/350 (a.k.a IVTV) cards
3 * through Connexant hardware MPEG decoder
4 * See http://ivtvdriver.org/index.php/Main_Page for more details on the
5 * cards supported by the ivtv driver.
7 * WARNING: You need to force -ac hwmpa for audio output to work.
9 * Copyright (C) 2006 Benjamin Zores
11 * This file is part of MPlayer.
13 * MPlayer is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * MPlayer is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License along
24 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 #include <inttypes.h>
30 #include "config.h"
32 #include "mp_msg.h"
33 #include "help_mp.h"
35 #include "audio_out.h"
36 #include "audio_out_internal.h"
37 #include "libaf/af_format.h"
38 #include "libmpdemux/mpeg_packetizer.h"
40 #define MPEG_AUDIO_ID 0x1C0
42 static int freq = 0;
44 static const ao_info_t info =
46 "IVTV MPEG Audio Decoder output",
47 "ivtv",
48 "Benjamin Zores",
52 LIBAO_EXTERN(ivtv)
54 /* to set/get/query special features/parameters */
55 static int
56 control (int cmd,void *arg)
58 return CONTROL_UNKNOWN;
61 /* open & setup audio device */
62 static int
63 init (int rate, int channels, int format, int flags)
65 extern int ivtv_fd;
67 if (ivtv_fd < 0)
68 return 0;
70 if (format != AF_FORMAT_MPEG2)
72 mp_msg (MSGT_AO, MSGL_FATAL,
73 "AO: [ivtv] can only handle MPEG audio streams.\n");
74 return 0;
77 ao_data.outburst = 2048;
78 ao_data.samplerate = rate;
79 ao_data.channels = channels;
80 ao_data.format = AF_FORMAT_MPEG2;
81 ao_data.buffersize = 2048;
82 ao_data.bps = rate * 2 * 2;
83 ao_data.pts = 0;
84 freq = rate;
86 /* check for supported audio rate */
87 if (rate != 32000 || rate != 41000 || rate != 48000)
89 mp_tmsg (MSGT_AO, MSGL_ERR, "[AO MPEGPES] %d Hz not supported, try to resample.\n", rate);
90 rate = 48000;
93 return 1;
96 /* close audio device */
97 static void
98 uninit (int immed)
100 /* nothing to do */
103 /* stop playing and empty buffers (for seeking/pause) */
104 static void
105 reset (void)
107 /* nothing to do */
110 /* stop playing, keep buffers (for pause) */
111 static void
112 audio_pause (void)
114 reset ();
117 /* resume playing, after audio_pause() */
118 static void
119 audio_resume (void)
121 /* nothing to do */
124 /* how many bytes can be played without blocking */
125 static int
126 get_space (void)
128 extern int vo_pts;
129 float x;
130 int y;
132 x = (float) (vo_pts - ao_data.pts) / 90000.0;
133 if (x <= 0)
134 return 0;
136 y = freq * 4 * x;
137 y /= ao_data.outburst;
138 y *= ao_data.outburst;
140 if (y > 32000)
141 y = 32000;
143 return y;
146 /* number of bytes played */
147 static int
148 play (void *data, int len, int flags)
150 int ivtv_write (const unsigned char *data, int len);
152 if (ao_data.format != AF_FORMAT_MPEG2)
153 return 0;
155 send_mpeg_pes_packet (data, len, MPEG_AUDIO_ID, ao_data.pts, 2, ivtv_write);
157 return len;
160 /* delay in seconds between first and last sample in buffer */
161 static float
162 get_delay (void)
164 return 0.0;