Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7407973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:49:29+00:00 2026-05-29T05:49:29+00:00

I do some learning of using voip over udp in a small network. I

  • 0

I do some learning of using voip over udp in a small network. I know there are bundles of libraries ready to do and overdo everything I ever need with a few method calls, but as I said I am learning, so need to reinvent the wheel to see how it works.

I am currently investigating the DatagramPacket class and I’ve noticed that there is no method that would set header information(ie packet order sequence number which I need to know to do interleaving) in DatagramPacket class.

A little code to reflect the environment:

byte[] block;
DatagramPacket packet; // UDP packet                

/* x Bytes per block , y blocks per second,
   z ms time block playback duration */

block = recorder.getBlock(); // assume I have class that handles audio
                              // recording and returns speech in a
                              // uncompressed form of bytes

packet = new DatagramPacket(block, block.length, clientIP, PORT);

Firstly, I assume that because it is UDP, the sender doesnt really care anything whatsoever besides the simple fact that he throws packets somewhere. So that is why there is no such method inside.

Secondly, I assume that I need to do it myself – add extra bytes to the byte block to be sent , which would contain a sequence number of a packet? However am also concerned that if I do that, then how do I recognize if bytes are header bytes not audio bytes? I can make assumption that first byte represents a number, however we know that byte can only represent 258 numbers. I’ve never really worked on byte level before. Or there maybe other techniques?

Shortly saying, to do interleaving I need to know how to set up packet sequence number as I can’t order unordered packets 🙂

Thank You,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T05:49:30+00:00Added an answer on May 29, 2026 at 5:49 am

    You’ll need to serialize/deserialize data types your program uses onto a byte array.

    Lets assume you’re talking about RTP, and you’d want to send a packet with these fields – look at chapter 5 in the RTP specs:

    Version = 2
    padding = 0
    extension = 0
    CSRC count = 1
    marker = 0
    payload type = 8 (G711 alaw)
    sequence number = 1234
    timestamp = 1
    one CSRC = 4321

    Lets put these into some variables, using integers for ease, or long when we need to deal with an unsigned 32 bit value:

    int version = 2;
    int padding = 0;
    int extension = 0;
    int csrcCount = 1;
    int marker = 0;
    int payloadType = 8;
    int sequenceNumber = 1234;
    long timestamp = 1;
    long ourCsrc = 4321;
    
    byte buf[] = ...; //allocate this big enough to hold the RTP header + audio data
    
    //assemble the first bytes according to the RTP spec (note, the spec marks version as bit 0 and 1, but
    //this is really the high bits of the first byte ...
    buf[0] = (byte) ((version & 0x3) << 6 | (padding & 0x1) << 5 | (extension & 0x1) << 4 | (csrcCount & 0xf));
    
    //2.byte
    buf[1] = (byte)((marker & 0x1) << 7 | payloadType & 0x7f);
    
    //squence number, 2 bytes, in big endian format. So the MSB first, then the LSB.
    buf[2] = (byte)((sequenceNumber & 0xff00) >> 8);
    buf[3] = (byte)(sequenceNumber  & 0x00ff);
    
    //packet timestamp , 4 bytes in big endian format
    buf[4] = (byte)((timestamp & 0xff000000) >> 24);
    buf[5] = (byte)((timestamp & 0x00ff0000) >> 16);
    buf[6] = (byte)((timestamp & 0x0000ff00) >> 8);
    buf[7] = (byte) (timestamp & 0x000000ff);
    //our CSRC , 4 bytes in big endian format
    buf[ 8] = (byte)((sequenceNumber & 0xff000000) >> 24);
    buf[ 9] = (byte)((sequenceNumber & 0x00ff0000) >> 16);
    buf[10] = (byte)((sequenceNumber & 0x0000ff00) >> 8);
    buf[11] = (byte) (sequenceNumber & 0x000000ff);
    

    That’s the header, now you can copy the audio bytes into buf, starting at buf[12] and send buf as one packet.

    Now, the above is ofcourse just to show the principles, an actual serializer for a RTP packet would have to deal with much more, in accordance to the RTP specificaion (e.g. you might need some extension headers, you might need more than one CSRC, you need the correct payload type according to the format of the audio data you have, you need to packetize and schedule those audio data correctly – e.g. for G.711Alaw you’ll should fill each RTP packet with 160 bytes of audio data and send one packet every 20 milisecond.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Are there any PIC microcontroller programmers here? I'm learning some PIC microcontroller programming using
I'm learning jQuery and am about to write some pages using intensively that library.
I'm learning about SNMP, and writing some applications using it. I have some basic
I'm learning Ruby on Rails. I'm using some associations (has_many :through, ...) But i'm
I'm just learning how to do things, and want to start using some sort
I am using cakephp 1.26. I am doing some self-learning about Pagination in CakePHP.
I'm learning Objective-C using GNUstep, but i searched at Google for some example of
What could some of you recommend for using when learning C and programming with
I've been using objective C for a while now, and I've started learning some
I need to do some heavy machine learning computations. I have a small number

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.