summaryrefslogtreecommitdiff
path: root/src/decoder
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2017-02-10 22:41:11 +0100
committerMax Kellermann <max@musicpd.org>2018-01-07 17:20:26 +0100
commit8649ea3d6fcbad110ecb668b8485cf4b8b45caba (patch)
tree0ad6948c8f77286aea01d524a2ca16220983139b /src/decoder
parent752ff12c37741d7b2bc52619529dabb59e91a998 (diff)
thread/Thread: use BoundMethod
Diffstat (limited to 'src/decoder')
-rw-r--r--src/decoder/DecoderControl.cxx3
-rw-r--r--src/decoder/DecoderControl.hxx3
-rw-r--r--src/decoder/DecoderThread.cxx38
3 files changed, 23 insertions, 21 deletions
diff --git a/src/decoder/DecoderControl.cxx b/src/decoder/DecoderControl.cxx
index 7a271b281..ef9b0bd5a 100644
--- a/src/decoder/DecoderControl.cxx
+++ b/src/decoder/DecoderControl.cxx
@@ -30,7 +30,8 @@
DecoderControl::DecoderControl(Mutex &_mutex, Cond &_client_cond,
const AudioFormat _configured_audio_format,
const ReplayGainConfig &_replay_gain_config)
- :mutex(_mutex), client_cond(_client_cond),
+ :thread(BIND_THIS_METHOD(RunThread)),
+ mutex(_mutex), client_cond(_client_cond),
configured_audio_format(_configured_audio_format),
replay_gain_config(_replay_gain_config) {}
diff --git a/src/decoder/DecoderControl.hxx b/src/decoder/DecoderControl.hxx
index cc858c9a5..dfd8232e6 100644
--- a/src/decoder/DecoderControl.hxx
+++ b/src/decoder/DecoderControl.hxx
@@ -415,6 +415,9 @@ public:
* mixramp_start/mixramp_end.
*/
void CycleMixRamp();
+
+private:
+ void RunThread();
};
#endif
diff --git a/src/decoder/DecoderThread.cxx b/src/decoder/DecoderThread.cxx
index 7d4a91560..50dace3cc 100644
--- a/src/decoder/DecoderThread.cxx
+++ b/src/decoder/DecoderThread.cxx
@@ -513,30 +513,28 @@ try {
dc.client_cond.signal();
}
-static void
-decoder_task(void *arg)
+void
+DecoderControl::RunThread()
{
- DecoderControl &dc = *(DecoderControl *)arg;
-
SetThreadName("decoder");
- const std::lock_guard<Mutex> protect(dc.mutex);
+ const std::lock_guard<Mutex> protect(mutex);
do {
- assert(dc.state == DecoderState::STOP ||
- dc.state == DecoderState::ERROR);
+ assert(state == DecoderState::STOP ||
+ state == DecoderState::ERROR);
- switch (dc.command) {
+ switch (command) {
case DecoderCommand::START:
- dc.CycleMixRamp();
- dc.replay_gain_prev_db = dc.replay_gain_db;
- dc.replay_gain_db = 0;
+ CycleMixRamp();
+ replay_gain_prev_db = replay_gain_db;
+ replay_gain_db = 0;
- decoder_run(dc);
+ decoder_run(*this);
- if (dc.state == DecoderState::ERROR) {
+ if (state == DecoderState::ERROR) {
try {
- std::rethrow_exception(dc.error);
+ std::rethrow_exception(error);
} catch (const std::exception &e) {
LogError(e);
} catch (...) {
@@ -552,20 +550,20 @@ decoder_task(void *arg)
/* we need to clear the pipe here; usually the
PlayerThread is responsible, but it is not
aware that the decoder has finished */
- dc.pipe->Clear(*dc.buffer);
+ pipe->Clear(*buffer);
- decoder_run(dc);
+ decoder_run(*this);
break;
case DecoderCommand::STOP:
- dc.CommandFinishedLocked();
+ CommandFinishedLocked();
break;
case DecoderCommand::NONE:
- dc.Wait();
+ Wait();
break;
}
- } while (dc.command != DecoderCommand::NONE || !dc.quit);
+ } while (command != DecoderCommand::NONE || !quit);
}
void
@@ -574,5 +572,5 @@ decoder_thread_start(DecoderControl &dc)
assert(!dc.thread.IsDefined());
dc.quit = false;
- dc.thread.Start(decoder_task, &dc);
+ dc.thread.Start();
}