mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Don't construct Webrtc::VideoTrack only for state tracking.
This commit is contained in:
parent
4543656aa3
commit
7a0ba58ffd
2 changed files with 30 additions and 53 deletions
|
@ -520,6 +520,7 @@ GroupCall::GroupCall(
|
||||||
}
|
}
|
||||||
|
|
||||||
setupMediaDevices();
|
setupMediaDevices();
|
||||||
|
setupOutgoingVideo();
|
||||||
|
|
||||||
if (_id) {
|
if (_id) {
|
||||||
join(inputCall);
|
join(inputCall);
|
||||||
|
@ -545,8 +546,7 @@ rpl::producer<bool> GroupCall::isSharingScreenValue() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GroupCall::isScreenPaused() const {
|
bool GroupCall::isScreenPaused() const {
|
||||||
return _screenOutgoing
|
return (_screenState.current() == Webrtc::VideoState::Paused);
|
||||||
&& (_screenOutgoing->state() == Webrtc::VideoState::Paused);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string &GroupCall::screenSharingEndpoint() const {
|
const std::string &GroupCall::screenSharingEndpoint() const {
|
||||||
|
@ -562,8 +562,7 @@ rpl::producer<bool> GroupCall::isSharingCameraValue() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GroupCall::isCameraPaused() const {
|
bool GroupCall::isCameraPaused() const {
|
||||||
return _cameraOutgoing
|
return (_cameraState.current() == Webrtc::VideoState::Paused);
|
||||||
&& (_cameraOutgoing->state() == Webrtc::VideoState::Paused);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string &GroupCall::cameraSharingEndpoint() const {
|
const std::string &GroupCall::cameraSharingEndpoint() const {
|
||||||
|
@ -588,32 +587,26 @@ rpl::producer<bool> GroupCall::canManageValue() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GroupCall::toggleVideo(bool active) {
|
void GroupCall::toggleVideo(bool active) {
|
||||||
if (!_instance
|
if (!_instance || !_id) {
|
||||||
|| !_id
|
|
||||||
|| (!active && !_cameraOutgoing)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ensureOutgoingVideo();
|
_cameraState = active
|
||||||
_cameraOutgoing->setState(active
|
|
||||||
? Webrtc::VideoState::Active
|
? Webrtc::VideoState::Active
|
||||||
: Webrtc::VideoState::Inactive);
|
: Webrtc::VideoState::Inactive;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GroupCall::toggleScreenSharing(std::optional<QString> uniqueId) {
|
void GroupCall::toggleScreenSharing(std::optional<QString> uniqueId) {
|
||||||
if (!_instance
|
if (!_instance || !_id) {
|
||||||
|| !_id
|
|
||||||
|| (!uniqueId && !_screenOutgoing)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
} else if (!uniqueId) {
|
||||||
ensureOutgoingVideo();
|
_screenState = Webrtc::VideoState::Inactive;
|
||||||
if (!uniqueId) {
|
|
||||||
_screenOutgoing->setState(Webrtc::VideoState::Inactive);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const auto changed = (_screenDeviceId != *uniqueId);
|
const auto changed = (_screenDeviceId != *uniqueId);
|
||||||
|
const auto wasSharing = isSharingScreen();
|
||||||
_screenDeviceId = *uniqueId;
|
_screenDeviceId = *uniqueId;
|
||||||
_screenOutgoing->setState(Webrtc::VideoState::Active);
|
_screenState = Webrtc::VideoState::Active;
|
||||||
if (changed) {
|
if (changed && wasSharing && isSharingScreen()) {
|
||||||
_screenCapture->switchToDevice(uniqueId->toStdString());
|
_screenCapture->switchToDevice(uniqueId->toStdString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1358,7 +1351,7 @@ void GroupCall::rejoinPresentation() {
|
||||||
} else {
|
} else {
|
||||||
LOG(("Call Error: "
|
LOG(("Call Error: "
|
||||||
"Could not screen join, error: %1").arg(type));
|
"Could not screen join, error: %1").arg(type));
|
||||||
_screenOutgoing->setState(Webrtc::VideoState::Inactive);
|
_screenState = Webrtc::VideoState::Inactive;
|
||||||
_errors.fire_copy(mutedByAdmin()
|
_errors.fire_copy(mutedByAdmin()
|
||||||
? Error::MutedNoScreen
|
? Error::MutedNoScreen
|
||||||
: Error::ScreenFailed);
|
: Error::ScreenFailed);
|
||||||
|
@ -1921,9 +1914,7 @@ bool GroupCall::emitShareCameraError() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GroupCall::emitShareCameraError(Error error) {
|
void GroupCall::emitShareCameraError(Error error) {
|
||||||
if (_cameraOutgoing) {
|
_cameraState = Webrtc::VideoState::Inactive;
|
||||||
_cameraOutgoing->setState(Webrtc::VideoState::Inactive);
|
|
||||||
}
|
|
||||||
_errors.fire_copy(error);
|
_errors.fire_copy(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1943,27 +1934,14 @@ bool GroupCall::emitShareScreenError() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GroupCall::emitShareScreenError(Error error) {
|
void GroupCall::emitShareScreenError(Error error) {
|
||||||
if (_screenOutgoing) {
|
_screenState = Webrtc::VideoState::Inactive;
|
||||||
_screenOutgoing->setState(Webrtc::VideoState::Inactive);
|
|
||||||
}
|
|
||||||
_errors.fire_copy(error);
|
_errors.fire_copy(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GroupCall::ensureOutgoingVideo() {
|
void GroupCall::setupOutgoingVideo() {
|
||||||
Expects(_id != 0);
|
|
||||||
|
|
||||||
using Webrtc::VideoState;
|
using Webrtc::VideoState;
|
||||||
if (_cameraOutgoing) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_cameraOutgoing = std::make_unique<Webrtc::VideoTrack>(
|
|
||||||
VideoState::Inactive,
|
|
||||||
_requireARGB32);
|
|
||||||
_screenOutgoing = std::make_unique<Webrtc::VideoTrack>(
|
|
||||||
VideoState::Inactive,
|
|
||||||
_requireARGB32);
|
|
||||||
|
|
||||||
_cameraOutgoing->stateValue(
|
_cameraState.value(
|
||||||
) | rpl::combine_previous(
|
) | rpl::combine_previous(
|
||||||
) | rpl::start_with_next([=](VideoState previous, VideoState state) {
|
) | rpl::start_with_next([=](VideoState previous, VideoState state) {
|
||||||
const auto wasPaused = (previous == VideoState::Paused);
|
const auto wasPaused = (previous == VideoState::Paused);
|
||||||
|
@ -1988,9 +1966,6 @@ void GroupCall::ensureOutgoingVideo() {
|
||||||
_cameraInputId);
|
_cameraInputId);
|
||||||
if (!_cameraCapture) {
|
if (!_cameraCapture) {
|
||||||
return emitShareCameraError(Error::NoCamera);
|
return emitShareCameraError(Error::NoCamera);
|
||||||
_cameraOutgoing->setState(VideoState::Inactive);
|
|
||||||
_errors.fire_copy(Error::NoCamera);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
_cameraCapture->switchToDevice(_cameraInputId.toStdString());
|
_cameraCapture->switchToDevice(_cameraInputId.toStdString());
|
||||||
|
@ -2012,7 +1987,7 @@ void GroupCall::ensureOutgoingVideo() {
|
||||||
applyMeInCallLocally();
|
applyMeInCallLocally();
|
||||||
}, _lifetime);
|
}, _lifetime);
|
||||||
|
|
||||||
_screenOutgoing->stateValue(
|
_screenState.value(
|
||||||
) | rpl::combine_previous(
|
) | rpl::combine_previous(
|
||||||
) | rpl::start_with_next([=](VideoState previous, VideoState state) {
|
) | rpl::start_with_next([=](VideoState previous, VideoState state) {
|
||||||
const auto wasPaused = (previous == VideoState::Paused);
|
const auto wasPaused = (previous == VideoState::Paused);
|
||||||
|
@ -2050,14 +2025,15 @@ void GroupCall::ensureOutgoingVideo() {
|
||||||
_screenCapture->setOnPause([=](bool paused) {
|
_screenCapture->setOnPause([=](bool paused) {
|
||||||
crl::on_main(weak, [=] {
|
crl::on_main(weak, [=] {
|
||||||
if (isSharingScreen()) {
|
if (isSharingScreen()) {
|
||||||
_screenOutgoing->setState(paused
|
_screenState = paused
|
||||||
? VideoState::Paused
|
? VideoState::Paused
|
||||||
: VideoState::Active);
|
: VideoState::Active;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
_screenCapture->switchToDevice(_screenDeviceId.toStdString());
|
_screenCapture->switchToDevice(
|
||||||
|
_screenDeviceId.toStdString());
|
||||||
}
|
}
|
||||||
if (_screenInstance) {
|
if (_screenInstance) {
|
||||||
_screenInstance->setVideoCapture(_screenCapture);
|
_screenInstance->setVideoCapture(_screenCapture);
|
||||||
|
@ -2496,10 +2472,10 @@ void GroupCall::fillActiveVideoEndpoints() {
|
||||||
const auto pausedState = Webrtc::VideoState::Paused;
|
const auto pausedState = Webrtc::VideoState::Paused;
|
||||||
feedOne(
|
feedOne(
|
||||||
{ Type::Camera, _joinAs, cameraSharingEndpoint() },
|
{ Type::Camera, _joinAs, cameraSharingEndpoint() },
|
||||||
(_cameraOutgoing && _cameraOutgoing->state() == pausedState));
|
isCameraPaused());
|
||||||
feedOne(
|
feedOne(
|
||||||
{ Type::Screen, _joinAs, screenSharingEndpoint() },
|
{ Type::Screen, _joinAs, screenSharingEndpoint() },
|
||||||
(_screenOutgoing && _screenOutgoing->state() == pausedState));
|
isScreenPaused());
|
||||||
}
|
}
|
||||||
if (large && !largeFound) {
|
if (large && !largeFound) {
|
||||||
setVideoEndpointLarge({});
|
setVideoEndpointLarge({});
|
||||||
|
@ -2835,8 +2811,8 @@ void GroupCall::sendSelfUpdate(SendUpdateType type) {
|
||||||
MTP_int(100000), // volume
|
MTP_int(100000), // volume
|
||||||
MTP_bool(muted() == MuteState::RaisedHand),
|
MTP_bool(muted() == MuteState::RaisedHand),
|
||||||
MTP_bool(!isSharingCamera()),
|
MTP_bool(!isSharingCamera()),
|
||||||
MTP_bool(_cameraOutgoing->state() == Webrtc::VideoState::Paused),
|
MTP_bool(isCameraPaused()),
|
||||||
MTP_bool(_screenOutgoing->state() == Webrtc::VideoState::Paused)
|
MTP_bool(isScreenPaused())
|
||||||
)).done([=](const MTPUpdates &result) {
|
)).done([=](const MTPUpdates &result) {
|
||||||
_selfUpdateRequestId = 0;
|
_selfUpdateRequestId = 0;
|
||||||
_peer->session().api().applyUpdates(result);
|
_peer->session().api().applyUpdates(result);
|
||||||
|
|
|
@ -31,6 +31,7 @@ class GlobalShortcutValue;
|
||||||
namespace Webrtc {
|
namespace Webrtc {
|
||||||
class MediaDevices;
|
class MediaDevices;
|
||||||
class VideoTrack;
|
class VideoTrack;
|
||||||
|
enum class VideoState;
|
||||||
} // namespace Webrtc
|
} // namespace Webrtc
|
||||||
|
|
||||||
namespace Data {
|
namespace Data {
|
||||||
|
@ -527,7 +528,7 @@ private:
|
||||||
void applyOtherParticipantUpdate(const MTPDgroupCallParticipant &data);
|
void applyOtherParticipantUpdate(const MTPDgroupCallParticipant &data);
|
||||||
|
|
||||||
void setupMediaDevices();
|
void setupMediaDevices();
|
||||||
void ensureOutgoingVideo();
|
void setupOutgoingVideo();
|
||||||
void setScreenEndpoint(std::string endpoint);
|
void setScreenEndpoint(std::string endpoint);
|
||||||
void setCameraEndpoint(std::string endpoint);
|
void setCameraEndpoint(std::string endpoint);
|
||||||
void addVideoOutput(const std::string &endpoint, SinkPointer sink);
|
void addVideoOutput(const std::string &endpoint, SinkPointer sink);
|
||||||
|
@ -592,7 +593,7 @@ private:
|
||||||
std::unique_ptr<tgcalls::GroupInstanceCustomImpl> _instance;
|
std::unique_ptr<tgcalls::GroupInstanceCustomImpl> _instance;
|
||||||
base::has_weak_ptr _instanceGuard;
|
base::has_weak_ptr _instanceGuard;
|
||||||
std::shared_ptr<tgcalls::VideoCaptureInterface> _cameraCapture;
|
std::shared_ptr<tgcalls::VideoCaptureInterface> _cameraCapture;
|
||||||
std::unique_ptr<Webrtc::VideoTrack> _cameraOutgoing;
|
rpl::variable<Webrtc::VideoState> _cameraState;
|
||||||
rpl::variable<bool> _isSharingCamera = false;
|
rpl::variable<bool> _isSharingCamera = false;
|
||||||
base::flat_map<std::string, SinkPointer> _pendingVideoOutputs;
|
base::flat_map<std::string, SinkPointer> _pendingVideoOutputs;
|
||||||
|
|
||||||
|
@ -602,7 +603,7 @@ private:
|
||||||
std::unique_ptr<tgcalls::GroupInstanceCustomImpl> _screenInstance;
|
std::unique_ptr<tgcalls::GroupInstanceCustomImpl> _screenInstance;
|
||||||
base::has_weak_ptr _screenInstanceGuard;
|
base::has_weak_ptr _screenInstanceGuard;
|
||||||
std::shared_ptr<tgcalls::VideoCaptureInterface> _screenCapture;
|
std::shared_ptr<tgcalls::VideoCaptureInterface> _screenCapture;
|
||||||
std::unique_ptr<Webrtc::VideoTrack> _screenOutgoing;
|
rpl::variable<Webrtc::VideoState> _screenState;
|
||||||
rpl::variable<bool> _isSharingScreen = false;
|
rpl::variable<bool> _isSharingScreen = false;
|
||||||
QString _screenDeviceId;
|
QString _screenDeviceId;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue