@Override public String getName() { return cdi.getName(); }
/** * ControllerListener for the Players. */ @Override public synchronized void controllerUpdate(ControllerEvent ce) { Player p = (Player) ce.getSourceController(); if (p == null) return; // Get this when the internal players are realized. if (ce instanceof RealizeCompleteEvent) { p.start(); } if (ce instanceof ControllerErrorEvent) { p.removeControllerListener(this); LOGGER.severe("Receiver internal error: " + ce); } } }
/** * Get video format for size. * * @param device device to get format from * @param size specific size to search * @return VideoFormat */ private VideoFormat getSizedVideoFormat(Dimension size) { Format[] formats = device.getFormats(); VideoFormat format = null; for (Format f : formats) { if (!"RGB".equalsIgnoreCase(f.getEncoding()) || !(f instanceof VideoFormat)) { continue; } Dimension d = ((VideoFormat) f).getSize(); if (d.width == size.width && d.height == size.height) { format = (VideoFormat) f; break; } } return format; }
ds = javax.media.Manager.createDataSource(locator); ds = javax.media.Manager.createDataSource(new MediaLocator("javasound://")); processor = javax.media.Manager.createProcessor(ds); TrackControl[] tracks = processor.getTrackControls(); ContentDescriptor cd = new ContentDescriptor(ContentDescriptor.RAW_RTP); processor.setContentDescriptor(cd); if (tracks[i].isEnabled()) { supported = tracks[i].getSupportedFormats(); if (this.format.matches(format)) chosen = format; tracks[i].setFormat(chosen); LOGGER.severe("Track " + i + " is set to transmit as: " + chosen); if (tracks[i].getFormat() instanceof AudioFormat) { int packetRate = 20; PacketSizeControl pktCtrl = (PacketSizeControl) processor.getControl(PacketSizeControl.class.getName()); if (pktCtrl != null) { try { pktCtrl.setPacketSize(getPacketSize(tracks[i].getFormat(), packetRate)); pktCtrl.setPacketSize(80);
try { AudioFormat af = new AudioFormat(AudioFormat.LINEAR, 44100, 16, 2); rend.setInputFormat(af); rend.open(); Format[] inputFormats = rend.getSupportedInputFormats(); PlugInManager.addPlugIn(dar, inputFormats, new Format[0], plType); Vector<String> rendList = PlugInManager.getPlugInList(null, null, plType); int listSize = rendList.size(); rendList.removeElementAt(listSize - 1); rendList.insertElementAt(dar, 0); PlugInManager.setPlugInList(rendList, plType); PlugInManager.commit(); rend.close();
/** * Stops the transmission if already started. * Stops the receiver also. */ public void stop() { if (!started) return; synchronized (this) { try { started = false; if (processor != null) { processor.stop(); processor = null; for (RTPManager rtpMgr : rtpMgrs) { rtpMgr.removeReceiveStreamListener(audioReceiver); rtpMgr.removeSessionListener(audioReceiver); rtpMgr.removeTargets("Session ended."); rtpMgr.dispose(); } sendStreams.clear(); } } catch (Exception e) { LOGGER.log(Level.WARNING, "exception", e); } } }
private synchronized boolean waitForState(Processor p, int state) { p.addControllerListener(new StateListener()); failed = false; // Call the required method on the processor if (state == Processor.Configured) { p.configure(); } else if (state == Processor.Realized) { p.realize(); } // Wait until we get an event that confirms the // success of the method, or a failure event. // See StateListener inner class while (p.getState() < state && !failed) { synchronized (getStateLock()) { try { getStateLock().wait(); } catch (InterruptedException ie) { return false; } } } return !failed; }
public PlayerStarter(Player player) { setDaemon(true); player.addControllerListener(this); player.start(); }
Vector<String> rendList = PlugInManager.getPlugInList(null, null, plType); int listSize = rendList.size(); PlugInManager.setPlugInList(rendList, plType); PlugInManager.commit();
@Override public void close() { if (!started && !available && !open) { LOG.debug("Cannot close webcam"); return; } LOG.debug("Closing webcam"); open = false; if (started || available) { started = false; available = false; player.stop(); player.close(); player.deallocate(); } }
localhost = InetAddress.getLocalHost(); AudioChannel audioChannel0 = new AudioChannel(new MediaLocator("javasound://8000"), localhost.getHostAddress(), localhost.getHostAddress(), 7002, 7020, new AudioFormat(AudioFormat.GSM_RTP), null); AudioChannel audioChannel1 = new AudioChannel(new MediaLocator("javasound://8000"), localhost.getHostAddress(), localhost.getHostAddress(), 7020, 7002, new AudioFormat(AudioFormat.GSM_RTP), null);
/** * Starts the transmission. Returns null if transmission started ok. * Otherwise it returns a string with the reason why the setup failed. * Starts receive also. * * @return result description */ public synchronized String start() { if (started) return null; // Create a processor for the specified jmf locator String result = createProcessor(); if (result != null) { started = false; } // Create an RTP session to transmit the output of the // processor to the specified IP address and port no. result = createTransmitter(); if (result != null) { processor.close(); processor = null; started = false; } else { started = true; } // Start the transmission processor.start(); return null; }
locator = device.getLocator(); format = createFormat(viewSize); converter = new BufferToImage(format); player = Manager.createRealizedPlayer(locator); } catch (Exception e) { throw new RuntimeException(e); grabber = (FrameGrabbingControl) getControl(GRABBING_CTRL); if (control.setFormat(format) == null) { throw new RuntimeException("Cannot change video format");
@Override public void run() { // wait for start while (!started) { try { Thread.sleep(10); } catch (InterruptedException e) { e.printStackTrace(); } started = player.getState() == Controller.Started; if (started) { break; } } // try to grab single image (wait 10 seconds) for (int i = 0; i < 100; i++) { Buffer buffer = grabber.grabFrame(); if (buffer.getLength() == 0) { try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } } } semaphore.release(); }
/** * Get the best stanza size for a given codec and a codec rate * * @param codecFormat * @param milliseconds * @return the best stanza size * @throws IllegalArgumentException */ private int getPacketSize(Format codecFormat, int milliseconds) throws IllegalArgumentException { String encoding = codecFormat.getEncoding(); if (encoding.equalsIgnoreCase(AudioFormat.GSM) || encoding.equalsIgnoreCase(AudioFormat.GSM_RTP)) { return milliseconds * 4; // 1 byte per millisec } else if (encoding.equalsIgnoreCase(AudioFormat.ULAW) || encoding.equalsIgnoreCase(AudioFormat.ULAW_RTP)) { return milliseconds * 8; } else { throw new IllegalArgumentException("Unknown codec type"); } }
/** * Initialize the Audio Channel to make it able to send and receive audio. */ @Override public void initialize() { String ip; String localIp; int localPort; int remotePort; if (this.getLocal().getSymmetric() != null) { ip = this.getLocal().getIp(); localIp = this.getLocal().getLocalIp(); localPort = getFreePort(); remotePort = this.getLocal().getSymmetric().getPort(); LOGGER.fine(this.getLocal().getConnection() + " " + ip + ": " + localPort + "->" + remotePort); } else { ip = this.getRemote().getIp(); localIp = this.getLocal().getLocalIp(); localPort = this.getLocal().getPort(); remotePort = this.getRemote().getPort(); } audioChannel = new AudioChannel(new MediaLocator(this.getMediaLocator()), localIp, ip, localPort, remotePort, AudioFormatUtils.getAudioFormat(this.getPayloadType()),this); }
@Override public List<WebcamDevice> getDevices() { if (devices == null) { devices = new ArrayList<WebcamDevice>(); @SuppressWarnings("unchecked") Vector<Object> cdis = CaptureDeviceManager.getDeviceList(new Format("RGB")); Iterator<Object> di = cdis.iterator(); while (di.hasNext()) { CaptureDeviceInfo cdi = (CaptureDeviceInfo) di.next(); devices.add(new JmfDevice(cdi)); } } return devices; }
/** * Get player control. * * @param name control name * @return Player control */ private Control getControl(String name) { Control control = player.getControl(name); if (control == null) { throw new RuntimeException("Cannot find format control " + name); } return control; }
/** * Get suitable video format to use (the largest one by default, but this * can be easily changed). * * @param device device to get video format for * @return Suitable video format */ private VideoFormat getLargestVideoFormat() { Format[] formats = device.getFormats(); VideoFormat format = null; int area = 0; // find the largest picture format for (Format f : formats) { if (!(f instanceof VideoFormat) || !"RGB".equalsIgnoreCase(f.getEncoding())) { continue; } VideoFormat vf = (VideoFormat) f; Dimension dim = vf.getSize(); int a = dim.width * dim.height; if (a > area) { area = a; format = vf; } } return format; }
@Override public Dimension[] getResolutions() { if (dimensions == null) { dimensions = new ArrayList<Dimension>(); Format[] formats = cdi.getFormats(); for (Format format : formats) { if ("RGB".equalsIgnoreCase(format.getEncoding())) { dimensions.add(((VideoFormat) format).getSize()); } } Collections.sort(dimensions, new Comparator<Dimension>() { @Override public int compare(Dimension a, Dimension b) { int apx = a.width * a.height; int bpx = b.width * b.height; if (apx > bpx) { return 1; } else if (apx < bpx) { return -1; } else { return 0; } } }); } return dimensions.toArray(new Dimension[dimensions.size()]); }