Fix dropping self level around mute button.

This commit is contained in:
John Preston 2021-06-14 14:57:25 +04:00
parent 68be54288c
commit 94f10ce72e

View file

@ -1614,13 +1614,19 @@ void GroupCall::addVideoOutput(
void GroupCall::setMuted(MuteState mute) { void GroupCall::setMuted(MuteState mute) {
const auto set = [=] { const auto set = [=] {
const auto wasMuted = (muted() == MuteState::Muted) const auto was = muted();
|| (muted() == MuteState::PushToTalk); const auto wasSpeaking = (was == MuteState::Active)
const auto wasRaiseHand = (muted() == MuteState::RaisedHand); || (was == MuteState::PushToTalk);
const auto wasMuted = (was == MuteState::Muted)
|| (was == MuteState::PushToTalk);
const auto wasRaiseHand = (was == MuteState::RaisedHand);
_muted = mute; _muted = mute;
const auto nowMuted = (muted() == MuteState::Muted) const auto now = muted();
|| (muted() == MuteState::PushToTalk); const auto nowSpeaking = (now == MuteState::Active)
const auto nowRaiseHand = (muted() == MuteState::RaisedHand); || (now == MuteState::PushToTalk);
const auto nowMuted = (now == MuteState::Muted)
|| (now == MuteState::PushToTalk);
const auto nowRaiseHand = (now == MuteState::RaisedHand);
if (wasMuted != nowMuted || wasRaiseHand != nowRaiseHand) { if (wasMuted != nowMuted || wasRaiseHand != nowRaiseHand) {
applyMeInCallLocally(); applyMeInCallLocally();
} }
@ -1628,6 +1634,14 @@ void GroupCall::setMuted(MuteState mute) {
toggleVideo(false); toggleVideo(false);
toggleScreenSharing(std::nullopt); toggleScreenSharing(std::nullopt);
} }
if (wasSpeaking && !nowSpeaking && _joinState.ssrc) {
_levelUpdates.fire(LevelUpdate{
.ssrc = _joinState.ssrc,
.value = 0.f,
.voice = false,
.me = true,
});
}
}; };
if (mute == MuteState::Active || mute == MuteState::PushToTalk) { if (mute == MuteState::Active || mute == MuteState::PushToTalk) {
_delegate->groupCallRequestPermissionsOrFail(crl::guard(this, set)); _delegate->groupCallRequestPermissionsOrFail(crl::guard(this, set));
@ -2203,10 +2217,8 @@ bool GroupCall::tryCreateScreencast() {
if (_screenInstance) { if (_screenInstance) {
return false; return false;
} }
//const auto &settings = Core::App().settings();
const auto weak = base::make_weak(&_screenInstanceGuard); const auto weak = base::make_weak(&_screenInstanceGuard);
//const auto myLevel = std::make_shared<tgcalls::GroupLevelValue>();
tgcalls::GroupInstanceDescriptor descriptor = { tgcalls::GroupInstanceDescriptor descriptor = {
.threads = tgcalls::StaticThreads::getThreads(), .threads = tgcalls::StaticThreads::getThreads(),
.config = tgcalls::GroupConfig{ .config = tgcalls::GroupConfig{
@ -2219,20 +2231,6 @@ bool GroupCall::tryCreateScreencast() {
.videoCapture = _screenCapture, .videoCapture = _screenCapture,
.videoContentType = tgcalls::VideoContentType::Screencast, .videoContentType = tgcalls::VideoContentType::Screencast,
}; };
// if (Logs::DebugEnabled()) {
// auto callLogFolder = cWorkingDir() + qsl("DebugLogs");
// auto callLogPath = callLogFolder + qsl("/last_group_call_log.txt");
// auto callLogNative = QDir::toNativeSeparators(callLogPath);
//#ifdef Q_OS_WIN
// descriptor.config.logPath.data = callLogNative.toStdWString();
//#else // Q_OS_WIN
// const auto callLogUtf = QFile::encodeName(callLogNative);
// descriptor.config.logPath.data.resize(callLogUtf.size());
// ranges::copy(callLogUtf, descriptor.config.logPath.data.begin());
//#endif // Q_OS_WIN
// QFile(callLogPath).remove();
// QDir().mkpath(callLogFolder);
// }
LOG(("Call Info: Creating group screen instance")); LOG(("Call Info: Creating group screen instance"));
_screenInstance = std::make_unique<tgcalls::GroupInstanceCustomImpl>( _screenInstance = std::make_unique<tgcalls::GroupInstanceCustomImpl>(
@ -2530,6 +2528,11 @@ void GroupCall::audioLevelsUpdated(const tgcalls::GroupLevelsUpdate &data) {
auto check = false; auto check = false;
auto checkNow = false; auto checkNow = false;
const auto now = crl::now(); const auto now = crl::now();
const auto meMuted = [&] {
const auto state = muted();
return (state != MuteState::Active)
&& (state != MuteState::PushToTalk);
};
for (const auto &[ssrcOrZero, value] : data.updates) { for (const auto &[ssrcOrZero, value] : data.updates) {
const auto ssrc = ssrcOrZero ? ssrcOrZero : _joinState.ssrc; const auto ssrc = ssrcOrZero ? ssrcOrZero : _joinState.ssrc;
if (!ssrc) { if (!ssrc) {
@ -2538,11 +2541,12 @@ void GroupCall::audioLevelsUpdated(const tgcalls::GroupLevelsUpdate &data) {
const auto level = value.level; const auto level = value.level;
const auto voice = value.voice; const auto voice = value.voice;
const auto me = (ssrc == _joinState.ssrc); const auto me = (ssrc == _joinState.ssrc);
const auto ignore = me && meMuted();
_levelUpdates.fire(LevelUpdate{ _levelUpdates.fire(LevelUpdate{
.ssrc = ssrc, .ssrc = ssrc,
.value = level, .value = ignore ? 0.f : level,
.voice = voice, .voice = (!ignore && voice),
.me = me .me = me,
}); });
if (level <= kSpeakLevelThreshold) { if (level <= kSpeakLevelThreshold) {
continue; continue;