diff --git a/CMakeLists.txt b/CMakeLists.txt index 3c155ea51e4d8c149048d04a3b6ae233d15255dd..8363a8d1816d6721e5b1735b435b02494ef880d0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -392,6 +392,7 @@ SET( libringclient_LIB_SRCS src/dbuserrorhandlerdefault.cpp #Other + src/avmodel.cpp src/hookmanager.cpp src/namedirectory.cpp src/itembase.cpp @@ -519,6 +520,7 @@ SET(libringclient_api_LIB_HDRS src/api/call.h src/api/account.h src/api/lrc.h + src/api/avmodel.h src/api/newaccountmodel.h src/api/newcallmodel.h src/api/newcodecmodel.h diff --git a/src/api/avmodel.h b/src/api/avmodel.h new file mode 100644 index 0000000000000000000000000000000000000000..6e17082782d0908b09768184fe0be341fda474e8 --- /dev/null +++ b/src/api/avmodel.h @@ -0,0 +1,59 @@ +/**************************************************************************** + * Copyright (C) 2018 Savoir-faire Linux * + * Author: Hugo Lefeuvre <hugo.lefeuvre@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/>. * + ***************************************************************************/ +#pragma once + +// std +#include <memory> +#include <string> + +// Qt +#include <qobject.h> + +// LRC +#include "typedefs.h" + +namespace lrc +{ + +class AVModelPimpl; + +namespace api +{ + +class LIB_EXPORT AVModel : public QObject { + Q_OBJECT +public: + AVModel(); + ~AVModel(); + /** + * Stop local record at given path + * @param path + */ + void stopLocalRecorder(const std::string& path) const; + /** + * Start a local recorder and return it path. + * @param audioOnly + */ + std::string startLocalRecorder(const bool& audioOnly) const; + +private: + std::unique_ptr<AVModelPimpl> pimpl_; +}; + +} // namespace api +} // namespace lrc diff --git a/src/api/lrc.h b/src/api/lrc.h index 64907049186a26148abed40cd754a20990471940..8847a216b7440d75507bf224f0494743210f6026 100644 --- a/src/api/lrc.h +++ b/src/api/lrc.h @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (C) 2017-2018 Savoir-faire Linux * + * Copyright (C) 2017-2018 Savoir-faire Linux * * Author: Nicolas Jäger <nicolas.jager@savoirfairelinux.com> * * Author: Sébastien Blin <sebastien.blin@savoirfairelinux.com> * * * @@ -35,6 +35,7 @@ namespace api class BehaviorController; class NewAccountModel; class DataTransferModel; +class AVModel; class LIB_EXPORT Lrc { public: @@ -55,6 +56,11 @@ public: * @return a DataTransferModel&. */ DataTransferModel& getDataTransferModel() const; + /** + * get a reference on the audio-video controller. + * @return a AVModel&. + */ + AVModel& getAVModel() const; /** * Inform the daemon that the connectivity changed diff --git a/src/avmodel.cpp b/src/avmodel.cpp new file mode 100644 index 0000000000000000000000000000000000000000..dcaaa7cf8139db80725bb14ec4159eec2dd0f605 --- /dev/null +++ b/src/avmodel.cpp @@ -0,0 +1,108 @@ +/**************************************************************************** + * Copyright (C) 2018 Savoir-faire Linux * + * Author: Hugo Lefeuvre <hugo.lefeuvre@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 "api/avmodel.h" + +// Std +#include <chrono> +#include <iomanip> // for std::put_time +#include <fstream> +#include <string> +#include <sstream> + +// Qt +#include <QtCore/QStandardPaths> +#include <QtCore/QDir> + +// LRC +#include "dbus/videomanager.h" + +namespace lrc +{ + +using namespace api; + +class AVModelPimpl: public QObject +{ + Q_OBJECT +public: + AVModelPimpl(AVModel& linked); + std::string getRecordingPath() const; + static const std::string recorderSavesSubdir; + AVModel& linked_; +}; + +const std::string AVModelPimpl::recorderSavesSubdir = "sent_data"; + +AVModel::AVModel() +: QObject() +, pimpl_(std::make_unique<AVModelPimpl>(*this)) +{ +} + +AVModel::~AVModel() +{ +} + +AVModelPimpl::AVModelPimpl(AVModel& linked) +: linked_(linked) +{ + std::srand(std::time(nullptr)); +} + +std::string +AVModelPimpl::getRecordingPath() const +{ + const QDir dir = QStandardPaths::writableLocation(QStandardPaths::DataLocation) + "/" + recorderSavesSubdir.c_str(); + dir.mkpath("."); + + std::chrono::time_point<std::chrono::system_clock> time_now = std::chrono::system_clock::now(); + std::time_t time_now_t = std::chrono::system_clock::to_time_t(time_now); + std::tm now_tm = *std::localtime(&time_now_t); + + std::stringstream ss; + ss << dir.path().toStdString(); + ss << "/"; + ss << std::put_time(&now_tm, "%Y%m%d-%H%M%S"); + ss << "-"; + ss << std::rand(); + + QDir file_path(ss.str().c_str()); + + return file_path.path().toStdString(); +} + +void AVModel::stopLocalRecorder(const std::string& path) const +{ + if (path.empty()) { + qDebug("stopLocalRecorder: can't stop non existing recording"); + return; + } + + VideoManager::instance().stopLocalRecorder(QString::fromStdString(path)); +} + +std::string AVModel::startLocalRecorder(const bool& audioOnly) const +{ + const QString path = QString::fromStdString(pimpl_->getRecordingPath()); + const QString finalPath = VideoManager::instance().startLocalRecorder(audioOnly, path); + return finalPath.toStdString(); +} +} // namespace lrc + +#include "api/moc_avmodel.cpp" +#include "avmodel.moc" diff --git a/src/lrc.cpp b/src/lrc.cpp index b8777f4d04a83b8c569e972b7c6071eb327e3144..07afd3a2e89c2d7413cb0e0fcd0ba352e9ae0f29 100644 --- a/src/lrc.cpp +++ b/src/lrc.cpp @@ -20,6 +20,7 @@ // Models and database #include "api/newaccountmodel.h" +#include "api/avmodel.h" #include "api/datatransfermodel.h" #include "api/behaviorcontroller.h" #include "database.h" @@ -44,6 +45,7 @@ public: std::unique_ptr<Database> database; std::unique_ptr<NewAccountModel> accountModel; std::unique_ptr<DataTransferModel> dataTransferModel; + std::unique_ptr<AVModel> AVModel_; }; Lrc::Lrc() @@ -76,6 +78,12 @@ Lrc::getDataTransferModel() const return *lrcPimpl_->dataTransferModel; } +AVModel& +Lrc::getAVModel() const +{ + return *lrcPimpl_->AVModel_; +} + void Lrc::connectivityChanged() const { @@ -109,6 +117,7 @@ LrcPimpl::LrcPimpl(Lrc& linked) , database(std::make_unique<Database>()) , accountModel(std::make_unique<NewAccountModel>(linked, *database, *callbackHandler, *behaviorController)) , dataTransferModel {std::make_unique<DataTransferModel>()} +, AVModel_ {std::make_unique<AVModel>()} { } diff --git a/src/private/videorenderermanager.cpp b/src/private/videorenderermanager.cpp index f5d652144c41932d642e3a2382faff1d51e98fa5..ff14d53210e4c6424d6662dcd13a6eb7c7774dbc 100644 --- a/src/private/videorenderermanager.cpp +++ b/src/private/videorenderermanager.cpp @@ -161,24 +161,20 @@ Video::Renderer* VideoRendererManager::previewRenderer() ///Stop video preview void VideoRendererManager::stopPreview() { - VideoManager::instance().stopCamera(); d_ptr->m_PreviewState = false; - } ///Start video preview void VideoRendererManager::startPreview() { - if (d_ptr->m_PreviewState) return; VideoManager::instance().startCamera(); d_ptr->m_PreviewState = true; - } ///Is the video model fetching preview from a camera diff --git a/src/private/videorenderermanager.h b/src/private/videorenderermanager.h index 071e48cefda47bc5c589171f7178e0b2396fc387..8a418c228e26f22839bffa1d8905db29c9319851 100644 --- a/src/private/videorenderermanager.h +++ b/src/private/videorenderermanager.h @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright (C) 2012-2018 Savoir-faire Linux * + * Copyright (C) 2012-2018 Savoir-faire Linux * * Author : Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com> * * * * This library is free software; you can redistribute it and/or * diff --git a/src/qtwrapper/videomanager_wrap.h b/src/qtwrapper/videomanager_wrap.h index 810335a2c602dd68a7569a96be068f0b95f7b2b7..211e9da61ad0ca1bacca9d10d7d74287324cad67 100644 --- a/src/qtwrapper/videomanager_wrap.h +++ b/src/qtwrapper/videomanager_wrap.h @@ -220,6 +220,16 @@ public Q_SLOTS: // METHODS DRing::setDecodingAccelerated(state); } + void stopLocalRecorder(const QString& path) + { + DRing::stopLocalRecorder(path.toStdString()); + } + + QString startLocalRecorder(bool audioOnly, const QString& path) + { + return QString::fromStdString(DRing::startLocalRecorder(audioOnly, path.toStdString())); + } + Q_SIGNALS: // SIGNALS void deviceEvent(); void startedDecoding(const QString &id, const QString &shmPath, int width, int height, bool isMixer); diff --git a/src/video/previewmanager.h b/src/video/previewmanager.h index 097e208897ae013eaa4bbd9473d2b9060fcccda2..07d954efc4cec3a1797adf3dad232cb62d3a6568 100644 --- a/src/video/previewmanager.h +++ b/src/video/previewmanager.h @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright (C) 2012-2018 Savoir-faire Linux * + * Copyright (C) 2012-2018 Savoir-faire Linux * * Author : Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com> * * * * This library is free software; you can redistribute it and/or * diff --git a/test/mocks/videomanager_mock.h b/test/mocks/videomanager_mock.h index 4ba0afa998945bde93857042727965baee370ea9..530db103f303e9903ccaa2c8925f2de478ad573c 100644 --- a/test/mocks/videomanager_mock.h +++ b/test/mocks/videomanager_mock.h @@ -175,10 +175,21 @@ public Q_SLOTS: // METHODS void setDecodingAccelerated(bool state) { - Q_UNUSED(state) } + void stopLocalRecorder(const QString& path) + { + Q_UNUSED(path) + } + + QString startLocalRecorder(bool audioOnly, const QString& path) + { + Q_UNUSED(audioOnly) + Q_UNUSED(path) + return "/tmp/foobar"; + } + Q_SIGNALS: // SIGNALS void deviceEvent(); void startedDecoding(const QString &id, const QString &shmPath, int width, int height, bool isMixer);