Ring Daemon 16.0.0
Loading...
Searching...
No Matches
media_recorder.h
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#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
29#include <map>
30#include <memory>
31#include <mutex>
32#include <queue>
33#include <stdexcept>
34#include <string>
35#include <utility>
36#include <condition_variable>
37#include <atomic>
38
39namespace jami {
40
41class MediaRecorder : public std::enable_shared_from_this<MediaRecorder>
42{
43public:
46
50 bool isRecording() const;
51
60 std::string getPath() const;
61
68 void audioOnly(bool audioOnly);
69
75 void setPath(const std::string& path);
76
86 void setMetadata(const std::string& title, const std::string& desc);
87
94
100 void removeStream(const MediaStream& ms);
101
107 Observer<std::shared_ptr<MediaFrame>>* getStream(const std::string& name) const;
108
114 int startRecording();
115
121 void stopRecording();
122
123private:
125
126 struct StreamObserver;
127
128 void onFrame(const std::string& name, const std::shared_ptr<MediaFrame>& frame);
129
130 void flush();
131 void reset();
132
133 int initRecord();
134 void setupVideoOutput();
135 std::string buildVideoFilter(const std::vector<MediaStream>& peers,
136 const MediaStream& local) const;
137 void setupAudioOutput();
138 std::mutex mutexStreamSetup_;
139 std::string buildAudioFilter(const std::vector<MediaStream>& peers) const;
140
141 std::mutex mutexFrameBuff_;
142 std::mutex mutexFilterVideo_;
143 std::mutex mutexFilterAudio_;
144
145 std::map<std::string, std::unique_ptr<StreamObserver>> streams_;
146
147 std::string path_;
148 std::tm startTime_;
149 int64_t startTimeStamp_;
150 std::string title_;
151 std::string description_;
152
153 std::unique_ptr<MediaEncoder> encoder_;
154 std::mutex encoderMtx_;
155 std::unique_ptr<MediaFilter> outputVideoFilter_;
156 std::unique_ptr<MediaFilter> outputAudioFilter_;
157
158 std::unique_ptr<MediaFilter> videoFilter_;
159 std::unique_ptr<MediaFilter> audioFilter_;
160
161 int videoIdx_ = -1;
162 int audioIdx_ = -1;
163 bool isRecording_ = false;
164 bool audioOnly_ = false;
165 int lastVideoPts_ = 0;
166
167 std::condition_variable cv_;
168 std::atomic_bool interrupted_ {false};
169
170 std::list<std::shared_ptr<MediaFrame>> frameBuff_;
171};
172
173}; // 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 ring_signal.h:64
Simple macro to hide class' copy constructor and assignment operator.
#define NON_COPYABLE(ClassName)
Definition noncopyable.h:30