2014-01-10 6 views
11

Ich baue einen RTSP-Streaming-Server in Java mit Xuggler, aber ich bin mir nicht sicher, wie Sie korrekte RTP-Paketierung implementieren.Wie Mediendatei in RTP-Paketen mit Xuggler zu kodieren

My aktuelle Ansatz ist ReadNextPacket(packet) auf dem Eingabebehälter zu rufen, anschließend mit der Nutzlast gefüllt durch packet.getData() und entsprechende Header (Nutzlasttyp basierend auf Stream-Index, Zeitstempel gesetzt durch getTimestamp(), etc.) aus und sendet es ein RTP-Paket herstellt.

Kann mir jemand ein praktisches Beispiel geben, wie man eine IPacket in eine korrekte rtp Nutzlast, in der meisten Input-Format-unabhängige Weise zu kodieren? Die Dokumentation fehlt ein bisschen daran.

+0

@Streak Ihre Verbindung ist gebrochen –

+0

Sorry, die Domain ist verschoben, denke ich. – streak

+1

Ich glaube es hängt vom Eingabeformat ab. z.B. Unter https://tools.ietf.org/html/rfc5219 erfahren Sie, wie Sie eine RTP-Payload für MP3-Dateien einrichten. Es gibt andere RFCs, die andere Formate dokumentieren. In jedem Fall ist das Eingabeformat sehr wichtig. Sie möchten beispielsweise keinen MP3-Frame zwischen zwei Paketen aufteilen. – colti

Antwort

0

Ich habe einen Code gesehen, der javax.media für die Implementierung von RTP-Server verwendet.

class MediaConvertion { 
private MediaLocator mediaLocator = null; 

private DataSink dataSink = null; 

private Processor mediaProcessor = null; 

private static final Format[] FORMATS = new Format[] { new AudioFormat(
     AudioFormat.DVI_RTP) }; 

private static final ContentDescriptor CONTENT_DESCRIPTOR = new ContentDescriptor(
     ContentDescriptor.RAW_RTP); 

public MediaConvertion(String url) throws IOException, 
     NoProcessorException, CannotRealizeException, NoDataSinkException, 
     NoDataSinkException { 
    mediaLocator = new MediaLocator(url); 
} 

public void setDataSource(DataSource ds) throws IOException, 
     NoProcessorException, CannotRealizeException, NoDataSinkException { 

    mediaProcessor = Manager.createRealizedProcessor(new ProcessorModel(ds, 
      FORMATS, CONTENT_DESCRIPTOR)); 
    dataSink = Manager.createDataSink(mediaProcessor.getDataOutput(), 
      mediaLocator); 
} 

public void startTransmitting() throws IOException { 
    mediaProcessor.start(); 
    dataSink.open(); 
    dataSink.start(); 
} 

public void stopTransmitting() throws IOException { 
    dataSink.stop(); 
    dataSink.close(); 
    mediaProcessor.stop(); 
    mediaProcessor.close(); 
} 
} 

public class MediaConverterExample extends Frame implements ActionListener { 

Button st_stream; 
static MediaConvertion mdcon; 

public static void main(String args[]) throws IOException, 
     NoProcessorException, CannotRealizeException, NoDataSinkException, 
     MalformedURLException, NoDataSourceException { 
    Format input1 = new AudioFormat(AudioFormat.MPEGLAYER3); 
    Format input2 = new AudioFormat(AudioFormat.MPEG); 
    Format output = new AudioFormat(AudioFormat.LINEAR); 
    PlugInManager.addPlugIn("com.sun.media.codec.audio.mp3.JavaDecoder", 
      new Format[] { input1, input2 }, new Format[] { output }, 
      PlugInManager.CODEC); 
    File mediaFile = new File(args[1]); 
    DataSource source = Manager.createDataSource(new MediaLocator(mediaFile 
      .toURL())); 
    mdcon = new MediaConvertion(args[0]); 
    mdcon.setDataSource(source); 
    new MediaConverterExample(); 
} 

public MediaConverterExample() { 
    st_stream = new Button("Start Streaming"); 
    add(st_stream); 
    st_stream.addActionListener(this); 
    setVisible(true); 
    setSize(200, 300); 

} 

public void actionPerformed(ActionEvent ae) { 
    try { 
     mdcon.startTransmitting(); 
    } catch (Exception e) { 
    } 
} 
}