Mercurial > hg > Applications > TreeVNC
changeset 293:d1ceb4b7097a
add function receive sound.
author | oc |
---|---|
date | Tue, 13 Jan 2015 12:49:15 +0900 |
parents | 6c6960291f81 |
children | b1749cab09a3 |
files | src/main/java/jp/ac/u_ryukyu/treevnc/ReceiveSound.java src/main/java/jp/ac/u_ryukyu/treevnc/SendSound.java src/main/java/jp/ac/u_ryukyu/treevnc/TreeRFBProto.java src/viewer_swing/java/com/glavsoft/viewer/TreeViewer.java src/viewer_swing/java/com/glavsoft/viewer/swing/ConnectionParams.java src/viewer_swing/java/com/glavsoft/viewer/swing/SwingViewerWindow.java |
diffstat | 6 files changed, 109 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/ReceiveSound.java Tue Jan 13 12:49:15 2015 +0900 @@ -0,0 +1,71 @@ +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; + } +}
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/SendSound.java Tue Jan 13 07:29:21 2015 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/SendSound.java Tue Jan 13 12:49:15 2015 +0900 @@ -24,16 +24,18 @@ private String destPort; // Constructor root version. - public SendSound(TreeRFBProto rfb) { + public SendSound(DatagramSocket socket, TreeRFBProto rfb) { this.rfb = rfb; + this.socket = socket; } // Constructor node version. - public SendSound(TreeRFBProto rfb, String destIp, String destPort) throws UnknownHostException, SocketException { + public SendSound(DatagramSocket socket, TreeRFBProto rfb, String destIp, String destPort) throws UnknownHostException, SocketException { this.rfb = rfb; - this.socket = new DatagramSocket(recvPort, InetAddress.getLocalHost()); + this.socket = socket; this.destIp = destIp; this.destPort = destPort; + this.isStop = false; } @Override
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/TreeRFBProto.java Tue Jan 13 07:29:21 2015 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/TreeRFBProto.java Tue Jan 13 12:49:15 2015 +0900 @@ -24,6 +24,8 @@ import com.glavsoft.viewer.ViewerInterface; import com.glavsoft.viewer.swing.ConnectionParams; +import javax.xml.crypto.Data; + public class TreeRFBProto { @@ -73,11 +75,13 @@ public int fixingSizeHeight; public int singleWidth = 0; + private DatagramSocket socket = null; public TreeRFBProto(boolean isTreeManager) { rThread = new RequestScreenThread(this); nets.setMyRfb(this); this.isTreeManager = isTreeManager; + this.socket = createSocket(); } public boolean isTreeManager() { @@ -189,11 +193,12 @@ buf.get(); sendSingleDisplayWidth(singleWidth); } else if (b[0] == ClientToServerMessage.READY_SHARE_SOUND) { - // 返事する?? - // IPアドレス送る?? - // 受信準備をする - // thread立ち上げる System.out.println("rootは受信準備を始める。"); + int rtpPort = selectPort(ConnectionParams.DEFAULT_RTP_PORT); + InetAddress hostname = InetAddress.getLocalHost(); + ReceiveSound receiveSound = new ReceiveSound(socket); + Thread receiveSoundThread = new Thread(receiveSound, "receive-sound"); + receiveSoundThread.start(); } else if (b[0] == ClientToServerMessage.CHECK_DELAY_REPLY) { ByteBuffer buf = ByteBuffer.wrap(b); buf.order(ByteOrder.BIG_ENDIAN); @@ -754,12 +759,14 @@ */ public void createShareSoundThread(TreeRFBProto rfb) throws SocketException, UnknownHostException { SendSound sendSound; +// DatagramSocket socket = new DatagramSocket(selectPort(ConnectionParams.DEFAULT_RTP_PORT), InetAddress.getLocalHost()); + if(rfb.isTreeManager()) { - sendSound = new SendSound(rfb); + sendSound = new SendSound(socket, rfb); } else { String ip = "133.13.57.59"; String port = "60004"; - sendSound = new SendSound(rfb, ip, port); + sendSound = new SendSound(socket, rfb, ip, port); } Thread sendSoundThread = new Thread(sendSound, "send-sound"); sendSoundThread.start(); @@ -847,4 +854,18 @@ this.filterSingleDisplay = filterSingleDisplay; } + private DatagramSocket createSocket() { + + try { + if (socket == null) { + this.socket = new DatagramSocket(ConnectionParams.DEFAULT_RTP_PORT, InetAddress.getLocalHost()); + } + } catch (SocketException e) { + e.printStackTrace(); + } catch (UnknownHostException e) { + e.printStackTrace(); + } + return socket; + } + } \ No newline at end of file
--- a/src/viewer_swing/java/com/glavsoft/viewer/TreeViewer.java Tue Jan 13 07:29:21 2015 +0900 +++ b/src/viewer_swing/java/com/glavsoft/viewer/TreeViewer.java Tue Jan 13 12:49:15 2015 +0900 @@ -4,6 +4,8 @@ import java.io.FileNotFoundException; import java.io.PrintStream; +import java.net.SocketException; +import java.net.UnknownHostException; public class TreeViewer { private boolean treeProxy; @@ -25,11 +27,11 @@ private boolean filterSingleDisplay = false; - public static void main(String[] args) { + public static void main(String[] args) throws SocketException, UnknownHostException { new TreeViewer().vncStart(args); } - private void vncStart(String[] args) { + private void vncStart(String[] args) throws SocketException, UnknownHostException { modeSelect(args); if(logFile) { PrintStream out = null; @@ -65,7 +67,7 @@ } - public void rootStart(String[] args, ViewerInterface v) { + public void rootStart(String[] args, ViewerInterface v) throws SocketException, UnknownHostException { v.setNoConnection(noConnection); // should we accept host name here? v.proxyStart(args,width,height, showTree, checkDelay, addSerialNum, fixingSizeDisplay, filterSingleDisplay); v.getRfb().setHasViewer(viewer);
--- a/src/viewer_swing/java/com/glavsoft/viewer/swing/ConnectionParams.java Tue Jan 13 07:29:21 2015 +0900 +++ b/src/viewer_swing/java/com/glavsoft/viewer/swing/ConnectionParams.java Tue Jan 13 12:49:15 2015 +0900 @@ -34,6 +34,7 @@ public static final int DEFAULT_SSH_PORT = 22; public static final int DEFAULT_RFB_PORT = 5900; public static final int DEFAULT_VNC_ROOT = 5950; + public static final int DEFAULT_RTP_PORT = 60004; public static final int DEFAULT_VNC_ROOT_FINDER = DEFAULT_RFB_PORT;
--- a/src/viewer_swing/java/com/glavsoft/viewer/swing/SwingViewerWindow.java Tue Jan 13 07:29:21 2015 +0900 +++ b/src/viewer_swing/java/com/glavsoft/viewer/swing/SwingViewerWindow.java Tue Jan 13 12:49:15 2015 +0900 @@ -876,7 +876,6 @@ int rightScreenNumber = 1; viewer.getRfb().singleWidth = (int) rectangles.get(leftScreenNumber).getWidth(); - // send用thread立ち上げのメソッドに飛ぶ try { if (viewer.getRfb().isTreeManager()) { changeVncServer(viewer, (int) rectangles.get(leftScreenNumber).getWidth(), (int) rectangles.get(leftScreenNumber).getHeight(), viewer.getRfb().getId()); @@ -885,9 +884,7 @@ } String adr = viewer.getRfb().getMyAddress(); context.sendMessage(new ScreenChangeRequest(adr, viewer.getRfb().getId(), (int) rectangles.get(leftScreenNumber).getWidth(), (int) rectangles.get(leftScreenNumber).getHeight())); - // rootにMsgを送信する context.sendMessage(new ReadyShareSound()); - // 送信用threadを立ち上げるメソッドに飛ぶ viewer.getRfb().createShareSoundThread(viewer.getRfb()); } catch (SocketException e1) { e1.printStackTrace();