source: roaraudio/plugins/mplayer/ao_roar.c @ 5823:f9f70dbaa376

Last change on this file since 5823:f9f70dbaa376 was 5823:f9f70dbaa376, checked in by phi, 11 years ago

updated copyright

File size: 4.3 KB
Line 
1//ao_roar.c:
2/*
3 * ao_roar - RoarAudio audio output driver for MPlayer
4 *
5 * copyright (c) 2002 Juergen Keil <jk@tools.de>
6 * copyright (c) 2008-2013 Philipp 'ph3-der-loewe' Schafft
7 *
8 * This file is part of RoarAudio, based on a file from MPlayer.
9 *
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.
14 *
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.
19 *
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.
23 */
24
25#include <sys/types.h>
26#include <sys/time.h>
27#include <sys/socket.h>
28#include <stdio.h>
29#include <string.h>
30#include <unistd.h>
31#include <errno.h>
32#include <fcntl.h>
33#include <time.h>
34#ifdef  __svr4__
35#include <stropts.h>
36#endif
37#include <roaraudio.h>
38
39#include "config.h"
40#include "audio_out.h"
41#include "audio_out_internal.h"
42#include "libaf/af_format.h"
43#include "mp_msg.h"
44#include "help_mp.h"
45
46
47#undef  ESD_DEBUG
48
49#if     ESD_DEBUG
50#define dprintf(...)    printf(__VA_ARGS__)
51#else
52#define dprintf(...)    /**/
53#endif
54
55
56#define ROAR_CLIENT_NAME        "MPlayer"
57
58static struct roar_connection  roar_con;
59static struct roar_stream      roar_stream;
60static struct roar_stream_info roar_info;
61static int                     roar_fh;
62
63static ao_info_t info =
64{
65    "RoarAudio audio output",
66    "roar",
67    "Philipp 'ph3-der-loewe' Schafft <lion@lion.leolix.org>",
68    ""
69};
70
71LIBAO_EXTERN(roar)
72
73/*
74 * to set/get/query special features/parameters
75 */
76static int control(int cmd, void *arg)
77{
78    switch (cmd) {
79    case AOCONTROL_GET_VOLUME:
80    case AOCONTROL_SET_VOLUME:
81      return CONTROL_OK;
82    default:
83      return CONTROL_UNKNOWN;
84    }
85}
86
87
88/*
89 * open & setup audio device
90 * return: 1=success 0=fail
91 */
92static int init(int rate_hz, int channels, int format, int flags) {
93 int codec = ROAR_CODEC_DEFAULT;
94 int bits  = 16;
95
96 if ( roar_simple_connect(&roar_con, NULL, ROAR_CLIENT_NAME) == -1 )
97  return 0;
98
99 switch (format) {
100  case AF_FORMAT_S8:
101   bits = 8;
102   break;
103  case AF_FORMAT_U8:
104   bits  = 8;
105   codec = ROAR_CODEC_PCM_U_LE;
106   break;
107 }
108
109 if ( (roar_fh = roar_simple_new_stream_obj(&roar_con, &roar_stream, rate_hz, channels, bits, codec, ROAR_DIR_PLAY)) == -1 )
110  return 0;
111
112 if ( roar_stream_get_info(&roar_con, &roar_stream, &roar_info) == -1 ) {
113  close(roar_fh);
114  return 0;
115 }
116
117 roar_socket_nonblock(roar_fh, ROAR_SOCKET_NONBLOCK);
118
119 return 1;
120}
121
122
123/*
124 * close audio device
125 */
126static void uninit(int immed) {
127 if ( roar_fh != -1 )
128  close(roar_fh);
129
130 roar_fh = -1;
131
132 roar_disconnect(&roar_con);
133}
134
135
136/*
137 * plays 'len' bytes of 'data'
138 * it should round it down to outburst*n
139 * return: number of bytes played
140 */
141static int play(void* data, int len, int flags) {
142 int pkg  = 441*2*2;
143 int ret  = 0;
144 int r;
145
146 while (len > 0) {
147  if ( (r = write(roar_fh, data, pkg < len ? pkg : len)) > 0 ) {
148   len  -= r;
149   data += r;
150   ret  += r;
151  } else {
152   break;
153  }
154 }
155
156// ROAR_WARN("play(*) = %i", ret);
157
158 return ret;
159}
160
161
162/*
163 * stop playing, keep buffers (for pause)
164 */
165static void audio_pause(void)
166{
167    /*
168     * not possible with esd.  the esd daemom will continue playing
169     * buffered data (not more than ESD_MAX_DELAY seconds of samples)
170     */
171}
172
173
174/*
175 * resume playing, after audio_pause()
176 */
177static void audio_resume(void)
178{
179    /*
180     * not possible with esd.
181     *
182     * Let's hope the pause was long enough that the esd ran out of
183     * buffered data;  we restart our time based delay computation
184     * for an audio resume.
185     */
186}
187
188
189/*
190 * stop playing and empty buffers (for seeking/pause)
191 */
192static void reset(void) {
193}
194
195
196/*
197 * return: how many bytes can be played without blocking
198 */
199static int get_space(void) {
200 fd_set sl;
201 struct timeval tv;
202 int r;
203
204 FD_ZERO(&sl);
205 FD_SET(roar_fh, &sl);
206
207 tv.tv_sec  = 0;
208 tv.tv_usec = 1;
209
210 if ((r = select(roar_fh + 1, NULL, &sl, NULL, &tv)) > 0) {
211  return roar_info.block_size;
212 }
213 return 0;
214}
215
216
217/*
218 * return: delay in seconds between first and last sample in buffer
219 */
220static float get_delay(void) {
221 return 0.02;
222}
Note: See TracBrowser for help on using the repository browser.