Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8651b364 authored by Mikhail Naganov's avatar Mikhail Naganov
Browse files

audio: Plumb IStreamOutEventCallback to the stream

The plumbing was missing from the CL which has added
the callback (aosp/2256190).

Bug: 205884982
Test: atest VtsHalAudioCoreTargetTest
Change-Id: Iab3c970b3efd0281e34e07f98864531acc4c519e
parent 6f46365c
Loading
Loading
Loading
Loading
+8 −6
Original line number Original line Diff line number Diff line
@@ -102,9 +102,10 @@ void Module::cleanUpPatch(int32_t patchId) {
    erase_all_values(mPatches, std::set<int32_t>{patchId});
    erase_all_values(mPatches, std::set<int32_t>{patchId});
}
}


ndk::ScopedAStatus Module::createStreamContext(int32_t in_portConfigId, int64_t in_bufferSizeFrames,
ndk::ScopedAStatus Module::createStreamContext(
        int32_t in_portConfigId, int64_t in_bufferSizeFrames,
        std::shared_ptr<IStreamCallback> asyncCallback,
        std::shared_ptr<IStreamCallback> asyncCallback,
                                               StreamContext* out_context) {
        std::shared_ptr<IStreamOutEventCallback> outEventCallback, StreamContext* out_context) {
    if (in_bufferSizeFrames <= 0) {
    if (in_bufferSizeFrames <= 0) {
        LOG(ERROR) << __func__ << ": non-positive buffer size " << in_bufferSizeFrames;
        LOG(ERROR) << __func__ << ": non-positive buffer size " << in_bufferSizeFrames;
        return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
        return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
@@ -147,7 +148,7 @@ ndk::ScopedAStatus Module::createStreamContext(int32_t in_portConfigId, int64_t
                std::make_unique<StreamContext::ReplyMQ>(1, true /*configureEventFlagWord*/),
                std::make_unique<StreamContext::ReplyMQ>(1, true /*configureEventFlagWord*/),
                portConfigIt->format.value(), portConfigIt->channelMask.value(),
                portConfigIt->format.value(), portConfigIt->channelMask.value(),
                std::make_unique<StreamContext::DataMQ>(frameSize * in_bufferSizeFrames),
                std::make_unique<StreamContext::DataMQ>(frameSize * in_bufferSizeFrames),
                asyncCallback, params);
                asyncCallback, outEventCallback, params);
        if (temp.isValid()) {
        if (temp.isValid()) {
            *out_context = std::move(temp);
            *out_context = std::move(temp);
        } else {
        } else {
@@ -545,7 +546,7 @@ ndk::ScopedAStatus Module::openInputStream(const OpenInputStreamArguments& in_ar
    }
    }
    StreamContext context;
    StreamContext context;
    if (auto status = createStreamContext(in_args.portConfigId, in_args.bufferSizeFrames, nullptr,
    if (auto status = createStreamContext(in_args.portConfigId, in_args.bufferSizeFrames, nullptr,
                                          &context);
                                          nullptr, &context);
        !status.isOk()) {
        !status.isOk()) {
        return status;
        return status;
    }
    }
@@ -598,7 +599,8 @@ ndk::ScopedAStatus Module::openOutputStream(const OpenOutputStreamArguments& in_
    }
    }
    StreamContext context;
    StreamContext context;
    if (auto status = createStreamContext(in_args.portConfigId, in_args.bufferSizeFrames,
    if (auto status = createStreamContext(in_args.portConfigId, in_args.bufferSizeFrames,
                                          isNonBlocking ? in_args.callback : nullptr, &context);
                                          isNonBlocking ? in_args.callback : nullptr,
                                          in_args.eventCallback, &context);
        !status.isOk()) {
        !status.isOk()) {
        return status;
        return status;
    }
    }
+1 −0
Original line number Original line Diff line number Diff line
@@ -115,6 +115,7 @@ class Module : public BnModule {
    ndk::ScopedAStatus createStreamContext(
    ndk::ScopedAStatus createStreamContext(
            int32_t in_portConfigId, int64_t in_bufferSizeFrames,
            int32_t in_portConfigId, int64_t in_bufferSizeFrames,
            std::shared_ptr<IStreamCallback> asyncCallback,
            std::shared_ptr<IStreamCallback> asyncCallback,
            std::shared_ptr<IStreamOutEventCallback> outEventCallback,
            ::aidl::android::hardware::audio::core::StreamContext* out_context);
            ::aidl::android::hardware::audio::core::StreamContext* out_context);
    std::vector<::aidl::android::media::audio::common::AudioDevice> findConnectedDevices(
    std::vector<::aidl::android::media::audio::common::AudioDevice> findConnectedDevices(
            int32_t portConfigId);
            int32_t portConfigId);
+12 −1
Original line number Original line Diff line number Diff line
@@ -31,6 +31,7 @@
#include <aidl/android/hardware/audio/core/BnStreamIn.h>
#include <aidl/android/hardware/audio/core/BnStreamIn.h>
#include <aidl/android/hardware/audio/core/BnStreamOut.h>
#include <aidl/android/hardware/audio/core/BnStreamOut.h>
#include <aidl/android/hardware/audio/core/IStreamCallback.h>
#include <aidl/android/hardware/audio/core/IStreamCallback.h>
#include <aidl/android/hardware/audio/core/IStreamOutEventCallback.h>
#include <aidl/android/hardware/audio/core/MicrophoneInfo.h>
#include <aidl/android/hardware/audio/core/MicrophoneInfo.h>
#include <aidl/android/hardware/audio/core/StreamDescriptor.h>
#include <aidl/android/hardware/audio/core/StreamDescriptor.h>
#include <aidl/android/media/audio/common/AudioDevice.h>
#include <aidl/android/media/audio/common/AudioDevice.h>
@@ -76,6 +77,7 @@ class StreamContext {
                  const ::aidl::android::media::audio::common::AudioFormatDescription& format,
                  const ::aidl::android::media::audio::common::AudioFormatDescription& format,
                  const ::aidl::android::media::audio::common::AudioChannelLayout& channelLayout,
                  const ::aidl::android::media::audio::common::AudioChannelLayout& channelLayout,
                  std::unique_ptr<DataMQ> dataMQ, std::shared_ptr<IStreamCallback> asyncCallback,
                  std::unique_ptr<DataMQ> dataMQ, std::shared_ptr<IStreamCallback> asyncCallback,
                  std::shared_ptr<IStreamOutEventCallback> outEventCallback,
                  DebugParameters debugParameters)
                  DebugParameters debugParameters)
        : mCommandMQ(std::move(commandMQ)),
        : mCommandMQ(std::move(commandMQ)),
          mInternalCommandCookie(std::rand()),
          mInternalCommandCookie(std::rand()),
@@ -84,6 +86,7 @@ class StreamContext {
          mChannelLayout(channelLayout),
          mChannelLayout(channelLayout),
          mDataMQ(std::move(dataMQ)),
          mDataMQ(std::move(dataMQ)),
          mAsyncCallback(asyncCallback),
          mAsyncCallback(asyncCallback),
          mOutEventCallback(outEventCallback),
          mDebugParameters(debugParameters) {}
          mDebugParameters(debugParameters) {}
    StreamContext(StreamContext&& other)
    StreamContext(StreamContext&& other)
        : mCommandMQ(std::move(other.mCommandMQ)),
        : mCommandMQ(std::move(other.mCommandMQ)),
@@ -93,6 +96,7 @@ class StreamContext {
          mChannelLayout(other.mChannelLayout),
          mChannelLayout(other.mChannelLayout),
          mDataMQ(std::move(other.mDataMQ)),
          mDataMQ(std::move(other.mDataMQ)),
          mAsyncCallback(std::move(other.mAsyncCallback)),
          mAsyncCallback(std::move(other.mAsyncCallback)),
          mOutEventCallback(std::move(other.mOutEventCallback)),
          mDebugParameters(std::move(other.mDebugParameters)) {}
          mDebugParameters(std::move(other.mDebugParameters)) {}
    StreamContext& operator=(StreamContext&& other) {
    StreamContext& operator=(StreamContext&& other) {
        mCommandMQ = std::move(other.mCommandMQ);
        mCommandMQ = std::move(other.mCommandMQ);
@@ -102,6 +106,7 @@ class StreamContext {
        mChannelLayout = std::move(other.mChannelLayout);
        mChannelLayout = std::move(other.mChannelLayout);
        mDataMQ = std::move(other.mDataMQ);
        mDataMQ = std::move(other.mDataMQ);
        mAsyncCallback = std::move(other.mAsyncCallback);
        mAsyncCallback = std::move(other.mAsyncCallback);
        mOutEventCallback = std::move(other.mOutEventCallback);
        mDebugParameters = std::move(other.mDebugParameters);
        mDebugParameters = std::move(other.mDebugParameters);
        return *this;
        return *this;
    }
    }
@@ -120,6 +125,9 @@ class StreamContext {
    bool getForceSynchronousDrain() const { return mDebugParameters.forceSynchronousDrain; }
    bool getForceSynchronousDrain() const { return mDebugParameters.forceSynchronousDrain; }
    size_t getFrameSize() const;
    size_t getFrameSize() const;
    int getInternalCommandCookie() const { return mInternalCommandCookie; }
    int getInternalCommandCookie() const { return mInternalCommandCookie; }
    std::shared_ptr<IStreamOutEventCallback> getOutEventCallback() const {
        return mOutEventCallback;
    }
    ReplyMQ* getReplyMQ() const { return mReplyMQ.get(); }
    ReplyMQ* getReplyMQ() const { return mReplyMQ.get(); }
    int getTransientStateDelayMs() const { return mDebugParameters.transientStateDelayMs; }
    int getTransientStateDelayMs() const { return mDebugParameters.transientStateDelayMs; }
    bool isValid() const;
    bool isValid() const;
@@ -133,6 +141,7 @@ class StreamContext {
    ::aidl::android::media::audio::common::AudioChannelLayout mChannelLayout;
    ::aidl::android::media::audio::common::AudioChannelLayout mChannelLayout;
    std::unique_ptr<DataMQ> mDataMQ;
    std::unique_ptr<DataMQ> mDataMQ;
    std::shared_ptr<IStreamCallback> mAsyncCallback;
    std::shared_ptr<IStreamCallback> mAsyncCallback;
    std::shared_ptr<IStreamOutEventCallback> mOutEventCallback;  // Only used by output streams
    DebugParameters mDebugParameters;
    DebugParameters mDebugParameters;
};
};


@@ -203,13 +212,15 @@ class StreamOutWorkerLogic : public StreamWorkerCommonLogic {
  public:
  public:
    static const std::string kThreadName;
    static const std::string kThreadName;
    explicit StreamOutWorkerLogic(const StreamContext& context)
    explicit StreamOutWorkerLogic(const StreamContext& context)
        : StreamWorkerCommonLogic(context) {}
        : StreamWorkerCommonLogic(context), mEventCallback(context.getOutEventCallback()) {}


  protected:
  protected:
    Status cycle() override;
    Status cycle() override;


  private:
  private:
    bool write(size_t clientSize, StreamDescriptor::Reply* reply);
    bool write(size_t clientSize, StreamDescriptor::Reply* reply);

    std::shared_ptr<IStreamOutEventCallback> mEventCallback;
};
};
using StreamOutWorker = ::android::hardware::audio::common::StreamWorker<StreamOutWorkerLogic>;
using StreamOutWorker = ::android::hardware::audio::common::StreamWorker<StreamOutWorkerLogic>;