Share video capturer between call and settings.
This commit is contained in:
		
							parent
							
								
									4672e3d068
								
							
						
					
					
						commit
						4d2041ae48
					
				
					 5 changed files with 41 additions and 11 deletions
				
			
		| 
						 | 
					@ -373,8 +373,7 @@ void Call::setupOutgoingVideo() {
 | 
				
			||||||
#ifndef DESKTOP_APP_DISABLE_WEBRTC_INTEGRATION
 | 
					#ifndef DESKTOP_APP_DISABLE_WEBRTC_INTEGRATION
 | 
				
			||||||
			Assert(state == Webrtc::VideoState::Active);
 | 
								Assert(state == Webrtc::VideoState::Active);
 | 
				
			||||||
			if (!_videoCapture) {
 | 
								if (!_videoCapture) {
 | 
				
			||||||
				_videoCapture = tgcalls::VideoCaptureInterface::Create(
 | 
									_videoCapture = _delegate->getVideoCapture();
 | 
				
			||||||
					Core::App().settings().callVideoInputDeviceId().toStdString());
 | 
					 | 
				
			||||||
				_videoCapture->setOutput(_videoOutgoing->sink());
 | 
									_videoCapture->setOutput(_videoOutgoing->sink());
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			if (_instance) {
 | 
								if (_instance) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -68,7 +68,9 @@ public:
 | 
				
			||||||
			Ended,
 | 
								Ended,
 | 
				
			||||||
		};
 | 
							};
 | 
				
			||||||
		virtual void playSound(Sound sound) = 0;
 | 
							virtual void playSound(Sound sound) = 0;
 | 
				
			||||||
		virtual void requestPermissionsOrFail(Fn<void()> result) = 0;
 | 
							virtual void requestPermissionsOrFail(Fn<void()> onSuccess) = 0;
 | 
				
			||||||
 | 
							virtual auto getVideoCapture()
 | 
				
			||||||
 | 
								-> std::shared_ptr<tgcalls::VideoCaptureInterface> = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		virtual ~Delegate() = default;
 | 
							virtual ~Delegate() = default;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -24,6 +24,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 | 
				
			||||||
#include "mainwidget.h"
 | 
					#include "mainwidget.h"
 | 
				
			||||||
#include "mtproto/mtproto_config.h"
 | 
					#include "mtproto/mtproto_config.h"
 | 
				
			||||||
#include "boxes/rate_call_box.h"
 | 
					#include "boxes/rate_call_box.h"
 | 
				
			||||||
 | 
					#include "tgcalls/VideoCaptureInterface.h"
 | 
				
			||||||
#include "app.h"
 | 
					#include "app.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace Calls {
 | 
					namespace Calls {
 | 
				
			||||||
| 
						 | 
					@ -344,4 +345,15 @@ void Instance::requestPermissionOrFail(Platform::PermissionType type, Fn<void()>
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					std::shared_ptr<tgcalls::VideoCaptureInterface> Instance::getVideoCapture() {
 | 
				
			||||||
 | 
						if (auto result = _videoCapture.lock()) {
 | 
				
			||||||
 | 
							return result;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						auto result = std::shared_ptr<tgcalls::VideoCaptureInterface>(
 | 
				
			||||||
 | 
							tgcalls::VideoCaptureInterface::Create(
 | 
				
			||||||
 | 
								Core::App().settings().callVideoInputDeviceId().toStdString()));
 | 
				
			||||||
 | 
						_videoCapture = result;
 | 
				
			||||||
 | 
						return result;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
} // namespace Calls
 | 
					} // namespace Calls
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -43,6 +43,7 @@ public:
 | 
				
			||||||
	void showInfoPanel(not_null<Call*> call);
 | 
						void showInfoPanel(not_null<Call*> call);
 | 
				
			||||||
	[[nodiscard]] Call *currentCall() const;
 | 
						[[nodiscard]] Call *currentCall() const;
 | 
				
			||||||
	[[nodiscard]] rpl::producer<Call*> currentCallValue() const;
 | 
						[[nodiscard]] rpl::producer<Call*> currentCallValue() const;
 | 
				
			||||||
 | 
						std::shared_ptr<tgcalls::VideoCaptureInterface> getVideoCapture() override;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	[[nodiscard]] bool isQuitPrevent();
 | 
						[[nodiscard]] bool isQuitPrevent();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -78,6 +79,7 @@ private:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	crl::time _lastServerConfigUpdateTime = 0;
 | 
						crl::time _lastServerConfigUpdateTime = 0;
 | 
				
			||||||
	base::weak_ptr<Main::Session> _serverConfigRequestSession;
 | 
						base::weak_ptr<Main::Session> _serverConfigRequestSession;
 | 
				
			||||||
 | 
						std::weak_ptr<tgcalls::VideoCaptureInterface> _videoCapture;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	std::unique_ptr<Call> _currentCall;
 | 
						std::unique_ptr<Call> _currentCall;
 | 
				
			||||||
	rpl::event_stream<Call*> _currentCallChanges;
 | 
						rpl::event_stream<Call*> _currentCallChanges;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -99,14 +99,16 @@ void Calls::setupContent() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const auto cameras = Webrtc::GetVideoInputList();
 | 
						const auto cameras = Webrtc::GetVideoInputList();
 | 
				
			||||||
	if (!cameras.empty()) {
 | 
						if (!cameras.empty()) {
 | 
				
			||||||
		auto capturerOwner = tgcalls::VideoCaptureInterface::Create(
 | 
							const auto hasCall = (Core::App().calls().currentCall() != nullptr);
 | 
				
			||||||
			settings.callVideoInputDeviceId().toStdString());
 | 
					
 | 
				
			||||||
 | 
							auto capturerOwner = Core::App().calls().getVideoCapture();
 | 
				
			||||||
		const auto capturer = capturerOwner.get();
 | 
							const auto capturer = capturerOwner.get();
 | 
				
			||||||
		content->lifetime().add([owner = std::move(capturerOwner)]{});
 | 
							content->lifetime().add([owner = std::move(capturerOwner)]{});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		const auto track = content->lifetime().make_state<Webrtc::VideoTrack>(
 | 
							const auto track = content->lifetime().make_state<Webrtc::VideoTrack>(
 | 
				
			||||||
			Webrtc::VideoState::Active);
 | 
								(hasCall
 | 
				
			||||||
		capturer->setOutput(track->sink());
 | 
									? Webrtc::VideoState::Inactive
 | 
				
			||||||
 | 
									: Webrtc::VideoState::Active));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		const auto currentCameraName = [&] {
 | 
							const auto currentCameraName = [&] {
 | 
				
			||||||
			const auto i = ranges::find(
 | 
								const auto i = ranges::find(
 | 
				
			||||||
| 
						 | 
					@ -181,17 +183,30 @@ void Calls::setupContent() {
 | 
				
			||||||
		track->renderNextFrame(
 | 
							track->renderNextFrame(
 | 
				
			||||||
		) | rpl::start_with_next([=] {
 | 
							) | rpl::start_with_next([=] {
 | 
				
			||||||
			const auto size = track->frameSize();
 | 
								const auto size = track->frameSize();
 | 
				
			||||||
			if (size.isEmpty()) {
 | 
								if (size.isEmpty() || Core::App().calls().currentCall()) {
 | 
				
			||||||
				return;
 | 
									return;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			const auto width = bubbleWrap->width();
 | 
								const auto width = bubbleWrap->width();
 | 
				
			||||||
			const auto use = (width - 2 * padding);
 | 
								const auto use = (width - 2 * padding);
 | 
				
			||||||
			bubbleWrap->resize(
 | 
								const auto height = std::min(
 | 
				
			||||||
				width,
 | 
									((use * size.height()) / size.width()),
 | 
				
			||||||
				top + ((use * size.height()) / size.width()) + bottom);
 | 
									(use * 480) / 640);
 | 
				
			||||||
 | 
								bubbleWrap->resize(width, top + height + bottom);
 | 
				
			||||||
			bubbleWrap->update();
 | 
								bubbleWrap->update();
 | 
				
			||||||
		}, bubbleWrap->lifetime());
 | 
							}, bubbleWrap->lifetime());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							Core::App().calls().currentCallValue(
 | 
				
			||||||
 | 
							) | rpl::start_with_next([=](::Calls::Call *value) {
 | 
				
			||||||
 | 
								if (value) {
 | 
				
			||||||
 | 
									track->setState(Webrtc::VideoState::Inactive);
 | 
				
			||||||
 | 
									bubbleWrap->resize(bubbleWrap->width(), 0);
 | 
				
			||||||
 | 
								} else {
 | 
				
			||||||
 | 
									capturer->setPreferredAspectRatio(0.);
 | 
				
			||||||
 | 
									track->setState(Webrtc::VideoState::Active);
 | 
				
			||||||
 | 
									capturer->setOutput(track->sink());
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}, content->lifetime());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		AddSkip(content);
 | 
							AddSkip(content);
 | 
				
			||||||
		AddDivider(content);
 | 
							AddDivider(content);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue