Video Audio Conferencing Source Code in Java
Video Audio Conferencing Source Code in Java
################################################################################
#
FEATURE
################################################################################
#
PREREQUISITE:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
*****/ just need to copy the client side code and run it to a pc not need any manual IP ***/
How to run :
Just run server side code in a PC and then Run Client side code to different PC.Then the
work is done.
ClientListener.java
Clients.java
Main.java
MessageListener.java
ServerConstant.java
ServerManager.java
ServerMonitor.java
ServerStatusListener.java
ClientListener.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package MessengSrserver;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package MessengSrserver;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.util.StringTokenizer;
import static MessengSrserver.ServerConstant.*;
clientListener.signIn(name);
clientListener.clientStatus(name+": is signIn ,
IPaddress :"+client.getInetAddress()+" ,portNumber :"+client.getPort()+"
by sharma");
String ip ="";
ip += client.getInetAddress();
clientListener.mapped(name,ip);
}
else if(header.equalsIgnoreCase(DISCONNECT_STRING))
{
clientListener.signOut(name);
serverManager.sendNameToAll(message);
ServerManager.clientTracker[clientNumber]="";
keepListening=false;
}
else if(header.equalsIgnoreCase("video"))
{
String name1 = tokens.nextToken();
String rec_ip = ServerMonitor.hm.get(name1);
String sen_ip = ServerMonitor.hm.get(name);
String message1 = name+" video "+rec_ip;
System.out.println("server ip back"+message1);
serverManager.sendInfo(message1);
String messa2 = name1+" video1 "+sen_ip;
serverManager.sendInfo(messa2);
}
else
{
serverManager.sendInfo(message);
}
}
catch (IOException ex)
{
clientListener.signOut(name);
serverManager.sendNameToAll(DISCONNECT_STRING+" "+name);
ServerManager.clientTracker[clientNumber]="";
break;
}
catch (ClassNotFoundException ex)
{
}
}
}
}
Main.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package MessengSrserver;
import MessengSrserver.ServerManager;
import MessengSrserver.ServerMonitor;
public class Main
{
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
ServerManager serverManager=new ServerManager();
ServerMonitor monitor=new ServerMonitor(serverManager);
monitor.setVisible(true);
}
MessageListener.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package MessengSrserver;
import java.io.ObjectOutputStream;
ServerConstant.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package MessengSrserver;
public interface ServerConstant
{
public static final int SERVER_PORT=12345;
public static final int BACKLOG=100;
public static final int CLIENT_NUMBER=100;
public static final int MULTICAST_SENDING_PORT=5555;
public static final int MULTICAST_LISTENING_PORT=5554;
public static final String MULTICAST_ADDRESS="239.0.0.1";
public static final String DISCONNECT_STRING="DISCONNECT";
public static final String MESSAGE_SEPARATOR=" >> ";
}
ServerMonitor.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* ServerMonitor.java
*
* Created on Jan 1, 2004, 2:37:44 PM
*/
package MessengSrserver;
import java.awt.BorderLayout;
import javax.swing.DefaultListSelectionModel;
import javax.swing.ListSelectionModel;
import java.util.*;
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("H-Server");
ta_monitor_clients.setColumns(20);
ta_monitor_clients.setEditable(false);
ta_monitor_clients.setRows(5);
ta_monitor_clients.setBorder(javax.swing.BorderFactory.createTitledBorder(
"MONITOR CLIENTS"));
jScrollPane1.setViewportView(ta_monitor_clients);
but_start.setText("Start");
but_start.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
but_startActionPerformed(evt);
}
});
but_stop.setText("Stop");
but_stop.setEnabled(false);
but_stop.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
but_stopActionPerformed(evt);
}
});
jMenu1.setText("File");
jMenuBar1.add(jMenu1);
jMenu2.setText("Edit");
jMenuBar1.add(jMenu2);
setJMenuBar(jMenuBar1);
pack();
}// </editor-fold>//GEN-END:initComponents
}//GEN-LAST:event_but_startActionPerformed
ServerManager.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package MessengSrserver;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;
import java.util.StringTokenizer;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import static MessengSrserver.ServerConstant.*;
ConnectionController(ServerStatusListener
getStatusListener,ClientListener getClientListener)
{
statusListener=getStatusListener;
clientListener=getClientListener;
}
ServerStatusListener.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package MessengSrserver;
***************************END OF
SERVER******************************************
CLIENT SIDE
ClientConstant.java
ClientListListener.java
ClientListPanel.java
ClientManager.java
ClientStatusListener.java
ClientWindowListener.java
FileReceiver.java
FileSender.java
LoginFrame.java
LogInPanel.java
Main.java
AVReceive2.java
AVTransmit2.java
MessageRecever.java
MessagingFrame.java
ClientConstant.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package messengerclient;
/**
*
* @author team3
*/
public interface ClientConstant
{
public static final String SERVER_ADDRESS="172.17.0.32";
public static final int SERVER_PORT=12345;
public static final int CLIENT_NUMBER=100;
public static final String DISCONNECT_STRING="DISCONNECT";
public static final String MESSAGE_SEPARATOR=" >> ";
}
ClientListListener.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package messengerclient;
/**
*
* @author team3
*/
public interface ClientListListener
{
void addToList(String userName);
void removeFromList(String userName);
}
ClientListPanel.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* ClientListPanel.java
*
* Created on May 31, 2010, 12:13:48 AM
*/
package messengerclient;
import java.awt.BorderLayout;
import javax.swing.DefaultListSelectionModel;
import javax.swing.ListSelectionModel;
/**
*
* @author team3
*/
public class ClientListPanel extends javax.swing.JPanel {
ClientManager.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package messengerclient;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.logging.Level;
import java.util.logging.Logger;
import static messengerclient.ClientConstant.*;
/**
*
* @author team3
*/
public class ClientManager
{
ExecutorService clientExecutor;
Socket clientSocket ;
boolean isConnected=false;
ClientStatusListener.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package messengerclient;
/**
*
* @author team3
*/
public interface ClientStatusListener
{
void loginStatus(String status);
}
ClientWindowListener.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package messengerclient;
/**
*
* @author team3
*/
public interface ClientWindowListener
{
public void openWindow(String message);
public void closeWindow(String message);
public void fileStatus(String filesStatus);
}
FileReceiver.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package messengerclient;
import java.net.*;
import java.io.*;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author team3
*/
public class FileReceiver implements Runnable
{
String address;
FileReceiver(String getAddress)
{
FileSender.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package messengerclient;
/**
*
* @author team3
*/
import java.net.*;
import java.io.*;
LoginFrame.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* LoginFrame.java
*
* Created on May 30, 2010, 11:59:04 PM
*/
package messengerclient;
import java.util.*;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.StringTokenizer;
import static messengerclient.ClientConstant.*;
/**
*
* @author team3
*/
public class LoginFrame extends javax.swing.JFrame {
buddyList.list_online_clients.addMouseListener(new
MouseAdapter()
{
public void mouseClicked(MouseEvent me)
{
if(me.getClickCount()==2)
{
String
to=(String)buddyList.list_online_clients.getSelectedValue();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("User");
lb_status.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
lb_status.setText("You r not connected to server");
jMenu1.setText("User");
mi_sign_in.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.even
t.KeyEvent.VK_C, java.awt.event.InputEvent.CTRL_MASK));
mi_sign_in.setText("Sign In");
jMenu1.add(mi_sign_in);
mi_sign_out.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.eve
nt.KeyEvent.VK_D, java.awt.event.InputEvent.CTRL_MASK));
mi_sign_out.setText("Sign Out");
mi_sign_out.setEnabled(false);
mi_sign_out.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt) {
mi_sign_outActionPerformed(evt);
}
});
jMenu1.add(mi_sign_out);
jMenuBar1.add(jMenu1);
jMenu2.setText("Help");
jMenuBar1.add(jMenu2);
setJMenuBar(jMenuBar1);
javax.swing.GroupLayout layout = new
javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(myPanel, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(lb_status, javax.swing.GroupLayout.DEFAULT_SIZE,
182, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(myPanel,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(lb_status)
.addContainerGap(36, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
public void removeFromList(String userName)
{
buddyList.list_model.removeElement(userName);
}
}
/**
* @param args the command line arguments
*/
LogInPanel.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* LogInPanel.java
*
* Created on May 30, 2010, 11:35:56 PM
*/
package messengerclient;
/**
*
* @author team3
*/
public class LogInPanel extends javax.swing.JPanel {
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Sign In
"));
but_signin.setText("SignIn");
Main.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import messengerclient.ClientManager;
import messengerclient.LoginFrame;
/**
*
* @author sharma
*/
public class Main {
/**
* @param args the command line
arguments
*/
public static void main(String[] args)
{
ClientManager clientManager=new ClientManager();
LoginFrame loginFrame=new LoginFrame(clientManager);
loginFrame.setVisible(true);
// TODO code application logic here
}
MessageRecever.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package messengerclient;
import javax.media.*;
import javax.media.rtp.*;
import javax.media.rtp.event.*;
import javax.media.rtp.rtcp.*;
import javax.media.protocol.*;
import javax.media.protocol.DataSource;
import javax.media.format.AudioFormat;
import javax.media.format.VideoFormat;
import javax.media.Format;
import javax.media.format.FormatChangeEvent;
import javax.media.control.BufferControl;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.Socket;
import java.util.StringTokenizer;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.logging.Level;
import java.util.logging.Logger;
import static messengerclient.ClientConstant.*;
/**
*
* @author sharma
*/
public class MessageRecever implements Runnable
{
ObjectInputStream input;
boolean keepListening=true;
ClientListListener clientListListener;
ClientWindowListener clientWindowListener;
ClientManager clientManager;
Socket clientSocket;
ExecutorService clientExecutor;
}
else if(header.equalsIgnoreCase(DISCONNECT_STRING))
{
clientListListener.removeFromList(name);
}
else if(header.equalsIgnoreCase("server"))
{
clientWindowListener.closeWindow(message);
}
// Video
else if(name.equalsIgnoreCase("video"))
{
// clientWindowListener.fileStatus("One File is
Receiving");
// String address=tokens.nextToken();
// String fileName=tokens.nextToken();
// clientExecutor.execute(new FileReceiver(address));
ips = tokens.nextToken();
String st="",pt="";
st += ips;
System.out.println("#########"+st);
}
}
}
MessagingFrame.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* MessagingFrame.java
*
* Created on Jul 28, 2010, 10:04:21 AM
*/
package messengerclient;
import javax.swing.JFileChooser;
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 java.util.StringTokenizer;
import java.io.ObjectInputStream;
import java.net.Socket;
/**
*
* @author team3
*/
public class MessagingFrame extends javax.swing.JFrame {
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
tp_write_message.setBorder(null);
jScrollPane2.setViewportView(tp_write_message);
but_send.setText("Send");
but_send.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
but_sendActionPerformed(evt);
}
});
jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing
.BorderFactory.createEtchedBorder(), "Video Conferencing......",
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
javax.swing.border.TitledBorder.DEFAULT_POSITION, new
java.awt.Font("Tahoma", 0, 11), new java.awt.Color(0, 0, 255))); // NOI18N
but_file.setText("Video");
but_file.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
but_fileActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel3Layout = new
javax.swing.GroupLayout(jPanel3);
jPanel3.setLayout(jPanel3Layout);
jPanel3Layout.setHorizontalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADIN
G)
.addGroup(jPanel3Layout.createSequentialGroup()
.addContainerGap()
.addComponent(but_file)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 27,
Short.MAX_VALUE)
.addComponent(tf_file,
javax.swing.GroupLayout.PREFERRED_SIZE, 166,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
jPanel3Layout.setVerticalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADIN
G)
.addGroup(jPanel3Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignm
ent.BASELINE)
.addComponent(but_file)
.addComponent(tf_file,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
}//GEN-LAST:event_but_sendActionPerformed
if (!avReceive.initialize())
{
System.err.println("Failed to initialize the sessions.");
System.exit(-1);
}
try
{
while (!avReceive.isDone())
Thread.sleep(60000);
}
catch (Exception ex)
{}
*/
// Transmit for 60 seconds and then close the processor
// This is a safeguard when using a capture data source
// so that the capture device will be properly released
// before quitting.
// The right thing to do would be to have a GUI with a
// "Stop" button that would call stop on VideoTransmit
/* try {
Thread.currentThread().sleep(600000);
} catch (InterruptedException ie) {
}
// Stop the transmission
vt.stop();
*/
}//GEN-LAST:event_but_fileActionPerformed
}
AVReceive2.java
/**
* @(#)AVReceive2.java
*
*
* @author sharma
* @version 1.00 2010/7/24
*/
package messengerclient;
import java.io.*;
import java.awt.*;
import java.net.*;
import java.awt.event.*;
import java.util.Vector;
import javax.media.*;
import javax.media.rtp.*;
import javax.media.rtp.event.*;
import javax.media.rtp.rtcp.*;
import javax.media.protocol.*;
import javax.media.protocol.DataSource;
import javax.media.format.AudioFormat;
import javax.media.format.VideoFormat;
import javax.media.Format;
import javax.media.format.FormatChangeEvent;
import javax.media.control.BufferControl;
/**
* AVReceive2 to receive RTP transmission using the new RTP API.
*/
public class AVReceive2 implements ReceiveStreamListener,
SessionListener,ControllerListener
{
String sessions[] = null;
RTPManager mgrs[] = null;
Vector playerWindows = null;
SessionLabel session;
ipAddr = InetAddress.getByName(session.addr);
if(
ipAddr.isMulticastAddress())
{
// local and remote address pairs are identical:
localAddr= new SessionAddress( ipAddr, session.port,
session.ttl);
destAddr = new SessionAddress( ipAddr, session.port,
session.ttl);
}
else
{
localAddr= new
SessionAddress( InetAddress.getLocalHost(), session.port);
destAddr = new SessionAddress( ipAddr, session.port);
mgrs[i].initialize( localAddr);
(BufferControl)mgrs[i].getControl("javax.media.control.BufferControl");
if (bc != null)
bc.setBufferLength(350);
mgrs[i].addTarget(destAddr);
}
}
catch (Exception e)
{
System.err.println("Cannot create the RTP Session: " +
e.getMessage());
return false;
}
//
Wait for data to arrive before moving on.
long then = System.currentTimeMillis();
long waitingPeriod = 600000; // wait for a maximum of 30 secs.
try
{
synchronized (dataSync)
{
{
if (!dataReceived)
System.err.println(" - Waiting for RTP data to
arrive...");
dataSync.wait(1000);
}
}
}
catch (Exception e)
{}
if
(!dataReceived)
{
System.err.println("No RTP data was received.");
close();
return false;
}
return true;
}
/**
* Close the players and
the session managers.
*/
protected void close()
{
for (int i = 0; i < playerWindows.size(); i++)
{
try
{
((PlayerWindow)playerWindows.elementAt(i)).close();
}
catch (Exception e)
{}
}
playerWindows.removeAllElements();
PlayerWindow
find(Player p)
{
for (int i = 0; i < playerWindows.size(); i++)
{
PlayerWindow pw = (PlayerWindow)playerWindows.elementAt(i);
if (pw.player == p)
return pw;
}
return null;
}
if (pw.stream == strm)
return pw;
}
return null;
}
/**
* SessionListener.
* SessionListener: Receives notification of changes in the state of
the session.
*/
public synchronized void update(SessionEvent evt)
{
if (evt instanceof
NewParticipantEvent)
{
Participant p = ((NewParticipantEvent)evt).getParticipant();
/**
* ReceiveStreamListener
* ReceiveStreamListener: Receives notification of changes in the
state of
* an RTP stream thatÕs being received.
*/
public synchronized void update(ReceiveStreamEvent evt)
{
//RTPManager->Participant->ReceiveStream
RTPManager mgr = (RTPManager)evt.getSource();
Participant participant = evt.getParticipant(); // could be null.
System.exit(0);
}
else if(evt instanceof NewReceiveStreamEvent)
{
// In RTP parlance, this means that RTP data packets have
been
// received from an SSRC that had not previously been sending
data.
try
{
stream = ((NewReceiveStreamEvent)evt).getReceiveStream();
DataSource ds = stream.getDataSource();
}
else
System.err.println(" - Recevied new RTP stream");
if (participant == null)
System.err.println(" The sender of this stream
had yet to be identified.");
else
{
System.err.println(" The stream comes from: " +
participant.getCNAME());
}
p.addControllerListener(this);
p.realize();
PlayerWindow pw = new PlayerWindow(p, stream);
playerWindows.addElement(pw);
synchronized(dataSync)
{
dataReceived = true;
dataSync.notifyAll();
}
}
catch (Exception e)
{
System.err.println("NewReceiveStreamEvent exception " +
e.getMessage());
return;
}
}
// Informs the RTP listener that a previously 'orphaned'
ReceiveStream
// has been associated with an Participant.
else if (evt instanceof StreamMappedEvent)
{
if (stream != null && stream.getDataSource() != null)
{
DataSource ds = stream.getDataSource();
// Find out the formats.
RTPControl ctl =
(RTPControl)ds.getControl("javax.media.rtp.RTPControl");
System.err.println(" - The previously unidentified
stream ");
if (ctl != null)
System.err.println(" " + ctl.getFormat());
System.err.println(" had now been identified as sent
by: " + participant.getCNAME());
}
}
PlayerWindow pw = find(stream);
if (pw != null)
{
pw.close();
playerWindows.removeElement(pw);
}
}
}
/**
* ControllerListenerfor the Players.
*/
public synchronized void controllerUpdate(ControllerEvent ce)
{
Player p = (Player)ce.getSourceController();
if (p == null)
return;
PlayerWindow pw = find(p);
if (pw == null)
{
// Some strange happened.
System.err.println("Internal error!");
System.exit(-1);
}
pw.initialize();
pw.setVisible(true);
p.start();
}
p.removeControllerListener(this);
PlayerWindow pw = find(p);
if (pw != null)
{
pw.close();
playerWindows.removeElement(pw);
}
System.err.println("AVReceive2 internal error: " + ce);
}
}
/**
* A utility class to parse the session addresses.
* <session>: <address>/<port>/<ttl>
*/
class SessionLabel
{
public String addr = null;
public int port;
public int ttl = 1;
session = session.substring(1);
if (addr == null)
throw new IllegalArgumentException();
if (portStr !=
null)
{
try
{
Integer integer = Integer.valueOf(portStr);
if (integer != null)
port = integer.intValue();
}
catch (Throwable t)
{
throw new IllegalArgumentException();
}
}
else
throw new IllegalArgumentException();
if (ttlStr !=
null)
{
try
{
Integer integer = Integer.valueOf(ttlStr);
if (integer != null)
ttl = integer.intValue();
}
catch (Throwable t)
{
throw new IllegalArgumentException();
}
}
}
}
/**
* GUI classes for the Player.
*/
class PlayerWindow extends Frame
{
Player player;
ReceiveStream stream;
/**
* GUI classes for the Player.
*/
class PlayerPanel extends Panel
{
Component vc, cc;
PlayerPanel(Player
p)
{
setLayout(new BorderLayout());
if ((vc = p.getVisualComponent()) != null)
add("Center", vc);
if ((cc = p.getControlPanelComponent()) != null)
add("South", cc);
}
System.err.println("Exiting AVReceive2");
}
static void
prUsage()
{
System.err.println("Usage: AVReceive2 <session> <session> ...");
System.err.println(" <session>:
</session></session></session></ttl></port></address><address>/<port>/<ttl
>");
System.exit(0);
} */
}// end of AVReceive2
AVTransmit2.java
package messengerclient;
import java.awt.*;
import java.io.*;
import java.net.InetAddress;
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.*;
// Input MediaLocator
// Can be a file or http or capture source
private MediaLocator locator;
private String ipAddress;
private int portBase;
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;
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[i].removeTargets( "Session ended.");
rtpMgrs[i].dispose();
}
}
}
}
DataSource ds;
DataSource clone;
try {
ds = javax.media.Manager.createDataSource(locator);
} catch (Exception e) {
return "Couldn't create DataSource";
}
Format supported[];
Format chosen;
boolean atLeastOneTrack = false;
// Program the tracks.
for (int i = 0; i < tracks.length; i++) {
Format format = tracks[i].getFormat();
if (tracks[i].isEnabled()) {
supported = tracks[i].getSupportedFormats();
if (supported.length > 0) {
if (supported[0] instanceof VideoFormat) {
// For video formats, we should double check the
// sizes since not all formats work in all sizes.
chosen = checkForVideoSizes(tracks[i].getFormat(),
supported[0]);
} else
chosen = supported[0];
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";
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[i].initialize( localAddr);
rtpMgrs[i].addTarget( destAddr);
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) {
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;
}
/**
* Setting the encoding quality to the specified value on the JPEG
encoder.
* 0.5 is a good default.
*/
void setJPEGQuality(Player p, float val) {
/****************************************************************
* Convenience methods to handle processor's state changes.
****************************************************************/
Integer getStateLock() {
return stateLock;
}
void setFailed() {
failed = true;
}
if (failed)
return false;
else
return true;
}
/****************************************************************
* Inner Classes
****************************************************************/
/****************************************************************
* Sample Usage for AVTransmit2 class
****************************************************************/
if (args.length < 3) {
prUsage();
}
System.err.println("...transmission ended.");
System.exit(0);
}