修复FrameDispatcher可能导致死锁的问题

This commit is contained in:
ziyue 2023-02-06 14:18:21 +08:00
parent 6eb36ec883
commit f6cba98a8e
2 changed files with 9 additions and 9 deletions

@ -1 +1 @@
Subproject commit 7af363c4015a63fa48079af2cb08da2ceb1f69e6 Subproject commit c7e301ec82fa6feb117e824ff522acd8a740cc9e

View File

@ -292,7 +292,7 @@ public:
* *
*/ */
FrameWriterInterface* addDelegate(FrameWriterInterface::Ptr delegate) { FrameWriterInterface* addDelegate(FrameWriterInterface::Ptr delegate) {
std::lock_guard<std::mutex> lck(_mtx); std::lock_guard<std::recursive_mutex> lck(_mtx);
return _delegates.emplace(delegate.get(), std::move(delegate)).first->second.get(); return _delegates.emplace(delegate.get(), std::move(delegate)).first->second.get();
} }
@ -302,7 +302,7 @@ public:
* *
*/ */
void delDelegate(FrameWriterInterface *ptr) { void delDelegate(FrameWriterInterface *ptr) {
std::lock_guard<std::mutex> lck(_mtx); std::lock_guard<std::recursive_mutex> lck(_mtx);
_delegates.erase(ptr); _delegates.erase(ptr);
} }
@ -310,7 +310,7 @@ public:
* *
*/ */
bool inputFrame(const Frame::Ptr &frame) override { bool inputFrame(const Frame::Ptr &frame) override {
std::lock_guard<std::mutex> lck(_mtx); std::lock_guard<std::recursive_mutex> lck(_mtx);
++_frames; ++_frames;
if (frame->keyFrame() && frame->getTrackType() == TrackVideo) { if (frame->keyFrame() && frame->getTrackType() == TrackVideo) {
++_video_key_frames; ++_video_key_frames;
@ -328,12 +328,12 @@ public:
* *
*/ */
size_t size() const { size_t size() const {
std::lock_guard<std::mutex> lck(_mtx); std::lock_guard<std::recursive_mutex> lck(_mtx);
return _delegates.size(); return _delegates.size();
} }
void clear() { void clear() {
std::lock_guard<std::mutex> lck(_mtx); std::lock_guard<std::recursive_mutex> lck(_mtx);
_delegates.clear(); _delegates.clear();
} }
@ -341,7 +341,7 @@ public:
* *
*/ */
uint64_t getVideoKeyFrames() const { uint64_t getVideoKeyFrames() const {
std::lock_guard<std::mutex> lck(_mtx); std::lock_guard<std::recursive_mutex> lck(_mtx);
return _video_key_frames; return _video_key_frames;
} }
@ -349,14 +349,14 @@ public:
* *
*/ */
uint64_t getFrames() const { uint64_t getFrames() const {
std::lock_guard<std::mutex> lck(_mtx); std::lock_guard<std::recursive_mutex> lck(_mtx);
return _frames; return _frames;
} }
private: private:
uint64_t _frames = 0; uint64_t _frames = 0;
uint64_t _video_key_frames = 0; uint64_t _video_key_frames = 0;
mutable std::mutex _mtx; mutable std::recursive_mutex _mtx;
std::map<void *, FrameWriterInterface::Ptr> _delegates; std::map<void *, FrameWriterInterface::Ptr> _delegates;
}; };