aboutsummaryrefslogtreecommitdiffstats
path: root/src/DecoderAPI.cxx
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/DecoderAPI.cxx54
1 files changed, 35 insertions, 19 deletions
diff --git a/src/DecoderAPI.cxx b/src/DecoderAPI.cxx
index 4fea02bef..4c6a6f918 100644
--- a/src/DecoderAPI.cxx
+++ b/src/DecoderAPI.cxx
@@ -20,6 +20,7 @@
#include "config.h"
#include "DecoderAPI.hxx"
#include "DecoderError.hxx"
+#include "pcm/PcmConvert.hxx"
#include "AudioConfig.hxx"
#include "ReplayGainConfig.hxx"
#include "MusicChunk.hxx"
@@ -33,7 +34,6 @@
#include "Log.hxx"
#include <assert.h>
-#include <stdlib.h>
#include <string.h>
#include <math.h>
@@ -47,6 +47,7 @@ decoder_initialized(Decoder &decoder,
assert(dc.state == DecoderState::START);
assert(dc.pipe != nullptr);
+ assert(decoder.convert == nullptr);
assert(decoder.stream_tag == nullptr);
assert(decoder.decoder_tag == nullptr);
assert(!decoder.seeking);
@@ -59,19 +60,28 @@ decoder_initialized(Decoder &decoder,
dc.seekable = seekable;
dc.total_time = total_time;
- dc.Lock();
- dc.state = DecoderState::DECODE;
- dc.client_cond.signal();
- dc.Unlock();
-
FormatDebug(decoder_domain, "audio_format=%s, seekable=%s",
audio_format_to_string(dc.in_audio_format, &af_string),
seekable ? "true" : "false");
- if (dc.in_audio_format != dc.out_audio_format)
+ if (dc.in_audio_format != dc.out_audio_format) {
FormatDebug(decoder_domain, "converting to %s",
audio_format_to_string(dc.out_audio_format,
&af_string));
+
+ decoder.convert = new PcmConvert();
+
+ Error error;
+ if (!decoder.convert->Open(dc.in_audio_format,
+ dc.out_audio_format,
+ error))
+ decoder.error = std::move(error);
+ }
+
+ dc.Lock();
+ dc.state = DecoderState::DECODE;
+ dc.client_cond.signal();
+ dc.Unlock();
}
/**
@@ -129,6 +139,10 @@ gcc_pure
static DecoderCommand
decoder_get_virtual_command(Decoder &decoder)
{
+ if (decoder.error.IsDefined())
+ /* an error has occurred: stop the decoder plugin */
+ return DecoderCommand::STOP;
+
const DecoderControl &dc = decoder.dc;
assert(dc.pipe != nullptr);
@@ -312,12 +326,12 @@ do_send_tag(Decoder &decoder, const Tag &tag)
if (decoder.chunk != nullptr) {
/* there is a partial chunk - flush it, we want the
tag in a new chunk */
- decoder_flush_chunk(decoder);
+ decoder.FlushChunk();
}
assert(decoder.chunk == nullptr);
- chunk = decoder_get_chunk(decoder);
+ chunk = decoder.GetChunk();
if (chunk == nullptr) {
assert(decoder.dc.command != DecoderCommand::NONE);
return decoder.dc.command;
@@ -388,13 +402,13 @@ decoder_data(Decoder &decoder,
return cmd;
}
- if (dc.in_audio_format != dc.out_audio_format) {
+ if (decoder.convert != nullptr) {
+ assert(dc.in_audio_format != dc.out_audio_format);
+
Error error;
- data = decoder.conv_state.Convert(dc.in_audio_format,
- data, length,
- dc.out_audio_format,
- &length,
- error);
+ data = decoder.convert->Convert(data, length,
+ &length,
+ error);
if (data == nullptr) {
/* the PCM conversion has failed - stop
playback, since we have no better way to
@@ -402,13 +416,15 @@ decoder_data(Decoder &decoder,
LogError(error);
return DecoderCommand::STOP;
}
+ } else {
+ assert(dc.in_audio_format == dc.out_audio_format);
}
while (length > 0) {
struct music_chunk *chunk;
bool full;
- chunk = decoder_get_chunk(decoder);
+ chunk = decoder.GetChunk();
if (chunk == nullptr) {
assert(dc.command != DecoderCommand::NONE);
return dc.command;
@@ -421,7 +437,7 @@ decoder_data(Decoder &decoder,
kbit_rate);
if (dest.IsNull()) {
/* the chunk is full, flush it */
- decoder_flush_chunk(decoder);
+ decoder.FlushChunk();
continue;
}
@@ -440,7 +456,7 @@ decoder_data(Decoder &decoder,
full = chunk->Expand(dc.out_audio_format, nbytes);
if (full) {
/* the chunk is full, flush it */
- decoder_flush_chunk(decoder);
+ decoder.FlushChunk();
}
data = (const uint8_t *)data + nbytes;
@@ -532,7 +548,7 @@ decoder_replay_gain(Decoder &decoder,
/* flush the current chunk because the new
replay gain values affect the following
samples */
- decoder_flush_chunk(decoder);
+ decoder.FlushChunk();
}
} else
decoder.replay_gain_serial = 0;