Fix vf_tcdump's compilation
[mplayer/kovensky.git] / libao2 / ao_ivtv.c
blob1fe1b1edda3c9bafe6d137354427cd673730e660
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"
34 #include "audio_out.h"
35 #include "audio_out_internal.h"
36 #include "libaf/af_format.h"
37 #include "libmpdemux/mpeg_packetizer.h"
39 #define MPEG_AUDIO_ID 0x1C0
41 static int freq = 0;
43 static const ao_info_t info =
45 "IVTV MPEG Audio Decoder output",
46 "ivtv",
47 "Benjamin Zores",
51 LIBAO_EXTERN(ivtv)
53 /* to set/get/query special features/parameters */
54 static int
55 control (int cmd,void *arg)
57 return CONTROL_UNKNOWN;
60 /* open & setup audio device */
61 static int
62 init (int rate, int channels, int format, int flags)
64 extern int ivtv_fd;
66 if (ivtv_fd < 0)
67 return 0;
69 if (format != AF_FORMAT_MPEG2)
71 mp_msg (MSGT_AO, MSGL_FATAL,
72 "AO: [ivtv] can only handle MPEG audio streams.\n");
73 return 0;
76 ao_data.outburst = 2048;
77 ao_data.samplerate = rate;
78 ao_data.channels = channels;
79 ao_data.format = AF_FORMAT_MPEG2;
80 ao_data.buffersize = 2048;
81 ao_data.bps = rate * 2 * 2;
82 ao_data.pts = 0;
83 freq = rate;
85 /* check for supported audio rate */
86 if (rate != 32000 || rate != 41000 || rate != 48000)
88 mp_tmsg (MSGT_AO, MSGL_ERR, "[AO MPEGPES] %d Hz not supported, try to resample.\n", rate);
89 rate = 48000;
92 return 1;
95 /* close audio device */
96 static void
97 uninit (int immed)
99 /* nothing to do */
102 /* stop playing and empty buffers (for seeking/pause) */
103 static void
104 reset (void)
106 /* nothing to do */
109 /* stop playing, keep buffers (for pause) */
110 static void
111 audio_pause (void)
113 reset ();
116 /* resume playing, after audio_pause() */
117 static void
118 audio_resume (void)
120 /* nothing to do */
123 /* how many bytes can be played without blocking */
124 static int
125 get_space (void)
127 extern int vo_pts;
128 float x;
129 int y;
131 x = (float) (vo_pts - ao_data.pts) / 90000.0;
132 if (x <= 0)
133 return 0;
135 y = freq * 4 * x;
136 y /= ao_data.outburst;
137 y *= ao_data.outburst;
139 if (y > 32000)
140 y = 32000;
142 return y;
145 /* number of bytes played */
146 static int
147 play (void *data, int len, int flags)
149 int ivtv_write (const unsigned char *data, int len);
151 if (ao_data.format != AF_FORMAT_MPEG2)
152 return 0;
154 send_mpeg_pes_packet (data, len, MPEG_AUDIO_ID, ao_data.pts, 2, ivtv_write);
156 return len;
159 /* delay in seconds between first and last sample in buffer */
160 static float
161 get_delay (void)
163 return 0.0;