Pull all interfaces into a single interface: Filter.
[sonitus.git] / src / main / java / net / pterodactylus / sonitus / data / Filter.java
1 /*
2  * Sonitus - Filter.java - Copyright © 2013 David Roden
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 package net.pterodactylus.sonitus.data;
19
20 import java.io.IOException;
21 import java.util.List;
22
23 /**
24  * A filter is both a source and a sink for audio data. It is used to process
25  * the audio date in whatever way seems appropriate.
26  *
27  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
28  */
29 public interface Filter {
30
31         /**
32          * Adds the given listener to the list of registered listeners.
33          *
34          * @param metadataListener
35          *              The metadata listener to add
36          */
37         void addMetadataListener(MetadataListener metadataListener);
38
39         /**
40          * Removes the given listener from the list of registered listeners.
41          *
42          * @param metadataListener
43          *              The metadata listener to remove
44          */
45         void removeMetadataListener(MetadataListener metadataListener);
46
47         /**
48          * Returns the name of this filter.
49          *
50          * @return The name of this filter
51          */
52         String name();
53
54         /**
55          * Returns the controllers offered by this filter.
56          *
57          * @return The controllers of this filter
58          */
59         List<Controller<?>> controllers();
60
61         /**
62          * Returns the metadata of the audio stream.
63          *
64          * @return The metadata of the audio stream
65          */
66         Metadata metadata();
67
68         /**
69          * Notifies the sink that the metadata of the audio stream has changed. This
70          * method should return as fast as possible, i.e. every heavy lifting should be
71          * done from another thread.
72          *
73          * @param metadata
74          *              The new metadata
75          */
76         void metadataUpdated(Metadata metadata);
77
78         /**
79          * Retrieves data from the audio stream.
80          *
81          * @param bufferSize
82          *              The maximum amount of bytes to retrieve from the audio stream
83          * @return A buffer filled with up to {@code bufferSize} bytes of data; the
84          *         returned buffer may contain less data than requested but will not
85          *         contain excess elements
86          * @throws IOException
87          *              if an I/O error occurs
88          */
89         byte[] get(int bufferSize) throws IOException;
90
91         /**
92          * Opens this sink using the format parameters of the given metadata.
93          *
94          * @param metadata
95          *              The metadata of the stream
96          * @throws IOException
97          *              if an I/O error occurs
98          */
99         void open(Metadata metadata) throws IOException;
100
101         /** Closes this sink. */
102         void close();
103
104         /**
105          * Processes the given buffer of data.
106          *
107          * @param buffer
108          *              The data to process
109          * @throws IOException
110          *              if an I/O error occurs
111          */
112         void process(byte[] buffer) throws IOException;
113
114 }