diff options
author | Hangyu Kuang <hkuang@google.com> | 2019-04-28 21:18:48 -0700 |
---|---|---|
committer | Hangyu Kuang <hkuang@google.com> | 2019-05-06 15:44:36 -0700 |
commit | 9c4de66caf0b87745bc83860c22174412d5af1b7 (patch) | |
tree | 0304bc6681c1a4ee5c2a5ff2e847e27128e03154 /media/eco/ECOSession.cpp | |
parent | 28aeb9e1a83027199b4e406418c6dcb351a7765a (diff) | |
download | av-9c4de66caf0b87745bc83860c22174412d5af1b7.tar.gz |
[ECOService]: Support adding listener after provider starts.
If a listener subscribe to ECOSession after the provider sending the
first session info, ECOSession should send the listener the latest
session info right after adding it to internal.
Also add a fix for the failrue in ECOSessionTest due to changing
FrameType from int32_t to int8_t.
Bug:117877984
Test: Unit test
Change-Id: Ib982c6d9bfadb625eb85e0653941e2608158c054
Diffstat (limited to 'media/eco/ECOSession.cpp')
-rw-r--r-- | media/eco/ECOSession.cpp | 77 |
1 files changed, 73 insertions, 4 deletions
diff --git a/media/eco/ECOSession.cpp b/media/eco/ECOSession.cpp index 3419d1d..1a1bc59 100644 --- a/media/eco/ECOSession.cpp +++ b/media/eco/ECOSession.cpp @@ -92,7 +92,7 @@ ECOSession::ECOSession(int32_t width, int32_t height, bool isCameraRecording) ECOSession::~ECOSession() { mStopThread = true; - mStatsQueueWaitCV.notify_all(); + mWorkerWaitCV.notify_all(); if (mThread.joinable()) { ECOLOGD("ECOSession: join the thread"); mThread.join(); @@ -112,8 +112,22 @@ void ECOSession::run() { while (!mStopThread) { std::unique_lock<std::mutex> runLock(mStatsQueueLock); - mStatsQueueWaitCV.wait(runLock, - [this] { return mStopThread == true || !mStatsQueue.empty(); }); + mWorkerWaitCV.wait(runLock, [this] { + return mStopThread == true || !mStatsQueue.empty() || mNewListenerAdded; + }); + + if (mStopThread) return; + + std::scoped_lock<std::mutex> lock(mSessionLock); + if (mNewListenerAdded) { + // Check if there is any session info available. + ECOData sessionInfo = generateLatestSessionInfoEcoData(); + if (!sessionInfo.isEmpty()) { + mListener->onNewInfo(sessionInfo); + } + mNewListenerAdded = false; + } + if (!mStatsQueue.empty()) { ECOData stats = mStatsQueue.front(); mStatsQueue.pop_front(); @@ -211,6 +225,57 @@ bool ECOSession::processSessionStats(const ECOData& stats) { return true; } +ECOData ECOSession::generateLatestSessionInfoEcoData() { + bool hasInfo = false; + + ECOData info(ECOData::DATA_TYPE_INFO, systemTime(SYSTEM_TIME_BOOTTIME)); + + if (mOutputWidth != -1) { + info.setInt32(ENCODER_OUTPUT_WIDTH, mOutputWidth); + hasInfo = true; + } + + if (mOutputHeight != -1) { + info.setInt32(ENCODER_OUTPUT_HEIGHT, mOutputHeight); + hasInfo = true; + } + + if (mCodecType != -1) { + info.setInt32(ENCODER_TYPE, mCodecType); + hasInfo = true; + } + + if (mCodecProfile != -1) { + info.setInt32(ENCODER_PROFILE, mCodecProfile); + hasInfo = true; + } + + if (mCodecLevel != -1) { + info.setInt32(ENCODER_LEVEL, mCodecLevel); + hasInfo = true; + } + + if (mBitrateBps != -1) { + info.setInt32(ENCODER_TARGET_BITRATE_BPS, mBitrateBps); + hasInfo = true; + } + + if (mKeyFrameIntervalFrames != -1) { + info.setInt32(ENCODER_KFI_FRAMES, mKeyFrameIntervalFrames); + hasInfo = true; + } + + if (mFramerateFps > 0) { + info.setFloat(ENCODER_FRAMERATE_FPS, mFramerateFps); + hasInfo = true; + } + + if (hasInfo) { + info.setString(KEY_INFO_TYPE, VALUE_INFO_TYPE_SESSION); + } + return info; +} + bool ECOSession::processFrameStats(const ECOData& stats) { ECOLOGD("processFrameStats"); @@ -371,6 +436,9 @@ Status ECOSession::addInfoListener( IPCThreadState::self()->getCallingUid(), IPCThreadState::self()->getCallingPid()); mListener = listener; + mNewListenerAdded = true; + mWorkerWaitCV.notify_all(); + *status = true; return binder::Status::ok(); } @@ -385,6 +453,7 @@ Status ECOSession::removeInfoListener( } mListener = nullptr; + mNewListenerAdded = false; *_aidl_return = true; return binder::Status::ok(); } @@ -393,7 +462,7 @@ Status ECOSession::pushNewStats(const ::android::media::eco::ECOData& stats, boo ECOLOGV("ECOSession get new stats type: %s", stats.getDataTypeString().c_str()); std::unique_lock<std::mutex> lock(mStatsQueueLock); mStatsQueue.push_back(stats); - mStatsQueueWaitCV.notify_all(); + mWorkerWaitCV.notify_all(); return binder::Status::ok(); } |