mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-18 15:17:07 +02:00
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
Telegram/SourceFiles
|
@ -373,8 +373,7 @@ void Call::setupOutgoingVideo() {
|
|||
#ifndef DESKTOP_APP_DISABLE_WEBRTC_INTEGRATION
|
||||
Assert(state == Webrtc::VideoState::Active);
|
||||
if (!_videoCapture) {
|
||||
_videoCapture = tgcalls::VideoCaptureInterface::Create(
|
||||
Core::App().settings().callVideoInputDeviceId().toStdString());
|
||||
_videoCapture = _delegate->getVideoCapture();
|
||||
_videoCapture->setOutput(_videoOutgoing->sink());
|
||||
}
|
||||
if (_instance) {
|
||||
|
|
|
@ -68,7 +68,9 @@ public:
|
|||
Ended,
|
||||
};
|
||||
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;
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "mainwidget.h"
|
||||
#include "mtproto/mtproto_config.h"
|
||||
#include "boxes/rate_call_box.h"
|
||||
#include "tgcalls/VideoCaptureInterface.h"
|
||||
#include "app.h"
|
||||
|
||||
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
|
||||
|
|
|
@ -43,6 +43,7 @@ public:
|
|||
void showInfoPanel(not_null<Call*> call);
|
||||
[[nodiscard]] Call *currentCall() const;
|
||||
[[nodiscard]] rpl::producer<Call*> currentCallValue() const;
|
||||
std::shared_ptr<tgcalls::VideoCaptureInterface> getVideoCapture() override;
|
||||
|
||||
[[nodiscard]] bool isQuitPrevent();
|
||||
|
||||
|
@ -78,6 +79,7 @@ private:
|
|||
|
||||
crl::time _lastServerConfigUpdateTime = 0;
|
||||
base::weak_ptr<Main::Session> _serverConfigRequestSession;
|
||||
std::weak_ptr<tgcalls::VideoCaptureInterface> _videoCapture;
|
||||
|
||||
std::unique_ptr<Call> _currentCall;
|
||||
rpl::event_stream<Call*> _currentCallChanges;
|
||||
|
|
|
@ -99,14 +99,16 @@ void Calls::setupContent() {
|
|||
|
||||
const auto cameras = Webrtc::GetVideoInputList();
|
||||
if (!cameras.empty()) {
|
||||
auto capturerOwner = tgcalls::VideoCaptureInterface::Create(
|
||||
settings.callVideoInputDeviceId().toStdString());
|
||||
const auto hasCall = (Core::App().calls().currentCall() != nullptr);
|
||||
|
||||
auto capturerOwner = Core::App().calls().getVideoCapture();
|
||||
const auto capturer = capturerOwner.get();
|
||||
content->lifetime().add([owner = std::move(capturerOwner)]{});
|
||||
|
||||
const auto track = content->lifetime().make_state<Webrtc::VideoTrack>(
|
||||
Webrtc::VideoState::Active);
|
||||
capturer->setOutput(track->sink());
|
||||
(hasCall
|
||||
? Webrtc::VideoState::Inactive
|
||||
: Webrtc::VideoState::Active));
|
||||
|
||||
const auto currentCameraName = [&] {
|
||||
const auto i = ranges::find(
|
||||
|
@ -181,17 +183,30 @@ void Calls::setupContent() {
|
|||
track->renderNextFrame(
|
||||
) | rpl::start_with_next([=] {
|
||||
const auto size = track->frameSize();
|
||||
if (size.isEmpty()) {
|
||||
if (size.isEmpty() || Core::App().calls().currentCall()) {
|
||||
return;
|
||||
}
|
||||
const auto width = bubbleWrap->width();
|
||||
const auto use = (width - 2 * padding);
|
||||
bubbleWrap->resize(
|
||||
width,
|
||||
top + ((use * size.height()) / size.width()) + bottom);
|
||||
const auto height = std::min(
|
||||
((use * size.height()) / size.width()),
|
||||
(use * 480) / 640);
|
||||
bubbleWrap->resize(width, top + height + bottom);
|
||||
bubbleWrap->update();
|
||||
}, 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);
|
||||
AddDivider(content);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue