Mercurial > hg > Members > riono > TreeVNC_ja_comment
view src/main/java/jp/ac/u_ryukyu/treevnc/ReceiveSound.java @ 423:ffe01c959cdd
Fix LostChild for root node
author | Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 22 Jan 2016 07:51:57 +0900 |
parents | a9b8514a7c0e |
children |
line wrap: on
line source
package jp.ac.u_ryukyu.treevnc; import javax.sound.sampled.*; import java.io.ByteArrayInputStream; import java.net.*; /** * Created by OcBookPro on 15/01/13. */ public class ReceiveSound implements Runnable { public static final int DEFAULT_SOUND_RECEIVE_PORT = 60004; public static final int recvPort = 60004; private DatagramSocket socket; private boolean isStop; public ReceiveSound(DatagramSocket socket) throws UnknownHostException, SocketException { this.socket = socket; this.isStop = false; } @Override public void run() { try { byte[] buffer = new byte[172]; byte[] linearBuffer = new byte[320]; DatagramPacket packet = new DatagramPacket(buffer,buffer.length); AudioFormat ulawFormat = new AudioFormat(AudioFormat.Encoding.ULAW,8000,8,1,1,8000,false); AudioFormat linearFormat = new AudioFormat(8000,16,1,true,false); AudioInputStream ulawStream = null; AudioInputStream linearStream = null; ByteArrayInputStream byteArrayInputStream = null; DataLine.Info info = new DataLine.Info(SourceDataLine.class,linearFormat); SourceDataLine sourceDataLine = (SourceDataLine) AudioSystem.getLine(info); sourceDataLine.open(linearFormat); sourceDataLine.start(); while(!isStop) { try { this.socket.receive(packet); // skip rtp header. byteArrayInputStream = new ByteArrayInputStream(packet.getData(), 12, 160); ulawStream = new AudioInputStream(byteArrayInputStream, ulawFormat, 160); linearStream = AudioSystem.getAudioInputStream(linearFormat, ulawStream); linearStream.read(linearBuffer, 0, linearBuffer.length); sourceDataLine.write(linearBuffer, 0, linearBuffer.length); } catch (Exception e) { e.printStackTrace(); } } sourceDataLine.stop(); sourceDataLine.close(); } catch (Exception e) { e.printStackTrace(); } } public void recvStop() { this.isStop = true; } }