Comments inline: ----- Original Message ----- > From: "Vivien Didelot" <[email protected]> > To: [email protected] > Cc: "Vivien Didelot" <[email protected]>, "tristan matthews" > <[email protected]> > Sent: Tuesday, February 18, 2014 9:54:32 PM > Subject: [PATCH RFC 2/2] daemon: introduce the VideoInputSelector class > > This new class is used to abstract any video input. It will handle in > a > transparent way the eventual switch between different video inputs. > > It is actually possible to switch the input with the new > switchInput() > dbus method which takes the new device string in parameter. > > Refs: #40807 > --- > .../src/client/dbus/video_controls-introspec.xml | 5 ++ > daemon/src/client/dbus/video_controls.cpp | 28 ++++--- > daemon/src/client/video_controls.h | 6 +- > daemon/src/video/Makefile.am | 1 + > daemon/src/video/video_input_selector.cpp | 90 > ++++++++++++++++++++++ > daemon/src/video/video_input_selector.h | 66 > ++++++++++++++++ > 6 files changed, 182 insertions(+), 14 deletions(-) > create mode 100644 daemon/src/video/video_input_selector.cpp > create mode 100644 daemon/src/video/video_input_selector.h > > diff --git a/daemon/src/client/dbus/video_controls-introspec.xml > b/daemon/src/client/dbus/video_controls-introspec.xml > index 7027e39..c95cb19 100644 > --- a/daemon/src/client/dbus/video_controls-introspec.xml > +++ b/daemon/src/client/dbus/video_controls-introspec.xml > @@ -110,6 +110,11 @@ > <method name="stopCamera" tp:name-for-bindings="stopCamera"> > </method> > > + <method name="switchInput" > tp:name-for-bindings="switchInput"> > + <arg type="s" name="device" direction="in"> > + </arg> > + </method> > + > <method name="hasCameraStarted" > tp:name-for-bindings="hasCameraStarted"> > <annotation name="com.trolltech.QtDBus.QtTypeName.Out0" > value="Bool"/> > <arg type="b" name="started" direction="out"> > diff --git a/daemon/src/client/dbus/video_controls.cpp > b/daemon/src/client/dbus/video_controls.cpp > index f2b65ea..d62fda6 100644 > --- a/daemon/src/client/dbus/video_controls.cpp > +++ b/daemon/src/client/dbus/video_controls.cpp > @@ -32,7 +32,7 @@ > > #include "video_controls.h" > #include "video/libav_utils.h" > -#include "video/video_input.h" > +#include "video/video_input_selector.h" > #include "account.h" > #include "logger.h" > #include "manager.h" > @@ -43,7 +43,7 @@ const char * const SERVER_PATH = > "/org/sflphone/SFLphone/VideoControls"; > > VideoControls::VideoControls(DBus::Connection& connection) : > DBus::ObjectAdaptor(connection, SERVER_PATH) > - , videoInput_() > + , videoInputSelector_() > , videoPreference_() > , inputClients_(0) > { > @@ -166,42 +166,46 @@ void > VideoControls::startCamera() > { > inputClients_++; > - if (videoInput_) { > + if (videoInputSelector_) { > WARN("Video preview was already started!"); > return; > } > > - using std::map; > - using std::string; > - > - map<string, string> args(videoPreference_.getSettings()); > - videoInput_.reset(new sfl_video::VideoInput(args)); > + const std::string& device = videoPreference_.getDevice(); > + videoInputSelector_.reset(new > sfl_video::VideoInputSelector(device)); > } > > void > VideoControls::stopCamera() > { > - if (videoInput_) { > + if (videoInputSelector_) { > DEBUG("Stopping video preview"); > inputClients_--; > if (inputClients_ <= 0) > - videoInput_.reset(); > + videoInputSelector_.reset(); > } else { > WARN("Video preview was already stopped"); > } > } > > +void > +VideoControls::switchInput(const std::string &device) > +{ > + DEBUG("Switching input device to %s", device.c_str()); > + videoInputSelector_->switchInput(device); > +} > + > std::weak_ptr<sfl_video::VideoFrameActiveWriter> > VideoControls::getVideoCamera() > { > - return videoInput_; > + return videoInputSelector_; > } > > bool > VideoControls::hasCameraStarted() > { > // see http://stackoverflow.com/a/7580064/21185 > - return static_cast<bool>(videoInput_); > + return static_cast<bool>(videoInputSelector_); > } > > std::string > diff --git a/daemon/src/client/video_controls.h > b/daemon/src/client/video_controls.h > index eb081ef..b2e9832 100644 > --- a/daemon/src/client/video_controls.h > +++ b/daemon/src/client/video_controls.h > @@ -58,15 +58,16 @@ > #include <memory> // for shared_ptr > #include "video/video_preferences.h" > #include "video/video_base.h" > +#include "video/video_input_selector.h" > > class VideoControls : public > org::sflphone::SFLphone::VideoControls_adaptor, > public DBus::IntrospectableAdaptor, > public DBus::ObjectAdaptor { > private: > - std::shared_ptr<sfl_video::VideoFrameActiveWriter> > videoInput_; > + std::shared_ptr<sfl_video::VideoInputSelector> > videoInputSelector_; > VideoPreference videoPreference_; > // Only modified from main thread > - int inputClients_; > + int inputClients_; // XXX necessary with the > videoInputSelector_?
Yeah the inputClients_ thing is a hack that should be eliminated. Basically, we were getting into trouble because the camera object was being destroyed while still being used. Hopefully this can be addressed by the inputselector (see start/stopCamera methods) to check. Will merge, thanks. Best, Tristan -- Tristan Matthews Développeur de logiciels libres [email protected] Ligne directe: 514-276-5468 poste 190 Fax : 514-276-5465 7275 Saint Urbain Bureau 200 Montréal, QC, H2R 2Y5 _______________________________________________ SFLphone mailing list [email protected] http://lists.savoirfairelinux.net/mailman/listinfo/sflphone
