Tôi muốn ghi và phát âm thanh bằng JMF 2.1.1e ở định dạng RTP. Tôi đã viết một máy phát đơn giản, tôi có thể truyền và nhận âm thanh. Nhưng khi tôi nhìn thấy trong Wireshark, tôi thấy các gói như UDP. Bất cứ ai có thể chỉ cho tôi ra vấn đề, xin vui lòng.Tại sao UDP không phải là RTP trong Wireshark khi tôi sử dụng jmf?
Và đây là chức năng của tôi chịu trách nhiệm thu và truyền âm thanh.
public void captureAudio(){
// Get the device list for ULAW
Vector devices = captureDevices();
CaptureDeviceInfo captureDeviceInfo = null;
if (devices.size() > 0) {
//get the first device from the list and cast it as CaptureDeviceInfo
captureDeviceInfo = (CaptureDeviceInfo) devices.firstElement();
}
else {
// exit if we could not find the relevant capturedevice.
System.out.println("No such device found");
System.exit(-1);
}
Processor processor = null;
try {
//Create a Processor for the specified media.
processor = Manager.createProcessor(captureDeviceInfo.getLocator());
} catch (IOException ex) {
System.err.println(ex);
} catch (NoProcessorException ex) {
System.err.println(ex);
}
//Prepares the Processor to be programmed.
//puts the Processor into the Configuring state.
processor.configure();
//Wait till the Processor configured.
while (processor.getState() != Processor.Configured){
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
//Sets the output content-type for this Processor
processor.setContentDescriptor(CONTENT_DESCRIPTOR);
/**
ContentDescriptor CONTENT_DESCRIPTOR
= new ContentDescriptor(ContentDescriptor.RAW_RTP);
*/
//Gets a TrackControl for each track in the media stream.
TrackControl track[] = processor.getTrackControls();
boolean encodingOk = false;
//searching through tracks to get a supported audio format track.
for (int i = 0; i < track.length; i++) {
if (!encodingOk && track[i] instanceof FormatControl) {
if (((FormatControl)
track[i]).setFormat(new AudioFormat(AudioFormat.ULAW_RTP, 8000, 8, 1)) == null)
{
track[i].setEnabled(false);
}
else {
encodingOk = true;
track[i].setEnabled(encodingOk);
System.out.println("enc: " + i);
}
} else {
// we could not set this track to ULAW, so disable it
track[i].setEnabled(false);
}
}
//If we could set this track to ULAW we proceed
if (encodingOk){
processor.realize();
while (processor.getState() != Processor.Realized){
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
DataSource dataSource = null;
try {
dataSource = processor.getDataOutput();
} catch (NotRealizedError e) {
e.printStackTrace();
}
try {
String url= "rtp://192.168.1.99:49150/audio/1";
MediaLocator m = new MediaLocator(url);
DataSink d = Manager.createDataSink(dataSource, m);
d.open();
d.start();
System.out.println("transmitting...");
processor.start();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Và vui lòng hỏi, nếu bạn tìm thấy bất kỳ điều gì không đúng hoặc mơ hồ. Cảm ơn trước. :)
Làm rõ: Tôi có một số nhỏ là C# mã để phát RTP. Và khi tôi nắm bắt được dữ liệu sử dụng Wireshark, tôi có thể nhìn thấy chúng như RTP, nhưng vấn đề là khi tôi nắm bắt được dòng dữ liệu từ JMF Wireshark cho họ như UDP. Và câu hỏi của tôi là, tại sao?
Tôi biết sự khác biệt giữa UDP và RTP.
Tôi nghĩ rằng sự cố là trên CONTENT_DESCRIPTOR, đó là raw-rtp. – shibli049
Tôi hiểu rằng bạn đang chạy mã ngoại trừ vấn đề bạn đang gặp phải ngay bây giờ. Chúng ta cần thấy trong mã nguồn JMF cách JMF thực hiện lớp Processor khi nó sử dụng CONTENT_DESCRIPTOR giống như những gì Osbcure đã nói. Có lẽ đây là sự khác biệt giữa mã C# và mã Java JMF. Hãy cẩn thận để biết bạn đang sử dụng thư viện phát trực tuyến nào cho phiên bản C#? – ecle
@eee: Dự án C# đang sử dụng pjsipDll, tôi vừa đưa nó từ một người bạn để kiểm tra các gói trong wireshark, và tôi không quen làm việc với C#. Vì vậy, không thể cung cấp thêm chi tiết cho bạn về C#. – shibli049