1
- // Copyright (c) 2017-2024 , Mudita Sp. z.o.o. All rights reserved.
1
+ // Copyright (c) 2017-2025 , Mudita Sp. z.o.o. All rights reserved.
2
2
// For licensing, see https://github.com/mudita/MuditaOS/blob/master/LICENSE.md
3
3
4
4
#include " PlaybackOperation.hpp"
@@ -16,8 +16,8 @@ namespace audio
16
16
using namespace AudioServiceMessage ;
17
17
18
18
PlaybackOperation::PlaybackOperation (const std::string &filePath,
19
- const audio:: PlaybackType &playbackType,
20
- const audio:: PlaybackMode &playbackMode,
19
+ const PlaybackType &playbackType,
20
+ const PlaybackMode &playbackMode,
21
21
Callback callback)
22
22
: Operation(std::move(callback), playbackType), playbackMode(playbackMode), dec(nullptr )
23
23
{
@@ -27,13 +27,13 @@ namespace audio
27
27
AddProfile (Profile::Type::PlaybackLoudspeaker, playbackType, true );
28
28
29
29
endOfFileCallback = [this ]() {
30
- if (this ->playbackMode == audio:: PlaybackMode::Single) {
30
+ if (this ->playbackMode == PlaybackMode::Single) {
31
31
state = State::Idle;
32
32
const auto msg = AudioServiceMessage::EndOfFile (operationToken);
33
33
serviceCallback (&msg);
34
34
}
35
35
else {
36
- dec->setPosition (playbackStartPosition );
36
+ dec->rewind ( );
37
37
}
38
38
};
39
39
@@ -56,7 +56,7 @@ namespace audio
56
56
}
57
57
}
58
58
59
- audio:: RetCode PlaybackOperation::Start (audio:: Token token)
59
+ RetCode PlaybackOperation::Start (Token token)
60
60
{
61
61
if (state == State::Active || (state == State::Paused && outputConnection != nullptr )) {
62
62
return RetCode::InvokedInIncorrectState;
@@ -69,7 +69,7 @@ namespace audio
69
69
}
70
70
catch (std::invalid_argument &e) {
71
71
LOG_FATAL (" Cannot create audio stream: %s" , e.what ());
72
- return audio:: RetCode::Failed;
72
+ return RetCode::Failed;
73
73
}
74
74
75
75
// create audio connection
@@ -89,11 +89,11 @@ namespace audio
89
89
return GetDeviceError (ret);
90
90
}
91
91
92
- audio:: RetCode PlaybackOperation::Stop ()
92
+ RetCode PlaybackOperation::Stop ()
93
93
{
94
94
state = State::Idle;
95
95
if (!audioDevice) {
96
- return audio:: RetCode::DeviceFailure;
96
+ return RetCode::DeviceFailure;
97
97
}
98
98
99
99
// stop playback by destroying audio connection
@@ -104,20 +104,20 @@ namespace audio
104
104
return GetDeviceError (audioDevice->Stop ());
105
105
}
106
106
107
- audio:: RetCode PlaybackOperation::Pause ()
107
+ RetCode PlaybackOperation::Pause ()
108
108
{
109
109
if (state == State::Paused || state == State::Idle || outputConnection == nullptr ) {
110
110
return RetCode::InvokedInIncorrectState;
111
111
}
112
112
const auto retCode = GetDeviceError (audioDevice->Pause ());
113
- if (retCode == audio:: RetCode::Success) {
113
+ if (retCode == RetCode::Success) {
114
114
state = State::Paused;
115
115
outputConnection->disable ();
116
116
}
117
117
return retCode;
118
118
}
119
119
120
- audio:: RetCode PlaybackOperation::Resume ()
120
+ RetCode PlaybackOperation::Resume ()
121
121
{
122
122
if (state == State::Active || state == State::Idle) {
123
123
return RetCode::InvokedInIncorrectState;
@@ -132,14 +132,14 @@ namespace audio
132
132
return GetDeviceError (audioDevice->Resume ());
133
133
}
134
134
135
- audio:: RetCode PlaybackOperation::SetOutputVolume (float vol)
135
+ RetCode PlaybackOperation::SetOutputVolume (float vol)
136
136
{
137
137
currentProfile->SetOutputVolume (vol);
138
138
auto ret = audioDevice->setOutputVolume (vol);
139
139
return GetDeviceError (ret);
140
140
}
141
141
142
- audio:: RetCode PlaybackOperation::SetInputGain (float gain)
142
+ RetCode PlaybackOperation::SetInputGain (float gain)
143
143
{
144
144
currentProfile->SetInputGain (gain);
145
145
auto ret = audioDevice->setInputGain (gain);
@@ -151,22 +151,21 @@ namespace audio
151
151
return dec->getCurrentPosition ();
152
152
}
153
153
154
- audio:: RetCode PlaybackOperation::SwitchToPriorityProfile (audio:: PlaybackType playbackType)
154
+ RetCode PlaybackOperation::SwitchToPriorityProfile (PlaybackType playbackType)
155
155
{
156
156
for (const auto &p : supportedProfiles) {
157
157
const auto profileType = p.profile ->GetType ();
158
- if (profileType == audio::Profile::Type::PlaybackBluetoothA2DP &&
159
- playbackType == audio::PlaybackType::CallRingtone) {
158
+ if (profileType == Profile::Type::PlaybackBluetoothA2DP && playbackType == PlaybackType::CallRingtone) {
160
159
continue ;
161
160
}
162
161
if (p.isAvailable ) {
163
162
return SwitchProfile (profileType);
164
163
}
165
164
}
166
- return audio:: RetCode::ProfileNotSet;
165
+ return RetCode::ProfileNotSet;
167
166
}
168
167
169
- audio:: RetCode PlaybackOperation::SendEvent (std::shared_ptr<Event> evt)
168
+ RetCode PlaybackOperation::SendEvent (std::shared_ptr<Event> evt)
170
169
{
171
170
const auto isAvailable = evt->getDeviceState () == Event::DeviceState::Connected;
172
171
switch (evt->getType ()) {
@@ -185,7 +184,7 @@ namespace audio
185
184
return RetCode::Success;
186
185
}
187
186
188
- audio:: RetCode PlaybackOperation::SwitchProfile (const Profile::Type type)
187
+ RetCode PlaybackOperation::SwitchProfile (const Profile::Type type)
189
188
{
190
189
auto newProfile = GetProfile (type);
191
190
if (newProfile == nullptr ) {
@@ -199,7 +198,7 @@ namespace audio
199
198
200
199
// adjust new profile with information from file's tags
201
200
newProfile->SetSampleRate (dec->getSourceFormat ().getSampleRate ());
202
- newProfile->SetInOutFlags (static_cast <std::uint32_t >(audio:: codec::Flags::OutputStereo));
201
+ newProfile->SetInOutFlags (static_cast <std::uint32_t >(codec::Flags::OutputStereo));
203
202
204
203
// / profile change - (re)create output device; stop audio first by
205
204
// / killing audio connection
@@ -228,7 +227,7 @@ namespace audio
228
227
Start (operationToken);
229
228
}
230
229
231
- return audio:: RetCode::Success;
230
+ return RetCode::Success;
232
231
}
233
232
234
233
PlaybackOperation::~PlaybackOperation ()
0 commit comments