Clone DataSource - view video while transmitting - EXAMPLE no answer

Thanks to me and captfoss, I create this application for all who want to understand how to clone DataSource.
Use this on SERVER side
* @(#)AVTransmit3.java     1.2 01/03/13
* Copyright (c) 1999-2001 Sun Microsystems, Inc. All Rights Reserved.
* Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
* modify and redistribute this software in source and binary code form,
* provided that i) this copyright notice and license appear on all copies of
* the software; and ii) Licensee does not utilize the software in a manner
* which is disparaging to Sun.
* This software is provided "AS IS," without a warranty of any kind. ALL
* EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
* IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
* LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
* OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
* LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
* INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
* CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
* OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGES.
* This software is not designed or intended for use in on-line control of
* aircraft, air traffic, aircraft navigation or aircraft communications; or in
* the design, construction, operation or maintenance of any nuclear
* facility. Licensee represents and warrants that it will not use or
* redistribute the Software for such purposes.
import java.awt.*;
import java.io.*;
import java.net.InetAddress;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.media.*;
import javax.media.protocol.*;
import javax.media.protocol.DataSource;
import javax.media.format.*;
import javax.media.control.TrackControl;
import javax.media.control.QualityControl;
import javax.media.rtp.*;
import javax.media.rtp.rtcp.*;
public class AVTransmit3 {
    // Input MediaLocator
    // Can be a file or http or capture source
    private MediaLocator locator;
    private String ipAddress;
    private int portBase;
    private Processor processor = null;
    private RTPManager rtpMgrs[];
    private DataSource dataOutput = null;
    private static boolean v = false;  
     private static DataSource ds = null;
    private static DataSource clone;
     private static DataSource cloned;       
    private String VFORMAT = "h263/rtp";   
    private String AFORMAT = "mpegaudio/rtp";   
    public AVTransmit3(MediaLocator locator,
                String ipAddress,
                String pb,
                Format format) {
     this.locator = locator;
     this.ipAddress = ipAddress;
     Integer integer = Integer.valueOf(pb);
     if (integer != null)
         this.portBase = integer.intValue();
     * Starts the transmission. Returns null if transmission started ok.
     * Otherwise it returns a string with the reason why the setup failed.
    public synchronized String start() {
     String result;
     // Create a processor for the specified media locator
     // and program it to output JPEG/RTP
     result = createProcessor();
     if (result != null)
         return result;
     // 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;
         return result;
     // Start the transmission
     processor.start();
     return null;
     * Stops the transmission if already started
    public void stop() {
     synchronized (this) {
         if (processor != null) {
          processor.stop();
          processor.close();
          processor = null;
          for (int i = 0; i < rtpMgrs.length; i++) {
              rtpMgrs.removeTargets( "Session ended.");
          rtpMgrs[i].dispose();
private String createProcessor() {
     if (locator == null)
     return "Locator is null";
     try {
     ds = javax.media.Manager.createDataSource(locator);
     } catch (Exception e) {
     return "Couldn't create DataSource";
//----------------------------------------------------Start
if(v)
/* Get a clonable version of our datasource */
ds = Manager.createCloneableDataSource(ds);
/* Make sure we got a clonable version before we try to clone it */
if (ds == null) {
System.err.println("Cannot get a clonable version of the datasource");
System.exit(0);
/* Create the clone of our original datasource */
DataSource dsClone = ((SourceCloneable)ds).createClone();
/* Make sure the clone happened successfully */
if (dsClone == null) {
System.err.println("Could not clone our datasource");
System.exit(0);
/* Create a new Clone class */
Clone cloneV = new Clone();
/* Open our clone class with our datasource clone */
if (! cloneV.open(dsClone))
System.exit(0);
//----------------------------------------------------End
     // Try to create a processor to handle the input media locator
     try {
     processor = javax.media.Manager.createProcessor(ds);
     } catch (NoProcessorException npe) {
     return "Couldn't create processor";
     } catch (IOException ioe) {
     return "IOException creating processor";
     // Wait for it to configure
     boolean result = waitForState(processor, Processor.Configured);
     if (result == false)
     return "Couldn't configure processor";
     // Get the tracks from the processor
     TrackControl [] tracks = processor.getTrackControls();
     // Do we have atleast one track?
     if (tracks == null || tracks.length < 1)
     return "Couldn't find tracks in processor";
     // Set the output content descriptor to RAW_RTP
     // This will limit the supported formats reported from
     // Track.getSupportedFormats to only valid RTP formats.
     ContentDescriptor cd = new ContentDescriptor(ContentDescriptor.RAW_RTP);
     processor.setContentDescriptor(cd);
     Format supported[];
     Format chosen = null;
     boolean atLeastOneTrack = false;
     // Program the tracks.
     for (int i = 0; i < tracks.length; i++)
AudioFormat aFormat = new AudioFormat(AFORMAT, 22050.00, 16, 1);
     Format format = tracks[i].getFormat();
     if (tracks[i].isEnabled())
          supported = tracks[i].getSupportedFormats();
          // We've set the output content to the RAW_RTP.
          // So all the supported formats should work with RTP.
          // We'll just pick the first one.
          if (supported.length > 0)
for(int k = 0; k < supported.length; k++)
if ((supported[k] instanceof VideoFormat) &&
(supported[k].getEncoding().equalsIgnoreCase(VFORMAT)))
// For video formats, we should double check the
// sizes since not all formats work in all sizes.
// Choose the H263rtp
chosen = checkForVideoSizes(tracks[i].getFormat(), supported[k]);
v = true;
break;
else if ((supported[k] instanceof AudioFormat) &&
(supported[k].matches(aFormat)))
// For audio formats
// Choose the H263rtp
// chosen = supported[3];
chosen = supported[k];
v = false;
break;
          tracks[i].setFormat(chosen);
          System.err.println("Track " + i + " is set to transmit as:");
          System.err.println(" " + chosen);
          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";
     // Realize the processor. This will internally create a flow
     // graph and attempt to create an output datasource for JPEG/RTP
     // audio frames.
     result = waitForState(processor, Controller.Realized);
     if (result == false)
     return "Couldn't realize processor";
     // Set the JPEG quality to .5.
     setJPEGQuality(processor, 0.5f);
     // Get the output data source of the processor
     dataOutput = processor.getDataOutput();
     return null;
* Use the RTPManager API to create sessions for each media
* track of the processor.
private String createTransmitter() {
     // Cheated. Should have checked the type.
     PushBufferDataSource pbds = (PushBufferDataSource)dataOutput;
     PushBufferStream pbss[] = pbds.getStreams();
     rtpMgrs = new RTPManager[pbss.length];
     SendStream sendStream;
     int port;
     SourceDescription srcDesList[];
     for (int i = 0; i < pbss.length; i++) {
     try {
          rtpMgrs[i] = RTPManager.newInstance();     
          port = portBase + 2*i;
          // Initialize the RTPManager with the RTPSocketAdapter
          rtpMgrs[i].initialize(new RTPSocketAdapter(
                         InetAddress.getByName(ipAddress),
                         port));
          System.err.println( "Created RTP session: " + ipAddress + " " + port);
          sendStream = rtpMgrs[i].createSendStream(dataOutput, i);          
          sendStream.start();
     } catch (Exception e) {
          return e.getMessage();
     return null;
* For JPEG and H263, we know that they only work for particular
* sizes. So we'll perform extra checking here to make sure they
* are of the right sizes.
Format checkForVideoSizes(Format original, Format supported) {
     int width, height;
     Dimension size = ((VideoFormat)original).getSize();
     Format jpegFmt = new Format(VideoFormat.JPEG_RTP);
     Format h263Fmt = new Format(VideoFormat.H263_RTP);
     if (supported.matches(jpegFmt)) {
     // For JPEG, make sure width and height are divisible by 8.
     width = (size.width % 8 == 0 ? size.width :
                    (int)(size.width / 8) * 8);
     height = (size.height % 8 == 0 ? size.height :
                    (int)(size.height / 8) * 8);
     } else if (supported.matches(h263Fmt)) {
     // For H.263, we only support some specific sizes.
     if (size.width < 128) {
          width = 128;
          height = 96;
     } else if (size.width < 176) {
          width = 176;
          height = 144;
     } else {
          width = 352;
          height = 288;
     } else {
     // We don't know this particular format. We'll just
     // leave it alone then.
     return supported;
     return (new VideoFormat(null,
                    new Dimension(width, height),
                    Format.NOT_SPECIFIED,
                    null,
                    Format.NOT_SPECIFIED)).intersects(supported);
* Setting the encoding quality to the specified value on the JPEG encoder.
* 0.5 is a good default.
void setJPEGQuality(Player p, float val) {
     Control cs[] = p.getControls();
     QualityControl qc = null;
     VideoFormat jpegFmt = new VideoFormat(VideoFormat.JPEG);
     // Loop through the controls to find the Quality control for
     // the JPEG encoder.
     for (int i = 0; i < cs.length; i++) {
     if (cs[i] instanceof QualityControl &&
          cs[i] instanceof Owned) {
          Object owner = ((Owned)cs[i]).getOwner();
          // Check to see if the owner is a Codec.
          // Then check for the output format.
          if (owner instanceof Codec) {
          Format fmts[] = ((Codec)owner).getSupportedOutputFormats(null);
          for (int j = 0; j < fmts.length; j++) {
               if (fmts[j].matches(jpegFmt)) {
               qc = (QualityControl)cs[i];
               qc.setQuality(val);
               System.err.println("- Setting quality to " +
                         val + " on " + qc);
               break;
          if (qc != null)
          break;
* Convenience methods to handle processor's state changes.
private Integer stateLock = new Integer(0);
private boolean failed = false;
Integer getStateLock() {
     return stateLock;
void setFailed() {
     failed = true;
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;
     if (failed)
     return false;
     else
     return true;
* Inner Classes
class StateListener implements ControllerListener {
     public void controllerUpdate(ControllerEvent ce) {
     // If there was an error during configure or
     // realize, the processor will be closed
     if (ce instanceof ControllerClosedEvent)
          setFailed();
     // All controller events, send a notification
     // to the waiting thread in waitForState method.
     if (ce instanceof ControllerEvent) {
          synchronized (getStateLock()) {
          getStateLock().notifyAll();
* Sample Usage for AVTransmit3 class
public static void main(String [] args) {
     // We need three parameters to do the transmission
     // For example,
     // java AVTransmit3 file:/C:/media/test.mov 129.130.131.132 42050
     Format fmt = null;
     int i = 0;
String title = "Video";
     // Create a audio transmit object with the specified params.
AVTransmit3 at = new AVTransmit3(new MediaLocator("vfw://0"),
                         "192.168.0.3", "12345", fmt);
//View GUI
JFrameMain jfm = new JFrameMain(at);
jfm.setVisible(true);
jfm.setTitle(title);
if(title.equals("Video"))
jfm.setLocation(jfm.getX()+180, jfm.getY());
v = true;
     // Start the transmission
     String result = at.start();
     // result will be non-null if there was an error. The return
     // value is a String describing the possible error. Print it.
     if (result != null) {
     System.err.println("Error : " + result);
     System.exit(0);
     System.err.println("Start transmission...");
try {
Thread.sleep(2000);
} catch (InterruptedException ex) {
Logger.getLogger(AVTransmit3.class.getName()).log(Level.SEVERE, null, ex);
/* Clone.java
* To change this template, choose Tools | Templates
* and open the template in the editor.
import java.awt.*;
import javax.media.*;
import javax.media.protocol.DataSource;
public class Clone extends Frame implements ControllerListener {
Player p;
Object waitSync = new Object();
boolean stateTransitionOK = true;
* Given a DataSource, create a player and use that player
* as a player to playback the media.
public boolean open(DataSource ds) {
     System.err.println("create player for: " + ds.getContentType());
     try {
     p = Manager.createPlayer(ds);
     } catch (Exception e) {
     System.err.println("Failed to create a player from the given DataSource: " + e);
     return false;
     p.addControllerListener(this);
     // Realize the player.
     p.prefetch();
     if (!waitForState(p.Prefetched)) {
     System.err.println("Failed to realize the player.");
     return false;
     // Display the visual & control component if there's one.
     setLayout(new BorderLayout());
//     Component cc;
     Component vc;
     if ((vc = p.getVisualComponent()) != null) {
     add("Center", vc);
//     if ((cc = p.getControlPanelComponent()) != null) {
//     add("South", cc);
     // Start the player.
     p.start();
     setVisible(true);
     return true;
public void addNotify() {
     super.addNotify();
     pack();
* Block until the player has transitioned to the given state.
* Return false if the transition failed.
boolean waitForState(int state) {
     synchronized (waitSync) {
     try {
          while (p.getState() < state && stateTransitionOK)
          waitSync.wait();
     } catch (Exception e) {}
     return stateTransitionOK;
* Controller Listener.
public void controllerUpdate(ControllerEvent evt) {
     if (evt instanceof ConfigureCompleteEvent ||
     evt instanceof RealizeCompleteEvent ||
     evt instanceof PrefetchCompleteEvent) {
     synchronized (waitSync) {
          stateTransitionOK = true;
          waitSync.notifyAll();
     } else if (evt instanceof ResourceUnavailableEvent) {
     synchronized (waitSync) {
          stateTransitionOK = false;
          waitSync.notifyAll();
     } else if (evt instanceof EndOfMediaEvent) {
     p.close();
     //System.exit(0);
     } else if (evt instanceof SizeChangeEvent) {
* @(#)RTPSocketAdapter.java     1.2 01/03/13
* Copyright (c) 1999-2001 Sun Microsystems, Inc. All Rights Reserved.
* Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
* modify and redistribute this software in source and binary code form,
* provided that i) this copyright notice and license appear on all copies of
* the software; and ii) Licensee does not utilize the software in a manner
* which is disparaging to Sun.
* This software is provided "AS IS," without a warranty of any kind. ALL
* EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
* IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
* LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
* OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
* LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
* INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
* CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
* OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGES.
* This software is not designed or intended for use in on-line control of
* aircraft, air traffic, aircraft navigation or aircraft communications; or in
* the design, construction, operation or maintenance of any nuclear
* facility. Licensee represents and warrants that it will not use or
* redistribute the Software for such purposes.
import java.io.IOException;
import java.net.InetAddress;
import java.net.DatagramSocket;
import java.net.MulticastSocket;
import java.net.DatagramPacket;
import java.net.SocketException;
import javax.media.protocol.DataSource;
import javax.media.protocol.PushSourceStream;
import javax.media.protocol.ContentDescriptor;
import javax.media.protocol.SourceTransferHandler;
import javax.media.rtp.RTPConnector;
import javax.media.rtp.OutputDataStream;
* An implementation of RTPConnector based on UDP sockets.
public class RTPSocketAdapter implements RTPConnector {
DatagramSocket dataSock;
DatagramSocket ctrlSock;
InetAddress addr;
int port;
SockInputStream dataInStrm = null, ctrlInStrm = null;
SockOutputStream dataOutStrm = null, ctrlOutStrm = null;
public RTPSocketAdapter(InetAddress addr, int port) throws IOException {
     this(addr, port, 1);
public RTPSocketAdapter(InetAddress addr, int port, int ttl) throws IOException {
     try {
     if (addr.isMulticastAddress()) {
          dataSock = new MulticastSocket(port);
          ctrlSock = new MulticastSocket(port+1);
          ((MulticastSocket)dataSock).joinGroup(addr);
          ((MulticastSocket)dataSock).setTimeToLive(ttl);
          ((MulticastSocket)ctrlSock).joinGroup(addr);
          ((MulticastSocket)ctrlSock).setTimeToLive(ttl);
     } else {
          dataSock = new DatagramSocket(port, InetAddress.getLocalHost());
          ctrlSock = new DatagramSocket(port+1, InetAddress.getLocalHost());
     } catch (SocketException e) {
     throw new IOException(e.getMessage());
     this.addr = addr;
     this.port = port;
* Returns an input stream to receive the RTP data.
public PushSourceStream getDataInputStream() throws IOException {
     if (dataInStrm == null) {
     dataInStrm = new SockInputStream(dataSock, addr, port);
     dataInStrm.start();
     return dataInStrm;
* Returns an output stream to send the RTP data.
public OutputDataStream getDataOutputStream() throws IOException {
     if (dataOutStrm == null)
     dataOutStrm = new SockOutputStream(dataSock, addr, port);
     return dataOutStrm;
* Returns an input stream to receive the RTCP data.
public PushSourceStream getControlInputStream() throws IOException {
     if (ctrlInStrm == null) {
     ctrlInStrm = new SockInputStream(ctrlSock, addr, port+1);
     ctrlInStrm.start();
     return ctrlInStrm;
* Returns an output stream to send the RTCP data.
public OutputDataStream getControlOutputStream() throws IOException {
     if (ctrlOutStrm == null)
     ctrlOutStrm = new SockOutputStream(ctrlSock, addr, port+1);
     return ctrlOutStrm;
* Close all the RTP, RTCP streams.
public void close() {
     if (dataInStrm != null)
     dataInStrm.kill();
     if (ctrlInStrm != null)
     ctrlInStrm.kill();
     dataSock.close();
     ctrlSock.close();
* Set the receive buffer size of the RTP data channel.
* This is only a hint to the implementation. The actual implementation
* may not be able to do anything to this.
public void setReceiveBufferSize( int size) throws IOException {
     dataSock.setReceiveBufferSize(size);
* Get the receive buffer size set on the RTP data channel.
* Return -1 if the receive buffer size is not applicable for
* the implementation.
public int getReceiveBufferSize() {
     try {
     return dataSock.getReceiveBufferSize();
     } catch (Exception e) {
     return -1;
* Set the send buffer size of the RTP data channel.
* This is only a hint to the implementation. The actual implementation
* may not be able to do anything to this.
public void setSendBufferSize( int size) throws IOException {
     dataSock.setSendBufferSize(size);
* Get the send buffer size set on the RTP data channel.
* Return -1 if the send buffer size is not applicable for
* the implementation.
public int getSendBufferSize() {
     try {
     return dataSock.getSendBufferSize();
     } catch (Exception e) {
     return -1;
* Return the RTCP bandwidth fraction. This value is used to
* initialize the RTPManager. Check RTPManager for more detauls.
* Return -1 to use the default values.
public double getRTCPBandwidthFraction() {
     return -1;
* Return the RTCP sender bandwidth fraction. This value is used to
* initialize the RTPManager. Check RTPManager for more detauls.
* Return -1 to use the default values.
public double getRTCPSenderBandwidthFraction() {
     return -1;
* An inner class to implement an OutputDataStream based on UDP sockets.
class SockOutputStream implements OutputDataStream {
     DatagramSocket sock;
     InetAddress addr;
     int port;
     public SockOutputStream(DatagramSocket sock, InetAddress addr, int port) {
     this.sock = sock;
     this.addr = addr;
     this.port = port;
     public int write(byte data[], int offset, int len) {
     try {
          sock.send(new DatagramPacket(data, offset, len, addr, port));
     } catch (Exception e) {
          return -1;
     return len;
* An inner class to implement an PushSourceStream based on UDP sockets.
class SockInputStream extends Thread implements PushSourceStream {
     DatagramSocket sock;
     InetAddress addr;
     int port;
     boolean done = false;
     boolean dataRead = false;
     SourceTransferHandler sth = null;
     public SockInputStream(DatagramSocket sock, InetAddress addr, int port) {
     this.sock = sock;
     this.addr = addr;
     this.port = port;
     public int read(byte buffer[], int offset, int length) {
     DatagramPacket p = new DatagramPacket(buffer, offset, length, addr, port);
     try {
          sock.receive(p);
     } catch (IOException e) {
          return -1;
     synchronized (this) {
          dataRead = true;
          notify();
     return p.getLength();
     public synchronized void start() {
     super.start();
     if (sth != null) {
          dataRead = true;
          notify();
     public synchronized void kill() {
     done = true;
     notify();
     public int getMinimumTransferSize() {
     return 2 * 1024;     // twice the MTU size, just to be safe.
     public synchronized void setTransferHandler(SourceTransferHandler sth) {
     this.sth = sth;
     dataRead = true;
     notify();
     // Not applicable.
     public ContentDescriptor getContentDescriptor() {
     return null;
     // Not applicable.
     public long getContentLength() {
     return LENGTH_UNKNOWN;
     // Not applicable.
     public boolean endOfStream() {
     return false;
     // Not applicable.
     public Object[] getControls() {
     return new Object[0];
     // Not applicable.
     public Object getControl(String type) {
     return null;
     * Loop and notify the transfer handler of new data.
     public void run() {
     while (!done) {
          synchronized (this) {
          while (!dataRead && !done) {
               try {
               wait();
               } catch (InterruptedException e) { }
          dataRead = false;
          if (sth != null && !done) {
          sth.transferData(this);
* JFrameMain.java
* @author Giovanni
public class JFrameMain extends javax.swing.JFrame {
/** Creates new form JFrameMain */
public JFrameMain(AVTransmit3 avt) {
avTransmit = avt;
initComponents();
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jButtonFine = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setResizable(false);
jButtonFine.setText("Fine Trasmissione");
jButtonFine.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
jButtonFineMousePressed(evt);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jButtonFine, javax.swing.GroupLayout.DEFAULT_SIZE, 124, Short.MAX_VALUE)
.addContainerGap())
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jButtonFine, javax.swing.GroupLayout.DEFAULT_SIZE, 32, Short.MAX_VALUE)
.addContainerGap())
setBounds(600, 110, 160, 90);
}// </editor-fold>
private void jButtonFineMousePressed(java.awt.event.MouseEvent evt) {                                        
avTransmit.stop();
System.exit(0);
* @param args the command line arguments
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
// new JFrameMain().setVisible(true);
// Variables declaration - do not modify
private javax.swing.JButton jButtonFine;
// End of variables declaration
private AVTransmit3 avTransmit = null;
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  

It's shake and bake, and I helped...

Similar Messages

  • Is there a way to view video while using Capture?

    This 'playing on video hardware' thing.
    Is that just a 'it's just part of the program, get used to it' situation or is there something I can do to view the video I'm caputuring?
    Thank you in advance for your time.
    Brad

    "No; HDV is not displayed during capture in the capture window. SD video is though. "
    Thanks CWRIG,
    It's just one of those things. .
    It puts my mind at ease knowing I can't do anything about it.
    So, I'm not spending the next 3 hours searching for a solution that doesn't exsist.
    -Brad

  • View video from webcam while transmitting

    Hi everyone, when I try to use AVTransmit3.java and Clone.java (example from sun) to see video from webcam while transmitting, an error occur:
    {color:#ff0000}+java.lang.NullPointerException+
    at com.sun.media.codec.video.colorspace.RGBConverter.process(RGBConverter.java:352)
    at com.sun.media.BasicFilterModule.process(BasicFilterModule.java:322)
    at com.sun.media.BasicModule.connectorPushed(BasicModule.java:69)
    at com.sun.media.BasicOutputConnector.writeReport(BasicOutputConnector.java:120)
    at com.sun.media.SourceThread.process(BasicSourceModule.java:655)
    at com.sun.media.util.LoopThread.run(LoopThread.java:135){color}
    So I'm only able to see in local my captured video, but cannot transmit.
    I try to debug JMStudio to find how to do this(monitoring transmitted video), but I'm not able to debug it.
    In method private String createProcessor() of AVTransmit3.java I added
    //----------------------------------------------------Start
                clone = Manager.createCloneableDataSource(ds);
                if (clone == null) {
                    System.err.println("Cannot clone the given DataSource");
                    System.exit(0);
                Clone cloneV = new Clone();
                if (!cloneV.open(clone))
                    System.exit(0);             
    //----------------------------------------------------End       
         return null;
        }This is the clone.java from sun
    /* Clone.java
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    *import java.awt.*;
    import javax.media.*;
    import javax.media.protocol.DataSource;
    public class Clone extends Frame implements ControllerListener {
        Player p;
        Object waitSync = new Object();
        boolean stateTransitionOK = true;
         * Given a DataSource, create a player and use that player
         * as a player to playback the media.
        public boolean open(DataSource ds) {
         System.err.println("create player for: " + ds.getContentType());
         try {
             p = Manager.createPlayer(ds);
         } catch (Exception e) {
             System.err.println("Failed to create a player from the given DataSource: " + e);
             return false;
         p.addControllerListener(this);
         // Realize the player.
         p.prefetch();
         if (!waitForState(p.Prefetched)) {
             System.err.println("Failed to realize the player.");
             return false;
         // Display the visual & control component if there's one.
         setLayout(new BorderLayout());
    //     Component cc;
         Component vc;
         if ((vc = p.getVisualComponent()) != null) {
                vc.setSize(176, 144);
             add("Center", vc);
    //     if ((cc = p.getControlPanelComponent()) != null) {
    //         add("South", cc);
         // Start the player.
         p.start();
            this.setSize(176, 144);
         setVisible(true);
         return true;
        public void addNotify() {
         super.addNotify();
         pack();
         * Block until the player has transitioned to the given state.
         * Return false if the transition failed.
        boolean waitForState(int state) {
         synchronized (waitSync) {
             try {
              while (p.getState() < state && stateTransitionOK)
                  waitSync.wait();
             } catch (Exception e) {}
         return stateTransitionOK;
         * Controller Listener.
        public void controllerUpdate(ControllerEvent evt) {
         if (evt instanceof ConfigureCompleteEvent ||
             evt instanceof RealizeCompleteEvent ||
             evt instanceof PrefetchCompleteEvent) {
             synchronized (waitSync) {
              stateTransitionOK = true;
              waitSync.notifyAll();
         } else if (evt instanceof ResourceUnavailableEvent) {
             synchronized (waitSync) {
              stateTransitionOK = false;
              waitSync.notifyAll();
         } else if (evt instanceof EndOfMediaEvent) {
             p.close();
             //System.exit(0);
         } else if (evt instanceof SizeChangeEvent) {
    }Please can you tell me what is wrong?
    thank you in advance

    I post all the class I use in this project.
    Copy and create your own project (SERVER side)
    Then on other pc (CLIENT side) run JMStudio and open RTP transmission: you will receive data but on server you will have a black window.
    I've modified only AVtransmit3.java -> look at Main() and modify dest-ip and port.
    JFrameMain is a class with a button to close the application.
    * @(#)AVTransmit3.java     1.2 01/03/13
    * Copyright (c) 1999-2001 Sun Microsystems, Inc. All Rights Reserved.
    * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
    * modify and redistribute this software in source and binary code form,
    * provided that i) this copyright notice and license appear on all copies of
    * the software; and ii) Licensee does not utilize the software in a manner
    * which is disparaging to Sun.
    * This software is provided "AS IS," without a warranty of any kind. ALL
    * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
    * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
    * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
    * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
    * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
    * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
    * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
    * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
    * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
    * POSSIBILITY OF SUCH DAMAGES.
    * This software is not designed or intended for use in on-line control of
    * aircraft, air traffic, aircraft navigation or aircraft communications; or in
    * the design, construction, operation or maintenance of any nuclear
    * facility. Licensee represents and warrants that it will not use or
    * redistribute the Software for such purposes.
    import java.awt.*;
    import java.io.*;
    import java.net.InetAddress;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.media.*;
    import javax.media.protocol.*;
    import javax.media.protocol.DataSource;
    import javax.media.format.*;
    import javax.media.control.TrackControl;
    import javax.media.control.QualityControl;
    import javax.media.rtp.*;
    import javax.media.rtp.rtcp.*;
    import com.sun.media.rtp.*;
    import java.util.Vector;
    public class AVTransmit3 {
        // Input MediaLocator
        // Can be a file or http or capture source
        private MediaLocator locator;
        private String ipAddress;
        private int portBase;
        private Processor processor = null;
        private RTPManager rtpMgrs[];
        private DataSource dataOutput = null;
        private static boolean v = false;  
         private static DataSource ds = null;
            private static DataSource clone;
         private static DataSource cloned;       
        private String VFORMAT = "h263/rtp";   
        private String AFORMAT = "mpegaudio/rtp";   
        public AVTransmit3(MediaLocator locator,
                    String ipAddress,
                    String pb,
                    Format format) {
         this.locator = locator;
         this.ipAddress = ipAddress;
         Integer integer = Integer.valueOf(pb);
         if (integer != null)
             this.portBase = integer.intValue();
         * Starts the transmission. Returns null if transmission started ok.
         * Otherwise it returns a string with the reason why the setup failed.
        public synchronized String start() {
         String result;
         // Create a processor for the specified media locator
         // and program it to output JPEG/RTP
         result = createProcessor();
         if (result != null)
             return result;
         // 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;
             return result;
         // Start the transmission
         processor.start();
         return null;
         * Stops the transmission if already started
        public void stop() {
         synchronized (this) {
             if (processor != null) {
              processor.stop();
              processor.close();
              processor = null;
              for (int i = 0; i < rtpMgrs.length; i++) {
                  rtpMgrs.removeTargets( "Session ended.");
              rtpMgrs[i].dispose();
    private String createProcessor() {
         if (locator == null)
         return "Locator is null";
         try {
         ds = javax.media.Manager.createDataSource(locator);
         } catch (Exception e) {
         return "Couldn't create DataSource";
         // Try to create a processor to handle the input media locator
         try {
         processor = javax.media.Manager.createProcessor(ds);
         } catch (NoProcessorException npe) {
         return "Couldn't create processor";
         } catch (IOException ioe) {
         return "IOException creating processor";
         // Wait for it to configure
         boolean result = waitForState(processor, Processor.Configured);
         if (result == false)
         return "Couldn't configure processor";
         // Get the tracks from the processor
         TrackControl [] tracks = processor.getTrackControls();
         // Do we have atleast one track?
         if (tracks == null || tracks.length < 1)
         return "Couldn't find tracks in processor";
         // Set the output content descriptor to RAW_RTP
         // This will limit the supported formats reported from
         // Track.getSupportedFormats to only valid RTP formats.
         ContentDescriptor cd = new ContentDescriptor(ContentDescriptor.RAW_RTP);
         processor.setContentDescriptor(cd);
         Format supported[];
         Format chosen = null;
         boolean atLeastOneTrack = false;
         // Program the tracks.
         for (int i = 0; i < tracks.length; i++)
    AudioFormat aFormat = new AudioFormat(AFORMAT, 22050.00, 16, 1);
         Format format = tracks[i].getFormat();
         if (tracks[i].isEnabled())
              supported = tracks[i].getSupportedFormats();
              // We've set the output content to the RAW_RTP.
              // So all the supported formats should work with RTP.
              // We'll just pick the first one.
              if (supported.length > 0)
    for(int k = 0; k < supported.length; k++)
    if ((supported[k] instanceof VideoFormat) &&
    (supported[k].getEncoding().equalsIgnoreCase(VFORMAT)))
    // For video formats, we should double check the
    // sizes since not all formats work in all sizes.
    // Choose the H263rtp
    chosen = checkForVideoSizes(tracks[i].getFormat(), supported[k]);
    v = true;
    break;
    else if ((supported[k] instanceof AudioFormat) &&
    (supported[k].matches(aFormat)))
    // For audio formats
    // Choose the H263rtp
    // chosen = supported[3];
    chosen = supported[k];
    v = false;
    break;
              tracks[i].setFormat(chosen);
              System.err.println("Track " + i + " is set to transmit as:");
              System.err.println(" " + chosen);
              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";
         // Realize the processor. This will internally create a flow
         // graph and attempt to create an output datasource for JPEG/RTP
         // audio frames.
         result = waitForState(processor, Controller.Realized);
         if (result == false)
         return "Couldn't realize processor";
         // Set the JPEG quality to .5.
         setJPEGQuality(processor, 0.5f);
         // Get the output data source of the processor
         dataOutput = processor.getDataOutput();
         return null;
    * Use the RTPManager API to create sessions for each media
    * track of the processor.
    private String createTransmitter() {
         // Cheated. Should have checked the type.
         PushBufferDataSource pbds = (PushBufferDataSource)dataOutput;
         PushBufferStream pbss[] = pbds.getStreams();
         rtpMgrs = new RTPManager[pbss.length];
         SendStream sendStream;
         int port;
         SourceDescription srcDesList[];
         for (int i = 0; i < pbss.length; i++) {
         try {
              rtpMgrs[i] = RTPManager.newInstance();     
              port = portBase + 2*i;
              // Initialize the RTPManager with the RTPSocketAdapter
              rtpMgrs[i].initialize(new RTPSocketAdapter(
                             InetAddress.getByName(ipAddress),
                             port));
              System.err.println( "Created RTP session: " + ipAddress + " " + port);
              sendStream = rtpMgrs[i].createSendStream(dataOutput, i);          
              sendStream.start();
         } catch (Exception e) {
              return e.getMessage();
         return null;
    * For JPEG and H263, we know that they only work for particular
    * sizes. So we'll perform extra checking here to make sure they
    * are of the right sizes.
    Format checkForVideoSizes(Format original, Format supported) {
         int width, height;
         Dimension size = ((VideoFormat)original).getSize();
         Format jpegFmt = new Format(VideoFormat.JPEG_RTP);
         Format h263Fmt = new Format(VideoFormat.H263_RTP);
         if (supported.matches(jpegFmt)) {
         // For JPEG, make sure width and height are divisible by 8.
         width = (size.width % 8 == 0 ? size.width :
                        (int)(size.width / 8) * 8);
         height = (size.height % 8 == 0 ? size.height :
                        (int)(size.height / 8) * 8);
         } else if (supported.matches(h263Fmt)) {
         // For H.263, we only support some specific sizes.
         if (size.width < 128) {
              width = 128;
              height = 96;
         } else if (size.width < 176) {
              width = 176;
              height = 144;
         } else {
    ///mod          width = 352;
    width = 176;
    ///mod          height = 288;
    height = 144;
         } else {
         // We don't know this particular format. We'll just
         // leave it alone then.
         return supported;
         return (new VideoFormat(null,
                        new Dimension(width, height),
                        Format.NOT_SPECIFIED,
                        null,
                        Format.NOT_SPECIFIED)).intersects(supported);
    * Setting the encoding quality to the specified value on the JPEG encoder.
    * 0.5 is a good default.
    void setJPEGQuality(Player p, float val) {
         Control cs[] = p.getControls();
         QualityControl qc = null;
         VideoFormat jpegFmt = new VideoFormat(VideoFormat.JPEG);
         // Loop through the controls to find the Quality control for
         // the JPEG encoder.
         for (int i = 0; i < cs.length; i++) {
         if (cs[i] instanceof QualityControl &&
              cs[i] instanceof Owned) {
              Object owner = ((Owned)cs[i]).getOwner();
              // Check to see if the owner is a Codec.
              // Then check for the output format.
              if (owner instanceof Codec) {
              Format fmts[] = ((Codec)owner).getSupportedOutputFormats(null);
              for (int j = 0; j < fmts.length; j++) {
                   if (fmts[j].matches(jpegFmt)) {
                   qc = (QualityControl)cs[i];
                   qc.setQuality(val);
                   System.err.println("- Setting quality to " +
                             val + " on " + qc);
                   break;
              if (qc != null)
              break;
    * Convenience methods to handle processor's state changes.
    private Integer stateLock = new Integer(0);
    private boolean failed = false;
    Integer getStateLock() {
         return stateLock;
    void setFailed() {
         failed = true;
    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;
         if (failed)
         return false;
         else
         return true;
    * Inner Classes
    class StateListener implements ControllerListener {
         public void controllerUpdate(ControllerEvent ce) {
         // If there was an error during configure or
         // realize, the processor will be closed
         if (ce instanceof ControllerClosedEvent)
              setFailed();
         // All controller events, send a notification
         // to the waiting thread in waitForState method.
         if (ce instanceof ControllerEvent) {
              synchronized (getStateLock()) {
              getStateLock().notifyAll();
    * Sample Usage for AVTransmit3 class
    public static void main(String [] args) {
         Format fmt = null;
         int i = 0;
    String title = "Video";
    AVTransmit3 at = new AVTransmit3(new MediaLocator("vfw://0"),
                             "192.168.0.5", "44350", fmt);
    //View GUI
    JFrameMain jfm = new JFrameMain(at);
    jfm.setVisible(true);
    jfm.setTitle(title);
    if(title.equals("Video"))
    jfm.setLocation(jfm.getX()+180, jfm.getY());
         // Start the transmission
         String result = at.start();
         // result will be non-null if there was an error. The return
         // value is a String describing the possible error. Print it.
         if (result != null) {
         System.err.println("Error : " + result);
         System.exit(0);
         System.err.println("Start transmission...");
    try {
    Thread.sleep(2000);
    } catch (InterruptedException ex) {
    Logger.getLogger(AVTransmit3.class.getName()).log(Level.SEVERE, null, ex);
    if(v)
    //----------------------------------------------------Start
    /* Get a clonable version of our datasource */
    clone = Manager.createCloneableDataSource(ds);
    /* Make sure we got a clonable version before we try to clone it */
    if (clone == null) {
    System.err.println("Cannot get a clonable version of the datasource");
    System.exit(0);
    /* Create the clone of our original datasource */
    DataSource dsClone = ((SourceCloneable)clone).createClone();
    /* Make our DS variable a clone too */
    ds = ((SourceCloneable)clone).createClone();
    /* Make sure the clone happened successfully */
    if (dsClone == null) {
    System.err.println("Could not clone our datasource");
    System.exit(0);
    /* Make sure the clone happened successfully */
    if (ds == null) {
    System.err.println("Could not clone our datasource");
    System.exit(0);
    /* Create a new Clone class */
    Clone cloneV = new Clone();
    /* Open our clone class with our datasource clone */
    if (! cloneV.open(dsClone))
    System.exit(0);
    //----------------------------------------------------End
    /* Clone.java
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    import java.awt.*;
    import javax.media.*;
    import javax.media.protocol.DataSource;
    public class Clone extends Frame implements ControllerListener {
    Player p;
    Object waitSync = new Object();
    boolean stateTransitionOK = true;
    * Given a DataSource, create a player and use that player
    * as a player to playback the media.
    public boolean open(DataSource ds) {
         System.err.println("create player for: " + ds.getContentType());
         try {
         p = Manager.createPlayer(ds);
         } catch (Exception e) {
         System.err.println("Failed to create a player from the given DataSource: " + e);
         return false;
         p.addControllerListener(this);
         // Realize the player.
         p.prefetch();
         if (!waitForState(p.Prefetched)) {
         System.err.println("Failed to realize the player.");
         return false;
         // Display the visual & control component if there's one.
         setLayout(new BorderLayout());
    //     Component cc;
         Component vc;
         if ((vc = p.getVisualComponent()) != null) {
    vc.setSize(176, 144);
         add("Center", vc);
    //     if ((cc = p.getControlPanelComponent()) != null) {
    //     add("South", cc);
         // Start the player.
         p.start();
    this.setSize(176, 144);
         setVisible(true);
         return true;
    public void addNotify() {
         super.addNotify();
         pack();
    * Block until the player has transitioned to the given state.
    * Return false if the transition failed.
    boolean waitForState(int state) {
         synchronized (waitSync) {
         try {
              while (p.getState() < state && stateTransitionOK)
              waitSync.wait();
         } catch (Exception e) {}
         return stateTransitionOK;
    * Controller Listener.
    public void controllerUpdate(ControllerEvent evt) {
         if (evt instanceof ConfigureCompleteEvent ||
         evt instanceof RealizeCompleteEvent ||
         evt instanceof PrefetchCompleteEvent) {
         synchronized (waitSync) {
              stateTransitionOK = true;
              waitSync.notifyAll();
         } else if (evt instanceof ResourceUnavailableEvent) {
         synchronized (waitSync) {
              stateTransitionOK = false;
              waitSync.notifyAll();
         } else if (evt instanceof EndOfMediaEvent) {
         p.close();
         //System.exit(0);
         } else if (evt instanceof SizeChangeEvent) {
    * JFrameMain.java
    * Created on 23 maggio 2008, 17.28
    * @author Giovanni
    public class JFrameMain extends javax.swing.JFrame {
    /** Creates new form JFrameMain */
    public JFrameMain(AVTransmit3 avt) {
    avTransmit = avt;
    initComponents();
    /** This method is called from within the constructor to
    * initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is
    * always regenerated by the Form Editor.
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {
    jButtonFine = new javax.swing.JButton();
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    setResizable(false);
    jButtonFine.setText("Fine Trasmissione");
    jButtonFine.addMouseListener(new java.awt.event.MouseAdapter() {
    public void mousePressed(java.awt.event.MouseEvent evt) {
    jButtonFineMousePressed(evt);
    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addContainerGap()
    .addComponent(jButtonFine, javax.swing.GroupLayout.DEFAULT_SIZE, 124, Short.MAX_VALUE)
    .addContainerGap())
    layout.setVerticalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addContainerGap()
    .addComponent(jButtonFine, javax.swing.GroupLayout.DEFAULT_SIZE, 32, Short.MAX_VALUE)
    .addContainerGap())
    setBounds(600, 110, 160, 90);
    }// </editor-fold>
    private void jButtonFineMousePressed(java.awt.event.MouseEvent evt) {                                        
    avTransmit.stop();
    System.exit(0);
    * @param args the command line arguments
    public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    // new JFrameMain().setVisible(true);
    // Variables declaration - do not modify
    private javax.swing.JButton jButtonFine;
    // End of variables declaration
    private AVTransmit3 avTransmit = null;
    * @(#)RTPSocketAdapter.java     1.2 01/03/13
    * Copyright (c) 1999-2001 Sun Microsystems, Inc. All Rights Reserved.
    * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
    * modify and redistribute this software in source and binary code form,
    * provided that i) this copyright notice and license appear on all copies of
    * the software; and ii) Licensee does not utilize the software in a manner
    * which is disparaging to Sun.
    * This software is provided "AS IS," without a warranty of any kind. ALL
    * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
    * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
    * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
    * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
    * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
    * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
    * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
    * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
    * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
    * POSSIBILITY OF SUCH DAMAGES.
    * This software is not designed or intended for use in on-line control of
    * aircraft, air traffic, aircraft navigation or aircraft communications; or in
    * the design, construction, operation or maintenance of any nuclear
    * facility. Licensee represents and warrants that it will not use or
    * redistribute the Software for such purposes.
    import java.io.IOException;
    import java.net.InetAddress;
    import java.net.DatagramSocket;
    import java.net.MulticastSocket;
    import java.net.DatagramPacket;
    import java.net.SocketException;
    import javax.media.protocol.DataSource;
    import javax.media.protocol.PushSourceStream;
    import javax.media.protocol.ContentDescriptor;
    import javax.media.protocol.SourceTransferHandler;
    import javax.media.rtp.RTPConnector;
    import javax.media.rtp.OutputDataStream;
    * An implementation of RTPConnector based on UDP sockets.
    public class RTPSocketAdapter implements RTPConnector {
    DatagramSocket dataSock;
    DatagramSocket ctrlSock;
    InetAddress addr;
    int port;
    SockInputStream dataInStrm = null, ctrlInStrm = null;
    SockOutputStream dataOutStrm = null, ctrlOutStrm = null;
    public RTPSocketAdapter(InetAddress addr, int port) throws IOException {
         this(addr, port, 1);
    public RTPSocketAdapter(InetAddress addr, int port, int ttl) throws IOException {
         try {
         if (addr.isMulticastAddress()) {
              dataSock = new MulticastSocket(port);
              ctrlSock = new MulticastSocket(port+1);
              ((MulticastSocket)dataSock).joinGroup(addr);
              ((MulticastSocket)dataSock).setTimeToLive(ttl);
              ((MulticastSocket)ctrlSock).joinGroup(addr);
              ((MulticastSocket)ctrlSock).setTimeToLive(ttl);
         } else {
              dataSock = new DatagramSocket(port, InetAddress.getLocalHost());
              ctrlSock = new DatagramSocket(port+1, InetAddress.getLocalHost());
         } catch (SocketException e) {
         throw new IOException(e.getMessage());
         this.addr = addr;
         this.port = port;
    * Returns an input stream to receive the RTP data.
    public PushSourceStream getDataInputStream() throws IOException {
         if (dataInStrm == null) {
         dataInStrm = new SockInputStream(dataSock, addr, port);
         dataInStrm.start();
         return dataInStrm;
    * Returns an output stream to send the RTP data.
    public OutputDataStream getDataOutputStream() throws IOException {
         if (dataOutStrm == null)
         dataOutStrm = new SockOutputStream(dataSock, addr, port);
         return dataOutStrm;
    * Returns an input stream to receive the RTCP data.
    public PushSourceStream getControlInputStream() throws IOException {
         if (ctrlInStrm == null) {
         ctrlInStrm = new SockInputStream(ctrlSock, addr, port+1);
         ctrlInStrm.start();
         return ctrlInStrm;
    * Returns an output stream to send the RTCP data.
    public OutputDataStream getControlOutputStream() throws IOException {
         if (ctrlOutStrm == null)
         ctrlOutStrm = new SockOutputStream(ctrlSock, addr, port+1);
         return ctrlOutStrm;
    * Close all the RTP, RTCP streams.
    public void close() {
         if (dataInStrm != null)
         dataInStrm.kill();
         if (ctrlInStrm != null)
         ctrlInStrm.kill();
         dataSock.close();
         ctrlSock.close();
    * Set the receive buffer size of the RTP data channel.
    * This is only a hint to the implementation. The actual implementation
    * may not be able to do anything to this.
    public void setReceiveBufferSize( int size) throws IOException {
         dataSock.setReceiveBufferSize(size);
    * Get the receive buffer size set on the RTP data channel.
    * Return -1 if the receive buffer size is not applicable for
    * the implementation.
    public int getReceiveBufferSize() {
         try {
         return dataSock.getReceiveBufferSize();
         } catch (Exception e) {
         return -1;
    * Set the send buffer size of the RTP data channel.
    * This is only a hint to the implementation. The actual implementation
    * may not be able to do anything to this.
    public void setSendBufferSize( int size) throws IOException {
         dataSock.setSendBufferSize(size);
    * Get the send buffer size set on the RTP data channel.
    * Return -1 if the send buffer size is not applicable for
    * the implementation.
    public int getSendBufferSize() {
         try {
         return dataSock.getSendBufferSize();
         } catch (Exception e) {
         return -1;
    * Return the RTCP bandwidth fraction. This value is used to
    * initialize the RTPManager. Check RTPManager for more detauls.
    * Return -1 to use the default values.
    public double getRTCPBandwidthFraction() {
         return -1;
    * Return the RTCP sender bandwidth fraction. This value is used to
    * initialize the RTPManager. Check RTPManager for more detauls.
    * Return -1 to use the default values.
    public double getRTCPSenderBandwidthFraction() {
         return -1;
    * An inner class to implement an OutputDataStream based on UDP sockets.
    class SockOutputStream implements OutputDataStream {
         DatagramSocket sock;
         InetAddress addr;
         int port;
         public SockOutputStream(DatagramSocket sock, InetAddress addr, int port) {
         this.sock = sock;
         this.addr = addr;
         this.port = port;
         public int write(byte data[], int offset, int len) {
         try {
              sock.send(new DatagramPacket(data, offset, len, addr, port));
         } catch (Exception e) {
              return -1;
         return len;
    * An inner class to implement an PushSourceStream based on UDP sockets.
    class SockInputStream extends Thread implements PushSourceStream {
         DatagramSocket sock;
         InetAddress addr;
         int port;
         boolean done = false;
         boolean dataRead = false;
         SourceTransferHandler sth = null;
         public SockInputStream(DatagramSocket sock, InetAddress addr, int port) {
         this.sock = sock;
         this.addr = addr;
         this.port = port;
         public int read(byte buffer[], int offset, int length) {
         DatagramPacket p = new DatagramPacket(buffer, offset, length, addr, port);
         try {
              sock.receive(p);
         } catch (IOException e) {
              return -1;
         synchronized (this) {
              dataRead = true;
              notify();
         return p.getLength();
         public synchronized void start() {
         super.start();
         if (sth != null) {
              dataRead = true;
              notify();
         public synchronized void kill() {
         done = true;
         notify();
         public int getMinimumTransferSize() {
         return 2 * 1024;     // twice the MTU size, just to be safe.
         public synchronized void setTransferHandler(SourceTransferHandler sth) {
         this.sth = sth;
         dataRead = true;
         notify();
         // Not applicable.
         public ContentDescriptor getContentDescriptor() {
         return null;
         // Not applicable.
         public long getContentLength() {
         return LENGTH_UNKNOWN;
         // Not applicable.
         public boolean endOfStream() {
         return false;
         // Not applicable.
         public Object[] getControls() {
         return new Object[0];
         // Not applicable.
         public Object getControl(String type) {
         return null;
         * Loop and notify the transfer handler of new data.
         public void run() {
         while (!done) {
              synchronized (this) {
              while (!dataRead && !done) {
                   try {
                   wait();
                   } catch (InterruptedException e) { }
              dataRead = false;
              if (sth != null && !done) {
              sth.transferData(this);
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          

  • Capturing video to a file while transmitting it over the network

    I have tried several ways to do this but non of them have worked. On the JMF Programmers Guide its stated that one could do something like this: creating a processor from a DataSource, and the taking two Datasources from the processor, one is used to transmitt the video over the network, and the other is used to save the data to a file(through a DataSink).
    One of the ways I've tried is to clone de DataSource before creating the Processor. I've also tried to clone the Data source after creating and realizing the processor. The other way I've tried is by using the JMFSolution "Video Capture Utility with Monitoring", found at the jmf's homepage, which intercepts the data carried from the capture data source to the Processor.
    Non of these have worked, and I always get Exceptions about not finding a DataSink for the DataSource I use. For example:
    "javax.media.NoDataSinkException: Cannot find a DataSink for: com.sun.media.multiplexer.RawBufferMux$RawBufferDataSource@d9850" ;
    "javax.media.NoDataSinkException: Cannot find a DataSink for: com.sun.media.vfw.PushBufferDataSource@1e45"
    I've search the Web triying to find something clear about capturing video to a file while transmitting it over the network, but nothing seems to work.
    I would appreciate a piece of an advice on this.

    you can try modifing de Capture example from JMF Solutions.
    change this function:
    public int startCapture() {
         int result = -1;
         enableComponents(false);
         buttonStart.setLabel("Pause");
         buttonEnd.setEnabled(true);
         startMonitoring();
         try {
    processor.start();
    DataSource clone = Manager.createCloneableDataSource(datasource);
         MediaLocator ml2 = new MediaLocator("file://capture.mov");
    System.out.println("Content Type " + clone.getContentType());
    datasink = Manager.createDataSink(processor.getDataOutput(), ml2);
         datasink.open();
    datasink.addDataSinkListener(this);
         datasink.start();
    result = 0;
         } catch (Exception e) {
         System.err.println("DataSink Exception " + e);
    result= -1;
    Regards.
    Fernando

  • Clone DataSource for simultaneously  receiving and transmitting?

    Hi!
    I wrote an application that receives a video stream and transmits it to a client. The application works fine.
    But if I change it to a servlet I get a StreamCorruptedException ("type code out of range, is 0")
    The API sais: StreamCorruptedException is thrown when control information that was read from an object stream violates internal consistency checks.
    Why is this exception only thrown in the servlet?
    Might this be because I use this datasource for receiving and transmitting data?
    Do I have to use a cloned datasource?
    Help please...
    Deike

    Hi
    can u please send me ur code. it is very urgent requirement
    in our application. thanks in adavance
    sent it to this mail id : [email protected]
    regards
    Narendra

  • Play video while showing slides of text

    Is it possible to have a video playing in the background while showing text slides? For example, showing a background video while displaying the words to a song on several slides?
    Thanks

    I do this by creating a slide with a looped videoo on the backmost position and display text blocks over it using appear and disappear from the build in and out settings of the seperate textfields
    this means that you will have one slide with many consecutive text being dispayed in order...
    The only drawback is that there is no really comfortable way of seeing all your texts to edit them since they are all stacked over another in the composing view..
    Hope this helps you further

  • HT1657 Once a rented movie is downloaded do I need an Internet connection to view it?  For example can I download a movie and watch it on a flight?

    Once a rented movie is downloaded do I need an Internet connection to view it?  For example can I download a movie and watch it on a flight?

    Please be aware of the movie rental's time limitation that you have 30 days from the time of rental to watch your movie, and once you start watching it, you have 24 hours to finish watching it. You may watch it as many times as you like during those 24 hours. It may be helpful to make sure the download completes successfully before you begin watching the movie.
    Once the download is complete you can watch it without an Internet connection. However, an Internet connection to the iTunes Store is required to authorize playback or activate the 24 hours time-limit of movie rentals. This means, only during the starting of the movie. Once you have started playing the movie rental, internet connection is not required. You can play anywhere without internet connection.
    For more information on movie rentals, you can visit:
    iTunes Store: Movie rental frequently asked questions (FAQ)
    http://support.apple.com/kb/HT1657
    Note: 24 hours time limit is for United States customer only, while 48 hours for other countries.

  • Where to learn about viewing video?

    Using my Mac mini 2 GHz Intel Core 2 Duo, running system 10.6.6, I have trouble viewing some live or recorded video Internet broadcasts, but have no trouble with others. One that I cannot view with any browser is broadcast by my Mac user group!
    Ones I can see: YouTube, CNN, live NASA TV, using Flip4Mac to tell QuickTime viewer to view. UStream no joy, for example. Cannot watch NASA videos online but after downloading they play well in QT.
    Where is a good place to learn how to be able to view videos, and why some are available and others are not? I do not find the help files on the Apple site to solve the problem.

    Some of the people at my Mac user group do not like questions from people who do not understand things so I am reluctant to ask any more questions.
    Message was edited by: itwontletme

  • Viewing videos from TV program

    Sometimes I miss a TV show. The TV network allows you to view videos of the show after the program has aired. When I try to see the video, it plays about 1 second, then stops while loading, plays another second, stops to load, etc. Is there any way to be able to see the video without so many interruptions? Is there something I need to add to my software to help with this problem?

    "The TV network allows you to view videos of the show after the program has aired."
    Link please? Need to test to see what the problem is.
    Make sure you have the following installed:
    Flip4Mac
    VLC Media Player
    Perian (AVI and FLV support)
    Make sure you have the latest versions of Adobe Flash Player Software
    Since you are using the basic OS, you will need to update to the latest OS which is 10.5.6. You will also need to download all the other software that is listed on Software Update.
    You will need to repair permission and restart your computer prior to & after all of the above installations.

  • I cannot view videos online

    I cannot view videos  on amazon.com in the customr review section. I have tried all the suggestions that apply to me on the web page http://www.macromedia.com/support/documentation/en/flashplayer/help/index.html  Any other suggetions? I have windows 7, and am using firefox as a browswer.

    I can not find video on amazon.com in the customer review section. What I see for example is like this:
    http://www.amazon.com/Les-Miserables/product-reviews/B00BI73CVI/ref=dp_top_cm_cr_acr_txt_c m_cr_acr_txt?ie=UTF8&showViewpoints=1
    What is the link to your problem video? Is the problem only in amazon.com in the customer review section? 

  • I can't view video on certain sites. It seems to be a problem with Firefox 9 and 10 for Mac.

    Ever since I upgraded to Firefox 9 on my laptop and Firefox 10 on my desktop (Mac OSX 10.6), I haven't been able to view video on certain sites. I can get youtube and vimeo and hulu no problem. However, it seems I cannot view video on sites where it seems to be embedded.
    Examples are velonews.com and thedailyshow.com. With the latter, I can't even see the site any more.
    BTW, I also can't access the firefox help system because it won't take my password. I'm doing this on Safari.

    If you use extensions (Tools > Add-ons > Extension) like <i>Adblock Plus</i> or <i>NoScript</i> or <i>Flash Block</i> that can block content then make sure that such extensions aren't blocking content.
    If it does work in Safe-mode then disable all extensions and then try to find which is causing it by enabling one at a time until the problem reappears.
    *Use "Disable all add-ons" on the [[Safe mode]] start window to disable all extensions.
    * Close and restart Firefox after each change via "File > Exit" (Mac: "Firefox > Quit"; Linux: "File > Quit")
    *https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes

  • Viewing video

    Hi All,
    I have a problem viewing video from certain web sites. example (http://www.adpulp.com/) shows up with the videos invisible. Is this just a limitation of a Mac computer? I've tried the new Safari 3,old Safari, Firefox, and Explorer but still cannot see the video.
    Thanks in advance,
    Madok

    Works fine for me. Try these settings:
    These are the downloads and the settings you need in order to view/hear pretty much everything that the net can throw at you: The setup described below has proved repeatedly successful on both PPC and Intel macs, but nothing in life carries a guarantee!
    Assuming you already run Tiger versions OS 10.4.9 or above (this has not yet been verified with Leopard) and have Quicktime 7.2, and are using Safari 2 or 3, download and install (or re-install even if you already had them) the latest versions, suitable for your flavor of Mac, of:
    RealPlayer 10 for Mac from http://forms.real.com/real/player/blackjack.html?platform2=Mac%20OS%20X&product= RealPlayer%2010&proc=g3&lang=&show_list=0&src=macjack
    Flip4Mac WMV Player from http://www.microsoft.com/windows/windowsmedia/player/wmcomponents.mspx (Windows Media Player for the Mac is no longer supported, even by Microsoft)
    Perian from http://perian.org/
    Adobe FlashPlayer from http://www.adobe.com/shockwave/download/download.cgi?P1ProdVersion=ShockwaveFlash
    In Quicktime Preferences, under advanced, UNcheck Enable Flash, and under Mime settings/Miscellananeous only check Quicktime HTML (QHTM).
    In Macintosh HD/Library/Quicktime/ delete any files relating to DivX (Perian already has them).
    Now go to Safari Preferences/Security, and tick the boxes under Web Content (all 4 of them).
    Lastly open Audio Midi Setup (which you will find in the Utilities Folder of your Applications Folder) and click on Audio Devices. Make sure that both Audio Input and Audio Output, under Format, are set to 44100 Hz.
    Important: Now repair permissions and restart.
    The world should now be your oyster!
    You should also have the free VLC Player from http://www.videolan.org/ in your armory, as this plays almost anything that DVD Player might not.

  • New iMac owner - trouble viewing videos

    Hi - I am a brand new iMac owner. Running OS 10.8.5  Mountain Lion I believe. What exact plug ins do I need to view videos? Nothing works through safari onn youtube or any other hosted video site that I've tried. Thanks

    Well, as a matter of fact there is no need to have Adobe Flash Player installed to watch videos on YouTube.
    Of course you can install it, but you can live without it and be able to watch YouTube videos altogether.
    Open Safari, go to Safari's preferences, Advanced. Check "Show Develop menu in menu bar"
    Now you have a new tag in the menu bar named Develop. From there you can select a new User Agent, for example "Safari iOS 6.1 - iPad". This, let YouTube's server believe that you are running Safari on an iPad and streaming the video on your Mac.

  • Capture video while playing audio in WP8 or WP81

    Hi,
    Whenever I try to record a video using the CaptureSource it stops whatever audio was playing. How do I prevent recording video from stopping the audio being played?
    Thank you

    Hi Baracat,
    Could you explain any scenario why you want to capture the video while playing the audio? You want to record the audio played from your device to your video?
    --James
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • View video

    When I attempt to view a video in for example BBC news I am told that I need to update the viewing program. I am then asked what operating system I am using but it lists only computer systems eg Windows, Mac etc.
    What do I have to do to enable these videos to be shown?
    My phone is the 6303c

    The only other systems mentioned as well as Windows and Mac were Linux and Solaris, so I imagine it refers only to PC. I used Nokia's OPERA MINI to view the content which I then assumed was a mobile version - but obviously not!

Maybe you are looking for