Skip to content

Commit c33a805

Browse files
[EGD-4099] BT set stream (#846)
1 parent 7e30be0 commit c33a805

31 files changed

+217
-133
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* `[meditation]` Added gong sound on meditation intervals
88
* `[meditation]` Added basic meditation functionalities and settings
99
* `[cellular]` Handling incoming calls and sms in sleep mode
10+
* `[audio]` Added Bluetooth related APIs to AudioServiceAPI
1011

1112
### Fixed
1213

module-audio/Audio/Audio.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include "Operation/Operation.hpp"
66

77
#include <log/log.hpp>
8-
#include <Utils.hpp>
98
#include <bsp/headset/headset.hpp>
109

1110
namespace audio
@@ -19,7 +18,7 @@ namespace audio
1918
if (ret) {
2019
currentOperation = std::move(ret.value());
2120
}
22-
headphonesInserted = bsp::headset::IsInserted();
21+
lineSinkAvailable = bsp::headset::IsInserted();
2322
}
2423

2524
Position Audio::GetPosition()
@@ -42,10 +41,16 @@ namespace audio
4241
{
4342
switch (evt->getType()) {
4443
case EventType::HeadphonesPlugin:
45-
headphonesInserted = true;
44+
lineSinkAvailable = true;
4645
break;
4746
case EventType::HeadphonesUnplug:
48-
headphonesInserted = false;
47+
lineSinkAvailable = false;
48+
break;
49+
case EventType::BTHeadsetOn:
50+
lineSinkAvailable = true;
51+
break;
52+
case EventType::BTHeadsetOff:
53+
lineSinkAvailable = false;
4954
break;
5055
default:
5156
break;
@@ -103,9 +108,13 @@ namespace audio
103108
}
104109
currentOperation = std::move(ret.value());
105110

106-
if (headphonesInserted == true) {
111+
if (lineSinkAvailable) {
107112
currentOperation->SendEvent(std::make_unique<Event>(EventType::HeadphonesPlugin));
108113
}
114+
if (btSinkAvailable && btData) {
115+
currentOperation->SendEvent(std::make_unique<Event>(EventType::BTHeadsetOn));
116+
currentOperation->SetBluetoothStreamData(btData);
117+
}
109118
}
110119
else {
111120
// If creating operation failed fallback to IdleOperation which is guaranteed to work
@@ -171,4 +180,9 @@ namespace audio
171180
return SetOutputVolume(0);
172181
}
173182

183+
void Audio::SetBluetoothStreamData(std::shared_ptr<BluetoothStreamData> data)
184+
{
185+
btData = data;
186+
}
187+
174188
} // namespace audio

module-audio/Audio/Audio.hpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include <optional>
88
#include <functional>
99

10+
#include <service-bluetooth/ServiceBluetoothCommon.hpp>
11+
1012
#include "AudioCommon.hpp"
1113
#include "Operation/Operation.hpp"
1214
#include "decoder/decoder.hpp"
@@ -74,9 +76,14 @@ namespace audio
7476
return GetCurrentOperation().GetState();
7577
}
7678

77-
[[nodiscard]] inline bool GetHeadphonesInserted() const
79+
[[nodiscard]] inline bool IsLineSinkAvailable() const
80+
{
81+
return lineSinkAvailable;
82+
}
83+
84+
[[nodiscard]] inline bool IsBtSinkAvailable() const
7885
{
79-
return headphonesInserted;
86+
return lineSinkAvailable;
8087
}
8188

8289
// Operations
@@ -95,8 +102,13 @@ namespace audio
95102

96103
virtual audio::RetCode Mute();
97104

105+
virtual void SetBluetoothStreamData(std::shared_ptr<BluetoothStreamData> data);
106+
98107
private:
99-
bool headphonesInserted = false;
108+
bool lineSinkAvailable = false;
109+
bool btSinkAvailable = false;
110+
std::shared_ptr<BluetoothStreamData> btData;
111+
100112
State currentState = State::Idle;
101113
std::unique_ptr<Operation> currentOperation;
102114

module-audio/Audio/AudioCommon.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
33

44
#include "AudioCommon.hpp"
5-
#include <cmath>
65
#include <sstream>
76
#include <Utils.hpp>
87
#include "Profiles/Profile.hpp"

module-audio/Audio/AudioCommon.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
#pragma once
55

66
#include <map>
7+
#include <bsp_audio.hpp>
78

89
#include "Profiles/Profile.hpp"
9-
#include "bsp_audio.hpp"
1010

