Skip to content

Commit

Permalink
audio: more dumb changes for API 2
Browse files Browse the repository at this point in the history
  • Loading branch information
Daz Jones committed Jan 25, 2013
1 parent afa4ff6 commit 45460ad
Showing 1 changed file with 117 additions and 47 deletions.
164 changes: 117 additions & 47 deletions audio/audio_hw_hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,74 @@ struct qcom_stream_in {
AudioStreamIn *qcom_in;
};

enum {
HAL_API_REV_1_0,
HAL_API_REV_2_0,
HAL_API_REV_NUM
} hal_api_rev;

static uint32_t audio_device_conv_table[][HAL_API_REV_NUM] =
{
/* output devices */
{ AudioSystem::DEVICE_OUT_EARPIECE, AUDIO_DEVICE_OUT_EARPIECE },
{ AudioSystem::DEVICE_OUT_SPEAKER, AUDIO_DEVICE_OUT_SPEAKER },
{ AudioSystem::DEVICE_OUT_WIRED_HEADSET, AUDIO_DEVICE_OUT_WIRED_HEADSET },
{ AudioSystem::DEVICE_OUT_WIRED_HEADPHONE, AUDIO_DEVICE_OUT_WIRED_HEADPHONE },
{ AudioSystem::DEVICE_OUT_BLUETOOTH_SCO, AUDIO_DEVICE_OUT_BLUETOOTH_SCO },
{ AudioSystem::DEVICE_OUT_BLUETOOTH_SCO_HEADSET, AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET },
{ AudioSystem::DEVICE_OUT_BLUETOOTH_SCO_CARKIT, AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT },
{ AudioSystem::DEVICE_OUT_BLUETOOTH_A2DP, AUDIO_DEVICE_OUT_BLUETOOTH_A2DP },
{ AudioSystem::DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES, AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES },
{ AudioSystem::DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER, AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER },
{ AudioSystem::DEVICE_OUT_AUX_DIGITAL, AUDIO_DEVICE_OUT_AUX_DIGITAL },
{ AudioSystem::DEVICE_OUT_ANLG_DOCK_HEADSET, AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET },
{ AudioSystem::DEVICE_OUT_DGTL_DOCK_HEADSET, AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET },
#ifdef QCOM_ANC_HEADSET_ENABLED
{ AudioSystem::DEVICE_OUT_ANC_HEADSET, AUDIO_DEVICE_OUT_ANC_HEADSET },
{ AudioSystem::DEVICE_OUT_ANC_HEADPHONE, AUDIO_DEVICE_OUT_ANC_HEADPHONE },
#endif
{ AudioSystem::DEVICE_OUT_DEFAULT, AUDIO_DEVICE_OUT_DEFAULT },
/* input devices */
{ AudioSystem::DEVICE_IN_COMMUNICATION, AUDIO_DEVICE_IN_COMMUNICATION },
{ AudioSystem::DEVICE_IN_AMBIENT, AUDIO_DEVICE_IN_AMBIENT },
{ AudioSystem::DEVICE_IN_BUILTIN_MIC, AUDIO_DEVICE_IN_BUILTIN_MIC },
{ AudioSystem::DEVICE_IN_BLUETOOTH_SCO_HEADSET, AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET },
{ AudioSystem::DEVICE_IN_WIRED_HEADSET, AUDIO_DEVICE_IN_WIRED_HEADSET },
{ AudioSystem::DEVICE_IN_AUX_DIGITAL, AUDIO_DEVICE_IN_AUX_DIGITAL },
{ AudioSystem::DEVICE_IN_VOICE_CALL, AUDIO_DEVICE_IN_VOICE_CALL },
{ AudioSystem::DEVICE_IN_BACK_MIC, AUDIO_DEVICE_IN_BACK_MIC },
#ifdef QCOM_ANC_HEADSET_ENABLED
{ AudioSystem::DEVICE_IN_ANC_HEADSET, AUDIO_DEVICE_IN_ANC_HEADSET },
#endif
{ AudioSystem::DEVICE_IN_DEFAULT, AUDIO_DEVICE_IN_DEFAULT },
};

static uint32_t convert_audio_device(uint32_t from_device, int from_rev, int to_rev)
{
const uint32_t k_num_devices = sizeof(audio_device_conv_table)/sizeof(uint32_t)/HAL_API_REV_NUM;
uint32_t to_device = AUDIO_DEVICE_NONE;
uint32_t in_bit = 0;

if (from_rev != HAL_API_REV_1_0) {
in_bit = from_device & AUDIO_DEVICE_BIT_IN;
from_device &= ~AUDIO_DEVICE_BIT_IN;
}

while (from_device) {
uint32_t i = 31 - __builtin_clz(from_device);
uint32_t cur_device = (1 << i) | in_bit;

for (i = 0; i < k_num_devices; i++) {
if (audio_device_conv_table[i][from_rev] == cur_device) {
to_device |= audio_device_conv_table[i][to_rev];
break;
}
}
from_device &= ~cur_device;
}
return to_device;
}

