KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > sound > sampled > spi > FormatConversionProvider


1 /*
2  * @(#)FormatConversionProvider.java 1.29 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package javax.sound.sampled.spi;
9
10 import java.io.InputStream JavaDoc;
11
12 import javax.sound.sampled.AudioFormat JavaDoc;
13 import javax.sound.sampled.AudioInputStream JavaDoc;
14
15 /**
16  * A format conversion provider provides format conversion services
17  * from one or more input formats to one or more output formats.
18  * Converters include codecs, which encode and/or decode audio data,
19  * as well as transcoders, etc. Format converters provide methods for
20  * determining what conversions are supported and for obtaining an audio
21  * stream from which converted data can be read.
22  * <p>
23  * The source format represents the format of the incoming
24  * audio data, which will be converted.
25  * <p>
26  * The target format represents the format of the processed, converted
27  * audio data. This is the format of the data that can be read from
28  * the stream returned by one of the <code>getAudioInputStream</code> methods.
29  *
30  * @author Kara Kytle
31  * @version 1.29, 03/12/19
32  * @since 1.3
33  */

34 public abstract class FormatConversionProvider {
35
36
37     // NEW METHODS
38

39     /**
40      * Obtains the set of source format encodings from which format
41      * conversion services are provided by this provider.
42      * @return array of source format encodings. The array will always
43      * have a length of at least 1.
44      */

45     public abstract AudioFormat.Encoding JavaDoc[] getSourceEncodings();
46
47
48     /**
49      * Obtains the set of target format encodings to which format
50      * conversion services are provided by this provider.
51      * @return array of target format encodings. The array will always
52      * have a length of at least 1.
53      */

54     public abstract AudioFormat.Encoding JavaDoc[] getTargetEncodings();
55
56
57     /**
58      * Indicates whether the format converter supports conversion from the
59      * specified source format encoding.
60      * @param sourceEncoding the source format encoding for which support is queried
61      * @return <code>true</code> if the encoding is supported, otherwise <code>false</code>
62      */

63     public boolean isSourceEncodingSupported(AudioFormat.Encoding JavaDoc sourceEncoding){
64
65     AudioFormat.Encoding JavaDoc sourceEncodings[] = getSourceEncodings();
66
67     for(int i=0; i<sourceEncodings.length; i++) {
68         if( sourceEncoding.equals( sourceEncodings[i]) ) {
69         return true;
70         }
71     }
72     return false;
73     }
74
75
76     /**
77      * Indicates whether the format converter supports conversion to the
78      * specified target format encoding.
79      * @param targetEncoding the target format encoding for which support is queried
80      * @return <code>true</code> if the encoding is supported, otherwise <code>false</code>
81      */

82     public boolean isTargetEncodingSupported(AudioFormat.Encoding JavaDoc targetEncoding){
83
84     AudioFormat.Encoding JavaDoc targetEncodings[] = getTargetEncodings();
85
86     for(int i=0; i<targetEncodings.length; i++) {
87         if( targetEncoding.equals( targetEncodings[i]) ) {
88         return true;
89         }
90     }
91     return false;
92     }
93
94
95     /**
96      * Obtains the set of target format encodings supported by the format converter
97      * given a particular source format.
98      * If no target format encodings are supported for this source format,
99      * an array of length 0 is returned.
100      * @return array of supported target format encodings.
101      */

102     public abstract AudioFormat.Encoding JavaDoc[] getTargetEncodings(AudioFormat JavaDoc sourceFormat);
103
104
105     /**
106      * Indicates whether the format converter supports conversion to a particular encoding
107      * from a particular format.
108      * @param targetEncoding desired encoding of the outgoing data
109      * @param sourceFormat format of the incoming data
110      * @return <code>true</code> if the conversion is supported, otherwise <code>false</code>
111      */

112     public boolean isConversionSupported(AudioFormat.Encoding JavaDoc targetEncoding, AudioFormat JavaDoc sourceFormat){
113
114     AudioFormat.Encoding JavaDoc targetEncodings[] = getTargetEncodings(sourceFormat);
115
116     for(int i=0; i<targetEncodings.length; i++) {
117         if( targetEncoding.equals( targetEncodings[i]) ) {
118         return true;
119         }
120     }
121     return false;
122     }
123
124
125     /**
126      * Obtains the set of target formats with the encoding specified
127      * supported by the format converter
128      * If no target formats with the specified encoding are supported
129      * for this source format, an array of length 0 is returned.
130      * @return array of supported target formats.
131      */

132     public abstract AudioFormat JavaDoc[] getTargetFormats(AudioFormat.Encoding JavaDoc targetEncoding, AudioFormat JavaDoc sourceFormat);
133
134
135     /**
136      * Indicates whether the format converter supports conversion to one
137      * particular format from another.
138      * @param targetFormat desired format of outgoing data
139      * @param sourceFormat format of the incoming data
140      * @return <code>true</code> if the conversion is supported, otherwise <code>false</code>
141      */

142     public boolean isConversionSupported(AudioFormat JavaDoc targetFormat, AudioFormat JavaDoc sourceFormat){
143
144     AudioFormat JavaDoc targetFormats[] = getTargetFormats( targetFormat.getEncoding(), sourceFormat );
145
146     for(int i=0; i<targetFormats.length; i++) {
147         if( targetFormat.matches( targetFormats[i] ) ) {
148         return true;
149         }
150     }
151     return false;
152     }
153
154
155     /**
156      * Obtains an audio input stream with the specified encoding from the given audio
157      * input stream.
158      * @param targetEncoding desired encoding of the stream after processing
159      * @param sourceStream stream from which data to be processed should be read
160      * @return stream from which processed data with the specified target encoding may be read
161      * @throws IllegalArgumentException if the format combination supplied is
162      * not supported.
163      */

164     public abstract AudioInputStream JavaDoc getAudioInputStream(AudioFormat.Encoding JavaDoc targetEncoding, AudioInputStream JavaDoc sourceStream);
165
166
167     /**
168      * Obtains an audio input stream with the specified format from the given audio
169      * input stream.
170      * @param targetFormat desired data format of the stream after processing
171      * @param sourceStream stream from which data to be processed should be read
172      * @return stream from which processed data with the specified format may be read
173      * @throws IllegalArgumentException if the format combination supplied is
174      * not supported.
175      */

176     public abstract AudioInputStream JavaDoc getAudioInputStream(AudioFormat JavaDoc targetFormat, AudioInputStream JavaDoc sourceStream);
177
178 }
179
Popular Tags