Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Telegram/SourceFiles/calls/calls.style
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,7 @@ groupCallScreenShareSmall: CallButton(groupCallSettingsSmall) {
rippleAreaPosition: point(8px, 12px);
}
}

groupCallMenuToggleSmall: CallButton(groupCallSettingsSmall) {
button: IconButton(groupCallSettingsInner) {
icon: icon {{ "calls/calls_more", groupCallIconFg }};
Expand Down
80 changes: 77 additions & 3 deletions Telegram/SourceFiles/calls/calls_call.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,12 @@ rpl::producer<Webrtc::DeviceResolvedId> Call::captureMuteDeviceId() {

void Call::setMuted(bool mute) {
_muted = mute;
if (_instance) {
if (_screenWithAudio && _screenAudioControl) {
_screenAudioControl->setMicrophoneMuted(mute);
if (_instance) {
_instance->setMuteMicrophone(false);
}
} else if (_instance) {
_instance->setMuteMicrophone(mute);
}
}
Expand Down Expand Up @@ -1080,6 +1085,13 @@ void Call::createAndStartController(const MTPDphoneCall &call) {
});
};

_screenAudioControl = std::make_shared<Webrtc::MixingAudioControl>();
auto admCreator = Webrtc::AudioDeviceModuleCreator(
saveSetDeviceIdCallback);
auto audioDeviceModuleCreator = Webrtc::MixingAudioDeviceModuleCreator(
std::move(admCreator),
_screenAudioControl);

tgcalls::Descriptor descriptor = {
.version = versionString,
.config = tgcalls::Config{
Expand Down Expand Up @@ -1139,8 +1151,7 @@ void Call::createAndStartController(const MTPDphoneCall &call) {
sendSignalingData(bytes);
});
},
.createAudioDeviceModule = Webrtc::AudioDeviceModuleCreator(
saveSetDeviceIdCallback),
.createAudioDeviceModule = std::move(audioDeviceModuleCreator),
};
if (Logs::DebugEnabled()) {
const auto callLogFolder = cWorkingDir() + u"DebugLogs"_q;
Expand Down Expand Up @@ -1381,6 +1392,48 @@ void Call::setState(State state) {
// }
//}

void Call::setPlaybackVolume(int volume) {
_playbackVolume = std::clamp(volume, 0, 20000);
const auto level = _playbackMuted.current()
? 0.f
: (_playbackVolume.current() / 10000.f);
if (_instance) {
_instance->setOutputVolume(level);
}
if (_screenAudioControl) {
_screenAudioControl->setPlaybackVolume(level);
}
}

int Call::playbackVolume() const {
return _playbackVolume.current();
}

void Call::setPlaybackMuted(bool muted) {
_playbackMuted = muted;
const auto level = muted
? 0.f
: (_playbackVolume.current() / 10000.f);
if (_instance) {
_instance->setOutputVolume(level);
}
if (_screenAudioControl) {
_screenAudioControl->setPlaybackVolume(level);
}
}

bool Call::playbackMuted() const {
return _playbackMuted.current();
}

rpl::producer<int> Call::playbackVolumeValue() const {
return _playbackVolume.value();
}

rpl::producer<bool> Call::playbackMutedValue() const {
return _playbackMuted.value();
}

void Call::setAudioDuckingEnabled(bool enabled) {
if (_instance) {
_instance->setAudioOutputDuckingEnabled(enabled);
Expand All @@ -1399,6 +1452,10 @@ bool Call::isSharingScreen() const {
return _videoCaptureIsScreencast && isSharingVideo();
}

bool Call::screenSharingWithAudio() const {
return isSharingScreen() && _screenWithAudio;
}

QString Call::cameraSharingDeviceId() const {
return isSharingCamera() ? _videoCaptureDeviceId : QString();
}
Expand Down Expand Up @@ -1445,6 +1502,13 @@ void Call::toggleScreenSharing(
}
_videoCaptureDeviceId = QString();
_videoCaptureIsScreencast = false;
if (_screenWithAudio && _screenAudioControl) {
_screenAudioControl->setMicrophoneMuted(false);
_screenAudioControl->setLoopbackEnabled(false);
if (_muted.current() && _instance) {
_instance->setMuteMicrophone(true);
}
}
_screenWithAudio = false;
if (_systemAudioCapture) {
_systemAudioCapture->stop();
Expand All @@ -1459,6 +1523,15 @@ void Call::toggleScreenSharing(
_videoCaptureIsScreencast = true;
_videoCaptureDeviceId = *uniqueId;
_screenWithAudio = withAudio;
if (_screenAudioControl) {
_screenAudioControl->setLoopbackEnabled(withAudio);
if (withAudio && _muted.current()) {
_screenAudioControl->setMicrophoneMuted(true);
if (_instance) {
_instance->setMuteMicrophone(false);
}
}
}
if (_videoCapture) {
_videoCapture->switchToDevice(uniqueId->toStdString(), true);
if (_instance) {
Expand Down Expand Up @@ -1647,6 +1720,7 @@ void Call::handleControllerError(const QString &error) {
}

void Call::destroyController() {
_screenAudioControl = nullptr;
_instanceLifetime.destroy();
Core::App().mediaDevices().setCaptureMuteTracker(this, false);
if (_systemAudioCapture) {
Expand Down
17 changes: 13 additions & 4 deletions Telegram/SourceFiles/calls/calls_call.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ namespace Webrtc {
enum class VideoState;
class VideoTrack;
struct DeviceResolvedId;
class MixingAudioControl;
} // namespace Webrtc

namespace Calls {

struct StartConferenceInfo;

struct DhConfig {
Expand Down Expand Up @@ -243,22 +243,28 @@ class Call final
//void setAudioVolume(bool input, float level);
void setAudioDuckingEnabled(bool enabled);

void setPlaybackVolume(int volume);
[[nodiscard]] int playbackVolume() const;
void setPlaybackMuted(bool muted);
[[nodiscard]] bool playbackMuted() const;
[[nodiscard]] rpl::producer<int> playbackVolumeValue() const;
[[nodiscard]] rpl::producer<bool> playbackMutedValue() const;

[[nodiscard]] QString videoDeviceId() const {
return _videoCaptureDeviceId;
}

[[nodiscard]] bool isSharingVideo() const;
[[nodiscard]] bool isSharingCamera() const;
[[nodiscard]] bool isSharingScreen() const;
[[nodiscard]] bool screenSharingWithAudio() const;
[[nodiscard]] QString cameraSharingDeviceId() const;
[[nodiscard]] QString screenSharingDeviceId() const;
void toggleCameraSharing(bool enabled);
void toggleScreenSharing(
std::optional<QString> uniqueId,
bool withAudio = false);
[[nodiscard]] bool screenSharingWithAudio() const {
return _screenWithAudio;
}

[[nodiscard]] auto peekVideoCapture() const
-> std::shared_ptr<tgcalls::VideoCaptureInterface>;

Expand Down Expand Up @@ -369,11 +375,14 @@ class Call final
std::vector<not_null<PeerData*>> _conferenceParticipants;

std::unique_ptr<tgcalls::Instance> _instance;
std::shared_ptr<Webrtc::MixingAudioControl> _screenAudioControl;
std::shared_ptr<tgcalls::VideoCaptureInterface> _videoCapture;
QString _videoCaptureDeviceId;
bool _videoCaptureIsScreencast = false;
bool _screenWithAudio = false;
std::unique_ptr<Webrtc::SystemAudioCapture> _systemAudioCapture;
rpl::variable<int> _playbackVolume = 10000;
rpl::variable<bool> _playbackMuted = false;
const std::unique_ptr<Webrtc::VideoTrack> _videoIncoming;
const std::unique_ptr<Webrtc::VideoTrack> _videoOutgoing;

Expand Down
86 changes: 85 additions & 1 deletion Telegram/SourceFiles/calls/calls_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ For license and copyright information please follow this link:
*/
#include "calls/calls_panel.h"

#include "ui/widgets/checkbox.h"
#include "webrtc/webrtc_create_adm.h"

#include "boxes/peers/replace_boost_box.h" // CreateUserpicsWithMoreBadge
#include "calls/group/calls_volume_item.h"
#include "calls/group/calls_group_common.h"
#include "calls/calls_panel_background.h"
#include "data/data_photo.h"
#include "data/data_session.h"
Expand All @@ -16,7 +21,6 @@ For license and copyright information please follow this link:
#include "data/data_photo_media.h"
#include "data/data_cloud_file.h"
#include "data/data_changes.h"
#include "calls/group/calls_group_common.h"
#include "calls/group/calls_group_invite_controller.h"
#include "calls/ui/calls_device_menu.h"
#include "calls/calls_emoji_fingerprint.h"
Expand Down Expand Up @@ -382,6 +386,21 @@ void Panel::initWidget() {
) | rpl::skip(1) | rpl::on_next([=] {
updateControlsGeometry();
}, lifetime());

base::install_event_filter(widget(), widget(), [=](
not_null<QEvent*> e) {
if (e->type() == QEvent::ContextMenu) {
const auto event = static_cast<QContextMenuEvent*>(e.get());
const auto pos = event->pos();
if (_incoming
&& _incoming->widget()->isVisible()
&& incomingFrameGeometry().contains(pos)) {
showIncomingVolumeMenu(event->globalPos());
return base::EventFilterResult::Cancel;
}
}
return base::EventFilterResult::Continue;
});
}

void Panel::initControls() {
Expand Down Expand Up @@ -1056,6 +1075,71 @@ void Panel::initMediaDeviceToggles() {
_audioDeviceToggle->setAccessibleName(tr::lng_settings_call_section_output(tr::now));
}

void Panel::showIncomingVolumeMenu(QPoint globalPos) {
if (!_call || _incomingVolumeMenu) {
return;
}

_incomingVolumeMenu = base::make_unique_q<Ui::PopupMenu>(
widget(),
st::groupCallPopupMenuWithVolume);

const auto menu = _incomingVolumeMenu.get();
const auto call = _call;
const auto peer = _user;
const auto startVolume = call->playbackVolume();
const auto startMuted = call->playbackMuted();

auto stateProducer = rpl::combine(
call->playbackVolumeValue(),
call->playbackMutedValue()
) | rpl::map([peer](int volume, bool muted) {
return Group::ParticipantState{
.peer = peer,
.volume = volume,
.mutedByMe = muted,
};
});

auto volumeItem = base::make_unique_q<MenuVolumeItem>(
menu->menu(),
st::groupCallPopupVolumeMenu,
st::groupCallMenuVolumeSlider,
std::move(stateProducer),
startVolume,
Group::kMaxVolume,
startMuted,
st::groupCallMenuVolumePadding);

volumeItem->toggleMuteRequests(
) | rpl::on_next([=](bool muted) {
call->setPlaybackMuted(muted);
if (muted) {
crl::on_main(menu, [=] {
menu->hideMenu();
});
}
}, volumeItem->lifetime());

volumeItem->toggleMuteLocallyRequests(
) | rpl::on_next([=](bool muted) {
call->setPlaybackMuted(muted);
}, volumeItem->lifetime());

volumeItem->changeVolumeRequests(
) | rpl::on_next([=](int volume) {
call->setPlaybackVolume(volume);
}, volumeItem->lifetime());

volumeItem->changeVolumeLocallyRequests(
) | rpl::on_next([=](int volume) {
call->setPlaybackVolume(volume);
}, volumeItem->lifetime());

menu->addAction(std::move(volumeItem));
_incomingVolumeMenu->popup(globalPos);
}

void Panel::showDevicesMenu(
not_null<QWidget*> button,
std::vector<DeviceSelection> types) {
Expand Down
2 changes: 2 additions & 0 deletions Telegram/SourceFiles/calls/calls_panel.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ class Panel final
void showDevicesMenu(
not_null<QWidget*> button,
std::vector<DeviceSelection> types);
void showIncomingVolumeMenu(QPoint globalPos);

[[nodiscard]] QRect incomingFrameGeometry() const;
[[nodiscard]] QRect outgoingFrameGeometry() const;
Expand Down Expand Up @@ -212,6 +213,7 @@ class Panel final
bool _mouseInside = false;

base::unique_qptr<Ui::PopupMenu> _devicesMenu;
base::unique_qptr<Ui::PopupMenu> _incomingVolumeMenu;

base::Timer _updateDurationTimer;
base::Timer _updateOuterRippleTimer;
Expand Down
Loading