Commit c5d05ac0 authored by Max Kellermann's avatar Max Kellermann

DecoderCommand: convert to strictly-typed enum

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