From 66fb352ccaac94a1ca5b6ac261ea15e790217f16 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 18 Nov 2016 07:59:01 +0100 Subject: [PATCH] decoder/Client: add virtual method Ready() Replaces decoder_initialized(). --- src/decoder/Client.hxx | 16 ++++++++++++++ src/decoder/DecoderAPI.cxx | 21 ++++++++----------- src/decoder/DecoderAPI.hxx | 17 +-------------- src/decoder/DecoderInternal.hxx | 4 ++++ src/decoder/plugins/AdPlugDecoderPlugin.cxx | 4 ++-- .../plugins/AudiofileDecoderPlugin.cxx | 2 +- src/decoder/plugins/DsdiffDecoderPlugin.cxx | 2 +- src/decoder/plugins/DsfDecoderPlugin.cxx | 2 +- src/decoder/plugins/FaadDecoderPlugin.cxx | 2 +- src/decoder/plugins/FfmpegDecoderPlugin.cxx | 3 +-- src/decoder/plugins/FlacCommon.cxx | 6 +++--- src/decoder/plugins/FlacCommon.hxx | 6 +++--- .../plugins/FluidsynthDecoderPlugin.cxx | 3 +-- src/decoder/plugins/GmeDecoderPlugin.cxx | 2 +- src/decoder/plugins/MadDecoderPlugin.cxx | 11 +++++----- src/decoder/plugins/MikmodDecoderPlugin.cxx | 3 +-- src/decoder/plugins/ModplugDecoderPlugin.cxx | 5 ++--- src/decoder/plugins/MpcdecDecoderPlugin.cxx | 5 ++--- src/decoder/plugins/Mpg123DecoderPlugin.cxx | 2 +- src/decoder/plugins/OpusDecoderPlugin.cxx | 5 ++--- src/decoder/plugins/PcmDecoderPlugin.cxx | 3 +-- src/decoder/plugins/SidplayDecoderPlugin.cxx | 2 +- src/decoder/plugins/SndfileDecoderPlugin.cxx | 3 +-- src/decoder/plugins/VorbisDecoderPlugin.cxx | 3 +-- src/decoder/plugins/WavpackDecoderPlugin.cxx | 2 +- src/decoder/plugins/WildmidiDecoderPlugin.cxx | 2 +- test/FakeDecoderAPI.cxx | 12 +++++------ test/FakeDecoderAPI.hxx | 4 ++++ 28 files changed, 73 insertions(+), 79 deletions(-) diff --git a/src/decoder/Client.hxx b/src/decoder/Client.hxx index e8d3ea641..f0064fcbb 100644 --- a/src/decoder/Client.hxx +++ b/src/decoder/Client.hxx @@ -21,11 +21,27 @@ #define MPD_DECODER_CLIENT_HXX #include "check.h" +#include "Chrono.hxx" + +struct AudioFormat; /** * An interface between the decoder plugin and the MPD core. */ class DecoderClient { +public: + /** + * Notify the client that it has finished initialization and + * that it has read the song's meta data. + * + * @param audio_format the audio format which is going to be + * sent to SubmitData() + * @param seekable true if the song is seekable + * @param duration the total duration of this song; negative if + * unknown + */ + virtual void Ready(AudioFormat audio_format, + bool seekable, SignedSongTime duration) = 0; }; #endif diff --git a/src/decoder/DecoderAPI.cxx b/src/decoder/DecoderAPI.cxx index 6c4658dfb..017edb897 100644 --- a/src/decoder/DecoderAPI.cxx +++ b/src/decoder/DecoderAPI.cxx @@ -38,21 +38,18 @@ #include void -decoder_initialized(DecoderClient &client, - const AudioFormat audio_format, - bool seekable, SignedSongTime duration) +Decoder::Ready(const AudioFormat audio_format, + bool seekable, SignedSongTime duration) { - auto &decoder = (Decoder &)client; - DecoderControl &dc = decoder.dc; struct audio_format_string af_string; assert(dc.state == DecoderState::START); assert(dc.pipe != nullptr); assert(dc.pipe->IsEmpty()); - assert(decoder.convert == nullptr); - assert(decoder.stream_tag == nullptr); - assert(decoder.decoder_tag == nullptr); - assert(!decoder.seeking); + assert(convert == nullptr); + assert(stream_tag == nullptr); + assert(decoder_tag == nullptr); + assert(!seeking); assert(audio_format.IsDefined()); assert(audio_format.IsValid()); @@ -71,13 +68,13 @@ decoder_initialized(DecoderClient &client, audio_format_to_string(dc.out_audio_format, &af_string)); - decoder.convert = new PcmConvert(); + convert = new PcmConvert(); try { - decoder.convert->Open(dc.in_audio_format, + convert->Open(dc.in_audio_format, dc.out_audio_format); } catch (...) { - decoder.error = std::current_exception(); + error = std::current_exception(); } } diff --git a/src/decoder/DecoderAPI.hxx b/src/decoder/DecoderAPI.hxx index 0393a9591..0f49e832b 100644 --- a/src/decoder/DecoderAPI.hxx +++ b/src/decoder/DecoderAPI.hxx @@ -30,6 +30,7 @@ // IWYU pragma: begin_exports #include "check.h" +#include "Client.hxx" #include "input/Ptr.hxx" #include "DecoderCommand.hxx" #include "DecoderPlugin.hxx" @@ -53,22 +54,6 @@ class DecoderClient; */ class StopDecoder {}; -/** - * Notify the player thread that it has finished initialization and - * that it has read the song's meta data. - * - * @param decoder the decoder object - * @param audio_format the audio format which is going to be sent to - * decoder_data() - * @param seekable true if the song is seekable - * @param duration the total duration of this song; negative if - * unknown - */ -void -decoder_initialized(DecoderClient &decoder, - AudioFormat audio_format, - bool seekable, SignedSongTime duration); - /** * Determines the pending decoder command. * diff --git a/src/decoder/DecoderInternal.hxx b/src/decoder/DecoderInternal.hxx index 91ea7928a..2a6cf1a93 100644 --- a/src/decoder/DecoderInternal.hxx +++ b/src/decoder/DecoderInternal.hxx @@ -116,6 +116,10 @@ struct Decoder final : DecoderClient { * Caller must not lock the #DecoderControl object. */ void FlushChunk(); + + /* virtual methods from DecoderClient */ + void Ready(AudioFormat audio_format, + bool seekable, SignedSongTime duration) override; }; #endif diff --git a/src/decoder/plugins/AdPlugDecoderPlugin.cxx b/src/decoder/plugins/AdPlugDecoderPlugin.cxx index a94c8530f..d3077ce5e 100644 --- a/src/decoder/plugins/AdPlugDecoderPlugin.cxx +++ b/src/decoder/plugins/AdPlugDecoderPlugin.cxx @@ -61,8 +61,8 @@ adplug_file_decode(DecoderClient &client, Path path_fs) const AudioFormat audio_format(sample_rate, SampleFormat::S16, 2); assert(audio_format.IsValid()); - decoder_initialized(client, audio_format, false, - SongTime::FromMS(player->songlength())); + client.Ready(audio_format, false, + SongTime::FromMS(player->songlength())); DecoderCommand cmd; diff --git a/src/decoder/plugins/AudiofileDecoderPlugin.cxx b/src/decoder/plugins/AudiofileDecoderPlugin.cxx index b87ba83b5..7c1cbe289 100644 --- a/src/decoder/plugins/AudiofileDecoderPlugin.cxx +++ b/src/decoder/plugins/AudiofileDecoderPlugin.cxx @@ -210,7 +210,7 @@ audiofile_stream_decode(DecoderClient &client, InputStream &is) const unsigned frame_size = (unsigned) afGetVirtualFrameSize(fh, AF_DEFAULT_TRACK, true); - decoder_initialized(client, audio_format, true, total_time); + client.Ready(audio_format, true, total_time); DecoderCommand cmd; do { diff --git a/src/decoder/plugins/DsdiffDecoderPlugin.cxx b/src/decoder/plugins/DsdiffDecoderPlugin.cxx index 7bb7f384f..7af58712d 100644 --- a/src/decoder/plugins/DsdiffDecoderPlugin.cxx +++ b/src/decoder/plugins/DsdiffDecoderPlugin.cxx @@ -437,7 +437,7 @@ dsdiff_stream_decode(DecoderClient &client, InputStream &is) audio_format.sample_rate); /* success: file was recognized */ - decoder_initialized(client, audio_format, is.IsSeekable(), songtime); + client.Ready(audio_format, is.IsSeekable(), songtime); /* every iteration of the following loop decodes one "DSD" chunk from a DFF file */ diff --git a/src/decoder/plugins/DsfDecoderPlugin.cxx b/src/decoder/plugins/DsfDecoderPlugin.cxx index 11877fdba..9818d2233 100644 --- a/src/decoder/plugins/DsfDecoderPlugin.cxx +++ b/src/decoder/plugins/DsfDecoderPlugin.cxx @@ -316,7 +316,7 @@ dsf_stream_decode(DecoderClient &client, InputStream &is) audio_format.sample_rate); /* success: file was recognized */ - decoder_initialized(client, audio_format, is.IsSeekable(), songtime); + client.Ready(audio_format, is.IsSeekable(), songtime); dsf_decode_chunk(client, is, metadata.channels, metadata.sample_rate, diff --git a/src/decoder/plugins/FaadDecoderPlugin.cxx b/src/decoder/plugins/FaadDecoderPlugin.cxx index d9e24c1b5..8dc0d2d95 100644 --- a/src/decoder/plugins/FaadDecoderPlugin.cxx +++ b/src/decoder/plugins/FaadDecoderPlugin.cxx @@ -339,7 +339,7 @@ faad_stream_decode(DecoderClient &client, InputStream &is, /* initialize the MPD core */ - decoder_initialized(client, audio_format, false, total_time); + client.Ready(audio_format, false, total_time); /* the decoder loop */ diff --git a/src/decoder/plugins/FfmpegDecoderPlugin.cxx b/src/decoder/plugins/FfmpegDecoderPlugin.cxx index 9346313ec..2fcdeac24 100644 --- a/src/decoder/plugins/FfmpegDecoderPlugin.cxx +++ b/src/decoder/plugins/FfmpegDecoderPlugin.cxx @@ -689,8 +689,7 @@ FfmpegDecode(DecoderClient &client, InputStream &input, const SignedSongTime total_time = FromFfmpegTimeChecked(av_stream.duration, av_stream.time_base); - decoder_initialized(client, audio_format, - input.IsSeekable(), total_time); + client.Ready(audio_format, input.IsSeekable(), total_time); FfmpegParseMetaData(client, format_context, audio_stream); diff --git a/src/decoder/plugins/FlacCommon.cxx b/src/decoder/plugins/FlacCommon.cxx index 688f2adc1..59d160e65 100644 --- a/src/decoder/plugins/FlacCommon.cxx +++ b/src/decoder/plugins/FlacCommon.cxx @@ -52,9 +52,9 @@ FlacDecoder::Initialize(unsigned sample_rate, unsigned bits_per_sample, audio_format.sample_rate) : SignedSongTime::Negative(); - decoder_initialized(*GetClient(), audio_format, - GetInputStream().IsSeekable(), - duration); + GetClient()->Ready(audio_format, + GetInputStream().IsSeekable(), + duration); initialized = true; return true; diff --git a/src/decoder/plugins/FlacCommon.hxx b/src/decoder/plugins/FlacCommon.hxx index 517fc12fe..eb49ad841 100644 --- a/src/decoder/plugins/FlacCommon.hxx +++ b/src/decoder/plugins/FlacCommon.hxx @@ -32,7 +32,7 @@ struct FlacDecoder : public FlacInput { /** - * Has decoder_initialized() been called yet? + * Has DecoderClient::Ready() been called yet? */ bool initialized = false; @@ -55,7 +55,7 @@ struct FlacDecoder : public FlacInput { :FlacInput(_input_stream, &_client) {} /** - * Wrapper for decoder_initialized(). + * Wrapper for DecoderClient::Ready(). */ bool Initialize(unsigned sample_rate, unsigned bits_per_sample, unsigned channels, FLAC__uint64 total_frames); @@ -77,7 +77,7 @@ private: void OnVorbisComment(const FLAC__StreamMetadata_VorbisComment &vc); /** - * This function attempts to call decoder_initialized() in case there + * This function attempts to call DecoderClient::Ready() in case there * was no STREAMINFO block. This is allowed for nonseekable streams, * where the server sends us only a part of the file, without * providing the STREAMINFO block from the beginning of the file diff --git a/src/decoder/plugins/FluidsynthDecoderPlugin.cxx b/src/decoder/plugins/FluidsynthDecoderPlugin.cxx index 1ec7a68eb..9a64a8013 100644 --- a/src/decoder/plugins/FluidsynthDecoderPlugin.cxx +++ b/src/decoder/plugins/FluidsynthDecoderPlugin.cxx @@ -160,8 +160,7 @@ fluidsynth_file_decode(DecoderClient &client, Path path_fs) MPD core */ const AudioFormat audio_format(sample_rate, SampleFormat::S16, 2); - decoder_initialized(client, audio_format, false, - SignedSongTime::Negative()); + client.Ready(audio_format, false, SignedSongTime::Negative()); DecoderCommand cmd; while (fluid_player_get_status(player) == FLUID_PLAYER_PLAYING) { diff --git a/src/decoder/plugins/GmeDecoderPlugin.cxx b/src/decoder/plugins/GmeDecoderPlugin.cxx index e2b587d5f..b3722d754 100644 --- a/src/decoder/plugins/GmeDecoderPlugin.cxx +++ b/src/decoder/plugins/GmeDecoderPlugin.cxx @@ -171,7 +171,7 @@ gme_file_decode(DecoderClient &client, Path path_fs) SampleFormat::S16, GME_CHANNELS); - decoder_initialized(client, audio_format, true, song_len); + client.Ready(audio_format, true, song_len); gme_err = gme_start_track(emu, container.track); if (gme_err != nullptr) diff --git a/src/decoder/plugins/MadDecoderPlugin.cxx b/src/decoder/plugins/MadDecoderPlugin.cxx index 731ae97f7..17944d42c 100644 --- a/src/decoder/plugins/MadDecoderPlugin.cxx +++ b/src/decoder/plugins/MadDecoderPlugin.cxx @@ -1050,12 +1050,11 @@ mp3_decode(DecoderClient &client, InputStream &input_stream) data.AllocateBuffers(); - decoder_initialized(client, - CheckAudioFormat(data.frame.header.samplerate, - SampleFormat::S24_P32, - MAD_NCHANNELS(&data.frame.header)), - input_stream.IsSeekable(), - data.total_time); + client.Ready(CheckAudioFormat(data.frame.header.samplerate, + SampleFormat::S24_P32, + MAD_NCHANNELS(&data.frame.header)), + input_stream.IsSeekable(), + data.total_time); if (tag != nullptr) { decoder_tag(client, input_stream, std::move(*tag)); diff --git a/src/decoder/plugins/MikmodDecoderPlugin.cxx b/src/decoder/plugins/MikmodDecoderPlugin.cxx index ceacc81b4..f91be1726 100644 --- a/src/decoder/plugins/MikmodDecoderPlugin.cxx +++ b/src/decoder/plugins/MikmodDecoderPlugin.cxx @@ -170,8 +170,7 @@ mikmod_decoder_file_decode(DecoderClient &client, Path path_fs) const AudioFormat audio_format(mikmod_sample_rate, SampleFormat::S16, 2); assert(audio_format.IsValid()); - decoder_initialized(client, audio_format, false, - SignedSongTime::Negative()); + client.Ready(audio_format, false, SignedSongTime::Negative()); Player_Start(handle); diff --git a/src/decoder/plugins/ModplugDecoderPlugin.cxx b/src/decoder/plugins/ModplugDecoderPlugin.cxx index 2bf25a81c..fe666701c 100644 --- a/src/decoder/plugins/ModplugDecoderPlugin.cxx +++ b/src/decoder/plugins/ModplugDecoderPlugin.cxx @@ -151,9 +151,8 @@ mod_decode(DecoderClient &client, InputStream &is) static constexpr AudioFormat audio_format(44100, SampleFormat::S16, 2); assert(audio_format.IsValid()); - decoder_initialized(client, audio_format, - is.IsSeekable(), - SongTime::FromMS(ModPlug_GetLength(f))); + client.Ready(audio_format, is.IsSeekable(), + SongTime::FromMS(ModPlug_GetLength(f))); DecoderCommand cmd; do { diff --git a/src/decoder/plugins/MpcdecDecoderPlugin.cxx b/src/decoder/plugins/MpcdecDecoderPlugin.cxx index bbf850a16..2acb1968d 100644 --- a/src/decoder/plugins/MpcdecDecoderPlugin.cxx +++ b/src/decoder/plugins/MpcdecDecoderPlugin.cxx @@ -174,9 +174,8 @@ mpcdec_decode(DecoderClient &client, InputStream &is) decoder_replay_gain(client, &rgi); - decoder_initialized(client, audio_format, - is.IsSeekable(), - SongTime::FromS(mpc_streaminfo_get_length(&info))); + client.Ready(audio_format, is.IsSeekable(), + SongTime::FromS(mpc_streaminfo_get_length(&info))); DecoderCommand cmd = DecoderCommand::NONE; do { diff --git a/src/decoder/plugins/Mpg123DecoderPlugin.cxx b/src/decoder/plugins/Mpg123DecoderPlugin.cxx index 8c1c45daf..2b81abf74 100644 --- a/src/decoder/plugins/Mpg123DecoderPlugin.cxx +++ b/src/decoder/plugins/Mpg123DecoderPlugin.cxx @@ -210,7 +210,7 @@ mpd_mpg123_file_decode(DecoderClient &client, Path path_fs) SongTime::FromScale(num_samples, audio_format.sample_rate); - decoder_initialized(client, audio_format, true, duration); + client.Ready(audio_format, true, duration); struct mpg123_frameinfo info; if (mpg123_info(handle, &info) != MPG123_OK) { diff --git a/src/decoder/plugins/OpusDecoderPlugin.cxx b/src/decoder/plugins/OpusDecoderPlugin.cxx index 880f9d95c..6e3e9cf4a 100644 --- a/src/decoder/plugins/OpusDecoderPlugin.cxx +++ b/src/decoder/plugins/OpusDecoderPlugin.cxx @@ -93,7 +93,7 @@ public: ~MPDOpusDecoder(); /** - * Has decoder_initialized() been called yet? + * Has DecoderClient::Ready() been called yet? */ bool IsInitialized() const { return previous_channels != 0; @@ -175,8 +175,7 @@ MPDOpusDecoder::OnOggBeginning(const ogg_packet &packet) previous_channels = channels; const AudioFormat audio_format(opus_sample_rate, SampleFormat::S16, channels); - decoder_initialized(client, audio_format, - eos_granulepos > 0, duration); + client.Ready(audio_format, eos_granulepos > 0, duration); frame_size = audio_format.GetFrameSize(); output_buffer = new opus_int16[opus_output_buffer_frames diff --git a/src/decoder/plugins/PcmDecoderPlugin.cxx b/src/decoder/plugins/PcmDecoderPlugin.cxx index 1948a895d..4ee9f7435 100644 --- a/src/decoder/plugins/PcmDecoderPlugin.cxx +++ b/src/decoder/plugins/PcmDecoderPlugin.cxx @@ -143,8 +143,7 @@ pcm_stream_decode(DecoderClient &client, InputStream &is) audio_format.sample_rate) : SignedSongTime::Negative(); - decoder_initialized(client, audio_format, - is.IsSeekable(), total_time); + client.Ready(audio_format, is.IsSeekable(), total_time); StaticFifoBuffer buffer; diff --git a/src/decoder/plugins/SidplayDecoderPlugin.cxx b/src/decoder/plugins/SidplayDecoderPlugin.cxx index 552569996..97c0e7c50 100644 --- a/src/decoder/plugins/SidplayDecoderPlugin.cxx +++ b/src/decoder/plugins/SidplayDecoderPlugin.cxx @@ -337,7 +337,7 @@ sidplay_file_decode(DecoderClient &client, Path path_fs) const AudioFormat audio_format(48000, SampleFormat::S16, channels); assert(audio_format.IsValid()); - decoder_initialized(client, audio_format, true, duration); + client.Ready(audio_format, true, duration); /* .. and play */ diff --git a/src/decoder/plugins/SndfileDecoderPlugin.cxx b/src/decoder/plugins/SndfileDecoderPlugin.cxx index bca24a6af..1d3efc293 100644 --- a/src/decoder/plugins/SndfileDecoderPlugin.cxx +++ b/src/decoder/plugins/SndfileDecoderPlugin.cxx @@ -205,8 +205,7 @@ sndfile_stream_decode(DecoderClient &client, InputStream &is) sndfile_sample_format(info), info.channels); - decoder_initialized(client, audio_format, info.seekable, - sndfile_duration(info)); + client.Ready(audio_format, info.seekable, sndfile_duration(info)); char buffer[16384]; diff --git a/src/decoder/plugins/VorbisDecoderPlugin.cxx b/src/decoder/plugins/VorbisDecoderPlugin.cxx index 766107490..86a4de9bb 100644 --- a/src/decoder/plugins/VorbisDecoderPlugin.cxx +++ b/src/decoder/plugins/VorbisDecoderPlugin.cxx @@ -175,8 +175,7 @@ VorbisDecoder::SubmitInit() audio_format.sample_rate) : SignedSongTime::Negative(); - decoder_initialized(client, audio_format, - eos_granulepos > 0, duration); + client.Ready(audio_format, eos_granulepos > 0, duration); } bool diff --git a/src/decoder/plugins/WavpackDecoderPlugin.cxx b/src/decoder/plugins/WavpackDecoderPlugin.cxx index 51310eb7d..3abd9b21c 100644 --- a/src/decoder/plugins/WavpackDecoderPlugin.cxx +++ b/src/decoder/plugins/WavpackDecoderPlugin.cxx @@ -168,7 +168,7 @@ wavpack_decode(DecoderClient &client, WavpackContext *wpc, bool can_seek) const uint32_t samples_requested = ARRAY_SIZE(chunk) / audio_format.channels; - decoder_initialized(client, audio_format, can_seek, total_time); + client.Ready(audio_format, can_seek, total_time); DecoderCommand cmd = decoder_get_command(client); while (cmd != DecoderCommand::STOP) { diff --git a/src/decoder/plugins/WildmidiDecoderPlugin.cxx b/src/decoder/plugins/WildmidiDecoderPlugin.cxx index 5194c0113..7e29fdd47 100644 --- a/src/decoder/plugins/WildmidiDecoderPlugin.cxx +++ b/src/decoder/plugins/WildmidiDecoderPlugin.cxx @@ -103,7 +103,7 @@ wildmidi_file_decode(DecoderClient &client, Path path_fs) SongTime::FromScale(info->approx_total_samples, WILDMIDI_SAMPLE_RATE); - decoder_initialized(client, audio_format, true, duration); + client.Ready(audio_format, true, duration); DecoderCommand cmd; do { diff --git a/test/FakeDecoderAPI.cxx b/test/FakeDecoderAPI.cxx index 08e49e401..8b61ca5d3 100644 --- a/test/FakeDecoderAPI.cxx +++ b/test/FakeDecoderAPI.cxx @@ -29,22 +29,20 @@ #include void -decoder_initialized(DecoderClient &client, - const AudioFormat audio_format, - gcc_unused bool seekable, - SignedSongTime duration) +FakeDecoder::Ready(const AudioFormat audio_format, + gcc_unused bool seekable, + SignedSongTime duration) { - auto &decoder = (FakeDecoder &)client; struct audio_format_string af_string; - assert(!decoder.initialized); + assert(!initialized); assert(audio_format.IsValid()); fprintf(stderr, "audio_format=%s duration=%f\n", audio_format_to_string(audio_format, &af_string), duration.ToDoubleS()); - decoder.initialized = true; + initialized = true; } DecoderCommand diff --git a/test/FakeDecoderAPI.hxx b/test/FakeDecoderAPI.hxx index 87a58a290..fadbbb5e8 100644 --- a/test/FakeDecoderAPI.hxx +++ b/test/FakeDecoderAPI.hxx @@ -30,6 +30,10 @@ struct FakeDecoder final : DecoderClient { Cond cond; bool initialized = false; + + /* virtual methods from DecoderClient */ + void Ready(AudioFormat audio_format, + bool seekable, SignedSongTime duration) override; }; #endif