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) std::shared_ptr<T> CreateFilter(const std::string& filterName, const FilterType type)
{ {
auto filter = CreateFilterPriv(filterName, type); auto filter = CreateFilterPriv(filterName, type);
auto typedFilter = ReinterpretPointerCast<T>(filter); auto typedFilter = Media::ReinterpretPointerCast<T>(filter);
return typedFilter; return typedFilter;
} }

View File

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

View File

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