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