net.sf.fmj.media.rtp
Class SSRCGenerator

java.lang.Object
  extended by net.sf.fmj.media.rtp.SSRCGenerator

public class SSRCGenerator
extends java.lang.Object

This class was written to generate different kinds of pseudo-random numbers, especially Synchronization SouRCes numbers (SSRC). An SSRC is a 32-bit numeric SSRC identifier carried in the RTP header so as not to be dependent upon the network address, and identifies the source of a stream of RTP packets. All packets from a synchronization source form part of the same timing and sequence number space. The RFC requests those numbers to be random enough to avoid synchronization of the PRNGs and a consequent collision of SSRCs. To avoid this problem, we generate the SSRC with an MD5 hash of information about the local participant. This class is also used as a normal pseudo-random number generator (PRNG) and uses SecureRandom to provide secure seeds to generate good series of random numbers.

Author:
Christian Vincenot

Constructor Summary
SSRCGenerator()
          Creates an instance of SSRC Generator.
 
Method Summary
 int generate()
          Generates a random integer using Math.random() to get a fast generation, but SecureRandom to give a good seed to Math.random() and garanties a good randomness.
 int generate(int salt)
          Generates a random integer using Math.random() to get a fast generation, but SecureRandom to give a good seed to Math.random() and garanties a good randomness.
static long getSecuredSeed()
          Generates a secured seed that can be used to initialize a PRNG (like Math.random).
static byte[] getSecuredSeed(int n)
          Generates a secured seed that can be used to initialize a PRNG (like Math.random).
static int nextSecuredRandomInt()
          Returns an integer generated in a very secure way.
static long nextSecuredRandomLong()
          Returns a long generated in a very secure way.
static short nextSecuredRandomShort()
          Returns a short integer generated in a very secure way.
 double random()
          Generates a random double between 0 and 1.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SSRCGenerator

public SSRCGenerator()
Creates an instance of SSRC Generator.

Method Detail

generate

public int generate()
Generates a random integer using Math.random() to get a fast generation, but SecureRandom to give a good seed to Math.random() and garanties a good randomness.

Returns:
a random integer

generate

public int generate(int salt)
Generates a random integer using Math.random() to get a fast generation, but SecureRandom to give a good seed to Math.random() and garanties a good randomness. Use this version when generating close successions of number.

Parameters:
salt - The "salt" argument is used if we have to generate several SSRCs in a very close succession (the hashs could be the same depending since the standard Random PRNG is time-based). This situation is very unlikely to happen.
Returns:
a random integer

getSecuredSeed

public static long getSecuredSeed()
Generates a secured seed that can be used to initialize a PRNG (like Math.random).

Returns:
a good seed

getSecuredSeed

public static byte[] getSecuredSeed(int n)
Generates a secured seed that can be used to initialize a PRNG (like Math.random). This version returns a seed generated on a space of n bytes.

Parameters:
n - number of bytes on which to generate the seed
Returns:
a good seed generated on a space of n bytes

nextSecuredRandomLong

public static long nextSecuredRandomLong()
Returns a long generated in a very secure way.

Returns:
a long generated in a very secure way

nextSecuredRandomInt

public static int nextSecuredRandomInt()
Returns an integer generated in a very secure way.

Returns:
an integer generated in a very secure way

nextSecuredRandomShort

public static short nextSecuredRandomShort()
Returns a short integer generated in a very secure way.

Returns:
a short integer generated in a very secure way

random

public double random()
Generates a random double between 0 and 1.

Returns:
a random double between 0 and 1