1111
namespace audio
1212
{

module-audio/Audio/Operation/IdleOperation.hpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
22
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
33

4-
#ifndef PUREPHONE_IDLEOPERATION_HPP
5-
#define PUREPHONE_IDLEOPERATION_HPP
4+
#pragma once
65

76
#include <memory>
87
#include <optional>
@@ -20,46 +19,48 @@ namespace audio
2019

2120
~IdleOperation() = default;
2221

23-
audio::RetCode Start([[maybe_unused]] audio::AsyncCallback callback, audio::Token token) override final
22+
audio::RetCode Start([[maybe_unused]] audio::AsyncCallback callback, audio::Token token) final
2423
{
2524
return audio::RetCode::Success;
2625
}
2726

28-
audio::RetCode Stop() override final
27+
audio::RetCode Stop() final
2928
{
3029
return audio::RetCode::Success;
3130
}
3231

33-
audio::RetCode Pause() override final
32+
audio::RetCode Pause() final
3433
{
3534
return audio::RetCode::Success;
3635
}
3736

38-
audio::RetCode Resume() override final
37+
audio::RetCode Resume() final
3938
{
4039
return audio::RetCode::Success;
4140
}
4241

43-
audio::RetCode SendEvent(std::shared_ptr<Event> evt) override final
42+
audio::RetCode SendEvent(std::shared_ptr<Event> evt) final
4443
{
4544
return audio::RetCode::Success;
4645
}
4746

48-
audio::RetCode SwitchProfile(const Profile::Type type) override final
47+
audio::RetCode SwitchProfile(const Profile::Type type) final
4948
{
5049
return audio::RetCode::Success;
5150
}
5251

53-
audio::RetCode SetOutputVolume(float vol) override final;
52+
audio::RetCode SetOutputVolume(float vol) final;
5453

55-
audio::RetCode SetInputGain(float gain) override final;
54+
audio::RetCode SetInputGain(float gain) final;
5655

57-
Position GetPosition() override final
56+
Position GetPosition() final
5857
{
5958
return 0.0;
6059
}
60+
61+
void SetBluetoothStreamData(std::shared_ptr<BluetoothStreamData> data) final
62+
{}
6163
};
6264

6365
} // namespace audio
6466

65-
#endif // PUREPHONE_IDLEOPERATION_HPP

module-audio/Audio/Operation/Operation.hpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
#include <optional>
88
#include <functional>
99

10-
#include "Audio/AudioCommon.hpp"
10+
#include <Audio/AudioCommon.hpp>
11+
#include <Audio/encoder/Encoder.hpp>
12+
#include <Audio/Profiles/Profile.hpp>
1113

12-
#include "Audio/encoder/Encoder.hpp"
13-
#include "Audio/Profiles/Profile.hpp"
14+
#include <service-bluetooth/ServiceBluetoothCommon.hpp>
1415

1516
namespace audio
1617
{
@@ -61,20 +62,15 @@ namespace audio
6162
std::function<uint32_t(const std::string &path, const uint32_t &defaultValue)> dbCallback = nullptr);
6263

6364
virtual audio::RetCode Start(audio::AsyncCallback callback, audio::Token token) = 0;
64-
6565
virtual audio::RetCode Stop() = 0;
66-
6766
virtual audio::RetCode Pause() = 0;
68-
6967
virtual audio::RetCode Resume() = 0;
70-
7168
virtual audio::RetCode SendEvent(std::shared_ptr<Event> evt) = 0;
72-
7369
virtual audio::RetCode SetOutputVolume(float vol) = 0;
74-
7570
virtual audio::RetCode SetInputGain(float gain) = 0;
7671

7772
virtual Position GetPosition() = 0;
73+
virtual void SetBluetoothStreamData(std::shared_ptr<BluetoothStreamData> data) = 0;
7874

7975
Volume GetOutputVolume() const
8076
{

module-audio/Audio/Operation/PlaybackOperation.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,4 +199,9 @@ namespace audio
199199
Stop();
200200
}
201201

202+
void PlaybackOperation::SetBluetoothStreamData(std::shared_ptr<BluetoothStreamData> data)
203+
{
204+
LOG_ERROR("UNIMPLEMENTED");
205+
}
206+
202207
} // namespace audio

module-audio/Audio/Operation/PlaybackOperation.hpp

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,17 @@ namespace audio
2828

2929
virtual ~PlaybackOperation();
3030

31-
audio::RetCode Start(audio::AsyncCallback callback, audio::Token token) override final;
32-
33-
audio::RetCode Stop() override final;
34-
35-
audio::RetCode Pause() override final;
36-
37-
audio::RetCode Resume() override final;
38-
39-
audio::RetCode SendEvent(std::shared_ptr<Event> evt) override final;
40-
41-
audio::RetCode SwitchProfile(const Profile::Type type) override final;
42-
43-
audio::RetCode SetOutputVolume(float vol) override final;
44-
45-
audio::RetCode SetInputGain(float gain) override final;
46-
47-
Position GetPosition() override final;
31+
audio::RetCode Start(audio::AsyncCallback callback, audio::Token token) final;
32+
audio::RetCode Stop() final;
33+
audio::RetCode Pause() final;
34+
audio::RetCode Resume() final;
35+
audio::RetCode SendEvent(std::shared_ptr<Event> evt) final;
36+
audio::RetCode SwitchProfile(const Profile::Type type) final;
37+
audio::RetCode SetOutputVolume(float vol) final;
38+
audio::RetCode SetInputGain(float gain) final;
39+
40+
Position GetPosition() final;
41+
void SetBluetoothStreamData(std::shared_ptr<BluetoothStreamData> data) final;
4842

4943
private:
5044
std::unique_ptr<decoder> dec;

module-audio/Audio/Operation/RecorderOperation.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,4 +206,9 @@ namespace audio
206206
{
207207
return enc->getCurrentPosition();
208208
}
209+
210+
void RecorderOperation::SetBluetoothStreamData(std::shared_ptr<BluetoothStreamData> data)
211+
{
212+
LOG_ERROR("UNIMPLEMENTED");
213+
}
209214
} // namespace audio

0 commit comments

Comments
 (0)