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-12-21 08:56:24 Functions: 6 8 75.0 %

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

Generated by: LCOV version 1.14