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 : #ifdef HAVE_CONFIG_H
20 : #include "config.h"
21 : #endif
22 :
23 : #include <memory> // for weak/shared_ptr
24 : #include <map>
25 : #include <mutex>
26 : #include <string>
27 :
28 : #include "media/audio/audio_input.h"
29 : #ifdef ENABLE_VIDEO
30 : #include "media/video/video_device_monitor.h"
31 : #include "media/video/video_input.h"
32 : #endif
33 : #include "media/media_player.h"
34 :
35 : namespace jami {
36 :
37 : struct VideoManager
38 : {
39 : public:
40 : // Client-managed video inputs and players
41 : std::map<std::string, std::shared_ptr<MediaPlayer>> mediaPlayers;
42 : std::mutex mediaPlayersMutex;
43 :
44 : // Client-managed audio preview
45 : std::shared_ptr<AudioInput> audioPreview;
46 :
47 : #ifdef ENABLE_VIDEO
48 : std::map<std::string, std::shared_ptr<video::VideoInput>> clientVideoInputs;
49 : void setDeviceOrientation(const std::string& deviceId, int angle);
50 : // device monitor
51 : video::VideoDeviceMonitor videoDeviceMonitor;
52 0 : std::shared_ptr<video::VideoInput> getVideoInput(std::string_view id) const
53 : {
54 0 : auto input = videoInputs.find(id);
55 0 : return input == videoInputs.end() ? nullptr : input->second.lock();
56 : }
57 : std::mutex videoMutex;
58 : std::map<std::string, std::weak_ptr<video::VideoInput>, std::less<>> videoInputs;
59 : #endif
60 :
61 : /**
62 : * Cache of the active Audio/Video input(s).
63 : */
64 : std::map<std::string, std::weak_ptr<AudioInput>, std::less<>> audioInputs;
65 : std::mutex audioMutex;
66 : bool hasRunningPlayers();
67 : };
68 :
69 : #ifdef ENABLE_VIDEO
70 : video::VideoDeviceMonitor* getVideoDeviceMonitor();
71 : std::shared_ptr<video::VideoInput> getVideoInput(const std::string& resource,
72 : video::VideoInputMode inputMode = video::VideoInputMode::Undefined,
73 : const std::string& sink = "");
74 : #endif
75 : std::shared_ptr<AudioInput> getAudioInput(const std::string& device);
76 : std::string createMediaPlayer(const std::string& path);
77 : std::shared_ptr<MediaPlayer> getMediaPlayer(const std::string& id);
78 : bool pausePlayer(const std::string& id, bool pause);
79 : bool closeMediaPlayer(const std::string& id);
80 : bool mutePlayerAudio(const std::string& id, bool mute);
81 : bool playerSeekToTime(const std::string& id, int time);
82 : int64_t getPlayerPosition(const std::string& id);
83 : int64_t getPlayerDuration(const std::string& id);
84 : void setAutoRestart(const std::string& id, bool restart);
85 :
86 : } // namespace jami
|