diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 955b0a5944045b677ed10c53506a087e7065a4ab..e86fbe7a87b396e59c5de1ecc86eecf8cef5d241 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -76,6 +76,9 @@ set( qtsflphone_LIB_SRCS itembackendmodel.cpp video/videodevicemodel.cpp video/videocodecmodel.cpp + video/videochannel.cpp + video/videoresolution.cpp + video/videorate.cpp video/videomodel.cpp #Data backends @@ -140,6 +143,9 @@ set( qtsflphone_LIB_HDRS video/videocodecmodel.h video/videomodel.h video/videorenderer.h + video/videoresolution.h + video/videochannel.h + video/videorate.h #commonbackendmanagerinterface.h ) diff --git a/src/video/videochannel.cpp b/src/video/videochannel.cpp new file mode 100644 index 0000000000000000000000000000000000000000..712adb50e65367ef3b9d32b67bd3ca7a3e7badce --- /dev/null +++ b/src/video/videochannel.cpp @@ -0,0 +1,95 @@ +/**************************************************************************** + * Copyright (C) 2014 by Savoir-Faire Linux * + * Author : Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com> * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * This library 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 * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ +#include "videochannel.h" + +//SFLphone +#include "videoresolution.h" +#include "videodevice.h" +#include "dbus/videomanager.h" + +VideoChannel::VideoChannel(VideoDevice* dev,const QString& name) : + m_Name(name),m_pCurrentResolution(nullptr),m_pDevice(dev) +{ +} + +VideoChannel* VideoDevice::activeChannel() const +{ + if (!m_pCurrentChannel) { + VideoManagerInterface& interface = DBus::VideoManager::instance(); + const QString chan = QMap<QString,QString>(interface.getPreferences(m_DeviceId))[VideoDevice::PreferenceNames::CHANNEL]; + foreach(VideoChannel* c, m_lChannels) { + if (c->name() == chan) { + const_cast<VideoDevice*>(this)->m_pCurrentChannel = c; + break; + } + } + } + if (!m_pCurrentChannel && m_lChannels.size()) { + const_cast<VideoDevice*>(this)->m_pCurrentChannel = m_lChannels[0]; + } + return m_pCurrentChannel; +} + +QVariant VideoChannel::data( const QModelIndex& index, int role) const +{ + if (index.isValid() && role == Qt::DisplayRole) { + return m_lValidResolutions[index.row()]->name(); + } + return QVariant(); +} + +int VideoChannel::rowCount( const QModelIndex& parent) const +{ + return (parent.isValid())?0:m_lValidResolutions.size(); +} + +Qt::ItemFlags VideoChannel::flags( const QModelIndex& idx) const +{ + if (idx.column() == 0) + return QAbstractItemModel::flags(idx) | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable; + return QAbstractItemModel::flags(idx); +} + +bool VideoChannel::setData( const QModelIndex& index, const QVariant &value, int role) +{ + Q_UNUSED(index) + Q_UNUSED(value) + Q_UNUSED(role) + return false; +} + +int VideoChannel::relativeIndex() { + return m_pDevice->channelList().indexOf(this); +} + +bool VideoChannel::setActiveResolution(int idx) +{ + if (idx < 0 || idx >= m_lValidResolutions.size()) return false; + return setActiveResolution(m_lValidResolutions[idx]); +} + +bool VideoChannel::setActiveResolution(VideoResolution* res) { + if ((!res) || m_lValidResolutions.indexOf(res) == -1 || res->name().isEmpty()) { + qWarning() << "Invalid active resolution" << (res?res->name():"NULL"); + return false; + } + m_pCurrentResolution = res; + m_pDevice->save(); + return true; +} + diff --git a/src/video/videochannel.h b/src/video/videochannel.h new file mode 100644 index 0000000000000000000000000000000000000000..a77474c5713ef6462bcc049d5e2bf3b702b8f412 --- /dev/null +++ b/src/video/videochannel.h @@ -0,0 +1,63 @@ +/**************************************************************************** + * Copyright (C) 2014 by Savoir-Faire Linux * + * Author : Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com> * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * This library 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 * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ +#ifndef VIDEOCHANNEL_H +#define VIDEOCHANNEL_H + +#include "../typedefs.h" +#include <QtCore/QAbstractListModel> + +class VideoResolution; +class VideoDevice; + +///@typedef VideoChannel A channel available in a Device +class LIB_EXPORT VideoChannel : public QAbstractListModel +{ + //Only VideoDevice can add resolutions + friend class VideoDevice; +public: + QString name() const { + return m_Name; + } + VideoResolution* activeResolution(); + QList<VideoResolution*> validResolutions() const { + return m_lValidResolutions; + } + VideoDevice* device() const { + return m_pDevice; + } + int relativeIndex(); + + bool setActiveResolution(VideoResolution* res); + bool setActiveResolution(int idx); + + //Model + QVariant data ( const QModelIndex& index, int role = Qt::DisplayRole ) const; + int rowCount ( const QModelIndex& parent = QModelIndex() ) const; + Qt::ItemFlags flags ( const QModelIndex& index ) const; + virtual bool setData ( const QModelIndex& index, const QVariant &value, int role) ; + +private: + VideoChannel(VideoDevice* dev,const QString& name); + virtual ~VideoChannel() {} + QString m_Name; + QList<VideoResolution*> m_lValidResolutions; + VideoResolution* m_pCurrentResolution; + VideoDevice* m_pDevice; +}; + +#endif diff --git a/src/video/videochannelmodel.cpp b/src/video/videochannelmodel.cpp deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/src/video/videochannelmodel.h b/src/video/videochannelmodel.h deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/src/video/videodevice.cpp b/src/video/videodevice.cpp index c3bd25567717117a78cb8ab29dbd0d8abc07e8c2..4ca53e301abe0525ae8f30d3e124292b22ff5c6f 100644 --- a/src/video/videodevice.cpp +++ b/src/video/videodevice.cpp @@ -18,49 +18,17 @@ #include "videodevice.h" #include "dbus/videomanager.h" #include "videodevicemodel.h" - -Resolution::Resolution(uint _width, uint _height):QSize(_width,_height), -m_pCurrentRate(nullptr),m_pChannel(nullptr) -{ -} - -Resolution::Resolution() : QSize(),m_pCurrentRate(nullptr),m_pChannel(nullptr) -{ -} - -Resolution::Resolution(const QString& size, VideoChannel* chan) -: m_pCurrentRate(nullptr),m_pChannel(chan) -{ - if (size.split('x').size() == 2) { - setWidth(size.split('x')[0].toInt()); - setHeight(size.split('x')[1].toInt()); - } -} - -Resolution::Resolution(const Resolution& res):QSize(res.width(),res.height()), -m_pCurrentRate(nullptr),m_pChannel(nullptr) -{ -} - -Resolution::Resolution(const QSize& size):QSize(size), -m_pCurrentRate(nullptr),m_pChannel(nullptr) -{ -} - -const QString Resolution::name() const -{ - return QString::number(width())+'x'+QString::number(height()); -} - +#include "videoresolution.h" +#include "videorate.h" +#include "videochannel.h" ///Constructor -VideoDevice::VideoDevice(const QString &id) : QObject(nullptr), m_DeviceId(id), +VideoDevice::VideoDevice(const QString &id) : QAbstractListModel(nullptr), m_DeviceId(id), m_pCurrentChannel(nullptr) { VideoManagerInterface& interface = DBus::VideoManager::instance(); MapStringMapStringVectorString cap = interface.getCapabilities(id); QMapIterator<QString, MapStringVectorString> channels(cap); - qDebug() << "\n\n\n\nCAP" << id << cap.size(); while (channels.hasNext()) { channels.next(); @@ -71,7 +39,7 @@ m_pCurrentChannel(nullptr) while (resolutions.hasNext()) { resolutions.next(); - Resolution* res = new Resolution(resolutions.key(),chan); + VideoResolution* res = new VideoResolution(resolutions.key(),chan); chan->m_lValidResolutions << res; foreach(const QString& rate, resolutions.value()) { @@ -88,6 +56,38 @@ VideoDevice::~VideoDevice() { } +QVariant VideoDevice::data( const QModelIndex& index, int role) const +{ + if (index.isValid() && role == Qt::DisplayRole) { + return m_lChannels[index.row()]->name(); + } + return QVariant(); +} + +int VideoDevice::rowCount( const QModelIndex& parent) const +{ + return (parent.isValid())?0:m_lChannels.size(); +} + +Qt::ItemFlags VideoDevice::flags( const QModelIndex& idx) const +{ + if (idx.column() == 0) + return QAbstractItemModel::flags(idx) | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable; + return QAbstractItemModel::flags(idx); +} + +bool VideoDevice::setData( const QModelIndex& index, const QVariant &value, int role) +{ + Q_UNUSED(index) + Q_UNUSED(value) + Q_UNUSED(role) + return false; +} + +// int VideoDevice::relativeIndex() { +// return m_pDevice->channelList().indexOf(this); +// } + ///Get the valid channel list QList<VideoChannel*> VideoDevice::channelList() const { @@ -125,13 +125,13 @@ bool VideoDevice::isActive() const return VideoDeviceModel::instance()->activeDevice() == this; } -Resolution* VideoChannel::activeResolution() +VideoResolution* VideoChannel::activeResolution() { //If it is the current device, then there is "current" resolution if ((!m_pCurrentResolution) && m_pDevice->isActive()) { VideoManagerInterface& interface = DBus::VideoManager::instance(); const QString res = QMap<QString,QString>(interface.getPreferences(m_pDevice->id()))[VideoDevice::PreferenceNames::SIZE]; - foreach(Resolution* r, validResolutions()) { + foreach(VideoResolution* r, validResolutions()) { if (r->name() == res) { m_pCurrentResolution = r; break; @@ -146,52 +146,6 @@ Resolution* VideoChannel::activeResolution() return m_pCurrentResolution; } -bool VideoChannel::setActiveResolution(Resolution* res) { - if ((!res) || m_lValidResolutions.indexOf(res) == -1 || res->name().isEmpty()) { - qWarning() << "Invalid active resolution" << (res?res->name():"NULL"); - return false; - } - m_pCurrentResolution = res; - m_pDevice->save(); - return true; -} - -VideoRate* Resolution::activeRate() -{ - if (!m_pChannel) { - qWarning() << "Trying to get the active rate of an unattached resolution"; - return nullptr; - } - if (!m_pCurrentRate && m_pChannel && m_pChannel->device()->isActive()) { - VideoManagerInterface& interface = DBus::VideoManager::instance(); - const QString rate = QMap<QString,QString>( - interface.getPreferences(m_pChannel->device()->id()))[VideoDevice::PreferenceNames::RATE]; - foreach(VideoRate* r, m_lValidRates) { - if (r->name() == rate) { - m_pCurrentRate = r; - break; - } - } - } - if ((!m_pCurrentRate) && m_lValidRates.size()) - m_pCurrentRate = m_lValidRates[0]; - - return m_pCurrentRate; -} - -int Resolution::index() const -{ - return m_pChannel?m_pChannel->validResolutions().indexOf(const_cast<Resolution*>(this)):-1; -} - -int VideoChannel::index() { - return m_pDevice->channelList().indexOf(this); -} - -int VideoRate::index() { - return m_pResolution->validRates().indexOf(this); -} - bool VideoDevice::setActiveChannel(VideoChannel* chan) { if (!chan || !m_lChannels.indexOf(chan)) { @@ -203,30 +157,8 @@ bool VideoDevice::setActiveChannel(VideoChannel* chan) return true; } -VideoChannel::VideoChannel(VideoDevice* dev,const QString& name) : - m_Name(name),m_pCurrentResolution(nullptr),m_pDevice(dev) +bool VideoDevice::setActiveChannel(int idx) { - m_pCurrentResolution = nullptr; - m_pCurrentResolution = nullptr; - m_pCurrentResolution = nullptr; - m_pCurrentResolution = nullptr; - m_pCurrentResolution = nullptr; + if (idx < 0 || idx >= m_lChannels.size()) return false; + return setActiveChannel(m_lChannels[idx]); } - -VideoChannel* VideoDevice::activeChannel() const -{ - if (!m_pCurrentChannel) { - VideoManagerInterface& interface = DBus::VideoManager::instance(); - const QString chan = QMap<QString,QString>(interface.getPreferences(m_DeviceId))[VideoDevice::PreferenceNames::CHANNEL]; - foreach(VideoChannel* c, m_lChannels) { - if (c->name() == chan) { - const_cast<VideoDevice*>(this)->m_pCurrentChannel = c; - break; - } - } - } - if (!m_pCurrentChannel && m_lChannels.size()) { - const_cast<VideoDevice*>(this)->m_pCurrentChannel = m_lChannels[0]; - } - return m_pCurrentChannel; -} \ No newline at end of file diff --git a/src/video/videodevice.h b/src/video/videodevice.h index 9ea86c236cff72e624e00da7f8b5996eb030972b..c2d0664da50ba32b77e0c67d8bf1236c3e161865 100644 --- a/src/video/videodevice.h +++ b/src/video/videodevice.h @@ -19,6 +19,7 @@ #define VIDEO_DEVICE_H #include "../typedefs.h" +#include <QtCore/QAbstractListModel> //Qt #include <QStringList> @@ -26,96 +27,15 @@ //SFLPhone class VideoRenderer; -class Resolution; +class VideoResolution; class VideoRate; class VideoChannel; class VideoDevice; -///@typedef VideoChannel A channel available in a Device -class LIB_EXPORT VideoChannel -{ - //Only VideoDevice can add resolutions - friend class VideoDevice; -public: - QString name() const { - return m_Name; - } - Resolution* activeResolution(); - QList<Resolution*> validResolutions() const { - return m_lValidResolutions; - } - VideoDevice* device() const { - return m_pDevice; - } - int index(); - - bool setActiveResolution(Resolution* res); - -private: - VideoChannel(VideoDevice* dev,const QString& name); - virtual ~VideoChannel() {} - QString m_Name; - QList<Resolution*> m_lValidResolutions; - Resolution* m_pCurrentResolution; - VideoDevice* m_pDevice; -}; - -///@typedef VideoRate The rate for a device -class LIB_EXPORT VideoRate -{ - //Can only be created by VideoDevice - friend class VideoDevice; - -public: - virtual ~VideoRate() {} - QString name() const { - return m_Name; - } - int index(); -private: - VideoRate(const Resolution* res,const QString& name) : - m_Name(name),m_pResolution(res) {} - QString m_Name; - const Resolution* m_pResolution; -}; - -///@struct Resolution Equivalent of "640x480" -class LIB_EXPORT Resolution : public QSize { - //Only VideoDevice can add validated rates - friend class VideoDevice; -public: - //Constructor - Resolution(uint _width, uint _height); - Resolution(const QString& size = QString(), VideoChannel* chan = nullptr); - Resolution(const Resolution& res); - Resolution(const QSize& size); - explicit Resolution(); - //Getter - const QString name() const; - const QList<VideoRate*> validRates() const { - return m_lValidRates; - } - int index() const; - VideoRate* activeRate(); - bool setActiveRate(VideoRate* rate) { - if (!rate || (m_lValidRates.indexOf(rate) != -1)) { - qWarning() << "Trying to set an invalid rate"; - return false; - } - return true; - } -private: - - //Attributes - QList<VideoRate*> m_lValidRates; - VideoRate* m_pCurrentRate; - VideoChannel* m_pChannel; -}; - class VideoModel; ///VideoDevice: V4L devices used to record video for video call -class LIB_EXPORT VideoDevice : public QObject { +class LIB_EXPORT VideoDevice : public QAbstractListModel { Q_OBJECT friend class VideoModel; friend class VideoDeviceModel; @@ -124,9 +44,24 @@ class LIB_EXPORT VideoDevice : public QObject { friend class VideoChannel; friend class Resolution; public: + + class PreferenceNames { + public: + constexpr static const char* RATE = "rate" ; + constexpr static const char* NAME = "name" ; + constexpr static const char* CHANNEL = "channel"; + constexpr static const char* SIZE = "size" ; + }; + //Constants constexpr static const char* NONE = ""; + //Model + QVariant data ( const QModelIndex& index, int role = Qt::DisplayRole ) const; + int rowCount ( const QModelIndex& parent = QModelIndex() ) const; + Qt::ItemFlags flags ( const QModelIndex& index ) const; + virtual bool setData ( const QModelIndex& index, const QVariant &value, int role) ; + //Getter QList<VideoChannel*> channelList () const; VideoChannel* activeChannel () const; @@ -138,6 +73,10 @@ class LIB_EXPORT VideoDevice : public QObject { //Setter bool setActiveChannel(VideoChannel* chan); + bool setActiveChannel(int idx); + + //Mutator + void save(); private: //Constructor @@ -149,16 +88,6 @@ class LIB_EXPORT VideoDevice : public QObject { VideoChannel* m_pCurrentChannel ; QList<VideoChannel*> m_lChannels ; - //Helper - void save(); - - class PreferenceNames { - public: - constexpr static const char* RATE = "rate" ; - constexpr static const char* NAME = "name" ; - constexpr static const char* CHANNEL = "channel"; - constexpr static const char* SIZE = "size" ; - }; Q_SIGNALS: void renderingStarted(VideoRenderer*); diff --git a/src/video/videodevicemodel.cpp b/src/video/videodevicemodel.cpp index 6045abdcf4d453aaf4ae006d7602ce0b7eb96590..b6fdb4227da99963fd4b3c9190bdd0bcfe0c7875 100644 --- a/src/video/videodevicemodel.cpp +++ b/src/video/videodevicemodel.cpp @@ -67,17 +67,10 @@ bool VideoDeviceModel::setData(const QModelIndex& idx, const QVariant &value, in ///Constructor VideoDeviceModel::VideoDeviceModel() : QAbstractListModel(QCoreApplication::instance()), -m_pResolutionModel(nullptr),m_pChannelModel(nullptr),m_pRateModel(nullptr), m_pDummyDevice(nullptr),m_pActiveDevice(nullptr) { - connect(this ,SIGNAL(changed()) , channelModel () , SLOT(reload())); - connect(channelModel() ,SIGNAL(changed()) , resolutionModel() , SLOT(reload())); - connect(resolutionModel(),SIGNAL(changed()) , rateModel () , SLOT(reload())); m_spInstance = this; reload(); - channelModel ()->reload(); - rateModel ()->reload(); - resolutionModel()->reload(); } ///Destructor @@ -147,7 +140,7 @@ void VideoDeviceModel::reload() m_lDevices = m_hDevices.values(); emit layoutChanged(); - channelModel ()->reload(); +// channelModel ()->reload(); setActive(activeDevice()); } @@ -182,312 +175,6 @@ int VideoDeviceModel::currentIndex() const } - - - -//Resolution - -VideoDeviceResolutionModel* VideoDeviceModel::resolutionModel() const -{ - if (!m_pResolutionModel) - const_cast<VideoDeviceModel*>(this)->m_pResolutionModel = new VideoDeviceResolutionModel(); - return m_pResolutionModel; -} - -///Get data from the model -QVariant VideoDeviceResolutionModel::data( const QModelIndex& idx, int role) const -{ - if(idx.column() == 0 && role == Qt::DisplayRole) - return QVariant(VideoDeviceModel::instance()->activeDevice()->activeChannel()->validResolutions()[idx.row()]->name()); - return QVariant(); -} - -///The number of codec -int VideoDeviceResolutionModel::rowCount( const QModelIndex& par ) const -{ - Q_UNUSED(par) - return VideoDeviceModel::instance()->activeDevice()->activeChannel()->validResolutions().size(); -} - -///Items flag -Qt::ItemFlags VideoDeviceResolutionModel::flags( const QModelIndex& idx ) const -{ - if (idx.column() == 0) - return QAbstractItemModel::flags(idx) | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable; - return QAbstractItemModel::flags(idx); -} - -///Set the codec data (codecs can't be added or removed that way) -bool VideoDeviceResolutionModel::setData(const QModelIndex& idx, const QVariant &value, int role) -{ - Q_UNUSED(idx) - Q_UNUSED(value) - Q_UNUSED(role) - return false; -} - -///Constructor -VideoDeviceResolutionModel::VideoDeviceResolutionModel() : QAbstractListModel(QCoreApplication::instance()) -{ -} - -///Destructor -VideoDeviceResolutionModel::~VideoDeviceResolutionModel() -{ - -} - - -Resolution* VideoDeviceResolutionModel::activeResolution() const -{ - return VideoDeviceModel::instance()->activeDevice()->activeChannel()->activeResolution(); -} - -///Save the current model over dbus -void VideoDeviceResolutionModel::setActive(const QModelIndex& idx) -{ - if (idx.isValid()) { - Resolution* r = VideoDeviceModel::instance()->activeDevice()->activeChannel()->validResolutions()[idx.row()]; - QSize s1(*r),s2(*VideoDeviceModel::instance()->activeDevice()->activeChannel()->activeResolution()); - if (s1 == s2) - return; - VideoDeviceModel::instance()->activeDevice()->activeChannel()->setActiveResolution(r); - emit changed(); - emit currentIndexChanged(idx.row()); - } - else - qDebug() << "INVALID RESOLUTION INDEX" << idx.row(); -} - -///Convenience -void VideoDeviceResolutionModel::setActive(const int idx) -{ - setActive(index(idx,0,QModelIndex())); -} - -void VideoDeviceResolutionModel::reload() -{ - QHash<QString,Resolution*> devicesHash; - VideoDevice* active = VideoDeviceModel::instance()->activeDevice(); - if (active) { - - emit layoutChanged(); - - VideoDeviceModel::instance()->rateModel()->reload(); - - emit changed(); - emit currentIndexChanged(activeResolution()->index()); - } - else { - m_hResolutions.clear(); - emit layoutChanged(); - } -} - - -int VideoDeviceResolutionModel::currentIndex() const -{ - return VideoDeviceModel::instance()->activeDevice()->activeChannel()->activeResolution()->index(); -} - - - - - -//Camera - - -VideoDeviceChannelModel* VideoDeviceModel::channelModel() const -{ - if (!m_pChannelModel) - const_cast<VideoDeviceModel*>(this)->m_pChannelModel = new VideoDeviceChannelModel(); - return m_pChannelModel; -} - - -VideoChannel* VideoDeviceChannelModel::activeChannel() const -{ - return VideoDeviceModel::instance()->activeDevice()->activeChannel(); -} - -///Get data from the model -QVariant VideoDeviceChannelModel::data( const QModelIndex& idx, int role) const -{ - if(idx.column() == 0 && role == Qt::DisplayRole) - return QVariant(activeChannel()->name()); - return QVariant(); -} - -///The number of codec -int VideoDeviceChannelModel::rowCount( const QModelIndex& par ) const -{ - Q_UNUSED(par) - return VideoDeviceModel::instance()->activeDevice()->channelList().size(); -} - -///Items flag -Qt::ItemFlags VideoDeviceChannelModel::flags( const QModelIndex& idx ) const -{ - if (idx.column() == 0) - return QAbstractItemModel::flags(idx) | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable; - return QAbstractItemModel::flags(idx); -} - -///Set the codec data (codecs can't be added or removed that way) -bool VideoDeviceChannelModel::setData(const QModelIndex& idx, const QVariant &value, int role) -{ - Q_UNUSED(idx) - Q_UNUSED(value) - Q_UNUSED(role) - return false; -} - -///Constructor -VideoDeviceChannelModel::VideoDeviceChannelModel() : QAbstractListModel(QCoreApplication::instance()) -{ -} - -///Destructor -VideoDeviceChannelModel::~VideoDeviceChannelModel() -{ -} - -///Save the current model over dbus -void VideoDeviceChannelModel::setActive(const QModelIndex& idx) -{ - if (idx.isValid()) { - VideoChannel* c = VideoDeviceModel::instance()->activeDevice()->channelList()[idx.row()]; - VideoDeviceModel::instance()->activeDevice()->setActiveChannel(c); - emit changed(); - emit currentIndexChanged(idx.row()); - } -} - -///Convenience -void VideoDeviceChannelModel::setActive(const int idx) -{ - setActive(index(idx,0,QModelIndex())); -} - -void VideoDeviceChannelModel::reload() -{ - VideoDevice* active = VideoDeviceModel::instance()->activeDevice(); - if (active) { - - emit layoutChanged(); - - VideoDeviceModel::instance()->resolutionModel()->reload(); - - setActive(activeChannel()->index()); - } - else { - emit layoutChanged(); - } -} - -int VideoDeviceChannelModel::currentIndex() const -{ - return activeChannel()->index(); -} - - - - -//Rate - - -VideoDeviceRateModel* VideoDeviceModel::rateModel() const -{ - if (!m_pRateModel) - const_cast<VideoDeviceModel*>(this)->m_pRateModel = new VideoDeviceRateModel(); - return m_pRateModel; -} - -VideoRate* VideoDeviceRateModel::activeRate() const -{ - return VideoDeviceModel::instance()->activeDevice()->activeChannel()->activeResolution()->activeRate(); -} - -///Get data from the model -QVariant VideoDeviceRateModel::data( const QModelIndex& idx, int role) const -{ - if(idx.isValid() && idx.column() == 0 && role == Qt::DisplayRole) - return QVariant(VideoDeviceModel::instance()->activeDevice()->activeChannel()->activeResolution()->validRates()[idx.row()]->name()); - return QVariant(); -} - -///The number of codec -int VideoDeviceRateModel::rowCount( const QModelIndex& par ) const -{ - Q_UNUSED(par) - return VideoDeviceModel::instance()->activeDevice()->activeChannel()->activeResolution()->validRates().size(); -} - -///Items flag -Qt::ItemFlags VideoDeviceRateModel::flags( const QModelIndex& idx ) const -{ - if (idx.column() == 0) - return QAbstractItemModel::flags(idx) | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable; - return QAbstractItemModel::flags(idx); -} - -///Set the codec data (codecs can't be added or removed that way) -bool VideoDeviceRateModel::setData(const QModelIndex& idx, const QVariant &value, int role) -{ - Q_UNUSED(idx) - Q_UNUSED(value) - Q_UNUSED(role) - return false; -} - -///Constructor -VideoDeviceRateModel::VideoDeviceRateModel() : QAbstractListModel(QCoreApplication::instance()) -{ -} - -///Destructor -VideoDeviceRateModel::~VideoDeviceRateModel() -{ -} - -///Save the current model over dbus -void VideoDeviceRateModel::setActive(const QModelIndex& idx) -{ - if (idx.isValid()) { - VideoDeviceModel::instance()->activeDevice()->activeChannel()->activeResolution()->setActiveRate( - VideoDeviceModel::instance()->activeDevice()->activeChannel()->activeResolution()->validRates()[idx.row()]); - emit changed(); - emit currentIndexChanged(idx.row()); - } - else - qDebug() << "INVALID RATE INDEX" << idx.row() << rowCount(); -} - -///Convenience -void VideoDeviceRateModel::setActive(const int idx) -{ - setActive(index(idx,0,QModelIndex())); -} - -void VideoDeviceRateModel::reload() -{ - QHash<QString,VideoDevice*> devicesHash; - VideoDevice* active = VideoDeviceModel::instance()->activeDevice(); - if (active) { - emit layoutChanged(); - setActive(activeRate()->index()); - } - else { - emit layoutChanged(); - } -} - -int VideoDeviceRateModel::currentIndex() const -{ - return activeRate()->index(); -} - - // Extended Device list @@ -591,9 +278,8 @@ void ExtendedVideoDeviceModel::setFile(const QUrl& url) m_CurrentFile = url; } -void ExtendedVideoDeviceModel::setDisplay(int index, Resolution res, QPoint point) +void ExtendedVideoDeviceModel::setDisplay(int index, QRect rect) { m_Display.index = index ; - m_Display.res = res ; - m_Display.point = point ; + m_Display.rect = rect ; } diff --git a/src/video/videodevicemodel.h b/src/video/videodevicemodel.h index 33946a57b658ec95642a811ee90f8d57b09bc5ef..b982e5b8fef37fd1ae840f5c3e02d0d7ec47da52 100644 --- a/src/video/videodevicemodel.h +++ b/src/video/videodevicemodel.h @@ -21,7 +21,7 @@ #include "../typedefs.h" #include <QtCore/QAbstractListModel> #include <QtCore/QUrl> -#include <QtCore/QPoint> +#include <QtCore/QRect> #include "videodevice.h" //Qt @@ -29,88 +29,6 @@ //SFLPhone class VideoDevice; -//DEPRECATED -///Abstract model for managing account video codec list -class LIB_EXPORT VideoDeviceResolutionModel : public QAbstractListModel { - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant" - Q_OBJECT - #pragma GCC diagnostic pop - -public: - //Private constructor, can only be called by 'Account' - explicit VideoDeviceResolutionModel(); - ~VideoDeviceResolutionModel(); - - //Model functions - QVariant data ( const QModelIndex& index, int role = Qt::DisplayRole ) const; - int rowCount ( const QModelIndex& parent = QModelIndex() ) const; - Qt::ItemFlags flags ( const QModelIndex& index ) const; - virtual bool setData ( const QModelIndex& index, const QVariant &value, int role) ; - - Resolution* activeResolution() const; - int currentIndex() const; - -private: - - //Attrbutes - QHash<QString,Resolution*> m_hResolutions ; -// QList<Resolution*> m_lResolutions; - static VideoDeviceResolutionModel* m_spInstance; - -public Q_SLOTS: - void setActive(const QModelIndex& idx); - void setActive(const int idx); - void reload(); - -Q_SIGNALS: - void changed(); - void currentIndexChanged(int); -}; -Q_DECLARE_METATYPE(VideoDeviceResolutionModel*) - -//DEPRECATED -///Abstract model for managing account video codec list -class LIB_EXPORT VideoDeviceChannelModel : public QAbstractListModel { - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant" - Q_OBJECT - #pragma GCC diagnostic pop - -public: - //Private constructor, can only be called by 'Account' - explicit VideoDeviceChannelModel(); - ~VideoDeviceChannelModel(); - - //Model functions - QVariant data ( const QModelIndex& index, int role = Qt::DisplayRole ) const; - int rowCount ( const QModelIndex& parent = QModelIndex() ) const; - Qt::ItemFlags flags ( const QModelIndex& index ) const; - virtual bool setData ( const QModelIndex& index, const QVariant &value, int role) ; - - static VideoDeviceChannelModel* instance(); - - VideoChannel* activeChannel() const; - int currentIndex() const; - -private: - //Attrbutes -// QList<QString> m_lChannels; - - -public Q_SLOTS: - void setActive(const QModelIndex& idx); - void setActive(const int idx); - void reload(); - -Q_SIGNALS: - void changed(); - void currentIndexChanged(int); -}; -Q_DECLARE_METATYPE(VideoDeviceChannelModel*) - - - //TODO qt5, use QIdentityProxyModel class LIB_EXPORT ExtendedVideoDeviceModel : public QAbstractListModel { Q_OBJECT @@ -139,10 +57,9 @@ private: }; struct Display { - Display() : res("0x0"),point(0,0),index(0){} - Resolution res ; /* Resolution 0x0 for native */ - QPoint point ; /* Origin, usually x:0,y:0 */ - int index ; /* X11 display ID, usually 0 */ + Display() : rect(0,0,0,0),index(0){} + QRect rect; + int index ; /* X11 display ID, usually 0 */ }; explicit ExtendedVideoDeviceModel(); static ExtendedVideoDeviceModel* m_spInstance; @@ -153,45 +70,8 @@ public Q_SLOTS: void switchTo(const QModelIndex& idx); void switchTo(const int idx); void setFile(const QUrl& url); - void setDisplay(int index, Resolution res = Resolution("0x0"), QPoint point = QPoint(0,0)); -}; - -//DEPRECATED -///Abstract model for managing account video codec list -class LIB_EXPORT VideoDeviceRateModel : public QAbstractListModel { - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant" - Q_OBJECT - #pragma GCC diagnostic pop - -public: - //Private constructor, can only be called by 'Account' - explicit VideoDeviceRateModel(); - ~VideoDeviceRateModel(); - - //Model functions - QVariant data ( const QModelIndex& index, int role = Qt::DisplayRole ) const; - int rowCount ( const QModelIndex& parent = QModelIndex() ) const; - Qt::ItemFlags flags ( const QModelIndex& index ) const; - virtual bool setData ( const QModelIndex& index, const QVariant &value, int role) ; - - VideoRate* activeRate() const; - int currentIndex() const; - -private: - //Attrbutes -// QList<QString> m_lRates; - -public Q_SLOTS: - void setActive(const QModelIndex& idx); - void setActive(const int idx); - void reload(); - -Q_SIGNALS: - void changed(); - void currentIndexChanged(int); + void setDisplay(int index, QRect rect = QRect(0,0,0,0)); }; -Q_DECLARE_METATYPE(VideoDeviceRateModel*) ///Abstract model for managing account video codec list class LIB_EXPORT VideoDeviceModel : public QAbstractListModel { @@ -213,21 +93,22 @@ public: static VideoDeviceModel* instance(); - VideoDeviceRateModel* rateModel () const; - VideoDeviceChannelModel* channelModel () const; - VideoDeviceResolutionModel* resolutionModel () const; VideoDevice* activeDevice() const; int currentIndex() const; + VideoDevice* getDevice(const QString& devId) const + { + return m_hDevices[devId]; + } + QList<VideoDevice*> devices() const { + return m_lDevices; + } private: //Attrbutes QHash<QString,VideoDevice*> m_hDevices ; QList<VideoDevice*> m_lDevices ; static VideoDeviceModel* m_spInstance ; - VideoDeviceResolutionModel* m_pResolutionModel; - VideoDeviceChannelModel* m_pChannelModel ; - VideoDeviceRateModel* m_pRateModel ; VideoDevice* m_pDummyDevice ; VideoDevice* m_pActiveDevice ; diff --git a/src/video/videomodel.cpp b/src/video/videomodel.cpp index c928e48428a36338a9d42fd45451822cdfced651..8ed6ddcdd09ae6b41b2b26a15d74da6598bcb09b 100644 --- a/src/video/videomodel.cpp +++ b/src/video/videomodel.cpp @@ -27,6 +27,9 @@ #include "callmodel.h" #include "videorenderer.h" #include "videodevicemodel.h" +#include "videochannel.h" +#include "videorate.h" +#include "videoresolution.h" //Static member VideoModel* VideoModel::m_spInstance = nullptr; @@ -43,10 +46,7 @@ VideoModel::VideoModel():QThread(),m_BufferSize(0),m_ShmKey(0),m_SemKey(0),m_Pre VideoModel::~VideoModel() { - foreach(VideoDevice* dev, m_hDevices) { - delete dev; - } - m_hDevices.clear(); + } ///Singleton @@ -70,7 +70,7 @@ VideoRenderer* VideoModel::previewRenderer() { if (!m_lRenderers["local"]) { m_lRenderers["local"] = new VideoRenderer("local","", - VideoDeviceModel::instance()->activeDevice()->activeChannel()->activeResolution()); + VideoDeviceModel::instance()->activeDevice()->activeChannel()->activeResolution()->size()); } return m_lRenderers["local"]; } @@ -115,18 +115,18 @@ void VideoModel::startedDecoding(const QString& id, const QString& shmPath, int { Q_UNUSED(id) - Resolution* res; + QSize res; if (VideoDeviceModel::instance()->activeDevice() && VideoDeviceModel::instance()->activeDevice()->activeChannel()->activeResolution()->width() == width) { //FIXME flawed logic - res = VideoDeviceModel::instance()->activeDevice()->activeChannel()->activeResolution(); + res = VideoDeviceModel::instance()->activeDevice()->activeChannel()->activeResolution()->size(); } else { - res = new Resolution(width,height); //FIXME leak + res = QSize(width,height); } if (m_lRenderers[id] == nullptr ) { - m_lRenderers[id] = new VideoRenderer(id,shmPath,res); + m_lRenderers[id] = new VideoRenderer(id,shmPath,res); m_lRenderers[id]->moveToThread(this); if (!isRunning()) start(); @@ -134,11 +134,11 @@ void VideoModel::startedDecoding(const QString& id, const QString& shmPath, int else { VideoRenderer* renderer = m_lRenderers[id]; renderer->setShmPath(shmPath); - renderer->setResolution(res); + renderer->setSize(res); } m_lRenderers[id]->startRendering(); - VideoDevice* dev = device(id); + VideoDevice* dev = VideoDeviceModel::instance()->getDevice(id); if (dev) { emit dev->renderingStarted(m_lRenderers[id]); } @@ -164,7 +164,7 @@ void VideoModel::stoppedDecoding(const QString& id, const QString& shmPath) qDebug() << "Video stopped for call" << id << "Renderer found:" << (m_lRenderers[id] != nullptr); // emit videoStopped(); - VideoDevice* dev = device(id); + VideoDevice* dev = VideoDeviceModel::instance()->getDevice(id); if (dev) { emit dev->renderingStopped(r); } @@ -184,45 +184,6 @@ void VideoModel::switchDevice(const VideoDevice* device) const interface.switchInput(device->id()); } -QList<VideoDevice*> VideoModel::devices() -{ - QHash<QString,VideoDevice*> devicesHash; - VideoManagerInterface& interface = DBus::VideoManager::instance(); - const QStringList deviceList = interface.getDeviceList(); - if (deviceList.size() == m_hDevices.size()) { -// qDebug() << "\n\nRETUNING CACHE" << m_hDevices.values(); -// foreach(const QString& deviceName,deviceList) { -// qDebug() << "Meh" << m_hDevices[deviceName]; -// } - return m_hDevices.values(); - } - - foreach(const QString& deviceName,deviceList) { - if (!m_hDevices[deviceName]) { - devicesHash[deviceName] = new VideoDevice(deviceName); -// qDebug() << "\n\nNEW" << devicesHash[deviceName]; - } - else { -// qDebug() << "\n\nPUSH" << m_hDevices[deviceName]; - devicesHash[deviceName] = m_hDevices[deviceName]; - } - } - foreach(VideoDevice* dev,m_hDevices) { - if (dev && devicesHash.key(dev).isEmpty()) { -// qDebug() << "\n\nDELETE"; - delete dev; - } - } - m_hDevices.clear(); - m_hDevices = devicesHash; - return m_hDevices.values(); -} - -VideoDevice* VideoModel::device(const QString &id) -{ - return m_hDevices[id]; -} - QMutex* VideoModel::startStopMutex() const { return m_SSMutex; diff --git a/src/video/videomodel.h b/src/video/videomodel.h index e70f8e21f6bcb194c2915e1cc97d4c6e05ad6b77..e94cc30a37285f96ef93749f4feaec82e10bc812 100644 --- a/src/video/videomodel.h +++ b/src/video/videomodel.h @@ -45,9 +45,9 @@ public: bool isPreviewing (); VideoRenderer* getRenderer(const Call* call) const; VideoRenderer* previewRenderer(); - QList<VideoDevice*> devices(); +// QList<VideoDevice*> devices(); // VideoDevice* activeDevice() const; - VideoDevice* device(const QString &id); +// VideoDevice* device(const QString &id); QMutex* startStopMutex() const; //Setters @@ -73,7 +73,7 @@ private: uint m_SemKey ; QMutex* m_SSMutex ; QHash<QString,VideoRenderer*> m_lRenderers; - QHash<QString,VideoDevice*> m_hDevices ; +// QHash<QString,VideoDevice*> m_hDevices ; public Q_SLOTS: void stopPreview (); diff --git a/src/video/videorate.cpp b/src/video/videorate.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e03693468be0dd6e0b03279f88e3d724658bb53d --- /dev/null +++ b/src/video/videorate.cpp @@ -0,0 +1,26 @@ +/**************************************************************************** + * Copyright (C) 2014 by Savoir-Faire Linux * + * Author : Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com> * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * This library 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 * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ +#include "videorate.h" +#include "videodevicemodel.h" +#include "videochannel.h" +#include "videoresolution.h" + +int VideoRate::relativeIndex() +{ + return VideoDeviceModel::instance()->activeDevice()->activeChannel()->activeResolution()->validRates().indexOf(this); +} \ No newline at end of file diff --git a/src/video/videorate.h b/src/video/videorate.h new file mode 100644 index 0000000000000000000000000000000000000000..2e396ed98235eff959c2854449ffee3ca0e82b34 --- /dev/null +++ b/src/video/videorate.h @@ -0,0 +1,45 @@ +/**************************************************************************** + * Copyright (C) 2014 by Savoir-Faire Linux * + * Author : Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com> * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * This library 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 * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ +#ifndef VIDEORATE_H +#define VIDEORATE_H + +#include "../typedefs.h" + +class VideoResolution; + +///@typedef VideoRate The rate for a device +class LIB_EXPORT VideoRate +{ + //Can only be created by VideoDevice + friend class VideoDevice; + +public: + virtual ~VideoRate() {} + QString name() const { + return m_Name; + } + int relativeIndex(); + +private: + VideoRate(const VideoResolution* res,const QString& name) : + m_Name(name),m_pResolution(res) {} + QString m_Name; + const VideoResolution* m_pResolution; +}; + +#endif diff --git a/src/video/videoratemodel.cpp b/src/video/videoratemodel.cpp deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/src/video/videoratemodel.h b/src/video/videoratemodel.h deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/src/video/videorenderer.cpp b/src/video/videorenderer.cpp index 1dc75a3f26d2b7052a05aad38de8954a596a7c0c..0c189e388c4246cda40faa52f9601b4c4d22b13e 100644 --- a/src/video/videorenderer.cpp +++ b/src/video/videorenderer.cpp @@ -37,6 +37,7 @@ #include <QtCore/QTimer> #include "videomodel.h" +#include "videoresolution.h" ///Shared memory object struct SHMHeader{ @@ -55,10 +56,10 @@ struct SHMHeader{ }; ///Constructor -VideoRenderer::VideoRenderer(const QString& id, const QString& shmPath, const Resolution* res): QObject(nullptr), - m_Width(res->width()), m_Height(res->height()), m_ShmPath(shmPath), fd(-1), +VideoRenderer::VideoRenderer(const QString& id, const QString& shmPath, const QSize& res): QObject(nullptr), + m_ShmPath(shmPath), fd(-1), m_pShmArea((SHMHeader*)MAP_FAILED), m_ShmAreaLen(0), m_BufferGen(0), - m_isRendering(false),m_pTimer(nullptr),m_pRes(const_cast<Resolution*>(res)),m_pMutex(new QMutex()), + m_isRendering(false),m_pTimer(nullptr),m_pSize(res),m_pMutex(new QMutex()), m_Id(id),m_FrameIdx(false),m_pSSMutex(new QMutex()) { setObjectName("VideoRenderer:"+id); @@ -330,9 +331,9 @@ const QByteArray& VideoRenderer::currentFrame() } ///Return the current resolution -const Resolution* VideoRenderer::activeResolution() +QSize VideoRenderer::size() { - return m_pRes; + return m_pSize; } ///Get mutex, in case renderer and views are not in the same thread @@ -354,11 +355,9 @@ int VideoRenderer::fps() const * * ****************************************************************************/ -void VideoRenderer::setResolution(Resolution* res) +void VideoRenderer::setSize(const QSize& size) { - m_pRes = res; - m_Width = res->width(); - m_Height = res->height(); + m_pSize = size; } void VideoRenderer::setShmPath(const QString& path) diff --git a/src/video/videorenderer.h b/src/video/videorenderer.h index cd949f2b50e0ff85c9926bbb4908370923986f74..ad13f1b2a16832aad9bc1bc6fa0b701b1ab6c29a 100644 --- a/src/video/videorenderer.h +++ b/src/video/videorenderer.h @@ -41,7 +41,7 @@ class LIB_EXPORT VideoRenderer : public QObject { public: //Constructor - VideoRenderer (const QString& id, const QString& shmPath, const Resolution* res); + VideoRenderer (const QString& id, const QString& shmPath, const QSize& res); ~VideoRenderer(); //Mutators @@ -53,18 +53,16 @@ class LIB_EXPORT VideoRenderer : public QObject { const char* rawData () ; bool isRendering () ; const QByteArray& currentFrame () ; - const Resolution* activeResolution() ; + QSize size () ; QMutex* mutex () ; int fps () const; //Setters - void setResolution(Resolution* res); + void setSize(const QSize& res); void setShmPath (const QString& path); private: //Attributes - uint m_Width ; - uint m_Height ; QString m_ShmPath ; int fd ; SHMHeader * m_pShmArea ; @@ -74,7 +72,7 @@ class LIB_EXPORT VideoRenderer : public QObject { QTimer* m_pTimer ; QByteArray m_Frame[2] ; bool m_FrameIdx ; - Resolution* m_pRes ; + QSize m_pSize ; QMutex* m_pMutex ; QMutex* m_pSSMutex ; QString m_Id ; diff --git a/src/video/videoresolution.cpp b/src/video/videoresolution.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3627364d06aa463eef89a6243f0a99391444a2a0 --- /dev/null +++ b/src/video/videoresolution.cpp @@ -0,0 +1,145 @@ +/**************************************************************************** + * Copyright (C) 2014 by Savoir-Faire Linux * + * Author : Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com> * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * This library 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 * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ +#include "videoresolution.h" + +#include "dbus/videomanager.h" +#include "videochannel.h" +#include "videorate.h" +#include "videodevice.h" + +#include <QtCore/QStringList> + +VideoResolution::VideoResolution(const QString& size, VideoChannel* chan) +: QAbstractListModel(chan), m_pCurrentRate(nullptr),m_pChannel(chan) +{ + Q_ASSERT(chan != nullptr); + if (size.split('x').size() == 2) { + setWidth(size.split('x')[0].toInt()); + setHeight(size.split('x')[1].toInt()); + } +} + +const QString VideoResolution::name() const +{ + return QString::number(width())+'x'+QString::number(height()); +} + + +QVariant VideoResolution::data( const QModelIndex& index, int role) const +{ + if (index.isValid() && role == Qt::DisplayRole && index.row() < m_lValidRates.size()) { + return m_lValidRates[index.row()]->name(); + } + return QVariant(); +} + +int VideoResolution::rowCount( const QModelIndex& parent) const +{ + return (parent.isValid())?0:m_lValidRates.size(); +} + +Qt::ItemFlags VideoResolution::flags( const QModelIndex& idx) const +{ + if (idx.column() == 0) + return QAbstractItemModel::flags(idx) | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable; + return QAbstractItemModel::flags(idx); +} + +bool VideoResolution::setData( const QModelIndex& index, const QVariant &value, int role) +{ + Q_UNUSED(index) + Q_UNUSED(value) + Q_UNUSED(role) + return false; +} + + +const QList<VideoRate*> VideoResolution::validRates() const { + return m_lValidRates; +} + + +bool VideoResolution::setActiveRate(VideoRate* rate) { + if (!rate || (m_lValidRates.indexOf(rate) == -1)) { + qWarning() << "Trying to set an invalid rate" << rate; + return false; + } + m_pCurrentRate = rate; + m_pChannel->device()->save(); + return true; +} + + +bool VideoResolution::setActiveRate(int idx) +{ + if (idx >= m_lValidRates.size() || idx < 0) return false; + return setActiveRate(m_lValidRates[idx]); +} + +VideoRate* VideoResolution::activeRate() +{ + if (!m_pChannel) { + qWarning() << "Trying to get the active rate of an unattached resolution"; + return nullptr; + } + if (!m_pCurrentRate && m_pChannel && m_pChannel->device()->isActive()) { + VideoManagerInterface& interface = DBus::VideoManager::instance(); + const QString rate = QMap<QString,QString>( + interface.getPreferences(m_pChannel->device()->id()))[VideoDevice::PreferenceNames::RATE]; + foreach(VideoRate* r, m_lValidRates) { + if (r->name() == rate) { + m_pCurrentRate = r; + break; + } + } + } + if ((!m_pCurrentRate) && m_lValidRates.size()) + m_pCurrentRate = m_lValidRates[0]; + + return m_pCurrentRate; +} + +int VideoResolution::relativeIndex() const +{ + return m_pChannel?m_pChannel->validResolutions().indexOf(const_cast<VideoResolution*>(this)):-1; +} + +int VideoResolution::width() const +{ + return m_Size.width(); +} + +int VideoResolution::height() const +{ + return m_Size.height(); +} + +QSize VideoResolution::size() const +{ + return m_Size; +} + +void VideoResolution::setWidth(int width) +{ + m_Size.setWidth(width); +} + +void VideoResolution::setHeight(int height) +{ + m_Size.setHeight(height); +} diff --git a/src/video/videoresolution.h b/src/video/videoresolution.h new file mode 100644 index 0000000000000000000000000000000000000000..a950251f55c0096d1e9d88d448c15876e52a61e4 --- /dev/null +++ b/src/video/videoresolution.h @@ -0,0 +1,70 @@ +/**************************************************************************** + * Copyright (C) 2014 by Savoir-Faire Linux * + * Author : Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com> * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * This library 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 * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ +#ifndef VIDEORESOLUTION_H +#define VIDEORESOLUTION_H + +#include <QtCore/QAbstractListModel> +#include <QtCore/QSize> +#include "../typedefs.h" + +class VideoRate; +class VideoChannel; +class VideoDevice; + +///@struct VideoResolution Equivalent of "640x480" +class LIB_EXPORT VideoResolution : public QAbstractListModel { + Q_OBJECT + //Only VideoDevice can add validated rates + friend class VideoDevice; +public: + //Constructor + VideoResolution(const QString& size, VideoChannel* chan); + explicit VideoResolution(); + + //Getter + const QString name() const; + const QList<VideoRate*> validRates() const; + int relativeIndex() const; + VideoRate* activeRate(); + bool setActiveRate(VideoRate* rate); + bool setActiveRate(int index); + int width() const; + int height() const; + QSize size() const; + + //Setters + void setWidth(int width); + void setHeight(int height); + + //Model + QVariant data ( const QModelIndex& index, int role = Qt::DisplayRole ) const; + int rowCount ( const QModelIndex& parent = QModelIndex() ) const; + Qt::ItemFlags flags ( const QModelIndex& index ) const; + virtual bool setData ( const QModelIndex& index, const QVariant &value, int role) ; + + +private: + + //Attributes + QList<VideoRate*> m_lValidRates; + VideoRate* m_pCurrentRate; + VideoChannel* m_pChannel; + QSize m_Size; +}; + +#endif diff --git a/src/video/videoresolutionmodel.cpp b/src/video/videoresolutionmodel.cpp deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/src/video/videoresolutionmodel.h b/src/video/videoresolutionmodel.h deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000