framework fix

Signed-off-by: Bobie <zhouchuanbo2@huawei.com>
This commit is contained in:
Bobie 2024-11-01 15:33:11 +08:00
parent bfb61c94a4
commit 3c54ca1b71
3 changed files with 117 additions and 33 deletions

View File

@ -43,7 +43,7 @@ public:
std::shared_ptr<T> CreateFilter(const std::string& filterName, const FilterType type)
{
auto filter = CreateFilterPriv(filterName, type);
auto typedFilter = ReinterpretPointerCast<T>(filter);
auto typedFilter = Media::ReinterpretPointerCast<T>(filter);
return typedFilter;
}

View File

@ -97,7 +97,9 @@ Status Filter::PrepareDone()
}
for (auto iter : nextFiltersMap_) {
for (auto filter : iter.second) {
filter->Prepare();
if (filter != nullptr) {
filter->Prepare();
}
}
}
ChangeState(FilterState::READY);
@ -117,15 +119,17 @@ Status Filter::Start()
filter->Start();
}
}
} else {
for (auto iter : nextFiltersMap_) {
for (auto filter : iter.second) {
return Status::OK;
}
for (auto iter : nextFiltersMap_) {
for (auto filter : iter.second) {
if (filter != nullptr) {
filter->Start();
}
}
return StartDone();
}
return Status::OK;
return StartDone();
}
Status Filter::StartDone()
@ -147,7 +151,9 @@ Status Filter::Pause()
}
for (auto iter : nextFiltersMap_) {
for (auto filter : iter.second) {
filter->Pause();
if (filter != nullptr) {
filter->Pause();
}
}
}
return ret;
@ -162,7 +168,9 @@ Status Filter::PauseDragging()
}
for (auto iter : nextFiltersMap_) {
for (auto filter : iter.second) {
filter->PauseDragging();
if (filter != nullptr) {
filter->PauseDragging();
}
}
}
return ret;
@ -190,15 +198,17 @@ Status Filter::Resume()
filter->Resume();
}
}
} else {
for (auto iter : nextFiltersMap_) {
for (auto filter : iter.second) {
return Status::OK;
}
for (auto iter : nextFiltersMap_) {
for (auto filter : iter.second) {
if (filter != nullptr) {
filter->Resume();
}
}
return ResumeDone();
}
return Status::OK;
return ResumeDone();
}
Status Filter::ResumeDone()
@ -223,15 +233,17 @@ Status Filter::ResumeDragging()
filter->ResumeDragging();
}
}
} else {
for (auto iter : nextFiltersMap_) {
for (auto filter : iter.second) {
return Status::OK;
}
for (auto iter : nextFiltersMap_) {
for (auto filter : iter.second) {
if (filter != nullptr) {
filter->ResumeDragging();
}
}
return DoResumeDragging();
}
return Status::OK;
return DoResumeDragging();
}
Status Filter::Stop()
@ -244,7 +256,9 @@ Status Filter::Stop()
}
for (auto iter : nextFiltersMap_) {
for (auto filter : iter.second) {
filter->Stop();
if (filter != nullptr) {
filter->Stop();
}
}
}
return ret;
@ -264,7 +278,9 @@ Status Filter::Flush()
AVTRANS_LOGD("Flush %{public}s, pState:%{public}d", name_.c_str(), curState_);
for (auto iter : nextFiltersMap_) {
for (auto filter : iter.second) {
filter->Flush();
if (filter != nullptr) {
filter->Flush();
}
}
}
jobIdxBase_ = jobIdx_;
@ -278,20 +294,23 @@ Status Filter::Release()
filterTask_->SubmitJobOnce([this]() {
ReleaseDone();
});
for (auto iter : nextFiltersMap_) {
for (auto filter : iter.second) {
filter->Release();
}
}
} else {
for (auto iter : nextFiltersMap_) {
for (auto filter : iter.second) {
filter->Release();
}
}
return ReleaseDone();
return Status::OK;
}
return Status::OK;
for (auto iter : nextFiltersMap_) {
for (auto filter : iter.second) {
if (filter != nullptr) {
filter->Release();
}
}
}
return ReleaseDone();
}
Status Filter::ReleaseDone()
@ -308,7 +327,9 @@ Status Filter::SetPlayRange(int64_t start, int64_t end)
AVTRANS_LOGD("SetPlayRange %{public}s, pState:%{public}d", name_.c_str(), curState_);
for (auto iter : nextFiltersMap_) {
for (auto filter : iter.second) {
filter->SetPlayRange(start, end);
if (filter != nullptr) {
filter->SetPlayRange(start, end);
}
}
}
return DoSetPlayRange(start, end);
@ -322,6 +343,9 @@ Status Filter::Preroll()
}
for (auto iter : nextFiltersMap_) {
for (auto filter : iter.second) {
if (filter == nullptr) {
continue;
}
ret = filter->Preroll();
if (ret != Status::OK) {
return ret;
@ -336,6 +360,9 @@ Status Filter::WaitPrerollDone(bool render)
Status ret = Status::OK;
for (auto iter : nextFiltersMap_) {
for (auto filter : iter.second) {
if (filter == nullptr) {
continue;
}
auto curRet = filter->WaitPrerollDone(render);
if (curRet != Status::OK) {
ret = curRet;
@ -505,6 +532,9 @@ Status Filter::WaitAllState(FilterState state)
Status res = Status::OK;
for (auto iter : nextFiltersMap_) {
for (auto filter : iter.second) {
if (filter == nullptr) {
continue;
}
if (filter->WaitAllState(state) != Status::OK) {
res = filter->GetErrCode();
}

View File

@ -56,12 +56,18 @@ Status Pipeline::Prepare()
Media::SubmitJobOnce([&] {
Media::AutoLock lock(mutex_);
for (auto it = filters_.begin(); it != filters_.end(); ++it) {
if (*it == nullptr) {
continue;
}
ret = (*it)->Prepare();
if (ret != Status::OK) {
return;
}
}
for (auto it = filters_.begin(); it != filters_.end(); ++it) {
if (*it == nullptr) {
continue;
}
ret = (*it)->WaitAllState(FilterState::READY);
if (ret != Status::OK) {
return;
@ -79,12 +85,18 @@ Status Pipeline::Start()
Media::SubmitJobOnce([&] {
Media::AutoLock lock(mutex_);
for (auto it = filters_.begin(); it != filters_.end(); ++it) {
if (*it == nullptr) {
continue;
}
ret = (*it)->Start();
if (ret != Status::OK) {
return;
}
}
for (auto it = filters_.begin(); it != filters_.end(); ++it) {
if (*it == nullptr) {
continue;
}
ret = (*it)->WaitAllState(FilterState::RUNNING);
if (ret != Status::OK) {
return;
@ -102,12 +114,18 @@ Status Pipeline::Pause()
Media::SubmitJobOnce([&] {
Media::AutoLock lock(mutex_);
for (auto it = filters_.begin(); it != filters_.end(); ++it) {
if (*it == nullptr) {
continue;
}
auto rtv = (*it)->Pause();
if (rtv != Status::OK) {
ret = rtv;
}
}
for (auto it = filters_.begin(); it != filters_.end(); ++it) {
if (*it == nullptr) {
continue;
}
auto rtv = (*it)->WaitAllState(FilterState::PAUSED);
if (rtv != Status::OK) {
ret = rtv;
@ -125,12 +143,18 @@ Status Pipeline::Resume()
Media::SubmitJobOnce([&] {
Media::AutoLock lock(mutex_);
for (auto it = filters_.begin(); it != filters_.end(); ++it) {
if (*it == nullptr) {
continue;
}
ret = (*it)->Resume();
if (ret != Status::OK) {
return;
}
}
for (auto it = filters_.begin(); it != filters_.end(); ++it) {
if (*it == nullptr) {
continue;
}
ret = (*it)->WaitAllState(FilterState::RUNNING);
if (ret != Status::OK) {
return;
@ -158,6 +182,9 @@ Status Pipeline::Stop()
}
}
for (auto it = filters_.begin(); it != filters_.end(); ++it) {
if (*it == nullptr) {
continue;
}
auto rtv = (*it)->WaitAllState(FilterState::STOPPED);
if (rtv != Status::OK) {
ret = rtv;
@ -175,6 +202,9 @@ Status Pipeline::Flush()
Media::SubmitJobOnce([&] {
Media::AutoLock lock(mutex_);
for (auto it = filters_.begin(); it != filters_.end(); ++it) {
if (*it == nullptr) {
continue;
}
(*it)->Flush();
}
});
@ -188,9 +218,15 @@ Status Pipeline::Release()
Media::SubmitJobOnce([&] {
Media::AutoLock lock(mutex_);
for (auto it = filters_.begin(); it != filters_.end(); ++it) {
if (*it == nullptr) {
continue;
}
(*it)->Release();
}
for (auto it = filters_.begin(); it != filters_.end(); ++it) {
if (*it == nullptr) {
continue;
}
(*it)->WaitAllState(FilterState::RELEASED);
}
filters_.clear();
@ -205,6 +241,9 @@ Status Pipeline::Preroll(bool render)
Status ret = Status::OK;
Media::AutoLock lock(mutex_);
for (auto it = filters_.begin(); it != filters_.end(); ++it) {
if (*it == nullptr) {
continue;
}
auto rtv = (*it)->Preroll();
if (rtv != Status::OK) {
ret = rtv;
@ -213,6 +252,9 @@ Status Pipeline::Preroll(bool render)
}
}
for (auto it = filters_.begin(); it != filters_.end(); ++it) {
if (*it == nullptr) {
continue;
}
auto rtv = (*it)->WaitPrerollDone(render);
if (rtv != Status::OK) {
ret = rtv;
@ -230,6 +272,9 @@ Status Pipeline::SetPlayRange(int64_t start, int64_t end)
Media::SubmitJobOnce([&] {
Media::AutoLock lock(mutex_);
for (auto it = filters_.begin(); it != filters_.end(); ++it) {
if (*it == nullptr) {
continue;
}
(*it)->SetPlayRange(start, end);
}
});
@ -242,6 +287,9 @@ Status Pipeline::AddHeadFilters(std::vector<std::shared_ptr<Filter>> filtersIn)
AVTRANS_LOGI("AddHeadFilters enter.");
std::vector<std::shared_ptr<Filter>> filtersToAdd;
for (auto& filterIn : filtersIn) {
if (filterIn == nullptr) {
continue;
}
bool matched = false;
for (const auto& filter : filters_) {
if (filterIn == filter) {
@ -275,9 +323,11 @@ Status Pipeline::RemoveHeadFilter(const std::shared_ptr<Filter>& filter)
if (it != filters_.end()) {
filters_.erase(it);
}
filter->Release();
filter->WaitAllState(FilterState::RELEASED);
filter->ClearAllNextFilters();
if (filter != nullptr) {
filter->Release();
filter->WaitAllState(FilterState::RELEASED);
filter->ClearAllNextFilters();
}
return Status::OK;
});
return Status::OK;
@ -287,7 +337,9 @@ Status Pipeline::LinkFilters(const std::shared_ptr<Filter> &preFilter,
const std::vector<std::shared_ptr<Filter>> &nextFilters,
StreamType type)
{
TRUE_RETURN_V(preFilter == nullptr, Status::ERROR_NULL_POINTER);
for (auto nextFilter : nextFilters) {
TRUE_RETURN_V(nextFilter == nullptr, Status::ERROR_NULL_POINTER);
auto ret = preFilter->LinkNext(nextFilter, type);
nextFilter->LinkPipeLine(groupId_);
TRUE_RETURN_V(ret != Status::OK, ret);
@ -299,6 +351,7 @@ Status Pipeline::UpdateFilters(const std::shared_ptr<Filter> &preFilter,
const std::vector<std::shared_ptr<Filter>> &nextFilters,
StreamType type)
{
TRUE_RETURN_V(preFilter == nullptr, Status::ERROR_NULL_POINTER);
for (auto nextFilter : nextFilters) {
preFilter->UpdateNext(nextFilter, type);
}
@ -309,6 +362,7 @@ Status Pipeline::UnLinkFilters(const std::shared_ptr<Filter> &preFilter,
const std::vector<std::shared_ptr<Filter>> &nextFilters,
StreamType type)
{
TRUE_RETURN_V(preFilter == nullptr, Status::ERROR_NULL_POINTER);
for (auto nextFilter : nextFilters) {
preFilter->UnLinkNext(nextFilter, type);
}