diff --git a/source/obs-source.cpp b/source/obs-source.cpp index 5b269e14..e0aeb8d9 100644 --- a/source/obs-source.cpp +++ b/source/obs-source.cpp @@ -456,29 +456,60 @@ obs::source::source(obs_source_t* source, bool track_ownership, bool add_referen connect_signals(); } -obs::source& obs::source::operator=(const source& ref) +obs::source::source(source const& other) { - if (this != &ref) { - if (self) { - if (track_ownership) { - obs_source_release(self); - } - } - self = ref.self; - track_ownership = ref.track_ownership; - if (track_ownership) { - obs_source_addref(self); - } + this->self = other.self; + + this->track_ownership = other.track_ownership; + if (this->track_ownership) { + obs_source_addref(this->self); } +} + +obs::source& obs::source::operator=(source const& other) +{ + if (this == &other) { + return *this; + } + + // Release previous source. + if (this->self && this->track_ownership) { + obs_source_release(this->self); + } + + this->self = other.self; + this->track_ownership = other.track_ownership; + if (this->track_ownership) { + obs_source_addref(this->self); + } + return *this; } -obs::source& obs::source::operator=(source&& ref) noexcept +obs::source::source(source&& other) { - if (this != &ref) { - self = ref.self; - ref.self = nullptr; + this->self = other.self; + this->track_ownership = other.track_ownership; + other.self = nullptr; + other.track_ownership = false; +} + +obs::source& obs::source::operator=(source&& other) +{ + if (this == &other) { + return *this; } + + // Release previous source. + if (this->self && this->track_ownership) { + obs_source_release(this->self); + } + + this->self = other.self; + this->track_ownership = other.track_ownership; + other.self = nullptr; + other.track_ownership = false; + return *this; } diff --git a/source/obs-source.hpp b/source/obs-source.hpp index cd9b0183..cb1f4e02 100644 --- a/source/obs-source.hpp +++ b/source/obs-source.hpp @@ -77,10 +77,15 @@ namespace obs { source(obs_source_t* source, bool track_ownership = true, bool add_reference = false); - source& operator=(const source& ref); + public /*copy*/: + source(source const& other); + source& operator=(source const& other); - source& operator=(source&& ref) noexcept; + public /*move*/: + source(source&& other); + source& operator=(source&& other); + public: obs_source_type type(); void* type_data(); @@ -108,17 +113,17 @@ namespace obs { util::event enable; - util::event push_to_mute_changed; + util::event push_to_mute_changed; util::event push_to_mute_delay; - util::event push_to_talk_changed; + util::event push_to_talk_changed; util::event push_to_talk_delay; util::event rename; - util::event update_properties; + util::event update_properties; util::event update_flags; - util::event mute; + util::event mute; util::event volume; util::event audio_sync; util::event audio_mixers;