From ba5a33be581ce9969f63d4c97c43d47e29155fe8 Mon Sep 17 00:00:00 2001 From: Boris Grozev <boris@jitsi.org> Date: Sat, 12 Apr 2014 14:22:40 +0200 Subject: [PATCH] Make MediaStream generate an initial local SSRC before being started. --- .../jitsi/impl/neomedia/MediaStreamImpl.java | 4 +- .../jitsi/impl/neomedia/SSRCFactoryImpl.java | 59 +++++++++++++++++++ 2 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 src/org/jitsi/impl/neomedia/SSRCFactoryImpl.java diff --git a/src/org/jitsi/impl/neomedia/MediaStreamImpl.java b/src/org/jitsi/impl/neomedia/MediaStreamImpl.java index 096d82c3..7930488f 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 00000000..1de332a9 --- /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(); + } +} + -- GitLab