FilterInternal.hxx 2.17 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 20 21 22 23 24
 * 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.
 */

/** \file
 *
 * Internal stuff for the filter core and filter plugins.
 */

Max Kellermann's avatar
Max Kellermann committed
25 26
#ifndef MPD_FILTER_INTERNAL_HXX
#define MPD_FILTER_INTERNAL_HXX
27

28 29
#include "AudioFormat.hxx"

30
#include <assert.h>
31 32
#include <stddef.h>

33
struct AudioFormat;
34
template<typename T> struct ConstBuffer;
35 36

class Filter {
37 38 39 40
protected:
	AudioFormat out_audio_format;

	explicit Filter(AudioFormat _out_audio_format)
41 42 43
		:out_audio_format(_out_audio_format) {
		assert(out_audio_format.IsValid());
	}
44

45 46 47 48
public:
	virtual ~Filter() {}

	/**
49
	 * Returns the #AudioFormat produced by FilterPCM().
50
	 */
51 52 53
	const AudioFormat &GetOutAudioFormat() const {
		return out_audio_format;
	}
54

55 56 57 58 59 60
	/**
	 * Reset the filter's state, e.g. drop/flush buffers.
	 */
	virtual void Reset() {
	}

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

74 75 76 77 78 79 80
class PreparedFilter {
public:
	virtual ~PreparedFilter() {}

	/**
	 * Opens the filter, preparing it for FilterPCM().
	 *
81 82
	 * Throws std::runtime_error on error.
	 *
83 84 85 86
	 * @param af the audio format of incoming data; the
	 * plugin may modify the object to enforce another input
	 * format
	 */
87
	virtual Filter *Open(AudioFormat &af) = 0;
88 89
};

90
#endif