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