diff --git a/configure.ac b/configure.ac index e293a0135c6188a4613130c2854f606623bcf09e..7a6ef62299c7b917452c8cf328c455c16f33a8e1 100644 --- a/configure.ac +++ b/configure.ac @@ -569,7 +569,7 @@ AS_IF([test "x$with_upnp" = "xyes"], AC_DEFINE([HAVE_LIBUPNP], 0, [Define if you have libupnp])]) ]) -AC_DEFINE_UNQUOTED([HAVE_SHM], `if test -z "${HAVE_LINUX_TRUE}"; then echo 1; else echo 0; fi`, +AC_DEFINE_UNQUOTED([HAVE_SHM], `if test -z "${HAVE_LINUX_TRUE}" && test -z "${HAVE_ANDROID_FALSE}" ; then echo 1; else echo 0; fi`, [Define if you have shared memory support]) # DOXYGEN @@ -623,6 +623,7 @@ AC_CONFIG_FILES([Makefile \ src/hooks/Makefile \ src/media/video/Makefile \ src/media/video/v4l2/Makefile \ + src/media/video/androidvideo/Makefile \ src/media/video/osxvideo/Makefile \ src/media/video/winvideo/Makefile \ src/media/video/test/Makefile \ diff --git a/src/Makefile.am b/src/Makefile.am index 9270739d67bda356f576d0dfd14c18b20878794e..2f88fbda4614fdcfc7cf580202b9c75d95fcaccc 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -5,9 +5,14 @@ RING_VIDEO_LIBS= if RING_VIDEO RING_VIDEO_LIBS+=./media/video/libvideo.la if HAVE_LINUX +if HAVE_ANDROID +RING_VIDEO_LIBS+= \ + ./media/video/androidvideo/libandroidvideo.la +else RING_VIDEO_LIBS+= \ ./media/video/v4l2/libv4l2.la endif +endif if HAVE_OSX RING_VIDEO_LIBS+= \ ./media/video/osxvideo/libosxvideo.la diff --git a/src/media/video/Makefile.am b/src/media/video/Makefile.am index b1b832366720ec30e462c5687cfa9f50b76e89e8..7e94139048a6000b017d4657c4a112239b2d8de8 100644 --- a/src/media/video/Makefile.am +++ b/src/media/video/Makefile.am @@ -3,8 +3,13 @@ include $(top_srcdir)/globals.mak SUBDIRS= test if HAVE_LINUX +if HAVE_ANDROID SUBDIRS+= \ - v4l2 + androidvideo +else +SUBDIRS+= \ + v4l2 +endif endif if HAVE_OSX diff --git a/src/media/video/androidvideo/Makefile.am b/src/media/video/androidvideo/Makefile.am new file mode 100644 index 0000000000000000000000000000000000000000..0393a07d604870a04c89a2fb52354f3df6e53f2d --- /dev/null +++ b/src/media/video/androidvideo/Makefile.am @@ -0,0 +1,10 @@ +include $(top_srcdir)/globals.mak + +noinst_LTLIBRARIES = libandroidvideo.la + +libandroidvideo_la_SOURCES = \ + video_device_impl.cpp \ + video_device_monitor_impl.cpp + +#AM_CXXFLAGS = @UDEV_CFLAGS@ +#libandroidvideo_la_LIBADD = @UDEV_LIBS@ diff --git a/src/media/video/androidvideo/video_device_impl.cpp b/src/media/video/androidvideo/video_device_impl.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1cb7351c028cf01448f773de43e0a95c473c27de --- /dev/null +++ b/src/media/video/androidvideo/video_device_impl.cpp @@ -0,0 +1,147 @@ +/* + * Copyright (C) 2011-2015 Savoir-Faire Linux Inc. + * Author: Rafaël Carré <rafael.carre@savoirfairelinux.com> + * Author: Vivien Didelot <vivien.didelot@savoirfairelinux.com> + * + * 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 "logger.h" +#include "../video_device.h" + +#include <algorithm> +#include <map> +#include <sstream> +#include <stdexcept> +#include <string> +#include <vector> + +namespace ring { namespace video { + +class VideoDeviceImpl { + public: + /** + * @throw std::runtime_error + */ + VideoDeviceImpl(const std::string& path); + + std::string device; + std::string name; + + std::vector<std::string> getChannelList() const; + std::vector<std::string> getSizeList(const std::string& channel) const; + std::vector<std::string> getRateList(const std::string& channel, const std::string& size) const; + + VideoSettings getSettings() const; + void applySettings(VideoSettings settings); + + DeviceParams getDeviceParams() const; +}; + +VideoDeviceImpl::VideoDeviceImpl(const std::string& path) : + device(path), name() +{ + // Set default settings + applySettings(VideoSettings()); +} + +std::vector<std::string> VideoDeviceImpl::getChannelList() const +{ +} + +std::vector<std::string> +VideoDeviceImpl::getSizeList(const std::string& channel) const +{ +} + +std::vector<std::string> +VideoDeviceImpl::getRateList(const std::string& channel, const std::string& size) const +{ +} + +void +VideoDeviceImpl::applySettings(VideoSettings settings) +{ +} + +VideoSettings +VideoDeviceImpl::getSettings() const +{ + VideoSettings settings; + settings.name = name; + return settings; +} + +DeviceParams +VideoDeviceImpl::getDeviceParams() const +{ + DeviceParams params; + params.input = device; + params.format = "android"; + return params; +} + +VideoDevice::VideoDevice(const std::string& path) : + deviceImpl_(new VideoDeviceImpl(path)) +{ + //node_ = path; + name = deviceImpl_->name; +} + +void +VideoDevice::applySettings(VideoSettings settings) +{ + deviceImpl_->applySettings(settings); +} + +VideoSettings +VideoDevice::getSettings() const +{ + return deviceImpl_->getSettings(); +} + +DeviceParams +VideoDevice::getDeviceParams() const +{ + return deviceImpl_->getDeviceParams(); +} + +DRing::VideoCapabilities +VideoDevice::getCapabilities() const +{ + DRing::VideoCapabilities cap; + + for (const auto& chan : deviceImpl_->getChannelList()) + for (const auto& size : deviceImpl_->getSizeList(chan)) + cap[chan][size] = deviceImpl_->getRateList(chan, size); + + return cap; +} + +VideoDevice::~VideoDevice() +{} + +}} // namespace ring::video diff --git a/src/media/video/androidvideo/video_device_monitor_impl.cpp b/src/media/video/androidvideo/video_device_monitor_impl.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9f5c5c454d24536a1de287bae6b85624e82db60f --- /dev/null +++ b/src/media/video/androidvideo/video_device_monitor_impl.cpp @@ -0,0 +1,121 @@ +/* + * Copyright (C) 2009 Rémi Denis-Courmont + * + * Copyright (C) 2004-2015 Savoir-Faire Linux Inc. + * Author: Rafaël Carré <rafael.carre@savoirfairelinux.com> + * Author: Vivien Didelot <vivien.didelot@savoirfairelinux.com> + * + * 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_device_monitor.h" +#include "logger.h" +#include "noncopyable.h" + +#include <algorithm> +#include <mutex> +#include <sstream> +#include <stdexcept> // for std::runtime_error +#include <string> +#include <thread> +#include <vector> + +namespace ring { namespace video { + +using std::vector; +using std::string; + +class VideoDeviceMonitorImpl { + public: + /* + * This is the only restriction to the pImpl design: + * as the Linux implementation has a thread, it needs a way to notify + * devices addition and deletion. + * + * This class should maybe inherit from VideoDeviceMonitor instead of + * being its pImpl. + */ + VideoDeviceMonitorImpl(VideoDeviceMonitor* monitor); + ~VideoDeviceMonitorImpl(); + + void start(); + + private: + NON_COPYABLE(VideoDeviceMonitorImpl); + + VideoDeviceMonitor* monitor_; + + void run(); + std::thread thread_; + mutable std::mutex mutex_; +/* + udev *udev_; + udev_monitor *udev_mon_;*/ + bool probing_; +}; + +VideoDeviceMonitorImpl::VideoDeviceMonitorImpl(VideoDeviceMonitor* monitor) : + monitor_(monitor), + thread_(), mutex_(), + probing_(false) +{} + +void VideoDeviceMonitorImpl::start() +{ + probing_ = true; + thread_ = std::thread(&VideoDeviceMonitorImpl::run, this); +} + +VideoDeviceMonitorImpl::~VideoDeviceMonitorImpl() +{ + probing_ = false; + if (thread_.joinable()) + thread_.join(); +} + +void VideoDeviceMonitorImpl::run() +{ + /*if (!udev_mon_) { + probing_ = false; + return; + } + + const int udev_fd = udev_monitor_get_fd(udev_mon_);*/ + while (probing_) { + } +} + +VideoDeviceMonitor::VideoDeviceMonitor() : + preferences_(), devices_(), + monitorImpl_(new VideoDeviceMonitorImpl(this)) +{ + monitorImpl_->start(); +} + +VideoDeviceMonitor::~VideoDeviceMonitor() +{} + +}} // namespace ring::video