summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--audio/mixer.c48
-rw-r--r--audio/mixer.h42
-rw-r--r--audio/out/ao_alsa.c1
-rw-r--r--audio/out/ao_oss.c1
-rw-r--r--mpvcore/command.c20
-rw-r--r--mpvcore/mp_core.h3
-rw-r--r--mpvcore/mplayer.c6
7 files changed, 64 insertions, 57 deletions
diff --git a/audio/mixer.c b/audio/mixer.c
index 3e16ce5f8e..0bc650c7e8 100644
--- a/audio/mixer.c
+++ b/audio/mixer.c
@@ -28,11 +28,35 @@
#include "talloc.h"
#include "mixer.h"
-void mixer_init(struct mixer *mixer, struct MPOpts *opts)
+struct mixer {
+ 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;
+};
+
+struct mixer *mixer_init(void *talloc_ctx, struct MPOpts *opts)
{
- mixer->opts = opts;
- mixer->vol_l = mixer->vol_r = 100;
- mixer->driver = "";
+ struct mixer *mixer = talloc_ptrtype(talloc_ctx, mixer);
+ *mixer = (struct mixer) {
+ .opts = opts,
+ .vol_l = 100,
+ .vol_r = 100,
+ .driver = "",
+ };
+ return mixer;
}
static void checkvolume(struct mixer *mixer)
@@ -73,14 +97,14 @@ static void checkvolume(struct mixer *mixer)
mixer->muted_by_us &= mixer->muted;
}
-void mixer_getvolume(mixer_t *mixer, float *l, float *r)
+void mixer_getvolume(struct mixer *mixer, float *l, float *r)
{
checkvolume(mixer);
*l = mixer->vol_l;
*r = mixer->vol_r;
}
-static void setvolume_internal(mixer_t *mixer, float l, float r)
+static void setvolume_internal(struct mixer *mixer, float l, float r)
{
struct ao_control_vol vol = {.left = l, .right = r};
if (!mixer->softvol) {
@@ -108,7 +132,7 @@ static void setvolume_internal(mixer_t *mixer, float l, float r)
}
}
-void mixer_setvolume(mixer_t *mixer, float l, float r)
+void mixer_setvolume(struct mixer *mixer, float l, float r)
{
checkvolume(mixer); // to check mute status
if (mixer->vol_l == l && mixer->vol_r == r)
@@ -119,7 +143,7 @@ void mixer_setvolume(mixer_t *mixer, float l, float r)
setvolume_internal(mixer, mixer->vol_l, mixer->vol_r);
}
-void mixer_getbothvolume(mixer_t *mixer, float *b)
+void mixer_getbothvolume(struct mixer *mixer, float *b)
{
float mixer_l, mixer_r;
mixer_getvolume(mixer, &mixer_l, &mixer_r);
@@ -159,17 +183,17 @@ static void addvolume(struct mixer *mixer, float d)
mixer_setvolume(mixer, vol_l + d, vol_r + d);
}
-void mixer_incvolume(mixer_t *mixer)
+void mixer_incvolume(struct mixer *mixer)
{
addvolume(mixer, mixer->opts->volstep);
}
-void mixer_decvolume(mixer_t *mixer)
+void mixer_decvolume(struct mixer *mixer)
{
addvolume(mixer, -mixer->opts->volstep);
}
-void mixer_getbalance(mixer_t *mixer, float *val)
+void mixer_getbalance(struct mixer *mixer, float *val)
{
if (mixer->af)
af_control_any_rev(mixer->af,
@@ -189,7 +213,7 @@ void mixer_getbalance(mixer_t *mixer, float *val)
* are significantly below 1 will be overwritten with much higher values.
*/
-void mixer_setbalance(mixer_t *mixer, float val)
+void mixer_setbalance(struct mixer *mixer, float val)
{
float level[AF_NCH];
int i;
diff --git a/audio/mixer.h b/audio/mixer.h
index a636a2b418..9fbb4bcdca 100644
--- a/audio/mixer.h
+++ b/audio/mixer.h
@@ -28,37 +28,23 @@ enum {
SOFTVOL_AUTO = 2,
};
-typedef struct mixer {
- 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;
-} mixer_t;
+struct MPOpts;
+struct ao;
+struct af_stream;
+struct mixer;
-void mixer_init(struct mixer *mixer, struct MPOpts *opts);
+struct mixer *mixer_init(void *talloc_ctx, struct MPOpts *opts);
void mixer_reinit_audio(struct mixer *mixer, struct ao *ao, struct af_stream *af);
void mixer_uninit_audio(struct mixer *mixer);
-void mixer_getvolume(mixer_t *mixer, float *l, float *r);
-void mixer_setvolume(mixer_t *mixer, float l, float r);
-void mixer_incvolume(mixer_t *mixer);
-void mixer_decvolume(mixer_t *mixer);
-void mixer_getbothvolume(mixer_t *mixer, float *b);
-void mixer_setmute(mixer_t *mixer, bool mute);
-bool mixer_getmute(mixer_t *mixer);
-void mixer_getbalance(mixer_t *mixer, float *bal);
-void mixer_setbalance(mixer_t *mixer, float bal);
+void mixer_getvolume(struct mixer *mixer, float *l, float *r);
+void mixer_setvolume(struct mixer *mixer, float l, float r);
+void mixer_incvolume(struct mixer *mixer);
+void mixer_decvolume(struct mixer *mixer);
+void mixer_getbothvolume(struct mixer *mixer, float *b);
+void mixer_setmute(struct mixer *mixer, bool mute);
+bool mixer_getmute(struct mixer *mixer);
+void mixer_getbalance(struct mixer *mixer, float *bal);
+void mixer_setbalance(struct mixer *mixer, float bal);
char *mixer_get_volume_restore_data(struct mixer *mixer);
#endif /* MPLAYER_MIXER_H */
diff --git a/audio/out/ao_alsa.c b/audio/out/ao_alsa.c
index 2db5041b95..ff931e2a0b 100644
--- a/audio/out/ao_alsa.c
+++ b/audio/out/ao_alsa.c
@@ -38,7 +38,6 @@
#include "config.h"
#include "mpvcore/options.h"
#include "mpvcore/m_option.h"
-#include "audio/mixer.h"
#include "mpvcore/mp_msg.h"
#define ALSA_PCM_NEW_HW_PARAMS_API
diff --git a/audio/out/ao_oss.c b/audio/out/ao_oss.c
index 79b96c7bc1..0890f11e0a 100644
--- a/audio/out/ao_oss.c
+++ b/audio/out/ao_oss.c
@@ -36,7 +36,6 @@
#include "config.h"
#include "mpvcore/options.h"
#include "mpvcore/mp_msg.h"
-#include "audio/mixer.h"
#ifdef HAVE_SYS_SOUNDCARD_H
#include <sys/soundcard.h>
diff --git a/mpvcore/command.c b/mpvcore/command.c
index cb1bdd9678..a2de363b3d 100644
--- a/mpvcore/command.c
+++ b/mpvcore/command.c
@@ -764,17 +764,17 @@ static int mp_property_volume(m_option_t *prop, int action, void *arg,
{
switch (action) {
case M_PROPERTY_GET:
- mixer_getbothvolume(&mpctx->mixer, arg);
+ mixer_getbothvolume(mpctx->mixer, arg);
return M_PROPERTY_OK;
case M_PROPERTY_SET:
- mixer_setvolume(&mpctx->mixer, *(float *) arg, *(float *) arg);
+ mixer_setvolume(mpctx->mixer, *(float *) arg, *(float *) arg);
return M_PROPERTY_OK;
case M_PROPERTY_SWITCH: {
struct m_property_switch_arg *sarg = arg;
if (sarg->inc <= 0)
- mixer_decvolume(&mpctx->mixer);
+ mixer_decvolume(mpctx->mixer);
else
- mixer_incvolume(&mpctx->mixer);
+ mixer_incvolume(mpctx->mixer);
return M_PROPERTY_OK;
}
}
@@ -787,10 +787,10 @@ static int mp_property_mute(m_option_t *prop, int action, void *arg,
{
switch (action) {
case M_PROPERTY_SET:
- mixer_setmute(&mpctx->mixer, *(int *) arg);
+ mixer_setmute(mpctx->mixer, *(int *) arg);
return M_PROPERTY_OK;
case M_PROPERTY_GET:
- *(int *)arg = mixer_getmute(&mpctx->mixer);
+ *(int *)arg = mixer_getmute(mpctx->mixer);
return M_PROPERTY_OK;
}
return M_PROPERTY_NOT_IMPLEMENTED;
@@ -801,7 +801,7 @@ static int mp_property_volrestore(m_option_t *prop, int action,
{
switch (action) {
case M_PROPERTY_GET: {
- char *s = mixer_get_volume_restore_data(&mpctx->mixer);
+ char *s = mixer_get_volume_restore_data(mpctx->mixer);
*(char **)arg = s;
return s ? M_PROPERTY_OK : M_PROPERTY_UNAVAILABLE;
}
@@ -906,11 +906,11 @@ static int mp_property_balance(m_option_t *prop, int action, void *arg,
switch (action) {
case M_PROPERTY_GET:
- mixer_getbalance(&mpctx->mixer, arg);
+ mixer_getbalance(mpctx->mixer, arg);
return M_PROPERTY_OK;
case M_PROPERTY_PRINT: {
char **str = arg;
- mixer_getbalance(&mpctx->mixer, &bal);
+ mixer_getbalance(mpctx->mixer, &bal);
if (bal == 0.f)
*str = talloc_strdup(NULL, "center");
else if (bal == -1.f)
@@ -925,7 +925,7 @@ static int mp_property_balance(m_option_t *prop, int action, void *arg,
return M_PROPERTY_OK;
}
case M_PROPERTY_SET:
- mixer_setbalance(&mpctx->mixer, *(float *)arg);
+ mixer_setbalance(mpctx->mixer, *(float *)arg);
return M_PROPERTY_OK;
}
return M_PROPERTY_NOT_IMPLEMENTED;
diff --git a/mpvcore/mp_core.h b/mpvcore/mp_core.h
index 8f57a65edf..98096aa5fe 100644
--- a/mpvcore/mp_core.h
+++ b/mpvcore/mp_core.h
@@ -22,7 +22,6 @@
#include <stdbool.h>
#include "mpvcore/options.h"
-#include "audio/mixer.h"
#include "demux/demux.h"
// definitions used internally by the core player code
@@ -179,7 +178,7 @@ typedef struct MPContext {
// demuxer defines metadata), or special purpose demuxers like TV.
struct demuxer *master_demuxer;
- mixer_t mixer;
+ struct mixer *mixer;
struct ao *ao;
struct vo *video_out;
diff --git a/mpvcore/mplayer.c b/mpvcore/mplayer.c
index 00229364e6..dc4322d4e3 100644
--- a/mpvcore/mplayer.c
+++ b/mpvcore/mplayer.c
@@ -449,7 +449,7 @@ void uninit_player(struct MPContext *mpctx, unsigned int mask)
if (mask & INITIALIZED_ACODEC) {
mpctx->initialized_flags &= ~INITIALIZED_ACODEC;
- mixer_uninit_audio(&mpctx->mixer);
+ mixer_uninit_audio(mpctx->mixer);
if (mpctx->sh_audio)
uninit_audio(mpctx->sh_audio);
cleanup_demux_stream(mpctx, STREAM_AUDIO);
@@ -1608,7 +1608,7 @@ static int recreate_audio_filters(struct MPContext *mpctx)
return -1;
}
- mixer_reinit_audio(&mpctx->mixer, mpctx->ao, mpctx->sh_audio->afilter);
+ mixer_reinit_audio(mpctx->mixer, mpctx->ao, mpctx->sh_audio->afilter);
return 0;
}
@@ -4826,7 +4826,7 @@ static int mpv_main(int argc, char *argv[])
init_libav();
GetCpuCaps(&gCpuCaps);
screenshot_init(mpctx);
- mixer_init(&mpctx->mixer, opts);
+ mpctx->mixer = mixer_init(mpctx, opts);
// Preparse the command line
m_config_preparse_command_line(mpctx->mconfig, argc, argv);