decoder/opus: throw exceptions instead of returning DecoderCommand::STOP
This commit is contained in:
@@ -33,6 +33,7 @@
|
|||||||
#include "tag/TagBuilder.hxx"
|
#include "tag/TagBuilder.hxx"
|
||||||
#include "input/InputStream.hxx"
|
#include "input/InputStream.hxx"
|
||||||
#include "util/Error.hxx"
|
#include "util/Error.hxx"
|
||||||
|
#include "util/RuntimeError.hxx"
|
||||||
#include "Log.hxx"
|
#include "Log.hxx"
|
||||||
|
|
||||||
#include <opus.h>
|
#include <opus.h>
|
||||||
@@ -176,10 +177,8 @@ MPDOpusDecoder::HandlePacket(const ogg_packet &packet)
|
|||||||
|
|
||||||
if (packet.b_o_s)
|
if (packet.b_o_s)
|
||||||
return HandleBOS(packet);
|
return HandleBOS(packet);
|
||||||
else if (opus_decoder == nullptr) {
|
else if (opus_decoder == nullptr)
|
||||||
LogDebug(opus_domain, "BOS packet expected");
|
throw std::runtime_error("BOS packet expected");
|
||||||
return DecoderCommand::STOP;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (IsOpusTags(packet))
|
if (IsOpusTags(packet))
|
||||||
return HandleTags(packet);
|
return HandleTags(packet);
|
||||||
@@ -243,27 +242,20 @@ MPDOpusDecoder::HandleBOS(const ogg_packet &packet)
|
|||||||
{
|
{
|
||||||
assert(packet.b_o_s);
|
assert(packet.b_o_s);
|
||||||
|
|
||||||
if (opus_decoder != nullptr || !IsOpusHead(packet)) {
|
if (opus_decoder != nullptr || !IsOpusHead(packet))
|
||||||
LogDebug(opus_domain, "BOS packet must be OpusHead");
|
throw std::runtime_error("BOS packet must be OpusHead");
|
||||||
return DecoderCommand::STOP;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned channels;
|
unsigned channels;
|
||||||
if (!ScanOpusHeader(packet.packet, packet.bytes, channels) ||
|
if (!ScanOpusHeader(packet.packet, packet.bytes, channels) ||
|
||||||
!audio_valid_channel_count(channels)) {
|
!audio_valid_channel_count(channels))
|
||||||
LogDebug(opus_domain, "Malformed BOS packet");
|
throw std::runtime_error("Malformed BOS packet");
|
||||||
return DecoderCommand::STOP;
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(opus_decoder == nullptr);
|
assert(opus_decoder == nullptr);
|
||||||
assert(IsInitialized() == (output_buffer != nullptr));
|
assert(IsInitialized() == (output_buffer != nullptr));
|
||||||
|
|
||||||
if (IsInitialized() && channels != previous_channels) {
|
if (IsInitialized() && channels != previous_channels)
|
||||||
FormatWarning(opus_domain,
|
throw FormatRuntimeError("Next stream has different channels (%u -> %u)",
|
||||||
"Next stream has different channels (%u -> %u)",
|
previous_channels, channels);
|
||||||
previous_channels, channels);
|
|
||||||
return DecoderCommand::STOP;
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto opus_serialno = os.GetSerialNo();
|
const auto opus_serialno = os.GetSerialNo();
|
||||||
|
|
||||||
@@ -273,11 +265,9 @@ MPDOpusDecoder::HandleBOS(const ogg_packet &packet)
|
|||||||
int opus_error;
|
int opus_error;
|
||||||
opus_decoder = opus_decoder_create(opus_sample_rate, channels,
|
opus_decoder = opus_decoder_create(opus_sample_rate, channels,
|
||||||
&opus_error);
|
&opus_error);
|
||||||
if (opus_decoder == nullptr) {
|
if (opus_decoder == nullptr)
|
||||||
FormatError(opus_domain, "libopus error: %s",
|
throw FormatRuntimeError("libopus error: %s",
|
||||||
opus_strerror(opus_error));
|
opus_strerror(opus_error));
|
||||||
return DecoderCommand::STOP;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (IsInitialized()) {
|
if (IsInitialized()) {
|
||||||
/* decoder was already initialized by the previous
|
/* decoder was already initialized by the previous
|
||||||
@@ -356,11 +346,9 @@ MPDOpusDecoder::HandleAudio(const ogg_packet &packet)
|
|||||||
packet.bytes,
|
packet.bytes,
|
||||||
output_buffer, opus_output_buffer_frames,
|
output_buffer, opus_output_buffer_frames,
|
||||||
0);
|
0);
|
||||||
if (nframes < 0) {
|
if (nframes < 0)
|
||||||
FormatError(opus_domain, "libopus error: %s",
|
throw FormatRuntimeError("libopus error: %s",
|
||||||
opus_strerror(nframes));
|
opus_strerror(nframes));
|
||||||
return DecoderCommand::STOP;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nframes > 0) {
|
if (nframes > 0) {
|
||||||
const size_t nbytes = nframes * frame_size;
|
const size_t nbytes = nframes * frame_size;
|
||||||
|
Reference in New Issue
Block a user