Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
662e4770
Commit
662e4770
authored
May 13, 2016
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
decoder/opus: throw exceptions instead of returning DecoderCommand::STOP
parent
b7b7c381
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
28 deletions
+16
-28
OpusDecoderPlugin.cxx
src/decoder/plugins/OpusDecoderPlugin.cxx
+16
-28
No files found.
src/decoder/plugins/OpusDecoderPlugin.cxx
View file @
662e4770
...
...
@@ -33,6 +33,7 @@
#include "tag/TagBuilder.hxx"
#include "input/InputStream.hxx"
#include "util/Error.hxx"
#include "util/RuntimeError.hxx"
#include "Log.hxx"
#include <opus.h>
...
...
@@ -176,10 +177,8 @@ MPDOpusDecoder::HandlePacket(const ogg_packet &packet)
if
(
packet
.
b_o_s
)
return
HandleBOS
(
packet
);
else
if
(
opus_decoder
==
nullptr
)
{
LogDebug
(
opus_domain
,
"BOS packet expected"
);
return
DecoderCommand
::
STOP
;
}
else
if
(
opus_decoder
==
nullptr
)
throw
std
::
runtime_error
(
"BOS packet expected"
);
if
(
IsOpusTags
(
packet
))
return
HandleTags
(
packet
);
...
...
@@ -243,27 +242,20 @@ MPDOpusDecoder::HandleBOS(const ogg_packet &packet)
{
assert
(
packet
.
b_o_s
);
if
(
opus_decoder
!=
nullptr
||
!
IsOpusHead
(
packet
))
{
LogDebug
(
opus_domain
,
"BOS packet must be OpusHead"
);
return
DecoderCommand
::
STOP
;
}
if
(
opus_decoder
!=
nullptr
||
!
IsOpusHead
(
packet
))
throw
std
::
runtime_error
(
"BOS packet must be OpusHead"
);
unsigned
channels
;
if
(
!
ScanOpusHeader
(
packet
.
packet
,
packet
.
bytes
,
channels
)
||
!
audio_valid_channel_count
(
channels
))
{
LogDebug
(
opus_domain
,
"Malformed BOS packet"
);
return
DecoderCommand
::
STOP
;
}
!
audio_valid_channel_count
(
channels
))
throw
std
::
runtime_error
(
"Malformed BOS packet"
);
assert
(
opus_decoder
==
nullptr
);
assert
(
IsInitialized
()
==
(
output_buffer
!=
nullptr
));
if
(
IsInitialized
()
&&
channels
!=
previous_channels
)
{
FormatWarning
(
opus_domain
,
"Next stream has different channels (%u -> %u)"
,
previous_channels
,
channels
);
return
DecoderCommand
::
STOP
;
}
if
(
IsInitialized
()
&&
channels
!=
previous_channels
)
throw
FormatRuntimeError
(
"Next stream has different channels (%u -> %u)"
,
previous_channels
,
channels
);
const
auto
opus_serialno
=
os
.
GetSerialNo
();
...
...
@@ -273,11 +265,9 @@ MPDOpusDecoder::HandleBOS(const ogg_packet &packet)
int
opus_error
;
opus_decoder
=
opus_decoder_create
(
opus_sample_rate
,
channels
,
&
opus_error
);
if
(
opus_decoder
==
nullptr
)
{
FormatError
(
opus_domain
,
"libopus error: %s"
,
opus_strerror
(
opus_error
));
return
DecoderCommand
::
STOP
;
}
if
(
opus_decoder
==
nullptr
)
throw
FormatRuntimeError
(
"libopus error: %s"
,
opus_strerror
(
opus_error
));
if
(
IsInitialized
())
{
/* decoder was already initialized by the previous
...
...
@@ -356,11 +346,9 @@ MPDOpusDecoder::HandleAudio(const ogg_packet &packet)
packet
.
bytes
,
output_buffer
,
opus_output_buffer_frames
,
0
);
if
(
nframes
<
0
)
{
FormatError
(
opus_domain
,
"libopus error: %s"
,
opus_strerror
(
nframes
));
return
DecoderCommand
::
STOP
;
}
if
(
nframes
<
0
)
throw
FormatRuntimeError
(
"libopus error: %s"
,
opus_strerror
(
nframes
));
if
(
nframes
>
0
)
{
const
size_t
nbytes
=
nframes
*
frame_size
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment