X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsonitus%2Fdata%2FFilter.java;h=ec8fb94d74da19e6305f63e78760a543341af3e4;hb=633a841142f978235ed9f745b6ba16c278963e62;hp=94c986c9337b486ab0e3cea9dc8ad571341c86d2;hpb=367edf1b6da27a73e1f822d7087a3a764ebff3e8;p=sonitus.git diff --git a/src/main/java/net/pterodactylus/sonitus/data/Filter.java b/src/main/java/net/pterodactylus/sonitus/data/Filter.java index 94c986c..ec8fb94 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/Filter.java +++ b/src/main/java/net/pterodactylus/sonitus/data/Filter.java @@ -17,31 +17,98 @@ package net.pterodactylus.sonitus.data; +import java.io.IOException; +import java.util.List; + /** - * A filter processes an input to produce an output. + * 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 David ‘Bombe’ Roden */ public interface Filter { /** - * Returns whether this filter understands the given format. + * 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> 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 format - * The format to check for - * @return {@code true} if this filter understands the given format, {@code - * false} otherwise + * @param metadata + * The new metadata */ - boolean understands(Format format); + 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(); /** - * Returns whether this filter can produce the given format. + * Processes the given buffer of data. * - * @param format - * The format to check for - * @return {@code true} if this filter can produce the given format, {@code - * false} otherwise + * @param buffer + * The data to process + * @throws IOException + * if an I/O error occurs */ - boolean produces(Format format); + void process(byte[] buffer) throws IOException; }