| 6 |
| // Copyright © 2020 Mikhail Filimonov. All rights reserved. |
| 7 | // |
| 8 |
| 9 | #include "tgcalls/desktop_capturer/DesktopCaptureSourceManager.h" |
| 10 |
| 11 | #include "modules/desktop_capture/desktop_and_cursor_composer.h" |
| 12 | #include "modules/desktop_capture/desktop_capturer_differ_wrapper.h" |
| 13 | #include "third_party/libyuv/include/libyuv.h" |
| 14 | #include "api/video/i420_buffer.h" |
| 15 | #include "tgcalls/desktop_capturer/DesktopCaptureSourceHelper.h" |
| 16 |
| 17 |
| 18 | namespace tgcalls { |
| 19 |
| 20 | DesktopCaptureSourceManager::DesktopCaptureSourceManager( |
| 21 | DesktopCaptureType type) |
| 22 | : _capturer(CreateForType(type)) |
| 23 | , _type(type) { |
| 24 | } |
| 25 |
| 26 | DesktopCaptureSourceManager::~DesktopCaptureSourceManager() = default; |
| 27 |
| 28 | webrtc::DesktopCaptureOptions DesktopCaptureSourceManager::OptionsForType( |
| 29 | DesktopCaptureType type) { |
| 30 | auto result = webrtc::DesktopCaptureOptions::CreateDefault(); |
| 31 | #ifdef WEBRTC_WIN |
| 32 | result.set_allow_directx_capturer(true); |
| 33 | #elif defined WEBRTC_MAC |
| 34 | result.set_allow_iosurface(type == DesktopCaptureType::Screen); |
| 35 | #elif defined WEBRTC_USE_PIPEWIRE |
| 36 | result.set_allow_pipewire(true); |
| 37 | #endif // WEBRTC_WIN || WEBRTC_MAC |
| 38 | result.set_detect_updated_region(true); |
| 39 | return result; |
| 40 | } |
| 41 |
| 42 | auto DesktopCaptureSourceManager::CreateForType(DesktopCaptureType type) |
| 43 | -> std::unique_ptr<webrtc::DesktopCapturer> { |
| 44 | const auto options = OptionsForType(type); |
| 45 | if (auto result = webrtc::DesktopCapturer::CreateGenericCapturer(options)) { |
| 46 | return result; |
| 47 | } |
| 48 | return (type == DesktopCaptureType::Screen) |
| 49 | ? webrtc::DesktopCapturer::CreateScreenCapturer(options) |
| 50 | : webrtc::DesktopCapturer::CreateWindowCapturer(options); |
| 51 | } |
| 52 |
| 53 | std::vector<DesktopCaptureSource> DesktopCaptureSourceManager::sources() { |
| 54 | auto result = std::vector<DesktopCaptureSource>(); |
| 55 | auto list = webrtc::DesktopCapturer::SourceList(); |
| 56 | if (_capturer && _capturer->GetSourceList(&list)) { |
| 57 | const auto isWindow = (_type == DesktopCaptureType::Window); |
| 58 | for (const auto &source : list) { |
| 59 | result.emplace_back(source.id, source.title, isWindow); |
| 60 | } |
| 61 | } |
| 62 | return result; |
| 63 | } |
| 64 |
| 65 | } // namespace tgcalls |
| 66 |