diff --git a/src/manager.cpp b/src/manager.cpp index 9bb9014014a0193f4e8c5465c2ba72baeeea5bcc..d1124f942eab566e4898f35210636279dab69f4a 100644 --- a/src/manager.cpp +++ b/src/manager.cpp @@ -2862,10 +2862,9 @@ Manager::createSinkClient(const std::string& id, bool mixer) { const auto& iter = sinkMap_.find(id); if (iter != std::end(sinkMap_)) { - if (iter->second.expired()) - sinkMap_.erase(iter); - else - return nullptr; + if (auto sink = iter->second.lock()) + return sink; + sinkMap_.erase(iter); // remove expired weak_ptr } auto sink = std::make_shared<video::SinkClient>(id, mixer); diff --git a/src/manager.h b/src/manager.h index 34c4ebb9964ef0cf02b158e7c65c00cfdb529c3d..54c17a736ce79a136d7b9c09827edf8f3967433b 100644 --- a/src/manager.h +++ b/src/manager.h @@ -994,8 +994,24 @@ class Manager { void scheduleTask(std::shared_ptr<Runnable> task, std::chrono::steady_clock::time_point when); #ifdef RING_VIDEO + /** + * Create a new SinkClient instance, store it in an internal cache as a weak_ptr + * and return it as a shared_ptr. If a SinkClient is already stored for the given id, + * this method returns this instance. + * @param id SinkClient identifier as a string. Default is empty. + * @param mixer true if the SinkCient is the sink of a VideoMixer node. Default is false. + * @return share_ptr<SinkClient> A shared pointer on the created instance. + */ std::shared_ptr<video::SinkClient> createSinkClient(const std::string& id="", bool mixer=false); + + /** + * Return an existing SinkClient instance as a shared_ptr associated to the given identifier. + * Return an empty shared_ptr (nullptr) if nothing found. + * @param id SinkClient identifier as a string. + * @return share_ptr<SinkClient> A shared pointer on the found instance. Empty if not found. + */ std::shared_ptr<video::SinkClient> getSinkClient(const std::string& id); + VideoManager& getVideoManager() const { return *videoManager_; } #endif // RING_VIDEO