Ring Daemon
Loading...
Searching...
No Matches
media_recorder.h
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#pragma once
18
19#ifdef HAVE_CONFIG_H
20#include "config.h"
21#endif
22#include "media_buffer.h"
23#include "media_encoder.h"
24#include "media_filter.h"
25#include "media_stream.h"
26#include "noncopyable.h"
27#include "observer.h"
28#include "audio/resampler.h"
30
31#include <map>
32#include <memory>
33#include <mutex>
34#include <string>
35#include <condition_variable>
36#include <atomic>
37
38namespace jami {
39
40class MediaRecorder : public std::enable_shared_from_this<MediaRecorder>
41{
42public:
45
49 bool isRecording() const;
50
59 std::string getPath() const;
60
67 void audioOnly(bool audioOnly);
68
74 void setPath(const std::string& path);
75
85 void setMetadata(const std::string& title, const std::string& desc);
86
93
99 void removeStream(const MediaStream& ms);
100
106 Observer<std::shared_ptr<MediaFrame>>* getStream(const std::string& name) const;
107
113 int startRecording();
114
120 void stopRecording();
121
122private:
124
125 struct StreamObserver;
126
127 void onFrame(const std::string& name, const std::shared_ptr<MediaFrame>& frame);
128
129 void flush();
130 void reset();
131
132 int initRecord();
133 void setupVideoOutput();
134 std::string buildVideoFilter(const std::vector<MediaStream>& peers, const MediaStream& local) const;
135 void setupAudioOutput();
136 std::mutex mutexStreamSetup_;
137 std::string buildAudioFilter(const std::vector<MediaStream>& peers) const;
138
139 std::mutex mutexFrameBuff_;
140 std::mutex mutexFilterVideo_;
141 std::mutex mutexFilterAudio_;
142
143 std::map<std::string, std::unique_ptr<StreamObserver>> streams_;
144
145 std::string path_;
146 std::tm startTime_;
147 int64_t startTimeStamp_;
148 std::string title_;
149 std::string description_;
150
151 std::unique_ptr<MediaEncoder> encoder_;
152 std::mutex encoderMtx_;
153 std::unique_ptr<MediaFilter> outputVideoFilter_;
154 std::unique_ptr<Resampler> outputAudioResampler_;
155 std::unique_ptr<AudioFrameResizer> audioFrameResizer_;
156
157 std::unique_ptr<MediaFilter> videoFilter_;
158 std::unique_ptr<MediaFilter> audioFilter_;
159
160 int videoIdx_ = -1;
161 int audioIdx_ = -1;
162 bool isRecording_ = false;
163 bool audioOnly_ = false;
164
165 std::condition_variable cv_;
166 std::atomic_bool interrupted_ {false};
167
168 std::list<std::shared_ptr<MediaFrame>> frameBuff_;
169};
170
171}; // namespace jami
bool isRecording() const
Gets whether or not the recorder is active.
Observer< std::shared_ptr< MediaFrame > > * addStream(const MediaStream &ms)
Adds a stream to the recorder.
void stopRecording()
Finalizes the file.
Observer< std::shared_ptr< MediaFrame > > * getStream(const std::string &name) const
Gets the stream observer.
std::string getPath() const
Get file path of file to be recorded.
void setPath(const std::string &path)
Sets output file path.
void audioOnly(bool audioOnly)
Resulting file will be audio or video.
void removeStream(const MediaStream &ms)
Removes a stream from the recorder.
int startRecording()
Initializes the file.
void setMetadata(const std::string &title, const std::string &desc)
Sets title and description metadata for the file.
void emitSignal(Args... args)
Definition jami_signal.h:64
Simple macro to hide class' copy constructor and assignment operator.
#define NON_COPYABLE(ClassName)
Definition noncopyable.h:30