diff --git a/src/org/jitsi/impl/neomedia/MediaStreamImpl.java b/src/org/jitsi/impl/neomedia/MediaStreamImpl.java index 096d82c3e4029c0619b955466e4f5be958701a8d..7930488fcb3d1332f90f1d5dd8dfc83e403fdb2f 100644 --- a/src/org/jitsi/impl/neomedia/MediaStreamImpl.java +++ b/src/org/jitsi/impl/neomedia/MediaStreamImpl.java @@ -173,7 +173,7 @@ else if (MediaDeviceSession.SSRC_LIST.equals(propertyName)) /** * Our own SSRC identifier. */ - private long localSourceID = -1; + private long localSourceID = new Random().nextInt(); /** * The list of CSRC IDs contributing to the media that this @@ -250,7 +250,7 @@ else if (MediaDeviceSession.SSRC_LIST.equals(propertyName)) * instance will employ internal logic to generate new synchronization * source (SSRC) identifiers. */ - private SSRCFactory ssrcFactory; + private SSRCFactory ssrcFactory = new SSRCFactoryImpl(localSourceID); /** * Initializes a new <tt>MediaStreamImpl</tt> instance which will use the diff --git a/src/org/jitsi/impl/neomedia/SSRCFactoryImpl.java b/src/org/jitsi/impl/neomedia/SSRCFactoryImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..1de332a90750d93edaa975867d0dae0d80d33d69 --- /dev/null +++ b/src/org/jitsi/impl/neomedia/SSRCFactoryImpl.java @@ -0,0 +1,59 @@ +/* + * Jitsi, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package org.jitsi.impl.neomedia; + +import net.sf.fmj.media.rtp.*; +import org.jitsi.service.neomedia.*; + +import java.util.*; + +/** + * An <tt>SSRCFactory</tt> implementation which allows the first generated + * SSRC to be set by the user. + * + * @author Lyubomir Marinov + * @author Boris Grozev + */ +class SSRCFactoryImpl + implements SSRCFactory +{ + private int i = 0; + private long initialLocalSSRC = -1; + + /** + * The <tt>Random</tt> instance used by this <tt>SSRCFactory</tt> to + * generate new synchronization source (SSRC) identifiers. + */ + private final Random random = new Random(); + + public SSRCFactoryImpl(long initialLocalSSRC) + { + this.initialLocalSSRC = initialLocalSSRC; + } + + private int doGenerateSSRC() + { + return random.nextInt(); + } + + /** + * {@inheritDoc} + */ + @Override + public long generateSSRC(String cause) + { + if (initialLocalSSRC != -1) + { + if (i++ == 0) + return (int) initialLocalSSRC; + else if (cause.equals(GenerateSSRCCause.REMOVE_SEND_STREAM.name())) + return Long.MAX_VALUE; + } + return doGenerateSSRC(); + } +} +