summaryrefslogtreecommitdiffstats
path: root/libao2
diff options
context:
space:
mode:
authorwm4 <wm4@mplayer2.org>2012-04-28 00:39:19 +0200
committerwm4 <wm4@mplayer2.org>2012-04-28 00:54:26 +0200
commit87f4cafe9c0881743d1117c2e8cd7e3376e33302 (patch)
treef41caa5aad8969d769a777c0a7912751721a66bd /libao2
parent1324eaece08d84fbe3eb539642dba99b74dd1c07 (diff)
parentb711624ef350d1e971f5fcc57eb4af9f74233d2a (diff)
downloadmpv-87f4cafe9c0881743d1117c2e8cd7e3376e33302.tar.bz2
mpv-87f4cafe9c0881743d1117c2e8cd7e3376e33302.tar.xz
Merge remote-tracking branch 'origin/master'
Conflicts: command.c libao2/ao_alsa.c libao2/ao_dsound.c libao2/ao_pulse.c libao2/audio_out.h mixer.c mixer.h mplayer.c Replace my mixer changes with uau's implementation, which is based on my code.
Diffstat (limited to 'libao2')
-rw-r--r--libao2/ao_alsa.c33
-rw-r--r--libao2/ao_oss.c16
-rw-r--r--libao2/ao_pulse.c47
-rw-r--r--libao2/ao_sgi.c7
-rw-r--r--libao2/ao_sun.c5
-rw-r--r--libao2/audio_out.c4
-rw-r--r--libao2/audio_out.h61
7 files changed, 67 insertions, 106 deletions
diff --git a/libao2/ao_alsa.c b/libao2/ao_alsa.c
index 65e7fda178..ff837e7d30 100644
--- a/libao2/ao_alsa.c
+++ b/libao2/ao_alsa.c
@@ -97,15 +97,11 @@ static void alsa_error_handler(const char *file, int line, const char *function,
static int control(int cmd, void *arg)
{
switch(cmd) {
- case AOCONTROL_QUERY_FORMAT:
- return CONTROL_TRUE;
case AOCONTROL_GET_MUTE:
case AOCONTROL_SET_MUTE:
case AOCONTROL_GET_VOLUME:
case AOCONTROL_SET_VOLUME:
{
- ao_control_vol_t *vol = (ao_control_vol_t *)arg;
-
int err;
snd_mixer_t *handle;
snd_mixer_elem_t *elem;
@@ -189,6 +185,7 @@ static int control(int cmd, void *arg)
switch (cmd) {
case AOCONTROL_SET_VOLUME: {
+ ao_control_vol_t *vol = arg;
set_vol = vol->left / f_multi + pmin + 0.5;
//setting channels
@@ -211,6 +208,7 @@ static int control(int cmd, void *arg)
break;
}
case AOCONTROL_GET_VOLUME: {
+ ao_control_vol_t *vol = arg;
snd_mixer_selem_get_playback_volume(elem, SND_MIXER_SCHN_FRONT_LEFT, &get_vol);
vol->left = (get_vol - pmin) * f_multi;
snd_mixer_selem_get_playback_volume(elem, SND_MIXER_SCHN_FRONT_RIGHT, &get_vol);
@@ -219,28 +217,29 @@ static int control(int cmd, void *arg)
break;
}
case AOCONTROL_SET_MUTE: {
+ bool *mute = arg;
if (!snd_mixer_selem_has_playback_switch(elem))
goto mixer_error;
- bool m_l = vol->left == 0.0f, m_r = vol->right == 0.0f;
- if (snd_mixer_selem_has_playback_switch_joined(elem)) {
- m_l = m_l || m_r;
- } else {
- snd_mixer_selem_set_playback_switch(elem, SND_MIXER_SCHN_FRONT_RIGHT, !m_r);
+ if (!snd_mixer_selem_has_playback_switch_joined(elem)) {
+ snd_mixer_selem_set_playback_switch(
+ elem, SND_MIXER_SCHN_FRONT_RIGHT, !*mute);
}
- snd_mixer_selem_set_playback_switch(elem, SND_MIXER_SCHN_FRONT_LEFT, !m_l);
+ snd_mixer_selem_set_playback_switch(elem, SND_MIXER_SCHN_FRONT_LEFT,
+ !*mute);
break;
}
case AOCONTROL_GET_MUTE: {
+ bool *mute = arg;
if (!snd_mixer_selem_has_playback_switch(elem))
goto mixer_error;
int tmp = 1;
- snd_mixer_selem_get_playback_switch(elem, SND_MIXER_SCHN_FRONT_LEFT, &tmp);
- vol->left = tmp ? 1.0f : 0.0f;
- if (snd_mixer_selem_has_playback_switch_joined(elem)) {
- vol->right = vol->left;
- } else {
- snd_mixer_selem_get_playback_switch(elem, SND_MIXER_SCHN_FRONT_RIGHT, &tmp);
- vol->right = tmp ? 1.0f : 0.0f;
+ snd_mixer_selem_get_playback_switch(elem, SND_MIXER_SCHN_FRONT_LEFT,
+ &tmp);
+ *mute = !tmp;
+ if (!snd_mixer_selem_has_playback_switch_joined(elem)) {
+ snd_mixer_selem_get_playback_switch(
+ elem, SND_MIXER_SCHN_FRONT_RIGHT, &tmp);
+ *mute &= !tmp;
}
break;
}
diff --git a/libao2/ao_oss.c b/libao2/ao_oss.c
index 82a0dd51e5..9290a73380 100644
--- a/libao2/ao_oss.c
+++ b/libao2/ao_oss.c
@@ -179,22 +179,6 @@ static int volume_oss4(ao_control_vol_t *vol, int cmd) {
// to set/get/query special features/parameters
static int control(int cmd,void *arg){
switch(cmd){
- case AOCONTROL_SET_DEVICE:
- dsp=(char*)arg;
- return CONTROL_OK;
- case AOCONTROL_GET_DEVICE:
- *(char**)arg=dsp;
- return CONTROL_OK;
-#ifdef SNDCTL_DSP_GETFMTS
- case AOCONTROL_QUERY_FORMAT:
- {
- int format;
- if (!ioctl(audio_fd, SNDCTL_DSP_GETFMTS, &format))
- if ((unsigned int)format & (unsigned long)arg)
- return CONTROL_TRUE;
- return CONTROL_FALSE;
- }
-#endif
case AOCONTROL_GET_VOLUME:
case AOCONTROL_SET_VOLUME:
{
diff --git a/libao2/ao_pulse.c b/libao2/ao_pulse.c
index 5e71f7bf7e..ed6e08286a 100644
--- a/libao2/ao_pulse.c
+++ b/libao2/ao_pulse.c
@@ -23,7 +23,6 @@
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
-#include <stdlib.h>
#include <pulse/pulseaudio.h>
@@ -422,18 +421,16 @@ static void info_func(struct pa_context *c, const struct pa_sink_input_info *i,
pa_threaded_mainloop_signal(priv->mainloop, 0);
}
-static int control(struct ao *ao, int cmd, void *arg)
+static int control(struct ao *ao, enum aocontrol cmd, void *arg)
{
struct priv *priv = ao->priv;
switch (cmd) {
- case AOCONTROL_GET_MUTE: // fallthrough
+ case AOCONTROL_GET_MUTE:
case AOCONTROL_GET_VOLUME: {
- ao_control_vol_t *vol = arg;
uint32_t devidx = pa_stream_get_index(priv->stream);
pa_threaded_mainloop_lock(priv->mainloop);
if (!waitop(priv, pa_context_get_sink_input_info(priv->context, devidx,
- info_func, ao)))
- {
+ info_func, ao))) {
GENERIC_ERR_MSG(priv->context,
"pa_stream_get_sink_input_info() failed");
return CONTROL_ERROR;
@@ -442,6 +439,7 @@ static int control(struct ao *ao, int cmd, void *arg)
// we naively copied the struct, without updating pointers etc.
// Pointers might point to invalid data, accessors might fail.
if (cmd == AOCONTROL_GET_VOLUME) {
+ ao_control_vol_t *vol = arg;
if (priv->pi.volume.channels != 2)
vol->left = vol->right =
pa_cvolume_avg(&priv->pi.volume) * 100 / PA_VOLUME_NORM;
@@ -450,30 +448,30 @@ static int control(struct ao *ao, int cmd, void *arg)
vol->right = priv->pi.volume.values[1] * 100 / PA_VOLUME_NORM;
}
} else if (cmd == AOCONTROL_GET_MUTE) {
- vol->left = vol->right = priv->pi.mute ? 0.0f : 1.0f;
+ bool *mute = arg;
+ *mute = priv->pi.mute;
}
-
return CONTROL_OK;
- }
+ }
- case AOCONTROL_SET_MUTE: // fallthrough
+ case AOCONTROL_SET_MUTE:
case AOCONTROL_SET_VOLUME: {
- const ao_control_vol_t *vol = arg;
pa_operation *o;
- struct pa_cvolume volume;
-
- pa_cvolume_reset(&volume, ao->channels);
- if (volume.channels != 2)
- pa_cvolume_set(&volume, volume.channels,
- (pa_volume_t)vol->left * PA_VOLUME_NORM / 100);
- else {
- volume.values[0] = (pa_volume_t)vol->left * PA_VOLUME_NORM / 100;
- volume.values[1] = (pa_volume_t)vol->right * PA_VOLUME_NORM / 100;
- }
pa_threaded_mainloop_lock(priv->mainloop);
uint32_t stream_index = pa_stream_get_index(priv->stream);
if (cmd == AOCONTROL_SET_VOLUME) {
+ const ao_control_vol_t *vol = arg;
+ struct pa_cvolume volume;
+
+ pa_cvolume_reset(&volume, ao->channels);
+ if (volume.channels != 2)
+ pa_cvolume_set(&volume, volume.channels,
+ vol->left * PA_VOLUME_NORM / 100);
+ else {
+ volume.values[0] = vol->left * PA_VOLUME_NORM / 100;
+ volume.values[1] = vol->right * PA_VOLUME_NORM / 100;
+ }
o = pa_context_set_sink_input_volume(priv->context, stream_index,
&volume, NULL, NULL);
if (!o) {
@@ -483,9 +481,9 @@ static int control(struct ao *ao, int cmd, void *arg)
return CONTROL_ERROR;
}
} else if (cmd == AOCONTROL_SET_MUTE) {
- int mute = vol->left == 0.0f || vol->right == 0.0f;
+ const bool *mute = arg;
o = pa_context_set_sink_input_mute(priv->context, stream_index,
- mute, NULL, NULL);
+ *mute, NULL, NULL);
if (!o) {
pa_threaded_mainloop_unlock(priv->mainloop);
GENERIC_ERR_MSG(priv->context,
@@ -498,8 +496,7 @@ static int control(struct ao *ao, int cmd, void *arg)
pa_operation_unref(o);
pa_threaded_mainloop_unlock(priv->mainloop);
return CONTROL_OK;
- }
-
+ }
default:
return CONTROL_UNKNOWN;
}
diff --git a/libao2/ao_sgi.c b/libao2/ao_sgi.c
index 40bc6b9177..492c8ff3ba 100644
--- a/libao2/ao_sgi.c
+++ b/libao2/ao_sgi.c
@@ -118,13 +118,6 @@ static int control(int cmd, void *arg){
mp_tmsg(MSGT_AO, MSGL_INFO, "[AO SGI] control.\n");
- switch(cmd) {
- case AOCONTROL_QUERY_FORMAT:
- /* Do not reject any format: return the closest matching
- * format if the request is not supported natively. */
- return CONTROL_TRUE;
- }
-
return CONTROL_UNKNOWN;
}
diff --git a/libao2/ao_sun.c b/libao2/ao_sun.c
index ef8417c5f9..ecdb23d4af 100644
--- a/libao2/ao_sun.c
+++ b/libao2/ao_sun.c
@@ -402,11 +402,6 @@ static void setup_device_paths(void)
// to set/get/query special features/parameters
static int control(int cmd,void *arg){
switch(cmd){
- case AOCONTROL_SET_DEVICE:
- audio_dev=(char*)arg;
- return CONTROL_OK;
- case AOCONTROL_QUERY_FORMAT:
- return CONTROL_TRUE;
case AOCONTROL_GET_VOLUME:
{
int fd;
diff --git a/libao2/audio_out.c b/libao2/audio_out.c
index 6130e2ed33..268c17d749 100644
--- a/libao2/audio_out.c
+++ b/libao2/audio_out.c
@@ -232,7 +232,7 @@ int ao_play(struct ao *ao, void *data, int len, int flags)
return ao->driver->play(ao, data, len, flags);
}
-int ao_control(struct ao *ao, int cmd, void *arg)
+int ao_control(struct ao *ao, enum aocontrol cmd, void *arg)
{
if (ao->driver->control)
return ao->driver->control(ao, cmd, arg);
@@ -299,7 +299,7 @@ int old_ao_play(struct ao *ao, void *data, int len, int flags)
return ao->driver->old_functions->play(data, len, flags);
}
-int old_ao_control(struct ao *ao, int cmd, void *arg)
+int old_ao_control(struct ao *ao, enum aocontrol cmd, void *arg)
{
return ao->driver->old_functions->control(cmd, arg);
}
diff --git a/libao2/audio_out.h b/libao2/audio_out.h
index aafedbf178..955376d460 100644
--- a/libao2/audio_out.h
+++ b/libao2/audio_out.h
@@ -23,6 +23,30 @@
#include "bstr.h"
+#define CONTROL_OK 1
+#define CONTROL_TRUE 1
+#define CONTROL_FALSE 0
+#define CONTROL_UNKNOWN -1
+#define CONTROL_ERROR -2
+#define CONTROL_NA -3
+
+enum aocontrol {
+ // _VOLUME commands take struct ao_control_vol pointer for input/output.
+ // If there's only one volume, SET should use average of left/right.
+ AOCONTROL_GET_VOLUME,
+ AOCONTROL_SET_VOLUME,
+ // _MUTE commands take a pointer to bool
+ AOCONTROL_GET_MUTE,
+ AOCONTROL_SET_MUTE,
+};
+
+#define AOPLAY_FINAL_CHUNK 1
+
+typedef struct ao_control_vol {
+ float left;
+ float right;
+} ao_control_vol_t;
+
typedef struct ao_info {
/* driver name ("Matrox Millennium G200/G400" */
const char *name;
@@ -53,7 +77,7 @@ struct ao_driver {
bool is_new;
const struct ao_info *info;
const struct ao_old_functions *old_functions;
- int (*control)(struct ao *ao, int cmd, void *arg);
+ int (*control)(struct ao *ao, enum aocontrol cmd, void *arg);
int (*init)(struct ao *ao, char *params);
void (*uninit)(struct ao *ao, bool cut_audio);
void (*reset)(struct ao*ao);
@@ -89,49 +113,18 @@ extern char *ao_subdevice;
void list_audio_out(void);
-#define CONTROL_OK 1
-#define CONTROL_TRUE 1
-#define CONTROL_FALSE 0
-#define CONTROL_UNKNOWN -1
-#define CONTROL_ERROR -2
-#define CONTROL_NA -3
-
-#define AOCONTROL_SET_DEVICE 1
-#define AOCONTROL_GET_DEVICE 2
-#define AOCONTROL_QUERY_FORMAT 3 /* test for availabilty of a format */
-// Uses ao_control_vol_t* as arg.
-// If the volume controls are joint, the average of both volumes should be used.
-#define AOCONTROL_GET_VOLUME 4
-#define AOCONTROL_SET_VOLUME 5
-// Uses ao_control_vol_t* as arg.
-// left==0.0f means muted, left==1.0f means not muted (right likewise)
-// Other values between are invalid.
-// If the mtue controls are joint, the output should be muted if either of the
-// two channels are muted.
-#define AOCONTROL_GET_MUTE 6
-#define AOCONTROL_SET_MUTE 7
-#define AOCONTROL_SET_PLUGIN_DRIVER 8
-#define AOCONTROL_SET_PLUGIN_LIST 9
-
-#define AOPLAY_FINAL_CHUNK 1
-
-typedef struct ao_control_vol {
- float left;
- float right;
-} ao_control_vol_t;
-
struct ao *ao_create(struct MPOpts *opts, struct input_ctx *input);
void ao_init(struct ao *ao, char **ao_list);
void ao_uninit(struct ao *ao, bool cut_audio);
int ao_play(struct ao *ao, void *data, int len, int flags);
-int ao_control(struct ao *ao, int cmd, void *arg);
+int ao_control(struct ao *ao, enum aocontrol cmd, void *arg);
double ao_get_delay(struct ao *ao);
int ao_get_space(struct ao *ao);
void ao_reset(struct ao *ao);
void ao_pause(struct ao *ao);
void ao_resume(struct ao *ao);
-int old_ao_control(struct ao *ao, int cmd, void *arg);
+int old_ao_control(struct ao *ao, enum aocontrol cmd, void *arg);
int old_ao_init(struct ao *ao, char *params);
void old_ao_uninit(struct ao *ao, bool cut_audio);
void old_ao_reset(struct ao*ao);