mirror of
https://github.com/openharmony/distributed_camera.git
synced 2026-07-19 16:43:57 -04:00
!104 fix distributed camera bug
Merge pull request !104 from zhuxu/master
This commit is contained in:
+2
@@ -16,6 +16,7 @@
|
||||
#ifndef OHOS_DCAMERA_SOURCE_DATRA_PROCESS_H
|
||||
#define OHOS_DCAMERA_SOURCE_DATRA_PROCESS_H
|
||||
|
||||
#include <mutex>
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
@@ -40,6 +41,7 @@ public:
|
||||
void GetAllStreamIds(std::vector<int32_t>& streamIds) override;
|
||||
|
||||
private:
|
||||
std::mutex streamMutex_;
|
||||
std::vector<std::shared_ptr<DCameraStreamDataProcess>> streamProcess_;
|
||||
std::set<int32_t> streamIds_;
|
||||
std::string devId_;
|
||||
|
||||
+1
-1
@@ -55,7 +55,7 @@ private:
|
||||
|
||||
std::thread producerThread_;
|
||||
std::condition_variable producerCon_;
|
||||
std::mutex producerMutex_;
|
||||
std::mutex bufferMutex_;
|
||||
std::queue<std::shared_ptr<DataBuffer>> buffers_;
|
||||
DCameraProducerState state_;
|
||||
uint32_t interval_;
|
||||
|
||||
+2
@@ -48,6 +48,7 @@ int32_t DCameraSourceDataProcess::FeedStream(std::vector<std::shared_ptr<DataBuf
|
||||
auto buffer = *(buffers.begin());
|
||||
DHLOGD("DCameraSourceDataProcess FeedStream devId %s dhId %s streamType %d streamSize: %d",
|
||||
GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str(), streamType_, buffer->Size());
|
||||
std::lock_guard<std::mutex> autoLock(streamMutex_);
|
||||
for (auto iter = streamProcess_.begin(); iter != streamProcess_.end(); iter++) {
|
||||
(*iter)->FeedStream(buffer);
|
||||
}
|
||||
@@ -102,6 +103,7 @@ int32_t DCameraSourceDataProcess::ReleaseStreams(std::vector<int32_t>& streamIds
|
||||
{
|
||||
DHLOGI("DCameraSourceDataProcess ReleaseStreams devId %s dhId %s streamType: %d", GetAnonyString(devId_).c_str(),
|
||||
GetAnonyString(dhId_).c_str(), streamType_);
|
||||
std::lock_guard<std::mutex> autoLock(streamMutex_);
|
||||
std::set<int32_t> streamIdSet(streamIds.begin(), streamIds.end());
|
||||
auto iter = streamProcess_.begin();
|
||||
while (iter != streamProcess_.end()) {
|
||||
|
||||
+36
-31
@@ -101,27 +101,30 @@ void DCameraStreamDataProcess::StartCapture(std::shared_ptr<DCameraStreamConfig>
|
||||
srcConfig->width_, srcConfig->height_, srcConfig->format_, srcConfig->dataspace_,
|
||||
srcConfig->type_, srcConfig->encodeType_);
|
||||
}
|
||||
std::lock_guard<std::mutex> autoLock(producerMutex_);
|
||||
srcConfig_ = srcConfig;
|
||||
if (streamType_ == CONTINUOUS_FRAME) {
|
||||
CreatePipeline();
|
||||
}
|
||||
for (auto iter = streamIds_.begin(); iter != streamIds_.end(); iter++) {
|
||||
uint32_t streamId = *iter;
|
||||
if (streamIds.find(streamId) == streamIds.end()) {
|
||||
continue;
|
||||
}
|
||||
{
|
||||
std::lock_guard<std::mutex> autoLock(producerMutex_);
|
||||
for (auto iter = streamIds_.begin(); iter != streamIds_.end(); iter++) {
|
||||
uint32_t streamId = *iter;
|
||||
if (streamIds.find(streamId) == streamIds.end()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
DHLOGI("DCameraStreamDataProcess StartCapture findProducer devId %s dhId %s streamType: %d streamId: %d",
|
||||
GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str(), streamType_, streamId);
|
||||
auto producerIter = producers_.find(streamId);
|
||||
if (producerIter != producers_.end()) {
|
||||
continue;
|
||||
DHLOGI("DCameraStreamDataProcess StartCapture findProducer devId %s dhId %s streamType: %d streamId: %d",
|
||||
GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str(), streamType_, streamId);
|
||||
auto producerIter = producers_.find(streamId);
|
||||
if (producerIter != producers_.end()) {
|
||||
continue;
|
||||
}
|
||||
DHLOGI("DCameraStreamDataProcess StartCapture CreateProducer devId %s dhId %s streamType: %d streamId: %d",
|
||||
GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str(), streamType_, streamId);
|
||||
producers_[streamId] =
|
||||
std::make_shared<DCameraStreamDataProcessProducer>(devId_, dhId_, streamId, streamType_);
|
||||
producers_[streamId]->Start();
|
||||
}
|
||||
DHLOGI("DCameraStreamDataProcess StartCapture CreateProducer devId %s dhId %s streamType: %d streamId: %d",
|
||||
GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str(), streamType_, streamId);
|
||||
producers_[streamId] = std::make_shared<DCameraStreamDataProcessProducer>(devId_, dhId_, streamId, streamType_);
|
||||
producers_[streamId]->Start();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,25 +134,27 @@ void DCameraStreamDataProcess::StopCapture(std::set<int32_t>& streamIds)
|
||||
DHLOGI("DCameraStreamDataProcess StopCapture devId %s dhId %s streamType: %d streamId: %d",
|
||||
GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str(), streamType_, *iter);
|
||||
}
|
||||
std::lock_guard<std::mutex> autoLock(producerMutex_);
|
||||
for (auto iter = streamIds_.begin(); iter != streamIds_.end(); iter++) {
|
||||
uint32_t streamId = *iter;
|
||||
if (streamIds.find(streamId) == streamIds.end()) {
|
||||
continue;
|
||||
}
|
||||
{
|
||||
std::lock_guard<std::mutex> autoLock(producerMutex_);
|
||||
for (auto iter = streamIds_.begin(); iter != streamIds_.end(); iter++) {
|
||||
uint32_t streamId = *iter;
|
||||
if (streamIds.find(streamId) == streamIds.end()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
DHLOGI("DCameraStreamDataProcess StopCapture findProducer devId %s dhId %s streamType: %d streamId: %d",
|
||||
GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str(), streamType_, streamId);
|
||||
auto producerIter = producers_.find(streamId);
|
||||
if (producerIter == producers_.end()) {
|
||||
DHLOGE("DCameraStreamDataProcess StopCapture no producer, devId %s dhId %s streamType: %d streamId: %d",
|
||||
DHLOGI("DCameraStreamDataProcess StopCapture findProducer devId %s dhId %s streamType: %d streamId: %d",
|
||||
GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str(), streamType_, streamId);
|
||||
continue;
|
||||
auto producerIter = producers_.find(streamId);
|
||||
if (producerIter == producers_.end()) {
|
||||
DHLOGE("DCameraStreamDataProcess StopCapture no producer, devId %s dhId %s streamType: %d streamId: %d",
|
||||
GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str(), streamType_, streamId);
|
||||
continue;
|
||||
}
|
||||
DHLOGI("DCameraStreamDataProcess StopCapture stop producer, devId %s dhId %s streamType: %d streamId: %d",
|
||||
GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str(), streamType_, streamId);
|
||||
producerIter->second->Stop();
|
||||
producerIter = producers_.erase(producerIter);
|
||||
}
|
||||
DHLOGI("DCameraStreamDataProcess StopCapture stop producer, devId %s dhId %s streamType: %d streamId: %d",
|
||||
GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str(), streamType_, streamId);
|
||||
producerIter->second->Stop();
|
||||
producerIter = producers_.erase(producerIter);
|
||||
}
|
||||
if (streamType_ == CONTINUOUS_FRAME && producers_.empty()) {
|
||||
DestroyPipeline();
|
||||
|
||||
+4
-4
@@ -75,7 +75,7 @@ void DCameraStreamDataProcessProducer::FeedStream(const std::shared_ptr<DataBuff
|
||||
{
|
||||
DHLOGD("DCameraStreamDataProcessProducer FeedStream devId %s dhId %s streamType: %d streamSize: %d",
|
||||
GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str(), streamType_, buffer->Size());
|
||||
std::unique_lock<std::mutex> lock(producerMutex_);
|
||||
std::unique_lock<std::mutex> lock(bufferMutex_);
|
||||
if (buffers_.size() >= DCAMERA_PRODUCER_MAX_BUFFER_SIZE) {
|
||||
DHLOGD("DCameraStreamDataProcessProducer FeedStream OverSize devId %s dhId %s streamType: %d streamSize: %d",
|
||||
GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str(), streamType_, buffer->Size());
|
||||
@@ -98,7 +98,7 @@ void DCameraStreamDataProcessProducer::LooperContinue()
|
||||
while (state_ == DCAMERA_PRODUCER_STATE_START) {
|
||||
std::shared_ptr<DataBuffer> buffer = nullptr;
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(producerMutex_);
|
||||
std::unique_lock<std::mutex> lock(bufferMutex_);
|
||||
producerCon_.wait_for(lock, std::chrono::milliseconds(interval_), [this] {
|
||||
return (this->state_ == DCAMERA_PRODUCER_STATE_STOP);
|
||||
});
|
||||
@@ -141,7 +141,7 @@ void DCameraStreamDataProcessProducer::LooperSnapShot()
|
||||
while (state_ == DCAMERA_PRODUCER_STATE_START) {
|
||||
std::shared_ptr<DataBuffer> buffer = nullptr;
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(producerMutex_);
|
||||
std::unique_lock<std::mutex> lock(bufferMutex_);
|
||||
producerCon_.wait(lock, [this] {
|
||||
return (!buffers_.empty() || state_ == DCAMERA_PRODUCER_STATE_STOP);
|
||||
});
|
||||
@@ -167,7 +167,7 @@ void DCameraStreamDataProcessProducer::LooperSnapShot()
|
||||
continue;
|
||||
}
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(producerMutex_);
|
||||
std::unique_lock<std::mutex> lock(bufferMutex_);
|
||||
buffers_.pop();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user