?? audiopanel.java
字號:
supported = tracks[i].getSupportedFormats();//將支持的format類型設為第一個 if (supported.length > 0) { chosen = supported[0]; //將傳輸數據量設為最小用G723/rtp格式 tracks[i].setFormat(audioFormat); atLeastOneTrack = true; } else tracks[i].setEnabled(false); } else tracks[i].setEnabled(false); } if (!atLeastOneTrack) return "Couldn't set any of the tracks to a valid RTP format"; result = waitForState(processor, Controller.Realized); if (result == false) return "Couldn't realize processor"; dataOutput = processor.getDataOutput(); processor.start(); return null; } private Integer stateLock = new Integer(0); private boolean failed = false; private BorderLayout borderLayout1 = new BorderLayout(); Integer getStateLock() { return stateLock; } void setFailed() { failed = true; } private synchronized boolean waitForState(Processor p, int state) { p.addControllerListener(new StateListener()); failed = false; if (state == Processor.Configured) { p.configure(); } else if (state == Processor.Realized) { p.realize(); } while (p.getState() < state && !failed) { synchronized (getStateLock()) { try { getStateLock().wait(); } catch (InterruptedException ie) { return false; } } } if (failed) return false; else return true; } public void transferData(PushBufferStream pbs) { try{ Data data; Vector dataVector=new Vector(); Buffer databuf=new Buffer(); pbs.read(databuf); byte[] databyte=(byte[])databuf.getData(); String ss="start"; dataVector.addElement(databyte); dataVector.addElement(ss); data =new Data(dataVector); channel.sendToAll(client,data); }catch(Exception ee){ System.out.println("發送數據錯誤1:"+ee); System.out.println(ee.getMessage()); } } class StateListener implements ControllerListener { public void controllerUpdate(ControllerEvent ce) { if (ce instanceof ControllerClosedEvent) setFailed(); if (ce instanceof ControllerEvent) { synchronized (getStateLock()) { getStateLock().notifyAll(); } } } } class LiveStream implements PushBufferStream, Runnable { protected ContentDescriptor cd = new ContentDescriptor(ContentDescriptor.RAW); protected int maxDataLength; protected byte [] data; protected Dimension size; protected RGBFormat rgbFormat; protected boolean started; public Thread mythread; protected float frameRate = 20f; protected BufferTransferHandler transferHandler; protected Control [] controls = new Control[0];// protected Buffer audioBuffer=new Buffer(); protected boolean videoData = false; public LiveStream() { maxDataLength = 1000; } public ContentDescriptor getContentDescriptor() { return cd; } public long getContentLength() { return LENGTH_UNKNOWN; } public boolean endOfStream() { return false; } public Format getFormat() { return audioFormat; } public void read(Buffer buffer) { if(bufdata.size()>1){ synchronized (this) { try{// System.out.println("讀數據read()"); buffer.setData((byte[])(bufdata.firstElement())); bufdata.removeElementAt(0);// System.out.println("bufdata的大小"+bufdata.size()); buffer.setFormat(audioFormat); buffer.setSequenceNumber(seqnum); buffer.setLength(bufferlength); System.out.println("bufdata里面的元素數據個數-1:"+bufdata.size()); }catch(Exception ee){ System.out.println("error:"+ee); System.out.println(ee.getMessage()); } } } } public void setTransferHandler(BufferTransferHandler transferHandler) { synchronized (this) { this.transferHandler = transferHandler; notifyAll(); } } void start(boolean started) { synchronized ( this ) { this.started = started; System.out.println("ready to start thread"); if (started) { System.out.println("進入判斷語句"); mythread = new Thread(this); mythread.start(); System.out.println("thread started"); } notifyAll(); } } public void run() { while (started) {// synchronized (this) {// while (transferHandler == null && started) {// try {// wait(1000);// } catch (InterruptedException ie) {// }// } // while// } if (started && transferHandler != null) { transferHandler.transferData(this); try { Thread.currentThread().sleep(600); } catch (InterruptedException ise) { } } } // while (started) } // run // Controls public void ableread(){ transferHandler.transferData(this); } public Object [] getControls() { return controls; } public Object getControl(String controlType) { try { Class cls = Class.forName(controlType); Object cs[] = getControls(); for (int i = 0; i < cs.length; i++) { if (cls.isInstance(cs[i])) return cs[i]; } return null; } catch (Exception e) { // no such controlType or such control return null; } } } class dataSource extends PushBufferDataSource { protected Object [] controls = new Object[0]; protected boolean started = false; protected String contentType = "raw"; protected boolean connected = false; protected Time duration = DURATION_UNKNOWN; protected LiveStream [] streams = null; protected LiveStream stream = null; public dataSource() { } public String getContentType() { if (!connected){ System.err.println("Error: dataSource not connected"); return null; } return contentType; } public void connect() throws IOException { if (connected) return; connected = true; } public void disconnect() { try { if (started) stop(); } catch (IOException e) {} connected = false; } public void start() throws IOException { // we need to throw error if connect() has not been called if (!connected) throw new java.lang.Error("dataSource must be connected before it can be started"); if (started) return; started = true; stream.start(true); } public void stop() throws IOException { if ((!connected) || (!started)) return; started = false; stream.start(false); } public Object [] getControls() { return controls; } public Object getControl(String controlType) { try { Class cls = Class.forName(controlType); Object cs[] = getControls(); for (int i = 0; i < cs.length; i++) { if (cls.isInstance(cs[i])) return cs[i]; } return null; } catch (Exception e) { // no such controlType or such control return null; } } public Time getDuration() { return duration; } public PushBufferStream [] getStreams() { if (streams == null) { streams = new LiveStream[1]; stream = streams[0] = new LiveStream(); } return streams; } }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -