LCOV - code coverage report
Current view: top level - foo/src/media - recordable.cpp (source / functions) Hit Total Coverage
Test: jami-coverage-filtered.info Lines: 36 49 73.5 %
Date: 2026-04-01 09:29:43 Functions: 6 8 75.0 %

          Line data    Source code
       1             : /*
       2             :  *  Copyright (C) 2004-2026 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 "fileutils.h"
      19             : #include "logger.h"
      20             : #include "manager.h"
      21             : #include "recordable.h"
      22             : 
      23             : namespace jami {
      24             : 
      25         404 : Recordable::Recordable()
      26         404 :     : recorder_(std::make_shared<MediaRecorder>())
      27         404 : {}
      28             : 
      29         404 : Recordable::~Recordable() {}
      30             : 
      31             : std::string
      32           4 : Recordable::getPath() const
      33             : {
      34           4 :     if (recorder_)
      35           4 :         return recorder_->getPath();
      36             :     else
      37           0 :         return "";
      38             : }
      39             : 
      40             : bool
      41           4 : Recordable::toggleRecording()
      42             : {
      43           4 :     if (!recorder_) {
      44           0 :         JAMI_ERR("Unable to toggle recording, non existent recorder");
      45           0 :         return false;
      46             :     }
      47             : 
      48           4 :     if (!recording_) {
      49           2 :         const auto& audioPath = Manager::instance().audioPreference.getRecordPath();
      50           2 :         auto dir = audioPath.empty() ? fileutils::get_home_dir() : std::filesystem::path(audioPath);
      51           2 :         dhtnet::fileutils::check_dir(dir);
      52           2 :         auto timeStamp = fmt::format("{:%Y%m%d-%H%M%S}", std::chrono::system_clock::now());
      53           2 :         startRecording((dir / timeStamp).string());
      54           2 :     } else {
      55           2 :         stopRecording();
      56             :     }
      57           4 :     return recording_;
      58             : }
      59             : 
      60             : bool
      61           2 : Recordable::startRecording(const std::string& path)
      62             : {
      63           2 :     std::lock_guard lk {apiMutex_};
      64           2 :     if (!recorder_) {
      65           0 :         JAMI_ERR("Unable to start recording, non existent recorder");
      66           0 :         return false;
      67             :     }
      68             : 
      69           2 :     if (!recording_) {
      70           2 :         if (path.empty()) {
      71           0 :             JAMI_ERR("Unable to start recording, path is empty");
      72           0 :             return false;
      73             :         }
      74             : 
      75           2 :         recorder_->audioOnly(isAudioOnly_);
      76           2 :         recorder_->setPath(path);
      77           2 :         recorder_->startRecording();
      78           2 :         recording_ = recorder_->isRecording();
      79             :     }
      80             : 
      81           2 :     return recording_;
      82           2 : }
      83             : 
      84             : void
      85           2 : Recordable::stopRecording()
      86             : {
      87           2 :     std::lock_guard lk {apiMutex_};
      88           2 :     if (!recorder_) {
      89           0 :         JAMI_WARN("Unable to stop recording, non existent recorder");
      90           0 :         return;
      91             :     }
      92             : 
      93           2 :     if (not recording_) {
      94           0 :         JAMI_WARN("Unable to stop non-running recording");
      95           0 :         return;
      96             :     }
      97             : 
      98           2 :     recorder_->stopRecording();
      99           2 :     recording_ = false;
     100           2 : }
     101             : 
     102             : bool
     103           0 : Recordable::isAudioOnly() const
     104             : {
     105           0 :     return isAudioOnly_;
     106             : }
     107             : 
     108             : } // namespace jami

Generated by: LCOV version 1.14