summaryrefslogtreecommitdiff
path: root/service/src/com/android/telephony/imsmedia/lib/libimsmedia/core/StreamScheduler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'service/src/com/android/telephony/imsmedia/lib/libimsmedia/core/StreamScheduler.cpp')
-rw-r--r--service/src/com/android/telephony/imsmedia/lib/libimsmedia/core/StreamScheduler.cpp60
1 files changed, 28 insertions, 32 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 d71707c7..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,53 +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())
+ 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
+ {
+ node->ProcessData();
+ }
+ else if (node->GetDataCount() > 0)
{
- pRetNode = node;
- nMaxDataInNode = nDataInNode;
+ listNodesToRun.push_back(node); // store node to run
}
}
}
- return pRetNode;
-}
-
-void StreamScheduler::RunRegisteredNode()
-{
- 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);
};
}
@@ -178,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