diff options
Diffstat (limited to 'services/audiopolicy/engineconfigurable/parameter-framework/plugin')
15 files changed, 821 insertions, 0 deletions
diff --git a/services/audiopolicy/engineconfigurable/parameter-framework/plugin/Android.mk b/services/audiopolicy/engineconfigurable/parameter-framework/plugin/Android.mk new file mode 100755 index 0000000..46b2725 --- /dev/null +++ b/services/audiopolicy/engineconfigurable/parameter-framework/plugin/Android.mk @@ -0,0 +1,41 @@ +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_MODULE_TAGS := optional +LOCAL_SRC_FILES := \ + PolicySubsystemBuilder.cpp \ + PolicySubsystem.cpp \ + Strategy.cpp \ + InputSource.cpp \ + VolumeProfile.cpp \ + Stream.cpp \ + Usage.cpp + +LOCAL_CFLAGS += \ + -Wall \ + -Werror \ + -Wextra \ + +LOCAL_C_INCLUDES := \ + $(TOPDIR)external/parameter-framework/parameter \ + $(TOPDIR)frameworks/av/services/audiopolicy/common/include \ + $(TOPDIR)frameworks/av/services/audiopolicy/engineconfigurable/include \ + $(TOPDIR)frameworks/av/services/audiopolicy/engineconfigurable/interface \ + +LOCAL_SHARED_LIBRARIES := \ + libaudiopolicyengineconfigurable \ + libparameter \ + libicuuc \ + liblog \ + +LOCAL_STATIC_LIBRARIES := \ + libxmlserializer \ + libpfw_utility \ + libxml2 \ + +LOCAL_MODULE_TAGS := optional +LOCAL_MODULE := libpolicy-subsystem + +include $(BUILD_SHARED_LIBRARY) + diff --git a/services/audiopolicy/engineconfigurable/parameter-framework/plugin/InputSource.cpp b/services/audiopolicy/engineconfigurable/parameter-framework/plugin/InputSource.cpp new file mode 100755 index 0000000..497d555 --- /dev/null +++ b/services/audiopolicy/engineconfigurable/parameter-framework/plugin/InputSource.cpp @@ -0,0 +1,53 @@ +/* + * 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. + */ + +#include "InputSource.h" +#include "PolicyMappingKeys.h" +#include "PolicySubsystem.h" + +using std::string; + +InputSource::InputSource(const string &mappingValue, + CInstanceConfigurableElement *instanceConfigurableElement, + const CMappingContext &context) + : CFormattedSubsystemObject(instanceConfigurableElement, + mappingValue, + MappingKeyAmend1, + (MappingKeyAmendEnd - MappingKeyAmend1 + 1), + context), + mPolicySubsystem(static_cast<const PolicySubsystem *>( + instanceConfigurableElement->getBelongingSubsystem())), + mPolicyPluginInterface(mPolicySubsystem->getPolicyPluginInterface()), + mApplicableInputDevice(mDefaultApplicableInputDevice) +{ + mId = static_cast<audio_source_t>(context.getItemAsInteger(MappingKeyIdentifier)); + // Declares the strategy to audio policy engine + mPolicyPluginInterface->addInputSource(getFormattedMappingValue(), mId); +} + +bool InputSource::receiveFromHW(string & /*error*/) +{ + blackboardWrite(&mApplicableInputDevice, sizeof(mApplicableInputDevice)); + return true; +} + +bool InputSource::sendToHW(string & /*error*/) +{ + uint32_t applicableInputDevice; + blackboardRead(&applicableInputDevice, sizeof(applicableInputDevice)); + mApplicableInputDevice = applicableInputDevice; + return mPolicyPluginInterface->setDeviceForInputSource(mId, mApplicableInputDevice); +} diff --git a/services/audiopolicy/engineconfigurable/parameter-framework/plugin/InputSource.h b/services/audiopolicy/engineconfigurable/parameter-framework/plugin/InputSource.h new file mode 100755 index 0000000..67c5b50 --- /dev/null +++ b/services/audiopolicy/engineconfigurable/parameter-framework/plugin/InputSource.h @@ -0,0 +1,49 @@ +/* + * 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. + */ + +#pragma once + +#include "FormattedSubsystemObject.h" +#include "InstanceConfigurableElement.h" +#include "MappingContext.h" +#include <AudioPolicyPluginInterface.h> +#include <string> + +class PolicySubsystem; + +class InputSource : public CFormattedSubsystemObject +{ +public: + InputSource(const std::string &mappingValue, + CInstanceConfigurableElement *instanceConfigurableElement, + const CMappingContext &context); + +protected: + virtual bool receiveFromHW(std::string &error); + virtual bool sendToHW(std::string &error); + +private: + const PolicySubsystem *mPolicySubsystem; /**< Route subsytem plugin. */ + + /** + * Interface to communicate with Audio Policy Engine. + */ + android::AudioPolicyPluginInterface *mPolicyPluginInterface; + + audio_source_t mId; /**< input source identifier to link with audio.h. */ + uint32_t mApplicableInputDevice; /**< applicable input device for this strategy. */ + static const uint32_t mDefaultApplicableInputDevice = 0; /**< default input device. */ +}; diff --git a/services/audiopolicy/engineconfigurable/parameter-framework/plugin/PolicyMappingKeys.h b/services/audiopolicy/engineconfigurable/parameter-framework/plugin/PolicyMappingKeys.h new file mode 100755 index 0000000..53944e9 --- /dev/null +++ b/services/audiopolicy/engineconfigurable/parameter-framework/plugin/PolicyMappingKeys.h @@ -0,0 +1,32 @@ +/* + * 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. + */ + +#pragma once + +/** + * Mapping item types + */ +enum PolicyItemType +{ + MappingKeyName, + MappingKeyCategory, + MappingKeyIdentifier, + MappingKeyAmend1, + MappingKeyAmend2, + MappingKeyAmend3 +}; + +static const uint8_t MappingKeyAmendEnd = MappingKeyAmend3; diff --git a/services/audiopolicy/engineconfigurable/parameter-framework/plugin/PolicySubsystem.cpp b/services/audiopolicy/engineconfigurable/parameter-framework/plugin/PolicySubsystem.cpp new file mode 100755 index 0000000..a5dab36 --- /dev/null +++ b/services/audiopolicy/engineconfigurable/parameter-framework/plugin/PolicySubsystem.cpp @@ -0,0 +1,105 @@ +/* + * 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. + */ + +#include "PolicySubsystem.h" +#include "SubsystemObjectFactory.h" +#include "PolicyMappingKeys.h" +#include "Strategy.h" +#include "Stream.h" +#include "InputSource.h" +#include "VolumeProfile.h" +#include "Usage.h" +#include <AudioPolicyPluginInterface.h> +#include <AudioPolicyEngineInstance.h> +#include <utils/Log.h> + +using android::audio_policy::EngineInstance; + +const char *const PolicySubsystem::mKeyName = "Name"; +const char *const PolicySubsystem::mKeyIdentifier = "Identifier"; +const char *const PolicySubsystem::mKeyCategory = "Category"; +const char *const PolicySubsystem::mKeyAmend1 = "Amend1"; +const char *const PolicySubsystem::mKeyAmend2 = "Amend2"; +const char *const PolicySubsystem::mKeyAmend3 = "Amend3"; + + +const char *const PolicySubsystem::mStreamComponentName = "Stream"; +const char *const PolicySubsystem::mStrategyComponentName = "Strategy"; +const char *const PolicySubsystem::mInputSourceComponentName = "InputSource"; +const char *const PolicySubsystem::mUsageComponentName = "Usage"; +const char *const PolicySubsystem::mVolumeProfileComponentName = "VolumeProfile"; + +PolicySubsystem::PolicySubsystem(const std::string &name) + : CSubsystem(name), + mPluginInterface(NULL) +{ + // Try to connect a Plugin Interface from Audio Policy Engine + EngineInstance *engineInstance = EngineInstance::getInstance(); + + if (engineInstance == NULL) { + ALOG_ASSERT(engineInstance != NULL, "NULL Plugin Interface"); + return; + } + // Retrieve the Route Interface + mPluginInterface = engineInstance->queryInterface<android::AudioPolicyPluginInterface>(); + if (mPluginInterface == NULL) { + // bailing out + ALOG_ASSERT(mPluginInterface != NULL, "NULL Plugin Interface"); + return; + } + + // Provide mapping keys to the core, necessary when parsing the XML Structure files. + addContextMappingKey(mKeyName); + addContextMappingKey(mKeyCategory); + addContextMappingKey(mKeyIdentifier); + addContextMappingKey(mKeyAmend1); + addContextMappingKey(mKeyAmend2); + addContextMappingKey(mKeyAmend3); + + // Provide creators to upper layer + addSubsystemObjectFactory( + new TSubsystemObjectFactory<Stream>( + mStreamComponentName, + (1 << MappingKeyAmend1) | (1 << MappingKeyIdentifier)) + ); + addSubsystemObjectFactory( + new TSubsystemObjectFactory<Strategy>( + mStrategyComponentName, + (1 << MappingKeyAmend1) | (1 << MappingKeyIdentifier)) + ); + addSubsystemObjectFactory( + new TSubsystemObjectFactory<Usage>( + mUsageComponentName, + (1 << MappingKeyAmend1) | (1 << MappingKeyIdentifier)) + ); + addSubsystemObjectFactory( + new TSubsystemObjectFactory<InputSource>( + mInputSourceComponentName, + (1 << MappingKeyAmend1) | (1 << MappingKeyIdentifier)) + ); + addSubsystemObjectFactory( + new TSubsystemObjectFactory<VolumeProfile>( + mVolumeProfileComponentName, + (1 << MappingKeyAmend1) | (1 << MappingKeyIdentifier) | (1 << MappingKeyIdentifier)) + ); +} + +// Retrieve Route interface +android::AudioPolicyPluginInterface *PolicySubsystem::getPolicyPluginInterface() const +{ + ALOG_ASSERT(mPluginInterface != NULL, "NULL Plugin Interface"); + return mPluginInterface; +} diff --git a/services/audiopolicy/engineconfigurable/parameter-framework/plugin/PolicySubsystem.h b/services/audiopolicy/engineconfigurable/parameter-framework/plugin/PolicySubsystem.h new file mode 100755 index 0000000..3c26fe1 --- /dev/null +++ b/services/audiopolicy/engineconfigurable/parameter-framework/plugin/PolicySubsystem.h @@ -0,0 +1,60 @@ +/* + * 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. + */ + +#pragma once + +#include "Subsystem.h" +#include <string> + +namespace android { + +class AudioPolicyPluginInterface; + +} + +class PolicySubsystem : public CSubsystem +{ +public: + PolicySubsystem(const std::string &strName); + + /** + * Retrieve Route Manager interface. + * + * @return RouteManager interface for the route plugin. + */ + android::AudioPolicyPluginInterface *getPolicyPluginInterface() const; + +private: + /* Copy facilities are put private to disable copy. */ + PolicySubsystem(const PolicySubsystem &object); + PolicySubsystem &operator=(const PolicySubsystem &object); + + android::AudioPolicyPluginInterface *mPluginInterface; /**< Audio Policy Plugin Interface. */ + + static const char *const mKeyName; /**< name key mapping string. */ + static const char *const mKeyIdentifier; + static const char *const mKeyCategory; + + static const char *const mKeyAmend1; /**< amend1 key mapping string. */ + static const char *const mKeyAmend2; /**< amend2 key mapping string. */ + static const char *const mKeyAmend3; /**< amend3 key mapping string. */ + + static const char *const mStreamComponentName; + static const char *const mStrategyComponentName; + static const char *const mInputSourceComponentName; + static const char *const mUsageComponentName; + static const char *const mVolumeProfileComponentName; +}; diff --git a/services/audiopolicy/engineconfigurable/parameter-framework/plugin/PolicySubsystemBuilder.cpp b/services/audiopolicy/engineconfigurable/parameter-framework/plugin/PolicySubsystemBuilder.cpp new file mode 100755 index 0000000..b14d446 --- /dev/null +++ b/services/audiopolicy/engineconfigurable/parameter-framework/plugin/PolicySubsystemBuilder.cpp @@ -0,0 +1,29 @@ +/* + * 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. + */ + +#include "SubsystemLibrary.h" +#include "NamedElementBuilderTemplate.h" +#include "PolicySubsystem.h" + +static const char *const POLICY_SUBSYSTEM_NAME = "Policy"; +extern "C" +{ +void getPOLICYSubsystemBuilder(CSubsystemLibrary *subsystemLibrary) +{ + subsystemLibrary->addElementBuilder(POLICY_SUBSYSTEM_NAME, + new TNamedElementBuilderTemplate<PolicySubsystem>()); +} +} diff --git a/services/audiopolicy/engineconfigurable/parameter-framework/plugin/Strategy.cpp b/services/audiopolicy/engineconfigurable/parameter-framework/plugin/Strategy.cpp new file mode 100755 index 0000000..1848813 --- /dev/null +++ b/services/audiopolicy/engineconfigurable/parameter-framework/plugin/Strategy.cpp @@ -0,0 +1,54 @@ +/* + * 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. + */ + +#include "Strategy.h" +#include "PolicyMappingKeys.h" +#include "PolicySubsystem.h" + +using std::string; +using android::routing_strategy; + +Strategy::Strategy(const string &mappingValue, + CInstanceConfigurableElement *instanceConfigurableElement, + const CMappingContext &context) + : CFormattedSubsystemObject(instanceConfigurableElement, + mappingValue, + MappingKeyAmend1, + (MappingKeyAmendEnd - MappingKeyAmend1 + 1), + context), + mPolicySubsystem(static_cast<const PolicySubsystem *>( + instanceConfigurableElement->getBelongingSubsystem())), + mPolicyPluginInterface(mPolicySubsystem->getPolicyPluginInterface()), + mApplicableOutputDevice(mDefaultApplicableOutputDevice) +{ + mId = static_cast<routing_strategy>(context.getItemAsInteger(MappingKeyIdentifier)); + + // Declares the strategy to audio policy engine + mPolicyPluginInterface->addStrategy(getFormattedMappingValue(), mId); +} + +bool Strategy::receiveFromHW(string & /*error*/) +{ + blackboardWrite(&mApplicableOutputDevice, sizeof(mApplicableOutputDevice)); + return true; +} + +bool Strategy::sendToHW(string & /*error*/) +{ + uint32_t applicableOutputDevice; + blackboardRead(&applicableOutputDevice, sizeof(applicableOutputDevice)); + return mPolicyPluginInterface->setDeviceForStrategy(mId, applicableOutputDevice); +} diff --git a/services/audiopolicy/engineconfigurable/parameter-framework/plugin/Strategy.h b/services/audiopolicy/engineconfigurable/parameter-framework/plugin/Strategy.h new file mode 100755 index 0000000..9a9b3e4 --- /dev/null +++ b/services/audiopolicy/engineconfigurable/parameter-framework/plugin/Strategy.h @@ -0,0 +1,49 @@ +/* + * 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. + */ + +#pragma once + +#include "FormattedSubsystemObject.h" +#include "InstanceConfigurableElement.h" +#include "MappingContext.h" +#include <AudioPolicyPluginInterface.h> +#include <string> + +class PolicySubsystem; + +class Strategy : public CFormattedSubsystemObject +{ +public: + Strategy(const std::string &mappingValue, + CInstanceConfigurableElement *instanceConfigurableElement, + const CMappingContext &context); + +protected: + virtual bool receiveFromHW(std::string &error); + virtual bool sendToHW(std::string &error); + +private: + const PolicySubsystem *mPolicySubsystem; /**< Route subsytem plugin. */ + + /** + * Interface to communicate with Audio Policy Engine. + */ + android::AudioPolicyPluginInterface *mPolicyPluginInterface; + + android::routing_strategy mId; /**< strategy identifier to link with audio.h.*/ + uint32_t mApplicableOutputDevice; /**< applicable output device for this strategy. */ + static const uint32_t mDefaultApplicableOutputDevice = 0; /**< default output device. */ +}; diff --git a/services/audiopolicy/engineconfigurable/parameter-framework/plugin/Stream.cpp b/services/audiopolicy/engineconfigurable/parameter-framework/plugin/Stream.cpp new file mode 100755 index 0000000..575b0bb --- /dev/null +++ b/services/audiopolicy/engineconfigurable/parameter-framework/plugin/Stream.cpp @@ -0,0 +1,56 @@ +/* + * 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. + */ + +#include "Stream.h" +#include "PolicyMappingKeys.h" +#include "PolicySubsystem.h" + +using std::string; +using android::routing_strategy; + +Stream::Stream(const string &mappingValue, + CInstanceConfigurableElement *instanceConfigurableElement, + const CMappingContext &context) + : CFormattedSubsystemObject(instanceConfigurableElement, + mappingValue, + MappingKeyAmend1, + (MappingKeyAmendEnd - MappingKeyAmend1 + 1), + context), + mPolicySubsystem(static_cast<const PolicySubsystem *>( + instanceConfigurableElement->getBelongingSubsystem())), + mPolicyPluginInterface(mPolicySubsystem->getPolicyPluginInterface()), + mApplicableStrategy(mDefaultApplicableStrategy) +{ + mId = static_cast<audio_stream_type_t>(context.getItemAsInteger(MappingKeyIdentifier)); + + // Declares the strategy to audio policy engine + mPolicyPluginInterface->addStream(getFormattedMappingValue(), mId); +} + +bool Stream::receiveFromHW(string & /*error*/) +{ + blackboardWrite(&mApplicableStrategy, sizeof(mApplicableStrategy)); + return true; +} + +bool Stream::sendToHW(string & /*error*/) +{ + uint32_t applicableStrategy; + blackboardRead(&applicableStrategy, sizeof(applicableStrategy)); + mApplicableStrategy = applicableStrategy; + return mPolicyPluginInterface->setStrategyForStream(mId, + static_cast<routing_strategy>(mApplicableStrategy)); +} diff --git a/services/audiopolicy/engineconfigurable/parameter-framework/plugin/Stream.h b/services/audiopolicy/engineconfigurable/parameter-framework/plugin/Stream.h new file mode 100755 index 0000000..7d90c36 --- /dev/null +++ b/services/audiopolicy/engineconfigurable/parameter-framework/plugin/Stream.h @@ -0,0 +1,49 @@ +/* + * 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. + */ + +#pragma once + +#include "FormattedSubsystemObject.h" +#include "InstanceConfigurableElement.h" +#include "MappingContext.h" +#include <AudioPolicyPluginInterface.h> +#include <string> + +class PolicySubsystem; + +class Stream : public CFormattedSubsystemObject +{ +public: + Stream(const std::string &mappingValue, + CInstanceConfigurableElement *instanceConfigurableElement, + const CMappingContext &context); + +protected: + virtual bool receiveFromHW(std::string &error); + virtual bool sendToHW(std::string &error); + +private: + const PolicySubsystem *mPolicySubsystem; /**< Route subsytem plugin. */ + + /** + * Interface to communicate with Audio Policy Engine. + */ + android::AudioPolicyPluginInterface *mPolicyPluginInterface; + + audio_stream_type_t mId; /**< stream type identifier to link with audio.h. */ + uint32_t mApplicableStrategy; /**< applicable strategy for this stream. */ + static const uint32_t mDefaultApplicableStrategy = 0; /**< default strategy. */ +}; diff --git a/services/audiopolicy/engineconfigurable/parameter-framework/plugin/Usage.cpp b/services/audiopolicy/engineconfigurable/parameter-framework/plugin/Usage.cpp new file mode 100755 index 0000000..1916b9b --- /dev/null +++ b/services/audiopolicy/engineconfigurable/parameter-framework/plugin/Usage.cpp @@ -0,0 +1,56 @@ +/* + * 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. + */ + +#include "Usage.h" +#include "PolicyMappingKeys.h" +#include "PolicySubsystem.h" + +using std::string; +using android::routing_strategy; + +Usage::Usage(const string &mappingValue, + CInstanceConfigurableElement *instanceConfigurableElement, + const CMappingContext &context) + : CFormattedSubsystemObject(instanceConfigurableElement, + mappingValue, + MappingKeyAmend1, + (MappingKeyAmendEnd - MappingKeyAmend1 + 1), + context), + mPolicySubsystem(static_cast<const PolicySubsystem *>( + instanceConfigurableElement->getBelongingSubsystem())), + mPolicyPluginInterface(mPolicySubsystem->getPolicyPluginInterface()), + mApplicableStrategy(mDefaultApplicableStrategy) +{ + mId = static_cast<audio_usage_t>(context.getItemAsInteger(MappingKeyIdentifier)); + + // Declares the strategy to audio policy engine + mPolicyPluginInterface->addUsage(getFormattedMappingValue(), mId); +} + +bool Usage::receiveFromHW(string & /*error*/) +{ + blackboardWrite(&mApplicableStrategy, sizeof(mApplicableStrategy)); + return true; +} + +bool Usage::sendToHW(string & /*error*/) +{ + uint32_t applicableStrategy; + blackboardRead(&applicableStrategy, sizeof(applicableStrategy)); + mApplicableStrategy = applicableStrategy; + return mPolicyPluginInterface->setStrategyForUsage(mId, + static_cast<routing_strategy>(mApplicableStrategy)); +} diff --git a/services/audiopolicy/engineconfigurable/parameter-framework/plugin/Usage.h b/services/audiopolicy/engineconfigurable/parameter-framework/plugin/Usage.h new file mode 100755 index 0000000..8e9b638 --- /dev/null +++ b/services/audiopolicy/engineconfigurable/parameter-framework/plugin/Usage.h @@ -0,0 +1,49 @@ +/* + * 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. + */ + +#pragma once + +#include "FormattedSubsystemObject.h" +#include "InstanceConfigurableElement.h" +#include "MappingContext.h" +#include <AudioPolicyPluginInterface.h> +#include <string> + +class PolicySubsystem; + +class Usage : public CFormattedSubsystemObject +{ +public: + Usage(const std::string &mappingValue, + CInstanceConfigurableElement *instanceConfigurableElement, + const CMappingContext &context); + +protected: + virtual bool receiveFromHW(std::string &error); + virtual bool sendToHW(std::string &error); + +private: + const PolicySubsystem *mPolicySubsystem; /**< Route subsytem plugin. */ + + /** + * Interface to communicate with Audio Policy Engine. + */ + android::AudioPolicyPluginInterface *mPolicyPluginInterface; + + audio_usage_t mId; /**< usage identifier to link with audio.h. */ + uint32_t mApplicableStrategy; /**< applicable strategy for this usage. */ + static const uint32_t mDefaultApplicableStrategy = 0; /**< default strategy. */ +}; diff --git a/services/audiopolicy/engineconfigurable/parameter-framework/plugin/VolumeProfile.cpp b/services/audiopolicy/engineconfigurable/parameter-framework/plugin/VolumeProfile.cpp new file mode 100755 index 0000000..5c155c8 --- /dev/null +++ b/services/audiopolicy/engineconfigurable/parameter-framework/plugin/VolumeProfile.cpp @@ -0,0 +1,75 @@ +/* + * 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. + */ + +#include "VolumeProfile.h" +#include "PolicyMappingKeys.h" +#include "PolicySubsystem.h" +#include "ParameterBlockType.h" +#include <Volume.h> +#include <math.h> + +using std::string; + +VolumeProfile::VolumeProfile(const string &mappingValue, + CInstanceConfigurableElement *instanceConfigurableElement, + const CMappingContext &context) + : CFormattedSubsystemObject(instanceConfigurableElement, + mappingValue, + MappingKeyAmend1, + (MappingKeyAmendEnd - MappingKeyAmend1 + 1), + context), + mPolicySubsystem(static_cast<const PolicySubsystem *>( + instanceConfigurableElement->getBelongingSubsystem())), + mPolicyPluginInterface(mPolicySubsystem->getPolicyPluginInterface()) +{ + uint32_t categoryKey = context.getItemAsInteger(MappingKeyCategory); + if (categoryKey >= Volume::DEVICE_CATEGORY_CNT) { + mCategory = Volume::DEVICE_CATEGORY_SPEAKER; + } else { + mCategory = static_cast<Volume::device_category>(categoryKey); + } + mId = static_cast<audio_stream_type_t>(context.getItemAsInteger(MappingKeyIdentifier)); + + // (no exception support, defer the error) + if (instanceConfigurableElement->getType() != CInstanceConfigurableElement::EParameterBlock) { + return; + } + // Get actual element type + const CParameterBlockType *parameterType = static_cast<const CParameterBlockType *>( + instanceConfigurableElement->getTypeElement()); + mPoints = parameterType->getArrayLength(); +} + +bool VolumeProfile::receiveFromHW(string & /*error*/) +{ + return true; +} + +bool VolumeProfile::sendToHW(string & /*error*/) +{ + Point points[mPoints]; + blackboardRead(&points, sizeof(Point) * mPoints); + + VolumeCurvePoints pointsVector; + for (size_t i = 0; i < mPoints; i++) { + VolumeCurvePoint curvePoint; + curvePoint.mIndex = points[i].index; + curvePoint.mDBAttenuation = static_cast<float>(points[i].dbAttenuation) / + (1UL << gFractional); + pointsVector.push_back(curvePoint); + } + return mPolicyPluginInterface->setVolumeProfileForStream(mId, mCategory, pointsVector); +} diff --git a/services/audiopolicy/engineconfigurable/parameter-framework/plugin/VolumeProfile.h b/services/audiopolicy/engineconfigurable/parameter-framework/plugin/VolumeProfile.h new file mode 100755 index 0000000..a00ae84 --- /dev/null +++ b/services/audiopolicy/engineconfigurable/parameter-framework/plugin/VolumeProfile.h @@ -0,0 +1,64 @@ +/* + * 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. + */ + +#pragma once + +#include "FormattedSubsystemObject.h" +#include "InstanceConfigurableElement.h" +#include "MappingContext.h" +#include <Volume.h> +#include <AudioPolicyPluginInterface.h> +#include <string> + +class PolicySubsystem; + +class VolumeProfile : public CFormattedSubsystemObject +{ +private: + struct Point + { + int index; + /** Volume is using FixedPointParameter until float parameters are available. */ + int16_t dbAttenuation; + } __attribute__((packed)); + +public: + VolumeProfile(const std::string &mappingValue, + CInstanceConfigurableElement *instanceConfigurableElement, + const CMappingContext &context); + +protected: + virtual bool receiveFromHW(std::string &error); + virtual bool sendToHW(std::string &error); + +private: + const PolicySubsystem *mPolicySubsystem; /**< Route subsytem plugin. */ + + /** + * Interface to communicate with Audio Policy Engine. + */ + android::AudioPolicyPluginInterface *mPolicyPluginInterface; + + /** + * volume profile identifier, which is in fact a stream type to link with audio.h. + */ + audio_stream_type_t mId; + + size_t mPoints; + Volume::device_category mCategory; + + static const uint32_t gFractional = 8; /**< Beware to align with the structure. */ +}; |