diff options
| author | Anton <anton@picapica.im> | 2026-08-09 08:21:47 +0400 |
|---|---|---|
| committer | Anton <anton@picapica.im> | 2026-08-09 08:21:47 +0400 |
| commit | 32b5ae5d300a6e6ee571febd121ac985758c574e (patch) | |
| tree | 271bdcd2fe3944d80a592525bd4b19e1ca9cbcb1 /pica-client/audiovideocallcontroller.cpp | |
| parent | debf41f7ee5907cbd4d75d754b18380983929d44 (diff) | |
| download | pica-pica-32b5ae5d300a6e6ee571febd121ac985758c574e.tar.gz pica-pica-32b5ae5d300a6e6ee571febd121ac985758c574e.zip | |
pica-client: add TonePlayer for classic telephony call tones
Wires ringback, busy, special-information (unreachable) and an
electromechanical-bell incoming ringtone into
AudioVideoCallController, each played on its own QThread since
TonePlayer::play() blocks. Device selection reads audio.playback_device
and audio.ring_device from Settings so it follows what's configured in
SettingsDialog.
Centralizes the FFmpeg libavdevice output driver name
(alsa/audiotoolbox/dsound) in AudioDevice::PlatformDriverName() rather
than hardcoding ALSA, so it can also back capture/playback later.
Adds toneplayer.{h,cpp} to the autotools build and adds the missing
GPL v3 header to the touched files that lacked it.
Diffstat (limited to 'pica-client/audiovideocallcontroller.cpp')
| -rw-r--r-- | pica-client/audiovideocallcontroller.cpp | 88 |
1 files changed, 87 insertions, 1 deletions
diff --git a/pica-client/audiovideocallcontroller.cpp b/pica-client/audiovideocallcontroller.cpp index 9eeb89c..65d9f3f 100644 --- a/pica-client/audiovideocallcontroller.cpp +++ b/pica-client/audiovideocallcontroller.cpp @@ -1,8 +1,26 @@ +/* + (c) Copyright 2012 - 2018 Anton Sviridenko + https://picapica.im + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, version 3. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. +*/ #include "audiovideocallcontroller.h" #include "globals.h" #include "skynet.h" +#include "settings.h" #include <QByteArray> #include <QDebug> +#include <QMetaObject> AudioVideoCallController::AudioVideoCallController(QObject *parent) : QObject(parent), callwindow(0), is_active(false) @@ -12,23 +30,86 @@ AudioVideoCallController::AudioVideoCallController(QObject *parent) connect(skynet, SIGNAL(CallAccepted(QByteArray)), this, SLOT(call_accepted(QByteArray))); connect(skynet, SIGNAL(CallRejected(QByteArray)), this, SLOT(call_rejected(QByteArray))); connect(skynet, SIGNAL(CallHungup(QByteArray)), this, SLOT(call_hungup(QByteArray))); + + // Earpiece tones (ringback/busy/unreachable) and the incoming call bell + // are played by two TonePlayer instances, each living on its own + // QThread since TonePlayer::play() blocks the calling thread for the + // duration of the tone sequence. + toneplayer = new TonePlayer(); + toneplayer->moveToThread(&toneplayer_thread); + toneplayer_thread.start(); + + ringtoneplayer = new TonePlayer(); + ringtoneplayer->moveToThread(&ringtoneplayer_thread); + ringtoneplayer_thread.start(); +} + +AudioVideoCallController::~AudioVideoCallController() +{ + stopTones(); + + toneplayer_thread.quit(); + toneplayer_thread.wait(); + delete toneplayer; + + ringtoneplayer_thread.quit(); + ringtoneplayer_thread.wait(); + delete ringtoneplayer; +} + +void AudioVideoCallController::playEarpieceTone(void (TonePlayer::*tone)()) +{ + Settings st(config_dbname); + QString dev = st.loadValue("audio.playback_device", "default").toString(); + + toneplayer->stop(); + QMetaObject::invokeMethod(toneplayer, "setDeviceName", Qt::QueuedConnection, Q_ARG(QString, dev)); + if (tone == &TonePlayer::playCallInProgress) + QMetaObject::invokeMethod(toneplayer, "playCallInProgress", Qt::QueuedConnection); + else if (tone == &TonePlayer::playUnreachable) + QMetaObject::invokeMethod(toneplayer, "playUnreachable", Qt::QueuedConnection); + else if (tone == &TonePlayer::playBusy) + QMetaObject::invokeMethod(toneplayer, "playBusy", Qt::QueuedConnection); +} + +void AudioVideoCallController::playRingTone() +{ + Settings st(config_dbname); + QString dev = st.loadValue("audio.ring_device", "default").toString(); + + ringtoneplayer->stop(); + QMetaObject::invokeMethod(ringtoneplayer, "setDeviceName", Qt::QueuedConnection, Q_ARG(QString, dev)); + QMetaObject::invokeMethod(ringtoneplayer, "playClassicRingtone", Qt::QueuedConnection); +} + +void AudioVideoCallController::stopTones() +{ + toneplayer->stop(); + ringtoneplayer->stop(); } void AudioVideoCallController::call_failed(QString reason) { qDebug() << "Call failed: " << reason << "\n"; + /* play unreachable */ + playEarpieceTone(&TonePlayer::playUnreachable); } void AudioVideoCallController::call_accepted(QByteArray peer_id) { + stopTones(); } void AudioVideoCallController::call_rejected(QByteArray peer_id) { + /* play busy tone */ + playEarpieceTone(&TonePlayer::playBusy); } void AudioVideoCallController::call_hungup(QByteArray peer_id) { + /* play busy tone */ + playEarpieceTone(&TonePlayer::playBusy); } void AudioVideoCallController::start_call(QByteArray peer_id) @@ -44,6 +125,8 @@ void AudioVideoCallController::start_call(QByteArray peer_id) connect(callwindow, SIGNAL(start_call_pressed()), this, SLOT(initiate_call())); connect(callwindow, SIGNAL(hang_call_pressed()), this, SLOT(end_call())); callwindow->show(); + /* play ringing tone */ + playEarpieceTone(&TonePlayer::playCallInProgress); } void AudioVideoCallController::call_from(QByteArray peer_id) @@ -62,7 +145,7 @@ void AudioVideoCallController::call_from(QByteArray peer_id) callwindow->show(); /* play ring tone */ - + playRingTone(); } void AudioVideoCallController::initiate_call() @@ -72,11 +155,14 @@ void AudioVideoCallController::initiate_call() void AudioVideoCallController::accept_call() { + stopTones(); skynet->AcceptCall(m_peer_id); } void AudioVideoCallController::end_call() { + stopTones(); + if (is_active) skynet->HangupCall(m_peer_id); else |
