Desidero acquisire e trasmettere audio utilizzando JMF 2.1.1e in formato RTP. Ho scritto un semplice trasmettitore, posso trasmettere e ricevere l'audio. Ma quando ho visto in Wireshark, ho visto i pacchetti come UDP. Qualcuno può indicarmi il problema, per favore.Perché è UDP, non RTP in Wireshark quando eseguo lo streaming utilizzando jmf?
E questa è la mia funzione responsabile per l'acquisizione e la trasmissione audio.
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();
}
}
}
E chiedere, se si trova qualcosa di improprio o vago. Grazie in anticipo. :)
Chiarimento: Ho un pezzo di codice C# per lo streaming RTP. E quando ho catturare i dati utilizzando Wireshark, posso vedere loro come RTP, ma il problema è quando ho catturare il flusso di dati da JMF Wireshark mostrare loro come UDP. E la mia domanda è, perché?
Conosco la differenza tra UDP e RTP.
Penso che il problema sia su CONTENT_DESCRIPTOR, è raw-rtp. – shibli049
Capisco che il tuo codice è in esecuzione tranne per il problema che stai affrontando proprio ora. Abbiamo bisogno di vedere nel codice sorgente JMF come JMF implementa la classe Processor quando usa CONTENT_DESCRIPTOR come quello che ha detto Osbcure. Forse questa è la differenza tra i codici C# e i codici Java JMF. Ti interessa sapere quale libreria di streaming stai usando per la versione C#? – ecle
@eee: Il progetto C# sta usando pjsipDll, l'ho appena portato da un amico per testare i pacchetti in wireshark, e non sono abituato a lavorare con C#. Quindi, non potrei fornirti ulteriori dettagli su C#. – shibli049