diff options
author | alk3pInjection <webmaster@raspii.tech> | 2023-09-19 11:54:48 +0800 |
---|---|---|
committer | alk3pInjection <webmaster@raspii.tech> | 2023-09-19 11:54:48 +0800 |
commit | ccf5222c7b1a73a295ca17ec48ae07f36f80a4ce (patch) | |
tree | 326fdb44604e4c8b3951138ce3ca0c47b9774718 | |
parent | cb0b6a1923a602dbc80489d8b8a6a3f3b9f57a80 (diff) | |
parent | af2fef14b510e43ebd202311ea9af22d438f5dc2 (diff) |
Merge tag 'LA.QSSI.13.0.r1-11500.01-qssi.0' into tachibana-mr1
"LA.QSSI.13.0.r1-11500.01-qssi.0"
Change-Id: I09d513cc3e3ea0391a07ae7660542173c7c3f5cf
-rw-r--r-- | cmds/screenrecord/Android.bp | 1 | ||||
-rw-r--r-- | cmds/screenrecord/screenrecord.cpp | 29 | ||||
-rw-r--r-- | media/libaudioclient/AudioTrack.cpp | 13 | ||||
-rw-r--r-- | media/libaudioclient/include/media/AudioTrack.h | 5 | ||||
-rw-r--r-- | media/mtp/MtpProperty.h | 3 | ||||
-rw-r--r-- | services/audiopolicy/service/AudioPolicyInterfaceImpl.cpp | 21 |
6 files changed, 68 insertions, 4 deletions
diff --git a/cmds/screenrecord/Android.bp b/cmds/screenrecord/Android.bp index d0b3ce074f..6e15724941 100644 --- a/cmds/screenrecord/Android.bp +++ b/cmds/screenrecord/Android.bp @@ -43,6 +43,7 @@ cc_binary { "libmedia", "libmediandk", "libmedia_omx", + "libmedia_codeclist", "libutils", "libbinder", "libstagefright_foundation", diff --git a/cmds/screenrecord/screenrecord.cpp b/cmds/screenrecord/screenrecord.cpp index d866c18fe2..e7dae65b64 100644 --- a/cmds/screenrecord/screenrecord.cpp +++ b/cmds/screenrecord/screenrecord.cpp @@ -49,16 +49,20 @@ #include <gui/SurfaceComposerClient.h> #include <gui/ISurfaceComposer.h> #include <media/MediaCodecBuffer.h> +#include <media/MediaCodecInfo.h> #include <media/NdkMediaCodec.h> #include <media/NdkMediaFormatPriv.h> #include <media/NdkMediaMuxer.h> #include <media/openmax/OMX_IVCommon.h> #include <media/stagefright/MediaCodec.h> #include <media/stagefright/MediaCodecConstants.h> +#include <media/stagefright/MediaCodecList.h> +#include <media/stagefright/MediaCodecListOverrides.h> #include <media/stagefright/MediaErrors.h> #include <media/stagefright/PersistentSurface.h> #include <media/stagefright/foundation/ABuffer.h> #include <media/stagefright/foundation/AMessage.h> +#include <media/stagefright/foundation/AUtils.h> #include <mediadrm/ICrypto.h> #include <ui/DisplayMode.h> #include <ui/DisplayState.h> @@ -75,9 +79,12 @@ using android::ui::DisplayMode; using android::FrameOutput; using android::IBinder; using android::IGraphicBufferProducer; +using android::IMediaCodecList; using android::ISurfaceComposer; using android::MediaCodec; using android::MediaCodecBuffer; +using android::MediaCodecList; +using android::MediaCodecInfo; using android::Overlay; using android::PersistentSurface; using android::PhysicalDisplayId; @@ -197,7 +204,6 @@ static status_t prepareEncoder(float displayFps, sp<MediaCodec>* pCodec, format->setString(KEY_MIME, kMimeTypeAvc); format->setInt32(KEY_COLOR_FORMAT, OMX_COLOR_FormatAndroidOpaque); format->setInt32(KEY_BIT_RATE, gBitRate); - format->setFloat(KEY_FRAME_RATE, displayFps); format->setInt32(KEY_I_FRAME_INTERVAL, 10); format->setInt32(KEY_MAX_B_FRAMES, gBframes); if (gBframes > 0) { @@ -226,6 +232,27 @@ static status_t prepareEncoder(float displayFps, sp<MediaCodec>* pCodec, } } + // set frame-rate based on codec capability + const sp<IMediaCodecList> mcl = MediaCodecList::getInstance(); + AString codecName; + codec->getName(&codecName); + ssize_t codecIdx = mcl->findCodecByName(codecName.c_str()); + sp<MediaCodecInfo> info = mcl->getCodecInfo(codecIdx); + sp<MediaCodecInfo::Capabilities> capabilities = info->getCapabilitiesFor(kMimeTypeAvc); + const sp<AMessage> &details = capabilities->getDetails(); + std::string perfPointKey = "performance-point-" + std::to_string(gVideoWidth) + "x" + + std::to_string(gVideoHeight) + "-range"; + AString minPerfPoint, maxPerfPoint; + AString perfPoint; + if (details->findString(perfPointKey.c_str(), &perfPoint) + && splitString(perfPoint, "-", &minPerfPoint, &maxPerfPoint)) { + int perfPointValue = strtol(maxPerfPoint.c_str(), NULL, 10); + if (perfPointValue < displayFps) { + displayFps = perfPointValue; + } + } + format->setFloat(KEY_FRAME_RATE, displayFps); + err = codec->configure(format, NULL, NULL, MediaCodec::CONFIGURE_FLAG_ENCODE); if (err != NO_ERROR) { 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; |