Ring Daemon
Loading...
Searching...
No Matches
localrecorder.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 "localrecorder.h"
20#include "client/videomanager.h"
21#include "media_stream.h"
22#include "manager.h"
23#include "logger.h"
24#include "client/videomanager.h"
25
26namespace jami {
27
29{
30 inputUri_ = inputUri;
31 isAudioOnly_ = inputUri_.empty();
32 recorder_->audioOnly(isAudioOnly_);
33}
34
40
41void
42LocalRecorder::setPath(const std::string& path)
43{
44 if (isRecording()) {
45 JAMI_ERR("Unable to set path while recording");
46 return;
47 }
48
49 recorder_->setPath(path);
50 path_ = path;
51}
52
53bool
55{
56 if (isRecording()) {
57 JAMI_ERR("Recording already started!");
58 return false;
59 }
60
61 if (path_.empty()) {
62 JAMI_ERR("Unable to start recording (path not set)");
63 return false;
64 }
65
66 if (!recorder_) {
67 JAMI_ERR("Unable to start recording (no recorder)");
68 return false;
69 }
70
71 // audio recording
72 // create read offset in RingBuffer
74
75 audioInput_ = getAudioInput(path_);
76 audioInput_->setFormat(AudioFormat::STEREO());
77 audioInput_->attach(recorder_->addStream(audioInput_->getInfo()));
78 audioInput_->switchInput("");
79
80#ifdef ENABLE_VIDEO
81 // video recording
82 if (!isAudioOnly_) {
83 videoInput_ = std::static_pointer_cast<video::VideoInput>(getVideoInput(inputUri_));
84 if (videoInput_) {
85 videoInput_->attach(recorder_->addStream(videoInput_->getInfo()));
86 } else {
87 JAMI_ERR() << "Unable to record video (no video input)";
88 return false;
89 }
90 }
91#endif
92
93 return Recordable::startRecording(path_);
94}
95
96void
98{
99 if (auto* ob = recorder_->getStream(audioInput_->getInfo().name))
100 audioInput_->detach(ob);
101#ifdef ENABLE_VIDEO
102 if (videoInput_)
103 if (auto* ob = recorder_->getStream(videoInput_->getInfo().name))
104 videoInput_->detach(ob);
105#endif
107 // NOTE stopRecording should be last call to avoid data races
109}
110
111} // namespace jami
bool start()
Start local recording.
LocalRecorder(const std::string &inputUri)
void setPath(const std::string &path)
Set recording path.
void stopRecording() override
Stops recording.
static LIBJAMI_TEST_EXPORT Manager & instance()
Definition manager.cpp:694
RingBufferPool & getRingBufferPool()
Return a pointer to the instance of the RingBufferPool.
Definition manager.cpp:3197
virtual bool startRecording(const std::string &path)
Start recording.
virtual void stopRecording()
Stop recording.
std::shared_ptr< MediaRecorder > recorder_
Definition recordable.h:69
bool isRecording() const
Return recording state (true/false)
Definition recordable.h:36
void bindHalfDuplexOut(const std::string &readerBufferId, const std::string &sourceBufferId)
Attaches a reader the specified source.
static const char *const DEFAULT_ID
void unBindHalfDuplexOut(const std::string &readerBufferId, const std::string &sourceBufferId)
Detaches a reader from the specified source.
#define JAMI_ERR(...)
Definition logger.h:230
void emitSignal(Args... args)
Definition jami_signal.h:64
std::shared_ptr< AudioInput > getAudioInput(const std::string &device)
static const constexpr AudioFormat STEREO()