diff --git a/3rdpart/ZLToolKit b/3rdpart/ZLToolKit index 617b6b1d..25ba684a 160000 --- a/3rdpart/ZLToolKit +++ b/3rdpart/ZLToolKit @@ -1 +1 @@ -Subproject commit 617b6b1db23f13e2592b29204b84b1b9dbbf81c0 +Subproject commit 25ba684a49142cc59e43719c98112031e1ec4bda diff --git a/server/WebApi.cpp b/server/WebApi.cpp index 41b88dcd..cb3b69b0 100755 --- a/server/WebApi.cpp +++ b/server/WebApi.cpp @@ -344,7 +344,8 @@ Value makeMediaSourceJson(MediaSource &media){ } //getLossRate有线程安全问题;使用getMediaInfo接口才能获取丢包率;getMediaList接口将忽略丢包率 - auto current_thread = media.getOwnerPoller()->isCurrentThread(); + auto current_thread = false; + try { current_thread = media.getOwnerPoller()->isCurrentThread();} catch (...) {} float last_loss = -1; for(auto &track : media.getTracks(false)){ Value obj; diff --git a/src/Common/MediaSource.cpp b/src/Common/MediaSource.cpp index bcd16cb9..fa37c508 100644 --- a/src/Common/MediaSource.cpp +++ b/src/Common/MediaSource.cpp @@ -124,7 +124,6 @@ MediaSource::MediaSource(const string &schema, const string &vhost, const string _app = app; _stream_id = stream_id; _create_stamp = time(NULL); - _default_poller = EventPollerPool::Instance().getPoller(); } MediaSource::~MediaSource() { @@ -289,23 +288,29 @@ toolkit::EventPoller::Ptr MediaSource::getOwnerPoller() { if (listener) { return listener->getOwnerPoller(*this); } - WarnL << toolkit::demangle(typeid(*this).name()) + "::getOwnerPoller failed, now return default poller: " + getUrl(); - return _default_poller; + throw std::runtime_error(toolkit::demangle(typeid(*this).name()) + "::getOwnerPoller failed: " + getUrl()); } void MediaSource::onReaderChanged(int size) { - weak_ptr weak_self = shared_from_this(); - auto listener = _listener.lock(); - if (!listener) { - return; + try { + weak_ptr weak_self = shared_from_this(); + getOwnerPoller()->async([weak_self, size]() { + auto strong_self = weak_self.lock(); + if (!strong_self) { + return; + } + auto listener = strong_self->_listener.lock(); + if (listener) { + listener->onReaderChanged(*strong_self, size); + } + }); + } catch (MediaSourceEvent::NotImplemented &ex) { + // 未实现接口,应该打印异常 + WarnL << ex.what(); + } catch (...) { + // getOwnerPoller()接口抛异常机制应该只对外不对内 + // 所以listener已经销毁导致获取归属线程失败的异常直接忽略 } - getOwnerPoller()->async([weak_self, size, listener]() { - auto strong_self = weak_self.lock(); - if (!strong_self) { - return; - } - listener->onReaderChanged(*strong_self, size); - }); } bool MediaSource::setupRecord(Recorder::type type, bool start, const string &custom_path, size_t max_second){ diff --git a/src/Common/MediaSource.h b/src/Common/MediaSource.h index 698cefca..e80f1e03 100644 --- a/src/Common/MediaSource.h +++ b/src/Common/MediaSource.h @@ -406,7 +406,6 @@ private: std::string _app; std::string _stream_id; std::weak_ptr _listener; - toolkit::EventPoller::Ptr _default_poller; // 对象个数统计 toolkit::ObjectStatistic _statistic; };