2010-01-30 23:24:23 +00:00
|
|
|
/*
|
|
|
|
* This file is part of MPlayer.
|
|
|
|
*
|
|
|
|
* MPlayer is free software; you can redistribute it and/or modify
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* MPlayer is distributed in the hope that it will be useful,
|
|
|
|
* 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
|
|
|
|
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2001-04-15 18:37:07 +00:00
|
|
|
#include <string.h>
|
2013-09-19 12:32:47 +00:00
|
|
|
#include <stdio.h>
|
2014-05-06 18:09:36 +00:00
|
|
|
#include <math.h>
|
2001-04-15 18:37:07 +00:00
|
|
|
|
2012-04-09 14:39:01 +00:00
|
|
|
#include <libavutil/common.h>
|
|
|
|
|
2001-06-05 18:40:44 +00:00
|
|
|
#include "config.h"
|
2012-11-09 00:06:43 +00:00
|
|
|
#include "audio/out/ao.h"
|
|
|
|
#include "audio/filter/af.h"
|
2013-12-21 17:19:47 +00:00
|
|
|
#include "common/global.h"
|
2013-12-17 01:39:45 +00:00
|
|
|
#include "common/msg.h"
|
2013-09-19 12:32:47 +00:00
|
|
|
#include "talloc.h"
|
2004-06-26 09:14:20 +00:00
|
|
|
#include "mixer.h"
|
2001-04-15 18:37:07 +00:00
|
|
|
|
2013-09-19 12:33:26 +00:00
|
|
|
struct mixer {
|
2013-12-21 17:19:47 +00:00
|
|
|
struct mp_log *log;
|
2013-09-19 12:33:26 +00:00
|
|
|
struct MPOpts *opts;
|
|
|
|
struct ao *ao;
|
|
|
|
struct af_stream *af;
|
|
|
|
// Static, dependent on ao/softvol settings
|
|
|
|
bool softvol; // use AO (true) or af_volume (false)
|
|
|
|
bool emulate_mute; // if true, emulate mute with volume=0
|
|
|
|
// Last known values (possibly out of sync with reality)
|
|
|
|
float vol_l, vol_r;
|
|
|
|
bool muted;
|
|
|
|
// Used to decide whether we should unmute on uninit
|
|
|
|
bool muted_by_us;
|
|
|
|
/* Contains ao driver name or "softvol" if volume is not persistent
|
|
|
|
* and needs to be restored after the driver is reinitialized. */
|
|
|
|
const char *driver;
|
|
|
|
// Other stuff
|
|
|
|
float balance;
|
|
|
|
};
|
|
|
|
|
2013-12-21 17:19:47 +00:00
|
|
|
struct mixer *mixer_init(void *talloc_ctx, struct mpv_global *global)
|
2013-09-19 12:32:09 +00:00
|
|
|
{
|
2013-09-19 12:33:26 +00:00
|
|
|
struct mixer *mixer = talloc_ptrtype(talloc_ctx, mixer);
|
|
|
|
*mixer = (struct mixer) {
|
2013-12-21 17:19:47 +00:00
|
|
|
.log = mp_log_new(mixer, global->log, "mixer"),
|
|
|
|
.opts = global->opts,
|
2013-09-19 12:33:26 +00:00
|
|
|
.vol_l = 100,
|
|
|
|
.vol_r = 100,
|
|
|
|
.driver = "",
|
|
|
|
};
|
|
|
|
return mixer;
|
2013-09-19 12:32:09 +00:00
|
|
|
}
|
2001-06-05 18:40:44 +00:00
|
|
|
|
2013-10-12 16:28:02 +00:00
|
|
|
bool mixer_audio_initialized(struct mixer *mixer)
|
|
|
|
{
|
|
|
|
return !!mixer->ao;
|
|
|
|
}
|
|
|
|
|
2014-06-08 21:52:58 +00:00
|
|
|
float mixer_getneutralvolume(struct mixer *mixer)
|
|
|
|
{
|
|
|
|
// gain == 1
|
|
|
|
return 1.0 / mixer->opts->softvol_max * 100.0 * 100.0;
|
|
|
|
}
|
|
|
|
|
2012-04-09 14:39:01 +00:00
|
|
|
static void checkvolume(struct mixer *mixer)
|
2001-06-05 18:40:44 +00:00
|
|
|
{
|
2011-12-26 00:41:35 +00:00
|
|
|
if (!mixer->ao)
|
2004-06-26 09:14:20 +00:00
|
|
|
return;
|
2011-12-26 00:41:35 +00:00
|
|
|
|
2013-09-19 12:32:09 +00:00
|
|
|
ao_control_vol_t vol = {mixer->vol_l, mixer->vol_r};
|
|
|
|
if (mixer->softvol) {
|
2013-11-09 22:25:31 +00:00
|
|
|
float gain;
|
2013-11-18 13:16:08 +00:00
|
|
|
if (!af_control_any_rev(mixer->af, AF_CONTROL_GET_VOLUME, &gain))
|
2013-11-09 22:25:31 +00:00
|
|
|
gain = 1.0;
|
|
|
|
vol.left = (gain / (mixer->opts->softvol_max / 100.0)) * 100.0;
|
|
|
|
vol.right = (gain / (mixer->opts->softvol_max / 100.0)) * 100.0;
|
2013-09-19 12:32:09 +00:00
|
|
|
} else {
|
|
|
|
// Rely on the values not changing if the query is not supported
|
|
|
|
ao_control(mixer->ao, AOCONTROL_GET_VOLUME, &vol);
|
|
|
|
ao_control(mixer->ao, AOCONTROL_GET_MUTE, &mixer->muted);
|
2004-06-26 09:14:20 +00:00
|
|
|
}
|
2012-04-09 14:39:01 +00:00
|
|
|
float l = mixer->vol_l;
|
|
|
|
float r = mixer->vol_r;
|
2013-09-19 12:32:09 +00:00
|
|
|
if (mixer->emulate_mute && mixer->muted)
|
2012-04-09 14:39:01 +00:00
|
|
|
l = r = 0;
|
|
|
|
/* Try to detect cases where the volume has been changed by some external
|
|
|
|
* action (such as something else changing a shared system-wide volume).
|
|
|
|
* We don't test for exact equality, as some AOs may round the value
|
|
|
|
* we last set to some nearby supported value. 3 has been the default
|
|
|
|
* volume step for increase/decrease keys, and is apparently big enough
|
|
|
|
* to step to the next possible value in most setups.
|
|
|
|
*/
|
|
|
|
if (FFABS(vol.left - l) >= 3 || FFABS(vol.right - r) >= 3) {
|
|
|
|
mixer->vol_l = vol.left;
|
|
|
|
mixer->vol_r = vol.right;
|
2013-09-19 12:32:09 +00:00
|
|
|
if (mixer->emulate_mute)
|
2012-04-10 01:45:53 +00:00
|
|
|
mixer->muted = false;
|
2012-04-09 14:39:01 +00:00
|
|
|
}
|
2012-04-10 01:45:53 +00:00
|
|
|
mixer->muted_by_us &= mixer->muted;
|
2001-06-05 18:40:44 +00:00
|
|
|
}
|
|
|
|
|
2013-09-19 12:33:26 +00:00
|
|
|
void mixer_getvolume(struct mixer *mixer, float *l, float *r)
|
2001-06-05 18:40:44 +00:00
|
|
|
{
|
2012-04-09 14:39:01 +00:00
|
|
|
checkvolume(mixer);
|
|
|
|
*l = mixer->vol_l;
|
|
|
|
*r = mixer->vol_r;
|
|
|
|
}
|
|
|
|
|
2013-09-19 12:33:26 +00:00
|
|
|
static void setvolume_internal(struct mixer *mixer, float l, float r)
|
2012-04-09 14:39:01 +00:00
|
|
|
{
|
|
|
|
struct ao_control_vol vol = {.left = l, .right = r};
|
2012-04-10 23:48:18 +00:00
|
|
|
if (!mixer->softvol) {
|
|
|
|
if (ao_control(mixer->ao, AOCONTROL_SET_VOLUME, &vol) != CONTROL_OK)
|
2013-12-21 17:19:47 +00:00
|
|
|
MP_ERR(mixer, "Failed to change audio output volume.\n");
|
2012-04-10 23:48:18 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-11-09 22:25:31 +00:00
|
|
|
float gain = (l + r) / 2.0 / 100.0 * mixer->opts->softvol_max / 100.0;
|
2013-11-18 13:16:08 +00:00
|
|
|
if (!af_control_any_rev(mixer->af, AF_CONTROL_SET_VOLUME, &gain)) {
|
2013-12-21 17:19:47 +00:00
|
|
|
MP_VERBOSE(mixer, "Inserting volume filter.\n");
|
2013-09-19 12:31:43 +00:00
|
|
|
if (!(af_add(mixer->af, "volume", NULL)
|
2013-11-18 13:16:08 +00:00
|
|
|
&& af_control_any_rev(mixer->af, AF_CONTROL_SET_VOLUME, &gain)))
|
2013-12-21 17:19:47 +00:00
|
|
|
MP_ERR(mixer, "No volume control available.\n");
|
2004-06-26 09:14:20 +00:00
|
|
|
}
|
2001-06-05 18:40:44 +00:00
|
|
|
}
|
2001-06-08 23:36:58 +00:00
|
|
|
|
2013-09-19 12:33:26 +00:00
|
|
|
void mixer_setvolume(struct mixer *mixer, float l, float r)
|
2001-04-15 18:37:07 +00:00
|
|
|
{
|
2013-09-19 12:32:09 +00:00
|
|
|
checkvolume(mixer); // to check mute status
|
|
|
|
if (mixer->vol_l == l && mixer->vol_r == r)
|
|
|
|
return; // just prevent af_volume insertion when not needed
|
2013-01-12 13:19:07 +00:00
|
|
|
mixer->vol_l = av_clipf(l, 0, 100);
|
|
|
|
mixer->vol_r = av_clipf(r, 0, 100);
|
2013-09-19 12:32:09 +00:00
|
|
|
if (mixer->ao && !(mixer->emulate_mute && mixer->muted))
|
|
|
|
setvolume_internal(mixer, mixer->vol_l, mixer->vol_r);
|
2001-04-15 18:37:07 +00:00
|
|
|
}
|
|
|
|
|
2013-09-19 12:33:26 +00:00
|
|
|
void mixer_getbothvolume(struct mixer *mixer, float *b)
|
2001-04-15 18:37:07 +00:00
|
|
|
{
|
2011-12-26 00:41:35 +00:00
|
|
|
float mixer_l, mixer_r;
|
|
|
|
mixer_getvolume(mixer, &mixer_l, &mixer_r);
|
|
|
|
*b = (mixer_l + mixer_r) / 2;
|
2001-04-15 18:37:07 +00:00
|
|
|
}
|
2002-02-21 16:02:26 +00:00
|
|
|
|
2012-04-09 14:39:01 +00:00
|
|
|
void mixer_setmute(struct mixer *mixer, bool mute)
|
2002-06-06 07:13:57 +00:00
|
|
|
{
|
2012-04-09 14:39:01 +00:00
|
|
|
checkvolume(mixer);
|
2013-09-19 12:32:09 +00:00
|
|
|
if (mute == mixer->muted)
|
|
|
|
return;
|
|
|
|
if (mixer->ao) {
|
|
|
|
mixer->muted = mute;
|
|
|
|
mixer->muted_by_us = mute;
|
|
|
|
if (mixer->emulate_mute) {
|
2012-04-10 01:45:53 +00:00
|
|
|
setvolume_internal(mixer, mixer->vol_l*!mute, mixer->vol_r*!mute);
|
2013-09-19 12:32:09 +00:00
|
|
|
} else {
|
|
|
|
ao_control(mixer->ao, AOCONTROL_SET_MUTE, &mute);
|
2012-04-10 01:45:53 +00:00
|
|
|
}
|
2013-09-19 12:32:09 +00:00
|
|
|
checkvolume(mixer);
|
|
|
|
} else {
|
2012-04-09 14:39:01 +00:00
|
|
|
mixer->muted = mute;
|
2012-04-10 01:45:53 +00:00
|
|
|
mixer->muted_by_us = mute;
|
2011-12-26 00:41:35 +00:00
|
|
|
}
|
2002-06-06 07:13:57 +00:00
|
|
|
}
|
2007-06-20 02:26:20 +00:00
|
|
|
|
2012-04-09 14:39:01 +00:00
|
|
|
bool mixer_getmute(struct mixer *mixer)
|
|
|
|
{
|
|
|
|
checkvolume(mixer);
|
|
|
|
return mixer->muted;
|
|
|
|
}
|
|
|
|
|
2014-02-27 00:07:46 +00:00
|
|
|
void mixer_addvolume(struct mixer *mixer, float step)
|
2012-04-09 14:39:01 +00:00
|
|
|
{
|
2013-09-19 12:32:09 +00:00
|
|
|
float vol_l, vol_r;
|
|
|
|
mixer_getvolume(mixer, &vol_l, &vol_r);
|
2014-02-27 00:07:46 +00:00
|
|
|
mixer_setvolume(mixer, vol_l + step, vol_r + step);
|
2012-04-09 14:39:01 +00:00
|
|
|
}
|
|
|
|
|
2013-09-19 12:33:26 +00:00
|
|
|
void mixer_getbalance(struct mixer *mixer, float *val)
|
2007-06-20 02:26:20 +00:00
|
|
|
{
|
2013-09-19 12:31:43 +00:00
|
|
|
if (mixer->af)
|
2013-11-18 13:16:08 +00:00
|
|
|
af_control_any_rev(mixer->af, AF_CONTROL_GET_PAN_BALANCE, &mixer->balance);
|
2012-04-09 18:06:10 +00:00
|
|
|
*val = mixer->balance;
|
2007-06-20 02:26:20 +00:00
|
|
|
}
|
|
|
|
|
2012-04-09 18:06:10 +00:00
|
|
|
/* NOTE: Currently the balance code is seriously buggy: it always changes
|
|
|
|
* the af_pan mapping between the first two input channels and first two
|
|
|
|
* output channels to particular values. These values make sense for an
|
|
|
|
* af_pan instance that was automatically inserted for balance control
|
|
|
|
* only and is otherwise an identity transform, but if the filter was
|
|
|
|
* there for another reason, then ignoring and overriding the original
|
2013-12-07 18:30:14 +00:00
|
|
|
* values is completely wrong.
|
2012-04-09 18:06:10 +00:00
|
|
|
*/
|
|
|
|
|
2013-09-19 12:33:26 +00:00
|
|
|
void mixer_setbalance(struct mixer *mixer, float val)
|
2007-06-20 02:26:20 +00:00
|
|
|
{
|
2012-11-01 11:23:48 +00:00
|
|
|
struct af_instance *af_pan_balance;
|
2011-12-26 00:41:35 +00:00
|
|
|
|
2012-04-09 18:06:10 +00:00
|
|
|
mixer->balance = val;
|
|
|
|
|
2013-09-19 12:31:43 +00:00
|
|
|
if (!mixer->af)
|
2011-12-26 00:41:35 +00:00
|
|
|
return;
|
2007-06-20 02:26:20 +00:00
|
|
|
|
2013-11-18 13:16:08 +00:00
|
|
|
if (af_control_any_rev(mixer->af, AF_CONTROL_SET_PAN_BALANCE, &val))
|
2011-12-26 00:41:35 +00:00
|
|
|
return;
|
|
|
|
|
2014-03-07 14:24:32 +00:00
|
|
|
if (val == 0)
|
2012-04-09 18:06:10 +00:00
|
|
|
return;
|
|
|
|
|
2013-09-19 12:31:43 +00:00
|
|
|
if (!(af_pan_balance = af_add(mixer->af, "pan", NULL))) {
|
2013-12-21 17:19:47 +00:00
|
|
|
MP_ERR(mixer, "No balance control available.\n");
|
2011-12-26 00:41:35 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* make all other channels pass thru since by default pan blocks all */
|
2014-05-11 14:37:52 +00:00
|
|
|
for (int i = 2; i < AF_NCH; i++) {
|
|
|
|
float level[AF_NCH] = {0};
|
2011-12-26 00:41:35 +00:00
|
|
|
level[i] = 1.f;
|
2014-05-11 14:37:52 +00:00
|
|
|
af_control_ext_t arg_ext = { .ch = i, .arg = level };
|
2013-11-18 13:16:08 +00:00
|
|
|
af_pan_balance->control(af_pan_balance, AF_CONTROL_SET_PAN_LEVEL,
|
2011-12-26 00:41:35 +00:00
|
|
|
&arg_ext);
|
|
|
|
}
|
|
|
|
|
2013-11-18 13:16:08 +00:00
|
|
|
af_pan_balance->control(af_pan_balance, AF_CONTROL_SET_PAN_BALANCE, &val);
|
2007-06-20 02:26:20 +00:00
|
|
|
}
|
2012-04-09 18:02:27 +00:00
|
|
|
|
2013-09-19 12:32:47 +00:00
|
|
|
char *mixer_get_volume_restore_data(struct mixer *mixer)
|
|
|
|
{
|
|
|
|
if (!mixer->driver[0])
|
|
|
|
return NULL;
|
2014-05-06 18:09:36 +00:00
|
|
|
return talloc_asprintf(NULL, "%s:%f:%f:%d:%f", mixer->driver, mixer->vol_l,
|
|
|
|
mixer->vol_r, mixer->muted_by_us,
|
|
|
|
mixer->opts->softvol_max);
|
2013-09-19 12:32:47 +00:00
|
|
|
}
|
|
|
|
|
2013-09-19 12:32:09 +00:00
|
|
|
static void probe_softvol(struct mixer *mixer)
|
|
|
|
{
|
|
|
|
if (mixer->opts->softvol == SOFTVOL_AUTO) {
|
|
|
|
// No system-wide volume => fine with AO volume control.
|
2014-03-07 14:24:32 +00:00
|
|
|
mixer->softvol =
|
2014-03-08 23:04:37 +00:00
|
|
|
ao_control(mixer->ao, AOCONTROL_HAS_TEMP_VOLUME, 0) != 1 ||
|
2014-03-07 14:24:32 +00:00
|
|
|
ao_control(mixer->ao, AOCONTROL_HAS_PER_APP_VOLUME, 0) != 1;
|
2013-09-19 12:32:09 +00:00
|
|
|
} else {
|
|
|
|
mixer->softvol = mixer->opts->softvol == SOFTVOL_YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we can't use real volume control => force softvol.
|
|
|
|
if (!mixer->softvol) {
|
|
|
|
ao_control_vol_t vol;
|
|
|
|
if (ao_control(mixer->ao, AOCONTROL_GET_VOLUME, &vol) != CONTROL_OK) {
|
|
|
|
mixer->softvol = true;
|
2013-12-21 17:19:47 +00:00
|
|
|
MP_WARN(mixer, "Hardware volume control unavailable.\n");
|
2013-09-19 12:32:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Probe native mute support.
|
|
|
|
mixer->emulate_mute = true;
|
|
|
|
if (!mixer->softvol) {
|
|
|
|
if (ao_control(mixer->ao, AOCONTROL_GET_MUTE, &(bool){0}) == CONTROL_OK)
|
|
|
|
mixer->emulate_mute = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void restore_volume(struct mixer *mixer)
|
|
|
|
{
|
|
|
|
struct MPOpts *opts = mixer->opts;
|
|
|
|
struct ao *ao = mixer->ao;
|
|
|
|
|
|
|
|
float force_vol_l = -1, force_vol_r = -1;
|
|
|
|
int force_mute = -1;
|
|
|
|
|
|
|
|
const char *prev_driver = mixer->driver;
|
2014-03-07 14:24:32 +00:00
|
|
|
mixer->driver = mixer->softvol ? "softvol" : ao_get_name(ao);
|
2013-09-19 12:32:09 +00:00
|
|
|
|
2014-03-08 23:04:37 +00:00
|
|
|
bool restore =
|
|
|
|
mixer->softvol || ao_control(ao, AOCONTROL_HAS_TEMP_VOLUME, 0) == 1;
|
2013-09-19 12:32:09 +00:00
|
|
|
|
|
|
|
// Restore old parameters if volume won't survive reinitialization.
|
|
|
|
// But not if volume scale is possibly different.
|
|
|
|
if (restore && strcmp(mixer->driver, prev_driver) == 0) {
|
|
|
|
force_vol_l = mixer->vol_l;
|
|
|
|
force_vol_r = mixer->vol_r;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set mute if we disabled it on uninit last time.
|
|
|
|
if (mixer->muted_by_us)
|
|
|
|
force_mute = 1;
|
|
|
|
|
|
|
|
// Set parameters from command line.
|
|
|
|
if (opts->mixer_init_volume >= 0)
|
|
|
|
force_vol_l = force_vol_r = opts->mixer_init_volume;
|
|
|
|
if (opts->mixer_init_mute >= 0)
|
|
|
|
force_mute = opts->mixer_init_mute;
|
|
|
|
|
2013-09-19 12:32:47 +00:00
|
|
|
// Set parameters from playback resume.
|
2014-05-06 18:09:36 +00:00
|
|
|
char *data = mixer->opts->mixer_restore_volume_data;
|
|
|
|
if (restore && data && data[0]) {
|
2013-09-19 12:32:47 +00:00
|
|
|
char drv[40];
|
2014-05-06 18:09:36 +00:00
|
|
|
float v_l, v_r, s;
|
2013-09-19 12:32:47 +00:00
|
|
|
int m;
|
2014-05-06 18:09:36 +00:00
|
|
|
if (sscanf(data, "%39[^:]:%f:%f:%d:%f", drv, &v_l, &v_r, &m, &s) == 5) {
|
|
|
|
float diff = fabs(mixer->opts->softvol_max - s);
|
|
|
|
if (strcmp(mixer->driver, drv) == 0 && diff < 0.01) {
|
2013-09-19 12:32:47 +00:00
|
|
|
force_vol_l = v_l;
|
|
|
|
force_vol_r = v_r;
|
|
|
|
force_mute = !!m;
|
|
|
|
}
|
|
|
|
}
|
2014-05-06 18:09:36 +00:00
|
|
|
talloc_free(mixer->opts->mixer_restore_volume_data);
|
2013-09-19 12:32:47 +00:00
|
|
|
mixer->opts->mixer_restore_volume_data = NULL;
|
|
|
|
}
|
|
|
|
|
2013-09-19 12:32:09 +00:00
|
|
|
// Using --volume should not reset the volume on every file (i.e. reinit),
|
|
|
|
// OTOH mpv --{ --volume 10 f1.mkv --} --{ --volume 20 f2.mkv --} must work.
|
|
|
|
// Resetting the option volumes to "auto" (-1) is easiest. If file local
|
2013-09-19 12:32:47 +00:00
|
|
|
// options (as shown above) are used, the option handler code will reset
|
|
|
|
// them to other values, and force the volume to be reset as well.
|
2013-09-19 12:32:09 +00:00
|
|
|
opts->mixer_init_volume = -1;
|
|
|
|
opts->mixer_init_mute = -1;
|
|
|
|
|
|
|
|
checkvolume(mixer);
|
|
|
|
if (force_vol_l >= 0 && force_vol_r >= 0)
|
|
|
|
mixer_setvolume(mixer, force_vol_l, force_vol_r);
|
|
|
|
if (force_mute >= 0)
|
|
|
|
mixer_setmute(mixer, force_mute);
|
|
|
|
}
|
|
|
|
|
2012-04-09 18:02:27 +00:00
|
|
|
// Called after the audio filter chain is built or rebuilt.
|
2013-09-19 12:32:09 +00:00
|
|
|
// (Can be called multiple times, even without mixer_uninit() in-between.)
|
2013-09-19 12:31:43 +00:00
|
|
|
void mixer_reinit_audio(struct mixer *mixer, struct ao *ao, struct af_stream *af)
|
2012-04-09 18:02:27 +00:00
|
|
|
{
|
2013-09-19 12:32:09 +00:00
|
|
|
if (!ao || !af)
|
|
|
|
return;
|
2012-04-09 18:02:27 +00:00
|
|
|
mixer->ao = ao;
|
2013-09-19 12:31:43 +00:00
|
|
|
mixer->af = af;
|
2013-09-19 12:32:09 +00:00
|
|
|
|
|
|
|
probe_softvol(mixer);
|
|
|
|
restore_volume(mixer);
|
|
|
|
|
2012-04-09 18:06:10 +00:00
|
|
|
if (mixer->balance != 0)
|
|
|
|
mixer_setbalance(mixer, mixer->balance);
|
2012-04-09 18:02:27 +00:00
|
|
|
}
|
2012-04-09 19:11:49 +00:00
|
|
|
|
2013-09-19 12:32:09 +00:00
|
|
|
/* Called before uninitializing the audio filter chain. The main purpose is to
|
2012-04-09 19:11:49 +00:00
|
|
|
* turn off mute, in case it's a global/persistent setting which might
|
|
|
|
* otherwise be left enabled even after this player instance exits.
|
|
|
|
*/
|
2013-09-19 12:31:43 +00:00
|
|
|
void mixer_uninit_audio(struct mixer *mixer)
|
2012-04-09 19:11:49 +00:00
|
|
|
{
|
2012-10-02 20:22:19 +00:00
|
|
|
if (!mixer->ao)
|
|
|
|
return;
|
|
|
|
|
2012-04-09 19:11:49 +00:00
|
|
|
checkvolume(mixer);
|
2012-04-10 01:45:53 +00:00
|
|
|
if (mixer->muted_by_us) {
|
2012-04-09 19:11:49 +00:00
|
|
|
/* Current audio output API combines playing the remaining buffered
|
|
|
|
* audio and uninitializing the AO into one operation, even though
|
|
|
|
* ideally unmute would happen between those two steps. We can't do
|
|
|
|
* volume changes after uninitialization, but we don't want the
|
|
|
|
* remaining audio to play at full volume either. Thus this
|
|
|
|
* workaround to drop remaining audio first. */
|
|
|
|
ao_reset(mixer->ao);
|
|
|
|
mixer_setmute(mixer, false);
|
|
|
|
/* We remember mute status and re-enable it if we play more audio
|
|
|
|
* in the same process. */
|
2012-04-10 01:45:53 +00:00
|
|
|
mixer->muted_by_us = true;
|
2012-04-09 19:11:49 +00:00
|
|
|
}
|
|
|
|
mixer->ao = NULL;
|
2013-09-19 12:32:09 +00:00
|
|
|
mixer->af = NULL;
|
2012-04-09 19:11:49 +00:00
|
|
|
}
|