Music Hub ..
A session-wide music playback service
Loading...
Searching...
No Matches
pulse_audio_output_observer.h
Go to the documentation of this file.
1/*
2 * Copyright © 2014 Canonical Ltd.
3 * Copyright © 2022 UBports Foundation.
4 *
5 * Contact: Alberto Mardegan <mardy@users.sourceforge.net>
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License version 3,
9 * as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * Authored by: Thomas Voß <thomas.voss@canonical.com>
20 * Ricardo Mendoza <ricardo.mendoza@canonical.com>
21 */
22#ifndef LOMIRI_MEDIAHUBSERVICE_AUDIO_PULSE_AUDIO_OUTPUT_OBSERVER_H
23#define LOMIRI_MEDIAHUBSERVICE_AUDIO_PULSE_AUDIO_OUTPUT_OBSERVER_H
24
26
27#include <iosfwd>
28#include <memory>
29#include <set>
30#include <string>
31
32class QStringList;
33
34namespace lomiri
35{
36namespace MediaHubService
37{
38namespace audio
39{
40// Implements the audio::OutputObserver interface
41// relying on pulse to query the connected ports
42// of the primary card of the system.
44{
45public:
46 // Reporter is responsible for surfacing events from the implementation
47 // that help in resolving/tracking down issues. Default implementation is empty.
48 struct Reporter
49 {
50 // To save us some typing.
51 typedef std::shared_ptr<Reporter> Ptr;
52
53 // Simple type to help in reporting.
54 struct Port
55 {
56 // Returns true iff the name of both ports are equal.
57 bool operator==(const Port& rhs) const;
58 // Returns true iff the name of the ports differ.
59 bool operator<(const Port& rhs) const;
60
61 std::string name; // The name of the port.
62 std::string description; // Human-readable description of the port.
63 bool is_available; // True if the port is available.
64 bool is_monitored; // True if the port is monitored by the observer.
65 };
66
67 virtual ~Reporter();
68 // connected_to_pulse_audio is called when a connection with pulse has been established.
69 virtual void connected_to_pulse_audio();
70 // query_for_default_sink_failed is called when no default sink was returned.
71 virtual void query_for_default_sink_failed();
72 // query_for_default_sink_finished is called when the default sink query against pulse
73 // has finished, reporting the name of the sink to observers.
74 virtual void query_for_default_sink_finished(const std::string& sink_name);
75 // query_for_sink_info_finished is called when a query for information about a specific sink
76 // has finished, reporting the name, index of the sink as well as the set of ports known to the sink.
77 virtual void query_for_sink_info_finished(const std::string& name, std::uint32_t index, const std::set<Port>& known_ports);
78 // sink_event_with_index is called when something happened on a sink, reporing the index of the
79 // sink.
80 virtual void sink_event_with_index(std::uint32_t index);
81 };
82
83 // Constructs a new instance, throws:
84 // * std::runtime_error if connection to pulseaudio fails.
85 // * std::runtime_error if reporter instance is null.
86 PulseAudioOutputObserver(const QString &sink,
87 const QStringList &outputPortPatterns,
88 Reporter::Ptr reporter,
90
91 // We provide the name of the sink we are connecting to as a
92 // getable property. This is specifically meant for
93 // consumption by test code.
94 QString sink() const;
95 // The set of ports that have been identified on the configured sink.
96 // Specifically meant for consumption by test code.
97 std::set<Reporter::Port>& knownPorts() const;
98
99private:
100 struct Private;
101 std::shared_ptr<Private> d;
102};
103}
104}
105}
106
107#endif // LOMIRI_MEDIAHUBSERVICE_AUDIO_PULSE_AUDIO_OUTPUT_OBSERVER_H
PulseAudioOutputObserver(const QString &sink, const QStringList &outputPortPatterns, Reporter::Ptr reporter, OutputObserver *q)
virtual void query_for_sink_info_finished(const std::string &name, std::uint32_t index, const std::set< Port > &known_ports)