summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Kocialkowski <contact@paulk.fr>2012-10-13 12:13:58 +0200
committerPaul Kocialkowski <contact@paulk.fr>2012-10-13 12:13:58 +0200
commit9b78c141abe0dcac335e5423f5ebdd05b481d1cc (patch)
tree1918be6c1c44afebf94ea4629a9350b57cc050b8
parent8aed9f23e589576d5bcc156f1f7d7544825fe5c2 (diff)
downloadhardware_tinyalsa-audio-9b78c141abe0dcac335e5423f5ebdd05b481d1cc.zip
hardware_tinyalsa-audio-9b78c141abe0dcac335e5423f5ebdd05b481d1cc.tar.gz
hardware_tinyalsa-audio-9b78c141abe0dcac335e5423f5ebdd05b481d1cc.tar.bz2
Volume and mic mute control handling
Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
-rw-r--r--audio_hw.c89
-rw-r--r--audio_hw.h6
-rw-r--r--audio_in.c17
-rw-r--r--audio_out.c20
-rw-r--r--mixer.c8
-rw-r--r--mixer.h3
6 files changed, 122 insertions, 21 deletions
diff --git a/audio_hw.c b/audio_hw.c
index 954c6ea..e2cb1c3 100644
--- a/audio_hw.c
+++ b/audio_hw.c
@@ -36,33 +36,33 @@
static uint32_t audio_hw_get_supported_devices(const struct audio_hw_device *dev)
{
- struct tinyalsa_audio_device *tinyalsa_audio_device;
+ struct tinyalsa_audio_device *device;
LOGD("%s(%p)", __func__, dev);
if(dev == NULL)
return -1;
- tinyalsa_audio_device = (struct tinyalsa_audio_device *) dev;
+ device = (struct tinyalsa_audio_device *) dev;
- if(tinyalsa_audio_device->mixer == NULL)
+ if(device->mixer == NULL)
return -1;
- return (uint32_t) tinyalsa_mixer_get_supported_devices(tinyalsa_audio_device->mixer);
+ return (uint32_t) tinyalsa_mixer_get_supported_devices(device->mixer);
}
static int audio_hw_init_check(const struct audio_hw_device *dev)
{
- struct tinyalsa_audio_device *tinyalsa_audio_device;
+ struct tinyalsa_audio_device *device;
LOGD("%s(%p)", __func__, dev);
if(dev == NULL)
return -1;
- tinyalsa_audio_device = (struct tinyalsa_audio_device *) dev;
+ device = (struct tinyalsa_audio_device *) dev;
- if(tinyalsa_audio_device->mixer == NULL)
+ if(device->mixer == NULL)
return -1;
return 0;
@@ -70,37 +70,104 @@ static int audio_hw_init_check(const struct audio_hw_device *dev)
static int audio_hw_set_voice_volume(struct audio_hw_device *dev, float volume)
{
+ struct tinyalsa_audio_device *device;
+
LOGD("%s(%p, %f)", __func__, dev, volume);
- return -ENOSYS;
+ if(dev == NULL)
+ return -1;
+
+ device = (struct tinyalsa_audio_device *) dev;
+
+ if(device->mixer == NULL)
+ return -1;
+
+ if(device->mode == AUDIO_MODE_IN_CALL) {
+ // FIXME: Select the device from ril interface
+ tinyalsa_mixer_set_voice_volume(device->mixer,
+ AUDIO_DEVICE_IN_DEFAULT, device->mode, volume);
+ }
+
+ return 0;
}
static int audio_hw_set_master_volume(struct audio_hw_device *dev, float volume)
{
+ struct tinyalsa_audio_device *device;
+
LOGD("%s(%p, %f)", __func__, dev, volume);
- return -ENOSYS;
+ if(dev == NULL)
+ return -1;
+
+ device = (struct tinyalsa_audio_device *) dev;
+
+ if(device->mixer == NULL)
+ return -1;
+
+ tinyalsa_mixer_set_master_volume(device->mixer, volume);
+
+ return 0;
}
static int audio_hw_set_mode(struct audio_hw_device *dev, int mode)
{
+ struct tinyalsa_audio_device *device;
+
LOGD("%s(%p, %d)", __func__, dev, mode);
+ if(dev == NULL)
+ return -1;
+
+ device = (struct tinyalsa_audio_device *) dev;
+
+ device->mode = mode;
+
+ // TODO: If mode changed, change routing
+
return 0;
}
static int audio_hw_set_mic_mute(struct audio_hw_device *dev, bool state)
{
+ struct tinyalsa_audio_device *device;
+
LOGD("%s(%p, %d)", __func__, dev, state);
- return -ENOSYS;
+ if(dev == NULL)
+ return -1;
+
+ device = (struct tinyalsa_audio_device *) dev;
+
+ if(device->mixer == NULL)
+ return -1;
+
+ if(device->mic_mute != state) {
+ device->mic_mute = state;
+
+ // FIXME: Select the device from input if mode isn't in-call,
+ // select it from ril interface if mode is in-call
+ tinyalsa_mixer_set_mic_mute(device->mixer,
+ AUDIO_DEVICE_IN_DEFAULT, device->mode, state);
+ }
+
+ return 0;
}
static int audio_hw_get_mic_mute(const struct audio_hw_device *dev, bool *state)
{
+ struct tinyalsa_audio_device *device;
+
LOGD("%s(%p, %p)", __func__, dev, state);
- return -ENOSYS;
+ if(dev == NULL)
+ return -1;
+
+ device = (struct tinyalsa_audio_device *) dev;
+
+ *state = device->mic_mute;
+
+ return 0;
}
static int audio_hw_set_parameters(struct audio_hw_device *dev,
diff --git a/audio_hw.h b/audio_hw.h
index e04af95..7343fb2 100644
--- a/audio_hw.h
+++ b/audio_hw.h
@@ -24,12 +24,12 @@
struct tinyalsa_audio_stream_out {
struct audio_stream_out stream;
- struct tinyalsa_audio_device *dev;
+ struct tinyalsa_audio_device *device;
};
struct tinyalsa_audio_stream_in {
struct audio_stream_in stream;
- struct tinyalsa_audio_device *dev;
+ struct tinyalsa_audio_device *device;
};
struct tinyalsa_audio_device {
@@ -39,6 +39,8 @@ struct tinyalsa_audio_device {
struct tinyalsa_audio_stream_in *stream_in;
struct tinyalsa_mixer *mixer;
+ audio_mode_t mode;
+ int mic_mute;
};
int audio_hw_open_output_stream(struct audio_hw_device *dev,
diff --git a/audio_in.c b/audio_in.c
index e416de8..44c47e8 100644
--- a/audio_in.c
+++ b/audio_in.c
@@ -30,6 +30,7 @@
#define EFFECT_UUID_NULL EFFECT_UUID_NULL_IN
#define EFFECT_UUID_NULL_STR EFFECT_UUID_NULL_STR_IN
#include "audio_hw.h"
+#include "mixer.h"
/*
* Functions
@@ -100,8 +101,22 @@ static char *audio_in_get_parameters(const struct audio_stream *stream,
static int audio_in_set_gain(struct audio_stream_in *stream, float gain)
{
+ struct tinyalsa_audio_stream_in *stream_in;
+
LOGD("%s(%p, %f)", __func__, stream, gain);
+ if(stream == NULL)
+ return -1;
+
+ stream_in = (struct tinyalsa_audio_stream_in *) stream;
+
+ if(stream_in->device == NULL || stream_in->device->mixer == NULL)
+ return -1;
+
+ // FIXME: Select the device
+ tinyalsa_mixer_set_input_gain(stream_in->device->mixer,
+ AUDIO_DEVICE_IN_DEFAULT, stream_in->device->mode, gain);
+
return 0;
}
@@ -168,7 +183,7 @@ int audio_hw_open_input_stream(struct audio_hw_device *dev,
if(tinyalsa_audio_stream_in == NULL)
return -ENOMEM;
- tinyalsa_audio_stream_in->dev = tinyalsa_audio_device;
+ tinyalsa_audio_stream_in->device = tinyalsa_audio_device;
stream = &(tinyalsa_audio_stream_in->stream);
stream->common.get_sample_rate = audio_in_get_sample_rate;
diff --git a/audio_out.c b/audio_out.c
index 2ea2db8..538438b 100644
--- a/audio_out.c
+++ b/audio_out.c
@@ -30,6 +30,7 @@
#define EFFECT_UUID_NULL EFFECT_UUID_NULL_OUT
#define EFFECT_UUID_NULL_STR EFFECT_UUID_NULL_STR_OUT
#include "audio_hw.h"
+#include "mixer.h"
/*
* Functions
@@ -107,8 +108,25 @@ static uint32_t audio_out_get_latency(const struct audio_stream_out *stream)
static int audio_out_set_volume(struct audio_stream_out *stream, float left,
float right)
{
+ struct tinyalsa_audio_stream_out *stream_out;
+ float volume;
+
LOGD("%s(%p, %f, %f)", __func__, stream, left, right);
+ if(stream == NULL)
+ return -1;
+
+ stream_out = (struct tinyalsa_audio_stream_out *) stream;
+
+ if(stream_out->device == NULL || stream_out->device->mixer == NULL)
+ return -1;
+
+ volume = (left + right) / 2;
+
+ // FIXME: Select the device
+ tinyalsa_mixer_set_output_volume(stream_out->device->mixer,
+ AUDIO_DEVICE_IN_DEFAULT, stream_out->device->mode, volume);
+
return 0;
}
@@ -176,7 +194,7 @@ int audio_hw_open_output_stream(struct audio_hw_device *dev,
if(tinyalsa_audio_stream_out == NULL)
return -ENOMEM;
- tinyalsa_audio_stream_out->dev = tinyalsa_audio_device;
+ tinyalsa_audio_stream_out->device = tinyalsa_audio_device;
stream = &(tinyalsa_audio_stream_out->stream);
stream->common.get_sample_rate = audio_out_get_sample_rate;
diff --git a/mixer.c b/mixer.c
index 1781215..35c289d 100644
--- a/mixer.c
+++ b/mixer.c
@@ -953,12 +953,12 @@ int tinyalsa_mixer_set_output_volume(struct tinyalsa_mixer *mixer,
"output-volume", volume);
}
-int tinyalsa_mixer_set_master_volume(struct tinyalsa_mixer *mixer,
- audio_devices_t device, audio_mode_t mode, float volume)
+int tinyalsa_mixer_set_master_volume(struct tinyalsa_mixer *mixer, float volume)
{
- LOGD("%s(%p, %x, %x, %f)", __func__, mixer, device, mode, volume);
+ LOGD("%s(%p, %f)", __func__, mixer, volume);
- return tinyalsa_mixer_set_device_volume_with_attr(mixer, device, mode,
+ return tinyalsa_mixer_set_device_volume_with_attr(mixer,
+ AUDIO_DEVICE_OUT_DEFAULT, AUDIO_MODE_NORMAL,
"master-volume", volume);
}
diff --git a/mixer.h b/mixer.h
index 669136c..3b1e19b 100644
--- a/mixer.h
+++ b/mixer.h
@@ -104,8 +104,7 @@ int tinyalsa_mixer_set_input_gain(struct tinyalsa_mixer *mixer,
audio_devices_t device, audio_mode_t mode, float gain);
int tinyalsa_mixer_set_mic_mute(struct tinyalsa_mixer *mixer,
audio_devices_t device, audio_mode_t mode, int mute);
-int tinyalsa_mixer_set_master_volume(struct tinyalsa_mixer *mixer,
- audio_devices_t device, audio_mode_t mode, float volume);
+int tinyalsa_mixer_set_master_volume(struct tinyalsa_mixer *mixer, float volume);
int tinyalsa_mixer_set_output_volume(struct tinyalsa_mixer *mixer,
audio_devices_t device, audio_mode_t mode, float volume);