Changeset View
Changeset View
Standalone View
Standalone View
tests/mediaendpointconnector.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright (C) 2018 Manuel Weichselbaumer <mincequi@web.de> | ||||
3 | * | ||||
4 | * This library is free software; you can redistribute it and/or | ||||
5 | * modify it under the terms of the GNU Lesser General Public | ||||
6 | * License as published by the Free Software Foundation; either | ||||
7 | * version 2.1 of the License, or (at your option) version 3, or any | ||||
8 | * later version accepted by the membership of KDE e.V. (or its | ||||
9 | * successor approved by the membership of KDE e.V.), which shall | ||||
10 | * act as a proxy defined in Section 6 of version 3 of the license. | ||||
11 | * | ||||
12 | * This library is distributed in the hope that it will be useful, | ||||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
15 | * Lesser General Public License for more details. | ||||
16 | * | ||||
17 | * You should have received a copy of the GNU Lesser General Public | ||||
18 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | */ | ||||
20 | | ||||
21 | #include "mediaendpointconnector.h" | ||||
22 | | ||||
23 | #include <QCoreApplication> | ||||
24 | #include <QDebug> | ||||
25 | | ||||
26 | #include "device.h" | ||||
27 | #include "initmanagerjob.h" | ||||
28 | #include "media.h" | ||||
29 | #include "mediaendpoint.h" | ||||
30 | #include "noinputnooutputagent.h" | ||||
31 | #include "services.h" | ||||
32 | | ||||
33 | using namespace BluezQt; | ||||
34 | | ||||
35 | MediaEndpointConnector::MediaEndpointConnector(Manager *manager, QObject *parent) | ||||
36 | : QObject(parent) | ||||
37 | , m_manager(manager) | ||||
38 | { | ||||
39 | NoInputNoOutputAgent *agent = new NoInputNoOutputAgent({Services::AdvancedAudioDistribution, Services::AudioVideoRemoteControl}); | ||||
40 | connect(agent, &NoInputNoOutputAgent::serviceAuthorized, this, &MediaEndpointConnector::onServiceAuthorized); | ||||
41 | manager->registerAgent(agent); | ||||
42 | manager->requestDefaultAgent(agent); | ||||
43 | | ||||
44 | MediaEndpoint *sbcSink = new MediaEndpoint({MediaEndpoint::Role::AudioSink, MediaEndpoint::Codec::Sbc}, manager); | ||||
45 | MediaEndpoint *aacSink = new MediaEndpoint({MediaEndpoint::Role::AudioSink, MediaEndpoint::Codec::Aac}, manager); | ||||
46 | connect(sbcSink, &MediaEndpoint::configurationSelected, this, &MediaEndpointConnector::onConfigurationSelected); | ||||
47 | connect(aacSink, &MediaEndpoint::configurationSelected, this, &MediaEndpointConnector::onConfigurationSelected); | ||||
48 | connect(sbcSink, &MediaEndpoint::configurationSet, this, &MediaEndpointConnector::onConfigurationSet); | ||||
49 | connect(aacSink, &MediaEndpoint::configurationSet, this, &MediaEndpointConnector::onConfigurationSet); | ||||
50 | connect(sbcSink, &MediaEndpoint::configurationCleared, this, &MediaEndpointConnector::onConfigurationCleared); | ||||
51 | connect(aacSink, &MediaEndpoint::configurationCleared, this, &MediaEndpointConnector::onConfigurationCleared); | ||||
52 | manager->media()->registerEndpoint(sbcSink); | ||||
53 | manager->media()->registerEndpoint(aacSink); | ||||
54 | } | ||||
55 | | ||||
56 | void MediaEndpointConnector::onServiceAuthorized(BluezQt::DevicePtr device, const QString &uuid, bool allowed) | ||||
57 | { | ||||
58 | qDebug() << (allowed ? "Accepted" : "Rejected") << "service:" << uuid << "from" << device->friendlyName(); | ||||
59 | } | ||||
60 | | ||||
61 | void MediaEndpointConnector::onConfigurationSelected(const QByteArray &capabilities, const QByteArray &configuration) | ||||
62 | { | ||||
63 | if (configuration.isEmpty()) { | ||||
64 | qDebug() << "No useable configuration found for capabilities:" << capabilities; | ||||
65 | } else { | ||||
66 | qDebug() << "Selected configuration:" << configuration << "for capabilities:" << capabilities; | ||||
67 | } | ||||
68 | } | ||||
69 | | ||||
70 | void MediaEndpointConnector::onConfigurationSet(const QString& transportObjectPath, const QVariantMap& properties) | ||||
71 | { | ||||
72 | qDebug() << "Set configuration for transport:" << transportObjectPath << "to:" << properties; | ||||
73 | } | ||||
74 | | ||||
75 | void MediaEndpointConnector::onConfigurationCleared(const QString& transportObjectPath) | ||||
76 | { | ||||
77 | qDebug() << "Cleared configuration for transport:" << transportObjectPath; | ||||
78 | } | ||||
79 | | ||||
80 | int main(int argc, char **argv) | ||||
81 | { | ||||
82 | QCoreApplication app(argc, argv); | ||||
83 | | ||||
84 | qDebug() << "Waiting for bluetooth audio source to connect. Ctrl + C to cancel..."; | ||||
85 | | ||||
86 | Manager *manager = new Manager(); | ||||
87 | InitManagerJob *initJob = manager->init(); | ||||
88 | initJob->exec(); | ||||
89 | if (initJob->error()) { | ||||
90 | qWarning() << "Error initializing manager:" << initJob->errorText(); | ||||
91 | return 1; | ||||
92 | } | ||||
93 | | ||||
94 | new MediaEndpointConnector(manager); | ||||
95 | | ||||
96 | return app.exec(); | ||||
97 | } |