Ring Daemon
Loading...
Searching...
No Matches
recordable.cpp
Go to the documentation of this file.
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
23namespace jami {
24
28
30
31std::string
33{
34 if (recorder_)
35 return recorder_->getPath();
36 else
37 return "";
38}
39
40bool
42{
43 if (!recorder_) {
44 JAMI_ERR("Unable to toggle recording, non existent recorder");
45 return false;
46 }
47
48 if (!recording_) {
50 auto dir = audioPath.empty() ? fileutils::get_home_dir() : std::filesystem::path(audioPath);
51 dhtnet::fileutils::check_dir(dir);
52 auto timeStamp = fmt::format("{:%Y%m%d-%H%M%S}", std::chrono::system_clock::now());
53 startRecording((dir / timeStamp).string());
54 } else {
56 }
57 return recording_;
58}
59
60bool
61Recordable::startRecording(const std::string& path)
62{
63 std::lock_guard lk {apiMutex_};
64 if (!recorder_) {
65 JAMI_ERR("Unable to start recording, non existent recorder");
66 return false;
67 }
68
69 if (!recording_) {
70 if (path.empty()) {
71 JAMI_ERR("Unable to start recording, path is empty");
72 return false;
73 }
74
75 recorder_->audioOnly(isAudioOnly_);
76 recorder_->setPath(path);
77 recorder_->startRecording();
78 recording_ = recorder_->isRecording();
79 }
80
81 return recording_;
82}
83
84void
86{
87 std::lock_guard lk {apiMutex_};
88 if (!recorder_) {
89 JAMI_WARN("Unable to stop recording, non existent recorder");
90 return;
91 }
92
93 if (not recording_) {
94 JAMI_WARN("Unable to stop non-running recording");
95 return;
96 }
97
98 recorder_->stopRecording();
99 recording_ = false;
100}
101
102bool
104{
105 return isAudioOnly_;
106}
107
108} // namespace jami
const std::string & getRecordPath() const
static LIBJAMI_TEST_EXPORT Manager & instance()
Definition manager.cpp:694
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:230
#define JAMI_WARN(...)
Definition logger.h:229
const std::filesystem::path & get_home_dir()
void emitSignal(Args... args)
Definition jami_signal.h:64