summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorbodamnam <bodamnam@google.com>2023-03-06 10:31:08 +0000
committerbodamnam <bodamnam@google.com>2023-03-15 02:37:19 +0000
commit3f2f6fcc77418e09f43b9b9804cc4bd304f3ffdd (patch)
treea4822f5bbff37b500a922425dce2e3b15f0edfbe /service
parentd45b64d109da41d4b2dde39b11ccae8d435989c7 (diff)
downloadImsMedia-3f2f6fcc77418e09f43b9b9804cc4bd304f3ffdd.tar.gz
Fix the StreamScheduler thread running infinite loop
1) The StreamScheduler calls the ProcessData method of the non-runtime node in the RunRegisteredNode method. There used to be a routine that removed nodes if the ProcessData method was invoked once, but it was removed by the change of StreamScheduler before which causes side effect in the video call not playing the video frames and RtpEncoderNode invokes ProcessData without time gap. I have improved that routine and made it more efficient to resolve the side effect. 2) Modify calling ProcessData interval to 1ms Bug: 270524661 Bug: 272724778 Test: Verified Voice Call, Video call and RTT call using loopback mode using the ImsMediaTestingApp, atest ImsMediaNativeTests Change-Id: I8c99cbf367e105a84c0f5dcd6644ffc90729f698
Diffstat (limited to 'service')
-rw-r--r--service/src/com/android/telephony/imsmedia/lib/libimsmedia/core/StreamScheduler.cpp70
-rw-r--r--service/src/com/android/telephony/imsmedia/lib/libimsmedia/core/include/StreamScheduler.h1
2 files changed, 28 insertions, 43 deletions
diff --git a/service/src/com/android/telephony/imsmedia/lib/libimsmedia/core/StreamScheduler.cpp b/service/src/com/android/telephony/imsmedia/lib/libimsmedia/core/StreamScheduler.cpp
index e3a59796..9184212c 100644
--- a/service/src/com/android/telephony/imsmedia/lib/libimsmedia/core/StreamScheduler.cpp
+++ b/service/src/com/android/telephony/imsmedia/lib/libimsmedia/core/StreamScheduler.cpp
@@ -19,11 +19,12 @@
#include <stdint.h>
#include <chrono>
#include <thread>
+#include <algorithm>
using namespace std::chrono;
-#define RUN_WAIT_TIMEOUT 6
-#define STOP_WAIT_TIMEOUT 1000
+#define RUN_WAIT_TIMEOUT_MS 1
+#define STOP_WAIT_TIMEOUT_MS 1000
StreamScheduler::StreamScheduler() {}
@@ -85,7 +86,7 @@ void StreamScheduler::Stop()
{
StopThread();
Awake();
- mConditionExit.wait_timeout(STOP_WAIT_TIMEOUT);
+ mConditionExit.wait_timeout(STOP_WAIT_TIMEOUT_MS);
}
IMLOGD1("[Stop] [%p] exit", this);
@@ -96,63 +97,48 @@ void StreamScheduler::Awake()
mConditionMain.signal();
}
-BaseNode* StreamScheduler::DetermineProcessingNode()
+void StreamScheduler::RunRegisteredNode()
{
- if (IsThreadStopped())
- {
- return nullptr;
- }
-
- BaseNode* pRetNode = nullptr;
- uint32_t nMaxDataInNode = 0;
+ // the list to contain non-source type node
+ std::list<BaseNode*> listNodesToRun;
for (auto& node : mlistRegisteredNode)
{
- if (node != nullptr && !node->IsRunTime() && !node->IsSourceNode())
+ if (node != nullptr && node->GetState() == kNodeStateRunning && !node->IsRunTime())
{
- uint32_t nDataInNode = node->GetDataCount();
-
- if (nDataInNode > 0 && nDataInNode >= nMaxDataInNode)
+ if (node->IsSourceNode()) // process the source node
{
- pRetNode = node;
- nMaxDataInNode = nDataInNode;
+ node->ProcessData();
+ }
+ else if (node->GetDataCount() > 0)
+ {
+ listNodesToRun.push_back(node); // store node to run
}
}
}
- return pRetNode;
-}
-
-void StreamScheduler::RunRegisteredNode()
-{
- // run source nodes
- for (auto& node : mlistRegisteredNode)
- {
- if (node != nullptr && node->GetState() == kNodeStateRunning && !node->IsRunTime() &&
- node->IsSourceNode())
- {
- node->ProcessData();
- }
- }
-
- for (;;)
+ while (!listNodesToRun.empty())
{
- BaseNode* pNode = DetermineProcessingNode();
-
- if (pNode == nullptr)
+ std::list<BaseNode*>::iterator maxNode =
+ std::max_element(listNodesToRun.begin(), listNodesToRun.end(),
+ [=](BaseNode* a, BaseNode* b)
+ {
+ return a->GetDataCount() < b->GetDataCount();
+ });
+
+ if (maxNode == listNodesToRun.end())
{
break;
}
- if (pNode->GetState() == kNodeStateRunning)
- {
- pNode->ProcessData();
- }
+ (*maxNode)->ProcessData(); // process the non runtime node
if (IsThreadStopped())
{
break;
}
+
+ listNodesToRun.remove(*maxNode);
};
}
@@ -188,10 +174,10 @@ void* StreamScheduler::run()
break;
}
- mConditionMain.wait_timeout(RUN_WAIT_TIMEOUT / 2);
+ mConditionMain.wait_timeout(RUN_WAIT_TIMEOUT_MS);
}
mConditionExit.signal();
IMLOGD1("[run] [%p] exit", this);
return nullptr;
-}
+} \ No newline at end of file
diff --git a/service/src/com/android/telephony/imsmedia/lib/libimsmedia/core/include/StreamScheduler.h b/service/src/com/android/telephony/imsmedia/lib/libimsmedia/core/include/StreamScheduler.h
index b083096a..f9612c5d 100644
--- a/service/src/com/android/telephony/imsmedia/lib/libimsmedia/core/include/StreamScheduler.h
+++ b/service/src/com/android/telephony/imsmedia/lib/libimsmedia/core/include/StreamScheduler.h
@@ -37,7 +37,6 @@ public:
virtual void* run();
private:
- BaseNode* DetermineProcessingNode();
void RunRegisteredNode();
std::list<BaseNode*> mlistRegisteredNode;
ImsMediaCondition mConditionMain;