decoder/Bridge: move code to DecoderControl::SetReady()

This commit is contained in:
Max Kellermann 2016-12-03 14:20:51 +01:00
parent 9fb7cc796b
commit b3723274f7
3 changed files with 36 additions and 17 deletions

View File

@ -248,27 +248,20 @@ DecoderBridge::Ready(const AudioFormat audio_format,
{
struct audio_format_string af_string;
assert(dc.state == DecoderState::START);
assert(dc.pipe != nullptr);
assert(dc.pipe->IsEmpty());
assert(convert == nullptr);
assert(stream_tag == nullptr);
assert(decoder_tag == nullptr);
assert(!seeking);
assert(audio_format.IsDefined());
assert(audio_format.IsValid());
dc.in_audio_format = audio_format;
dc.out_audio_format = audio_format;
dc.out_audio_format.ApplyMask(dc.configured_audio_format);
dc.seekable = seekable;
dc.total_time = duration;
FormatDebug(decoder_domain, "audio_format=%s, seekable=%s",
audio_format_to_string(dc.in_audio_format, &af_string),
audio_format_to_string(audio_format, &af_string),
seekable ? "true" : "false");
{
const ScopeLock protect(dc.mutex);
dc.SetReady(audio_format, seekable, duration);
}
if (dc.in_audio_format != dc.out_audio_format) {
FormatDebug(decoder_domain, "converting to %s",
audio_format_to_string(dc.out_audio_format,
@ -283,10 +276,6 @@ DecoderBridge::Ready(const AudioFormat audio_format,
error = std::current_exception();
}
}
const ScopeLock protect(dc.mutex);
dc.state = DecoderState::DECODE;
dc.client_cond.signal();
}
DecoderCommand

View File

@ -53,6 +53,27 @@ DecoderControl::WaitForDecoder()
client_is_waiting = false;
}
void
DecoderControl::SetReady(const AudioFormat audio_format,
bool _seekable, SignedSongTime _duration)
{
assert(state == DecoderState::START);
assert(pipe != nullptr);
assert(pipe->IsEmpty());
assert(audio_format.IsDefined());
assert(audio_format.IsValid());
in_audio_format = audio_format;
out_audio_format = audio_format;
out_audio_format.ApplyMask(configured_audio_format);
seekable = _seekable;
total_time = _duration;
state = DecoderState::DECODE;
client_cond.signal();
}
bool
DecoderControl::IsCurrentSong(const DetachedSong &_song) const
{

View File

@ -254,6 +254,15 @@ struct DecoderControl {
return HasFailed();
}
/**
* Transition this obejct from DecoderState::START to
* DecoderState::DECODE.
*
* Caller must lock the object.
*/
void SetReady(const AudioFormat audio_format,
bool _seekable, SignedSongTime _duration);
/**
* Checks whether an error has occurred, and if so, rethrows
* it.