Path: blob/master/test/jdk/javax/sound/sampled/Lines/BufferSizeCheck.java
41153 views
/*1* Copyright (c) 2002, 2016, 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.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import javax.sound.sampled.AudioFormat;24import javax.sound.sampled.AudioSystem;25import javax.sound.sampled.DataLine;26import javax.sound.sampled.LineUnavailableException;27import javax.sound.sampled.Mixer;28import javax.sound.sampled.SourceDataLine;2930/**31* @test32* @bug 466160233* @summary Buffersize is checked when re-opening line34*/35public class BufferSizeCheck {3637public static void main(String[] args) throws Exception {38boolean realTest = false;39if (!isSoundcardInstalled()) {40return;41}4243try {44out("4661602: Buffersize is checked when re-opening line");45AudioFormat format = new AudioFormat(44100, 16, 2, true, false);46DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);47SourceDataLine sdl = (SourceDataLine) AudioSystem.getLine(info);48out("Opening with buffersize 12000...");49sdl.open(format, 12000);50out("Opening with buffersize 11000...");51realTest=true;52sdl.open(format, 11000);53try {54sdl.close();55} catch(Throwable t) {}56} catch (Exception e) {57e.printStackTrace();58// do not fail if no audio device installed - bug 474202159if (realTest || !(e instanceof LineUnavailableException)) {60throw e;61}62}63out("Test passed");64}6566static void out(String s) {67System.out.println(s); System.out.flush();68}6970/**71* Returns true if at least one soundcard is correctly installed72* on the system.73*/74public static boolean isSoundcardInstalled() {75boolean result = false;76try {77Mixer.Info[] mixers = AudioSystem.getMixerInfo();78if (mixers.length > 0) {79result = AudioSystem.getSourceDataLine(null) != null;80}81} catch (Exception e) {82System.err.println("Exception occured: "+e);83}84if (!result) {85System.err.println("Soundcard does not exist or sound drivers not installed!");86System.err.println("This test requires sound drivers for execution.");87}88return result;89}90}919293