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

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

Snap for 13204655 from 3fef84e7 to 25Q2-release

Change-Id: I8c68eb9b7c22a6147af1c81ed5290a819542344d
parents 69b2ab6a 3fef84e7
Loading
Loading
Loading
Loading
+18 −16
Original line number Diff line number Diff line
@@ -71,6 +71,7 @@ status_t CryptoAsync::decrypt(sp<AMessage> &msg) {
       return -ENOSYS;
    }
    bool shouldPost = false;
    msg->setWhat(kWhatDecrypt);
    Mutexed<std::list<sp<AMessage>>>::Locked pendingBuffers(mPendingBuffers);
    if (mState != kCryptoAsyncActive) {
       ALOGE("Cannot decrypt in errored state");
@@ -241,18 +242,16 @@ void CryptoAsync::onMessageReceived(const sp<AMessage> & msg) {
                pendingBuffers->pop_front();
                continue;
            }
            nextTask = kWhatDecrypt;
            nextTask = nextBuffer->what();
        }
        return OK;
    };
    sp<AMessage> thisMsg;
    uint32_t nextTask = kWhatDoNothing;
    getCurrentAndNextTask(&thisMsg, nextTask);
    switch(msg->what()) {
        case kWhatDecrypt:
        {
            sp<AMessage> thisMsg;
            uint32_t nextTask = kWhatDoNothing;
            if(OK != getCurrentAndNextTask(&thisMsg, nextTask)) {
                return;
            }
            if (thisMsg != nullptr) {
                int32_t action;
                err = OK;
@@ -280,15 +279,6 @@ void CryptoAsync::onMessageReceived(const sp<AMessage> & msg) {
                    mState = kCryptoAsyncError;
                }
            }
            // we won't take  next buffers if buffer caused
            // an error. We want the caller to deal with the error first
            // Expected behahiour is that the caller acknowledge the error
            // with a call to stop() which clear the queues.
            // Then move forward with processing of next set of buffers.
            if (mState == kCryptoAsyncActive && nextTask != kWhatDoNothing) {
                sp<AMessage> nextMsg = new AMessage(nextTask,this);
                nextMsg->post();
            }
            break;
        }

@@ -306,10 +296,13 @@ void CryptoAsync::onMessageReceived(const sp<AMessage> & msg) {
                returnList->splice(returnList->end(), std::move(*pendingBuffers));
            }
            pendingBuffers->clear();
            // stop() is a blocking call.
            // this is needed as the queue is cleared now and there should
            // not be any next task. The next buffer when queued will kick off this loop
            nextTask = kWhatDoNothing;
            mState = kCryptoAsyncActive;
            response->setInt32("err", OK);
            response->postReply(replyID);

            break;
        }

@@ -321,6 +314,15 @@ void CryptoAsync::onMessageReceived(const sp<AMessage> & msg) {
            break;
        }
    }
    // we won't take  next buffers if buffer caused
    // an error. We want the caller to deal with the error first
    // Expected behahiour is that the caller acknowledge the error
    // with a call to stop() which clear the queues.
    // Then move forward with processing of next set of buffers.
    if (mState == kCryptoAsyncActive && nextTask != kWhatDoNothing) {
        sp<AMessage> nextMsg = new AMessage(nextTask,this);
        nextMsg->post();
    }
}

}  // namespace android
+19 −13
Original line number Diff line number Diff line
@@ -4298,6 +4298,21 @@ inline void MediaCodec::initClientConfigParcel(ClientConfigParcel& clientConfig)
    clientConfig.id = mCodecId;
}

void MediaCodec::stopCryptoAsync() {
    if (mCryptoAsync) {
        sp<RefBase> obj;
        sp<MediaCodecBuffer> buffer;
        std::list<sp<AMessage>> stalebuffers;
        mCryptoAsync->stop(&stalebuffers);
        for (sp<AMessage> &msg : stalebuffers) {
            if (msg->findObject("buffer", &obj)) {
                buffer = decltype(buffer.get())(obj.get());
                mBufferChannel->discardBuffer(buffer);
            }
        }
    }
}

