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...

Similar Messages

  • How to decode audio data from dvi/rtp to PCM linear

    Hi all,
    I am getting audio data as DVI/RTP 4 bit mono as input stream but not able to create player for this can any one send me any decoding function so that i can change this data to PCM linear 16 bit format

    S+S, ahh an academic.
    This is actually a forest-trees issue here.
    What your doing is appending the files, which would result in a size of 2S. What you want is somthing of size S. To do this you would need a Normilized merge. I say normalized merge because thats going to give you the best result while still avoiding out of range values.
    This is easy enough to by hand if both streams S1 and S2 are of the same frequency. If they are not the same frequency, the result will be size of the larger file when convereted to whatever uniformfrequency.

  • 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

  • Decoder from DVI/RTP 4 bit mono to PCM linear 16 bit

    Hi all,
    I am getting audio data as DVI/RTP 4 bit mono as input stream but not able to create player for this can any one send me any decoding function so that i can change this data to PCM linear 16 bit format

    I guess, one topic is more than enough... http://forum.java.sun.com/thread.jspa?threadID=5213182&tstart=0
    Just get the specs of the data format and do the decoding yourself.

  • Does JMF2.1.1 cross platform version support dvi/rtp

    hi!!!
    does JMF2.1.1 cross platform version support dvi/rtp ,8000.0 Hz,4-bit format???
    when i type java AVTransmit2 javasound:/0 224.0.0.1 22222 at the konsole in linux i am getting the following error:
    Audio not supported: interface TargetDataLine supporting format PCM_SIGNED, 44100.0 Hz, 16 bit, stereo, little-endian, audio data, and buffers of 22050 to 22050 bytes
    Audio not supported: interface TargetDataLine supporting format PCM_SIGNED, 44100.0 Hz, 16 bit, stereo, little-endian, audio data, and buffers of 22050 to 22050 bytes

    hi,
    I still dont understand well the jmf either, but i can confirm that i am able to capture audio (using javasound://8000) to capture at 8Khz, setting a processor model with this source, AudioFormat.DVI_RTP and ContentDescriptor.RAW_RTP
    and my transmition happens well:
    dvi/rtp, 8000.0 Hz, 4-bit, Mono
    I JUST CAN CONFIRM THAT JMF 2.1.1 DO SUPPORT DVI/RTP 8000.0 4BIT
    as per the documentation, a processor model requires:
    1. a datasource
    2. an imput audio format
    3. the output content description
    one will think then that the audio imput should be linear and the output should be div/rtp, but it seems it doesnt work like that, im digging on the docs with no success till now, so by experiments i can say that somehow the imput audio format, already tells the kind of coder one will use, that case, DVI/RTP. This means, the data is encoded to a special DVI format who prepare the packets to be Transmitted, and then on the output content one says, is data ready to be transmitted, since is already packetize you say just content is raw or raw_rtp.
    you can not for example say, then ok, convert my imput to a DVI and then packetize it to a (DVI)/RTP, because in this case you will have, starting from the capture device:
    LINEAR convert to DVI> DVI packetize> DVI_RTP -----> Tx
    why not? because there is no codec that receives DVI and convert it to DVI_RTP,
    the only one we got is com.ibm.media.codec.audio.dvi.JavaEncoder
    this one is only able to take linear and convert it to DVI/RTP
    so you have to use the model
    LINEAR ----> DVI/RTP -----> CONTENT = RAW ----> tx it, sink it, but not write...
    to write there are more problems, but that was not the question, just tx
    if someone can explain this better or point to a docs were it is explain it, ill appreciate,
    regards,
    jahm

  • 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.

  • 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...

  • Packet sniffer only picks up UDP and no RTP packets when using JMF???

    Hi,
    I am developing a voice mail application to interface with asterisk. Here is the problem.
    I am using ethereal packet sniffer to sniff the packets. When I connect two regular SIP phones and sniff , I can sniff the RTP packets.
    But when I use JMF AVtransmit2.java and AVReceive2.java I sniff only UDP packets and no RTP packets.
    I am very confused. What is going on? If JMF sends over RTP (that uses UDP underneath), then why cannot packet sniffers detect it.

    Hi,
    I am developing a voice mail application to interface with asterisk. Here is the problem.
    I am using ethereal packet sniffer to sniff the packets. When I connect two regular SIP phones and sniff , I can sniff the RTP packets.
    But when I use JMF AVtransmit2.java and AVReceive2.java I sniff only UDP packets and no RTP packets.
    I am very confused. What is going on? If JMF sends over RTP (that uses UDP underneath), then why cannot packet sniffers detect it.

  • 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.

  • 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

  • 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...

  • RVS4000 mangles RTP Packets

    I've come across a strange issue with a Cisco RVS4000 router, firmware      V2.0.2.7
    First of all, ALG is turned off in the router!  The RTP port range 10001-10999 is forwarded to the PBX internal IP.
    A PBX sitting behind NAT with ports forwarded establishes a given  incoming call with a SIP trunk provider.  Packet sniffs have shown the  PBX and Trunk agree on given IP's and port numbers in Session  Description Protocol for the conversation.  The PBX behaves as you would  expect, sending the audio from the agreed ports: PBX  PrivateIP/Port(10202) --> Trunk PublicIP/Port(53544).
    The strangeness sets in when the packets come out of the WAN side of  the router.  The call setup is identical however, the first 10 RTP  packets are changed to appear to come from a different port: PBX  PublicIP/Port(51062) --> Trunk PublicIP/Port(53544).
    The remaining RTP packets after the first 10 come from the correct  port: PBX PublicIP/Port(10202) --> Trunk PublicIP/Port(53544).
    The SIP trunk provider sends audio in the reverse direction: Trunk PublicIP/Port(53544) --> PBX  PublicIP/Port(51062)
    However, the incoming audio works and arrives at the PBX on port 10202 - therefore the router is obviously applying NAT to those packets.
    The result is that the SIP trunk provider ignore all RTP packets  after the first 10 (and thus one-way audio from the trunk to the PBX) because their system accepted the first 10 from the  "wrong" port and therefore ignores the remaining packets coming from the  "right" port.
    To make things even stranger, the router behaves properly on  subsequent calls.  The issue usually only appears after a long period  without incoming calls (> 30 min.)
    Business telephones in Calgary
    www.atcomsystems.ca

    I wish to put the time of my computer...or have you any other idea to generate timestamp?

  • 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 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.

  • 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.

Maybe you are looking for

  • Payment Terms fetch Issue(Plant Level) @ SRM 7.0

    Hello Experts, We are currently implementing SRM 7.0 system(Classical Scenario) across regions.In one such scenario we found out that when we create a PO directly in SRM the Payment Terms is fetched correctly from the Vendor Master at Plant Level(Byp

  • Problem calling XML Report Publisher from Oracle Reports

    Hi, I'm facing a problem in calling XML Report Publisher from Oracle Reports. Basically, I'm trying to customise Dunning Letter program. The program which is submitted calls another program. I have customised the second program and added a call to a

  • What's wrong with my AND??

    New to SQL, here's my code:<br><br> if ( :P2_FILE_NAME is not null ) then<br> insert into DBA_PATCH_LOG(REMEDY_PARENT, LINK, FILE_NAME, SUBJECT, TASK_NAME, BLOB_CONTENT, MIME_TYPE)<br> select <br>:P2_REMEDY_PARENT,id,:P2_FILE_NAME,:P2_SUBJECT,:P2_TAS

  • How much functionality in constructor?

    Hi Lets say I have a class 'schedule' which builds a schedule from a set of data and then holds that schedule for further processing. Which of these two options is better designed?: public class Schedule      public Schedule(SomeInputs inputs)       

  • Connecting to broadband network using blue tooth d...

    Is it possible to connect a N-93 or any N-series phone to broadband network of PC using bluetooth dongle installed in the P C. ? If yes how. If no why If my post has helped you please click the white star on the right