diff options
author | Max Kellermann <max@duempel.org> | 2013-09-27 12:27:33 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2013-09-27 12:27:33 +0200 |
commit | 6765901687b1b5869e240dfa7507430ab8b6eb73 (patch) | |
tree | 4caa2e0f82fe98196684fd4da03cb0575d1d465c | |
parent | c5d05ac0cf18dbd3d04534de240c437f8b07bd28 (diff) | |
download | mpd-6765901687b1b5869e240dfa7507430ab8b6eb73.tar.gz mpd-6765901687b1b5869e240dfa7507430ab8b6eb73.tar.xz mpd-6765901687b1b5869e240dfa7507430ab8b6eb73.zip |
DecoderControl: convert "enum decoder_state" to strictly-typed enum
Diffstat (limited to '')
-rw-r--r-- | src/DecoderAPI.cxx | 16 | ||||
-rw-r--r-- | src/DecoderControl.cxx | 18 | ||||
-rw-r--r-- | src/DecoderControl.hxx | 38 | ||||
-rw-r--r-- | src/DecoderThread.cxx | 28 |
4 files changed, 53 insertions, 47 deletions
diff --git a/src/DecoderAPI.cxx b/src/DecoderAPI.cxx index 06313c909..b5f1edf76 100644 --- a/src/DecoderAPI.cxx +++ b/src/DecoderAPI.cxx @@ -47,7 +47,7 @@ decoder_initialized(struct decoder *decoder, struct decoder_control *dc = decoder->dc; struct audio_format_string af_string; - assert(dc->state == DECODE_STATE_START); + assert(dc->state == DecoderState::START); assert(dc->pipe != NULL); assert(decoder != NULL); assert(decoder->stream_tag == NULL); @@ -63,7 +63,7 @@ decoder_initialized(struct decoder *decoder, dc->total_time = total_time; dc->Lock(); - dc->state = DECODE_STATE_DECODE; + dc->state = DecoderState::DECODE; dc->client_cond.signal(); dc->Unlock(); @@ -88,7 +88,7 @@ decoder_prepare_initial_seek(struct decoder *decoder) const struct decoder_control *dc = decoder->dc; assert(dc->pipe != NULL); - if (dc->state != DECODE_STATE_DECODE) + if (dc->state != DecoderState::DECODE) /* wait until the decoder has finished initialisation (reading file headers etc.) before emitting the virtual "SEEK" command */ @@ -247,7 +247,7 @@ decoder_check_cancel_read(const struct decoder *decoder) /* ignore the SEEK command during initialization, the plugin should handle that after it has initialized successfully */ if (dc->command == DecoderCommand::SEEK && - (dc->state == DECODE_STATE_START || decoder->seeking)) + (dc->state == DecoderState::START || decoder->seeking)) return false; return true; @@ -260,8 +260,8 @@ size_t decoder_read(struct decoder *decoder, /* XXX don't allow decoder==NULL */ assert(decoder == NULL || - decoder->dc->state == DECODE_STATE_START || - decoder->dc->state == DECODE_STATE_DECODE); + decoder->dc->state == DecoderState::START || + decoder->dc->state == DecoderState::DECODE); assert(is != NULL); assert(buffer != NULL); @@ -364,7 +364,7 @@ decoder_data(struct decoder *decoder, struct decoder_control *dc = decoder->dc; DecoderCommand cmd; - assert(dc->state == DECODE_STATE_DECODE); + assert(dc->state == DecoderState::DECODE); assert(dc->pipe != NULL); assert(length % dc->in_audio_format.GetFrameSize() == 0); @@ -472,7 +472,7 @@ decoder_tag(gcc_unused struct decoder *decoder, struct input_stream *is, gcc_unused const struct decoder_control *dc = decoder->dc; DecoderCommand cmd; - assert(dc->state == DECODE_STATE_DECODE); + assert(dc->state == DecoderState::DECODE); assert(dc->pipe != NULL); /* save the tag */ diff --git a/src/DecoderControl.cxx b/src/DecoderControl.cxx index 53957195e..483d9203b 100644 --- a/src/DecoderControl.cxx +++ b/src/DecoderControl.cxx @@ -29,7 +29,7 @@ decoder_control::decoder_control() :thread(nullptr), - state(DECODE_STATE_STOP), + state(DecoderState::STOP), command(DecoderCommand::NONE), song(nullptr), replay_gain_db(0), replay_gain_prev_db(0), @@ -54,12 +54,12 @@ decoder_control::IsCurrentSong(const Song *_song) const assert(_song != NULL); switch (state) { - case DECODE_STATE_STOP: - case DECODE_STATE_ERROR: + case DecoderState::STOP: + case DecoderState::ERROR: return false; - case DECODE_STATE_START: - case DECODE_STATE_DECODE: + case DecoderState::START: + case DecoderState::DECODE: return song_equals(song, _song); } @@ -99,7 +99,7 @@ decoder_control::Stop() function (see below). */ SynchronousCommandLocked(DecoderCommand::STOP); - if (state != DECODE_STATE_STOP && state != DECODE_STATE_ERROR) + if (state != DecoderState::STOP && state != DecoderState::ERROR) SynchronousCommandLocked(DecoderCommand::STOP); Unlock(); @@ -108,11 +108,11 @@ decoder_control::Stop() bool decoder_control::Seek(double where) { - assert(state != DECODE_STATE_START); + assert(state != DecoderState::START); assert(where >= 0.0); - if (state == DECODE_STATE_STOP || - state == DECODE_STATE_ERROR || !seekable) + if (state == DecoderState::STOP || + state == DecoderState::ERROR || !seekable) return false; seek_where = where; diff --git a/src/DecoderControl.hxx b/src/DecoderControl.hxx index 8afe103c2..3885305a7 100644 --- a/src/DecoderControl.hxx +++ b/src/DecoderControl.hxx @@ -29,15 +29,21 @@ #include <glib.h> #include <assert.h> +#include <stdint.h> + +/* damn you, windows.h! */ +#ifdef ERROR +#undef ERROR +#endif struct Song; class MusicBuffer; class MusicPipe; -enum decoder_state { - DECODE_STATE_STOP = 0, - DECODE_STATE_START, - DECODE_STATE_DECODE, +enum class DecoderState : uint8_t { + STOP = 0, + START, + DECODE, /** * The last "START" command failed, because there was an I/O @@ -45,7 +51,7 @@ enum decoder_state { * This state will only come after START; once the state has * turned to DECODE, by definition no such error can occur. */ - DECODE_STATE_ERROR, + ERROR, }; struct decoder_control { @@ -71,14 +77,14 @@ struct decoder_control { */ Cond client_cond; - enum decoder_state state; + DecoderState state; DecoderCommand command; /** * The error that occurred in the decoder thread. This - * attribute is only valid if #state is #DECODE_STATE_ERROR. + * attribute is only valid if #state is #DecoderState::ERROR. * The object must be freed when this object transitions to - * any other state (usually #DECODE_STATE_START). + * any other state (usually #DecoderState::START). */ Error error; @@ -182,8 +188,8 @@ struct decoder_control { } bool IsIdle() const { - return state == DECODE_STATE_STOP || - state == DECODE_STATE_ERROR; + return state == DecoderState::STOP || + state == DecoderState::ERROR; } gcc_pure @@ -195,7 +201,7 @@ struct decoder_control { } bool IsStarting() const { - return state == DECODE_STATE_START; + return state == DecoderState::START; } gcc_pure @@ -209,7 +215,7 @@ struct decoder_control { bool HasFailed() const { assert(command == DecoderCommand::NONE); - return state == DECODE_STATE_ERROR; + return state == DecoderState::ERROR; } gcc_pure @@ -229,10 +235,10 @@ struct decoder_control { gcc_pure Error GetError() const { assert(command == DecoderCommand::NONE); - assert(state != DECODE_STATE_ERROR || error.IsDefined()); + assert(state != DecoderState::ERROR || error.IsDefined()); Error result; - if (state == DECODE_STATE_ERROR) + if (state == DecoderState::ERROR) result.Set(error); return result; } @@ -254,9 +260,9 @@ struct decoder_control { * Caller must lock the object. */ void ClearError() { - if (state == DECODE_STATE_ERROR) { + if (state == DecoderState::ERROR) { error.Clear(); - state = DECODE_STATE_STOP; + state = DecoderState::STOP; } } diff --git a/src/DecoderThread.cxx b/src/DecoderThread.cxx index 235865fd3..5d7bf3e5f 100644 --- a/src/DecoderThread.cxx +++ b/src/DecoderThread.cxx @@ -120,7 +120,7 @@ decoder_stream_decode(const struct decoder_plugin *plugin, assert(decoder->decoder_tag == NULL); assert(input_stream != NULL); assert(input_stream->ready); - assert(decoder->dc->state == DECODE_STATE_START); + assert(decoder->dc->state == DecoderState::START); g_debug("probing plugin %s", plugin->name); @@ -136,10 +136,10 @@ decoder_stream_decode(const struct decoder_plugin *plugin, decoder->dc->Lock(); - assert(decoder->dc->state == DECODE_STATE_START || - decoder->dc->state == DECODE_STATE_DECODE); + assert(decoder->dc->state == DecoderState::START || + decoder->dc->state == DecoderState::DECODE); - return decoder->dc->state != DECODE_STATE_START; + return decoder->dc->state != DecoderState::START; } static bool @@ -153,7 +153,7 @@ decoder_file_decode(const struct decoder_plugin *plugin, assert(decoder->decoder_tag == NULL); assert(path != NULL); assert(g_path_is_absolute(path)); - assert(decoder->dc->state == DECODE_STATE_START); + assert(decoder->dc->state == DecoderState::START); g_debug("probing plugin %s", plugin->name); @@ -166,10 +166,10 @@ decoder_file_decode(const struct decoder_plugin *plugin, decoder->dc->Lock(); - assert(decoder->dc->state == DECODE_STATE_START || - decoder->dc->state == DECODE_STATE_DECODE); + assert(decoder->dc->state == DecoderState::START || + decoder->dc->state == DecoderState::DECODE); - return decoder->dc->state != DECODE_STATE_START; + return decoder->dc->state != DecoderState::START; } /** @@ -380,7 +380,7 @@ decoder_run_song(struct decoder_control *dc, ? new Tag(*song->tag) : nullptr); int ret; - dc->state = DECODE_STATE_START; + dc->state = DecoderState::START; decoder_command_finished_locked(dc); @@ -398,9 +398,9 @@ decoder_run_song(struct decoder_control *dc, dc->Lock(); if (ret) - dc->state = DECODE_STATE_STOP; + dc->state = DecoderState::STOP; else { - dc->state = DECODE_STATE_ERROR; + dc->state = DecoderState::ERROR; const char *error_uri = song->uri; char *allocated = uri_remove_auth(error_uri); @@ -431,7 +431,7 @@ decoder_run(struct decoder_control *dc) uri = song->GetURI(); if (uri == NULL) { - dc->state = DECODE_STATE_ERROR; + dc->state = DecoderState::ERROR; dc->error.Set(decoder_domain, "Failed to map song"); decoder_command_finished_locked(dc); @@ -451,8 +451,8 @@ decoder_task(gpointer arg) dc->Lock(); do { - assert(dc->state == DECODE_STATE_STOP || - dc->state == DECODE_STATE_ERROR); + assert(dc->state == DecoderState::STOP || + dc->state == DecoderState::ERROR); switch (dc->command) { case DecoderCommand::START: |