diff options
33 files changed, 219 insertions, 223 deletions
diff --git a/src/DecoderAPI.cxx b/src/DecoderAPI.cxx index 71c3d0497..06313c909 100644 --- a/src/DecoderAPI.cxx +++ b/src/DecoderAPI.cxx @@ -106,7 +106,7 @@ decoder_prepare_initial_seek(struct decoder *decoder) return false; } - if (dc->command == DECODE_COMMAND_NONE) { + if (dc->command == DecoderCommand::NONE) { /* begin initial seek */ decoder->initial_seek_pending = false; @@ -129,19 +129,19 @@ decoder_prepare_initial_seek(struct decoder *decoder) * track. */ gcc_pure -static enum decoder_command +static DecoderCommand decoder_get_virtual_command(struct decoder *decoder) { const struct decoder_control *dc = decoder->dc; assert(dc->pipe != NULL); if (decoder_prepare_initial_seek(decoder)) - return DECODE_COMMAND_SEEK; + return DecoderCommand::SEEK; return dc->command; } -enum decoder_command +DecoderCommand decoder_get_command(struct decoder *decoder) { return decoder_get_virtual_command(decoder); @@ -154,9 +154,9 @@ decoder_command_finished(struct decoder *decoder) dc->Lock(); - assert(dc->command != DECODE_COMMAND_NONE || + assert(dc->command != DecoderCommand::NONE || decoder->initial_seek_running); - assert(dc->command != DECODE_COMMAND_SEEK || + assert(dc->command != DecoderCommand::SEEK || decoder->initial_seek_running || dc->seek_error || decoder->seeking); assert(dc->pipe != NULL); @@ -187,7 +187,7 @@ decoder_command_finished(struct decoder *decoder) decoder->timestamp = dc->seek_where; } - dc->command = DECODE_COMMAND_NONE; + dc->command = DecoderCommand::NONE; dc->client_cond.signal(); dc->Unlock(); } @@ -201,7 +201,7 @@ double decoder_seek_where(gcc_unused struct decoder * decoder) if (decoder->initial_seek_running) return dc->start_ms / 1000.; - assert(dc->command == DECODE_COMMAND_SEEK); + assert(dc->command == DecoderCommand::SEEK); decoder->seeking = true; @@ -221,7 +221,7 @@ void decoder_seek_error(struct decoder * decoder) return; } - assert(dc->command == DECODE_COMMAND_SEEK); + assert(dc->command == DecoderCommand::SEEK); dc->seek_error = true; decoder->seeking = false; @@ -241,12 +241,12 @@ decoder_check_cancel_read(const struct decoder *decoder) return false; const struct decoder_control *dc = decoder->dc; - if (dc->command == DECODE_COMMAND_NONE) + if (dc->command == DecoderCommand::NONE) return false; /* ignore the SEEK command during initialization, the plugin should handle that after it has initialized successfully */ - if (dc->command == DECODE_COMMAND_SEEK && + if (dc->command == DecoderCommand::SEEK && (dc->state == DECODE_STATE_START || decoder->seeking)) return false; @@ -308,7 +308,7 @@ decoder_timestamp(struct decoder *decoder, double t) * Sends a #tag as-is to the music pipe. Flushes the current chunk * (decoder.chunk) if there is one. */ -static enum decoder_command +static DecoderCommand do_send_tag(struct decoder *decoder, const Tag &tag) { struct music_chunk *chunk; @@ -324,12 +324,12 @@ do_send_tag(struct decoder *decoder, const Tag &tag) chunk = decoder_get_chunk(decoder); if (chunk == NULL) { - assert(decoder->dc->command != DECODE_COMMAND_NONE); + assert(decoder->dc->command != DecoderCommand::NONE); return decoder->dc->command; } chunk->tag = new Tag(tag); - return DECODE_COMMAND_NONE; + return DecoderCommand::NONE; } static bool @@ -355,14 +355,14 @@ update_stream_tag(struct decoder *decoder, struct input_stream *is) return true; } -enum decoder_command +DecoderCommand decoder_data(struct decoder *decoder, struct input_stream *is, const void *data, size_t length, uint16_t kbit_rate) { struct decoder_control *dc = decoder->dc; - enum decoder_command cmd; + DecoderCommand cmd; assert(dc->state == DECODE_STATE_DECODE); assert(dc->pipe != NULL); @@ -372,7 +372,7 @@ decoder_data(struct decoder *decoder, cmd = decoder_get_virtual_command(decoder); dc->Unlock(); - if (cmd == DECODE_COMMAND_STOP || cmd == DECODE_COMMAND_SEEK || + if (cmd == DecoderCommand::STOP || cmd == DecoderCommand::SEEK || length == 0) return cmd; @@ -389,7 +389,7 @@ decoder_data(struct decoder *decoder, /* send only the stream tag */ cmd = do_send_tag(decoder, *decoder->stream_tag); - if (cmd != DECODE_COMMAND_NONE) + if (cmd != DecoderCommand::NONE) return cmd; } @@ -405,7 +405,7 @@ decoder_data(struct decoder *decoder, playback, since we have no better way to bail out */ g_warning("%s", error.GetMessage()); - return DECODE_COMMAND_STOP; + return DecoderCommand::STOP; } } @@ -416,7 +416,7 @@ decoder_data(struct decoder *decoder, chunk = decoder_get_chunk(decoder); if (chunk == NULL) { - assert(dc->command != DECODE_COMMAND_NONE); + assert(dc->command != DecoderCommand::NONE); return dc->command; } @@ -459,18 +459,18 @@ decoder_data(struct decoder *decoder, decoder->timestamp >= dc->end_ms / 1000.0) /* the end of this range has been reached: stop decoding */ - return DECODE_COMMAND_STOP; + return DecoderCommand::STOP; } - return DECODE_COMMAND_NONE; + return DecoderCommand::NONE; } -enum decoder_command +DecoderCommand decoder_tag(gcc_unused struct decoder *decoder, struct input_stream *is, Tag &&tag) { gcc_unused const struct decoder_control *dc = decoder->dc; - enum decoder_command cmd; + DecoderCommand cmd; assert(dc->state == DECODE_STATE_DECODE); assert(dc->pipe != NULL); @@ -490,7 +490,7 @@ decoder_tag(gcc_unused struct decoder *decoder, struct input_stream *is, /* during initial seek, no music chunk must be created until seeking is finished; skip the rest of the function here */ - return DECODE_COMMAND_SEEK; + return DecoderCommand::SEEK; /* send tag to music pipe */ diff --git a/src/DecoderAPI.hxx b/src/DecoderAPI.hxx index ff7cdc27b..f96aa596a 100644 --- a/src/DecoderAPI.hxx +++ b/src/DecoderAPI.hxx @@ -54,10 +54,10 @@ decoder_initialized(struct decoder *decoder, * Determines the pending decoder command. * * @param decoder the decoder object - * @return the current command, or DECODE_COMMAND_NONE if there is no + * @return the current command, or DecoderCommand::NONE if there is no * command pending */ -enum decoder_command +DecoderCommand decoder_get_command(struct decoder *decoder); /** @@ -71,7 +71,7 @@ void decoder_command_finished(struct decoder *decoder); /** - * Call this when you have received the DECODE_COMMAND_SEEK command. + * Call this when you have received the DecoderCommand::SEEK command. * * @param decoder the decoder object * @return the destination position for the week @@ -120,10 +120,10 @@ decoder_timestamp(struct decoder *decoder, double t); * for the player * @param data the source buffer * @param length the number of bytes in the buffer - * @return the current command, or DECODE_COMMAND_NONE if there is no + * @return the current command, or DecoderCommand::NONE if there is no * command pending */ -enum decoder_command +DecoderCommand decoder_data(struct decoder *decoder, struct input_stream *is, const void *data, size_t length, uint16_t kbit_rate); @@ -136,10 +136,10 @@ decoder_data(struct decoder *decoder, struct input_stream *is, * @param is an input stream which is buffering while we are waiting * for the player * @param tag the tag to send - * @return the current command, or DECODE_COMMAND_NONE if there is no + * @return the current command, or DecoderCommand::NONE if there is no * command pending */ -enum decoder_command +DecoderCommand decoder_tag(struct decoder *decoder, struct input_stream *is, Tag &&tag); /** diff --git a/src/DecoderCommand.hxx b/src/DecoderCommand.hxx index e6dc26982..394f270c2 100644 --- a/src/DecoderCommand.hxx +++ b/src/DecoderCommand.hxx @@ -20,11 +20,13 @@ #ifndef MPD_DECODER_COMMAND_HXX #define MPD_DECODER_COMMAND_HXX -enum decoder_command { - DECODE_COMMAND_NONE = 0, - DECODE_COMMAND_START, - DECODE_COMMAND_STOP, - DECODE_COMMAND_SEEK +#include <stdint.h> + +enum class DecoderCommand : uint8_t { + NONE = 0, + START, + STOP, + SEEK }; #endif diff --git a/src/DecoderControl.cxx b/src/DecoderControl.cxx index 063a78644..53957195e 100644 --- a/src/DecoderControl.cxx +++ b/src/DecoderControl.cxx @@ -30,7 +30,7 @@ decoder_control::decoder_control() :thread(nullptr), state(DECODE_STATE_STOP), - command(DECODE_COMMAND_NONE), + command(DecoderCommand::NONE), song(nullptr), replay_gain_db(0), replay_gain_prev_db(0), mixramp_start(nullptr), mixramp_end(nullptr), @@ -84,7 +84,7 @@ decoder_control::Start(Song *_song, buffer = &_buffer; pipe = &_pipe; - LockSynchronousCommand(DECODE_COMMAND_START); + LockSynchronousCommand(DecoderCommand::START); } void @@ -92,15 +92,15 @@ decoder_control::Stop() { Lock(); - if (command != DECODE_COMMAND_NONE) + if (command != DecoderCommand::NONE) /* Attempt to cancel the current command. If it's too late and the decoder thread is already executing the old command, we'll call STOP again in this function (see below). */ - SynchronousCommandLocked(DECODE_COMMAND_STOP); + SynchronousCommandLocked(DecoderCommand::STOP); if (state != DECODE_STATE_STOP && state != DECODE_STATE_ERROR) - SynchronousCommandLocked(DECODE_COMMAND_STOP); + SynchronousCommandLocked(DecoderCommand::STOP); Unlock(); } @@ -117,7 +117,7 @@ decoder_control::Seek(double where) seek_where = where; seek_error = false; - SynchronousCommandLocked(DECODE_COMMAND_SEEK); + SynchronousCommandLocked(DecoderCommand::SEEK); return !seek_error; } @@ -128,7 +128,7 @@ decoder_control::Quit() assert(thread != nullptr); quit = true; - LockAsynchronousCommand(DECODE_COMMAND_STOP); + LockAsynchronousCommand(DecoderCommand::STOP); g_thread_join(thread); thread = nullptr; diff --git a/src/DecoderControl.hxx b/src/DecoderControl.hxx index b9c58dcf2..8afe103c2 100644 --- a/src/DecoderControl.hxx +++ b/src/DecoderControl.hxx @@ -72,7 +72,7 @@ struct decoder_control { Cond client_cond; enum decoder_state state; - enum decoder_command command; + DecoderCommand command; /** * The error that occurred in the decoder thread. This @@ -95,7 +95,7 @@ struct decoder_control { /** * The song currently being decoded. This attribute is set by - * the player thread, when it sends the #DECODE_COMMAND_START + * the player thread, when it sends the #DecoderCommand::START * command. * * This is a duplicate, and must be freed when this attribute @@ -207,7 +207,7 @@ struct decoder_control { } bool HasFailed() const { - assert(command == DECODE_COMMAND_NONE); + assert(command == DecoderCommand::NONE); return state == DECODE_STATE_ERROR; } @@ -228,7 +228,7 @@ struct decoder_control { */ gcc_pure Error GetError() const { - assert(command == DECODE_COMMAND_NONE); + assert(command == DecoderCommand::NONE); assert(state != DECODE_STATE_ERROR || error.IsDefined()); Error result; @@ -286,7 +286,7 @@ private: * object. */ void WaitCommandLocked() { - while (command != DECODE_COMMAND_NONE) + while (command != DecoderCommand::NONE) WaitForDecoder(); } @@ -297,7 +297,7 @@ private: * To be called from the client thread. Caller must lock the * object. */ - void SynchronousCommandLocked(decoder_command cmd) { + void SynchronousCommandLocked(DecoderCommand cmd) { command = cmd; Signal(); WaitCommandLocked(); @@ -310,14 +310,14 @@ private: * To be called from the client thread. This method locks the * object. */ - void LockSynchronousCommand(decoder_command cmd) { + void LockSynchronousCommand(DecoderCommand cmd) { Lock(); ClearError(); SynchronousCommandLocked(cmd); Unlock(); } - void LockAsynchronousCommand(decoder_command cmd) { + void LockAsynchronousCommand(DecoderCommand cmd) { Lock(); command = cmd; Signal(); diff --git a/src/DecoderInternal.cxx b/src/DecoderInternal.cxx index 0c9a10436..307a3550b 100644 --- a/src/DecoderInternal.cxx +++ b/src/DecoderInternal.cxx @@ -41,11 +41,11 @@ decoder::~decoder() * All chunks are full of decoded data; wait for the player to free * one. */ -static enum decoder_command +static DecoderCommand need_chunks(struct decoder_control *dc, bool do_wait) { - if (dc->command == DECODE_COMMAND_STOP || - dc->command == DECODE_COMMAND_SEEK) + if (dc->command == DecoderCommand::STOP || + dc->command == DecoderCommand::SEEK) return dc->command; if (do_wait) { @@ -55,14 +55,14 @@ need_chunks(struct decoder_control *dc, bool do_wait) return dc->command; } - return DECODE_COMMAND_NONE; + return DecoderCommand::NONE; } struct music_chunk * decoder_get_chunk(struct decoder *decoder) { struct decoder_control *dc = decoder->dc; - enum decoder_command cmd; + DecoderCommand cmd; assert(decoder != NULL); @@ -84,7 +84,7 @@ decoder_get_chunk(struct decoder *decoder) dc->Lock(); cmd = need_chunks(dc, true); dc->Unlock(); - } while (cmd == DECODE_COMMAND_NONE); + } while (cmd == DecoderCommand::NONE); return NULL; } diff --git a/src/DecoderThread.cxx b/src/DecoderThread.cxx index a789cc30f..235865fd3 100644 --- a/src/DecoderThread.cxx +++ b/src/DecoderThread.cxx @@ -52,9 +52,9 @@ static void decoder_command_finished_locked(struct decoder_control *dc) { - assert(dc->command != DECODE_COMMAND_NONE); + assert(dc->command != DecoderCommand::NONE); - dc->command = DECODE_COMMAND_NONE; + dc->command = DecoderCommand::NONE; dc->client_cond.signal(); } @@ -67,7 +67,7 @@ decoder_command_finished_locked(struct decoder_control *dc) * * Unlock the decoder before calling this function. * - * @return an input_stream on success or if #DECODE_COMMAND_STOP is + * @return an input_stream on success or if #DecoderCommand::STOP is * received, NULL on error */ static struct input_stream * @@ -90,7 +90,7 @@ decoder_input_stream_open(struct decoder_control *dc, const char *uri) is->Update(); while (!is->ready && - dc->command != DECODE_COMMAND_STOP) { + dc->command != DecoderCommand::STOP) { dc->Wait(); is->Update(); @@ -124,7 +124,7 @@ decoder_stream_decode(const struct decoder_plugin *plugin, g_debug("probing plugin %s", plugin->name); - if (decoder->dc->command == DECODE_COMMAND_STOP) + if (decoder->dc->command == DecoderCommand::STOP) return true; /* rewind the stream, so each plugin gets a fresh start */ @@ -157,7 +157,7 @@ decoder_file_decode(const struct decoder_plugin *plugin, g_debug("probing plugin %s", plugin->name); - if (decoder->dc->command == DECODE_COMMAND_STOP) + if (decoder->dc->command == DecoderCommand::STOP) return true; decoder->dc->Unlock(); @@ -286,7 +286,7 @@ decoder_run_stream(struct decoder *decoder, const char *uri) GSList *tried = NULL; - success = dc->command == DECODE_COMMAND_STOP || + success = dc->command == DecoderCommand::STOP || /* first we try mime types: */ decoder_run_stream_mime_type(decoder, input_stream, &tried) || /* if that fails, try suffix matching the URL: */ @@ -455,7 +455,7 @@ decoder_task(gpointer arg) dc->state == DECODE_STATE_ERROR); switch (dc->command) { - case DECODE_COMMAND_START: + case DecoderCommand::START: dc->MixRampStart(nullptr); dc->MixRampPrevEnd(dc->mixramp_end); dc->mixramp_end = NULL; /* Don't free, it's copied above. */ @@ -464,19 +464,19 @@ decoder_task(gpointer arg) /* fall through */ - case DECODE_COMMAND_SEEK: + case DecoderCommand::SEEK: decoder_run(dc); break; - case DECODE_COMMAND_STOP: + case DecoderCommand::STOP: decoder_command_finished_locked(dc); break; - case DECODE_COMMAND_NONE: + case DecoderCommand::NONE: dc->Wait(); break; } - } while (dc->command != DECODE_COMMAND_NONE || !dc->quit); + } while (dc->command != DecoderCommand::NONE || !dc->quit); dc->Unlock(); diff --git a/src/decoder/AdPlugDecoderPlugin.cxx b/src/decoder/AdPlugDecoderPlugin.cxx index 51a3f7ea7..5c04e116d 100644 --- a/src/decoder/AdPlugDecoderPlugin.cxx +++ b/src/decoder/AdPlugDecoderPlugin.cxx @@ -68,7 +68,7 @@ adplug_file_decode(struct decoder *decoder, const char *path_fs) int16_t buffer[2048]; const unsigned frames_per_buffer = G_N_ELEMENTS(buffer) / 2; - enum decoder_command cmd; + DecoderCommand cmd; do { if (!player->update()) @@ -78,7 +78,7 @@ adplug_file_decode(struct decoder *decoder, const char *path_fs) cmd = decoder_data(decoder, NULL, buffer, sizeof(buffer), 0); - } while (cmd == DECODE_COMMAND_NONE); + } while (cmd == DecoderCommand::NONE); delete player; } diff --git a/src/decoder/AudiofileDecoderPlugin.cxx b/src/decoder/AudiofileDecoderPlugin.cxx index 6b638bb3f..1ee57de4a 100644 --- a/src/decoder/AudiofileDecoderPlugin.cxx +++ b/src/decoder/AudiofileDecoderPlugin.cxx @@ -166,7 +166,6 @@ audiofile_stream_decode(struct decoder *decoder, struct input_stream *is) uint16_t bit_rate; int ret; char chunk[CHUNK_SIZE]; - enum decoder_command cmd; if (!is->IsSeekable()) { g_warning("not seekable"); @@ -202,6 +201,7 @@ audiofile_stream_decode(struct decoder *decoder, struct input_stream *is) decoder_initialized(decoder, audio_format, true, total_time); + DecoderCommand cmd; do { ret = afReadFrames(af_fp, AF_DEFAULT_TRACK, chunk, CHUNK_SIZE / fs); @@ -212,15 +212,15 @@ audiofile_stream_decode(struct decoder *decoder, struct input_stream *is) chunk, ret * fs, bit_rate); - if (cmd == DECODE_COMMAND_SEEK) { + if (cmd == DecoderCommand::SEEK) { AFframecount frame = decoder_seek_where(decoder) * audio_format.sample_rate; afSeekFrame(af_fp, AF_DEFAULT_TRACK, frame); decoder_command_finished(decoder); - cmd = DECODE_COMMAND_NONE; + cmd = DecoderCommand::NONE; } - } while (cmd == DECODE_COMMAND_NONE); + } while (cmd == DecoderCommand::NONE); afCloseFile(af_fp); } diff --git a/src/decoder/DsdiffDecoderPlugin.cxx b/src/decoder/DsdiffDecoderPlugin.cxx index 49b0c601d..80b88a2c2 100644 --- a/src/decoder/DsdiffDecoderPlugin.cxx +++ b/src/decoder/DsdiffDecoderPlugin.cxx @@ -403,17 +403,16 @@ dsdiff_decode_chunk(struct decoder *decoder, struct input_stream *is, if (lsbitfirst) bit_reverse_buffer(buffer, buffer + nbytes); - enum decoder_command cmd = - decoder_data(decoder, is, buffer, nbytes, 0); + const auto cmd = decoder_data(decoder, is, buffer, nbytes, 0); switch (cmd) { - case DECODE_COMMAND_NONE: + case DecoderCommand::NONE: break; - case DECODE_COMMAND_START: - case DECODE_COMMAND_STOP: + case DecoderCommand::START: + case DecoderCommand::STOP: return false; - case DECODE_COMMAND_SEEK: + case DecoderCommand::SEEK: /* Not implemented yet */ decoder_seek_error(decoder); diff --git a/src/decoder/DsfDecoderPlugin.cxx b/src/decoder/DsfDecoderPlugin.cxx index 275f34929..b327fc9dc 100644 --- a/src/decoder/DsfDecoderPlugin.cxx +++ b/src/decoder/DsfDecoderPlugin.cxx @@ -258,17 +258,16 @@ dsf_decode_chunk(struct decoder *decoder, struct input_stream *is, dsf_to_pcm_order(buffer, dsf_scratch_buffer, nbytes); - enum decoder_command cmd = - decoder_data(decoder, is, buffer, nbytes, 0); + const auto cmd = decoder_data(decoder, is, buffer, nbytes, 0); switch (cmd) { - case DECODE_COMMAND_NONE: + case DecoderCommand::NONE: break; - case DECODE_COMMAND_START: - case DECODE_COMMAND_STOP: + case DecoderCommand::START: + case DecoderCommand::STOP: return false; - case DECODE_COMMAND_SEEK: + case DecoderCommand::SEEK: /* not implemented yet */ decoder_seek_error(decoder); diff --git a/src/decoder/FaadDecoderPlugin.cxx b/src/decoder/FaadDecoderPlugin.cxx index c8acfb521..f026a6216 100644 --- a/src/decoder/FaadDecoderPlugin.cxx +++ b/src/decoder/FaadDecoderPlugin.cxx @@ -368,7 +368,6 @@ faad_stream_decode(struct decoder *mpd_decoder, struct input_stream *is) bool ret; uint16_t bit_rate = 0; DecoderBuffer *buffer; - enum decoder_command cmd; buffer = decoder_buffer_new(mpd_decoder, is, FAAD_MIN_STREAMSIZE * AAC_MAX_CHANNELS); @@ -386,7 +385,7 @@ faad_stream_decode(struct decoder *mpd_decoder, struct input_stream *is) NeAACDecSetConfiguration(decoder, config); while (!decoder_buffer_is_full(buffer) && !is->LockIsEOF() && - decoder_get_command(mpd_decoder) == DECODE_COMMAND_NONE) { + decoder_get_command(mpd_decoder) == DecoderCommand::NONE) { adts_find_frame(buffer); decoder_buffer_fill(buffer); } @@ -407,6 +406,7 @@ faad_stream_decode(struct decoder *mpd_decoder, struct input_stream *is) /* the decoder loop */ + DecoderCommand cmd; do { size_t frame_size; const void *decoded; @@ -457,7 +457,7 @@ faad_stream_decode(struct decoder *mpd_decoder, struct input_stream *is) cmd = decoder_data(mpd_decoder, is, decoded, (size_t)frame_info.samples * 2, bit_rate); - } while (cmd != DECODE_COMMAND_STOP); + } while (cmd != DecoderCommand::STOP); /* cleanup */ diff --git a/src/decoder/FfmpegDecoderPlugin.cxx b/src/decoder/FfmpegDecoderPlugin.cxx index a0ac5b8fb..a725e1f7d 100644 --- a/src/decoder/FfmpegDecoderPlugin.cxx +++ b/src/decoder/FfmpegDecoderPlugin.cxx @@ -253,7 +253,7 @@ copy_interleave_frame(const AVCodecContext *codec_context, return data_size; } -static enum decoder_command +static DecoderCommand ffmpeg_send_packet(struct decoder *decoder, struct input_stream *is, const AVPacket *packet, AVCodecContext *codec_context, @@ -269,9 +269,8 @@ ffmpeg_send_packet(struct decoder *decoder, struct input_stream *is, uint8_t *output_buffer; - enum decoder_command cmd = DECODE_COMMAND_NONE; - while (packet2.size > 0 && - cmd == DECODE_COMMAND_NONE) { + DecoderCommand cmd = DecoderCommand::NONE; + while (packet2.size > 0 && cmd == DecoderCommand::NONE) { int audio_size = 0; int got_frame = 0; int len = avcodec_decode_audio4(codec_context, @@ -470,7 +469,7 @@ ffmpeg_decode(struct decoder *decoder, struct input_stream *input) uint8_t *interleaved_buffer = NULL; int interleaved_buffer_size = 0; - enum decoder_command cmd; + DecoderCommand cmd; do { AVPacket packet; if (av_read_frame(format_context, &packet) < 0) @@ -488,7 +487,7 @@ ffmpeg_decode(struct decoder *decoder, struct input_stream *input) av_free_packet(&packet); - if (cmd == DECODE_COMMAND_SEEK) { + if (cmd == DecoderCommand::SEEK) { int64_t where = time_to_ffmpeg(decoder_seek_where(decoder), av_stream->time_base); @@ -501,7 +500,7 @@ ffmpeg_decode(struct decoder *decoder, struct input_stream *input) decoder_command_finished(decoder); } } - } while (cmd != DECODE_COMMAND_STOP); + } while (cmd != DecoderCommand::STOP); #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(54, 28, 0) avcodec_free_frame(&frame); diff --git a/src/decoder/FlacCommon.cxx b/src/decoder/FlacCommon.cxx index 62409d3cc..9f5d81f85 100644 --- a/src/decoder/FlacCommon.cxx +++ b/src/decoder/FlacCommon.cxx @@ -158,7 +158,6 @@ flac_common_write(struct flac_data *data, const FLAC__Frame * frame, const FLAC__int32 *const buf[], FLAC__uint64 nbytes) { - enum decoder_command cmd; void *buffer; unsigned bit_rate; @@ -178,19 +177,19 @@ flac_common_write(struct flac_data *data, const FLAC__Frame * frame, else bit_rate = 0; - cmd = decoder_data(data->decoder, data->input_stream, - buffer, buffer_size, - bit_rate); + auto cmd = decoder_data(data->decoder, data->input_stream, + buffer, buffer_size, + bit_rate); data->next_frame += frame->header.blocksize; switch (cmd) { - case DECODE_COMMAND_NONE: - case DECODE_COMMAND_START: + case DecoderCommand::NONE: + case DecoderCommand::START: break; - case DECODE_COMMAND_STOP: + case DecoderCommand::STOP: return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT; - case DECODE_COMMAND_SEEK: + case DecoderCommand::SEEK: return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE; } diff --git a/src/decoder/FlacDecoderPlugin.cxx b/src/decoder/FlacDecoderPlugin.cxx index c5dd03665..a6b10fbe2 100644 --- a/src/decoder/FlacDecoderPlugin.cxx +++ b/src/decoder/FlacDecoderPlugin.cxx @@ -168,11 +168,11 @@ flac_decoder_loop(struct flac_data *data, FLAC__StreamDecoder *flac_dec, FLAC__uint64 t_start, FLAC__uint64 t_end) { struct decoder *decoder = data->decoder; - enum decoder_command cmd; data->first_frame = t_start; while (true) { + DecoderCommand cmd; if (!data->tag.IsEmpty()) { cmd = decoder_tag(data->decoder, data->input_stream, std::move(data->tag)); @@ -180,7 +180,7 @@ flac_decoder_loop(struct flac_data *data, FLAC__StreamDecoder *flac_dec, } else cmd = decoder_get_command(decoder); - if (cmd == DECODE_COMMAND_SEEK) { + if (cmd == DecoderCommand::SEEK) { FLAC__uint64 seek_sample = t_start + decoder_seek_where(decoder) * data->audio_format.sample_rate; @@ -192,7 +192,7 @@ flac_decoder_loop(struct flac_data *data, FLAC__StreamDecoder *flac_dec, decoder_command_finished(decoder); } else decoder_seek_error(decoder); - } else if (cmd == DECODE_COMMAND_STOP || + } else if (cmd == DecoderCommand::STOP || FLAC__stream_decoder_get_state(flac_dec) == FLAC__STREAM_DECODER_END_OF_STREAM) break; @@ -201,7 +201,7 @@ flac_decoder_loop(struct flac_data *data, FLAC__StreamDecoder *flac_dec, break; if (!FLAC__stream_decoder_process_single(flac_dec) && - decoder_get_command(decoder) == DECODE_COMMAND_NONE) { + decoder_get_command(decoder) == DecoderCommand::NONE) { /* a failure that was not triggered by a decoder command */ flacPrintErroredState(FLAC__stream_decoder_get_state(flac_dec)); diff --git a/src/decoder/FlacInput.cxx b/src/decoder/FlacInput.cxx index 947177cde..19abfca81 100644 --- a/src/decoder/FlacInput.cxx +++ b/src/decoder/FlacInput.cxx @@ -33,7 +33,7 @@ FlacInput::Read(FLAC__byte buffer[], size_t *bytes) if (r == 0) { if (input_stream->LockIsEOF() || (decoder != nullptr && - decoder_get_command(decoder) != DECODE_COMMAND_NONE)) + decoder_get_command(decoder) != DecoderCommand::NONE)) return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM; else return FLAC__STREAM_DECODER_READ_STATUS_ABORT; @@ -79,8 +79,8 @@ FLAC__bool FlacInput::Eof() { return (decoder != nullptr && - decoder_get_command(decoder) != DECODE_COMMAND_NONE && - decoder_get_command(decoder) != DECODE_COMMAND_SEEK) || + decoder_get_command(decoder) != DecoderCommand::NONE && + decoder_get_command(decoder) != DecoderCommand::SEEK) || input_stream->LockIsEOF(); } @@ -88,7 +88,7 @@ void FlacInput::Error(FLAC__StreamDecoderErrorStatus status) { if (decoder == nullptr || - decoder_get_command(decoder) != DECODE_COMMAND_STOP) + decoder_get_command(decoder) != DecoderCommand::STOP) g_warning("%s", FLAC__StreamDecoderErrorStatusString[status]); } diff --git a/src/decoder/FluidsynthDecoderPlugin.cxx b/src/decoder/FluidsynthDecoderPlugin.cxx index 533f02ef1..4db4f1618 100644 --- a/src/decoder/FluidsynthDecoderPlugin.cxx +++ b/src/decoder/FluidsynthDecoderPlugin.cxx @@ -102,7 +102,6 @@ fluidsynth_file_decode(struct decoder *decoder, const char *path_fs) fluid_synth_t *synth; fluid_player_t *player; int ret; - enum decoder_command cmd; /* set up fluid settings */ @@ -167,6 +166,7 @@ fluidsynth_file_decode(struct decoder *decoder, const char *path_fs) const AudioFormat audio_format(sample_rate, SampleFormat::S16, 2); decoder_initialized(decoder, audio_format, false, -1); + DecoderCommand cmd; while (fluid_player_get_status(player) == FLUID_PLAYER_PLAYING) { int16_t buffer[2048]; const unsigned max_frames = G_N_ELEMENTS(buffer) / 2; @@ -182,7 +182,7 @@ fluidsynth_file_decode(struct decoder *decoder, const char *path_fs) cmd = decoder_data(decoder, nullptr, buffer, sizeof(buffer), 0); - if (cmd != DECODE_COMMAND_NONE) + if (cmd != DecoderCommand::NONE) break; } diff --git a/src/decoder/GmeDecoderPlugin.cxx b/src/decoder/GmeDecoderPlugin.cxx index cc31c6bab..dbe1d000f 100644 --- a/src/decoder/GmeDecoderPlugin.cxx +++ b/src/decoder/GmeDecoderPlugin.cxx @@ -174,7 +174,7 @@ gme_file_decode(struct decoder *decoder, const char *path_fs) gme_set_fade(emu, ti->length); /* play */ - enum decoder_command cmd; + DecoderCommand cmd; do { short buf[GME_BUFFER_SAMPLES]; gme_err = gme_play(emu, GME_BUFFER_SAMPLES, buf); @@ -184,7 +184,7 @@ gme_file_decode(struct decoder *decoder, const char *path_fs) } cmd = decoder_data(decoder, nullptr, buf, sizeof(buf), 0); - if (cmd == DECODE_COMMAND_SEEK) { + if (cmd == DecoderCommand::SEEK) { float where = decoder_seek_where(decoder); gme_err = gme_seek(emu, int(where * 1000)); if (gme_err != nullptr) @@ -194,7 +194,7 @@ gme_file_decode(struct decoder *decoder, const char *path_fs) if (gme_track_ended(emu)) break; - } while (cmd != DECODE_COMMAND_STOP); + } while (cmd != DecoderCommand::STOP); gme_free_info(ti); gme_delete(emu); diff --git a/src/decoder/MadDecoderPlugin.cxx b/src/decoder/MadDecoderPlugin.cxx index dc2d0b806..b7d90892b 100644 --- a/src/decoder/MadDecoderPlugin.cxx +++ b/src/decoder/MadDecoderPlugin.cxx @@ -171,13 +171,13 @@ struct MadDecoder { /** * Sends the synthesized current frame via decoder_data(). */ - enum decoder_command SendPCM(unsigned i, unsigned pcm_length); + DecoderCommand SendPCM(unsigned i, unsigned pcm_length); /** * Synthesize the current frame and send it via * decoder_data(). */ - enum decoder_command SyncAndSend(); + DecoderCommand SyncAndSend(); bool Read(); }; @@ -953,7 +953,7 @@ MadDecoder::UpdateTimerNextFrame() elapsed_time = mad_timer_count(timer, MAD_UNITS_MILLISECONDS) / 1000.0; } -enum decoder_command +DecoderCommand MadDecoder::SendPCM(unsigned i, unsigned pcm_length) { unsigned max_samples; @@ -963,7 +963,6 @@ MadDecoder::SendPCM(unsigned i, unsigned pcm_length) MAD_NCHANNELS(&frame.header); while (i < pcm_length) { - enum decoder_command cmd; unsigned int num_samples = pcm_length - i; if (num_samples > max_samples) num_samples = max_samples; @@ -975,17 +974,17 @@ MadDecoder::SendPCM(unsigned i, unsigned pcm_length) MAD_NCHANNELS(&frame.header)); num_samples *= MAD_NCHANNELS(&frame.header); - cmd = decoder_data(decoder, input_stream, output_buffer, - sizeof(output_buffer[0]) * num_samples, - bit_rate / 1000); - if (cmd != DECODE_COMMAND_NONE) + auto cmd = decoder_data(decoder, input_stream, output_buffer, + sizeof(output_buffer[0]) * num_samples, + bit_rate / 1000); + if (cmd != DecoderCommand::NONE) return cmd; } - return DECODE_COMMAND_NONE; + return DecoderCommand::NONE; } -inline enum decoder_command +inline DecoderCommand MadDecoder::SyncAndSend() { mad_synth_frame(&synth, &frame); @@ -1001,12 +1000,12 @@ MadDecoder::SyncAndSend() if (drop_start_frames > 0) { drop_start_frames--; - return DECODE_COMMAND_NONE; + return DecoderCommand::NONE; } else if ((drop_end_frames > 0) && (current_frame == (max_frames + 1 - drop_end_frames))) { /* stop decoding, effectively dropping all remaining frames */ - return DECODE_COMMAND_STOP; + return DecoderCommand::STOP; } unsigned i = 0; @@ -1024,28 +1023,29 @@ MadDecoder::SyncAndSend() pcm_length -= drop_end_samples; } - enum decoder_command cmd = SendPCM(i, pcm_length); - if (cmd != DECODE_COMMAND_NONE) + auto cmd = SendPCM(i, pcm_length); + if (cmd != DecoderCommand::NONE) return cmd; if (drop_end_samples && (current_frame == max_frames - drop_end_frames)) /* stop decoding, effectively dropping * all remaining samples */ - return DECODE_COMMAND_STOP; + return DecoderCommand::STOP; - return DECODE_COMMAND_NONE; + return DecoderCommand::NONE; } inline bool MadDecoder::Read() { enum mp3_action ret; - enum decoder_command cmd; UpdateTimerNextFrame(); switch (mute_frame) { + DecoderCommand cmd; + case MUTEFRAME_SKIP: mute_frame = MUTEFRAME_NONE; break; @@ -1055,7 +1055,7 @@ MadDecoder::Read() break; case MUTEFRAME_NONE: cmd = SyncAndSend(); - if (cmd == DECODE_COMMAND_SEEK) { + if (cmd == DecoderCommand::SEEK) { unsigned long j; assert(input_stream->IsSeekable()); @@ -1072,7 +1072,7 @@ MadDecoder::Read() mute_frame = MUTEFRAME_SEEK; decoder_command_finished(decoder); } - } else if (cmd != DECODE_COMMAND_NONE) + } else if (cmd != DecoderCommand::NONE) return false; } @@ -1119,7 +1119,7 @@ mp3_decode(struct decoder *decoder, struct input_stream *input_stream) if (!data.DecodeFirstFrame(&tag)) { delete tag; - if (decoder_get_command(decoder) == DECODE_COMMAND_NONE) + if (decoder_get_command(decoder) == DecoderCommand::NONE) g_warning ("Input does not appear to be a mp3 bit stream.\n"); return; diff --git a/src/decoder/MikmodDecoderPlugin.cxx b/src/decoder/MikmodDecoderPlugin.cxx index f98b22a6d..78a26891a 100644 --- a/src/decoder/MikmodDecoderPlugin.cxx +++ b/src/decoder/MikmodDecoderPlugin.cxx @@ -148,7 +148,6 @@ mikmod_decoder_file_decode(struct decoder *decoder, const char *path_fs) MODULE *handle; int ret; SBYTE buffer[MIKMOD_FRAME_SIZE]; - enum decoder_command cmd = DECODE_COMMAND_NONE; path2 = g_strdup(path_fs); handle = Player_Load(path2, 128, 0); @@ -168,7 +167,9 @@ mikmod_decoder_file_decode(struct decoder *decoder, const char *path_fs) decoder_initialized(decoder, audio_format, false, 0); Player_Start(handle); - while (cmd == DECODE_COMMAND_NONE && Player_Active()) { + + DecoderCommand cmd = DecoderCommand::NONE; + while (cmd == DecoderCommand::NONE && Player_Active()) { ret = VC_WriteBytes(buffer, sizeof(buffer)); cmd = decoder_data(decoder, nullptr, buffer, ret, 0); } diff --git a/src/decoder/ModplugDecoderPlugin.cxx b/src/decoder/ModplugDecoderPlugin.cxx index d6840300c..9cbf44b15 100644 --- a/src/decoder/ModplugDecoderPlugin.cxx +++ b/src/decoder/ModplugDecoderPlugin.cxx @@ -99,7 +99,6 @@ mod_decode(struct decoder *decoder, struct input_stream *is) GByteArray *bdatas; int ret; char audio_buffer[MODPLUG_FRAME_SIZE]; - enum decoder_command cmd = DECODE_COMMAND_NONE; bdatas = mod_loadfile(decoder, is); @@ -131,6 +130,7 @@ mod_decode(struct decoder *decoder, struct input_stream *is) is->IsSeekable(), ModPlug_GetLength(f) / 1000.0); + DecoderCommand cmd; do { ret = ModPlug_Read(f, audio_buffer, MODPLUG_FRAME_SIZE); if (ret <= 0) @@ -140,7 +140,7 @@ mod_decode(struct decoder *decoder, struct input_stream *is) audio_buffer, ret, 0); - if (cmd == DECODE_COMMAND_SEEK) { + if (cmd == DecoderCommand::SEEK) { float where = decoder_seek_where(decoder); ModPlug_Seek(f, (int)(where * 1000.0)); @@ -148,7 +148,7 @@ mod_decode(struct decoder *decoder, struct input_stream *is) decoder_command_finished(decoder); } - } while (cmd != DECODE_COMMAND_STOP); + } while (cmd != DecoderCommand::STOP); ModPlug_Unload(f); } diff --git a/src/decoder/MpcdecDecoderPlugin.cxx b/src/decoder/MpcdecDecoderPlugin.cxx index d9c7a17d1..252fe92e6 100644 --- a/src/decoder/MpcdecDecoderPlugin.cxx +++ b/src/decoder/MpcdecDecoderPlugin.cxx @@ -147,7 +147,7 @@ mpcdec_decode(struct decoder *mpd_decoder, struct input_stream *is) mpc_demux *demux = mpc_demux_init(&reader); if (demux == nullptr) { - if (decoder_get_command(mpd_decoder) != DECODE_COMMAND_STOP) + if (decoder_get_command(mpd_decoder) != DecoderCommand::STOP) g_warning("Not a valid musepack stream"); return; } @@ -178,9 +178,9 @@ mpcdec_decode(struct decoder *mpd_decoder, struct input_stream *is) is->IsSeekable(), mpc_streaminfo_get_length(&info)); - enum decoder_command cmd = DECODE_COMMAND_NONE; + DecoderCommand cmd = DecoderCommand::NONE; do { - if (cmd == DECODE_COMMAND_SEEK) { + if (cmd == DecoderCommand::SEEK) { mpc_int64_t where = decoder_seek_where(mpd_decoder) * audio_format.sample_rate; bool success; @@ -218,7 +218,7 @@ mpcdec_decode(struct decoder *mpd_decoder, struct input_stream *is) cmd = decoder_data(mpd_decoder, is, chunk, ret * sizeof(chunk[0]), bit_rate); - } while (cmd != DECODE_COMMAND_STOP); + } while (cmd != DecoderCommand::STOP); mpc_demux_exit(demux); } diff --git a/src/decoder/Mpg123DecoderPlugin.cxx b/src/decoder/Mpg123DecoderPlugin.cxx index a44fc1241..3100a0f1c 100644 --- a/src/decoder/Mpg123DecoderPlugin.cxx +++ b/src/decoder/Mpg123DecoderPlugin.cxx @@ -106,7 +106,6 @@ mpd_mpg123_file_decode(struct decoder *decoder, const char *path_fs) mpg123_handle *handle; int error; off_t num_samples; - enum decoder_command cmd; struct mpg123_frameinfo info; /* open the file */ @@ -149,6 +148,7 @@ mpd_mpg123_file_decode(struct decoder *decoder, const char *path_fs) /* the decoder main loop */ + DecoderCommand cmd; do { unsigned char buffer[8192]; size_t nbytes; @@ -175,7 +175,7 @@ mpd_mpg123_file_decode(struct decoder *decoder, const char *path_fs) cmd = decoder_data(decoder, nullptr, buffer, nbytes, info.bitrate); - if (cmd == DECODE_COMMAND_SEEK) { + if (cmd == DecoderCommand::SEEK) { off_t c = decoder_seek_where(decoder)*audio_format.sample_rate; c = mpg123_seek(handle, c, SEEK_SET); if (c < 0) @@ -185,9 +185,9 @@ mpd_mpg123_file_decode(struct decoder *decoder, const char *path_fs) decoder_timestamp(decoder, c/(double)audio_format.sample_rate); } - cmd = DECODE_COMMAND_NONE; + cmd = DecoderCommand::NONE; } - } while (cmd == DECODE_COMMAND_NONE); + } while (cmd == DecoderCommand::NONE); /* cleanup */ diff --git a/src/decoder/OpusDecoderPlugin.cxx b/src/decoder/OpusDecoderPlugin.cxx index c757d66ef..ea1d6660c 100644 --- a/src/decoder/OpusDecoderPlugin.cxx +++ b/src/decoder/OpusDecoderPlugin.cxx @@ -96,11 +96,11 @@ public: bool ReadFirstPage(OggSyncState &oy); bool ReadNextPage(OggSyncState &oy); - enum decoder_command HandlePackets(); - enum decoder_command HandlePacket(const ogg_packet &packet); - enum decoder_command HandleBOS(const ogg_packet &packet); - enum decoder_command HandleTags(const ogg_packet &packet); - enum decoder_command HandleAudio(const ogg_packet &packet); + DecoderCommand HandlePackets(); + DecoderCommand HandlePacket(const ogg_packet &packet); + DecoderCommand HandleBOS(const ogg_packet &packet); + DecoderCommand HandleTags(const ogg_packet &packet); + DecoderCommand HandleAudio(const ogg_packet &packet); }; MPDOpusDecoder::~MPDOpusDecoder() @@ -143,29 +143,29 @@ MPDOpusDecoder::ReadNextPage(OggSyncState &oy) return true; } -inline enum decoder_command +inline DecoderCommand MPDOpusDecoder::HandlePackets() { ogg_packet packet; while (ogg_stream_packetout(&os, &packet) == 1) { - enum decoder_command cmd = HandlePacket(packet); - if (cmd != DECODE_COMMAND_NONE) + auto cmd = HandlePacket(packet); + if (cmd != DecoderCommand::NONE) return cmd; } - return DECODE_COMMAND_NONE; + return DecoderCommand::NONE; } -inline enum decoder_command +inline DecoderCommand MPDOpusDecoder::HandlePacket(const ogg_packet &packet) { if (packet.e_o_s) - return DECODE_COMMAND_STOP; + return DecoderCommand::STOP; if (packet.b_o_s) return HandleBOS(packet); else if (!found_opus) - return DECODE_COMMAND_STOP; + return DecoderCommand::STOP; if (IsOpusTags(packet)) return HandleTags(packet); @@ -173,18 +173,18 @@ MPDOpusDecoder::HandlePacket(const ogg_packet &packet) return HandleAudio(packet); } -inline enum decoder_command +inline DecoderCommand MPDOpusDecoder::HandleBOS(const ogg_packet &packet) { assert(packet.b_o_s); if (found_opus || !IsOpusHead(packet)) - return DECODE_COMMAND_STOP; + return DecoderCommand::STOP; unsigned channels; if (!ScanOpusHeader(packet.packet, packet.bytes, channels) || !audio_valid_channel_count(channels)) - return DECODE_COMMAND_STOP; + return DecoderCommand::STOP; assert(opus_decoder == nullptr); assert(output_buffer == nullptr); @@ -201,7 +201,7 @@ MPDOpusDecoder::HandleBOS(const ogg_packet &packet) if (opus_decoder == nullptr) { g_warning("libopus error: %s", opus_strerror(opus_error)); - return DECODE_COMMAND_STOP; + return DecoderCommand::STOP; } const AudioFormat audio_format(opus_sample_rate, @@ -220,12 +220,12 @@ MPDOpusDecoder::HandleBOS(const ogg_packet &packet) return decoder_get_command(decoder); } -inline enum decoder_command +inline DecoderCommand MPDOpusDecoder::HandleTags(const ogg_packet &packet) { TagBuilder tag_builder; - enum decoder_command cmd; + DecoderCommand cmd; if (ScanOpusTags(packet.packet, packet.bytes, &add_tag_handler, &tag_builder) && !tag_builder.IsEmpty()) { @@ -238,7 +238,7 @@ MPDOpusDecoder::HandleTags(const ogg_packet &packet) return cmd; } -inline enum decoder_command +inline DecoderCommand MPDOpusDecoder::HandleAudio(const ogg_packet &packet) { assert(opus_decoder != nullptr); @@ -250,20 +250,19 @@ MPDOpusDecoder::HandleAudio(const ogg_packet &packet) 0); if (nframes < 0) { g_warning("%s", opus_strerror(nframes)); - return DECODE_COMMAND_STOP; + return DecoderCommand::STOP; } if (nframes > 0) { const size_t nbytes = nframes * frame_size; - enum decoder_command cmd = - decoder_data(decoder, input_stream, - output_buffer, nbytes, - 0); - if (cmd != DECODE_COMMAND_NONE) + auto cmd = decoder_data(decoder, input_stream, + output_buffer, nbytes, + 0); + if (cmd != DecoderCommand::NONE) return cmd; } - return DECODE_COMMAND_NONE; + return DecoderCommand::NONE; } static void @@ -284,8 +283,8 @@ mpd_opus_stream_decode(struct decoder *decoder, return; while (true) { - enum decoder_command cmd = d.HandlePackets(); - if (cmd != DECODE_COMMAND_NONE) + auto cmd = d.HandlePackets(); + if (cmd != DecoderCommand::NONE) break; if (!d.ReadNextPage(oy)) diff --git a/src/decoder/PcmDecoderPlugin.cxx b/src/decoder/PcmDecoderPlugin.cxx index 4fccca75d..94867f01d 100644 --- a/src/decoder/PcmDecoderPlugin.cxx +++ b/src/decoder/PcmDecoderPlugin.cxx @@ -48,8 +48,6 @@ pcm_stream_decode(struct decoder *decoder, struct input_stream *is) const bool reverse_endian = mime != nullptr && strcmp(mime, "audio/x-mpd-cdda-pcm-reverse") == 0; - enum decoder_command cmd; - const double time_to_size = audio_format.GetTimeToSize(); float total_time = -1; @@ -60,6 +58,7 @@ pcm_stream_decode(struct decoder *decoder, struct input_stream *is) decoder_initialized(decoder, audio_format, is->IsSeekable(), total_time); + DecoderCommand cmd; do { char buffer[4096]; @@ -79,7 +78,7 @@ pcm_stream_decode(struct decoder *decoder, struct input_stream *is) ? decoder_data(decoder, is, buffer, nbytes, 0) : decoder_get_command(decoder); - if (cmd == DECODE_COMMAND_SEEK) { + if (cmd == DecoderCommand::SEEK) { goffset offset = (goffset)(time_to_size * decoder_seek_where(decoder)); @@ -91,9 +90,9 @@ pcm_stream_decode(struct decoder *decoder, struct input_stream *is) decoder_seek_error(decoder); } - cmd = DECODE_COMMAND_NONE; + cmd = DecoderCommand::NONE; } - } while (cmd == DECODE_COMMAND_NONE); + } while (cmd == DecoderCommand::NONE); } static const char *const pcm_mime_types[] = { diff --git a/src/decoder/SndfileDecoderPlugin.cxx b/src/decoder/SndfileDecoderPlugin.cxx index 252e88df5..56853958c 100644 --- a/src/decoder/SndfileDecoderPlugin.cxx +++ b/src/decoder/SndfileDecoderPlugin.cxx @@ -119,7 +119,6 @@ sndfile_stream_decode(struct decoder *decoder, struct input_stream *is) size_t frame_size; sf_count_t read_frames, num_frames; int buffer[4096]; - enum decoder_command cmd; info.format = 0; @@ -147,6 +146,7 @@ sndfile_stream_decode(struct decoder *decoder, struct input_stream *is) frame_size = audio_format.GetFrameSize(); read_frames = sizeof(buffer) / frame_size; + DecoderCommand cmd; do { num_frames = sf_readf_int(sf, buffer, read_frames); if (num_frames <= 0) @@ -155,7 +155,7 @@ sndfile_stream_decode(struct decoder *decoder, struct input_stream *is) cmd = decoder_data(decoder, is, buffer, num_frames * frame_size, 0); - if (cmd == DECODE_COMMAND_SEEK) { + if (cmd == DecoderCommand::SEEK) { sf_count_t c = time_to_frame(decoder_seek_where(decoder), &audio_format); @@ -164,9 +164,9 @@ sndfile_stream_decode(struct decoder *decoder, struct input_stream *is) decoder_seek_error(decoder); else decoder_command_finished(decoder); - cmd = DECODE_COMMAND_NONE; + cmd = DecoderCommand::NONE; } - } while (cmd == DECODE_COMMAND_NONE); + } while (cmd == DecoderCommand::NONE); sf_close(sf); } diff --git a/src/decoder/VorbisDecoderPlugin.cxx b/src/decoder/VorbisDecoderPlugin.cxx index 2b175912d..a4a938aa8 100644 --- a/src/decoder/VorbisDecoderPlugin.cxx +++ b/src/decoder/VorbisDecoderPlugin.cxx @@ -83,7 +83,7 @@ static int ogg_seek_cb(void *data, ogg_int64_t offset, int whence) Error error; return vis->seekable && - (!vis->decoder || decoder_get_command(vis->decoder) != DECODE_COMMAND_STOP) && + (!vis->decoder || decoder_get_command(vis->decoder) != DecoderCommand::STOP) && vis->input_stream->LockSeek(offset, whence, error) ? 0 : -1; } @@ -143,7 +143,7 @@ vorbis_is_open(struct vorbis_input_stream *vis, OggVorbis_File *vf, int ret = ov_open_callbacks(vis, vf, NULL, 0, vorbis_is_callbacks); if (ret < 0) { if (decoder == NULL || - decoder_get_command(decoder) == DECODE_COMMAND_NONE) + decoder_get_command(decoder) == DecoderCommand::NONE) g_warning("Failed to open Ogg Vorbis stream: %s", vorbis_strerror(ret)); return false; @@ -221,8 +221,6 @@ vorbis_stream_decode(struct decoder *decoder, decoder_initialized(decoder, audio_format, vis.seekable, total_time); - enum decoder_command cmd = decoder_get_command(decoder); - #ifdef HAVE_TREMOR char buffer[4096]; #else @@ -235,8 +233,9 @@ vorbis_stream_decode(struct decoder *decoder, int prev_section = -1; unsigned kbit_rate = 0; + DecoderCommand cmd = decoder_get_command(decoder); do { - if (cmd == DECODE_COMMAND_SEEK) { + if (cmd == DecoderCommand::SEEK) { double seek_where = decoder_seek_where(decoder); if (0 == ov_time_seek_page(&vf, seek_where)) { decoder_command_finished(decoder); @@ -302,7 +301,7 @@ vorbis_stream_decode(struct decoder *decoder, cmd = decoder_data(decoder, input_stream, buffer, nbytes, kbit_rate); - } while (cmd != DECODE_COMMAND_STOP); + } while (cmd != DecoderCommand::STOP); ov_clear(&vf); } diff --git a/src/decoder/WavpackDecoderPlugin.cxx b/src/decoder/WavpackDecoderPlugin.cxx index d0122ad87..ecabafefe 100644 --- a/src/decoder/WavpackDecoderPlugin.cxx +++ b/src/decoder/WavpackDecoderPlugin.cxx @@ -177,9 +177,9 @@ wavpack_decode(struct decoder *decoder, WavpackContext *wpc, bool can_seek) decoder_initialized(decoder, audio_format, can_seek, total_time); - enum decoder_command cmd = decoder_get_command(decoder); - while (cmd != DECODE_COMMAND_STOP) { - if (cmd == DECODE_COMMAND_SEEK) { + DecoderCommand cmd = decoder_get_command(decoder); + while (cmd != DecoderCommand::STOP) { + if (cmd == DecoderCommand::SEEK) { if (can_seek) { unsigned where = decoder_seek_where(decoder) * audio_format.sample_rate; diff --git a/src/decoder/WildmidiDecoderPlugin.cxx b/src/decoder/WildmidiDecoderPlugin.cxx index daa0e0cc9..3a057ca2c 100644 --- a/src/decoder/WildmidiDecoderPlugin.cxx +++ b/src/decoder/WildmidiDecoderPlugin.cxx @@ -72,7 +72,6 @@ wildmidi_file_decode(struct decoder *decoder, const char *path_fs) }; midi *wm; const struct _WM_Info *info; - enum decoder_command cmd; wm = WildMidi_Open(path_fs); if (wm == nullptr) @@ -87,6 +86,7 @@ wildmidi_file_decode(struct decoder *decoder, const char *path_fs) decoder_initialized(decoder, audio_format, true, info->approx_total_samples / WILDMIDI_SAMPLE_RATE); + DecoderCommand cmd; do { char buffer[4096]; int len; @@ -101,7 +101,7 @@ wildmidi_file_decode(struct decoder *decoder, const char *path_fs) cmd = decoder_data(decoder, nullptr, buffer, len, 0); - if (cmd == DECODE_COMMAND_SEEK) { + if (cmd == DecoderCommand::SEEK) { unsigned long seek_where = WILDMIDI_SAMPLE_RATE * decoder_seek_where(decoder); @@ -111,10 +111,10 @@ wildmidi_file_decode(struct decoder *decoder, const char *path_fs) WildMidi_FastSeek(wm, &seek_where); #endif decoder_command_finished(decoder); - cmd = DECODE_COMMAND_NONE; + cmd = DecoderCommand::NONE; } - } while (cmd == DECODE_COMMAND_NONE); + } while (cmd == DecoderCommand::NONE); WildMidi_Close(wm); } diff --git a/src/decoder/sidplay_decoder_plugin.cxx b/src/decoder/sidplay_decoder_plugin.cxx index 19969c00a..fed0476ec 100644 --- a/src/decoder/sidplay_decoder_plugin.cxx +++ b/src/decoder/sidplay_decoder_plugin.cxx @@ -290,7 +290,7 @@ sidplay_file_decode(struct decoder *decoder, const char *path_fs) const unsigned timebase = player.timebase(); song_len *= timebase; - enum decoder_command cmd; + DecoderCommand cmd; do { char buffer[4096]; size_t nbytes; @@ -303,7 +303,7 @@ sidplay_file_decode(struct decoder *decoder, const char *path_fs) cmd = decoder_data(decoder, NULL, buffer, nbytes, 0); - if(cmd==DECODE_COMMAND_SEEK) { + if (cmd == DecoderCommand::SEEK) { unsigned data_time = player.time(); unsigned target_time = (unsigned) (decoder_seek_where(decoder) * timebase); @@ -328,7 +328,7 @@ sidplay_file_decode(struct decoder *decoder, const char *path_fs) if (song_len > 0 && player.time() >= (unsigned)song_len) break; - } while (cmd != DECODE_COMMAND_STOP); + } while (cmd != DecoderCommand::STOP); } static bool diff --git a/test/dump_playlist.cxx b/test/dump_playlist.cxx index 45719fab0..af73ed4e7 100644 --- a/test/dump_playlist.cxx +++ b/test/dump_playlist.cxx @@ -59,10 +59,10 @@ decoder_initialized(gcc_unused struct decoder *decoder, { } -enum decoder_command +DecoderCommand decoder_get_command(gcc_unused struct decoder *decoder) { - return DECODE_COMMAND_NONE; + return DecoderCommand::NONE; } void @@ -96,22 +96,22 @@ decoder_timestamp(gcc_unused struct decoder *decoder, { } -enum decoder_command +DecoderCommand decoder_data(gcc_unused struct decoder *decoder, gcc_unused struct input_stream *is, const void *data, size_t datalen, gcc_unused uint16_t kbit_rate) { gcc_unused ssize_t nbytes = write(1, data, datalen); - return DECODE_COMMAND_NONE; + return DecoderCommand::NONE; } -enum decoder_command +DecoderCommand decoder_tag(gcc_unused struct decoder *decoder, gcc_unused struct input_stream *is, gcc_unused Tag &&tag) { - return DECODE_COMMAND_NONE; + return DecoderCommand::NONE; } void diff --git a/test/read_tags.cxx b/test/read_tags.cxx index de100134b..d7f2f38d9 100644 --- a/test/read_tags.cxx +++ b/test/read_tags.cxx @@ -47,10 +47,10 @@ decoder_initialized(gcc_unused struct decoder *decoder, { } -enum decoder_command +DecoderCommand decoder_get_command(gcc_unused struct decoder *decoder) { - return DECODE_COMMAND_NONE; + return DecoderCommand::NONE; } void decoder_command_finished(gcc_unused struct decoder *decoder) @@ -81,22 +81,22 @@ decoder_timestamp(gcc_unused struct decoder *decoder, { } -enum decoder_command +DecoderCommand decoder_data(gcc_unused struct decoder *decoder, gcc_unused struct input_stream *is, const void *data, size_t datalen, gcc_unused uint16_t bit_rate) { gcc_unused ssize_t nbytes = write(1, data, datalen); - return DECODE_COMMAND_NONE; + return DecoderCommand::NONE; } -enum decoder_command +DecoderCommand decoder_tag(gcc_unused struct decoder *decoder, gcc_unused struct input_stream *is, gcc_unused Tag &&tag) { - return DECODE_COMMAND_NONE; + return DecoderCommand::NONE; } void diff --git a/test/run_decoder.cxx b/test/run_decoder.cxx index ed29c1880..794302b5d 100644 --- a/test/run_decoder.cxx +++ b/test/run_decoder.cxx @@ -68,10 +68,10 @@ decoder_initialized(struct decoder *decoder, decoder->initialized = true; } -enum decoder_command +DecoderCommand decoder_get_command(gcc_unused struct decoder *decoder) { - return DECODE_COMMAND_NONE; + return DecoderCommand::NONE; } void decoder_command_finished(gcc_unused struct decoder *decoder) @@ -101,22 +101,22 @@ decoder_timestamp(gcc_unused struct decoder *decoder, { } -enum decoder_command +DecoderCommand decoder_data(gcc_unused struct decoder *decoder, gcc_unused struct input_stream *is, const void *data, size_t datalen, gcc_unused uint16_t kbit_rate) { gcc_unused ssize_t nbytes = write(1, data, datalen); - return DECODE_COMMAND_NONE; + return DecoderCommand::NONE; } -enum decoder_command +DecoderCommand decoder_tag(gcc_unused struct decoder *decoder, gcc_unused struct input_stream *is, gcc_unused Tag &&tag) { - return DECODE_COMMAND_NONE; + return DecoderCommand::NONE; } void |