1 /* 2 * Copyright 2003-2021 The Music Player Daemon Project 3 * http://www.musicpd.org 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License along 16 * with this program; if not, write to the Free Software Foundation, Inc., 17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 */ 19 20 #ifndef CHROMAPRINT_DECODER_CLIENT_HXX 21 #define CHROMAPRINT_DECODER_CLIENT_HXX 22 23 #include "Context.hxx" 24 #include "decoder/Client.hxx" 25 #include "thread/Mutex.hxx" 26 27 #include <cstdint> 28 #include <exception> 29 #include <memory> 30 31 class PcmConvert; 32 33 class ChromaprintDecoderClient : public DecoderClient { 34 bool ready = false; 35 36 std::unique_ptr<PcmConvert> convert; 37 38 Chromaprint::Context chromaprint; 39 40 uint64_t remaining_bytes; 41 42 protected: 43 /** 44 * This is set when an I/O error occurs while decoding; it 45 * will be rethrown by Finish(). 46 */ 47 std::exception_ptr error; 48 49 public: 50 Mutex mutex; 51 52 ChromaprintDecoderClient(); 53 ~ChromaprintDecoderClient() noexcept; 54 IsReady() const55 bool IsReady() const noexcept { 56 return ready; 57 } 58 Reset()59 void Reset() noexcept { 60 } 61 62 void Finish(); 63 GetFingerprint() const64 std::string GetFingerprint() const { 65 return chromaprint.GetFingerprint(); 66 } 67 68 /* virtual methods from DecoderClient */ 69 void Ready(AudioFormat audio_format, 70 bool seekable, SignedSongTime duration) noexcept override; 71 GetCommand()72 DecoderCommand GetCommand() noexcept override { 73 return !error && (!ready || remaining_bytes > 0) 74 ? DecoderCommand::NONE 75 : DecoderCommand::STOP; 76 } 77 CommandFinished()78 void CommandFinished() noexcept override {} 79 GetSeekTime()80 SongTime GetSeekTime() noexcept override { 81 return SongTime::zero(); 82 } 83 GetSeekFrame()84 uint64_t GetSeekFrame() noexcept override { 85 return 0; 86 } 87 SeekError()88 void SeekError() noexcept override {} 89 90 //InputStreamPtr OpenUri(const char *) override; 91 92 size_t Read(InputStream &is, 93 void *buffer, size_t length) noexcept override; 94 SubmitTimestamp(FloatDuration)95 void SubmitTimestamp(FloatDuration) noexcept override {} 96 DecoderCommand SubmitData(InputStream *is, 97 const void *data, size_t length, 98 uint16_t kbit_rate) noexcept override; 99 SubmitTag(InputStream *,Tag &&)100 DecoderCommand SubmitTag(InputStream *, Tag &&) noexcept override { 101 return GetCommand(); 102 } 103 SubmitReplayGain(const ReplayGainInfo *)104 void SubmitReplayGain(const ReplayGainInfo *) noexcept override {} SubmitMixRamp(MixRampInfo &&)105 void SubmitMixRamp(MixRampInfo &&) noexcept override {} 106 }; 107 108 #endif 109