Filter.hxx 1.88 KB
Newer Older
1
/*
Max Kellermann's avatar
Max Kellermann committed
2
 * Copyright 2003-2017 The Music Player Daemon Project
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 * http://www.musicpd.org
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

20 21
#ifndef MPD_FILTER_HXX
#define MPD_FILTER_HXX
22

23 24
#include "AudioFormat.hxx"

25
#include <assert.h>
26

27
template<typename T> struct ConstBuffer;
28 29

class Filter {
30 31 32
protected:
	AudioFormat out_audio_format;

33
	explicit Filter(AudioFormat _out_audio_format) noexcept
34 35 36
		:out_audio_format(_out_audio_format) {
		assert(out_audio_format.IsValid());
	}
37

38
public:
39
	virtual ~Filter() noexcept {}
40 41

	/**
42
	 * Returns the #AudioFormat produced by FilterPCM().
43
	 */
44
	const AudioFormat &GetOutAudioFormat() const noexcept {
45 46
		return out_audio_format;
	}
47

48 49 50
	/**
	 * Reset the filter's state, e.g. drop/flush buffers.
	 */
51
	virtual void Reset() noexcept {
52 53
	}

54 55 56
	/**
	 * Filters a block of PCM data.
	 *
57 58
	 * Throws std::runtime_error on error.
	 *
59 60
	 * @param src the input buffer
	 * @return the destination buffer on success (will be
61
	 * invalidated by deleting this object or the next FilterPCM()
62
	 * or Reset() call)
63
	 */
64
	virtual ConstBuffer<void> FilterPCM(ConstBuffer<void> src) = 0;
65 66 67 68 69 70

	/**
	 * Flush pending data and return it.  This should be called
	 * repepatedly until it returns nullptr.
	 */
	virtual ConstBuffer<void> Flush();
71
};
72 73

#endif