/** audio_stream_out implementation **/
static uint32_t out_get_sample_rate(const struct audio_stream *stream)
{
Expand Down Expand Up @@ -82,7 +150,7 @@ static audio_channel_mask_t out_get_channels(const struct audio_stream *stream)
{
const struct qcom_stream_out *out =
reinterpret_cast<const struct qcom_stream_out *>(stream);
return out->qcom_out->channels();
return (audio_channel_mask_t) out->qcom_out->channels();
}

static audio_format_t out_get_format(const struct audio_stream *stream)
Expand Down Expand Up @@ -120,15 +188,33 @@ static int out_set_parameters(struct audio_stream *stream, const char *kvpairs)
{
struct qcom_stream_out *out =
reinterpret_cast<struct qcom_stream_out *>(stream);
return out->qcom_out->setParameters(String8(kvpairs));
int val;
String8 s8 = String8(kvpairs);
AudioParameter parms = AudioParameter(String8(kvpairs));

if (parms.getInt(String8(AUDIO_PARAMETER_STREAM_ROUTING), val) == NO_ERROR) {
val = convert_audio_device(val, HAL_API_REV_2_0, HAL_API_REV_1_0);
parms.remove(String8(AUDIO_PARAMETER_STREAM_ROUTING));
parms.addInt(String8(AUDIO_PARAMETER_STREAM_ROUTING), val);
s8 = parms.toString();
}
return out->qcom_out->setParameters(s8);
}

static char * out_get_parameters(const struct audio_stream *stream, const char *keys)
{
const struct qcom_stream_out *out =
reinterpret_cast<const struct qcom_stream_out *>(stream);
String8 s8;
int val;
s8 = out->qcom_out->getParameters(String8(keys));
AudioParameter parms = AudioParameter(s8);
if (parms.getInt(String8(AUDIO_PARAMETER_STREAM_ROUTING), val) == NO_ERROR) {
val = convert_audio_device(val, HAL_API_REV_1_0, HAL_API_REV_2_0);
parms.remove(String8(AUDIO_PARAMETER_STREAM_ROUTING));
parms.addInt(String8(AUDIO_PARAMETER_STREAM_ROUTING), val);
s8 = parms.toString();
}
return strdup(s8.string());
}

Expand Down Expand Up @@ -262,7 +348,7 @@ static audio_channel_mask_t in_get_channels(const struct audio_stream *stream)
{
const struct qcom_stream_in *in =
reinterpret_cast<const struct qcom_stream_in *>(stream);
return in->qcom_in->channels();
return (audio_channel_mask_t) in->qcom_in->channels();
}

static audio_format_t in_get_format(const struct audio_stream *stream)
Expand Down Expand Up @@ -299,7 +385,17 @@ static int in_set_parameters(struct audio_stream *stream, const char *kvpairs)
{
struct qcom_stream_in *in =
reinterpret_cast<struct qcom_stream_in *>(stream);
return in->qcom_in->setParameters(String8(kvpairs));
int val;
AudioParameter parms = AudioParameter(String8(kvpairs));
String8 s8 = String8(kvpairs);

if (parms.getInt(String8(AUDIO_PARAMETER_STREAM_ROUTING), val) == NO_ERROR) {
val = convert_audio_device(val, HAL_API_REV_2_0, HAL_API_REV_1_0);
parms.remove(String8(AUDIO_PARAMETER_STREAM_ROUTING));
parms.addInt(String8(AUDIO_PARAMETER_STREAM_ROUTING), val);
s8 = parms.toString();
}
return in->qcom_in->setParameters(s8);
}

static char * in_get_parameters(const struct audio_stream *stream,
Expand All @@ -308,7 +404,15 @@ static char * in_get_parameters(const struct audio_stream *stream,
const struct qcom_stream_in *in =
reinterpret_cast<const struct qcom_stream_in *>(stream);
String8 s8;
int val;
s8 = in->qcom_in->getParameters(String8(keys));
AudioParameter parms = AudioParameter(s8);
if (parms.getInt(String8(AUDIO_PARAMETER_STREAM_ROUTING), val) == NO_ERROR) {
val = convert_audio_device(val, HAL_API_REV_1_0, HAL_API_REV_2_0);
parms.remove(String8(AUDIO_PARAMETER_STREAM_ROUTING));
parms.addInt(String8(AUDIO_PARAMETER_STREAM_ROUTING), val);
s8 = parms.toString();
}
return strdup(s8.string());
}

Expand Down Expand Up @@ -359,42 +463,6 @@ static inline const struct qcom_audio_device * to_cladev(const struct audio_hw_d
return reinterpret_cast<const struct qcom_audio_device *>(dev);
}

static uint32_t adev_get_supported_devices(const struct audio_hw_device *dev)
{
/* XXX: The old AudioHardwareInterface interface is not smart enough to
* tell us this, so we'll lie and basically tell AF that we support the
* below input/output devices and cross our fingers. To do things properly,
* audio hardware interfaces that need advanced features (like this) should
* convert to the new HAL interface and not use this wrapper. */
return (/* OUT */
AUDIO_DEVICE_OUT_EARPIECE |
AUDIO_DEVICE_OUT_SPEAKER |
AUDIO_DEVICE_OUT_WIRED_HEADSET |
AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
AUDIO_DEVICE_OUT_AUX_DIGITAL |
AUDIO_DEVICE_OUT_ALL_SCO |
AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET |
AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET |
#ifdef QCOM_FM_ENABLED
// AUDIO_DEVICE_OUT_FM |
#endif
AUDIO_DEVICE_OUT_DEFAULT |
/* IN */
AUDIO_DEVICE_IN_VOICE_CALL |
AUDIO_DEVICE_IN_COMMUNICATION |
AUDIO_DEVICE_IN_AMBIENT |
AUDIO_DEVICE_IN_BUILTIN_MIC |
AUDIO_DEVICE_IN_WIRED_HEADSET |
AUDIO_DEVICE_IN_AUX_DIGITAL |
AUDIO_DEVICE_IN_BACK_MIC |
AUDIO_DEVICE_IN_ALL_SCO |
#ifdef QCOM_FM_ENABLED
// AUDIO_DEVICE_IN_FM_RX |
// AUDIO_DEVICE_IN_FM_RX_A2DP |
#endif
AUDIO_DEVICE_IN_DEFAULT);
}

static int adev_init_check(const struct audio_hw_device *dev)
{
const struct qcom_audio_device *qadev = to_cladev(dev);
Expand Down Expand Up @@ -430,7 +498,7 @@ static int adev_set_fm_volume(struct audio_hw_device *dev, float volume)
static int adev_set_mode(struct audio_hw_device *dev, audio_mode_t mode)
{
struct qcom_audio_device *qadev = to_ladev(dev);
return qadev->hwif->setMode(mode);
return qadev->hwif->setMode((int)mode);
}

static int adev_set_mic_mute(struct audio_hw_device *dev, bool state)
Expand Down Expand Up @@ -465,7 +533,8 @@ static size_t adev_get_input_buffer_size(const struct audio_hw_device *dev,
const struct audio_config *config)
{
const struct qcom_audio_device *qadev = to_cladev(dev);
return qadev->hwif->getInputBufferSize(config->sample_rate, config->format, popcount(config->channel_mask));
uint8_t channelCount = popcount(config->channel_mask);
return qadev->hwif->getInputBufferSize(config->sample_rate,config->format,channelCount);
}


Expand All @@ -485,6 +554,7 @@ static int adev_open_output_stream(struct audio_hw_device *dev,
if (!out)
return -ENOMEM;

devices = convert_audio_device(devices, HAL_API_REV_2_0, HAL_API_REV_1_0);
out->qcom_out = qadev->hwif->openOutputStream(devices,
(int *)&config->format,
&config->channel_mask,
Expand Down Expand Up @@ -543,8 +613,8 @@ static void adev_close_output_stream(struct audio_hw_device *dev,
static int adev_open_input_stream(struct audio_hw_device *dev,
audio_io_handle_t handle,
audio_devices_t devices,
audio_config *config,
audio_stream_in **stream_in)
struct audio_config *config,
struct audio_stream_in **stream_in)
{
struct qcom_audio_device *qadev = to_ladev(dev);
status_t status;
Expand All @@ -555,6 +625,7 @@ static int adev_open_input_stream(struct audio_hw_device *dev,
if (!in)
return -ENOMEM;

devices = convert_audio_device(devices, HAL_API_REV_2_0, HAL_API_REV_1_0);
in->qcom_in = qadev->hwif->openInputStream(devices, (int *)&config->format,
&config->channel_mask,
&config->sample_rate,
Expand Down Expand Up @@ -643,7 +714,6 @@ static int qcom_adev_open(const hw_module_t* module, const char* name,
qadev->device.common.module = const_cast<hw_module_t*>(module);
qadev->device.common.close = qcom_adev_close;

qadev->device.get_supported_devices = adev_get_supported_devices;
qadev->device.init_check = adev_init_check;
qadev->device.set_voice_volume = adev_set_voice_volume;
qadev->device.set_master_volume = adev_set_master_volume;
Expand Down Expand Up @@ -686,8 +756,8 @@ struct qcom_audio_module HAL_MODULE_INFO_SYM = {
module: {
common: {
tag: HARDWARE_MODULE_TAG,
version_major: 1,
version_minor: 0,
version_major: AUDIO_MODULE_API_VERSION_0_1,
version_minor: HARDWARE_HAL_API_VERSION,
id: AUDIO_HARDWARE_MODULE_ID,
name: "QCOM Audio HW HAL",
author: "Code Aurora Forum",
Expand Down

0 comments on commit 45460ad

Please sign in to comment.