Skip to content
Snippets Groups Projects
Commit bca56b98 authored by Guillaume Roguez's avatar Guillaume Roguez
Browse files

manager: fix Manager::createSinkClient()

Manager::createSinkClient() returns a nullptr set shared_ptr
when called with an id already associated to a sink client.
This is not the waiting behaviour: returns the existing client.

This patch fixes that and also add documentation to the public
API to explicit this behaviour.

Change-Id: Idc9a0b4f7d7a06e2bdafe965891469903f0d5d99
(cherry picked from commit a06588ed)
parent 9fab6d32
Branches
Tags
No related merge requests found
...@@ -2862,10 +2862,9 @@ Manager::createSinkClient(const std::string& id, bool mixer) ...@@ -2862,10 +2862,9 @@ Manager::createSinkClient(const std::string& id, bool mixer)
{ {
const auto& iter = sinkMap_.find(id); const auto& iter = sinkMap_.find(id);
if (iter != std::end(sinkMap_)) { if (iter != std::end(sinkMap_)) {
if (iter->second.expired()) if (auto sink = iter->second.lock())
sinkMap_.erase(iter); return sink;
else sinkMap_.erase(iter); // remove expired weak_ptr
return nullptr;
} }
auto sink = std::make_shared<video::SinkClient>(id, mixer); auto sink = std::make_shared<video::SinkClient>(id, mixer);
......
...@@ -994,8 +994,24 @@ class Manager { ...@@ -994,8 +994,24 @@ class Manager {
void scheduleTask(std::shared_ptr<Runnable> task, std::chrono::steady_clock::time_point when); void scheduleTask(std::shared_ptr<Runnable> task, std::chrono::steady_clock::time_point when);
#ifdef RING_VIDEO #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); 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); std::shared_ptr<video::SinkClient> getSinkClient(const std::string& id);
VideoManager& getVideoManager() const { return *videoManager_; } VideoManager& getVideoManager() const { return *videoManager_; }
#endif // RING_VIDEO #endif // RING_VIDEO
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment