Pull all interfaces into a single interface: Filter.
[sonitus.git] / src / main / java / net / pterodactylus / sonitus / data / Filter.java
index c251cfe..ec8fb94 100644 (file)
 
 package net.pterodactylus.sonitus.data;
 
+import java.io.IOException;
+import java.util.List;
+
 /**
- * A filter is both a {@link Source} and a {@link Sink}. It is used to process
+ * A filter is both a source and a sink for audio data. It is used to process
  * the audio date in whatever way seems appropriate.
  *
  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
  */
-public interface Filter extends ControlledComponent, Source, Sink {
+public interface Filter {
+
+       /**
+        * Adds the given listener to the list of registered listeners.
+        *
+        * @param metadataListener
+        *              The metadata listener to add
+        */
+       void addMetadataListener(MetadataListener metadataListener);
+
+       /**
+        * Removes the given listener from the list of registered listeners.
+        *
+        * @param metadataListener
+        *              The metadata listener to remove
+        */
+       void removeMetadataListener(MetadataListener metadataListener);
+
+       /**
+        * Returns the name of this filter.
+        *
+        * @return The name of this filter
+        */
+       String name();
+
+       /**
+        * Returns the controllers offered by this filter.
+        *
+        * @return The controllers of this filter
+        */
+       List<Controller<?>> controllers();
+
+       /**
+        * Returns the metadata of the audio stream.
+        *
+        * @return The metadata of the audio stream
+        */
+       Metadata metadata();
+
+       /**
+        * Notifies the sink that the metadata of the audio stream has changed. This
+        * method should return as fast as possible, i.e. every heavy lifting should be
+        * done from another thread.
+        *
+        * @param metadata
+        *              The new metadata
+        */
+       void metadataUpdated(Metadata metadata);
+
+       /**
+        * Retrieves data from the audio stream.
+        *
+        * @param bufferSize
+        *              The maximum amount of bytes to retrieve from the audio stream
+        * @return A buffer filled with up to {@code bufferSize} bytes of data; the
+        *         returned buffer may contain less data than requested but will not
+        *         contain excess elements
+        * @throws IOException
+        *              if an I/O error occurs
+        */
+       byte[] get(int bufferSize) throws IOException;
+
+       /**
+        * Opens this sink using the format parameters of the given metadata.
+        *
+        * @param metadata
+        *              The metadata of the stream
+        * @throws IOException
+        *              if an I/O error occurs
+        */
+       void open(Metadata metadata) throws IOException;
+
+       /** Closes this sink. */
+       void close();
+
+       /**
+        * Processes the given buffer of data.
+        *
+        * @param buffer
+        *              The data to process
+        * @throws IOException
+        *              if an I/O error occurs
+        */
+       void process(byte[] buffer) throws IOException;
 
 }