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_?
public:
@@ -127,6 +128,7 @@ class VideoControls : public
org::sflphone::SFLphone::VideoControls_adaptor,
void startCamera();
void stopCamera();
+ void switchInput(const std::string& device);
bool hasCameraStarted();
std::weak_ptr<sfl_video::VideoFrameActiveWriter> getVideoCamera();
};
diff --git a/daemon/src/video/Makefile.am b/daemon/src/video/Makefile.am
index 225be03..1d8a871 100644
--- a/daemon/src/video/Makefile.am
+++ b/daemon/src/video/Makefile.am
@@ -15,6 +15,7 @@ libvideo_la_SOURCES = \
socket_pair.cpp socket_pair.h \
shm_sink.cpp shm_sink.h \
video_input.cpp video_input.h \
+ video_input_selector.cpp video_input_selector.h \
video_receive_thread.cpp video_receive_thread.h \
video_sender.cpp video_sender.h \
video_rtp_session.cpp video_rtp_session.h \
diff --git a/daemon/src/video/video_input_selector.cpp
b/daemon/src/video/video_input_selector.cpp
new file mode 100644
index 0000000..2749045
--- /dev/null
+++ b/daemon/src/video/video_input_selector.cpp
@@ -0,0 +1,90 @@
+/*
+ * Copyright (C) 2004-2014 Savoir-Faire Linux Inc.
+ * Author: Vivien Didelot <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
USA.
+ *
+ * Additional permission under GNU GPL version 3 section 7:
+ *
+ * If you modify this program, or any covered work, by linking or
+ * combining it with the OpenSSL project's OpenSSL library (or a
+ * modified version of that library), containing parts covered by the
+ * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
+ * grants you additional permission to convey the resulting work.
+ * Corresponding Source for a non-source form of such a combination
+ * shall include the source code for the parts of OpenSSL used as well
+ * as that of the covered work.
+ */
+
+#include "video_input_selector.h"
+#include "video_input.h"
+#include "check.h"
+
+#include "manager.h"
+#include "client/video_controls.h"
+
+#include <map>
+#include <string>
+
+namespace sfl_video {
+
+VideoInputSelector::VideoInputSelector(const std::string& device) :
+ VideoFramePassiveReader::VideoFramePassiveReader()
+ , VideoFrameActiveWriter::VideoFrameActiveWriter()
+ , currentInput_()
+{
+ openInput(device);
+}
+
+VideoInputSelector::~VideoInputSelector()
+{
+ closeInput();
+}
+
+void
+VideoInputSelector::update(Observable<std::shared_ptr<sfl_video::VideoFrame>>*
/* input */, std::shared_ptr<VideoFrame>& frame_ptr)
+{
+ notify(frame_ptr);
+}
+
+static const std::map<std::string, std::string>
+getSettings(const std::string& device)
+{
+ return Manager::instance().getVideoControls()->getSettingsFor(device);
+}
+
+void
+VideoInputSelector::openInput(const std::string& device)
+{
+ currentInput_ = new VideoInput(getSettings(device));
+ currentInput_->attach(this);
+}
+
+void
+VideoInputSelector::closeInput(void)
+{
+ currentInput_->detach(this);
+ delete currentInput_;
+}
+
+void
+VideoInputSelector::switchInput(const std::string& device)
+{
+ DEBUG("Switching input to %s", device.c_str());
+ closeInput();
+ openInput(device);
+}
+
+} // end namespace sfl_video
diff --git a/daemon/src/video/video_input_selector.h
b/daemon/src/video/video_input_selector.h
new file mode 100644
index 0000000..8756351
--- /dev/null
+++ b/daemon/src/video/video_input_selector.h
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2011-2014 Savoir-Faire Linux Inc.
+ * Author: Vivien Didelot <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
USA.
+ *
+ * Additional permission under GNU GPL version 3 section 7:
+ *
+ * If you modify this program, or any covered work, by linking or
+ * combining it with the OpenSSL project's OpenSSL library (or a
+ * modified version of that library), containing parts covered by the
+ * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
+ * grants you additional permission to convey the resulting work.
+ * Corresponding Source for a non-source form of such a combination
+ * shall include the source code for the parts of OpenSSL used as well
+ * as that of the covered work.
+ */
+
+#ifndef __VIDEO_INPUT_SELECTOR_H__
+#define __VIDEO_INPUT_SELECTOR_H__
+
+#include "noncopyable.h"
+#include "video_input.h"
+
+#include <string>
+#include <map>
+
+namespace sfl_video {
+
+class VideoInputSelector :
+ public VideoFramePassiveReader,
+ public VideoFrameActiveWriter
+{
+public:
+ VideoInputSelector(const std::string& device);
+ ~VideoInputSelector();
+
+ /* as of VideoFrameActiveReader (Observer) */
+ void update(Observable<std::shared_ptr<sfl_video::VideoFrame>>*,
std::shared_ptr<VideoFrame>&);
+
+ void switchInput(const std::string& device);
+
+private:
+ NON_COPYABLE(VideoInputSelector);
+
+ void openInput(const std::string& device);
+ void closeInput(void);
+
+ VideoInput *currentInput_;
+};
+
+}
+
+#endif // __VIDEO_INPUT_SELECTOR_H__
--
1.8.5.4
_______________________________________________
SFLphone mailing list
[email protected]
http://lists.savoirfairelinux.net/mailman/listinfo/sflphone