void MediaCodec::onMessageReceived(const sp<AMessage> &msg) {
    switch (msg->what()) {
        case kWhatCodecNotify:
@@ -4330,10 +4345,7 @@ void MediaCodec::onMessageReceived(const sp<AMessage> &msg) {
                    }
                    codecErrorState = kCodecErrorState;
                    origin += stateString(mState);
                    if (mCryptoAsync) {
                        //TODO: do some book keeping on the buffers
                        mCryptoAsync->stop();
                    }
                    stopCryptoAsync();
                    switch (mState) {
                        case INITIALIZING:
                        {
@@ -5630,9 +5642,7 @@ void MediaCodec::onMessageReceived(const sp<AMessage> &msg) {

            sp<AReplyToken> replyID;
            CHECK(msg->senderAwaitsResponse(&replyID));
            if (mCryptoAsync) {
                mCryptoAsync->stop();
            }
            stopCryptoAsync();
            sp<AMessage> asyncNotify;
            (void)msg->findMessage("async", &asyncNotify);
            // post asyncNotify if going out of scope.
@@ -6100,11 +6110,7 @@ void MediaCodec::onMessageReceived(const sp<AMessage> &msg) {
            mReplyID = replyID;
            // TODO: skip flushing if already FLUSHED
            setState(FLUSHING);
            if (mCryptoAsync) {
                std::list<sp<AMessage>> pendingBuffers;
                mCryptoAsync->stop(&pendingBuffers);
                //TODO: do something with these buffers
            }
            stopCryptoAsync();
            mCodec->signalFlush();
            returnBuffersToCodec();
            TunnelPeekState previousState = mTunnelPeekState;
@@ -6932,7 +6938,7 @@ status_t MediaCodec::onQueueInputBuffer(const sp<AMessage> &msg) {
            // prepare a message and enqueue
            sp<AMessage> cryptoInfo = new AMessage();
            buildCryptoInfoAMessage(cryptoInfo, CryptoAsync::kActionDecrypt);
            mCryptoAsync->decrypt(cryptoInfo);
            err = mCryptoAsync->decrypt(cryptoInfo);
        } else if (msg->findObject("cryptoInfos", &obj)) {
                buffer->meta()->setObject("cryptoInfos", obj);
                err = mBufferChannel->queueSecureInputBuffers(
+2 −0
Original line number Diff line number Diff line
@@ -757,6 +757,8 @@ private:

    void onReleaseCrypto(const sp<AMessage>& msg);

    void stopCryptoAsync();

    // managing time-of-flight aka latency
    typedef struct {
            int64_t presentationUs;
+30 −0
Original line number Diff line number Diff line
@@ -82,6 +82,8 @@
#define ALOGVV(a...) do { } while(0)
#endif

namespace audioserver_flags = com::android::media::audioserver;

namespace android {

using namespace std::string_view_literals;
@@ -627,6 +629,11 @@ status_t AudioFlinger::openMmapStream(MmapStreamInterface::stream_direction_t di
        }
    }
    if (ret != NO_ERROR) {
        if (audioserver_flags::enable_gmap_mode()
                && direction == MmapStreamInterface::DIRECTION_INPUT) {
            audio_utils::lock_guard _l(mutex());
            setHasAlreadyCaptured_l(adjAttributionSource.uid);
        }
        return ret;
    }

@@ -2541,6 +2548,9 @@ status_t AudioFlinger::createRecord(const media::CreateRecordRequest& _input,
            audio_utils::lock_guard _l2(thread->mutex());
            thread->addEffectChain_l(chain);
        }
        if (audioserver_flags::enable_gmap_mode()) {
            setHasAlreadyCaptured_l(adjAttributionSource.uid);
        }
        break;
    }
    // End of retry loop.
@@ -2577,6 +2587,26 @@ Exit:

// ----------------------------------------------------------------------------

void AudioFlinger::setHasAlreadyCaptured_l(uid_t uid) {
    {
        const std::lock_guard _l(mCapturingClientsMutex);
        if (mCapturingClients.count(uid)) return;
        mCapturingClients.emplace(uid);
    }
    for (size_t i = 0; i < mPlaybackThreads.size(); i++) {
        IAfPlaybackThread* const playbackThread = mPlaybackThreads.valueAt(i).get();
        playbackThread->checkUpdateTrackMetadataForUid(uid);
    }
    for (size_t i = 0; i < mMmapThreads.size(); i++) {
        IAfMmapThread* const mmapThread = mMmapThreads.valueAt(i).get();
        if (mmapThread->isOutput()) {
            IAfMmapPlaybackThread* const mmapPlaybackThread =
                    mmapThread->asIAfMmapPlaybackThread().get();
            mmapPlaybackThread->checkUpdateTrackMetadataForUid(uid);
        }
    }
}

status_t AudioFlinger::getAudioPolicyConfig(media::AudioPolicyConfig *config)
{
    if (config == nullptr) {
+13 −0
Original line number Diff line number Diff line
@@ -417,8 +417,15 @@ private:

    bool isHardeningOverrideEnabled() const final;

    bool hasAlreadyCaptured(uid_t uid) const final {
        const std::lock_guard _l(mCapturingClientsMutex);
        return mCapturingClients.contains(uid);
    }

    // ---- end of IAfThreadCallback interface

    void setHasAlreadyCaptured_l(uid_t uid) REQUIRES(mutex());

    /* List available audio ports and their attributes */
    status_t listAudioPorts(unsigned int* num_ports, struct audio_port* ports) const
            EXCLUDES_AudioFlinger_Mutex;
@@ -788,6 +795,12 @@ private:
    const int64_t mStartTime = audio_utils_get_real_time_ns();
    // Late-inited from main()
    std::atomic<int64_t> mStartupFinishedTime {};

    // List of client UIDs having already captured audio in the past.
    // This is used to control GMAP bidirectional mode track metadata tag
    // generation.
    std::set<uid_t> mCapturingClients GUARDED_BY(mCapturingClientsMutex);
    mutable std::mutex  mCapturingClientsMutex; // only for mCapturingClients
};

// ----------------------------------------------------------------------------
Loading