Line data Source code
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 : #include "observer.h"
20 :
21 : #pragma GCC diagnostic push
22 : #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
23 : #pragma GCC diagnostic ignored "-Wshadow"
24 : #include <yaml-cpp/yaml.h>
25 : #pragma GCC diagnostic pop
26 :
27 : #include <cstdlib>
28 : #include <memory>
29 : #include <mutex>
30 :
31 : extern "C" {
32 : #include <libavutil/pixfmt.h>
33 :
34 : struct AVPacket;
35 : struct AVDictionary;
36 :
37 : #ifndef AVFORMAT_AVIO_H
38 : struct AVIOContext;
39 : #endif
40 : }
41 :
42 : namespace libjami {
43 : class MediaFrame;
44 : class VideoFrame;
45 : } // namespace libjami
46 :
47 : namespace jami {
48 : using MediaFrame = libjami::MediaFrame;
49 : using VideoFrame = libjami::VideoFrame;
50 : } // namespace jami
51 :
52 : namespace jami {
53 : namespace video {
54 :
55 : struct VideoFrameActiveWriter : Observable<std::shared_ptr<MediaFrame>>
56 : {};
57 : struct VideoFramePassiveReader : Observer<std::shared_ptr<MediaFrame>>
58 : {};
59 :
60 : /*=== VideoGenerator =========================================================*/
61 :
62 : class VideoGenerator : public VideoFrameActiveWriter
63 : {
64 : public:
65 238 : VideoGenerator() {}
66 :
67 : virtual int getWidth() const = 0;
68 : virtual int getHeight() const = 0;
69 : virtual AVPixelFormat getPixelFormat() const = 0;
70 :
71 : std::shared_ptr<VideoFrame> obtainLastFrame();
72 :
73 : public:
74 : // getNewFrame and publishFrame must be called by the same thread only
75 : VideoFrame& getNewFrame();
76 : void publishFrame();
77 : void publishFrame(std::shared_ptr<VideoFrame>);
78 : void flushFrames();
79 :
80 : private:
81 : std::shared_ptr<VideoFrame> writableFrame_ = nullptr;
82 : std::shared_ptr<VideoFrame> lastFrame_ = nullptr;
83 : std::mutex mutex_ {}; // lock writableFrame_/lastFrame_ access
84 : };
85 :
86 : struct VideoSettings
87 : {
88 93 : VideoSettings() {}
89 : VideoSettings(const std::map<std::string, std::string>& settings);
90 :
91 : std::map<std::string, std::string> to_map() const;
92 :
93 : std::string unique_id {};
94 : std::string input {};
95 : std::string name {};
96 : std::string channel {};
97 : std::string video_size {};
98 : std::string framerate {};
99 : bool passthrough {false};
100 : };
101 :
102 : } // namespace video
103 : } // namespace jami
104 :
105 : namespace YAML {
106 : template<>
107 : struct convert<jami::video::VideoSettings>
108 : {
109 : static Node encode(const jami::video::VideoSettings& rhs);
110 : static bool decode(const Node& node, jami::video::VideoSettings& rhs);
111 : };
112 :
113 : Emitter& operator<<(Emitter& out, const jami::video::VideoSettings& v);
114 :
115 : } // namespace YAML
|