1 Star 0 Fork 1K

开发者手机开源团队 / drivers_peripheral

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
patch 14.68 KB
一键复制 编辑 原始数据 按行查看 历史
diff --git a/audio/supportlibs/alsa_adapter/src/alsa_lib_render.c b/audio/supportlibs/alsa_adapter/src/alsa_lib_render.c
index d131b94ee..9e2524384 100644
--- a/audio/supportlibs/alsa_adapter/src/alsa_lib_render.c
+++ b/audio/supportlibs/alsa_adapter/src/alsa_lib_render.c
@@ -188,8 +188,6 @@ int32_t AudioCtlRenderGetVolume(const struct DevHandle *handle, int cmdId, struc
int32_t AudioCtlRenderSetPauseStu(
const struct DevHandle *handle, int cmdId, const struct AudioHwRenderParam *handleData)
{
- struct AudioCardInfo *cardIns = NULL;
-
(void)cmdId;
if (handle == NULL || handleData == NULL) {
AUDIO_FUNC_LOGE("Parameter error!");
diff --git a/camera/hal/adapter/platform/v4l2/src/driver_adapter/include/v4l2_dev.h b/camera/hal/adapter/platform/v4l2/src/driver_adapter/include/v4l2_dev.h
index 31b7b81ce..761e74f49 100644
--- a/camera/hal/adapter/platform/v4l2/src/driver_adapter/include/v4l2_dev.h
+++ b/camera/hal/adapter/platform/v4l2/src/driver_adapter/include/v4l2_dev.h
@@ -113,6 +113,7 @@ private:
int epollFd_ = 0;
std::vector<epoll_event> epollEvent_;
std::mutex epollLock_;
+ std::mutex streamLock_;
std::shared_ptr<HosV4L2Buffers> myBuffers_ = nullptr;
std::shared_ptr<HosV4L2Streams> myStreams_ = nullptr;
diff --git a/camera/hal/adapter/platform/v4l2/src/driver_adapter/src/v4l2_dev.cpp b/camera/hal/adapter/platform/v4l2/src/driver_adapter/src/v4l2_dev.cpp
index efcc181bb..2128bf6ff 100644
--- a/camera/hal/adapter/platform/v4l2/src/driver_adapter/src/v4l2_dev.cpp
+++ b/camera/hal/adapter/platform/v4l2/src/driver_adapter/src/v4l2_dev.cpp
@@ -238,7 +238,13 @@ void HosV4L2Dev::loopBuffers()
CAMERA_LOGD("!!! loopBuffers enter, streamNumber_=%{public}d\n", streamNumber_);
prctl(PR_SET_NAME, "v4l2_loopbuffer");
- while (streamNumber_ > 0) {
+ while (true) {
+ {
+ std::lock_guard<std::mutex> l(streamLock_);
+ if (streamNumber_ <= 0) {
+ break;
+ }
+ }
nfds = epoll_wait(epollFd_, events, MAXSTREAMCOUNT, -1);
CAMERA_LOGD("loopBuffers: epoll_wait rc = %{public}d streamNumber_ == %{public}d\n", nfds, streamNumber_);
@@ -357,47 +363,46 @@ RetCode HosV4L2Dev::StartStream(const std::string& cameraID)
RetCode HosV4L2Dev::StopStream(const std::string& cameraID)
{
- int rc, fd;
-
- if (myStreams_ == nullptr) {
- CAMERA_LOGE("error: StopStream: myStreams_ is NULL\n");
+ if (myStreams_ == nullptr || streamThread_ == nullptr) {
+ CAMERA_LOGE("error: StopStream: myStreams_ or streamThread_ is nullptr");
return RC_ERROR;
}
- if (streamThread_ == nullptr) {
- CAMERA_LOGE("StopStream thread is stopped\n");
+ int fd = GetCurrentFd(cameraID);
+ if (fd < 0) {
+ CAMERA_LOGE("error: StopStream: GetCurrentFd error\n");
return RC_ERROR;
}
- streamNumber_ -= 1;
- CAMERA_LOGD("HosV4L2Dev::StopStream streamNumber_ = %d\n", streamNumber_);
+ unsigned int streamNum = 0;
+ {
+ std::lock_guard<std::mutex> l(streamLock_);
+ streamNum = --streamNumber_;
+ CAMERA_LOGD("HosV4L2Dev::StopStream streamNumber_ = %d\n", streamNumber_);
+ }
- if (streamNumber_ == 0) {
+ if (streamNum == 0) {
CAMERA_LOGD("waiting loopBuffers stop\n");
uint64_t one = 1;
write(eventFd_, &one, sizeof(one));
streamThread_->join();
close(eventFd_);
+ CAMERA_LOGD("waiting loopBuffers exit\n");
}
- fd = GetCurrentFd(cameraID);
- if (fd < 0) {
- CAMERA_LOGE("error: ReqBuffers: GetCurrentFd error\n");
- return RC_ERROR;
- }
-
- rc = myStreams_->V4L2StreamOff(fd);
- if (rc == RC_ERROR) {
- CAMERA_LOGE("error: StartStream: V4L2StreamOn error\n");
+ if (myStreams_->V4L2StreamOff(fd) == RC_ERROR) {
+ CAMERA_LOGE("error: StopStream: V4L2StreamOn error\n");
return RC_ERROR;
}
EraseEpoll(fd);
-
- if (streamNumber_ == 0) {
- close(epollFd_);
- delete streamThread_;
- streamThread_ = nullptr;
+ {
+ std::lock_guard<std::mutex> l(streamLock_);
+ if (streamNumber_ == 0) {
+ close(epollFd_);
+ delete streamThread_;
+ streamThread_ = nullptr;
+ }
}
return RC_OK;
diff --git a/camera/hal/buffer_manager/src/buffer_manager.cpp b/camera/hal/buffer_manager/src/buffer_manager.cpp
index 8de9c6cb6..97d36ae01 100644
--- a/camera/hal/buffer_manager/src/buffer_manager.cpp
+++ b/camera/hal/buffer_manager/src/buffer_manager.cpp
@@ -55,4 +55,13 @@ std::shared_ptr<IBufferPool> BufferManager::GetBufferPool(uint64_t id)
return bufferPoolMap_[id].lock();
}
+
+void BufferManager::EraseBufferPoolMapById(uint64_t id)
+{
+ std::lock_guard<std::mutex> l(lock_);
+ auto findIter = bufferPoolMap_.find(id);
+ if (findIter != bufferPoolMap_.end()) {
+ bufferPoolMap_.erase(findIter);
+ }
+}
} // namespace OHOS::Camera
diff --git a/camera/hal/buffer_manager/src/buffer_pool.cpp b/camera/hal/buffer_manager/src/buffer_pool.cpp
index 8900198f3..6d638938d 100644
--- a/camera/hal/buffer_manager/src/buffer_pool.cpp
+++ b/camera/hal/buffer_manager/src/buffer_pool.cpp
@@ -247,12 +247,14 @@ void BufferPool::SetId(const int64_t id)
void BufferPool::NotifyStop()
{
+ std::unique_lock<std::mutex> l(lock_);
stop_ = true;
cv_.notify_all();
}
void BufferPool::NotifyStart()
{
+ std::unique_lock<std::mutex> l(lock_);
stop_ = false;
cv_.notify_all();
}
diff --git a/camera/hal/hdi_impl/include/stream_operator/istream.h b/camera/hal/hdi_impl/include/stream_operator/istream.h
index f7e676649..4e8769c63 100644
--- a/camera/hal/hdi_impl/include/stream_operator/istream.h
+++ b/camera/hal/hdi_impl/include/stream_operator/istream.h
@@ -53,6 +53,7 @@ public:
virtual RetCode OnFrame(const std::shared_ptr<CaptureRequest>& request) = 0;
virtual bool IsRunning() const = 0;
virtual void DumpStatsInfo() const = 0;
+ virtual void ReleaseStreamBufferPool() = 0;
public:
static std::map<StreamIntent, std::string> g_availableStreamType;
diff --git a/camera/hal/hdi_impl/include/stream_operator/stream_base.h b/camera/hal/hdi_impl/include/stream_operator/stream_base.h
index bec3a5541..b7e3c9ca5 100644
--- a/camera/hal/hdi_impl/include/stream_operator/stream_base.h
+++ b/camera/hal/hdi_impl/include/stream_operator/stream_base.h
@@ -51,6 +51,7 @@ public:
RetCode OnFrame(const std::shared_ptr<CaptureRequest>& request) override;
bool IsRunning() const override;
void DumpStatsInfo() const override;
+ void ReleaseStreamBufferPool() override;
virtual void HandleRequest();
virtual uint64_t GetUsage();
diff --git a/camera/hal/hdi_impl/src/stream_operator/stream_base.cpp b/camera/hal/hdi_impl/src/stream_operator/stream_base.cpp
index ab972e3b1..9a3977057 100644
--- a/camera/hal/hdi_impl/src/stream_operator/stream_base.cpp
+++ b/camera/hal/hdi_impl/src/stream_operator/stream_base.cpp
@@ -599,4 +599,13 @@ void StreamBase::DumpStatsInfo() const
tunnel_->DumpStats();
}
}
+
+void StreamBase::ReleaseStreamBufferPool()
+{
+ BufferManager* mgr = BufferManager::GetInstance();
+ if (mgr != nullptr) {
+ mgr->EraseBufferPoolMapById(poolId_);
+ }
+ bufferPool_ = nullptr;
+}
} // namespace OHOS::Camera
diff --git a/camera/hal/hdi_impl/src/stream_operator/stream_operator.cpp b/camera/hal/hdi_impl/src/stream_operator/stream_operator.cpp
index 87118e55d..be89514f2 100644
--- a/camera/hal/hdi_impl/src/stream_operator/stream_operator.cpp
+++ b/camera/hal/hdi_impl/src/stream_operator/stream_operator.cpp
@@ -278,6 +278,7 @@ int32_t StreamOperator::ReleaseStreams(const std::vector<int32_t>& streamIds)
it->second->StopStream();
}
it->second->DumpStatsInfo();
+ it->second->ReleaseStreamBufferPool();
streamMap_.erase(it);
}
diff --git a/camera/hal/include/buffer_manager.h b/camera/hal/include/buffer_manager.h
index e25edf33e..15974882c 100644
--- a/camera/hal/include/buffer_manager.h
+++ b/camera/hal/include/buffer_manager.h
@@ -32,6 +32,7 @@ public:
// get a buffer pool from id.
std::shared_ptr<IBufferPool> GetBufferPool(uint64_t id);
+ void EraseBufferPoolMapById(uint64_t id);
private:
BufferManager() = default;
diff --git a/camera/hal/pipeline_core/ipp/src/offline_pipeline.cpp b/camera/hal/pipeline_core/ipp/src/offline_pipeline.cpp
index b5e35b497..f76b5c7a8 100644
--- a/camera/hal/pipeline_core/ipp/src/offline_pipeline.cpp
+++ b/camera/hal/pipeline_core/ipp/src/offline_pipeline.cpp
@@ -32,7 +32,9 @@ RetCode OfflinePipeline::StartProcess()
running_ = true;
processThread_ = new std::thread([this]() {
prctl(PR_SET_NAME, "offlinepipeline");
+ std::unique_lock<std::mutex> l(queueLock_);
while (running_) {
+ cv_.wait(l, [this] { return !(running_.load() && bufferCache_.empty()); });
HandleBuffers();
}
});
@@ -49,11 +51,14 @@ RetCode OfflinePipeline::StopProcess()
return RC_ERROR;
}
- if (running_.load() == false) {
- return RC_OK;
+ {
+ std::unique_lock<std::mutex> l(queueLock_);
+ if (running_.load() == false) {
+ return RC_OK;
+ }
+ running_ = false;
}
- running_ = false;
cv_.notify_one();
processThread_->join();
delete processThread_;
@@ -148,31 +153,18 @@ void OfflinePipeline::ReceiveCache(std::vector<std::shared_ptr<IBuffer>>& buffer
void OfflinePipeline::HandleBuffers()
{
- if (bufferCache_.empty()) {
- std::unique_lock<std::mutex> l(queueLock_);
- if (bufferCache_.empty()) {
- cv_.wait(l, [this] { return !(running_.load() && bufferCache_.empty()); });
- }
- }
-
if (running_ == false) {
return;
}
std::vector<std::shared_ptr<IBuffer>> cache = {};
- if (!bufferCache_.empty()) {
- std::unique_lock<std::mutex> l(queueLock_);
- if (!bufferCache_.empty()) {
- cache = bufferCache_.front();
- bufferCache_.pop_front();
- }
- }
-
+ cache = bufferCache_.front();
+ bufferCache_.pop_front();
if (cache.empty()) {
return;
}
- ProcessCache(cache);
+ ProcessCache(cache);
return;
}
diff --git a/camera/hal/pipeline_core/nodes/src/source_node/source_node.cpp b/camera/hal/pipeline_core/nodes/src/source_node/source_node.cpp
index 9fb1a3c60..4ce3fd50d 100644
--- a/camera/hal/pipeline_core/nodes/src/source_node/source_node.cpp
+++ b/camera/hal/pipeline_core/nodes/src/source_node/source_node.cpp
@@ -246,7 +246,9 @@ RetCode SourceNode::PortHandler::StartDistributeBuffers()
int id = format.streamId_;
std::string name = "collect#" + std::to_string(id);
prctl(PR_SET_NAME, name.c_str());
+ std::unique_lock<std::mutex> l(rblock);
while (dbtRun) {
+ rbcv.wait(l, [this] { return !dbtRun || !respondBufferList.empty(); });
DistributeBuffers();
}
});
@@ -257,8 +259,11 @@ RetCode SourceNode::PortHandler::StartDistributeBuffers()
RetCode SourceNode::PortHandler::StopDistributeBuffers()
{
CAMERA_LOGV("SourceNode::PortHandler::StopDistributeBuffers enter");
- dbtRun = false;
- rbcv.notify_one();
+ {
+ std::unique_lock<std::mutex> l(rblock);
+ dbtRun = false;
+ rbcv.notify_one();
+ }
if (distributor != nullptr) {
distributor->join();
}
@@ -271,8 +276,6 @@ void SourceNode::PortHandler::DistributeBuffers()
{
std::shared_ptr<IBuffer> buffer = nullptr;
{
- std::unique_lock<std::mutex> l(rblock);
- rbcv.wait(l, [this] { return dbtRun == false || !respondBufferList.empty(); });
if (!dbtRun) {
return;
}
diff --git a/camera/hal/pipeline_core/nodes/src/source_node/source_node.h b/camera/hal/pipeline_core/nodes/src/source_node/source_node.h
index 8893deb40..09d0f11e9 100644
--- a/camera/hal/pipeline_core/nodes/src/source_node/source_node.h
+++ b/camera/hal/pipeline_core/nodes/src/source_node/source_node.h
@@ -60,7 +60,7 @@ protected:
bool cltRun = false;
std::unique_ptr<std::thread> collector = nullptr;
- bool dbtRun = false;
+ std::atomic<bool> dbtRun = false;
std::unique_ptr<std::thread> distributor = nullptr;
std::shared_ptr<IBufferPool> pool = nullptr;
diff --git a/thermal/interfaces/hdi_service/include/thermal_hdf_timer.h b/thermal/interfaces/hdi_service/include/thermal_hdf_timer.h
index b5c425601..d215268b8 100644
--- a/thermal/interfaces/hdi_service/include/thermal_hdf_timer.h
+++ b/thermal/interfaces/hdi_service/include/thermal_hdf_timer.h
@@ -19,6 +19,7 @@
#include <atomic>
#include <map>
#include <thread>
+#include "thermal_dfx.h"
#include "thermal_hdf_config.h"
#include "thermal_simulation_node.h"
#include "thermal_zone_manager.h"
@@ -62,6 +63,7 @@ private:
HdfThermalCallbackInfo tzInfoEventV2_;
HdfThermalCallbackInfo tzInfoEvent_;
sptr<IThermalCallback> thermalCb_;
+ std::unique_ptr<ThermalDfx> thermalDfx_ = nullptr;
std::vector<int32_t> multipleList_;
int32_t reportTime_;
int32_t isSim_;
diff --git a/thermal/interfaces/hdi_service/src/thermal_dfx.cpp b/thermal/interfaces/hdi_service/src/thermal_dfx.cpp
index 4db6456aa..ead017564 100644
--- a/thermal/interfaces/hdi_service/src/thermal_dfx.cpp
+++ b/thermal/interfaces/hdi_service/src/thermal_dfx.cpp
@@ -97,7 +97,7 @@ static std::string GetCurrentTime(const int32_t format)
ThermalDfx::~ThermalDfx()
{
isRunning_ = false;
- if (logThread_->joinable()) {
+ if (logThread_ != nullptr && logThread_->joinable()) {
logThread_->join();
}
}
diff --git a/thermal/interfaces/hdi_service/src/thermal_hdf_timer.cpp b/thermal/interfaces/hdi_service/src/thermal_hdf_timer.cpp
index bce0b6196..3f5f6261b 100644
--- a/thermal/interfaces/hdi_service/src/thermal_hdf_timer.cpp
+++ b/thermal/interfaces/hdi_service/src/thermal_hdf_timer.cpp
@@ -24,7 +24,6 @@
#include <sys/timerfd.h>
#include <linux/netlink.h>
#include "thermal_log.h"
-#include "thermal_dfx.h"
namespace OHOS {
namespace HDI {
@@ -45,7 +44,7 @@ ThermalHdfTimer::ThermalHdfTimer(const std::shared_ptr<ThermalSimulationNode> &n
ThermalHdfTimer::~ThermalHdfTimer()
{
isRunning_ = false;
- if (callbackThread_->joinable()) {
+ if (callbackThread_ != nullptr && callbackThread_->joinable()) {
callbackThread_->join();
}
}
@@ -109,9 +108,9 @@ void ThermalHdfTimer::StartThread()
int32_t ThermalHdfTimer::Init()
{
- std::unique_ptr<ThermalDfx> thermalDfx = std::make_unique<ThermalDfx>();
- if (thermalDfx != nullptr) {
- thermalDfx->Init();
+ thermalDfx_ = std::make_unique<ThermalDfx>();
+ if (thermalDfx_ != nullptr) {
+ thermalDfx_->Init();
}
StartThread();
return HDF_SUCCESS;
1
https://gitee.com/develop-phone-open-source/drivers_peripheral.git
git@gitee.com:develop-phone-open-source/drivers_peripheral.git
develop-phone-open-source
drivers_peripheral
drivers_peripheral
OpenHarmony-4.0-Release

搜索帮助