vo_corevideo: fix key interpretation with modifiers
[mplayer.git] / libao2 / ao_v4l2.c
blob2bc74379a01e2ceb81604aef38e904f2698db2b1
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"
31 #include "audio_out.h"
32 #include "audio_out_internal.h"
33 #include "libaf/af_format.h"
34 #include "libmpdemux/mpeg_packetizer.h"
35 #include "libvo/vo_v4l2.h"
37 #define MPEG_AUDIO_ID 0x1C0
39 static int freq = 0;
41 static const ao_info_t info =
43 "V4L2 MPEG Audio Decoder output",
44 "v4l2",
45 "Benjamin Zores",
49 LIBAO_EXTERN (v4l2)
51 /* to set/get/query special features/parameters */
52 static int
53 control (int cmd,void *arg)
55 return CONTROL_UNKNOWN;
58 /* open & setup audio device */
59 static int
60 init (int rate, int channels, int format, int flags)
62 if (v4l2_fd < 0)
63 return 0;
65 if (format != AF_FORMAT_MPEG2)
67 mp_msg (MSGT_AO, MSGL_FATAL,
68 "AO: [v4l2] can only handle MPEG audio streams.\n");
69 return 0;
72 ao_data.outburst = 2048;
73 ao_data.samplerate = rate;
74 ao_data.channels = channels;
75 ao_data.format = AF_FORMAT_MPEG2;
76 ao_data.buffersize = 2048;
77 ao_data.bps = rate * 2 * 2;
78 ao_data.brokenpts = 0;
79 freq = rate;
81 /* check for supported audio rate */
82 if (rate != 32000 || rate != 41000 || rate != 48000)
84 mp_tmsg (MSGT_AO, MSGL_ERR, "[AO MPEGPES] %d Hz not supported, try to resample.\n", rate);
85 rate = 48000;
88 return 1;
91 /* close audio device */
92 static void
93 uninit (int immed)
95 /* nothing to do */
98 /* stop playing and empty buffers (for seeking/pause) */
99 static void
100 reset (void)
102 /* nothing to do */
105 /* stop playing, keep buffers (for pause) */
106 static void
107 audio_pause (void)
109 reset ();
112 /* resume playing, after audio_pause() */
113 static void
114 audio_resume (void)
116 /* nothing to do */
119 /* how many bytes can be played without blocking */
120 static int
121 get_space (void)
123 extern int vo_pts;
124 float x;
125 int y;
127 x = (float) (vo_pts - ao_data.brokenpts) / 90000.0;
128 if (x <= 0)
129 return 0;
131 y = freq * 4 * x;
132 y /= ao_data.outburst;
133 y *= ao_data.outburst;
135 if (y > 32000)
136 y = 32000;
138 return y;
141 /* number of bytes played */
142 static int
143 play (void *data, int len, int flags)
145 if (ao_data.format != AF_FORMAT_MPEG2)
146 return 0;
148 send_mpeg_pes_packet (data, len, MPEG_AUDIO_ID, ao_data.brokenpts, 2, v4l2_write);
150 return len;
153 /* delay in seconds between first and last sample in buffer */
154 static float
155 get_delay (void)
157 return 0.0;