Коммит a337f072 создал по автору Denis Grigorev's avatar Denis Grigorev
Просмотр файлов

[example] Add support for AudioControl interface. OMP#OS-24179

Authors:
    - Denis Grigorev
    - Konstantin Evdokimenko
владелец 21ee7bf6
......@@ -100,6 +100,33 @@ Page {
text: "Supports DTMF"
}
TextSwitch {
id: muteSwitch
text: "Mute microphone"
automaticCheck: false
checked: callManager.audioManager.mute
onClicked: callManager.audioManager.mute = !checked
}
ComboBox {
id: audioDevice
label: "Output audio device"
automaticSelection: false
menu: ContextMenu {
Repeater {
model: callManager.audioManager.devices
MenuItem {
text: modelData.name ? modelData.name : modelData.id
onClicked: callManager.audioManager.outputDeviceIndex = index
}
}
}
currentIndex: callManager.audioManager.outputDeviceIndex
}
TextField {
id: delayValue
label: "Delay before incoming call, ms"
......
......@@ -50,6 +50,7 @@ SOURCES += \
src/audiocallmanager.cpp \
src/audiocall.cpp \
src/audioinput.cpp \
src/audiomanager.cpp \
src/audiooutput.cpp \
src/urihandler.cpp \
src/urihandleradaptor.cpp \
......@@ -59,6 +60,7 @@ HEADERS += \
src/audiocallmanager.h \
src/audiocall.h \
src/audioinput.h \
src/audiomanager.h \
src/audiooutput.h \
src/urihandler.h \
src/urihandleradaptor.h
......
......@@ -28,7 +28,7 @@ class AudioCall
#ifndef STANDALONE_DTMF
Q_INTERFACES(ru::auroraos::call::DTMFInterface)
#endif
Q_PROPERTY(bool supportsDtmf READ supportsDtmf)
Q_PROPERTY(bool supportsDtmf READ supportsDtmf CONSTANT)
Q_PROPERTY(QString dtmfString READ dtmfString NOTIFY dtmfStringChanged)
Q_PROPERTY(float microphoneRms READ microphoneRms NOTIFY microphoneRmsChanged)
......
......@@ -56,7 +56,10 @@ Call *AudioCallManager::newCall(QVariantMap &properties)
QString id = QString::number(m_callId++);
return CallManager::newCall(id, properties);
// Add audio control interface.
auto call = CallManager::newCall(id, properties);
call->addInterfaces({ audioManager() });
return call;
}
Call *AudioCallManager::initiateCall(const QVariantMap &props)
......
......@@ -7,6 +7,8 @@
#include <audiocontext.h>
#include <callmanager.h>
#include "audiomanager.h"
using ru::auroraos::call::AudioContext;
using ru::auroraos::call::Call;
using ru::auroraos::call::CallManager;
......@@ -19,6 +21,7 @@ class AudioCallManager : public CallManager
Q_PROPERTY(bool holdable READ holdable WRITE setHoldable NOTIFY holdableChanged)
Q_PROPERTY(bool redialable READ redialable WRITE setRedialable NOTIFY redialableChanged)
Q_PROPERTY(AudioManager* audioManager READ audioManager CONSTANT)
public:
explicit AudioCallManager(const QString &accountId, QObject *parent = nullptr);
......@@ -34,6 +37,11 @@ public:
bool redialable() const;
void setRedialable(bool on);
AudioManager *audioManager()
{
return &m_audioManager;
}
public slots:
void openUri(const QString &uri);
......@@ -46,6 +54,7 @@ private:
private:
AudioContext m_audioContext;
AudioManager m_audioManager;
unsigned int m_callId;
bool m_holdable;
bool m_redialable;
......
#include "audiomanager.h"
#include <QDebug>
AudioManager::AudioManager(QObject *parent)
: QObject(parent)
, m_mute(false)
, m_outputDeviceIndex(-1)
{
}
bool AudioManager::mute() const
{
return m_mute;
}
void AudioManager::setMute(bool on)
{
emit RequestMute(on);
}
QVariantList AudioManager::devices() const
{
QVariantList result;
for (const auto &device : m_audioDevices)
result.append(QVariant::fromValue(device));
return result;
}
int AudioManager::outputDeviceIndex() const
{
return m_outputDeviceIndex;
}
void AudioManager::setOutputDeviceIndex(int index)
{
if (index >= 0 && index < m_audioDevices.size()) {
// An empty device id means no change.
emit RequestAudioRoute(QStringLiteral(""), m_audioDevices.at(index).id);
}
}
void AudioManager::UpdateAudioRouteState(
const QList<AudioDevice> &devices,
bool microphoneMuted,
const QString &activeInputDeviceId,
const QString &activeOutputDeviceId)
{
// Filter out input-only devices.
QList<AudioDevice> availableDevices;
for (const auto &device : devices) {
if (device.hasOutput)
availableDevices.append(device);
}
// Deselect the current device as we recreate the device list
// and the previous index is already invalid.
if (m_outputDeviceIndex >= 0) {
m_outputDeviceIndex = -1;
emit outputDeviceIndexChanged(m_outputDeviceIndex);
}
m_audioDevices = availableDevices;
emit devicesChanged(m_audioDevices);
UpdateAudioRoute(microphoneMuted, activeInputDeviceId, activeOutputDeviceId);
}
void AudioManager::UpdateAudioRoute(
bool muteMicrophone,
const QString &inputDeviceId,
const QString &outputDeviceId)
{
if (m_mute != muteMicrophone) {
m_mute = muteMicrophone;
emit muteChanged(m_mute);
}
m_inputDeviceId = inputDeviceId;
m_outputDeviceIndex = -1;
m_outputDeviceId = QString();
if (m_outputDeviceId != outputDeviceId) {
for (int i = 0; i < m_audioDevices.size(); i++) {
if (m_audioDevices.at(i).id == outputDeviceId) {
m_outputDeviceIndex = i;
m_outputDeviceId = outputDeviceId;
break;
}
}
}
emit outputDeviceIndexChanged(m_outputDeviceIndex);
}
#pragma once
#include <QObject>
#include <QVariantList>
#include <audiocontrolinterface.h>
using ru::auroraos::call::AudioDevice;
class AudioManager : public QObject, public ru::auroraos::call::AudioControlInterface
{
Q_OBJECT
Q_INTERFACES(ru::auroraos::call::AudioControlInterface)
Q_PROPERTY(bool mute READ mute WRITE setMute NOTIFY muteChanged)
Q_PROPERTY(QVariantList devices READ devices NOTIFY devicesChanged);
Q_PROPERTY(int outputDeviceIndex READ outputDeviceIndex WRITE setOutputDeviceIndex NOTIFY outputDeviceIndexChanged);
public:
explicit AudioManager(QObject *parent = nullptr);
~AudioManager() = default;
QVariantList devices() const;
bool mute() const;
void setMute(bool on);
int outputDeviceIndex() const;
void setOutputDeviceIndex(int index);
signals:
void muteChanged(bool mute);
void devicesChanged(const QList<AudioDevice> &devices);
void outputDeviceIndexChanged(int index);
private:
bool m_mute;
QList<AudioDevice> m_audioDevices;
QString m_inputDeviceId;
QString m_outputDeviceId;
int m_outputDeviceIndex;
// AudioControlInterface
signals:
void RequestMute(bool mute) override;
void RequestAudioRoute(
const QString &inputDeviceId,
const QString &outputDeviceId) override;
public slots:
void UpdateAudioRouteState(
const QList<AudioDevice> &devices,
bool microphoneMuted,
const QString &activeInputDeviceId,
const QString &activeOutputDeviceId) override;
void UpdateAudioRoute(
bool microphoneMuted,
const QString &activeInputDeviceId,
const QString &activeOutputDeviceId) override;
};
......@@ -52,9 +52,15 @@ int main(int argc, char *argv[])
qRegisterMetaType<ru::auroraos::call::Call*>("Call*");
qmlRegisterUncreatableType<ru::auroraos::call::Call>("AudioCallExample", 1, 0, "Call", QStringLiteral("Call"));
qRegisterMetaType<AudioCall*>("AudioCall*");
qmlRegisterUncreatableType<AudioCall>("AudioCallExample", 1, 0, "AudioCall", QStringLiteral("AudioCall"));
qRegisterMetaType<ru::auroraos::call::AudioDevice>("AudioDevice");
qRegisterMetaType<ru::auroraos::call::AudioDevice::Type>("AudioDeviceType");
qRegisterMetaType<ru::auroraos::call::AudioDeviceList>("AudioDeviceList");
qmlRegisterUncreatableType<ru::auroraos::call::AudioDevice>("AudioCallExample", 1, 0, "AudioDevice", QStringLiteral("AudioDevice"));
AudioCallManager callManager(QStringLiteral("account0"));
UriHandler uriHandler;
QObject::connect(&uriHandler, &UriHandler::openedUri,
......
Поддерживает Markdown
0% или .
You are about to add 0 people to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Пожалуйста, зарегистрируйтесь или чтобы прокомментировать