Skip to content

Commit 848668c

Browse files
authored
[EGD-4003] audio: fix workers destroying (#806)
Improve workers destroying by replacing sudden death with a gentle close request. Make (De)Init static - when creating second instance of a codec there was a situation when destructing one instance was causing first one to stop working, because they share common hardware resources.
1 parent e799186 commit 848668c

File tree

11 files changed

+340
-340
lines changed

11 files changed

+340
-340
lines changed

changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
* `[audio]` Fix headphones autodetection.
1414
* `[audio]` Cumulative set of minor fixes and improvements
1515

16+
### Other
17+
18+
* `[audio]` Improve synchronization when switching operations.
19+
1620
## [0.42.2 2020-10-16]
1721

1822
### Added

module-audio/Audio/Audio.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ namespace audio
117117

118118
audio::RetCode Audio::Start()
119119
{
120+
currentOperation->Stop();
120121
return Start(currentOperation->GetOperationType(),
121122
currentOperation->GetToken(),
122123
currentOperation->GetFilePath().c_str(),

module-audio/Audio/Operation/PlaybackOperation.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ namespace audio
2222
std::function<uint32_t(const std::string &path, const uint32_t &defaultValue)> dbCallback)
2323
: Operation(false, playbackType), dec(nullptr)
2424
{
25-
2625
audioCallback = [this](const void *inputBuffer, void *outputBuffer, unsigned long framesPerBuffer) -> int32_t {
2726

2827
#if PERF_STATS_ON == 1
@@ -73,7 +72,6 @@ namespace audio
7372

7473
audio::RetCode PlaybackOperation::Start(audio::AsyncCallback callback, audio::Token token)
7574
{
76-
7775
if (state == State::Active || state == State::Paused) {
7876
return RetCode::InvokedInIncorrectState;
7977
}
@@ -98,9 +96,6 @@ namespace audio
9896

9997
audio::RetCode PlaybackOperation::Stop()
10098
{
101-
if (state == State::Idle) {
102-
return RetCode::InvokedInIncorrectState;
103-
}
10499
state = State::Idle;
105100
return GetDeviceError(audioDevice->Stop());
106101
}
@@ -122,7 +117,7 @@ namespace audio
122117
if (state == State::Active || state == State::Idle) {
123118
return RetCode::InvokedInIncorrectState;
124119
}
125-
state = State::Active;
120+
state = State::Active;
126121
auto ret = audioDevice->Start(currentProfile->GetAudioFormat());
127122
return GetDeviceError(ret);
128123
}
@@ -196,4 +191,9 @@ namespace audio
196191
return audio::RetCode::Success;
197192
}
198193

194+
PlaybackOperation::~PlaybackOperation()
195+
{
196+
Stop();
197+
}
198+
199199
} // namespace audio

module-audio/Audio/Operation/PlaybackOperation.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ namespace audio
2323
const audio::PlaybackType &playbackType,
2424
std::function<uint32_t(const std::string &path, const uint32_t &defaultValue)> dbCallback = nullptr);
2525

26+
virtual ~PlaybackOperation();
27+
2628
audio::RetCode Start(audio::AsyncCallback callback, audio::Token token) override final;
2729

2830
audio::RetCode Stop() override final;

0 commit comments

Comments
 (0)