decoder/API: simplify the client==nullptr code path in decoder_read()

This commit is contained in:
Max Kellermann 2016-11-21 22:09:15 +01:00
parent 2718f4c333
commit 322bfbaf57

View File

@ -256,37 +256,29 @@ DecoderBridge::OpenUri(const char *uri)
}
}
/**
* Should be read operation be cancelled? That is the case when the
* player thread has sent a command such as "STOP".
*/
gcc_pure
static inline bool
decoder_check_cancel_read(const DecoderBridge *bridge)
{
return bridge != nullptr && bridge->CheckCancelRead();
}
size_t
decoder_read(DecoderClient *client,
InputStream &is,
void *buffer, size_t length)
try {
/* XXX don't allow decoder==nullptr */
auto *bridge = (DecoderBridge *)client;
assert(bridge == nullptr ||
bridge->dc.state == DecoderState::START ||
bridge->dc.state == DecoderState::DECODE);
assert(buffer != nullptr);
/* XXX don't allow client==nullptr */
if (client == nullptr)
return is.LockRead(buffer, length);
auto &bridge = *(DecoderBridge *)client;
assert(bridge.dc.state == DecoderState::START ||
bridge.dc.state == DecoderState::DECODE);
if (length == 0)
return 0;
ScopeLock lock(is.mutex);
while (true) {
if (decoder_check_cancel_read(bridge))
if (bridge.CheckCancelRead())
return 0;
if (is.IsAvailable())