LCOV - code coverage report
Current view: top level - src/media - recordable.cpp (source / functions) Hit Total Coverage
Test: jami-coverage-filtered.info Lines: 36 49 73.5 %
Date: 2024-03-28 08:00:27 Functions: 6 8 75.0 %

          Line data    Source code
       1             : /*
       2             :  *  Copyright (C) 2004-2024 Savoir-faire Linux Inc.
       3             :  *
       4             :  *  Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
       5             :  *  Author: Philippe Gorley <philippe.gorley@savoirfairelinux.com>
       6             :  *
       7             :  *  This program is free software; you can redistribute it and/or modify
       8             :  *  it under the terms of the GNU General Public License as published by
       9             :  *  the Free Software Foundation; either version 3 of the License, or
      10             :  *  (at your option) any later version.
      11             :  *
      12             :  *  This program is distributed in the hope that it will be useful,
      13             :  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
      14             :  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15             :  *  GNU General Public License for more details.
      16             :  *
      17             :  *  You should have received a copy of the GNU General Public License
      18             :  *  along with this program; if not, write to the Free Software
      19             :  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.
      20             :  */
      21             : 
      22             : #include "audio/ringbufferpool.h"
      23             : #include "fileutils.h"
      24             : #include "logger.h"
      25             : #include "manager.h"
      26             : #include "recordable.h"
      27             : 
      28             : #include <iomanip>
      29             : 
      30             : namespace jami {
      31             : 
      32         444 : Recordable::Recordable()
      33         444 :  : recorder_(std::make_shared<MediaRecorder>())
      34         444 : {}
      35             : 
      36         444 : Recordable::~Recordable() {}
      37             : 
      38             : std::string
      39          13 : Recordable::getPath() const
      40             : {
      41          13 :     if (recorder_)
      42          13 :         return recorder_->getPath();
      43             :     else
      44           0 :         return "";
      45             : }
      46             : 
      47             : bool
      48          19 : Recordable::toggleRecording()
      49             : {
      50          19 :     if (!recorder_) {
      51           0 :         JAMI_ERR("couldn't toggle recording, non existent recorder");
      52           0 :         return false;
      53             :     }
      54             : 
      55          19 :     if (!recording_) {
      56          11 :         const auto& audioPath = Manager::instance().audioPreference.getRecordPath();
      57          11 :         auto dir = audioPath.empty() ? fileutils::get_home_dir() : std::filesystem::path(audioPath);
      58          11 :         dhtnet::fileutils::check_dir(dir);
      59          11 :         auto timeStamp = fmt::format("{:%Y%m%d-%H%M%S}", std::chrono::system_clock::now());
      60          11 :         startRecording((dir / timeStamp).string());
      61          11 :     } else {
      62           8 :         stopRecording();
      63             :     }
      64          19 :     return recording_;
      65             : }
      66             : 
      67             : bool
      68          11 : Recordable::startRecording(const std::string& path)
      69             : {
      70          11 :     std::lock_guard lk {apiMutex_};
      71          11 :     if (!recorder_) {
      72           0 :         JAMI_ERR("couldn't start recording, non existent recorder");
      73           0 :         return false;
      74             :     }
      75             : 
      76          11 :     if (!recording_) {
      77          11 :         if (path.empty()) {
      78           0 :             JAMI_ERR("couldn't start recording, path is empty");
      79           0 :             return false;
      80             :         }
      81             : 
      82          11 :         recorder_->audioOnly(isAudioOnly_);
      83          11 :         recorder_->setPath(path);
      84          11 :         recorder_->startRecording();
      85          11 :         recording_ = recorder_->isRecording();
      86             :     }
      87             : 
      88          11 :     return recording_;
      89          11 : }
      90             : 
      91             : void
      92          11 : Recordable::stopRecording()
      93             : {
      94          11 :     std::lock_guard lk {apiMutex_};
      95          11 :     if (!recorder_) {
      96           0 :         JAMI_WARN("couldn't stop recording, non existent recorder");
      97           0 :         return;
      98             :     }
      99             : 
     100          11 :     if (not recording_) {
     101           0 :         JAMI_WARN("couldn't stop non-running recording");
     102           0 :         return;
     103             :     }
     104             : 
     105          11 :     recorder_->stopRecording();
     106          11 :     recording_ = false;
     107          11 : }
     108             : 
     109             : bool
     110           0 : Recordable::isAudioOnly() const
     111             : {
     112           0 :     return isAudioOnly_;
     113             : }
     114             : 
     115             : } // namespace jami

Generated by: LCOV version 1.14