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

Commit 4f04c9d2 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 11717025 from 3b88c57a to 24Q3-release

Change-Id: I8df79042e645ca2069224c96c4699e2008e4a3ed
parents 8f3baefb 3b88c57a
Loading
Loading
Loading
Loading
+1 −5
Original line number Diff line number Diff line
@@ -236,7 +236,6 @@ status_t AudioTrack::getMetrics(mediametrics::Item * &item)
AudioTrack::AudioTrack(const AttributionSourceState& attributionSource)
    : mClientAttributionSource(attributionSource)
{

}

AudioTrack::AudioTrack(
@@ -257,7 +256,6 @@ AudioTrack::AudioTrack(
        float maxRequiredSpeed,
        audio_port_handle_t selectedDeviceId)
{
    // make_unique does not aggregate init until c++20
    mSetParams = std::make_unique<SetParams>(
        streamType, sampleRate, format, channelMask, frameCount, flags, callback,
        notificationFrames, nullptr /*sharedBuffer*/, false /*threadCanCallJava*/,
@@ -377,9 +375,6 @@ AudioTrack::~AudioTrack()
}

void AudioTrack::stopAndJoinCallbacks() {
    // Prevent nullptr crash if it did not open properly.
    if (mStatus != NO_ERROR) return;

    // Make sure that callback function exits in the case where
    // it is looping on buffer full condition in obtainBuffer().
    // Otherwise the callback thread will never exit.
@@ -896,6 +891,7 @@ void AudioTrack::stop()
    const int64_t beginNs = systemTime();

    AutoMutex lock(mLock);
    if (mProxy == nullptr) return;  // not successfully initialized.
    mediametrics::Defer defer([&]() {
        mediametrics::LogItem(mMetricsId)
            .set(AMEDIAMETRICS_PROP_EVENT, AMEDIAMETRICS_PROP_EVENT_VALUE_STOP)
+3 −0
Original line number Diff line number Diff line
@@ -38,6 +38,9 @@ TEST(AudioTrackTestBasic, EmptyAudioTrack) {

    EXPECT_EQ(NO_INIT, at->initCheck());
    EXPECT_EQ(true, at->stopped());

    // ensure we do not crash.
    at->stop();
}

TEST(AudioTrackTest, TestPlayTrack) {
+23 −19
Original line number Diff line number Diff line
@@ -506,6 +506,8 @@ status_t StreamHalAidl::sendCommand(
                "%s %s: must be invoked from the worker thread (%d)",
                __func__, command.toString().c_str(), workerTid);
    }
    {
        std::lock_guard l(mCommandReplyLock);
        if (!mContext.getCommandMQ()->writeBlocking(&command, 1)) {
            ALOGE("%s: failed to write command %s to MQ", __func__, command.toString().c_str());
            return NOT_ENOUGH_DATA;
@@ -515,7 +517,8 @@ status_t StreamHalAidl::sendCommand(
            reply = &localReply;
        }
        if (!mContext.getReplyMQ()->readBlocking(reply, 1)) {
        ALOGE("%s: failed to read from reply MQ, command %s", __func__, command.toString().c_str());
            ALOGE("%s: failed to read from reply MQ, command %s",
                    __func__, command.toString().c_str());
            return NOT_ENOUGH_DATA;
        }
        {
@@ -528,6 +531,7 @@ status_t StreamHalAidl::sendCommand(
            mLastReply = *reply;
            mLastReplyExpirationNs = uptimeNanos() + mLastReplyLifeTimeNs;
        }
    }
    switch (reply->status) {
        case STATUS_OK: return OK;
        case STATUS_BAD_VALUE: return BAD_VALUE;
+11 −0
Original line number Diff line number Diff line
@@ -243,6 +243,15 @@ class StreamHalAidl : public virtual StreamHalInterface, public ConversionHelper
    const bool mIsInput;
    const audio_config_base_t mConfig;
    const StreamContextAidl mContext;
    // This lock is used to make sending of a command and receiving a reply an atomic
    // operation. Otherwise, when two threads are trying to send a command, they may both advance to
    // reading of the reply once the HAL has consumed the command from the MQ, and that creates a
    // race condition between them.
    //
    // Note that only access to command and reply MQs needs to be protected because the data MQ is
    // only accessed by the I/O thread. Also, there is no need to protect lookup operations on the
    // queues as they are thread-safe, only send/receive operation must be protected.
    std::mutex mCommandReplyLock;

  private:
    static audio_config_base_t configToBase(const audio_config& config) {
@@ -256,6 +265,8 @@ class StreamHalAidl : public virtual StreamHalInterface, public ConversionHelper
        std::lock_guard l(mLock);
        return mLastReply.state;
    }
    // Note: Since `sendCommand` takes mLock while holding mCommandReplyLock, never call
    // it with `mLock` being held.
    status_t sendCommand(
            const ::aidl::android::hardware::audio::core::StreamDescriptor::Command &command,
            ::aidl::android::hardware::audio::core::StreamDescriptor::Reply* reply = nullptr,