2022-10-14 01:07:47 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2022 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 <memory>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
2023-03-09 18:19:01 -08:00
|
|
|
#include <Utils.h>
|
2022-11-08 14:45:07 +05:30
|
|
|
#include <android-base/logging.h>
|
2022-10-14 01:07:47 +00:00
|
|
|
#include <fmq/AidlMessageQueue.h>
|
2024-01-09 20:50:53 +00:00
|
|
|
#include <fmq/EventFlag.h>
|
2022-11-08 14:45:07 +05:30
|
|
|
|
|
|
|
|
#include <aidl/android/hardware/audio/effect/BnEffect.h>
|
2022-10-26 22:47:20 +00:00
|
|
|
#include "EffectTypes.h"
|
2022-10-14 01:07:47 +00:00
|
|
|
|
|
|
|
|
namespace aidl::android::hardware::audio::effect {
|
|
|
|
|
|
|
|
|
|
class EffectContext {
|
|
|
|
|
public:
|
|
|
|
|
typedef ::android::AidlMessageQueue<
|
|
|
|
|
IEffect::Status, ::aidl::android::hardware::common::fmq::SynchronizedReadWrite>
|
|
|
|
|
StatusMQ;
|
|
|
|
|
typedef ::android::AidlMessageQueue<
|
2022-10-26 22:47:20 +00:00
|
|
|
float, ::aidl::android::hardware::common::fmq::SynchronizedReadWrite>
|
2022-10-14 01:07:47 +00:00
|
|
|
DataMQ;
|
|
|
|
|
|
2024-01-09 20:50:53 +00:00
|
|
|
EffectContext(size_t statusDepth, const Parameter::Common& common);
|
|
|
|
|
virtual ~EffectContext() {
|
|
|
|
|
if (mEfGroup) {
|
|
|
|
|
::android::hardware::EventFlag::deleteEventFlag(&mEfGroup);
|
2022-10-14 01:07:47 +00:00
|
|
|
}
|
2022-10-26 22:47:20 +00:00
|
|
|
}
|
2022-10-14 01:07:47 +00:00
|
|
|
|
2024-01-09 20:50:53 +00:00
|
|
|
std::shared_ptr<StatusMQ> getStatusFmq() const;
|
|
|
|
|
std::shared_ptr<DataMQ> getInputDataFmq() const;
|
|
|
|
|
std::shared_ptr<DataMQ> getOutputDataFmq() const;
|
2022-10-14 01:07:47 +00:00
|
|
|
|
2024-01-09 20:50:53 +00:00
|
|
|
float* getWorkBuffer();
|
2024-01-25 00:45:55 +00:00
|
|
|
size_t getWorkBufferSize() const;
|
2022-10-26 22:47:20 +00:00
|
|
|
|
2022-12-15 20:34:32 +00:00
|
|
|
// reset buffer status by abandon input data in FMQ
|
2024-01-09 20:50:53 +00:00
|
|
|
void resetBuffer();
|
|
|
|
|
void dupeFmq(IEffect::OpenEffectReturn* effectRet);
|
|
|
|
|
size_t getInputFrameSize() const;
|
|
|
|
|
size_t getOutputFrameSize() const;
|
|
|
|
|
int getSessionId() const;
|
|
|
|
|
int getIoHandle() const;
|
2022-10-26 22:47:20 +00:00
|
|
|
|
2024-01-09 20:50:53 +00:00
|
|
|
virtual void dupeFmqWithReopen(IEffect::OpenEffectReturn* effectRet);
|
2022-10-26 22:47:20 +00:00
|
|
|
|
|
|
|
|
virtual RetCode setOutputDevice(
|
2024-01-09 20:50:53 +00:00
|
|
|
const std::vector<aidl::android::media::audio::common::AudioDeviceDescription>& device);
|
2023-01-19 16:55:02 +05:30
|
|
|
|
2023-01-10 03:20:00 +00:00
|
|
|
virtual std::vector<aidl::android::media::audio::common::AudioDeviceDescription>
|
2024-01-09 20:50:53 +00:00
|
|
|
getOutputDevice();
|
2022-10-26 22:47:20 +00:00
|
|
|
|
2024-01-09 20:50:53 +00:00
|
|
|
virtual RetCode setAudioMode(const aidl::android::media::audio::common::AudioMode& mode);
|
|
|
|
|
virtual aidl::android::media::audio::common::AudioMode getAudioMode();
|
2022-10-26 22:47:20 +00:00
|
|
|
|
2024-01-09 20:50:53 +00:00
|
|
|
virtual RetCode setAudioSource(const aidl::android::media::audio::common::AudioSource& source);
|
|
|
|
|
virtual aidl::android::media::audio::common::AudioSource getAudioSource();
|
2022-10-26 22:47:20 +00:00
|
|
|
|
2024-01-09 20:50:53 +00:00
|
|
|
virtual RetCode setVolumeStereo(const Parameter::VolumeStereo& volumeStereo);
|
|
|
|
|
virtual Parameter::VolumeStereo getVolumeStereo();
|
2022-10-26 22:47:20 +00:00
|
|
|
|
2024-01-09 20:50:53 +00:00
|
|
|
virtual RetCode setCommon(const Parameter::Common& common);
|
|
|
|
|
virtual Parameter::Common getCommon();
|
|
|
|
|
|
|
|
|
|
virtual ::android::hardware::EventFlag* getStatusEventFlag();
|
2022-10-26 22:47:20 +00:00
|
|
|
|
|
|
|
|
protected:
|
2022-11-08 14:45:07 +05:30
|
|
|
size_t mInputFrameSize;
|
|
|
|
|
size_t mOutputFrameSize;
|
2024-01-09 20:50:53 +00:00
|
|
|
size_t mInputChannelCount;
|
|
|
|
|
size_t mOutputChannelCount;
|
|
|
|
|
Parameter::Common mCommon = {};
|
|
|
|
|
std::vector<aidl::android::media::audio::common::AudioDeviceDescription> mOutputDevice = {};
|
|
|
|
|
aidl::android::media::audio::common::AudioMode mMode =
|
|
|
|
|
aidl::android::media::audio::common::AudioMode::SYS_RESERVED_INVALID;
|
|
|
|
|
aidl::android::media::audio::common::AudioSource mSource =
|
|
|
|
|
aidl::android::media::audio::common::AudioSource::SYS_RESERVED_INVALID;
|
|
|
|
|
Parameter::VolumeStereo mVolumeStereo = {};
|
|
|
|
|
RetCode updateIOFrameSize(const Parameter::Common& common);
|
|
|
|
|
RetCode notifyDataMqUpdate();
|
2022-10-14 01:07:47 +00:00
|
|
|
|
|
|
|
|
private:
|
2022-10-26 22:47:20 +00:00
|
|
|
// fmq and buffers
|
2022-10-14 01:07:47 +00:00
|
|
|
std::shared_ptr<StatusMQ> mStatusMQ;
|
|
|
|
|
std::shared_ptr<DataMQ> mInputMQ;
|
|
|
|
|
std::shared_ptr<DataMQ> mOutputMQ;
|
2024-01-09 20:50:53 +00:00
|
|
|
// std::shared_ptr<IEffect::OpenEffectReturn> mRet;
|
2022-10-14 01:07:47 +00:00
|
|
|
// work buffer set by effect instances, the access and update are in same thread
|
2022-10-26 22:47:20 +00:00
|
|
|
std::vector<float> mWorkBuffer;
|
2024-01-09 20:50:53 +00:00
|
|
|
|
|
|
|
|
::android::hardware::EventFlag* mEfGroup;
|
2022-10-14 01:07:47 +00:00
|
|
|
};
|
|
|
|
|
} // namespace aidl::android::hardware::audio::effect
|