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