Play sounds in calls.
This commit is contained in:
parent
2e816f2a67
commit
fd24aff6b1
Binary file not shown.
|
@ -3,13 +3,20 @@
|
|||
<file alias="fonts/OpenSans-Regular.ttf">../fonts/OpenSans-Regular.ttf</file>
|
||||
<file alias="fonts/OpenSans-Bold.ttf">../fonts/OpenSans-Bold.ttf</file>
|
||||
<file alias="fonts/OpenSans-Semibold.ttf">../fonts/OpenSans-Semibold.ttf</file>
|
||||
<file alias="art/newmsg.wav">../art/newmsg.wav</file>
|
||||
<file alias="art/bg.jpg">../art/bg.jpg</file>
|
||||
<file alias="art/bg_initial.jpg">../art/bg_initial.jpg</file>
|
||||
<file alias="art/icon256.png">../art/icon256.png</file>
|
||||
<file alias="art/iconbig256.png">../art/iconbig256.png</file>
|
||||
<file alias="art/sunrise.jpg">../art/sunrise.jpg</file>
|
||||
</qresource>
|
||||
<qresource prefix="/sounds">
|
||||
<file alias="msg_incoming.mp3">../sounds/msg_incoming.mp3</file>
|
||||
<file alias="call_incoming.mp3">../sounds/call_incoming.mp3</file>
|
||||
<file alias="call_outgoing.mp3">../sounds/call_outgoing.mp3</file>
|
||||
<file alias="call_busy.mp3">../sounds/call_busy.mp3</file>
|
||||
<file alias="call_connect.mp3">../sounds/call_connect.mp3</file>
|
||||
<file alias="call_end.mp3">../sounds/call_end.mp3</file>
|
||||
</qresource>
|
||||
<qresource prefix="/qt-project.org">
|
||||
<file>qmime/freedesktop.org.xml</file>
|
||||
</qresource>
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -28,6 +28,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
|||
#include "calls/calls_instance.h"
|
||||
#include "base/openssl_help.h"
|
||||
#include "mtproto/connection.h"
|
||||
#include "media/media_audio_track.h"
|
||||
|
||||
#ifdef slots
|
||||
#undef slots
|
||||
|
@ -84,6 +85,7 @@ Call::Call(gsl::not_null<Delegate*> delegate, gsl::not_null<UserData*> user, Typ
|
|||
if (_type == Type::Outgoing) {
|
||||
setState(State::Requesting);
|
||||
}
|
||||
startWaitingTrack();
|
||||
}
|
||||
|
||||
void Call::generateModExpFirst(base::const_byte_span randomSeed) {
|
||||
|
@ -219,9 +221,17 @@ void Call::redial() {
|
|||
t_assert(_controller == nullptr);
|
||||
_type = Type::Outgoing;
|
||||
setState(State::Requesting);
|
||||
startWaitingTrack();
|
||||
_delegate->callRedial(this);
|
||||
}
|
||||
|
||||
void Call::startWaitingTrack() {
|
||||
_waitingTrack = Media::Audio::Current().createTrack();
|
||||
auto trackFileName = (_type == Type::Outgoing) ? qsl(":/sounds/call_outgoing.mp3") : qsl(":/sounds/call_incoming.mp3");
|
||||
_waitingTrack->fillFromFile(trackFileName);
|
||||
_waitingTrack->playInLoop();
|
||||
}
|
||||
|
||||
bool Call::isKeyShaForFingerprintReady() const {
|
||||
return (_keyFingerprint != 0);
|
||||
}
|
||||
|
@ -494,24 +504,41 @@ bool Call::checkCallFields(const MTPDphoneCallAccepted &call) {
|
|||
|
||||
void Call::setState(State state) {
|
||||
if (_state != state) {
|
||||
auto wasBusy = (_state == State::Busy);
|
||||
|
||||
_state = state;
|
||||
_stateChanged.notify(state, true);
|
||||
|
||||
if (true
|
||||
&& _state != State::Starting
|
||||
&& _state != State::Requesting
|
||||
&& _state != State::Waiting
|
||||
&& _state != State::WaitingIncoming
|
||||
&& _state != State::Ringing) {
|
||||
_waitingTrack.reset();
|
||||
}
|
||||
switch (_state) {
|
||||
case State::WaitingInit:
|
||||
case State::WaitingInitAck:
|
||||
case State::Established:
|
||||
_startTime = getms(true);
|
||||
break;
|
||||
case State::ExchangingKeys:
|
||||
_delegate->playSound(Delegate::Sound::Connecting);
|
||||
break;
|
||||
case State::Ended:
|
||||
if (!wasBusy) {
|
||||
_delegate->playSound(Delegate::Sound::Ended);
|
||||
}
|
||||
_delegate->callFinished(this);
|
||||
break;
|
||||
case State::Failed:
|
||||
if (!wasBusy) {
|
||||
_delegate->playSound(Delegate::Sound::Ended);
|
||||
}
|
||||
_delegate->callFailed(this);
|
||||
break;
|
||||
case State::Busy:
|
||||
destroyController();
|
||||
// TODO play sound
|
||||
_delegate->playSound(Delegate::Sound::Busy);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,12 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
|||
#include "mtproto/sender.h"
|
||||
#include "mtproto/auth_key.h"
|
||||
|
||||
namespace Media {
|
||||
namespace Audio {
|
||||
class Track;
|
||||
} // namespace Audio
|
||||
} // namespace Media
|
||||
|
||||
namespace tgvoip {
|
||||
class VoIPController;
|
||||
} // namespace tgvoip
|
||||
|
@ -46,6 +52,13 @@ public:
|
|||
virtual void callFailed(gsl::not_null<Call*> call) = 0;
|
||||
virtual void callRedial(gsl::not_null<Call*> call) = 0;
|
||||
|
||||
enum class Sound {
|
||||
Connecting,
|
||||
Busy,
|
||||
Ended,
|
||||
};
|
||||
virtual void playSound(Sound sound) = 0;
|
||||
|
||||
};
|
||||
|
||||
static constexpr auto kRandomPowerSize = 256;
|
||||
|
@ -114,6 +127,7 @@ private:
|
|||
void finish(const MTPPhoneCallDiscardReason &reason);
|
||||
void startOutgoing();
|
||||
void startIncoming();
|
||||
void startWaitingTrack();
|
||||
|
||||
void generateModExpFirst(base::const_byte_span randomSeed);
|
||||
void handleControllerStateChange(tgvoip::VoIPController *controller, int state);
|
||||
|
@ -158,6 +172,8 @@ private:
|
|||
|
||||
std::unique_ptr<tgvoip::VoIPController> _controller;
|
||||
|
||||
std::unique_ptr<Media::Audio::Track> _waitingTrack;
|
||||
|
||||
};
|
||||
|
||||
void UpdateConfig(const std::map<std::string, std::string> &data);
|
||||
|
|
|
@ -28,7 +28,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
|||
#include "boxes/confirm_box.h"
|
||||
#include "calls/calls_call.h"
|
||||
#include "calls/calls_panel.h"
|
||||
|
||||
#include "media/media_audio_track.h"
|
||||
|
||||
#include "boxes/rate_call_box.h"
|
||||
namespace Calls {
|
||||
|
@ -41,9 +41,10 @@ constexpr auto kServerConfigUpdateTimeoutMs = 24 * 3600 * TimeMs(1000);
|
|||
Instance::Instance() = default;
|
||||
|
||||
void Instance::startOutgoingCall(gsl::not_null<UserData*> user) {
|
||||
if (_currentCall) {
|
||||
finishCurrentBusyCall();
|
||||
if (_currentCall) { // Already in a call.
|
||||
_currentCallPanel->showAndActivate();
|
||||
return; // Already in a call.
|
||||
return;
|
||||
}
|
||||
if (user->callsStatus() == UserData::CallsStatus::Private) {
|
||||
// Request full user once more to refresh the setting in case it was changed.
|
||||
|
@ -68,6 +69,34 @@ void Instance::callRedial(gsl::not_null<Call*> call) {
|
|||
}
|
||||
}
|
||||
|
||||
void Instance::playSound(Sound sound) {
|
||||
switch (sound) {
|
||||
case Sound::Busy: {
|
||||
if (!_callBusyTrack) {
|
||||
_callBusyTrack = Media::Audio::Current().createTrack();
|
||||
_callBusyTrack->fillFromFile(qsl(":/sounds/call_busy.mp3"));
|
||||
}
|
||||
_callBusyTrack->playOnce();
|
||||
} break;
|
||||
|
||||
case Sound::Ended: {
|
||||
if (!_callEndedTrack) {
|
||||
_callEndedTrack = Media::Audio::Current().createTrack();
|
||||
_callEndedTrack->fillFromFile(qsl(":/sounds/call_end.mp3"));
|
||||
}
|
||||
_callEndedTrack->playOnce();
|
||||
} break;
|
||||
|
||||
case Sound::Connecting: {
|
||||
if (!_callConnectingTrack) {
|
||||
_callConnectingTrack = Media::Audio::Current().createTrack();
|
||||
_callConnectingTrack->fillFromFile(qsl(":/sounds/call_connect.mp3"));
|
||||
}
|
||||
_callConnectingTrack->playOnce();
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
void Instance::destroyCall(gsl::not_null<Call*> call) {
|
||||
if (_currentCall.get() == call) {
|
||||
_currentCallPanel.reset();
|
||||
|
@ -230,6 +259,7 @@ void Instance::handleCallUpdate(const MTPPhoneCall &call) {
|
|||
} else if (user->isSelf()) {
|
||||
LOG(("API Error: Self found in phoneCallRequested."));
|
||||
}
|
||||
finishCurrentBusyCall();
|
||||
if (_currentCall || !user || user->isSelf()) {
|
||||
request(MTPphone_DiscardCall(MTP_inputPhoneCall(phoneCall.vid, phoneCall.vaccess_hash), MTP_int(0), MTP_phoneCallDiscardReasonBusy(), MTP_long(0))).send();
|
||||
} else if (phoneCall.vdate.v + Global::CallRingTimeoutMs() / 1000 < unixtime()) {
|
||||
|
@ -243,6 +273,12 @@ void Instance::handleCallUpdate(const MTPPhoneCall &call) {
|
|||
}
|
||||
}
|
||||
|
||||
void Instance::finishCurrentBusyCall() {
|
||||
if (_currentCall && _currentCall->state() == Call::State::Busy) {
|
||||
_currentCall->hangup();
|
||||
}
|
||||
}
|
||||
|
||||
Instance::~Instance() = default;
|
||||
|
||||
Instance &Current() {
|
||||
|
|
|
@ -23,6 +23,12 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
|||
#include "mtproto/sender.h"
|
||||
#include "calls/calls_call.h"
|
||||
|
||||
namespace Media {
|
||||
namespace Audio {
|
||||
class Track;
|
||||
} // namespace Audio
|
||||
} // namespace Media
|
||||
|
||||
namespace Calls {
|
||||
|
||||
class Panel;
|
||||
|
@ -57,12 +63,15 @@ private:
|
|||
void callFinished(gsl::not_null<Call*> call) override;
|
||||
void callFailed(gsl::not_null<Call*> call) override;
|
||||
void callRedial(gsl::not_null<Call*> call) override;
|
||||
using Sound = Call::Delegate::Sound;
|
||||
void playSound(Sound sound) override;
|
||||
void createCall(gsl::not_null<UserData*> user, Call::Type type);
|
||||
void destroyCall(gsl::not_null<Call*> call);
|
||||
|
||||
void refreshDhConfig();
|
||||
void refreshServerConfig();
|
||||
|
||||
void finishCurrentBusyCall();
|
||||
void handleCallUpdate(const MTPPhoneCall &call);
|
||||
|
||||
DhConfig _dhConfig;
|
||||
|
@ -75,6 +84,10 @@ private:
|
|||
base::Observable<Call*> _currentCallChanged;
|
||||
base::Observable<FullMsgId> _newServiceMessage;
|
||||
|
||||
std::unique_ptr<Media::Audio::Track> _callConnectingTrack;
|
||||
std::unique_ptr<Media::Audio::Track> _callEndedTrack;
|
||||
std::unique_ptr<Media::Audio::Track> _callBusyTrack;
|
||||
|
||||
};
|
||||
|
||||
Instance &Current();
|
||||
|
|
|
@ -362,7 +362,7 @@ void System::ensureSoundCreated() {
|
|||
}
|
||||
|
||||
_soundTrack = Media::Audio::Current().createTrack();
|
||||
_soundTrack->fillFromFile(qsl(":/gui/art/newmsg.wav"));
|
||||
_soundTrack->fillFromFile(qsl(":/sounds/msg_incoming.mp3"));
|
||||
}
|
||||
|
||||
void System::updateAll() {
|
||||
|
|
Loading…
Reference in New Issue