RTPVoiceSender.java
资源名称:SIPPhone.zip [点击查看]
上传用户:pdtewte
上传日期:2021-10-16
资源大小:13k
文件大小:4k
源码类别:
IP电话/视频会议
开发平台:
Java
- import javax.media.*;
- import javax.media.format.*;
- import javax.media.rtp.*;
- //import javax.media.rtp.rtcp.*;
- import javax.media.protocol.*;
- //import javax.media.rtp.event.*;
- import javax.media.control.*;
- import java.util.*;
- //import java.io.*;
- import java.net.*;
- public class RTPVoiceSender
- {
- private Processor mProcessor ;
- private DataSource mDataSource;
- private String destIP;
- private int destport;
- public RTPVoiceSender( String destIP,int port)
- {
- this.destIP = destIP;
- this.destport = port;
- AudioFormat format = new AudioFormat(AudioFormat.GSM_RTP,8000,8,1);
- Vector devices = CaptureDeviceManager.getDeviceList(format);
- CaptureDeviceInfo di= null;
- if ( devices.size() > 0 )
- {
- di = (CaptureDeviceInfo)devices.elementAt(0);
- System.out.println("��ȡ��Ƶ�ɼ��豸�ɹ�!");
- }
- else
- {
- di = CaptureDeviceManager.getDevice("DirectSoundCapture");
- System.out.println("��ȡ��Ƶ�ɼ��豸ʧ��!");
- }
- try
- {
- mProcessor = Manager.createProcessor(di.getLocator());
- }
- catch (Exception e)
- {
- System.out.println(e);
- }
- mProcessor.configure();
- while( mProcessor.getState() < Processor.Configured )
- {
- }
- mProcessor.setContentDescriptor(new ContentDescriptor( ContentDescriptor.RAW_RTP));
- TrackControl track[] = mProcessor.getTrackControls();
- boolean encodingOk = false;
- for (int i = 0; i < track.length; i++)
- {
- if (!encodingOk && track[i] instanceof FormatControl)
- {
- if (((FormatControl)track[i]).setFormat( new AudioFormat(AudioFormat.GSM_RTP,8000,8,1)) == null)
- {
- track[i].setEnabled(false);
- }
- else
- {
- encodingOk = true;
- }
- }
- else
- {
- track[i].setEnabled(false);
- }
- }
- mProcessor.realize();
- while(mProcessor.getState()< Processor.Realized)
- {
- }
- try
- {
- mDataSource = mProcessor.getDataOutput();
- } catch ( NotRealizedError e)
- {
- System.out.println(e);
- }
- PushBufferDataSource pdbs = (PushBufferDataSource)mDataSource;
- PushBufferStream pbss[] = pdbs.getStreams();
- RTPManager rtpMgrs[] = new RTPManager[pbss.length];
- rtpMgrs[0] = RTPManager.newInstance();
- try
- {
- InetAddress ipaddr = InetAddress.getByName(this.destIP);
- SessionAddress localAddr = new SessionAddress(InetAddress.getLocalHost(),10002);
- //this.destport
- SessionAddress destAddr = new SessionAddress(ipaddr,this.destport);
- rtpMgrs[0].initialize(localAddr);
- rtpMgrs[0].addTarget(destAddr);
- SendStream sendStream = rtpMgrs[0].createSendStream(mDataSource,0);
- sendStream.start();
- mProcessor.start();
- }
- catch (Exception e)
- {
- System.out.println(e);
- }
- }
- }