|
本人刚开始研究jMF,需要同步传送语音与摄像头视频,找好些资料没有同时采集声音和视频进行RTP传输的。我知道在RTPManager里可以进行多轨传输,可是不知道怎么能够得到一个具备声音和图象的DataSource,难道需要分两部分做吗?一个程序负责采集语音然后建立RTP传输,另一个程序负责采集视频然后传输那样也就失去了RTPManager的价值了,不过本人程序代码里,是使用RTPManager建立多轨了,可是不知道如何得到音视频?
请高手给予指点?
this.locator = new javax.media.CaptureDeviceManager().getDevice("vfw:Microsoft WDM Image Capture (Win32):0").getLocator();
this.ipAddress = ipAddress;
Integer integer = Integer.valueOf(pb);
if (integer != null)
this.portBase = integer.intValue();
}
DataSource ds;
DataSource clone;
ds = javax.media.Manager.createDataSource(locator);
processor = javax.media.Manager.createProcessor(ds);
ContentDescriptor cd = new ContentDescriptor(ContentDescriptor.RAW_RTP);
processor.setContentDescriptor(cd);
Format supported[];
Format chosen;
boolean atLeastOneTrack = false;
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) {
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);
}
setJPEGQuality(processor, 0.5f);
dataOutput = processor.getDataOutput();
return null;
}
private String createTransmitter() {
PushBufferDataSource pbds = (PushBufferDataSource)dataOutput;
PushBufferStream pbss[] = pbds.getStreams();
rtpMgrs = new RTPManager[pbss.length];
SessionAddress localAddr, destAddr;
InetAddress ipAddr;
SendStream sendStream;
int port;
SourceDescription srcDesList[];
for (int i = 0; i < pbss.length; i++) {
try {
rtpMgrs[i] = RTPManager.newInstance();
port = portBase + 2*i;
ipAddr = InetAddress.getByName(ipAddress);
localAddr = new SessionAddress( InetAddress.getLocalHost(),
port);
destAddr = new SessionAddress( ipAddr, port);
rtpMgrs[i].initialize( localAddr);
rtpMgrs[i].addTarget( destAddr);
System.err.println( "Created RTP session: " + ipAddress + " " + port);
sendStream = rtpMgrs[i].createSendStream(dataOutput, i);
sendStream.start();
} catch (Exception e) {
return e.getMessage();
}
}
return null;
}
/****************************************************************
* Inner Classes
****************************************************************/
public static void main(String [] args) {
Format fmt = null;
int i = 0;
AVTransmit2 at = new AVTransmit2("192.168.0.63", "42020", fmt);
String result = at.start();
}
|
|