summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinux Build Service Account <lnxbuild@localhost>2023-09-06 14:54:20 -0700
committerLinux Build Service Account <lnxbuild@localhost>2023-09-06 14:54:20 -0700
commit81f05d3be209b6860c63095f925f3fe65b76ca0e (patch)
tree97409eeea3a879ef5032690ea0bb909b1ca55ce3
parent4619ec2cb5544cad7aa1f4744497bd0f6f5bc009 (diff)
parentb84385194fd520a5756dda8b42e6e49784a997d3 (diff)
Merge b84385194fd520a5756dda8b42e6e49784a997d3 on remote branch
Change-Id: I4fd045b994590cda4ed75ebd6c1a2aca1a72c2c0
-rw-r--r--media/libaudioclient/AudioTrack.cpp13
-rw-r--r--media/libaudioclient/include/media/AudioTrack.h5
-rw-r--r--media/mtp/MtpProperty.h3
-rw-r--r--services/audiopolicy/service/AudioPolicyInterfaceImpl.cpp21
4 files changed, 39 insertions, 3 deletions
diff --git a/media/libaudioclient/AudioTrack.cpp b/media/libaudioclient/AudioTrack.cpp
index 41a86a69db..23065d3cde 100644
--- a/media/libaudioclient/AudioTrack.cpp
+++ b/media/libaudioclient/AudioTrack.cpp
@@ -2373,7 +2373,6 @@ status_t AudioTrack::obtainBuffer(Buffer* audioBuffer, const struct timespec *re
// obtainBuffer() is called with mutex unlocked, so keep extra references to these fields to
// keep them from going away if another thread re-creates the track during obtainBuffer()
sp<AudioTrackClientProxy> proxy;
- sp<IMemory> iMem;
{ // start of lock scope
AutoMutex lock(mLock);
@@ -2399,8 +2398,9 @@ status_t AudioTrack::obtainBuffer(Buffer* audioBuffer, const struct timespec *re
}
// Keep the extra references
+ mProxyObtainBufferRef = mProxy;
proxy = mProxy;
- iMem = mCblkMemory;
+ mCblkMemoryObtainBufferRef = mCblkMemory;
if (mState == STATE_STOPPING) {
status = -EINTR;
@@ -2448,6 +2448,8 @@ void AudioTrack::releaseBuffer(const Buffer* audioBuffer)
buffer.mFrameCount = stepCount;
buffer.mRaw = audioBuffer->raw;
+ sp<IMemory> tempMemory;
+ sp<AudioTrackClientProxy> tempProxy;
AutoMutex lock(mLock);
if (audioBuffer->sequence != mSequence) {
// This Buffer came from a different IAudioTrack instance, so ignore the releaseBuffer
@@ -2457,7 +2459,12 @@ void AudioTrack::releaseBuffer(const Buffer* audioBuffer)
}
mReleased += stepCount;
mInUnderrun = false;
- mProxy->releaseBuffer(&buffer);
+ mProxyObtainBufferRef->releaseBuffer(&buffer);
+ // The extra reference of shared memory and proxy from `obtainBuffer` is not used after
+ // calling `releaseBuffer`. Move the extra reference to a temp strong pointer so that it
+ // will be cleared outside `releaseBuffer`.
+ tempMemory = std::move(mCblkMemoryObtainBufferRef);
+ tempProxy = std::move(mProxyObtainBufferRef);
// restart track if it was disabled by audioflinger due to previous underrun
restartIfDisabled();
diff --git a/media/libaudioclient/include/media/AudioTrack.h b/media/libaudioclient/include/media/AudioTrack.h
index b52d1d577b..64b817da61 100644
--- a/media/libaudioclient/include/media/AudioTrack.h
+++ b/media/libaudioclient/include/media/AudioTrack.h
@@ -1316,6 +1316,11 @@ public:
audio_track_cblk_t* mCblk; // re-load after mLock.unlock()
audio_io_handle_t mOutput = AUDIO_IO_HANDLE_NONE; // from AudioSystem::getOutputForAttr()
+ // A copy of shared memory and proxy between obtainBuffer and releaseBuffer to keep the
+ // shared memory valid when processing data.
+ sp<IMemory> mCblkMemoryObtainBufferRef GUARDED_BY(mLock);
+ sp<AudioTrackClientProxy> mProxyObtainBufferRef GUARDED_BY(mLock);
+
sp<AudioTrackThread> mAudioTrackThread;
bool mThreadCanCallJava;
diff --git a/media/mtp/MtpProperty.h b/media/mtp/MtpProperty.h
index 36d736065f..2bdbfd3262 100644
--- a/media/mtp/MtpProperty.h
+++ b/media/mtp/MtpProperty.h
@@ -26,6 +26,9 @@ namespace android {
class MtpDataPacket;
struct MtpPropertyValue {
+ // pointer str initialized to NULL so that free operation
+ // is not called for pre-assigned value
+ MtpPropertyValue() : str (NULL) {}
union {
int8_t i8;
uint8_t u8;
diff --git a/services/audiopolicy/service/AudioPolicyInterfaceImpl.cpp b/services/audiopolicy/service/AudioPolicyInterfaceImpl.cpp
index c33dba8096..d9981eab67 100644
--- a/services/audiopolicy/service/AudioPolicyInterfaceImpl.cpp
+++ b/services/audiopolicy/service/AudioPolicyInterfaceImpl.cpp
@@ -813,8 +813,29 @@ Status AudioPolicyService::startInput(int32_t portIdAidl)
Mutex::Autolock _l(mLock);
+ ALOGW_IF(client->silenced, "startInput on silenced input for port %d, uid %d. Unsilencing.",
+ portIdAidl,
+ client->attributionSource.uid);
+
+ if (client->active) {
+ ALOGE("Client should never be active before startInput. Uid %d port %d",
+ client->attributionSource.uid, portId);
+ finishRecording(client->attributionSource, client->attributes.source);
+ return binderStatusFromStatusT(INVALID_OPERATION);
+ }
+
+ // Force the possibly silenced client to be unsilenced since we just called
+ // startRecording (i.e. we have assumed it is unsilenced).
+ // At this point in time, the client is inactive, so no calls to appops are sent in
+ // setAppState_l.
+ // This ensures existing clients have the same behavior as new clients (starting unsilenced).
+ // TODO(b/282076713)
+ setAppState_l(client, APP_STATE_TOP);
+
client->active = true;
client->startTimeNs = systemTime();
+ // This call updates the silenced state, and since we are active, appropriately notifies appops
+ // if we silence the track.
updateUidStates_l();
status_t status;