受信側プログラムはJMStudioを利用
import javax.media.*; import javax.media.control.*; import javax.media.protocol.*; import javax.media.format.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.io.*; import java.util.*; public class TransmitterTest extends JFrame { private MediaLocator mediaLocator = null; private DataSink dataSink = null; private Processor mediaProcessor = null; private Format[] formats = new Format[] { new VideoFormat( VideoFormat.JPEG_RTP ) }; private ContentDescriptor descriptor = new ContentDescriptor( ContentDescriptor.RAW_RTP ); private InputPanel ipanel; private static final int PORT=22224; private Component ctrl; /** Creates a new transmitter frame. */ public TransmitterTest() { super( "Video Transmitter" ); ipanel = new InputPanel(); getContentPane().add( ipanel, "Center" ); pack(); show(); } /** set locator from Capture Device */ public void setLocator() { try { MediaLocator deviceLocator = searchCaptureDevice(); DataSource source = Manager.createDataSource( deviceLocator ); mediaLocator = new MediaLocator( "rtp://" + ipanel.host.getText() + ":" + PORT + "/video" ); mediaProcessor = Manager.createRealizedProcessor( new ProcessorModel( source, formats, descriptor ) ); dataSink = Manager.createDataSink( mediaProcessor.getDataOutput(), mediaLocator ); setControlPanel(); startTransmitting(); } catch (Exception e) { System.err.println( e.toString() ); } } /** Search Capture Device for Video */ public static MediaLocator searchCaptureDevice() { Vector list = CaptureDeviceManager.getDeviceList( new VideoFormat( VideoFormat.YUV ) ); if( list.size() > 0 ) { CaptureDeviceInfo info = (CaptureDeviceInfo)list.elementAt( 0 ); return info.getLocator(); } System.err.println( "No Capture Device" ); return null; } /** set Control */ public void setControlPanel() { ctrl = mediaProcessor.getControlPanelComponent(); getContentPane().add( ctrl, "South" ); pack(); } /** Starts transmitting the media. */ public void startTransmitting() throws IOException { mediaProcessor.start(); dataSink.open(); dataSink.start(); } /** start here */ public static void main(String[] args) { TransmitterTest transmitter = new TransmitterTest(); } /** Input receive host name, port number */ class InputPanel extends JPanel implements ActionListener { public JLabel label = new JLabel( "Receiver Adress:" ); public JTextField host = new JTextField( "", 16 ); public JButton transmit = new JButton( "Transmit" ); InputPanel() { add( label ); add( host ); add( transmit ); transmit.addActionListener( this ); } /** Event Processing */ public void actionPerformed( ActionEvent evt ) { if( evt.getSource() instanceof JButton ) { if( (JButton)(evt.getSource()) == transmit ) { setLocator(); } } } } }
0 件のコメント:
コメントを投稿