Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/javax/sound/sampled/TargetDataLine.java
38918 views
/*1* Copyright (c) 1999, 2003, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.sound.sampled;2627/**28* A target data line is a type of <code>{@link DataLine}</code> from which29* audio data can be read. The most common example is a data line that gets30* its data from an audio capture device. (The device is implemented as a31* mixer that writes to the target data line.)32* <p>33* Note that the naming convention for this interface reflects the relationship34* between the line and its mixer. From the perspective of an application,35* a target data line may act as a source for audio data.36* <p>37* The target data line can be obtained from a mixer by invoking the38* <code>{@link Mixer#getLine getLine}</code>39* method of <code>Mixer</code> with an appropriate40* <code>{@link DataLine.Info}</code> object.41* <p>42* The <code>TargetDataLine</code> interface provides a method for reading the43* captured data from the target data line's buffer.Applications44* that record audio should read data from the target data line quickly enough45* to keep the buffer from overflowing, which could cause discontinuities in46* the captured data that are perceived as clicks. Applications can use the47* <code>{@link DataLine#available available}</code> method defined in the48* <code>DataLine</code> interface to determine the amount of data currently49* queued in the data line's buffer. If the buffer does overflow,50* the oldest queued data is discarded and replaced by new data.51*52* @author Kara Kytle53* @see Mixer54* @see DataLine55* @see SourceDataLine56* @since 1.357*/58public interface TargetDataLine extends DataLine {596061/**62* Opens the line with the specified format and requested buffer size,63* causing the line to acquire any required system resources and become64* operational.65* <p>66* The buffer size is specified in bytes, but must represent an integral67* number of sample frames. Invoking this method with a requested buffer68* size that does not meet this requirement may result in an69* IllegalArgumentException. The actual buffer size for the open line may70* differ from the requested buffer size. The value actually set may be71* queried by subsequently calling <code>{@link DataLine#getBufferSize}</code>72* <p>73* If this operation succeeds, the line is marked as open, and an74* <code>{@link LineEvent.Type#OPEN OPEN}</code> event is dispatched to the75* line's listeners.76* <p>77* Invoking this method on a line that is already open is illegal78* and may result in an <code>IllegalStateException</code>.79* <p>80* Some lines, once closed, cannot be reopened. Attempts81* to reopen such a line will always result in a82* <code>LineUnavailableException</code>.83*84* @param format the desired audio format85* @param bufferSize the desired buffer size, in bytes.86* @throws LineUnavailableException if the line cannot be87* opened due to resource restrictions88* @throws IllegalArgumentException if the buffer size does not represent89* an integral number of sample frames,90* or if <code>format</code> is not fully specified or invalid91* @throws IllegalStateException if the line is already open92* @throws SecurityException if the line cannot be93* opened due to security restrictions94*95* @see #open(AudioFormat)96* @see Line#open97* @see Line#close98* @see Line#isOpen99* @see LineEvent100*/101public void open(AudioFormat format, int bufferSize) throws LineUnavailableException;102103104/**105* Opens the line with the specified format, causing the line to acquire any106* required system resources and become operational.107*108* <p>109* The implementation chooses a buffer size, which is measured in bytes but110* which encompasses an integral number of sample frames. The buffer size111* that the system has chosen may be queried by subsequently calling <code>{@link DataLine#getBufferSize}</code>112* <p>113* If this operation succeeds, the line is marked as open, and an114* <code>{@link LineEvent.Type#OPEN OPEN}</code> event is dispatched to the115* line's listeners.116* <p>117* Invoking this method on a line that is already open is illegal118* and may result in an <code>IllegalStateException</code>.119* <p>120* Some lines, once closed, cannot be reopened. Attempts121* to reopen such a line will always result in a122* <code>LineUnavailableException</code>.123*124* @param format the desired audio format125* @throws LineUnavailableException if the line cannot be126* opened due to resource restrictions127* @throws IllegalArgumentException if <code>format</code>128* is not fully specified or invalid129* @throws IllegalStateException if the line is already open130* @throws SecurityException if the line cannot be131* opened due to security restrictions132*133* @see #open(AudioFormat, int)134* @see Line#open135* @see Line#close136* @see Line#isOpen137* @see LineEvent138*/139public void open(AudioFormat format) throws LineUnavailableException;140141142/**143* Reads audio data from the data line's input buffer. The requested144* number of bytes is read into the specified array, starting at145* the specified offset into the array in bytes. This method blocks until146* the requested amount of data has been read. However, if the data line147* is closed, stopped, drained, or flushed before the requested amount has148* been read, the method no longer blocks, but returns the number of bytes149* read thus far.150* <p>151* The number of bytes that can be read without blocking can be ascertained152* using the <code>{@link DataLine#available available}</code> method of the153* <code>DataLine</code> interface. (While it is guaranteed that154* this number of bytes can be read without blocking, there is no guarantee155* that attempts to read additional data will block.)156* <p>157* The number of bytes to be read must represent an integral number of158* sample frames, such that:159* <br>160* <center><code>[ bytes read ] % [frame size in bytes ] == 0</code></center>161* <br>162* The return value will always meet this requirement. A request to read a163* number of bytes representing a non-integral number of sample frames cannot164* be fulfilled and may result in an IllegalArgumentException.165*166* @param b a byte array that will contain the requested input data when167* this method returns168* @param off the offset from the beginning of the array, in bytes169* @param len the requested number of bytes to read170* @return the number of bytes actually read171* @throws IllegalArgumentException if the requested number of bytes does172* not represent an integral number of sample frames.173* or if <code>len</code> is negative.174* @throws ArrayIndexOutOfBoundsException if <code>off</code> is negative,175* or <code>off+len</code> is greater than the length of the array176* <code>b</code>.177*178* @see SourceDataLine#write179* @see DataLine#available180*/181public int read(byte[] b, int off, int len);182183/**184* Obtains the number of sample frames of audio data that can be read from185* the target data line without blocking. Note that the return value186* measures sample frames, not bytes.187* @return the number of sample frames currently available for reading188* @see SourceDataLine#availableWrite189*/190//public int availableRead();191}192193194