2011-06-24 13:56:43 +00:00
|
|
|
/*
|
|
|
|
* RSound audio output driver
|
|
|
|
*
|
|
|
|
* Copyright (C) 2011 Hans-Kristian Arntzen
|
|
|
|
*
|
2015-04-13 07:36:54 +00:00
|
|
|
* This file is part of mpv.
|
2011-06-24 13:56:43 +00:00
|
|
|
*
|
2015-04-13 07:36:54 +00:00
|
|
|
* mpv is free software; you can redistribute it and/or modify
|
2011-06-24 13:56:43 +00:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
2015-04-13 07:36:54 +00:00
|
|
|
* mpv is distributed in the hope that it will be useful,
|
2011-06-24 13:56:43 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
2015-04-13 07:36:54 +00:00
|
|
|
* with mpv. If not, see <http://www.gnu.org/licenses/>.
|
2011-06-24 13:56:43 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <rsound.h>
|
|
|
|
|
2016-01-11 18:03:40 +00:00
|
|
|
#include "mpv_talloc.h"
|
2011-06-24 13:56:43 +00:00
|
|
|
|
2013-12-17 01:02:25 +00:00
|
|
|
#include "options/m_option.h"
|
2011-06-24 13:56:43 +00:00
|
|
|
#include "osdep/timer.h"
|
2012-11-09 00:06:43 +00:00
|
|
|
#include "audio/format.h"
|
|
|
|
#include "ao.h"
|
2014-03-07 14:24:32 +00:00
|
|
|
#include "internal.h"
|
2011-06-24 13:56:43 +00:00
|
|
|
|
|
|
|
struct priv {
|
|
|
|
rsound_t *rd;
|
2013-11-23 20:40:33 +00:00
|
|
|
char *host;
|
|
|
|
char *port;
|
2011-06-24 13:56:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int set_format(struct ao *ao)
|
|
|
|
{
|
|
|
|
int rsd_format;
|
|
|
|
|
|
|
|
switch (ao->format) {
|
|
|
|
case AF_FORMAT_U8:
|
|
|
|
rsd_format = RSD_U8;
|
|
|
|
break;
|
2014-09-23 19:04:37 +00:00
|
|
|
case AF_FORMAT_S32:
|
|
|
|
rsd_format = RSD_S32_NE;
|
2011-06-24 13:56:43 +00:00
|
|
|
break;
|
|
|
|
default:
|
2014-09-23 19:04:37 +00:00
|
|
|
rsd_format = RSD_S16_NE;
|
|
|
|
ao->format = AF_FORMAT_S16;
|
2011-06-24 13:56:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return rsd_format;
|
|
|
|
}
|
|
|
|
|
2013-07-22 20:57:51 +00:00
|
|
|
static int init(struct ao *ao)
|
2011-06-24 13:56:43 +00:00
|
|
|
{
|
2013-07-21 20:33:09 +00:00
|
|
|
struct priv *priv = ao->priv;
|
2011-06-24 13:56:43 +00:00
|
|
|
|
2013-07-21 20:33:09 +00:00
|
|
|
if (rsd_init(&priv->rd) < 0)
|
2011-06-24 13:56:43 +00:00
|
|
|
return -1;
|
|
|
|
|
2013-07-21 20:33:09 +00:00
|
|
|
if (priv->host && priv->host[0])
|
|
|
|
rsd_set_param(priv->rd, RSD_HOST, priv->host);
|
2011-06-24 13:56:43 +00:00
|
|
|
|
2013-07-21 20:33:09 +00:00
|
|
|
if (priv->port && priv->port[0])
|
|
|
|
rsd_set_param(priv->rd, RSD_PORT, priv->port);
|
2011-06-24 13:56:43 +00:00
|
|
|
|
2013-05-09 16:06:26 +00:00
|
|
|
// Actual channel layout unknown.
|
|
|
|
struct mp_chmap_sel sel = {0};
|
|
|
|
mp_chmap_sel_add_waveext_def(&sel);
|
|
|
|
if (!ao_chmap_sel_adjust(ao, &sel, &ao->channels)) {
|
|
|
|
rsd_free(priv->rd);
|
|
|
|
return -1;
|
|
|
|
}
|
2013-04-05 21:06:22 +00:00
|
|
|
|
2014-03-09 17:38:35 +00:00
|
|
|
rsd_set_param(priv->rd, RSD_SAMPLERATE, (int[]) { ao->samplerate });
|
|
|
|
rsd_set_param(priv->rd, RSD_CHANNELS, (int[]) { ao->channels.num });
|
2011-06-24 13:56:43 +00:00
|
|
|
|
2013-11-10 22:15:02 +00:00
|
|
|
ao->format = af_fmt_from_planar(ao->format);
|
|
|
|
|
2011-06-24 13:56:43 +00:00
|
|
|
int rsd_format = set_format(ao);
|
|
|
|
rsd_set_param(priv->rd, RSD_FORMAT, &rsd_format);
|
|
|
|
|
|
|
|
if (rsd_start(priv->rd) < 0) {
|
|
|
|
rsd_free(priv->rd);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-03-08 23:49:39 +00:00
|
|
|
static void uninit(struct ao *ao)
|
2011-06-24 13:56:43 +00:00
|
|
|
{
|
|
|
|
struct priv *priv = ao->priv;
|
|
|
|
|
|
|
|
rsd_stop(priv->rd);
|
|
|
|
rsd_free(priv->rd);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void reset(struct ao *ao)
|
|
|
|
{
|
|
|
|
struct priv *priv = ao->priv;
|
|
|
|
rsd_stop(priv->rd);
|
|
|
|
rsd_start(priv->rd);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void audio_pause(struct ao *ao)
|
|
|
|
{
|
|
|
|
struct priv *priv = ao->priv;
|
|
|
|
rsd_pause(priv->rd, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void audio_resume(struct ao *ao)
|
|
|
|
{
|
|
|
|
struct priv *priv = ao->priv;
|
|
|
|
rsd_pause(priv->rd, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int get_space(struct ao *ao)
|
|
|
|
{
|
|
|
|
struct priv *priv = ao->priv;
|
2013-11-10 22:24:21 +00:00
|
|
|
return rsd_get_avail(priv->rd) / ao->sstride;
|
2011-06-24 13:56:43 +00:00
|
|
|
}
|
|
|
|
|
2013-11-10 22:24:21 +00:00
|
|
|
static int play(struct ao *ao, void **data, int samples, int flags)
|
2011-06-24 13:56:43 +00:00
|
|
|
{
|
|
|
|
struct priv *priv = ao->priv;
|
2013-11-10 22:24:21 +00:00
|
|
|
return rsd_write(priv->rd, data[0], samples * ao->sstride) / ao->sstride;
|
2011-06-24 13:56:43 +00:00
|
|
|
}
|
|
|
|
|
2014-11-09 10:45:04 +00:00
|
|
|
static double get_delay(struct ao *ao)
|
2011-06-24 13:56:43 +00:00
|
|
|
{
|
|
|
|
struct priv *priv = ao->priv;
|
|
|
|
return rsd_delay_ms(priv->rd) / 1000.0;
|
|
|
|
}
|
|
|
|
|
2013-07-21 20:33:09 +00:00
|
|
|
#define OPT_BASE_STRUCT struct priv
|
|
|
|
|
2011-06-24 13:56:43 +00:00
|
|
|
const struct ao_driver audio_out_rsound = {
|
2013-10-23 17:07:27 +00:00
|
|
|
.description = "RSound output driver",
|
|
|
|
.name = "rsound",
|
2011-06-24 13:56:43 +00:00
|
|
|
.init = init,
|
|
|
|
.uninit = uninit,
|
|
|
|
.reset = reset,
|
|
|
|
.get_space = get_space,
|
|
|
|
.play = play,
|
|
|
|
.get_delay = get_delay,
|
|
|
|
.pause = audio_pause,
|
|
|
|
.resume = audio_resume,
|
2013-07-21 20:33:09 +00:00
|
|
|
.priv_size = sizeof(struct priv),
|
|
|
|
.options = (const struct m_option[]) {
|
2016-09-05 19:07:30 +00:00
|
|
|
OPT_STRING("host", host, 0,
|
|
|
|
.deprecation_message = "request --audio-device support on issue tracker"),
|
2016-09-07 16:10:12 +00:00
|
|
|
OPT_STRING("port", port, 0,
|
2016-09-05 19:07:30 +00:00
|
|
|
.deprecation_message = "request --audio-device support on issue tracker"),
|
2013-07-21 20:33:09 +00:00
|
|
|
{0}
|
|
|
|
},
|
2016-09-05 19:07:03 +00:00
|
|
|
.legacy_prefix = "rsound",
|
2011-06-24 13:56:43 +00:00
|
|
|
};
|
|
|
|
|