Ring Daemon 16.0.0
Loading...
Searching...
No Matches
recordable.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2004-2025 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
19#include "fileutils.h"
20#include "logger.h"
21#include "manager.h"
22#include "recordable.h"
23
24#include <iomanip>
25
26namespace jami {
27
31
33
34std::string
36{
37 if (recorder_)
38 return recorder_->getPath();
39 else
40 return "";
41}
42
43bool
45{
46 if (!recorder_) {
47 JAMI_ERR("Unable to toggle recording, non existent recorder");
48 return false;
49 }
50
51 if (!recording_) {
53 auto dir = audioPath.empty() ? fileutils::get_home_dir() : std::filesystem::path(audioPath);
54 dhtnet::fileutils::check_dir(dir);
55 auto timeStamp = fmt::format("{:%Y%m%d-%H%M%S}", std::chrono::system_clock::now());
56 startRecording((dir / timeStamp).string());
57 } else {
59 }
60 return recording_;
61}
62
63bool
64Recordable::startRecording(const std::string& path)
65{
66 std::lock_guard lk {apiMutex_};
67 if (!recorder_) {
68 JAMI_ERR("Unable to start recording, non existent recorder");
69 return false;
70 }
71
72 if (!recording_) {
73 if (path.empty()) {
74 JAMI_ERR("Unable to start recording, path is empty");
75 return false;
76 }
77
78 recorder_->audioOnly(isAudioOnly_);
79 recorder_->setPath(path);
80 recorder_->startRecording();
81 recording_ = recorder_->isRecording();
82 }
83
84 return recording_;
85}
86
87void
89{
90 std::lock_guard lk {apiMutex_};
91 if (!recorder_) {
92 JAMI_WARN("Unable to stop recording, non existent recorder");
93 return;
94 }
95
96 if (not recording_) {
97 JAMI_WARN("Unable to stop non-running recording");
98 return;
99 }
100
101 recorder_->stopRecording();
102 recording_ = false;
103}
104
105bool
107{
108 return isAudioOnly_;
109}
110
111} // namespace jami
const std::string & getRecordPath() const
static LIBJAMI_TEST_EXPORT Manager & instance()
Definition manager.cpp:676
AudioPreference audioPreference
Audio preferences.
Definition manager.h:90
virtual bool startRecording(const std::string &path)
Start recording.
std::mutex apiMutex_
Definition recordable.h:67
virtual ~Recordable()
virtual void stopRecording()
Stop recording.
virtual bool toggleRecording()
This method must be implemented for this interface as calls and conferences have different behavior.
std::shared_ptr< MediaRecorder > recorder_
Definition recordable.h:69
bool isAudioOnly() const
virtual std::string getPath() const
Return the file path for this recording.
#define JAMI_ERR(...)
Definition logger.h:218
#define JAMI_WARN(...)
Definition logger.h:217
const std::filesystem::path & get_home_dir()
void emitSignal(Args... args)
Definition ring_signal.h:64