diff options
author | Bruce Beare <bruce.j.beare@intel.com> | 2016-01-15 01:12:49 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2016-01-15 01:12:49 +0000 |
commit | f80d0f8d7cfad19fecc4c836f131eb4888a2c3c7 (patch) | |
tree | fd0e23f37b1e7d992b4bca88847e0d7e37887d1f | |
parent | ed83102a14bb99abbb0742811adbf307d92977c4 (diff) | |
parent | d29449ddd2a165389723aede7d49e66a8baa682f (diff) | |
download | intel-f80d0f8d7cfad19fecc4c836f131eb4888a2c3c7.tar.gz |
Audio HAL supports both generic audio and USB
am: d29449ddd2
* commit 'd29449ddd2a165389723aede7d49e66a8baa682f':
Audio HAL supports both generic audio and USB
-rw-r--r-- | peripheral/audio/generic/audio_hal.c (renamed from peripheral/audio/usb/audio_hal.c) | 66 | ||||
-rw-r--r-- | peripheral/audio/generic/media_codecs.xml (renamed from peripheral/audio/usb/media_codecs.xml) | 0 | ||||
-rw-r--r-- | peripheral/audio/generic/primary/audio_policy.conf | 42 | ||||
-rw-r--r-- | peripheral/audio/generic/primary/hal.mk | 36 | ||||
-rw-r--r-- | peripheral/audio/generic/primary/peripheral.mk | 27 | ||||
-rw-r--r-- | peripheral/audio/generic/usb/audio_policy.conf (renamed from peripheral/audio/usb/audio_policy.conf) | 0 | ||||
-rw-r--r-- | peripheral/audio/generic/usb/hal.mk (renamed from peripheral/audio/usb/hal.mk) | 11 | ||||
-rw-r--r-- | peripheral/audio/generic/usb/peripheral.mk (renamed from peripheral/audio/usb/peripheral.mk) | 11 |
8 files changed, 177 insertions, 16 deletions
diff --git a/peripheral/audio/usb/audio_hal.c b/peripheral/audio/generic/audio_hal.c index 438ac67..e44b4de 100644 --- a/peripheral/audio/usb/audio_hal.c +++ b/peripheral/audio/generic/audio_hal.c @@ -14,7 +14,7 @@ * limitations under the License. */ -#define LOG_TAG "modules.usbaudio.audio_hal" +#define LOG_TAG "modules.audio.audio_hal" /*#define LOG_NDEBUG 0*/ #include <errno.h> @@ -45,7 +45,11 @@ #define PCM_DEV_STR "pcm" -#define USB_AUDIO_STR "USB Audio" +#if TARGET_AUDIO_PRIMARY +#define AUDIO_STR "ALC662 rev1 Analog" +#else +#define AUDIO_STR "USB Audio" +#endif #define MAX_PATH_LEN 30 #define NBR_RETRIES 5 @@ -82,6 +86,9 @@ struct audio_device { bool mic_muted; bool standby; +#if TARGET_AUDIO_PRIMARY + unsigned int master_volume; +#endif }; struct stream_out { @@ -150,7 +157,7 @@ static int in_stream_card_number = -1, out_stream_card_number = -1; * Examines a pcm-device file to see if its a USB Audio device and * returns its card-number. If no match, returns -1. */ -static int first_valid_usb_card(char *pcm_name, bool is_out_stream) +static int first_valid_sound_card(char *pcm_name, bool is_out_stream) { int fd; char pcm_dev_path[MAX_PATH_LEN]; @@ -176,7 +183,7 @@ static int first_valid_usb_card(char *pcm_name, bool is_out_stream) if (fd != -1) { if (!(ioctl(fd, SNDRV_PCM_IOCTL_INFO, &info))) { - if (strstr(info.id, USB_AUDIO_STR)) { + if (strstr(info.id, AUDIO_STR)) { close(fd); ALOGV("%s exit",__func__); return info.card; @@ -196,7 +203,7 @@ static int first_valid_usb_card(char *pcm_name, bool is_out_stream) * Returns the number of the first valid USB Audio card * If none is found, returns -1. */ -static int get_first_usb_card(bool is_out_stream) +static int get_first_sound_card(bool is_out_stream) { DIR *dir; struct dirent *de = NULL; @@ -213,7 +220,7 @@ static int get_first_usb_card(bool is_out_stream) while ((de = readdir(dir))) { if (strncmp(de->d_name, PCM_DEV_STR, sizeof(PCM_DEV_STR) - 1) == 0) { - if ((card_nr = first_valid_usb_card(de->d_name, is_out_stream)) != -1) { + if ((card_nr = first_valid_sound_card(de->d_name, is_out_stream)) != -1) { closedir(dir); ALOGV("%s exit",__func__); return card_nr; @@ -247,7 +254,7 @@ static bool parse_card_device_params(bool is_out_stream, int *card, int *device) } for (try_time = 0; try_time < NBR_RETRIES; try_time++) { - found_card = get_first_usb_card(is_out_stream); + found_card = get_first_sound_card(is_out_stream); if (found_card == -1) usleep(RETRY_WAIT_USEC); else @@ -1103,7 +1110,30 @@ static int adev_set_voice_volume(struct audio_hw_device *dev, float volume) static int adev_set_master_volume(struct audio_hw_device *dev, float volume) { +#if TARGET_AUDIO_PRIMARY + struct mixer *mixer; + struct mixer_ctl *ctl; + struct audio_device * adev = (struct audio_device *)dev; + + if ((0 > volume) || (1 < volume) || (NULL == adev)) + return -EINVAL; + + pthread_mutex_lock(&adev->lock); + adev->master_volume = (int)(volume*100); + + if (!(mixer = mixer_open(1))) { + pthread_mutex_unlock(&adev->lock); + return -ENOSYS; + } + + ctl = mixer_get_ctl(mixer,29); + mixer_ctl_set_value(ctl,0,adev->master_volume); + mixer_close(mixer); + pthread_mutex_unlock(&adev->lock); + return 0; +#else return -ENOSYS; +#endif } static int adev_set_mode(struct audio_hw_device *dev, audio_mode_t mode) @@ -1140,6 +1170,10 @@ static int adev_close(hw_device_t *device) static int adev_open(const hw_module_t* module, const char* name, hw_device_t** device) { +#if TARGET_AUDIO_PRIMARY + struct mixer *mixer; + struct mixer_ctl *ctl; +#endif if (strcmp(name, AUDIO_HARDWARE_INTERFACE) != 0) return -EINVAL; @@ -1171,7 +1205,21 @@ static int adev_open(const hw_module_t* module, const char* name, hw_device_t** adev->hw_device.dump = adev_dump; *device = &adev->hw_device.common; - +#if TARGET_AUDIO_PRIMARY + mixer = mixer_open(1); + + if (mixer) { + /* turning on master volume */ + ctl = mixer_get_ctl(mixer,30); + mixer_ctl_set_value(ctl,0,1); + + /* setting master volume to value 50 */ + ctl = mixer_get_ctl(mixer,29); + adev->master_volume = 50; + mixer_ctl_set_value(ctl,0,adev->master_volume); + mixer_close(mixer); + } +#endif return 0; } @@ -1185,7 +1233,7 @@ struct audio_module HAL_MODULE_INFO_SYM = { .module_api_version = AUDIO_MODULE_API_VERSION_0_1, .hal_api_version = HARDWARE_HAL_API_VERSION, .id = AUDIO_HARDWARE_MODULE_ID, - .name = "USB audio HW HAL", + .name = "audio HW HAL", .author = "The Android Open Source Project", .methods = &hal_module_methods, }, diff --git a/peripheral/audio/usb/media_codecs.xml b/peripheral/audio/generic/media_codecs.xml index 934619c..934619c 100644 --- a/peripheral/audio/usb/media_codecs.xml +++ b/peripheral/audio/generic/media_codecs.xml diff --git a/peripheral/audio/generic/primary/audio_policy.conf b/peripheral/audio/generic/primary/audio_policy.conf new file mode 100644 index 0000000..28bd32d --- /dev/null +++ b/peripheral/audio/generic/primary/audio_policy.conf @@ -0,0 +1,42 @@ +# +# Copyright (C) 2015 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +audio_hw_modules { +primary { +global_configuration { + attached_output_devices AUDIO_DEVICE_OUT_SPEAKER + attached_input_devices AUDIO_DEVICE_IN_BUILTIN_MIC + } + outputs { + primary { + sampling_rates 48000 + channel_masks AUDIO_CHANNEL_OUT_STEREO + formats AUDIO_FORMAT_PCM_16_BIT + devices AUDIO_DEVICE_OUT_SPEAKER|AUDIO_DEVICE_OUT_WIRED_HEADSET|AUDIO_DEVICE_OUT_WIRED_HEADPHONE|AUDIO_DEVICE_OUT_ALL_SCO|AUDIO_DEVICE_OUT_LINE + flags AUDIO_OUTPUT_FLAG_PRIMARY + } + } + inputs { + primary { + sampling_rates 8000|11025|12000|16000|22050|24000|32000|44100|48000 + channel_masks AUDIO_CHANNEL_IN_MONO|AUDIO_CHANNEL_IN_STEREO + formats AUDIO_FORMAT_PCM_16_BIT + devices AUDIO_DEVICE_IN_BUILTIN_MIC|AUDIO_DEVICE_IN_WIRED_HEADSET|AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET + } + } + } + +} diff --git a/peripheral/audio/generic/primary/hal.mk b/peripheral/audio/generic/primary/hal.mk new file mode 100644 index 0000000..4b1603d --- /dev/null +++ b/peripheral/audio/generic/primary/hal.mk @@ -0,0 +1,36 @@ +# Copyright (C) 2012 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_MODULE_RELATIVE_PATH := hw +LOCAL_SRC_FILES := \ + ../audio_hal.c +LOCAL_C_INCLUDES += \ + external/tinyalsa/include \ + $(call include-path-for, audio-utils) \ + $(call include-path-for, alsa-utils) +LOCAL_SHARED_LIBRARIES := liblog libcutils libtinyalsa libaudioutils libalsautils +LOCAL_MODULE_TAGS := optional + +# setting to build for primary audio or usb audio +# set -DTARGET_AUDIO_PRIMARY to 1 for Primary (audio jack) +# set -DTARGET_AUDIO_PRIMARY to 0 for USB audio +LOCAL_CFLAGS := -Wno-unused-parameter -DTARGET_AUDIO_PRIMARY=1 +LOCAL_MODULE := audio.primary.$(TARGET_DEVICE) + +include $(BUILD_SHARED_LIBRARY) + diff --git a/peripheral/audio/generic/primary/peripheral.mk b/peripheral/audio/generic/primary/peripheral.mk new file mode 100644 index 0000000..509b741 --- /dev/null +++ b/peripheral/audio/generic/primary/peripheral.mk @@ -0,0 +1,27 @@ +# +# Copyright 2015 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# Audio configuration files +PRODUCT_COPY_FILES += \ + frameworks/av/media/libstagefright/data/media_codecs_google_audio.xml:system/etc/media_codecs_google_audio.xml + +PRODUCT_COPY_FILES += \ + hardware/bsp/intel/peripheral/audio/generic/media_codecs.xml:system/etc/media_codecs.xml \ + hardware/bsp/intel/peripheral/audio/generic/primary/audio_policy.conf:system/etc/audio_policy.conf + +# Primary audio HAL +DEVICE_PACKAGES += \ + audio.primary.$(TARGET_DEVICE) diff --git a/peripheral/audio/usb/audio_policy.conf b/peripheral/audio/generic/usb/audio_policy.conf index eebf55c..eebf55c 100644 --- a/peripheral/audio/usb/audio_policy.conf +++ b/peripheral/audio/generic/usb/audio_policy.conf diff --git a/peripheral/audio/usb/hal.mk b/peripheral/audio/generic/usb/hal.mk index 2ce1b2e..2e1674c 100644 --- a/peripheral/audio/usb/hal.mk +++ b/peripheral/audio/generic/usb/hal.mk @@ -16,17 +16,20 @@ LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) -LOCAL_MODULE := audio.usb.$(TARGET_DEVICE) LOCAL_MODULE_RELATIVE_PATH := hw LOCAL_SRC_FILES := \ - audio_hal.c + ../audio_hal.c LOCAL_C_INCLUDES += \ external/tinyalsa/include \ $(call include-path-for, audio-utils) \ $(call include-path-for, alsa-utils) LOCAL_SHARED_LIBRARIES := liblog libcutils libtinyalsa libaudioutils libalsautils LOCAL_MODULE_TAGS := optional -LOCAL_CFLAGS := -Wno-unused-parameter -include $(BUILD_SHARED_LIBRARY) +# setting to build for primary audio or usb audio +# set -DTARGET_AUDIO_PRIMARY to 1 for Primary (audio jack) +# set -DTARGET_AUDIO_PRIMARY to 0 for USB audio +LOCAL_CFLAGS := -Wno-unused-parameter -DTARGET_AUDIO_PRIMARY=0 +LOCAL_MODULE := audio.usb.$(TARGET_DEVICE) +include $(BUILD_SHARED_LIBRARY) diff --git a/peripheral/audio/usb/peripheral.mk b/peripheral/audio/generic/usb/peripheral.mk index faf48f8..c9aa982 100644 --- a/peripheral/audio/usb/peripheral.mk +++ b/peripheral/audio/generic/usb/peripheral.mk @@ -16,6 +16,11 @@ # Audio configuration files PRODUCT_COPY_FILES += \ - frameworks/av/media/libstagefright/data/media_codecs_google_audio.xml:system/etc/media_codecs_google_audio.xml \ - hardware/bsp/intel/peripheral/audio/usb/audio_policy.conf:system/etc/audio_policy.conf \ - hardware/bsp/intel/peripheral/audio/usb/media_codecs.xml:system/etc/media_codecs.xml + frameworks/av/media/libstagefright/data/media_codecs_google_audio.xml:system/etc/media_codecs_google_audio.xml + +PRODUCT_COPY_FILES += \ + hardware/bsp/intel/peripheral/audio/generic/media_codecs.xml:system/etc/media_codecs.xml \ + hardware/bsp/intel/peripheral/audio/generic/usb/audio_policy.conf:system/etc/audio_policy.conf + +DEVICE_PACKAGES += \ + audio.usb.$(TARGET_DEVICE) |