mirror of
https://github.com/Evolution-X/hardware_interfaces
synced 2026-02-01 11:36:00 +00:00
Merge "Wait for all the thread loop to exit to finish the filter/dvr/frontend close/stop API Call" into sc-dev
This commit is contained in:
@@ -27,12 +27,16 @@ namespace V1_0 {
|
||||
namespace implementation {
|
||||
|
||||
#define WAIT_TIMEOUT 3000000000
|
||||
|
||||
Demux::Demux(uint32_t demuxId, sp<Tuner> tuner) {
|
||||
mDemuxId = demuxId;
|
||||
mTunerService = tuner;
|
||||
}
|
||||
|
||||
Demux::~Demux() {}
|
||||
Demux::~Demux() {
|
||||
mFrontendInputThreadRunning = false;
|
||||
std::lock_guard<std::mutex> lock(mFrontendInputThreadLock);
|
||||
}
|
||||
|
||||
Return<Result> Demux::setFrontendDataSource(uint32_t frontendId) {
|
||||
ALOGV("%s", __FUNCTION__);
|
||||
@@ -171,6 +175,8 @@ Return<Result> Demux::close() {
|
||||
mFilters.clear();
|
||||
mLastUsedFilterId = -1;
|
||||
mTunerService->removeDemux(mDemuxId);
|
||||
mFrontendInputThreadRunning = false;
|
||||
std::lock_guard<std::mutex> lock(mFrontendInputThreadLock);
|
||||
|
||||
return Result::SUCCESS;
|
||||
}
|
||||
@@ -322,6 +328,7 @@ uint16_t Demux::getFilterTpid(uint64_t filterId) {
|
||||
}
|
||||
|
||||
void Demux::startFrontendInputLoop() {
|
||||
mFrontendInputThreadRunning = true;
|
||||
pthread_create(&mFrontendInputThread, NULL, __threadLoopFrontend, this);
|
||||
pthread_setname_np(mFrontendInputThread, "frontend_input_thread");
|
||||
}
|
||||
@@ -334,8 +341,6 @@ void* Demux::__threadLoopFrontend(void* user) {
|
||||
|
||||
void Demux::frontendInputThreadLoop() {
|
||||
std::lock_guard<std::mutex> lock(mFrontendInputThreadLock);
|
||||
mFrontendInputThreadRunning = true;
|
||||
|
||||
if (!mDvrPlayback) {
|
||||
ALOGW("[Demux] No software Frontend input configured. Ending Frontend thread loop.");
|
||||
mFrontendInputThreadRunning = false;
|
||||
|
||||
@@ -37,7 +37,10 @@ Dvr::Dvr(DvrType type, uint32_t bufferSize, const sp<IDvrCallback>& cb, sp<Demux
|
||||
mDemux = demux;
|
||||
}
|
||||
|
||||
Dvr::~Dvr() {}
|
||||
Dvr::~Dvr() {
|
||||
mDvrThreadRunning = false;
|
||||
lock_guard<mutex> lock(mDvrThreadLock);
|
||||
}
|
||||
|
||||
Return<void> Dvr::getQueueDesc(getQueueDesc_cb _hidl_cb) {
|
||||
ALOGV("%s", __FUNCTION__);
|
||||
@@ -118,6 +121,9 @@ Return<Result> Dvr::detachFilter(const sp<V1_0::IFilter>& filter) {
|
||||
|
||||
Return<Result> Dvr::start() {
|
||||
ALOGV("%s", __FUNCTION__);
|
||||
if (mDvrThreadRunning) {
|
||||
return Result::SUCCESS;
|
||||
}
|
||||
|
||||
if (!mCallback) {
|
||||
return Result::NOT_INITIALIZED;
|
||||
@@ -128,6 +134,7 @@ Return<Result> Dvr::start() {
|
||||
}
|
||||
|
||||
if (mType == DvrType::PLAYBACK) {
|
||||
mDvrThreadRunning = true;
|
||||
pthread_create(&mDvrThread, NULL, __threadLoopPlayback, this);
|
||||
pthread_setname_np(mDvrThread, "playback_waiting_loop");
|
||||
} else if (mType == DvrType::RECORD) {
|
||||
@@ -144,7 +151,6 @@ Return<Result> Dvr::stop() {
|
||||
ALOGV("%s", __FUNCTION__);
|
||||
|
||||
mDvrThreadRunning = false;
|
||||
|
||||
lock_guard<mutex> lock(mDvrThreadLock);
|
||||
|
||||
mIsRecordStarted = false;
|
||||
@@ -164,6 +170,8 @@ Return<Result> Dvr::flush() {
|
||||
Return<Result> Dvr::close() {
|
||||
ALOGV("%s", __FUNCTION__);
|
||||
|
||||
mDvrThreadRunning = false;
|
||||
lock_guard<mutex> lock(mDvrThreadLock);
|
||||
return Result::SUCCESS;
|
||||
}
|
||||
|
||||
@@ -199,7 +207,6 @@ void* Dvr::__threadLoopPlayback(void* user) {
|
||||
void Dvr::playbackThreadLoop() {
|
||||
ALOGD("[Dvr] playback threadLoop start.");
|
||||
lock_guard<mutex> lock(mDvrThreadLock);
|
||||
mDvrThreadRunning = true;
|
||||
|
||||
while (mDvrThreadRunning) {
|
||||
uint32_t efState = 0;
|
||||
|
||||
@@ -77,7 +77,10 @@ Filter::Filter(DemuxFilterType type, uint64_t filterId, uint32_t bufferSize,
|
||||
}
|
||||
}
|
||||
|
||||
Filter::~Filter() {}
|
||||
Filter::~Filter() {
|
||||
mFilterThreadRunning = false;
|
||||
std::lock_guard<std::mutex> lock(mFilterThreadLock);
|
||||
}
|
||||
|
||||
Return<void> Filter::getId64Bit(getId64Bit_cb _hidl_cb) {
|
||||
ALOGV("%s", __FUNCTION__);
|
||||
@@ -137,15 +140,14 @@ Return<Result> Filter::configure(const DemuxFilterSettings& settings) {
|
||||
|
||||
Return<Result> Filter::start() {
|
||||
ALOGV("%s", __FUNCTION__);
|
||||
|
||||
mFilterThreadRunning = true;
|
||||
return startFilterLoop();
|
||||
}
|
||||
|
||||
Return<Result> Filter::stop() {
|
||||
ALOGV("%s", __FUNCTION__);
|
||||
|
||||
mFilterThreadRunning = false;
|
||||
|
||||
std::lock_guard<std::mutex> lock(mFilterThreadLock);
|
||||
return Result::SUCCESS;
|
||||
}
|
||||
|
||||
@@ -185,6 +187,8 @@ Return<Result> Filter::releaseAvHandle(const hidl_handle& avMemory, uint64_t avD
|
||||
Return<Result> Filter::close() {
|
||||
ALOGV("%s", __FUNCTION__);
|
||||
|
||||
mFilterThreadRunning = false;
|
||||
std::lock_guard<std::mutex> lock(mFilterThreadLock);
|
||||
return mDemux->removeFilter(mFilterId);
|
||||
}
|
||||
|
||||
@@ -331,9 +335,11 @@ void* Filter::__threadLoopFilter(void* user) {
|
||||
}
|
||||
|
||||
void Filter::filterThreadLoop() {
|
||||
ALOGD("[Filter] filter %" PRIu64 " threadLoop start.", mFilterId);
|
||||
if (!mFilterThreadRunning) {
|
||||
return;
|
||||
}
|
||||
std::lock_guard<std::mutex> lock(mFilterThreadLock);
|
||||
mFilterThreadRunning = true;
|
||||
ALOGD("[Filter] filter %" PRIu64 " threadLoop start.", mFilterId);
|
||||
|
||||
// For the first time of filter output, implementation needs to send the filter
|
||||
// Event Callback without waiting for the DATA_CONSUMED to init the process.
|
||||
@@ -382,6 +388,9 @@ void Filter::filterThreadLoop() {
|
||||
// We do not wait for the last round of written data to be read to finish the thread
|
||||
// because the VTS can verify the reading itself.
|
||||
for (int i = 0; i < SECTION_WRITE_COUNT; i++) {
|
||||
if (!mFilterThreadRunning) {
|
||||
break;
|
||||
}
|
||||
while (mFilterThreadRunning && mIsUsingFMQ) {
|
||||
status_t status = mFilterEventFlag->wait(
|
||||
static_cast<uint32_t>(DemuxQueueNotifyBits::DATA_CONSUMED), &efState,
|
||||
@@ -417,9 +426,8 @@ void Filter::filterThreadLoop() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
mFilterThreadRunning = false;
|
||||
break;
|
||||
}
|
||||
|
||||
ALOGD("[Filter] filter thread ended.");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user