2 * Copyright (C) 2007 Benjamin Zores
3 * Audio output for V4L2 hardware MPEG decoders.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 * WARNING: you need to force -ac hwmpa for audio output to work.
29 #include "audio_out.h"
30 #include "audio_out_internal.h"
31 #include "libaf/af_format.h"
32 #include "libmpdemux/mpeg_packetizer.h"
34 #define MPEG_AUDIO_ID 0x1C0
38 static ao_info_t info
=
40 "V4L2 MPEG Audio Decoder output",
48 /* to set/get/query special features/parameters */
50 control (int cmd
,void *arg
)
52 return CONTROL_UNKNOWN
;
55 /* open & setup audio device */
57 init (int rate
, int channels
, int format
, int flags
)
64 if (format
!= AF_FORMAT_MPEG2
)
66 mp_msg (MSGT_AO
, MSGL_FATAL
,
67 "AO: [v4l2] can only handle MPEG audio streams.\n");
71 ao_data
.outburst
= 2048;
72 ao_data
.samplerate
= rate
;
73 ao_data
.channels
= channels
;
74 ao_data
.format
= AF_FORMAT_MPEG2
;
75 ao_data
.buffersize
= 2048;
76 ao_data
.bps
= rate
* 2 * 2;
80 /* check for supported audio rate */
81 if (rate
!= 32000 || rate
!= 41000 || rate
!= 48000)
83 mp_msg (MSGT_AO
, MSGL_ERR
, MSGTR_AO_MPEGPES_UnsupSamplerate
, rate
);
90 /* close audio device */
97 /* stop playing and empty buffers (for seeking/pause) */
104 /* stop playing, keep buffers (for pause) */
111 /* resume playing, after audio_pause() */
118 /* how many bytes can be played without blocking */
126 x
= (float) (vo_pts
- ao_data
.pts
) / 90000.0;
131 y
/= ao_data
.outburst
;
132 y
*= ao_data
.outburst
;
140 /* number of bytes played */
142 play (void *data
, int len
, int flags
)
144 extern int v4l2_write (unsigned char *data
, int len
);
146 if (ao_data
.format
!= AF_FORMAT_MPEG2
)
149 send_mpeg_pes_packet (data
, len
, MPEG_AUDIO_ID
, ao_data
.pts
, 2, v4l2_write
);
154 /* delay in seconds between first and last sample in buffer */