mirror of
https://github.com/Evolution-X/hardware_interfaces
synced 2026-02-01 16:50:18 +00:00
CSD: Add default AIDL HAL implementation am: 3c8b6ce171
Original change: https://android-review.googlesource.com/c/platform/hardware/interfaces/+/2813173 Change-Id: Ib509a9ca6e9b00c8017347f50146c9e1eebce04d Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -242,7 +242,8 @@ ndk::ScopedAStatus Module::createStreamContext(
|
||||
portConfigIt->channelMask.value(), portConfigIt->sampleRate.value().value, flags,
|
||||
portConfigIt->ext.get<AudioPortExt::mix>().handle,
|
||||
std::make_unique<StreamContext::DataMQ>(frameSize * in_bufferSizeFrames),
|
||||
asyncCallback, outEventCallback, params);
|
||||
asyncCallback, outEventCallback,
|
||||
std::weak_ptr<sounddose::StreamDataProcessorInterface>{}, params);
|
||||
if (temp.isValid()) {
|
||||
*out_context = std::move(temp);
|
||||
} else {
|
||||
|
||||
@@ -90,6 +90,14 @@ bool StreamContext::isValid() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
void StreamContext::startStreamDataProcessor() {
|
||||
auto streamDataProcessor = mStreamDataProcessor.lock();
|
||||
if (streamDataProcessor != nullptr) {
|
||||
streamDataProcessor->startDataProcessor(mSampleRate, getChannelCount(mChannelLayout),
|
||||
mFormat);
|
||||
}
|
||||
}
|
||||
|
||||
void StreamContext::reset() {
|
||||
mCommandMQ.reset();
|
||||
mReplyMQ.reset();
|
||||
@@ -593,6 +601,10 @@ bool StreamOutWorkerLogic::write(size_t clientSize, StreamDescriptor::Reply* rep
|
||||
fatal = true;
|
||||
LOG(ERROR) << __func__ << ": write failed: " << status;
|
||||
}
|
||||
auto streamDataProcessor = mContext->getStreamDataProcessor().lock();
|
||||
if (streamDataProcessor != nullptr) {
|
||||
streamDataProcessor->process(mDataBuffer.get(), actualFrameCount * frameSize);
|
||||
}
|
||||
} else {
|
||||
if (mContext->getAsyncCallback() == nullptr) {
|
||||
usleep(3000); // Simulate blocking transfer delay.
|
||||
|
||||
@@ -175,7 +175,7 @@ class Module : public BnModule {
|
||||
bool mMicMute = false;
|
||||
bool mMasterMute = false;
|
||||
float mMasterVolume = 1.0f;
|
||||
ChildInterface<sounddose::ISoundDose> mSoundDose;
|
||||
ChildInterface<sounddose::SoundDose> mSoundDose;
|
||||
std::optional<bool> mIsMmapSupported;
|
||||
|
||||
protected:
|
||||
|
||||
@@ -20,11 +20,23 @@
|
||||
|
||||
#include <aidl/android/hardware/audio/core/sounddose/BnSoundDose.h>
|
||||
#include <aidl/android/media/audio/common/AudioDevice.h>
|
||||
|
||||
using aidl::android::media::audio::common::AudioDevice;
|
||||
#include <aidl/android/media/audio/common/AudioFormatDescription.h>
|
||||
|
||||
namespace aidl::android::hardware::audio::core::sounddose {
|
||||
|
||||
// Interface used for processing the data received by a stream.
|
||||
class StreamDataProcessorInterface {
|
||||
public:
|
||||
virtual ~StreamDataProcessorInterface() = default;
|
||||
|
||||
virtual void startDataProcessor(
|
||||
uint32_t samplerate, uint32_t channelCount,
|
||||
const ::aidl::android::media::audio::common::AudioFormatDescription& format) = 0;
|
||||
virtual void setAudioDevice(
|
||||
const ::aidl::android::media::audio::common::AudioDevice& audioDevice) = 0;
|
||||
virtual void process(const void* buffer, size_t size) = 0;
|
||||
};
|
||||
|
||||
class SoundDose : public BnSoundDose {
|
||||
public:
|
||||
SoundDose() : mRs2Value(DEFAULT_MAX_RS2){};
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
#include <utils/Errors.h>
|
||||
|
||||
#include "core-impl/ChildInterface.h"
|
||||
#include "core-impl/SoundDose.h"
|
||||
#include "core-impl/utils.h"
|
||||
|
||||
namespace aidl::android::hardware::audio::core {
|
||||
@@ -87,6 +88,7 @@ class StreamContext {
|
||||
int32_t mixPortHandle, std::unique_ptr<DataMQ> dataMQ,
|
||||
std::shared_ptr<IStreamCallback> asyncCallback,
|
||||
std::shared_ptr<IStreamOutEventCallback> outEventCallback,
|
||||
std::weak_ptr<sounddose::StreamDataProcessorInterface> streamDataProcessor,
|
||||
DebugParameters debugParameters)
|
||||
: mCommandMQ(std::move(commandMQ)),
|
||||
mInternalCommandCookie(std::rand()),
|
||||
@@ -100,6 +102,7 @@ class StreamContext {
|
||||
mDataMQ(std::move(dataMQ)),
|
||||
mAsyncCallback(asyncCallback),
|
||||
mOutEventCallback(outEventCallback),
|
||||
mStreamDataProcessor(streamDataProcessor),
|
||||
mDebugParameters(debugParameters) {}
|
||||
StreamContext(StreamContext&& other)
|
||||
: mCommandMQ(std::move(other.mCommandMQ)),
|
||||
@@ -114,6 +117,7 @@ class StreamContext {
|
||||
mDataMQ(std::move(other.mDataMQ)),
|
||||
mAsyncCallback(std::move(other.mAsyncCallback)),
|
||||
mOutEventCallback(std::move(other.mOutEventCallback)),
|
||||
mStreamDataProcessor(std::move(other.mStreamDataProcessor)),
|
||||
mDebugParameters(std::move(other.mDebugParameters)),
|
||||
mFrameCount(other.mFrameCount) {}
|
||||
StreamContext& operator=(StreamContext&& other) {
|
||||
@@ -129,6 +133,7 @@ class StreamContext {
|
||||
mDataMQ = std::move(other.mDataMQ);
|
||||
mAsyncCallback = std::move(other.mAsyncCallback);
|
||||
mOutEventCallback = std::move(other.mOutEventCallback);
|
||||
mStreamDataProcessor = std::move(other.mStreamDataProcessor);
|
||||
mDebugParameters = std::move(other.mDebugParameters);
|
||||
mFrameCount = other.mFrameCount;
|
||||
return *this;
|
||||
@@ -154,6 +159,10 @@ class StreamContext {
|
||||
std::shared_ptr<IStreamOutEventCallback> getOutEventCallback() const {
|
||||
return mOutEventCallback;
|
||||
}
|
||||
std::weak_ptr<sounddose::StreamDataProcessorInterface> getStreamDataProcessor() const {
|
||||
return mStreamDataProcessor;
|
||||
}
|
||||
void startStreamDataProcessor();
|
||||
int getPortId() const { return mPortId; }
|
||||
ReplyMQ* getReplyMQ() const { return mReplyMQ.get(); }
|
||||
int getTransientStateDelayMs() const { return mDebugParameters.transientStateDelayMs; }
|
||||
@@ -179,6 +188,7 @@ class StreamContext {
|
||||
std::unique_ptr<DataMQ> mDataMQ;
|
||||
std::shared_ptr<IStreamCallback> mAsyncCallback;
|
||||
std::shared_ptr<IStreamOutEventCallback> mOutEventCallback; // Only used by output streams
|
||||
std::weak_ptr<sounddose::StreamDataProcessorInterface> mStreamDataProcessor;
|
||||
DebugParameters mDebugParameters;
|
||||
long mFrameCount = 0;
|
||||
};
|
||||
|
||||
@@ -79,6 +79,10 @@ class StreamOutPrimary final : public StreamOut,
|
||||
|
||||
ndk::ScopedAStatus getHwVolume(std::vector<float>* _aidl_return) override;
|
||||
ndk::ScopedAStatus setHwVolume(const std::vector<float>& in_channelVolumes) override;
|
||||
|
||||
ndk::ScopedAStatus setConnectedDevices(
|
||||
const std::vector<::aidl::android::media::audio::common::AudioDevice>& devices)
|
||||
override;
|
||||
};
|
||||
|
||||
} // namespace aidl::android::hardware::audio::core
|
||||
|
||||
@@ -37,7 +37,9 @@ using android::base::GetBoolProperty;
|
||||
namespace aidl::android::hardware::audio::core {
|
||||
|
||||
StreamPrimary::StreamPrimary(StreamContext* context, const Metadata& metadata)
|
||||
: StreamAlsa(context, metadata, 3 /*readWriteRetries*/), mIsInput(isInput(metadata)) {}
|
||||
: StreamAlsa(context, metadata, 3 /*readWriteRetries*/), mIsInput(isInput(metadata)) {
|
||||
context->startStreamDataProcessor();
|
||||
}
|
||||
|
||||
std::vector<alsa::DeviceProfile> StreamPrimary::getDeviceProfiles() {
|
||||
static const std::vector<alsa::DeviceProfile> kBuiltInSource{
|
||||
@@ -183,4 +185,15 @@ ndk::ScopedAStatus StreamOutPrimary::setHwVolume(const std::vector<float>& in_ch
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus StreamOutPrimary::setConnectedDevices(
|
||||
const std::vector<::aidl::android::media::audio::common::AudioDevice>& devices) {
|
||||
if (!devices.empty()) {
|
||||
auto streamDataProcessor = mContextInstance.getStreamDataProcessor().lock();
|
||||
if (streamDataProcessor != nullptr) {
|
||||
streamDataProcessor->setAudioDevice(devices[0]);
|
||||
}
|
||||
}
|
||||
return StreamSwitcher::setConnectedDevices(devices);
|
||||
}
|
||||
|
||||
} // namespace aidl::android::hardware::audio::core
|
||||
|
||||
Reference in New Issue
Block a user