How to capture rtp packet??

Hi,
can someone plz tell me how to capture rtp packets. And also can u tell me how to remove the rtp header. I want to add another header to the rtp packet. I will be glad if u can also send me some code samples too.
Thank you in advance.
bye
R.Ravi Kiran

To Capture the RTP Packet all you need to do is listen for a UDP packet on the destination address and you will be able to receive the data. The Data field is by default 256 bytes long (just to let you know).
So you will send the RTP Packet to Localhost port 4444
To capture the packet you need to be listening for a UDP packet on that Address
it would look something like this:
byte[] buf = new byte[256];
DatagramSocket socket = new DatagramSocket(4444);
DatagramPacket packet = new DatagramPacket(buf, buf.length);
socket.receive(packet);
then you just have to do what you want with the buf array
I'm not to sure about the RTP Header I'm working on that as well.. so if I find anything I will let you know.

Similar Messages

  • Wireshark capture rtp packets on Cisco CUBE.

    Hello all,
    We have this call flow and we are having intermittent DTMF issue
    CUCM 10.5--->CUBE(10.1.1.10--->AVAYA(10.1.1.11)--->PSTN
    I am trying to capture RTP packets between CUBE and AVAYA, How can we capture RTP packets between(10.1.1.10 and 10.1.1.11)??
    I followed below steps and I can see the traffic only from AVAYA to CUBE and that too only SIP and TCP not RTP.
    Router(config)# access-list 140 permit ip host 32.55.55.32 any
    Router(config)# access-list 140 permit ip any host 32.55.55.32
    This ACL will capture all traffic to and from this IP address.
    Next we need to enable the Cisco packet monitoring service:
    Router# monitor capture buffer holdpackets
    Now we can filter the monitored traffic by filtering it through our access-list:
    Router# monitor capture buffer holdpackets filter access-list 140
    Now we need to name our particular packet capture. I have called mine "testcap"
    Router# monitor capture point ip cef testcap all both
    Router# monitor capture point associate testcap holdpackets
    Now we can start our capture!
    Router# monitor capture point start testcap
    Once you think you have acquired enough packets, to stop the capture, type:
    Router# monitor capture point stop testcap
    Now you can export your data to your tftp server by typing in the following command. You can then open the .pcap file in Wireshark for viewing
    Router# monitor capture buffer holdpackets export tftp://10.0.0.55/testcap.pcap
    Once uploaded you can clear your capture buffer by typing the following:
    Router# no monitor capture buffer holdpackets
    Any help is much appreciated
    Thanks!

    But when i configure the destination as USB0 my pendrive, it fails.
    Could be a bug but I wouldn't recommend configuring the destination as your USB drive because no one has the same luxury as you to have the USB sit there all the time.
    Store to the flash and transfer to USB is probably the best solution.

  • How to send RTP packet through SIP Dialog

    Hello there !
    I work on a Java softphone which use JMF and Jain-SIP. I know JMF is "old" but I think it would be simple to capture and transmit RTP audio. So, my SIP dialog is working, I can send text messages but now, I would like to send RTP with this SIP session. I know I have to send SDP messages for codec convenience but then, what is the MediaLocator for RTP packet ? Only SIP User Agent IP or something else ?
    I also accept all ressources that can help me achieve my work :)

    I have no idea how SIP works, but, RTP packets go to an IP:PORT... theoretically, in the SIP phonecall setup, I'd imagine you'd have to be given the address to send RTP packets to the remote phone. Or perhaps the port is already well-defined by the SIP standard.
    Either way, you should have a way of knowing / finding out which PORT to send to for your SIP call, either from the call setup or the SIP standard itself.

  • How to edit RTP Packets

    Hi,
    I want to add some information in RTP Packet, (in Extensions Header). How can I do that in JMF ?
    Thanks in Advance,
    Karthikeyan R

    OK, thank you. So specifically -- if I want to prioritize all of the RTP traffic flowing out through the router, can I do it ALL with just COS and not set any QoS, profile binding etc?
    So far I have enabled the COS Queue, left the default settings (where COS Priorities 6 and 7 are set to highest), then on the COS to DSCP page I have entered the value 46 into the Priority 6 and 7 boxes. All the rest I left at 0.
    Unfortunately this didn't seem to solve the issue. The way I have been testing is to call our PBX from an outside line, then put myself on hold so I can hear the hold music (effectively an audio stream from the PBX server). Then I listen carefully while I run a bandwidth test from speedtest.net.
    During the download test the audio (music on hold) is pretty smooth. But during the upload test (lots of data flowing outbound) the audio gets very choppy. The COS settings I've tried don't seem to improve or even change that
    I assume I'm doing something wrong and/or need to involve QoS somehow?
    - Keith

  • How to prioritize RTP Packets for VOIP Audio on RV180

    Hi There,
    I'm a relative newbie to more advanced networking but have managed to get our small office IP PBX running over a SIP Trunk. The only real problem we are having is choppy outgoing audio when there is other heavy outgoing traffic on the network.
    My understanding is that I need to set some QoS parameters, which I have played with but it didn't seem to help much. I mostly dealt with allocating bandwidth. I now think I need to somehow prioritize the outgoing RTP packets from our PBX (which runs on a PC on our LAN) to help avoid the choppy audio. My research shows this can maybe be done with something called DSCP 46 and my router does support that -- I'm just a little confused on how to exactly set the configuration.
    Our router is a Cisco rv180w. I'm thinking it should be pretty straightforward, but any guidance would be appreciated (and feel free to let me know if I'm barking up the entirely wrong tree, too!)
    Thanks so much.

    OK, thank you. So specifically -- if I want to prioritize all of the RTP traffic flowing out through the router, can I do it ALL with just COS and not set any QoS, profile binding etc?
    So far I have enabled the COS Queue, left the default settings (where COS Priorities 6 and 7 are set to highest), then on the COS to DSCP page I have entered the value 46 into the Priority 6 and 7 boxes. All the rest I left at 0.
    Unfortunately this didn't seem to solve the issue. The way I have been testing is to call our PBX from an outside line, then put myself on hold so I can hear the hold music (effectively an audio stream from the PBX server). Then I listen carefully while I run a bandwidth test from speedtest.net.
    During the download test the audio (music on hold) is pretty smooth. But during the upload test (lots of data flowing outbound) the audio gets very choppy. The COS settings I've tried don't seem to improve or even change that
    I assume I'm doing something wrong and/or need to involve QoS somehow?
    - Keith

  • How to use jmf convert the rtp packet (captured by jpcap) in to wav file?

    I use the jpcap capture the rtp packets(payload: ITU-T G.711 PCMU ,from voip)
    and now I want to use JMF read those data and convert in to wav file
    How to do this? please help me

    pedrorp wrote:
    Hi Captfoss!
    I fixed it but now I have another problem. My application send me this message:
    Cannot initialize audio renderer with format: LINEAR, Unknown Sample Rate, 16-bit, Mono, LittleEndian, Signed
    Unable to handle format: ALAW/rtp, Unknown Sample Rate, 8-bit, Mono, FrameSize=8 bits
    Failed to prefetch: com.sun.media.PlaybackEngine@1b45ddc
    Error: Unable to prefetch com.sun.media.PlaybackEngine@1b45ddc
    This time the fail is prefetching. I have no idea why this problem is. Could you help me?The system cant play an audio file / stream if it doesn't know the sample rate...somewhere along the way, in your code, the sample rate got lost. Sample rates are highly important, because they tell the system how fast to play the file.
    You need to go look through your code and find where the sample rate information is getting lost...

  • How to read sequence numbers from RTP packets

    hi everyone.
    i want to know how to read sequence numbers of RTP packets. I will need that to reconstruct my stream from packet losses.
    URGENT Help needed!!

    The StreamTokenizer parses all numbers into only one type of value, a double. If you know that all the numeric values in the file will be integers, you could just cast the nval double field to an int and the toString() method will format it correctly.
    If you want to have different tokens and value types for different kinds of numbers, you will have to sub-class StreamTokenizer and add these capabilities yourself. You can add the type constant TT_INT, and provide an int field named ival. The toString() method would then format the value in the correct manner.
    If, on the other hand, you are actually looking for the exact text that was parsed, you could add code that collects the characters as they are parsed for any token type into the sval field in the nextToken() method, just like it already does when the token is a TT_WORD. In this manner sval is always valid for any token type.
    I hope you find this of some help.

  • JMF How to stream rtp from udp packet

    I implemented an rtsp client and use the client to setup two rtp session(audio, vedio). But when I use the example pramgram "AVReceive3" to stream the udp packet, it doesn't work.
    When the AVReceive3 receive the udp packet from the rtp port, it will call the update(ReceiveStreamEvent evt) function, and the event type is StreamMappedEvent, and the call to evt.getReceiveStream().getDataSource() return null.
    I thought the first event should be NewReceiveStreamEvent. Please help to solve the problem.
    What's rtp packet will cause the event StreamMappedEvent.
    Following is the code of AVReceive3.java:
    * AVReceive3.java
    * Created on 2007年10月30日, 下午4:11
    * To change this template, choose Tools | Template Manager
    * and open the template in the editor.
    package PlayerTest;
    import java.io.*;
    import java.awt.*;
    import java.net.*;
    import java.awt.event.*;
    import java.util.Vector;
    import javax.media.*;
    import javax.media.rtp.*;
    import javax.media.rtp.event.*;
    import javax.media.rtp.rtcp.*;
    import javax.media.protocol.*;
    import javax.media.protocol.DataSource;
    import javax.media.format.AudioFormat;
    import javax.media.format.VideoFormat;
    import javax.media.Format;
    import javax.media.format.FormatChangeEvent;
    import javax.media.control.BufferControl;
    * AVReceive3 to receive RTP transmission using the RTPConnector.
    public class AVReceive3 extends Thread implements ReceiveStreamListener, SessionListener,
    ControllerListener
    String sessions[] = null;
    RTPManager mgrs[] = null;
    Vector playerWindows = null;
    boolean dataReceived = false;
    Object dataSync = new Object();
    public AVReceive3(String sessions[])
    this.sessions = sessions;
    public void run()
    initialize();
    public boolean initialize() {
    try {
    mgrs = new RTPManager[sessions.length];
    playerWindows = new Vector();
    SessionLabel session;
    // Open the RTP sessions.
    for (int i = 0; i < sessions.length; i++) {
    // Parse the session addresses.
    try {
    session = new SessionLabel(sessions);
    } catch (IllegalArgumentException e) {
    System.err.println("Failed to parse the session address given: " + sessions[i]);
    return false;
    System.err.println(" - Open RTP session for: addr: " + session.addr + " port: " + session.port + " ttl: " + session.ttl);
    mgrs[i] = (RTPManager) RTPManager.newInstance();
    mgrs[i].addSessionListener(this);
    mgrs[i].addReceiveStreamListener(this);
    // Initialize the RTPManager with the RTPSocketAdapter
    mgrs[i].initialize(new RTPSocketAdapter(
    InetAddress.getByName(session.addr),
    session.port, session.ttl));
    // You can try out some other buffer size to see
    // if you can get better smoothness.
    BufferControl bc = (BufferControl)mgrs[i].getControl("javax.media.control.BufferControl");
    if (bc != null)
    bc.setBufferLength(350);
    } catch (Exception e){
    System.err.println("Cannot create the RTP Session: " + e.getMessage());
    return false;
    // Wait for data to arrive before moving on.
    long then = System.currentTimeMillis();
    long waitingPeriod = 30000; // wait for a maximum of 30 secs.
    try{
    synchronized (dataSync) {
    while (!dataReceived &&
    System.currentTimeMillis() - then < waitingPeriod) {
    if (!dataReceived)
    System.err.println(" - Waiting for RTP data to arrive");
    dataSync.wait(1000);
    } catch (Exception e) {}
    if (!dataReceived) {
    System.err.println("No RTP data was received.");
    close();
    return false;
    return true;
    public boolean isDone() {
    return playerWindows.size() == 0;
    * Close the players and the session managers.
    protected void close() {
    for (int i = 0; i < playerWindows.size(); i++) {
    try {
    ((PlayerWindow)playerWindows.elementAt(i)).close();
    } catch (Exception e) {}
    playerWindows.removeAllElements();
    // close the RTP session.
    for (int i = 0; i < mgrs.length; i++) {
    if (mgrs[i] != null) {
    mgrs[i].removeTargets( "Closing session from AVReceive3");
    mgrs[i].dispose();
    mgrs[i] = null;
    PlayerWindow find(Player p) {
    for (int i = 0; i < playerWindows.size(); i++) {
    PlayerWindow pw = (PlayerWindow)playerWindows.elementAt(i);
    if (pw.player == p)
    return pw;
    return null;
    PlayerWindow find(ReceiveStream strm) {
    for (int i = 0; i < playerWindows.size(); i++) {
    PlayerWindow pw = (PlayerWindow)playerWindows.elementAt(i);
    if (pw.stream == strm)
    return pw;
    return null;
    * SessionListener.
    public synchronized void update(SessionEvent evt) {
    if (evt instanceof NewParticipantEvent) {
    Participant p = ((NewParticipantEvent)evt).getParticipant();
    System.err.println(" - A new participant had just joined: " + p.getCNAME());
    * ReceiveStreamListener
    public synchronized void update( ReceiveStreamEvent evt) {
    System.out.println("\nReceive an receiveStreamEvent:"+evt.toString());
    RTPManager mgr = (RTPManager)evt.getSource();
    Participant participant = evt.getParticipant(); // could be null.
    ReceiveStream stream = evt.getReceiveStream(); // could be null.
    System.out.println("The RTPManager is:");
    if (evt instanceof RemotePayloadChangeEvent) {
    System.err.println(" - Received an RTP PayloadChangeEvent.");
    System.err.println("Sorry, cannot handle payload change.");
    System.exit(0);
    else if (evt instanceof NewReceiveStreamEvent) {
    try {
    stream = ((NewReceiveStreamEvent)evt).getReceiveStream();
    DataSource ds = stream.getDataSource();
    // Find out the formats.
    RTPControl ctl = (RTPControl)ds.getControl("javax.media.rtp.RTPControl");
    if (ctl != null){
    System.err.println(" - Recevied new RTP stream: " + ctl.getFormat());
    } else
    System.err.println(" - Recevied new RTP stream");
    if (participant == null)
    System.err.println(" The sender of this stream had yet to be identified.");
    else {
    System.err.println(" The stream comes from: " + participant.getCNAME());
    // create a player by passing datasource to the Media Manager
    Player p = javax.media.Manager.createPlayer(ds);
    if (p == null)
    return;
    p.addControllerListener(this);
    p.realize();
    PlayerWindow pw = new PlayerWindow(p, stream);
    playerWindows.addElement(pw);
    pw.setVisible(true);
    // Notify intialize() that a new stream had arrived.
    synchronized (dataSync) {
    dataReceived = true;
    dataSync.notifyAll();
    } catch (Exception e) {
    System.err.println("NewReceiveStreamEvent exception " + e.getMessage());
    return;
    else if (evt instanceof StreamMappedEvent) {
    if (stream != null)
    if(stream.getDataSource()!=null)
    DataSource ds = stream.getDataSource();
    // Find out the formats.
    RTPControl ctl = (RTPControl)ds.getControl("javax.media.rtp.RTPControl");
    System.err.println(" - The previously unidentified stream ");
    if (ctl != null)
    System.err.println(" " + ctl.getFormat());
    System.err.println(" had now been identified as sent by: " + participant.getCNAME());
    else if (evt instanceof ByeEvent) {
    System.err.println(" - Got \"bye\" from: " + participant.getCNAME());
    PlayerWindow pw = find(stream);
    if (pw != null) {
    pw.close();
    playerWindows.removeElement(pw);
    * ControllerListener for the Players.
    public synchronized void controllerUpdate(ControllerEvent ce) {
    Player p = (Player)ce.getSourceController();
    if (p == null)
    return;
    // Get this when the internal players are realized.
    if (ce instanceof RealizeCompleteEvent) {
    PlayerWindow pw = find(p);
    if (pw == null) {
    // Some strange happened.
    System.err.println("Internal error!");
    System.exit(-1);
    pw.initialize();
    pw.setVisible(true);
    p.start();
    if (ce instanceof ControllerErrorEvent) {
    p.removeControllerListener(this);
    PlayerWindow pw = find(p);
    if (pw != null) {
    pw.close();
    playerWindows.removeElement(pw);
    System.err.println("AVReceive3 internal error: " + ce);
    * A utility class to parse the session addresses.
    class SessionLabel {
    public String addr = null;
    public int port;
    public int ttl = 1;
    SessionLabel(String session) throws IllegalArgumentException {
    int off;
    String portStr = null, ttlStr = null;
    if (session != null && session.length() > 0) {
    while (session.length() > 1 && session.charAt(0) == '/')
    session = session.substring(1);
    // Now see if there's a addr specified.
    off = session.indexOf('/');
    if (off == -1) {
    if (!session.equals(""))
    addr = session;
    } else {
    addr = session.substring(0, off);
    session = session.substring(off + 1);
    // Now see if there's a port specified
    off = session.indexOf('/');
    if (off == -1) {
    if (!session.equals(""))
    portStr = session;
    } else {
    portStr = session.substring(0, off);
    session = session.substring(off + 1);
    // Now see if there's a ttl specified
    off = session.indexOf('/');
    if (off == -1) {
    if (!session.equals(""))
    ttlStr = session;
    } else {
    ttlStr = session.substring(0, off);
    if (addr == null)
    throw new IllegalArgumentException();
    if (portStr != null) {
    try {
    Integer integer = Integer.valueOf(portStr);
    if (integer != null)
    port = integer.intValue();
    } catch (Throwable t) {
    throw new IllegalArgumentException();
    } else
    throw new IllegalArgumentException();
    if (ttlStr != null) {
    try {
    Integer integer = Integer.valueOf(ttlStr);
    if (integer != null)
    ttl = integer.intValue();
    } catch (Throwable t) {
    throw new IllegalArgumentException();
    * GUI classes for the Player.
    class PlayerWindow extends Frame {
    Player player;
    ReceiveStream stream;
    PlayerWindow(Player p, ReceiveStream strm) {
    player = p;
    stream = strm;
    public void initialize() {
    add(new PlayerPanel(player));
    public void close() {
    player.close();
    setVisible(false);
    dispose();
    public void addNotify() {
    super.addNotify();
    pack();
    * GUI classes for the Player.
    class PlayerPanel extends Panel {
    Component vc, cc;
    PlayerPanel(Player p) {
    setLayout(new BorderLayout());
    if ((vc = p.getVisualComponent()) != null)
    add("Center", vc);
    if ((cc = p.getControlPanelComponent()) != null)
    add("South", cc);
    public Dimension getPreferredSize() {
    int w = 0, h = 0;
    if (vc != null) {
    Dimension size = vc.getPreferredSize();
    w = size.width;
    h = size.height;
    if (cc != null) {
    Dimension size = cc.getPreferredSize();
    if (w == 0)
    w = size.width;
    h += size.height;
    if (w < 160)
    w = 160;
    return new Dimension(w, h);
    public static void main(String argv[]) {
    //if (argv.length == 0)
    // prUsage();
    String sessions[]= new String[] {"127.0.0.1/6670","127.0.0.1/6672"};
    AVReceive3 avReceive = new AVReceive3(sessions);
    if (!avReceive.initialize()) {
    System.err.println("Failed to initialize the sessions.");
    System.exit(-1);
    // Check to see if AVReceive3 is done.
    try {
    while (!avReceive.isDone())
    Thread.sleep(1000);
    } catch (Exception e) {}
    System.err.println("Exiting AVReceive3");
    static void prUsage() {
    System.err.println("Usage: AVReceive3 <session> <session> ");
    System.err.println(" <session>: <address>/<port>/<ttl>");
    System.exit(0);
    }// end of AVReceive3
    Following is the code of RTPSocketAdapter.java:
    * RTPSocketAdapter.java
    * Created on 2007&#24180;10&#26376;30&#26085;, &#19979;&#21320;4:13
    * To change this template, choose Tools | Template Manager
    * and open the template in the editor.
    package PlayerTest;
    import java.io.IOException;
    import java.net.InetAddress;
    import java.net.DatagramSocket;
    import java.net.MulticastSocket;
    import java.net.DatagramPacket;
    import java.net.SocketException;
    import javax.media.protocol.DataSource;
    import javax.media.protocol.PushSourceStream;
    import javax.media.protocol.ContentDescriptor;
    import javax.media.protocol.SourceTransferHandler;
    import javax.media.rtp.RTPConnector;
    import javax.media.rtp.OutputDataStream;
    * An implementation of RTPConnector based on UDP sockets.
    public class RTPSocketAdapter implements RTPConnector {
    DatagramSocket dataSock;
    DatagramSocket ctrlSock;
    InetAddress addr;
    int port;
    SockInputStream dataInStrm = null;
    SockInputStream ctrlInStrm = null;
    SockOutputStream dataOutStrm = null;
    SockOutputStream ctrlOutStrm = null;
    public RTPSocketAdapter(InetAddress addr, int port) throws IOException {
    this(addr, port, 1);
    public RTPSocketAdapter(InetAddress addr, int port, int ttl) throws IOException {
    try {
    if (addr.isMulticastAddress()) {
    dataSock = new MulticastSocket(port);
    ctrlSock = new MulticastSocket(port+1);
    ((MulticastSocket)dataSock).joinGroup(addr);
    ((MulticastSocket)dataSock).setTimeToLive(ttl);
    ((MulticastSocket)ctrlSock).joinGroup(addr);
    ((MulticastSocket)ctrlSock).setTimeToLive(ttl);
    } else {
    dataSock = new DatagramSocket(port, InetAddress.getLocalHost());
    ctrlSock = new DatagramSocket(port+1, InetAddress.getLocalHost());
    } catch (SocketException e) {
    throw new IOException(e.getMessage());
    this.addr = addr;
    this.port = port;
    * Returns an input stream to receive the RTP data.
    public PushSourceStream getDataInputStream() throws IOException {
    if (dataInStrm == null) {
    dataInStrm = new SockInputStream(dataSock, addr, port);
    dataInStrm.start();
    return dataInStrm;
    * Returns an output stream to send the RTP data.
    public OutputDataStream getDataOutputStream() throws IOException {
    if (dataOutStrm == null)
    dataOutStrm = new SockOutputStream(dataSock, addr, port);
    return dataOutStrm;
    * Returns an input stream to receive the RTCP data.
    public PushSourceStream getControlInputStream() throws IOException {
    if (ctrlInStrm == null) {
    ctrlInStrm = new SockInputStream(ctrlSock, addr, port+1);
    ctrlInStrm.start();
    return ctrlInStrm;
    * Returns an output stream to send the RTCP data.
    public OutputDataStream getControlOutputStream() throws IOException {
    if (ctrlOutStrm == null)
    ctrlOutStrm = new SockOutputStream(ctrlSock, addr, port+1);
    return ctrlOutStrm;
    * Close all the RTP, RTCP streams.
    public void close() {
    if (dataInStrm != null)
    dataInStrm.kill();
    if (ctrlInStrm != null)
    ctrlInStrm.kill();
    dataSock.close();
    ctrlSock.close();
    * Set the receive buffer size of the RTP data channel.
    * This is only a hint to the implementation. The actual implementation
    * may not be able to do anything to this.
    public void setReceiveBufferSize( int size) throws IOException {
    dataSock.setReceiveBufferSize(size);
    * Get the receive buffer size set on the RTP data channel.
    * Return -1 if the receive buffer size is not applicable for
    * the implementation.
    public int getReceiveBufferSize() {
    try {
    return dataSock.getReceiveBufferSize();
    } catch (Exception e) {
    return -1;
    * Set the send buffer size of the RTP data channel.
    * This is only a hint to the implementation. The actual implementation
    * may not be able to do anything to this.
    public void setSendBufferSize( int size) throws IOException {
    dataSock.setSendBufferSize(size);
    * Get the send buffer size set on the RTP data channel.
    * Return -1 if the send buffer size is not applicable for
    * the implementation.
    public int getSendBufferSize() {
    try {
    return dataSock.getSendBufferSize();
    } catch (Exception e) {
    return -1;
    * Return the RTCP bandwidth fraction. This value is used to
    * initialize the RTPManager. Check RTPManager for more detauls.
    * Return -1 to use the default values.
    public double getRTCPBandwidthFraction() {
    return -1;
    * Return the RTCP sender bandwidth fraction. This value is used to
    * initialize the RTPManager. Check RTPManager for more detauls.
    * Return -1 to use the default values.
    public double getRTCPSenderBandwidthFraction() {
    return -1;
    * An inner class to implement an OutputDataStream based on UDP sockets.
    class SockOutputStream implements OutputDataStream {
    DatagramSocket sock;
    InetAddress addr;
    int port;
    public SockOutputStream(DatagramSocket sock, InetAddress addr, int port) {
    this.sock = sock;
    this.addr = addr;
    this.port = port;
    public int write(byte data[], int offset, int len) {
    try {
    sock.send(new DatagramPacket(data, offset, len, addr, port));
    } catch (Exception e) {
    return -1;
    return len;
    * An inner class to implement an PushSourceStream based on UDP sockets.
    class SockInputStream extends Thread implements PushSourceStream {
    DatagramSocket sock;
    InetAddress addr;
    int port;
    boolean done = false;
    boolean dataRead = false;
    SourceTransferHandler sth = null;
    public SockInputStream(DatagramSocket sock, InetAddress addr, int port) {
    this.sock = sock;
    this.addr = addr;
    this.port = port;
    public int read(byte buffer[], int offset, int length) {
    DatagramPacket p = new DatagramPacket(buffer, offset, length, addr, port);
    try {
    sock.receive(p);
    } catch (IOException e) {
    return -1;
    synchronized (this) {
    dataRead = true;
    notify();
    System.out.println("RTPSocketAdapter receive RTP packet from port:"+port);
    System.out.println("The received RTP packet:"+new String(buffer));
    return p.getLength();
    public synchronized void start() {
    super.start();
    if (sth != null) {
    dataRead = true;
    notify();
    public synchronized void kill() {
    done = true;
    notify();
    public int getMinimumTransferSize() {
    return 2 * 1024; // twice the MTU size, just to be safe.
    public synchronized void setTransferHandler(SourceTransferHandler sth) {
    this.sth = sth;
    dataRead = true;
    notify();
    // Not applicable.
    public ContentDescriptor getContentDescriptor() {
    return null;
    // Not applicable.
    public long getContentLength() {
    return LENGTH_UNKNOWN;
    // Not applicable.
    public boolean endOfStream() {
    return false;
    // Not applicable.
    public Object[] getControls() {
    return new Object[0];
    // Not applicable.
    public Object getControl(String type) {
    return null;
    * Loop and notify the transfer handler of new data.
    public void run() {
    while (!done) {
    synchronized (this) {
    while (!dataRead && !done) {
    try {
    wait();
    } catch (InterruptedException e) { }
    dataRead = false;
    if (sth != null && !done) {
    sth.transferData(this);
    Thanks.

    The error of No format has been registered for RTP Payload type 96
    is caused by the dynamic payload mapping, when I add the dynamic mapping between dynamic payload and format. The Player cann't work yet. I think it because JMF doesn't support the format of my clips. For example:
    video: a=rtpmap:96 H263-2000/90000
    audio:a=rtpmap:97 MP4A-LATM/12000/1
    Is there some available plugin to support these format?
    Thanks

  • Capturing RTP sent by JMF with Wireshark

    The post was originally at http://forums.sun.com/thread.jspa?threadID=5331241.
    I am using http://java.sun.com/javase/technologies/desktop/media/jmf/2.1.1/solutions/RTPConnector.html as a template in my program. I see the packets sent back and forth using Wireshark but Wireshark doesnt recognize them as RTP packets but UDP. The original thread had an answer about the payload.
    Where is the payload defined in the sample code I am using and how can I change the payload so that Wireshark captures them as RTP? Is it this line:
    ContentDescriptor cd = new ContentDescriptor(ContentDescriptor.RAW_RTP); If yes, what should I change it to? Also, I took a look at Wireshark and you can force the UDP packets to decode as RTP but it is not very feasible.
    Thanks.

    If you need the custom RTPConnector to send out UDP packets that show up as RTP packets, I'd recommend reposting the question to the networking forum. That's more of a networking question than it is a JMF one.

  • DVI/RTP packet decode

    Hi,
    I need to stream audio and/or video to a PDA device. There is a trick here which is:
    The PDA must receive the stream from a multicast address. For this I have implemented a Bridge application which joins the multicast group on behalf of the PDA and receives the Multicast RTP packets (which are sent from JMStudio) and Unicasts them to the PDA.(HP iPAQ) I had no problem implementing this. The streaming is done using JMStudio player which encodes the streaming audio data into a number of encodings (DVI/RTP in my case). I choose DVI/RTP and stream a .wav audio file.
    Now I have to accept the packets and play the stream on the PDA.
    The j2me application receives all the RTP packets successfully and I can extract usefull information from the packets such as: Timestamp, sequence number, payload type. The payload type is 5 which means it is a DVI4 encoding.
    I use the following method to decode the samples:
    public int decode(Object state, byte[] input, int inp, int len, short[] output, int outp) {
    int sign;
    int delta;
    int vpdiff;
    //int valprev = audio.Convert.byte2short(input, inp);
    //int index = input[inp + 2];
    int valprev=0,index=0;
    int inputbuffer = 0;
    int bufferstep = 0;
    valprev = input[0] <<8;
    valprev |= input[1] &0xff;
    index = input[2] &0xff;
    if ( index < 0 ) index = 0;
    else if ( index > 88 ) index = 88;
    int step = stepsizeTable[index];
    inp += 4;
    len = (len - 4) * 2;
    int count = len;
    while(count-- > 0) {
    if ( 0 == bufferstep ) {
    inputbuffer = input[inp++];
    delta = (inputbuffer >> 4) & 0xf;
    bufferstep = 1;
    } else {
    delta = inputbuffer & 0xf;
    bufferstep = 0;
    index += indexTable[delta];
    if ( index < 0 ) index = 0;
    else if ( index > 88 ) index = 88;
    sign = delta & 8;
    delta = delta & 7;
    vpdiff = step >> 1;
    if ( (delta & 4) == 4 ) vpdiff += (step << 2);
    if ( (delta & 2) == 2 ) vpdiff += (step << 1);
    if ( (delta & 1) == 1 ) vpdiff += step;
    vpdiff >>= 2;
    if ( 0 != sign )
    valprev -= vpdiff;
    else
    valprev += vpdiff;
    if ( valprev > 32767 )
    valprev = 32767;
    else if ( valprev < -32768 )
    valprev = -32768;
    step = stepsizeTable[index];
    output[outp++] = (short) valprev;
    ((AdpcmState)state).valprev = valprev;
    ((AdpcmState)state).index = index;
    return len;
    which stores the result into a short[] array.
    I then convert this short[] array into a byte[] array with the following way:
    s is the short[] array
    adp is the byte array
    for(int g=0,k=0;g<s.length;g++,k=k+2){
    audio.Convert.short2byte(s[g],adp,k);
    public static void short2byte(short ival, byte b[], int offset) {
    int i;
    int bits = 16;
    for(i = 0; i >< 2; i++) {
    bits -= 8;
    b[offset + i] = (byte) ((ival >> bits) & 0xff);
    The final result is loaded to the player as follows:
    ByteArrayInputStream input1 = new ByteArrayInputStream(adp);
    player = Manager.createPlayer(input1, "audio/x-wav");//create new player
    player.addPlayerListener(this);
    player.prefetch();
    player.realize();
    player.start();
    The player begins to play but I only get horrible sounds instead of the original wave file
    The player now initializes ok without any problem but I can only hear a meesed up sound rather than the original. So now I strongly believe that the problem is in the decoding of the samples of the DVI/RTP codec.

    thesti wrote:
    how JMF deal with RTP packet loss? since my application doesn't handle anything due to RTP packet loss, i believe that JMF has a mechanism to deal with it.It "deals" with it by having a blank spot in the rendering where that packet would have gone...

  • Setting dimension of RTP packet with 'rtp' jmf

    How is it possibile to set the dimension of RTP packet with JMF in the transmitting audio stream with RTP????

    thesti wrote:
    how JMF deal with RTP packet loss? since my application doesn't handle anything due to RTP packet loss, i believe that JMF has a mechanism to deal with it.It "deals" with it by having a blank spot in the rendering where that packet would have gone...

  • Create one player to play RTP packets from many clients

    Hi,
    Am a JMF newbie and I want to create one player to play packets from many clients.
    So I wrote a small UDPserver thread within the app to receive rtp packets from the clients on the LAN which in turn forwards them to the player.
    I instatiated two threads one to forward RTP packets and another to forward RTCP packets which listens on RTPPort+1
    The reason why i do this is that i don't want the whole internet to bombard the player with anonymous voice transmissions.So the server thread is acting as a firewall. To filter out packets from from unknown ip addresses.
    this is a snippet of the player.
    MY_IPADDRESS =   InetAddress.getLocalHost().getHostAddress();+
    url = "rtp://" + MY_IPADDRESS + ":" + RTPPlayer.PORT + "/audio/1";
    MediaLocator mrl = new MediaLocator(url);
    player = Manager.createPlayer(mrl);
    More code which starts the server thread
    if (player != null) {
           player.addControllerListener(this);
           player.realize();
    player.start();When the server thread receives the packet it calls its forward method to forward the packet to the player by resetting the only the IP and PORT.
    public void forward(DatagramPacket rtpPacket) {
             //print out packet info to view which packets are being received
             System.out.println("forwarding "+request.getAddress() + " -> " + MY_IPADDRESS+":"+portToSend);
             //set address of packet to MY_IPADDRESS
           rtpPacket.setAddress(
                   InetAddress.getByName(RTPPlayer.MY_IPADDRESS));
              //set the port to the rtp port
           rtpPacket.setPort(RTPPlayer.PORT);
           datagramSocket.send(rtpPacket);
    }This works fine for two clients.
    When the clients become three(c1, c2 and c3),
    two clients communicate well(c1 and c2) but c3's voice cannot be heard on any other pc(c1 or c2) though it plays voice from both c1 and c2.
    But System.out.println("forwarding "+request.getAddress() + " -> " + MY_IPADDRESS+":"+portToSend);in the forward() method shows that packets from all clients on each pc are being received.
    Does any one have an idea why this happens?
    Are the packets so many that they overwhelm the player so it discards some or all?
    Is this the best way of doing this?
    Just to let u know all the mics are working fine.
    Thx in advance
    Edited by: noryak on Oct 29, 2008 10:29 AM

    THAT IS MY MAIN PROBLEM. In the future, please do a little bit of research before you shout at people trying to help you. I'm so so sorry if you find my answer bothersom because it sheds some light on the fact that you have absolutely no idea what you're doing.
    Your problem is that you obviously do not understand how JMF works...and you obviously havn't bothered to do any sort of research into it.
    You also don't seem to understand the concept of streaming media, concurrency, politeness, good design, proper programming, audio interleaving, or common sense.
    At least i have implemented a player playing packets from 2 different clients.Yeah, you implemented a player that plays packets from 2 different clients using a horrible workaround that doesn't treat the data correctly and manages to just drop data after scaling past 2 clients.
    Oh yeah, you've definately found the holy grail there. At least.
    You wanna know what your player is actually doing? It's playing a peice of data from A, and then a peice of data from B. It might sound like it's playing them both at the same time, but it's not. It's playing the data from one client in the gaps where there's no data, and once you've filled up the gaps in time by adding more nodes, you'll end up with data getting dropped (and that's the best case scenerio).
    my issue is that i wouldn't like to create a player for each participant imagine they were people in a conference that makes it 10 players. Please understand that if you have 10 players, you'll receive 10 times as much data as you can play with one player. You end up either having to drop 90% of your data, or having to play the data at 1/10th the speed... because you're not mixing the audio data, you're interleaving it.
    I just want to use one standard port on each client so that all clients send to the same port: The RTPManager class will allow you to receive as many streams as you want on a single port.
    As a matter of fact, had you bothered to play with any of the source code readily available online, you'd realize there is a file that does exactly what you want.
    [http://java.sun.com/javase/technologies/desktop/media/jmf/2.1.1/solutions/AVReceive2.java]
    It handles receiving multiple RTP streams from a single port, and plays them all simultaniously using an array of player objects.
    Does absolutely everything you want, out of the box.
    That sounds like alot of threadsIf you're concerned that it's too many threads, well, maybe you should stick to hello world and other things less scary. Concurrent data processing requires threads...one per peice of concurrent data, as a matter of fact, and you're dealing with a lot of streams of concurrent data here.

  • Decode raw RTP packets using JMF

    Hi!
    I have a stream of raw RTP packets comming from another program.
    How can I use JMF to decode all raw RTP packets and get the media stream using JMF?
    /Tec

    Hello,
    Have you resolved your problem?
    I've tried with Jmf, but finaly i receive each stream and save raw data in a file.
    Then i convert it to an audio file format. (tritonus : RawAudioConverter.java)
    If you have resolved with jmf i'm interested by your solution.
    try{
    rtpRcvSock.receive(rcvPkt);
    data = rcvPkt.getData();
              boolean extensionHeader = ( (data[0] & 0x08) == 0x08) ? true : false;
         int payloadType = data[1] & 0x7F;
         int cc = data[0] & 0x0F;
         int sequenceNumber = ( (data[2] & 0xFF) << 8) | (data[3] & 0xFF);
         int mediaStart = 3 * 4 + cc * 4;
         int extLength = 0;
              System.out.println("PayLoad = "+payloadType);
              System.out.println("Seqnum = "+sequenceNumber);
              System.out.println("Data Length = "+ (data.length - mediaStart));
         if (extensionHeader) {
         extLength = (data[mediaStart + 3] & 0xFF)
         | ( (data[mediaStart + 2] & 0xFF) << 8);
         mediaStart += extLength;
         byte[] mediaData = new byte[data.length - mediaStart];
         System.arraycopy(data, mediaStart, mediaData, 0, mediaData.length);
              ByteArrayInputStream bb = new ByteArrayInputStream(mediaData);
                   AudioInputStream aiStream = new AudioInputStream(bb,format,mediaData.length);
                   //AudioSystem.write(aiStream,AudioFileFormat.Type.WAVE,file);
                   file.write(mediaData);
    Then as i told i use RawAudioDataConverter.java
    Sam

  • Raw RTP packets

    I have extracted raw RTP packets with Ethereal and want the media to be put together and saved to file. Can I user JMF to put a raw RTP session together?
    If "Yes", how?
    /Tec

    I know that, but I will always have raw RTP packets that I need to have "decoded" and put to file. I cant use JMF to fetch the RTP packets.

  • Directly sending RTP Packets

    Hello,
    I have a media file divided in chunks on disk.
    I want to stream the whole media file with RTP. How can I do that? Can you directly send RTP Packets?
    For example:
    for every chunk i
       for (every 1000 bytes b[] in i)
          sendRTPPacket(b[]) //this creates a new RTP Packet with the contents of b[] and sends itIs that possible?
    If that is not possible, I have another idea:
    If I open a different RTP session for each chunk (so I can just specify as dataSource the actual chunk file), can I synchronize that at the receiver side? how can I then reconstruct the whole file ?
    How would you do that?
    Thank you!

    Hello,
    after searchig the internet, I found this:
    http://forums.sun.com/thread.jspa?threadID=5356475&tstart=1
    I think creating a customized Push DataSource will work fine, what do you think? it would push data each time a new chunk is available.
    I tried the example on http://java.sun.com/javase/technologies/desktop/media/jmf/2.1.1/solutions/LiveData.html but I'm not sure how to use it: I cannot register it.
    I would like to see the results on a player, so I used a player that I have:
    DataSource dataSource = new DataSource();
                   //dataSource.connect();
                   //dataSource.start();
                   player = Manager.createPlayer(dataSource);But I get Error: DataSource not connected
    If I call dataSource.connect() I get:
    java.lang.ClassCastException: [B cannot be cast to [I
         at com.omnividea.media.renderer.video.Java2DRenderer.bufferToImage(Java2DRenderer.java:131)
         at com.omnividea.media.renderer.video.Java2DRenderer.process(Java2DRenderer.java:105)
         at com.sun.media.BasicRendererModule.processBuffer(BasicRendererModule.java:728)
         at com.sun.media.BasicRendererModule.scheduleBuffer(BasicRendererModule.java:499)
         at com.sun.media.BasicRendererModule.doProcess(BasicRendererModule.java:400)
         at com.sun.media.RenderThread.process(BasicRendererModule.java:1114)
         at com.sun.media.util.LoopThread.run(LoopThread.java:135)
    Do you have a media player where this works? or can you tell me how to use the example, maybe without explicitly registering the new dataSource, to play media in a media player?
    What do you think about the idea of creating a similar DataSource (push) in order to push the data chunks that we have already into it?
    Thanks!
    Edited by: thawxx on Mar 11, 2009 7:20 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Maybe you are looking for

  • Can you turn the data off?

    Im planning on buying an iPhone. I dont want to get a data plan. Is there a way to make the iPhone only transfer data via wi-fi and not any of my cell phones networks?

  • Extending wait times in Workflow (items that have already started)

    We have Order Mgt order line workflow that has multiple wait and loop activities. A number of these timeout in 2 minutes. We think that this is causing the WF BG process to run extremely long times because a processed item key times out before the pr

  • InDesign CS4 will not install

    THE PROBLEM: buy clicking on the .exe file the DVD starts-up but doesn't get any further! swapped the DVD drive still no joy! Have tried everything from the Adobe TechNote: installing in "simple mode" from the desktop, virus scanner de-installed all

  • Searching for tasks based on Responsible Resource

    Hi All, I am having a requirement to search for all the tasks within cProjects based on the Responsible Resource field in cProjects. I am planning to design a custom Webdynpro application for this purpose. The requirement is that when i enter the use

  • Proper use of

    Just want to get some clarification about the correct use of public and why my error message is telling me "illegal start of expression". Please refer to the code below for the object that I'm attempting to create: public class Average extends Object