private void done(boolean restart) { if (done) { return; } done = true; if (stdOutListener != null) { stdOutListener.done(); } if (stdErrListener != null) { stdErrListener.done(); } vuMeter.stop(); setVisible(false); if (restart) { try { restart(); } catch (IOException ioe) { ioe.printStackTrace(); } } // text.setText(BEFORE_TEST); }
private void performTest() { // launch the mic tester ServerSocket srv = null; boolean fail = false; try { srv = new ServerSocket(0); } catch (IOException ioe) { typeText( "Unable to test the audio input. Please use your " + "system's sound utilities to check your input and output."); return; } int port = srv.getLocalPort(); float mySampleRate = Utils.getIntPreference("com.sun.mc.softphone.media.SAMPLE_RATE"); if (mySampleRate == 0) { mySampleRate = (int) MediaManager.DEFAULT_SAMPLE_RATE; } if (Utils.isMacOS() == true) { mySampleRate = 44100.0f; } int myChannels = Utils.getIntPreference("com.sun.mc.softphone.media.CHANNELS"); if (myChannels == 0) { myChannels = (int) MediaManager.DEFAULT_CHANNELS; } String javaHome = System.getProperty("java.home"); String classPath = System.getProperty("java.class.path"); String sep = System.getProperty("file.separator"); String cmd[] = new String[12]; cmd[0] = javaHome + sep + "bin" + sep + "java"; cmd[1] = "-cp"; cmd[2] = classPath; cmd[3] = "com.sun.mc.softphone.media.LevelTest"; cmd[4] = "-port"; cmd[5] = String.valueOf(port); cmd[6] = "-sampleRate"; cmd[7] = String.valueOf(mySampleRate); cmd[8] = "-channels"; cmd[9] = String.valueOf(myChannels); cmd[10] = "-duration"; cmd[11] = "4"; // four seconds worth of data. Socket sock = null; DataInputStream dis = null; try { vuMeter.setState(vuMeter.STANDBY); lineTest = Runtime.getRuntime().exec(cmd); stdOutListener = new ProcOutputListener(lineTest.getInputStream()); stdErrListener = new ProcOutputListener(lineTest.getErrorStream()); stdOutListener.start(); stdErrListener.start(); srv.setSoTimeout(5000); sock = srv.accept(); sock.setTcpNoDelay(true); dis = new DataInputStream(sock.getInputStream()); vuMeter.setState(vuMeter.ENABLED); while (true) { float val = dis.readFloat(); vuMeter.setValue(val); } } catch (SocketTimeoutException ste) { typeText("No response from testing program. Please try again."); fail = true; } catch (IOException ioe) { // System.out.println(ioe); } finally { vuMeter.setState(vuMeter.DISABLED); if (dis != null) { try { dis.close(); } catch (IOException ioe) { } } if (sock != null) { try { sock.close(); } catch (IOException ioe) { } } if (srv != null) { try { srv.close(); } catch (IOException ioe) { } } if (!fail) { typeText(AFTER_TEST); } testAction.setEnabled(true); } }
private void cancel() { vuMeter.stop(); setVisible(false); }