< prev index next >

test/javax/sound/sampled/Clip/ClipCloseLoss.java

Print this page


   1 /*
   2  * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 import java.io.ByteArrayInputStream;
  25 
  26 import javax.sound.sampled.AudioFormat;
  27 import javax.sound.sampled.AudioInputStream;
  28 import javax.sound.sampled.AudioSystem;
  29 import javax.sound.sampled.Clip;
  30 import javax.sound.sampled.DataLine;
  31 import javax.sound.sampled.LineUnavailableException;
  32 import javax.sound.sampled.Mixer;
  33 
  34 /**
  35  * @test
  36  * @bug 4946913
  37  * @summary DirectClip doesn't kill the thread correctly, sometimes
  38  * @run main/othervm ClipCloseLoss
  39  * @key headful
  40  */
  41 public class ClipCloseLoss {
  42     static int frameCount = 441000; // lets say 10 seconds
  43     static AudioFormat format = new AudioFormat(44100.0f, 16, 2, true, false);
  44     static ByteArrayInputStream bais =
  45     new ByteArrayInputStream(new byte[frameCount * format.getFrameSize()]);
  46 
  47     static int success = 0;
  48     static boolean failed = false;
  49 
  50     public static void run(Mixer m) {
  51         Clip clip = null;
  52         try {
  53             if (m == null) {
  54                 out("Using default mixer");
  55                 clip = (Clip) AudioSystem.getClip();
  56             } else {
  57                 out("Using mixer: "+m);
  58                 DataLine.Info info = new DataLine.Info(Clip.class, format, AudioSystem.NOT_SPECIFIED);
  59                 clip = (Clip) m.getLine(info);


   1 /*
   2  * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 import java.io.ByteArrayInputStream;
  25 
  26 import javax.sound.sampled.AudioFormat;
  27 import javax.sound.sampled.AudioInputStream;
  28 import javax.sound.sampled.AudioSystem;
  29 import javax.sound.sampled.Clip;
  30 import javax.sound.sampled.DataLine;
  31 import javax.sound.sampled.LineUnavailableException;
  32 import javax.sound.sampled.Mixer;
  33 
  34 /**
  35  * @test
  36  * @bug 4946913
  37  * @summary DirectClip doesn't kill the thread correctly, sometimes
  38  * @run main/othervm ClipCloseLoss

  39  */
  40 public class ClipCloseLoss {
  41     static int frameCount = 441000; // lets say 10 seconds
  42     static AudioFormat format = new AudioFormat(44100.0f, 16, 2, true, false);
  43     static ByteArrayInputStream bais =
  44     new ByteArrayInputStream(new byte[frameCount * format.getFrameSize()]);
  45 
  46     static int success = 0;
  47     static boolean failed = false;
  48 
  49     public static void run(Mixer m) {
  50         Clip clip = null;
  51         try {
  52             if (m == null) {
  53                 out("Using default mixer");
  54                 clip = (Clip) AudioSystem.getClip();
  55             } else {
  56                 out("Using mixer: "+m);
  57                 DataLine.Info info = new DataLine.Info(Clip.class, format, AudioSystem.NOT_SPECIFIED);
  58                 clip = (Clip) m.getLine(info);


< prev index next >