summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2019-06-16 10:02:51 +0200
committerMax Kellermann <max@musicpd.org>2019-08-02 22:49:55 +0200
commit61a3c69a06f0ceb970326c85ab687f5e33ab7219 (patch)
treee6ee889b14839fd96d36cdff70db66e13e6429e2
parent089615a01e9f5f2384d797974d79cde2bbf5ae8a (diff)
decoder/mad: make enums strictly-typed
-rw-r--r--src/decoder/plugins/MadDecoderPlugin.cxx96
1 files changed, 48 insertions, 48 deletions
diff --git a/src/decoder/plugins/MadDecoderPlugin.cxx b/src/decoder/plugins/MadDecoderPlugin.cxx
index f8230ce69..05fef9b3c 100644
--- a/src/decoder/plugins/MadDecoderPlugin.cxx
+++ b/src/decoder/plugins/MadDecoderPlugin.cxx
@@ -45,17 +45,17 @@
static constexpr unsigned long FRAMES_CUSHION = 2000;
-enum mp3_action {
- DECODE_SKIP = -3,
- DECODE_BREAK = -2,
- DECODE_CONT = -1,
- DECODE_OK = 0
+enum class MadDecoderAction {
+ SKIP,
+ BREAK,
+ CONT,
+ OK
};
-enum muteframe {
- MUTEFRAME_NONE,
- MUTEFRAME_SKIP,
- MUTEFRAME_SEEK
+enum class MadDecoderMuteFrame {
+ NONE,
+ SKIP,
+ SEEK
};
/* the number of samples of silence the decoder inserts at start */
@@ -125,7 +125,7 @@ struct MadDecoder {
SignedSongTime total_time;
SongTime elapsed_time;
SongTime seek_time;
- enum muteframe mute_frame = MUTEFRAME_NONE;
+ MadDecoderMuteFrame mute_frame = MadDecoderMuteFrame::NONE;
long *frame_offsets = nullptr;
mad_timer_t *times = nullptr;
unsigned long highest_frame = 0;
@@ -149,8 +149,8 @@ struct MadDecoder {
bool Seek(long offset);
bool FillBuffer();
void ParseId3(size_t tagsize, Tag *tag);
- enum mp3_action DecodeNextFrameHeader(Tag *tag);
- enum mp3_action DecodeNextFrame();
+ MadDecoderAction DecodeNextFrameHeader(Tag *tag);
+ MadDecoderAction DecodeNextFrame();
gcc_pure
offset_type ThisFrameOffset() const noexcept;
@@ -360,26 +360,26 @@ id3_tag_query(const void *p0, size_t length)
}
#endif /* !ENABLE_ID3TAG */
-static enum mp3_action
+static MadDecoderAction
RecoverFrameError(struct mad_stream &stream)
{
if (MAD_RECOVERABLE(stream.error))
- return DECODE_SKIP;
+ return MadDecoderAction::SKIP;
else if (stream.error == MAD_ERROR_BUFLEN)
- return DECODE_CONT;
+ return MadDecoderAction::CONT;
FormatWarning(mad_domain,
"unrecoverable frame level error: %s",
mad_stream_errorstr(&stream));
- return DECODE_BREAK;
+ return MadDecoderAction::BREAK;
}
-enum mp3_action
+MadDecoderAction
MadDecoder::DecodeNextFrameHeader(Tag *tag)
{
if ((stream.buffer == nullptr || stream.error == MAD_ERROR_BUFLEN) &&
!FillBuffer())
- return DECODE_BREAK;
+ return MadDecoderAction::BREAK;
if (mad_header_decode(&frame.header, &stream)) {
if (stream.error == MAD_ERROR_LOSTSYNC && stream.this_frame) {
@@ -389,7 +389,7 @@ MadDecoder::DecodeNextFrameHeader(Tag *tag)
if (tagsize > 0) {
ParseId3((size_t)tagsize, tag);
- return DECODE_CONT;
+ return MadDecoderAction::CONT;
}
}
@@ -400,24 +400,24 @@ MadDecoder::DecodeNextFrameHeader(Tag *tag)
if (layer == (mad_layer)0) {
if (new_layer != MAD_LAYER_II && new_layer != MAD_LAYER_III) {
/* Only layer 2 and 3 have been tested to work */
- return DECODE_SKIP;
+ return MadDecoderAction::SKIP;
}
layer = new_layer;
} else if (new_layer != layer) {
/* Don't decode frames with a different layer than the first */
- return DECODE_SKIP;
+ return MadDecoderAction::SKIP;
}
- return DECODE_OK;
+ return MadDecoderAction::OK;
}
-enum mp3_action
+MadDecoderAction
MadDecoder::DecodeNextFrame()
{
if ((stream.buffer == nullptr || stream.error == MAD_ERROR_BUFLEN) &&
!FillBuffer())
- return DECODE_BREAK;
+ return MadDecoderAction::BREAK;
if (mad_frame_decode(&frame, &stream)) {
if (stream.error == MAD_ERROR_LOSTSYNC) {
@@ -426,14 +426,14 @@ MadDecoder::DecodeNextFrame()
stream.this_frame);
if (tagsize > 0) {
mad_stream_skip(&stream, tagsize);
- return DECODE_CONT;
+ return MadDecoderAction::CONT;
}
}
return RecoverFrameError(stream);
}
- return DECODE_OK;
+ return MadDecoderAction::OK;
}
/* xing stuff stolen from alsaplayer, and heavily modified by jat */
@@ -695,20 +695,20 @@ MadDecoder::DecodeFirstFrame(Tag *tag)
struct xing xing;
while (true) {
- enum mp3_action ret;
+ MadDecoderAction ret;
do {
ret = DecodeNextFrameHeader(tag);
- } while (ret == DECODE_CONT);
- if (ret == DECODE_BREAK)
+ } while (ret == MadDecoderAction::CONT);
+ if (ret == MadDecoderAction::BREAK)
return false;
- if (ret == DECODE_SKIP) continue;
+ if (ret == MadDecoderAction::SKIP) continue;
do {
ret = DecodeNextFrame();
- } while (ret == DECODE_CONT);
- if (ret == DECODE_BREAK)
+ } while (ret == MadDecoderAction::CONT);
+ if (ret == MadDecoderAction::BREAK)
return false;
- if (ret == DECODE_OK) break;
+ if (ret == MadDecoderAction::OK) break;
}
struct mad_bitptr ptr = stream.anc_ptr;
@@ -720,7 +720,7 @@ MadDecoder::DecodeFirstFrame(Tag *tag)
* if an xing tag exists, use that!
*/
if (parse_xing(&xing, &ptr, &bitlen)) {
- mute_frame = MUTEFRAME_SKIP;
+ mute_frame = MadDecoderMuteFrame::SKIP;
if ((xing.flags & XING_FRAMES) && xing.frames) {
mad_timer_t duration = frame.header.duration;
@@ -902,14 +902,14 @@ MadDecoder::Read()
switch (mute_frame) {
DecoderCommand cmd;
- case MUTEFRAME_SKIP:
- mute_frame = MUTEFRAME_NONE;
+ case MadDecoderMuteFrame::SKIP:
+ mute_frame = MadDecoderMuteFrame::NONE;
break;
- case MUTEFRAME_SEEK:
+ case MadDecoderMuteFrame::SEEK:
if (elapsed_time >= seek_time)
- mute_frame = MUTEFRAME_NONE;
+ mute_frame = MadDecoderMuteFrame::NONE;
break;
- case MUTEFRAME_NONE:
+ case MadDecoderMuteFrame::NONE:
cmd = SyncAndSend();
if (cmd == DecoderCommand::SEEK) {
assert(input_stream.IsSeekable());
@@ -924,7 +924,7 @@ MadDecoder::Read()
client->SeekError();
} else {
seek_time = t;
- mute_frame = MUTEFRAME_SEEK;
+ mute_frame = MadDecoderMuteFrame::SEEK;
client->CommandFinished();
}
} else if (cmd != DecoderCommand::NONE)
@@ -932,7 +932,7 @@ MadDecoder::Read()
}
while (true) {
- enum mp3_action ret;
+ MadDecoderAction ret;
do {
Tag tag;
@@ -941,21 +941,21 @@ MadDecoder::Read()
if (!tag.IsEmpty())
client->SubmitTag(input_stream,
std::move(tag));
- } while (ret == DECODE_CONT);
- if (ret == DECODE_BREAK)
+ } while (ret == MadDecoderAction::CONT);
+ if (ret == MadDecoderAction::BREAK)
return false;
- const bool skip = ret == DECODE_SKIP;
+ const bool skip = ret == MadDecoderAction::SKIP;
- if (mute_frame == MUTEFRAME_NONE) {
+ if (mute_frame == MadDecoderMuteFrame::NONE) {
do {
ret = DecodeNextFrame();
- } while (ret == DECODE_CONT);
- if (ret == DECODE_BREAK)
+ } while (ret == MadDecoderAction::CONT);
+ if (ret == MadDecoderAction::BREAK)
return false;
}
- if (!skip && ret == DECODE_OK)
+ if (!skip && ret == MadDecoderAction::OK)
return true;
}
}