0N/A/*
2362N/A * Copyright (c) 1999, 2003, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage javax.sound.sampled.spi;
0N/A
0N/Aimport java.io.InputStream;
0N/A
0N/Aimport javax.sound.sampled.AudioFormat;
0N/Aimport javax.sound.sampled.AudioInputStream;
0N/A
0N/A/**
0N/A * A format conversion provider provides format conversion services
0N/A * from one or more input formats to one or more output formats.
0N/A * Converters include codecs, which encode and/or decode audio data,
0N/A * as well as transcoders, etc. Format converters provide methods for
0N/A * determining what conversions are supported and for obtaining an audio
0N/A * stream from which converted data can be read.
0N/A * <p>
0N/A * The source format represents the format of the incoming
0N/A * audio data, which will be converted.
0N/A * <p>
0N/A * The target format represents the format of the processed, converted
0N/A * audio data. This is the format of the data that can be read from
0N/A * the stream returned by one of the <code>getAudioInputStream</code> methods.
0N/A *
0N/A * @author Kara Kytle
0N/A * @since 1.3
0N/A */
0N/Apublic abstract class FormatConversionProvider {
0N/A
0N/A
0N/A // NEW METHODS
0N/A
0N/A /**
0N/A * Obtains the set of source format encodings from which format
0N/A * conversion services are provided by this provider.
0N/A * @return array of source format encodings. If for some reason provider
0N/A * does not provide any conversion services, an array of length 0 is
0N/A * returned.
0N/A */
0N/A public abstract AudioFormat.Encoding[] getSourceEncodings();
0N/A
0N/A
0N/A /**
0N/A * Obtains the set of target format encodings to which format
0N/A * conversion services are provided by this provider.
0N/A * @return array of target format encodings. If for some reason provider
0N/A * does not provide any conversion services, an array of length 0 is
0N/A * returned.
0N/A */
0N/A public abstract AudioFormat.Encoding[] getTargetEncodings();
0N/A
0N/A
0N/A /**
0N/A * Indicates whether the format converter supports conversion from the
0N/A * specified source format encoding.
0N/A * @param sourceEncoding the source format encoding for which support is queried
0N/A * @return <code>true</code> if the encoding is supported, otherwise <code>false</code>
0N/A */
0N/A public boolean isSourceEncodingSupported(AudioFormat.Encoding sourceEncoding){
0N/A
0N/A AudioFormat.Encoding sourceEncodings[] = getSourceEncodings();
0N/A
0N/A for(int i=0; i<sourceEncodings.length; i++) {
0N/A if( sourceEncoding.equals( sourceEncodings[i]) ) {
0N/A return true;
0N/A }
0N/A }
0N/A return false;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Indicates whether the format converter supports conversion to the
0N/A * specified target format encoding.
0N/A * @param targetEncoding the target format encoding for which support is queried
0N/A * @return <code>true</code> if the encoding is supported, otherwise <code>false</code>
0N/A */
0N/A public boolean isTargetEncodingSupported(AudioFormat.Encoding targetEncoding){
0N/A
0N/A AudioFormat.Encoding targetEncodings[] = getTargetEncodings();
0N/A
0N/A for(int i=0; i<targetEncodings.length; i++) {
0N/A if( targetEncoding.equals( targetEncodings[i]) ) {
0N/A return true;
0N/A }
0N/A }
0N/A return false;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Obtains the set of target format encodings supported by the format converter
0N/A * given a particular source format.
0N/A * If no target format encodings are supported for this source format,
0N/A * an array of length 0 is returned.
0N/A * @return array of supported target format encodings.
0N/A */
0N/A public abstract AudioFormat.Encoding[] getTargetEncodings(AudioFormat sourceFormat);
0N/A
0N/A
0N/A /**
0N/A * Indicates whether the format converter supports conversion to a particular encoding
0N/A * from a particular format.
0N/A * @param targetEncoding desired encoding of the outgoing data
0N/A * @param sourceFormat format of the incoming data
0N/A * @return <code>true</code> if the conversion is supported, otherwise <code>false</code>
0N/A */
0N/A public boolean isConversionSupported(AudioFormat.Encoding targetEncoding, AudioFormat sourceFormat){
0N/A
0N/A AudioFormat.Encoding targetEncodings[] = getTargetEncodings(sourceFormat);
0N/A
0N/A for(int i=0; i<targetEncodings.length; i++) {
0N/A if( targetEncoding.equals( targetEncodings[i]) ) {
0N/A return true;
0N/A }
0N/A }
0N/A return false;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Obtains the set of target formats with the encoding specified
0N/A * supported by the format converter
0N/A * If no target formats with the specified encoding are supported
0N/A * for this source format, an array of length 0 is returned.
0N/A * @return array of supported target formats.
0N/A */
0N/A public abstract AudioFormat[] getTargetFormats(AudioFormat.Encoding targetEncoding, AudioFormat sourceFormat);
0N/A
0N/A
0N/A /**
0N/A * Indicates whether the format converter supports conversion to one
0N/A * particular format from another.
0N/A * @param targetFormat desired format of outgoing data
0N/A * @param sourceFormat format of the incoming data
0N/A * @return <code>true</code> if the conversion is supported, otherwise <code>false</code>
0N/A */
0N/A public boolean isConversionSupported(AudioFormat targetFormat, AudioFormat sourceFormat){
0N/A
0N/A AudioFormat targetFormats[] = getTargetFormats( targetFormat.getEncoding(), sourceFormat );
0N/A
0N/A for(int i=0; i<targetFormats.length; i++) {
0N/A if( targetFormat.matches( targetFormats[i] ) ) {
0N/A return true;
0N/A }
0N/A }
0N/A return false;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Obtains an audio input stream with the specified encoding from the given audio
0N/A * input stream.
0N/A * @param targetEncoding desired encoding of the stream after processing
0N/A * @param sourceStream stream from which data to be processed should be read
0N/A * @return stream from which processed data with the specified target encoding may be read
0N/A * @throws IllegalArgumentException if the format combination supplied is
0N/A * not supported.
0N/A */
0N/A public abstract AudioInputStream getAudioInputStream(AudioFormat.Encoding targetEncoding, AudioInputStream sourceStream);
0N/A
0N/A
0N/A /**
0N/A * Obtains an audio input stream with the specified format from the given audio
0N/A * input stream.
0N/A * @param targetFormat desired data format of the stream after processing
0N/A * @param sourceStream stream from which data to be processed should be read
0N/A * @return stream from which processed data with the specified format may be read
0N/A * @throws IllegalArgumentException if the format combination supplied is
0N/A * not supported.
0N/A */
0N/A public abstract AudioInputStream getAudioInputStream(AudioFormat targetFormat, AudioInputStream sourceStream);
0N/A
0N/A}