2 * RSound audio output driver
4 * Copyright (C) 2011 Hans-Kristian Arntzen
6 * This file is part of mplayer2.
8 * mplayer2 is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * mplayer2 is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with mplayer2; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
32 #include "subopt-helper.h"
33 #include "osdep/timer.h"
34 #include "libaf/af_format.h"
35 #include "audio_out.h"
41 static int set_format(struct ao
*ao
)
52 case AF_FORMAT_S16_LE
:
53 rsd_format
= RSD_S16_LE
;
55 case AF_FORMAT_S16_BE
:
56 rsd_format
= RSD_S16_BE
;
58 case AF_FORMAT_U16_LE
:
59 rsd_format
= RSD_U16_LE
;
61 case AF_FORMAT_U16_BE
:
62 rsd_format
= RSD_U16_BE
;
64 case AF_FORMAT_S24_LE
:
65 case AF_FORMAT_S24_BE
:
66 case AF_FORMAT_U24_LE
:
67 case AF_FORMAT_U24_BE
:
68 rsd_format
= RSD_S32_LE
;
69 ao
->format
= AF_FORMAT_S32_LE
;
71 case AF_FORMAT_S32_LE
:
72 rsd_format
= RSD_S32_LE
;
74 case AF_FORMAT_S32_BE
:
75 rsd_format
= RSD_S32_BE
;
77 case AF_FORMAT_U32_LE
:
78 rsd_format
= RSD_U32_LE
;
80 case AF_FORMAT_U32_BE
:
81 rsd_format
= RSD_U32_BE
;
84 rsd_format
= RSD_ALAW
;
86 case AF_FORMAT_MU_LAW
:
87 rsd_format
= RSD_MULAW
;
90 rsd_format
= RSD_S16_LE
;
91 ao
->format
= AF_FORMAT_S16_LE
;
97 static int init(struct ao
*ao
, char *params
)
99 struct priv
*priv
= talloc_zero(ao
, struct priv
);
105 const opt_t subopts
[] = {
106 {"host", OPT_ARG_MSTRZ
, &host
, NULL
},
107 {"port", OPT_ARG_MSTRZ
, &port
, NULL
},
111 if (subopt_parse(params
, subopts
) != 0)
114 if (rsd_init(&priv
->rd
) < 0) {
121 rsd_set_param(priv
->rd
, RSD_HOST
, host
);
126 rsd_set_param(priv
->rd
, RSD_PORT
, port
);
130 rsd_set_param(priv
->rd
, RSD_SAMPLERATE
, &ao
->samplerate
);
131 rsd_set_param(priv
->rd
, RSD_CHANNELS
, &ao
->channels
);
133 int rsd_format
= set_format(ao
);
134 rsd_set_param(priv
->rd
, RSD_FORMAT
, &rsd_format
);
136 if (rsd_start(priv
->rd
) < 0) {
141 ao
->bps
= ao
->channels
* ao
->samplerate
* af_fmt2bits(ao
->format
) / 8;
146 static void uninit(struct ao
*ao
, bool cut_audio
)
148 struct priv
*priv
= ao
->priv
;
149 /* The API does not provide a direct way to explicitly wait until
150 * the last byte has been played server-side as this cannot be
151 * guaranteed by backend drivers, so we approximate this behavior.
154 usec_sleep(rsd_delay_ms(priv
->rd
) * 1000);
160 static void reset(struct ao
*ao
)
162 struct priv
*priv
= ao
->priv
;
167 static void audio_pause(struct ao
*ao
)
169 struct priv
*priv
= ao
->priv
;
170 rsd_pause(priv
->rd
, 1);
173 static void audio_resume(struct ao
*ao
)
175 struct priv
*priv
= ao
->priv
;
176 rsd_pause(priv
->rd
, 0);
179 static int get_space(struct ao
*ao
)
181 struct priv
*priv
= ao
->priv
;
182 return rsd_get_avail(priv
->rd
);
185 static int play(struct ao
*ao
, void *data
, int len
, int flags
)
187 struct priv
*priv
= ao
->priv
;
188 return rsd_write(priv
->rd
, data
, len
);
191 static float get_delay(struct ao
*ao
)
193 struct priv
*priv
= ao
->priv
;
194 return rsd_delay_ms(priv
->rd
) / 1000.0;
197 const struct ao_driver audio_out_rsound
= {
199 .info
= &(const struct ao_info
) {
200 .name
= "RSound output driver",
201 .short_name
= "rsound",
202 .author
= "Hans-Kristian Arntzen",
208 .get_space
= get_space
,
210 .get_delay
= get_delay
,
211 .pause
= audio_pause
,
212 .resume
= audio_resume
,