summaryrefslogtreecommitdiff
authorLawrence Mok <lawrence.mok@amlogic.com>2014-12-18 22:16:04 (GMT)
committer Lawrence Mok <lawrence.mok@amlogic.com>2014-12-18 22:29:52 (GMT)
commitff3f5fad8024f7ebe55f3f7078828fe739640d6f (patch)
tree8afc365e1a98e5b183891351cc61dcfdf3e237f6
parenta5e787a7269c5a069b263787661ee22160676e87 (diff)
downloadaudio-ff3f5fad8024f7ebe55f3f7078828fe739640d6f.zip
audio-ff3f5fad8024f7ebe55f3f7078828fe739640d6f.tar.gz
audio-ff3f5fad8024f7ebe55f3f7078828fe739640d6f.tar.bz2
add audio policy manager
currently used by mbx for forcing remote submix as input Fixes voice search. PD#101046 Change-Id: Ia7a412c411a3e6a884b15008f0ec61663f93fe36
Diffstat
-rw-r--r--[-rwxr-xr-x]Android.mk43
-rw-r--r--DLGAudioPolicyManager.cpp117
-rw-r--r--DLGAudioPolicyManager.h54
3 files changed, 198 insertions, 16 deletions
diff --git a/Android.mk b/Android.mk
index e338b8a..9b88943 100755..100644
--- a/Android.mk
+++ b/Android.mk
@@ -73,21 +73,6 @@ ifeq ($(strip $(BOARD_ALSA_AUDIO)),tiny)
include $(BUILD_SHARED_LIBRARY)
-
-# The stub audio policy HAL module that can be used as a skeleton for
-# new implementations.
-#include $(CLEAR_VARS)
-
-#LOCAL_MODULE := audio_policy.amlogic
-#LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
-#LOCAL_SRC_FILES := audio_policy.c
-#LOCAL_SHARED_LIBRARIES := liblog libcutils
-#LOCAL_MODULE_TAGS := optional
-
-#include $(BUILD_SHARED_LIBRARY)
-
-#endif
-
#########################################################
ifdef DOLBY_UDC
@@ -106,4 +91,30 @@ include $(CLEAR_VARS)
endif
-endif
+#########################################################
+# Audio Policy Manager
+ifeq ($(USE_CUSTOM_AUDIO_POLICY),1)
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := \
+ DLGAudioPolicyManager.cpp
+
+LOCAL_SHARED_LIBRARIES := \
+ libcutils \
+ liblog \
+ libutils \
+ libmedia \
+ libbinder \
+ libaudiopolicymanagerdefault
+
+LOCAL_C_INCLUDES := \
+ external/tinyalsa/include \
+ $(TOPDIR)frameworks/av/services/audiopolicy
+
+LOCAL_MODULE := libaudiopolicymanager
+LOCAL_MODULE_TAGS := optional
+
+include $(BUILD_SHARED_LIBRARY)
+endif # USE_CUSTOM_AUDIO_POLICY
+
+endif # BOARD_ALSA_AUDIO
diff --git a/DLGAudioPolicyManager.cpp b/DLGAudioPolicyManager.cpp
new file mode 100644
index 0000000..715935b
--- a/dev/null
+++ b/DLGAudioPolicyManager.cpp
@@ -0,0 +1,117 @@
+/*
+ * Copyright (C) 2014 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.
+ */
+
+#define LOG_TAG "DLGAudioPolicyManager"
+//#define LOG_NDEBUG 0
+#include <media/AudioParameter.h>
+#include <media/mediarecorder.h>
+#include <utils/Log.h>
+#include <utils/String16.h>
+#include <utils/String8.h>
+#include <utils/StrongPointer.h>
+
+#include "DLGAudioPolicyManager.h"
+
+
+namespace android {
+// ----------------------------------------------------------------------------
+// Common audio policy manager code is implemented in AudioPolicyManager class
+// ----------------------------------------------------------------------------
+
+// --- class factory
+
+
+extern "C" AudioPolicyInterface* createAudioPolicyManager(
+ AudioPolicyClientInterface *clientInterface)
+{
+ return new DLGAudioPolicyManager(clientInterface);
+}
+
+extern "C" void destroyAudioPolicyManager(AudioPolicyInterface *interface)
+{
+ delete interface;
+}
+
+DLGAudioPolicyManager::DLGAudioPolicyManager(
+ AudioPolicyClientInterface *clientInterface)
+ : AudioPolicyManager(clientInterface), mForceSubmixInputSelection(false)
+{
+}
+
+float DLGAudioPolicyManager::computeVolume(audio_stream_type_t stream,
+ int index,
+ audio_io_handle_t output,
+ audio_devices_t device)
+{
+ // We only use master volume, so all audio flinger streams
+ // should be set to maximum
+ (void)stream;
+ (void)index;
+ (void)output;
+ (void)device;
+ return 1.0;
+}
+
+status_t DLGAudioPolicyManager::setDeviceConnectionState(audio_devices_t device,
+ audio_policy_dev_state_t state,
+ const char *device_address)
+{
+ audio_devices_t tmp = AUDIO_DEVICE_NONE;;
+ ALOGV("setDeviceConnectionState %08x %x %s", device, state,
+ device_address ? device_address : "(null)");
+
+ // If the input device is the remote submix and an address starting with "force=" was
+ // specified, enable "force=1" / disable "force=0" the forced selection of the remote submix
+ // input device over hardware input devices (e.g RemoteControl).
+ if (device == AUDIO_DEVICE_IN_REMOTE_SUBMIX && device_address) {
+ AudioParameter parameters = AudioParameter(String8(device_address));
+ int forceValue;
+ if (parameters.getInt(String8("force"), forceValue) == OK) {
+ mForceSubmixInputSelection = forceValue != 0;
+ }
+ }
+
+ status_t ret = 0;
+ if (device != AUDIO_DEVICE_IN_REMOTE_SUBMIX) {
+ ret = AudioPolicyManager::setDeviceConnectionState(
+ device, state, device_address);
+ }
+
+ return ret;
+}
+
+audio_devices_t DLGAudioPolicyManager::getDeviceForInputSource(audio_source_t inputSource)
+{
+ uint32_t device = AUDIO_DEVICE_NONE;
+ bool usePhysRemote = true;
+
+ if (inputSource == AUDIO_SOURCE_VOICE_RECOGNITION) {
+ ALOGV("getDeviceForInputSource %s", mForceSubmixInputSelection ? "use virtual" : "");
+ audio_devices_t availableDeviceTypes = mAvailableInputDevices.types() &
+ ~AUDIO_DEVICE_BIT_IN;
+ if (availableDeviceTypes & AUDIO_DEVICE_IN_REMOTE_SUBMIX &&
+ mForceSubmixInputSelection) {
+ // REMOTE_SUBMIX should always be avaible, let's make sure it's being forced at the moment
+ ALOGV("Virtual remote available");
+ device = AUDIO_DEVICE_IN_REMOTE_SUBMIX;
+ }
+ }
+
+ ALOGV("getDeviceForInputSource() input source %d, device %08x", inputSource, device);
+ return device;
+}
+
+} // namespace android
diff --git a/DLGAudioPolicyManager.h b/DLGAudioPolicyManager.h
new file mode 100644
index 0000000..bd3a307
--- a/dev/null
+++ b/DLGAudioPolicyManager.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2014 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.
+ */
+
+
+#include <stdint.h>
+#include <sys/types.h>
+#include <utils/Timers.h>
+#include <utils/Errors.h>
+#include <utils/KeyedVector.h>
+#include <AudioPolicyManager.h>
+
+#ifndef ANDROID_DLG_AUDIO_POLICY_MANAGER_H
+#define ANDROID_DLG_AUDIO_POLICY_MANAGER_H
+
+namespace android {
+
+class DLGAudioPolicyManager: public AudioPolicyManager
+{
+public:
+ DLGAudioPolicyManager(AudioPolicyClientInterface *clientInterface);
+ virtual ~DLGAudioPolicyManager() {}
+
+ virtual status_t setDeviceConnectionState(audio_devices_t device,
+ audio_policy_dev_state_t state,
+ const char *device_address);
+
+ virtual audio_devices_t getDeviceForInputSource(audio_source_t inputSource);
+
+protected:
+ virtual float computeVolume(audio_stream_type_t stream,
+ int index,
+ audio_io_handle_t output,
+ audio_devices_t device);
+
+private:
+ // Flag which indicates whether to record from the submix device.
+ bool mForceSubmixInputSelection;
+};
+
+} // namespace android
+#endif // DLG_ANDROID_AUDIO_POLICY_MANAGER_H