×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Jul 2007
    Posts
    2

    DVI/RTP packets decoding

    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.

  2. #2
    Registered User
    Join Date
    May 2007
    Posts
    25

    Re: DVI/RTP packets decoding

    Its possible the problem is with decoding. Is there another way to test the same content, for example from a native unicast, or local file playback?

    Its interesting you implemented a multicast to unicast gateway, I ended up doing something along these lines for an N95 phone since the real player doesn't seem to deal with multicast or SDP

    Any idea why these workarounds are needed? I mean what about native multicast?

    /steverino2

  3. #3
    Registered User
    Join Date
    Jul 2007
    Posts
    2

    Re: DVI/RTP packets decoding

    Hi
    Thanks for your interest

    I hae managed to decode the file correctly in about I would say 80%
    I just switched the bytes into little endian and it worked

    I can hear the sound but I hear it a little pitched than the original and with brakes which I suppose they belong the beginning of the data of each packet which I insert into the buffer before playing it.

    Do you know why it is pitched?
    thanks

  4. #4
    Registered User
    Join Date
    May 2007
    Posts
    25

    Re: DVI/RTP packets decoding

    good progress. well I would think the audio might be pitched if the decoding speed was too fast.

    How about the video?

    One possible test would be to measure the total playback time for a known clip. if the actual playback matches the expected time then the play speed is OK. if it is too fast then the stream can be slowed down, etc.

Similar Threads

  1. QR code Decoding
    By kair_g in forum Symbian Media (Closed)
    Replies: 2
    Last Post: 2007-06-08, 06:53
  2. IP packets interceptions. Please help.
    By Svat_ in forum Symbian
    Replies: 8
    Last Post: 2007-02-15, 16:35
  3. Bluetooth - DM/DH packets
    By neo82 in forum Mobile Java General
    Replies: 1
    Last Post: 2006-04-25, 20:51
  4. How to receive RTP packets and depacktize it?
    By maodean in forum Mobile Java Media (Graphics & Sounds)
    Replies: 2
    Last Post: 2006-02-10, 00:17
  5. Sending multicast packets and link-local for N6600
    By carl_rocha in forum Symbian Networking & Messaging (Closed)
    Replies: 0
    Last Post: 2004-05-28, 11:56

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×