+++ /dev/null
-/*
- * Sonitus - Format.java - Copyright © 2013 David Roden
- *
- * 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 3 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, see <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sonitus.data;
-
-/**
- * A format is a combination of a number of channels, a sampling frequency, and
- * an encoding scheme.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public class Format {
-
- /** Constant for an unknown number of channels. */
- public static final int UNKNOWN_CHANNELS = -1;
-
- /** Constant for an unknown frequency. */
- public static final int UNKNOWN_FREQUENCY = -1;
-
- /** Constant for an unknown format. */
- public static final String UNKNOWN_ENCODING = "UNKNOWN";
-
- /** The number of channels of this format. */
- private final int channels;
-
- /** The sampling frequency of this format. */
- private final int frequency;
-
- /** The encoding of this format. */
- private final String encoding;
-
- /**
- * Creates a new format.
- *
- * @param channels
- * The number of channels of this format
- * @param frequency
- * The sampling frequency of this format
- * @param encoding
- * The encoding of this format
- */
- public Format(int channels, int frequency, String encoding) {
- this.channels = channels;
- this.frequency = frequency;
- this.encoding = encoding;
- }
-
- //
- // ACCESSORS
- //
-
- /**
- * Returns the number of channels of this format.
- *
- * @return The number of channels of this format
- */
- public int channels() {
- return channels;
- }
-
- /**
- * Returns the sampling frequency of this format.
- *
- * @return The sampling frequency of this format
- */
- public int frequency() {
- return frequency;
- }
-
- /**
- * Returns the encoding of this format
- *
- * @return The encoding of this format
- */
- public String encoding() {
- return encoding;
- }
-
- //
- // MUTATORS
- //
-
- /**
- * Returns a format with the same parameters as this format and the given
- * number of channels.
- *
- * @param channels
- * The new number of channels
- * @return A new format with the given number of channels
- */
- public Format channels(int channels) {
- return new Format(channels, frequency, encoding);
- }
-
- /**
- * Returns a new format with the same parameters as this format and the given
- * frequency.
- *
- * @param frequency
- * The new frequency
- * @return A new format with the given frequency
- */
- public Format frequency(int frequency) {
- return new Format(channels, frequency, encoding);
- }
-
- /**
- * Returns a new format with the same parameters as this format and the given
- * encoding.
- *
- * @param encoding
- * The new encoding
- * @return A new format with the given encoding
- */
- public Format encoding(String encoding) {
- return new Format(channels, frequency, encoding);
- }
-
- //
- // OBJECT METHODS
- //
-
- @Override
- public int hashCode() {
- return (channels << 16) ^ frequency ^ encoding.toUpperCase().hashCode();
- }
-
- @Override
- public boolean equals(Object object) {
- if ((object == null) || (getClass() != object.getClass())) {
- return false;
- }
- Format format = (Format) object;
- return (format.channels == channels) && (format.frequency == frequency) && format.encoding.equalsIgnoreCase(encoding());
- }
-
- @Override
- public String toString() {
- return String.format("%d Channel%s, %d Hz, %s", channels, channels != 1 ? "s" : "", frequency, encoding);
- }
-
-}
import com.google.common.base.Optional;
/**
- * Metadata contains information about a source, e.g. the name of the content,
- * the artist performing it, dates, comments, URLs, etc. The {@link Format},
- * however, is not part of the metadata because a {@link Source} already exposes
- * it.
+ * Metadata contains information about a source, e.g. the number of channels,
+ * the frequency, the encoding, the name of the content, the artist performing
+ * it, dates, comments, URLs, etc.
* <p/>
* Metadata, once created, is immutable.
*
*/
public class Metadata {
+ /** Constant for an unknown number of channels. */
+ public static final int UNKNOWN_CHANNELS = -1;
+
+ /** Constant for an unknown frequency. */
+ public static final int UNKNOWN_FREQUENCY = -1;
+
+ /** Constant for an unknown metadata. */
+ public static final String UNKNOWN_ENCODING = "UNKNOWN";
+
+ /** The number of channels of this metadata. */
+ private final int channels;
+
+ /** The sampling frequency of this metadata. */
+ private final int frequency;
+
+ /** The encoding of this metadata. */
+ private final String encoding;
+
/** The artist performing the content. */
private final Optional<String> artist;
private final Optional<String> name;
/** Creates empty metadata. */
- public Metadata() {
- this(null, null);
+ public Metadata(int channels, int frequency, String encoding) {
+ this(channels, frequency, encoding, null, null);
}
/**
* @param name
* The name of the content (may be {@code null})
*/
- private Metadata(String artist, String name) {
+ private Metadata(int channels, int frequency, String encoding, String artist, String name) {
+ this.channels = channels;
+ this.frequency = frequency;
+ this.encoding = encoding;
this.artist = Optional.fromNullable(artist);
this.name = Optional.fromNullable(name);
}
+ //
+ // ACCESSORS
+ //
+
+ /**
+ * Returns the number of channels of this metadata.
+ *
+ * @return The number of channels of this metadata
+ */
+ public int channels() {
+ return channels;
+ }
+
+ /**
+ * Returns a metadata with the same parameters as this metadata and the given
+ * number of channels.
+ *
+ * @param channels
+ * The new number of channels
+ * @return A new metadata with the given number of channels
+ */
+ public Metadata channels(int channels) {
+ return new Metadata(channels, frequency, encoding, artist.orNull(), name.orNull());
+ }
+
+ /**
+ * Returns the sampling frequency of this metadata.
+ *
+ * @return The sampling frequency of this metadata
+ */
+ public int frequency() {
+ return frequency;
+ }
+
+ /**
+ * Returns a new metadata with the same parameters as this metadata and the
+ * given frequency.
+ *
+ * @param frequency
+ * The new frequency
+ * @return A new metadata with the given frequency
+ */
+ public Metadata frequency(int frequency) {
+ return new Metadata(channels, frequency, encoding, artist.orNull(), name.orNull());
+ }
+
+ /**
+ * Returns the encoding of this metadata
+ *
+ * @return The encoding of this metadata
+ */
+ public String encoding() {
+ return encoding;
+ }
+
+ /**
+ * Returns a new metadata with the same parameters as this metadata and the
+ * given encoding.
+ *
+ * @param encoding
+ * The new encoding
+ * @return A new metadata with the given encoding
+ */
+ public Metadata encoding(String encoding) {
+ return new Metadata(channels, frequency, encoding, artist.orNull(), name.orNull());
+ }
+
/**
* Returns the artist, if any.
*
* @return New metadata with a changed artist
*/
public Metadata artist(String artist) {
- return new Metadata(artist, this.artist.orNull());
+ return new Metadata(channels, frequency, encoding, artist, this.artist.orNull());
}
/**
* @return New metadata with a changed name
*/
public Metadata name(String name) {
- return new Metadata(name, this.name.orNull());
+ return new Metadata(channels, frequency, encoding, name, this.name.orNull());
+ }
+
+ //
+ // OBJECT METHODS
+ //
+
+ @Override
+ public int hashCode() {
+ int hashCode = (channels << 16) ^ frequency ^ encoding.toUpperCase().hashCode();
+ if (artist.isPresent()) {
+ hashCode ^= artist.get().hashCode();
+ }
+ if (name.isPresent()) {
+ hashCode ^= name.get().hashCode();
+ }
+ return hashCode;
+ }
+
+ @Override
+ public boolean equals(Object object) {
+ if ((object == null) || (getClass() != object.getClass())) {
+ return false;
+ }
+ Metadata metadata = (Metadata) object;
+ if ((metadata.channels != channels) || (metadata.frequency != frequency) || !metadata.encoding.equalsIgnoreCase(encoding())) {
+ return false;
+ }
+ if (artist.equals(metadata.artist)) {
+ return false;
+ }
+ if (name.equals(metadata.name)) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder string = new StringBuilder();
+ string.append(String.format("%d Channel%s, %d Hz, %s:", channels, channels != 1 ? "s" : "", frequency, encoding));
+ if (artist.isPresent()) {
+ string.append(" Artist(").append(artist.get()).append(")");
+ }
+ if (name.isPresent()) {
+ string.append(" Name(").append(name.get()).append(")");
+ }
+ return string.toString();
}
}
* @param source
* The source to connect to
* @throws ConnectException
- * if the source can not be connected, e.g. due to a {@link Format} mismatch
+ * if the source can not be connected, e.g. due to a {@link Metadata}
+ * mismatch
*/
void connect(Source source) throws ConnectException;
public interface Source {
/**
- * Returns the format of this source.
- *
- * @return The format of this source
- */
- Format format();
-
- /**
* Returns the metadata of this source.
*
* @return The metadata of this source
import net.pterodactylus.sonitus.data.ConnectException;
import net.pterodactylus.sonitus.data.Connection;
import net.pterodactylus.sonitus.data.Filter;
-import net.pterodactylus.sonitus.data.Format;
import net.pterodactylus.sonitus.data.Metadata;
import net.pterodactylus.sonitus.data.Source;
import net.pterodactylus.sonitus.io.InputStreamDrainer;
//
@Override
- public Format format() {
- return source.format();
- }
-
- @Override
public Metadata metadata() {
return source.metadata();
}
this.source = source;
try {
- final Process process = Runtime.getRuntime().exec(Iterables.toArray(ImmutableList.<String>builder().add(binary(source.format())).addAll(parameters(source.format())).build(), String.class));
+ final Process process = Runtime.getRuntime().exec(Iterables.toArray(ImmutableList.<String>builder().add(binary(source.metadata())).addAll(parameters(source.metadata())).build(), String.class));
final InputStream processOutput = process.getInputStream();
final OutputStream processInput = process.getOutputStream();
final InputStream processError = process.getErrorStream();
/**
* Returns the location of the binary to execute.
*
- * @param format
- * The format being processed
+ * @param metadata
+ * The metadata being processed
* @return The location of the binary to execute
*/
- protected abstract String binary(Format format);
+ protected abstract String binary(Metadata metadata);
/**
* Returns the parameters for the binary.
*
- * @param format
- * The format being processed
+ * @param metadata
+ * The metadata being processed
* @return The parameters for the binary
*/
- protected abstract Iterable<String> parameters(Format format);
+ protected abstract Iterable<String> parameters(Metadata metadata);
}
import static com.google.common.base.Preconditions.*;
import net.pterodactylus.sonitus.data.ConnectException;
-import net.pterodactylus.sonitus.data.Format;
+import net.pterodactylus.sonitus.data.Metadata;
import net.pterodactylus.sonitus.data.Source;
/**
public abstract class ExternalMp3Decoder extends ExternalFilter {
@Override
- public Format format() {
- return super.format().encoding("PCM");
+ public Metadata metadata() {
+ return super.metadata().encoding("PCM");
}
@Override
public void connect(Source source) throws ConnectException {
checkNotNull(source, "source must not be null");
- checkState(source.format().encoding().equalsIgnoreCase("MP3"), "source must be MP3-encoded");
+ checkState(source.metadata().encoding().equalsIgnoreCase("MP3"), "source must be MP3-encoded");
super.connect(source);
}
package net.pterodactylus.sonitus.data.filter;
import net.pterodactylus.sonitus.data.ConnectException;
-import net.pterodactylus.sonitus.data.Format;
+import net.pterodactylus.sonitus.data.Metadata;
import net.pterodactylus.sonitus.data.Source;
import com.google.common.base.Preconditions;
/**
* Basic {@link ExternalFilter} implementation that verifies that the connected
- * source is PCM-encoded and that returns an MP3-encoded format.
+ * source is PCM-encoded and that returns an MP3-encoded metadata.
*
* @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
*/
public abstract class ExternalMp3Encoder extends ExternalFilter {
@Override
- public Format format() {
- return super.format().encoding("MP3");
+ public Metadata metadata() {
+ return super.metadata().encoding("MP3");
}
@Override
public void connect(Source source) throws ConnectException {
Preconditions.checkNotNull(source, "source must not be null");
- Preconditions.checkState(source.format().encoding().equalsIgnoreCase("PCM"), "source must be PCM-encoded");
+ Preconditions.checkState(source.metadata().encoding().equalsIgnoreCase("PCM"), "source must be PCM-encoded");
super.connect(source);
}
package net.pterodactylus.sonitus.data.filter;
-import net.pterodactylus.sonitus.data.Format;
+import net.pterodactylus.sonitus.data.Metadata;
import com.google.common.collect.ImmutableList;
//
@Override
- protected String binary(Format format) {
+ protected String binary(Metadata metadata) {
return binary;
}
@Override
- protected Iterable<String> parameters(Format format) {
+ protected Iterable<String> parameters(Metadata metadata) {
ImmutableList.Builder parameters = ImmutableList.builder();
parameters.add("--mp3input").add("--decode").add("-t");
if (swapBytes) {
import java.util.Arrays;
-import net.pterodactylus.sonitus.data.Format;
+import net.pterodactylus.sonitus.data.Metadata;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
//
@Override
- protected String binary(Format format) {
+ protected String binary(Metadata metadata) {
return binary;
}
@Override
- protected Iterable<String> parameters(Format format) {
+ protected Iterable<String> parameters(Metadata metadata) {
ImmutableList.Builder parameters = ImmutableList.builder();
parameters.add("-r");
- parameters.add("-s").add(String.valueOf(format.frequency() / 1000.0));
+ parameters.add("-s").add(String.valueOf(metadata.frequency() / 1000.0));
if (swapBytes) {
parameters.add("-x");
}
import net.pterodactylus.sonitus.data.ConnectException;
import net.pterodactylus.sonitus.data.Filter;
-import net.pterodactylus.sonitus.data.Format;
import net.pterodactylus.sonitus.data.Metadata;
import net.pterodactylus.sonitus.data.ReusableSink;
import net.pterodactylus.sonitus.data.Source;
}
@Override
- public Format format() {
- synchronized (syncObject) {
- return connection.source.format();
- }
- }
-
- @Override
public Metadata metadata() {
synchronized (syncObject) {
return connection.source.metadata();
public void connect(Source source) throws ConnectException {
checkNotNull(source, "source must not be null");
if ((connection != null) && (connection.source != null)) {
- checkArgument(connection.source.format().equals(source.format()), "source’s format must equal this sink’s format");
+ checkArgument(connection.source.metadata().channels() == source.metadata().channels(), "source’s channel count must equal existing source’s channel count");
+ checkArgument(connection.source.metadata().frequency() == source.metadata().frequency(), "source’s frequency must equal existing source’s frequency");
+ checkArgument(connection.source.metadata().encoding().equalsIgnoreCase(source.metadata().encoding()), "source’s encoding must equal existing source’s encoding");
}
if (connection == null) {
import net.pterodactylus.sonitus.data.ConnectException;
import net.pterodactylus.sonitus.data.Connection;
import net.pterodactylus.sonitus.data.Filter;
-import net.pterodactylus.sonitus.data.Format;
import net.pterodactylus.sonitus.data.Metadata;
import net.pterodactylus.sonitus.data.Source;
/** The limiting rate in bytes/second. */
private final int rate;
- /** The source’s format. */
+ /** The source. */
private Source source;
/** The input stream to read from. */
//
@Override
- public Format format() {
- return source.format();
- }
-
- @Override
public Metadata metadata() {
return source.metadata();
}
import net.pterodactylus.sonitus.data.ConnectException;
import net.pterodactylus.sonitus.data.Connection;
-import net.pterodactylus.sonitus.data.Format;
+import net.pterodactylus.sonitus.data.Metadata;
import net.pterodactylus.sonitus.data.Sink;
import net.pterodactylus.sonitus.data.Source;
@Override
public void connect(Source source) throws ConnectException {
checkNotNull(source, "source must not be null");
- checkState(source.format().encoding().equalsIgnoreCase("PCM"), "source must be PCM-encoded");
+ checkState(source.metadata().encoding().equalsIgnoreCase("PCM"), "source must be PCM-encoded");
- final Format sourceFormat = source.format();
- AudioFormat audioFormat = new AudioFormat(sourceFormat.frequency(), 16, sourceFormat.channels(), true, false);
+ final Metadata sourceMetadata = source.metadata();
+ AudioFormat audioFormat = new AudioFormat(sourceMetadata.frequency(), 16, sourceMetadata.channels(), true, false);
try {
final SourceDataLine sourceDataLine = AudioSystem.getSourceDataLine(audioFormat);
sourceDataLine.open(audioFormat);
@Override
protected int bufferSize() {
- return sourceFormat.channels() * sourceFormat.frequency() * 2;
+ return sourceMetadata.channels() * sourceMetadata.frequency() * 2;
}
@Override
import net.pterodactylus.sonitus.data.ConnectException;
import net.pterodactylus.sonitus.data.Connection;
-import net.pterodactylus.sonitus.data.Format;
import net.pterodactylus.sonitus.data.Metadata;
import net.pterodactylus.sonitus.data.Sink;
import net.pterodactylus.sonitus.data.Source;
sendLine(socketOutputStream, String.format("SOURCE /%s ICE/1.0", mountPoint));
sendLine(socketOutputStream, String.format("Authorization: Basic %s", generatePassword(password)));
- sendLine(socketOutputStream, String.format("Content-Type: %s", getContentType(source.format())));
+ sendLine(socketOutputStream, String.format("Content-Type: %s", getContentType(source.metadata())));
sendLine(socketOutputStream, String.format("ICE-Name: %s", serverName));
sendLine(socketOutputStream, String.format("ICE-Description: %s", serverDescription));
sendLine(socketOutputStream, String.format("ICE-Genre: %s", genre));
}
/**
- * Returns a MIME type for the given format. Currently only Vorbis, MP3, and
+ * Returns a MIME type for the given metadata. Currently only Vorbis, MP3, and
* PCM formats are recognized.
*
- * @param format
- * The format to get a MIME type for
- * @return The MIME type of the format
+ * @param metadata
+ * The metadata to get a MIME type for
+ * @return The MIME type of the metadata
*/
- private static String getContentType(Format format) {
- String encoding = format.encoding();
+ private static String getContentType(Metadata metadata) {
+ String encoding = metadata.encoding();
if ("Vorbis".equalsIgnoreCase(encoding)) {
return "audio/ogg";
}
package net.pterodactylus.sonitus.data.source;
import static com.google.common.base.Preconditions.*;
-import static net.pterodactylus.sonitus.data.Format.UNKNOWN_CHANNELS;
-import static net.pterodactylus.sonitus.data.Format.UNKNOWN_ENCODING;
-import static net.pterodactylus.sonitus.data.Format.UNKNOWN_FREQUENCY;
+import static net.pterodactylus.sonitus.data.Metadata.UNKNOWN_CHANNELS;
+import static net.pterodactylus.sonitus.data.Metadata.UNKNOWN_ENCODING;
+import static net.pterodactylus.sonitus.data.Metadata.UNKNOWN_FREQUENCY;
import java.io.EOFException;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Arrays;
-import net.pterodactylus.sonitus.data.Format;
import net.pterodactylus.sonitus.data.Metadata;
import net.pterodactylus.sonitus.data.Source;
import net.pterodactylus.sonitus.io.IdentifyingInputStream;
/** The path of the file. */
private final String path;
- /** The identified format of the file. */
- private final Format format;
+ /** The identified metadata of the file. */
+ private final Metadata metadata;
/** The input stream. */
private InputStream fileInputStream;
/* identify file type. */
Optional<IdentifyingInputStream> identifyingInputStream = IdentifyingInputStream.create(new FileInputStream(path));
if (identifyingInputStream.isPresent()) {
- format = identifyingInputStream.get().format();
+ metadata = identifyingInputStream.get().metadata();
} else {
/* fallback. */
- format = new Format(UNKNOWN_CHANNELS, UNKNOWN_FREQUENCY, UNKNOWN_ENCODING);
+ metadata = new Metadata(UNKNOWN_CHANNELS, UNKNOWN_FREQUENCY, UNKNOWN_ENCODING);
}
}
//
@Override
- public Format format() {
- return format;
- }
-
- @Override
public Metadata metadata() {
- return new Metadata().name(path);
+ return metadata.name(path);
}
@Override
@Override
public String toString() {
- return String.format("%s (%s)", path, format);
+ return String.format("%s (%s)", path, metadata);
}
}
import java.io.IOException;
import java.io.InputStream;
-import net.pterodactylus.sonitus.data.Format;
+import net.pterodactylus.sonitus.data.Metadata;
import com.google.common.base.Optional;
import com.google.common.io.ByteStreams;
/**
- * Wrapper around an {@link InputStream} that identifies the {@link Format} of
+ * Wrapper around an {@link InputStream} that identifies the {@link Metadata} of
* the wrapped stream.
*
* @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
*/
public class IdentifyingInputStream extends FilterInputStream {
- /** The identified format. */
- private final Format format;
+ /** The identified metadata. */
+ private final Metadata metadata;
/**
* Creates a new identifying input stream.
*
* @param inputStream
* The input stream to wrap
- * @param format
- * The format of the stream
+ * @param metadata
+ * The metadata of the stream
*/
- private IdentifyingInputStream(InputStream inputStream, Format format) {
+ private IdentifyingInputStream(InputStream inputStream, Metadata metadata) {
super(inputStream);
- this.format = format;
+ this.metadata = metadata;
}
//
//
/**
- * Returns the identified format.
+ * Returns the identified metadata.
*
- * @return The identified format
+ * @return The identified metadata
*/
- public Format format() {
- return format;
+ public Metadata metadata() {
+ return metadata;
}
//
* @param inputStream
* The input stream to identify
* @return An identifying input stream that delivers the original stream and
- * the format it detected, or {@link com.google.common.base.Optional#absent()}
- * if no format could be identified
+ * the metadata it detected, or {@link Optional#absent()} if no
+ * metadata could be identified
* @throws IOException
* if an I/O error occurs
*/
RememberingInputStream rememberingInputStream = new RememberingInputStream(inputStream);
/* try Ogg Vorbis first. */
- Optional<Format> format = OggVorbisIdentifier.identify(rememberingInputStream);
- if (format.isPresent()) {
- return Optional.of(new IdentifyingInputStream(rememberingInputStream.remembered(), format.get()));
+ Optional<Metadata> metadata = OggVorbisIdentifier.identify(rememberingInputStream);
+ if (metadata.isPresent()) {
+ return Optional.of(new IdentifyingInputStream(rememberingInputStream.remembered(), metadata.get()));
}
/* try MP3 now. */
rememberingInputStream = new RememberingInputStream(rememberingInputStream.remembered());
InputStream limitedInputStream = ByteStreams.limit(rememberingInputStream, 1048576);
- format = Mp3Identifier.identify(limitedInputStream);
- if (format.isPresent()) {
- return Optional.of(new IdentifyingInputStream(rememberingInputStream.remembered(), format.get()));
+ metadata = Mp3Identifier.identify(limitedInputStream);
+ if (metadata.isPresent()) {
+ return Optional.of(new IdentifyingInputStream(rememberingInputStream.remembered(), metadata.get()));
}
return Optional.absent();
import java.io.IOException;
import java.io.InputStream;
-import net.pterodactylus.sonitus.data.Format;
+import net.pterodactylus.sonitus.data.Metadata;
import com.google.common.base.Optional;
import javazoom.jl.decoder.Bitstream;
*
* @param inputStream
* The input stream
- * @return The identified format, or {@link com.google.common.base.Optional#absent()}
- * if the format can not be identified
+ * @return The identified metadata, or {@link Optional#absent()} if the
+ * metadata can not be identified
* @throws IOException
* if an I/O error occurs
*/
- public static Optional<Format> identify(InputStream inputStream) throws IOException {
+ public static Optional<Metadata> identify(InputStream inputStream) throws IOException {
Bitstream bitstream = new Bitstream(inputStream);
try {
Header frame = bitstream.readFrame();
if (frame == null) {
return Optional.absent();
}
- return Optional.of(new Format(frame.mode() == Header.SINGLE_CHANNEL ? 1 : 2, frame.frequency(), "MP3"));
+ return Optional.of(new Metadata(frame.mode() == Header.SINGLE_CHANNEL ? 1 : 2, frame.frequency(), "MP3"));
} catch (BitstreamException be1) {
return Optional.absent();
}
import java.io.IOException;
import java.io.InputStream;
-import net.pterodactylus.sonitus.data.Format;
+import net.pterodactylus.sonitus.data.Metadata;
import com.google.common.base.Optional;
import com.jcraft.jogg.Packet;
/**
* Tries to parse the given stream as Ogg Vorbis file and returns a {@link
- * Format} describing the stream.
+ * Metadata} describing the stream.
*
* @param inputStream
* The input stream to identify as Ogg Vorbis
- * @return The identified format, or {@link com.google.common.base.Optional#absent()}
- * if the stream could not be identified
+ * @return The identified metadata, or {@link Optional#absent()} if the stream
+ * could not be identified
* @throws IOException
* if an I/O error occurs
*/
- public static Optional<Format> identify(InputStream inputStream) throws IOException {
+ public static Optional<Metadata> identify(InputStream inputStream) throws IOException {
/* stuff needed to decode Ogg. */
Packet packet = new Packet();
buffer = syncState.data;
}
- return Optional.of(new Format(info.channels, info.rate, "Vorbis"));
+ return Optional.of(new Metadata(info.channels, info.rate, "Vorbis"));
}
}