Raise LIBASS_VERSION, forgotten in r31293.
[mplayer/glamo.git] / libao2 / ao_v4l2.c
blob3781fab35904fba5a9d7817cf31a6cbbe768152b
1 /*
2 * audio output for V4L2 hardware MPEG decoders
4 * WARNING: You need to force -ac hwmpa for audio output to work.
6 * Copyright (C) 2007 Benjamin Zores
8 * This file is part of MPlayer.
10 * MPlayer is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * MPlayer is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include <inttypes.h>
27 #include "config.h"
29 #include "mp_msg.h"
30 #include "help_mp.h"
32 #include "audio_out.h"
33 #include "audio_out_internal.h"
34 #include "libaf/af_format.h"
35 #include "libmpdemux/mpeg_packetizer.h"
36 #include "libvo/vo_v4l2.h"
38 #define MPEG_AUDIO_ID 0x1C0
40 static int freq = 0;
42 static const ao_info_t info =
44 "V4L2 MPEG Audio Decoder output",
45 "v4l2",
46 "Benjamin Zores",
50 LIBAO_EXTERN (v4l2)
52 /* to set/get/query special features/parameters */
53 static int
54 control (int cmd,void *arg)
56 return CONTROL_UNKNOWN;
59 /* open & setup audio device */
60 static int
61 init (int rate, int channels, int format, int flags)
63 extern int v4l2_fd;
65 if (v4l2_fd < 0)
66 return 0;
68 if (format != AF_FORMAT_MPEG2)
70 mp_msg (MSGT_AO, MSGL_FATAL,
71 "AO: [v4l2] can only handle MPEG audio streams.\n");
72 return 0;
75 ao_data.outburst = 2048;
76 ao_data.samplerate = rate;
77 ao_data.channels = channels;
78 ao_data.format = AF_FORMAT_MPEG2;
79 ao_data.buffersize = 2048;
80 ao_data.bps = rate * 2 * 2;
81 ao_data.pts = 0;
82 freq = rate;
84 /* check for supported audio rate */
85 if (rate != 32000 || rate != 41000 || rate != 48000)
87 mp_msg (MSGT_AO, MSGL_ERR, MSGTR_AO_MPEGPES_UnsupSamplerate, rate);
88 rate = 48000;
91 return 1;
94 /* close audio device */
95 static void
96 uninit (int immed)
98 /* nothing to do */
101 /* stop playing and empty buffers (for seeking/pause) */
102 static void
103 reset (void)
105 /* nothing to do */
108 /* stop playing, keep buffers (for pause) */
109 static void
110 audio_pause (void)
112 reset ();
115 /* resume playing, after audio_pause() */
116 static void
117 audio_resume (void)
119 /* nothing to do */
122 /* how many bytes can be played without blocking */
123 static int
124 get_space (void)
126 extern int vo_pts;
127 float x;
128 int y;
130 x = (float) (vo_pts - ao_data.pts) / 90000.0;
131 if (x <= 0)
132 return 0;
134 y = freq * 4 * x;
135 y /= ao_data.outburst;
136 y *= ao_data.outburst;
138 if (y > 32000)
139 y = 32000;
141 return y;
144 /* number of bytes played */
145 static int
146 play (void *data, int len, int flags)
148 if (ao_data.format != AF_FORMAT_MPEG2)
149 return 0;
151 send_mpeg_pes_packet (data, len, MPEG_AUDIO_ID, ao_data.pts, 2, v4l2_write);
153 return len;
156 /* delay in seconds between first and last sample in buffer */
157 static float
158 get_delay (void)
160 return 0.0;