Music Hub ..
A session-wide music playback service
Loading...
Searching...
No Matches
engine.cpp
Go to the documentation of this file.
1/*
2 * Copyright © 2013-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 * Jim Hodapp <jim.hodapp@canonical.com>
21 */
22
23#include "engine.h"
24
25#include <QSize>
26
27#include <exception>
28#include <stdexcept>
29
31
32using namespace media;
33
34namespace lomiri {
35namespace MediaHubService {
36
38{
39 Q_DECLARE_PUBLIC(Engine)
40
41public:
43
44private:
45 QSharedPointer<Engine::MetaDataExtractor> m_metadataExtractor;
46 Engine::State m_state;
47 bool m_isVideoSource;
48 bool m_isAudioSource;
49 Player::AudioStreamRole m_audioStreamRole;
50 Player::Lifetime m_lifetime;
51 Player::Orientation m_orientation;
52 double m_volume;
53 QPair<QUrl,Track::MetaData> m_trackMetadata;
54 Player::PlaybackStatus m_playbackStatus;
55 QSize m_videoDimension;
56 Engine *q_ptr;
57};
58
59}} // namespace
60
62 m_state(Engine::State::no_media),
63 m_isVideoSource(false),
64 m_isAudioSource(false),
65 m_audioStreamRole(Player::AudioStreamRole::multimedia),
66 m_lifetime(Player::Lifetime::normal),
67 m_orientation(Player::Orientation::rotate0),
68 m_volume(1.0),
69 q_ptr(q)
70{
71}
72
74 QObject(parent),
75 d_ptr(new EnginePrivate(this))
76{
77}
78
79Engine::~Engine() = default;
80
81void Engine::setMetadataExtractor(const QSharedPointer<MetaDataExtractor> &extractor)
82{
83 Q_D(Engine);
84 d->m_metadataExtractor = extractor;
85}
86
87const QSharedPointer<Engine::MetaDataExtractor> &Engine::metadataExtractor() const
88{
89 Q_D(const Engine);
90 return d->m_metadataExtractor;
91}
92
94{
95 Q_D(Engine);
96 if (state == d->m_state) return;
97 d->m_state = state;
98 Q_EMIT stateChanged();
99}
100
102{
103 Q_D(const Engine);
104 return d->m_state;
105}
106
108{
109 Q_D(Engine);
110 if (value == d->m_isVideoSource) return;
111 d->m_isVideoSource = value;
112 Q_EMIT isVideoSourceChanged();
113}
114
116{
117 Q_D(const Engine);
118 return d->m_isVideoSource;
119}
120
122{
123 Q_D(Engine);
124 if (value == d->m_isAudioSource) return;
125 d->m_isAudioSource = value;
126 Q_EMIT isAudioSourceChanged();
127}
128
130{
131 Q_D(const Engine);
132 return d->m_isAudioSource;
133}
134
136{
137 Q_D(Engine);
138 if (o == d->m_orientation) return;
139 d->m_orientation = o;
140 Q_EMIT orientationChanged();
141}
142
144{
145 Q_D(const Engine);
146 return d->m_orientation;
147}
148
150{
151 Q_D(Engine);
152 if (role == d->m_audioStreamRole) return;
153 d->m_audioStreamRole = role;
155}
156
158{
159 Q_D(const Engine);
160 return d->m_audioStreamRole;
161}
162
164{
165 Q_D(Engine);
166 if (lifetime == d->m_lifetime) return;
167 d->m_lifetime = lifetime;
169}
170
172{
173 Q_D(const Engine);
174 return d->m_lifetime;
175}
176
177void Engine::setTrackMetadata(const QPair<QUrl,Track::MetaData> &metadata)
178{
179 Q_D(Engine);
180 d->m_trackMetadata = metadata;
181 Q_EMIT trackMetadataChanged();
182}
183
184QPair<QUrl,Track::MetaData> Engine::trackMetadata() const
185{
186 Q_D(const Engine);
187 return d->m_trackMetadata;
188}
189
191{
192 Q_D(Engine);
193 if (status == d->m_playbackStatus) return;
194 d->m_playbackStatus = status;
195 Q_EMIT playbackStatusChanged();
196}
197
199{
200 Q_D(const Engine);
201 return d->m_playbackStatus;
202}
203
204void Engine::setVideoDimension(const QSize &size)
205{
206 Q_D(Engine);
207 if (size == d->m_videoDimension) return;
208 d->m_videoDimension = size;
209 Q_EMIT videoDimensionChanged();
210}
211
213{
214 Q_D(const Engine);
215 return d->m_videoDimension;
216}
217
219{
220 Q_D(Engine);
221 d->m_volume = qMax(qMin(volume, 1.0), 0.0);
222 doSetVolume(d->m_volume);
223}
224
225double Engine::volume() const
226{
227 Q_D(const Engine);
228 return d->m_volume;
229}
Player::Lifetime lifetime() const
Definition engine.cpp:171
void setPlaybackStatus(Player::PlaybackStatus status)
Definition engine.cpp:190
Engine(QObject *parent=nullptr)
Definition engine.cpp:73
void setState(State state)
Definition engine.cpp:93
void setVideoDimension(const QSize &size)
Definition engine.cpp:204
void setLifetime(Player::Lifetime lifetime)
Definition engine.cpp:163
QPair< QUrl, Track::MetaData > trackMetadata() const
Definition engine.cpp:184
virtual void doSetLifetime(Player::Lifetime lifetime)=0
void setIsAudioSource(bool value)
Definition engine.cpp:121
void setTrackMetadata(const QPair< QUrl, Track::MetaData > &metadata)
Definition engine.cpp:177
virtual void doSetVolume(double volume)=0
void setMetadataExtractor(const QSharedPointer< MetaDataExtractor > &extractor)
Definition engine.cpp:81
void setIsVideoSource(bool value)
Definition engine.cpp:107
virtual void doSetAudioStreamRole(Player::AudioStreamRole role)=0
const QSharedPointer< MetaDataExtractor > & metadataExtractor() const
Definition engine.cpp:87
void setAudioStreamRole(Player::AudioStreamRole role)
Definition engine.cpp:149
void setOrientation(Player::Orientation o)
Definition engine.cpp:135
Player::AudioStreamRole audioStreamRole() const
Definition engine.cpp:157
void setVolume(double volume)
Definition engine.cpp:218
Player::PlaybackStatus playbackStatus() const
Definition engine.cpp:198
Player::Orientation orientation() const
Definition engine.cpp:143