Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Supportmultiplepayloads #3

Merged
merged 2 commits into from

2 participants

@vmarquez

I've changed the internal PayloadType field to be a HashSet instead of a single Int, and modified the constructors of the RtpSession classes to allow for take a generic Collection of payload types. We check the payloadtype against the set for incoming packets and if we're able to, set the payload according to the set for outgoing packets.

This passes all the tests and I can't think of any reason the changes would break existing code. It's working nicely for my scala Sip Server.

@mgodave mgodave merged commit 04f9bed into biasedbit:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
36 src/main/java/com/biasedbit/efflux/session/AbstractRtpSession.java
@@ -63,7 +63,10 @@
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
-
+import java.util.Collections;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Collection;
/**
* @author <a:mailto="bruno.carvalho@wit-software.com" />Bruno de Carvalho</a>
*/
@@ -90,7 +93,7 @@
// configuration --------------------------------------------------------------------------------------------------
protected final String id;
- protected final int payloadType;
+ protected final Set<Integer> payloadTypes = new HashSet<Integer>();
protected final HashedWheelTimer timer;
protected final OrderedMemoryAwareThreadPoolExecutor executor;
protected String host;
@@ -139,19 +142,26 @@ public AbstractRtpSession(String id, int payloadType, RtpParticipant local,
OrderedMemoryAwareThreadPoolExecutor executor) {
this(id, payloadType, local, null, executor);
}
-
+
public AbstractRtpSession(String id, int payloadType, RtpParticipant local, HashedWheelTimer timer,
+ OrderedMemoryAwareThreadPoolExecutor executor) {
+ this(id, Collections.singleton(payloadType), local, timer, executor);
+ }
+
+ public AbstractRtpSession(String id, Collection<Integer> payloadTypes , RtpParticipant local, HashedWheelTimer timer,
OrderedMemoryAwareThreadPoolExecutor executor) {
- if ((payloadType < 0) || (payloadType > 127)) {
- throw new IllegalArgumentException("PayloadType must be in range [0;127]");
- }
+ for (int payloadType : payloadTypes) {
+ if ((payloadType < 0) || (payloadType > 127)) {
+ throw new IllegalArgumentException("PayloadTypes must be in range [0;127]");
+ }
+ }
if (!local.isReceiver()) {
throw new IllegalArgumentException("Local participant must have its data & control addresses set");
}
this.id = id;
- this.payloadType = payloadType;
+ this.payloadTypes.addAll(payloadTypes);
this.localParticipant = local;
this.participantDatabase = this.createDatabase();
this.executor = executor;
@@ -192,8 +202,8 @@ public String getId() {
}
@Override
- public int getPayloadType() {
- return this.payloadType;
+ public Set<Integer> getPayloadType() {
+ return this.payloadTypes;
}
@Override
@@ -319,8 +329,10 @@ public boolean sendDataPacket(DataPacket packet) {
if (!this.running.get()) {
return false;
}
-
- packet.setPayloadType(this.payloadType);
+ if (!this.payloadTypes.contains(packet.getPayloadType()) && this.payloadTypes.size() == 1) {
+ packet.setPayloadType(this.payloadTypes.iterator().next());
+ }
+
packet.setSsrc(this.localParticipant.getSsrc());
packet.setSequenceNumber(this.sequence.incrementAndGet());
this.internalSendData(packet);
@@ -418,7 +430,7 @@ public void dataPacketReceived(SocketAddress origin, DataPacket packet) {
return;
}
- if (packet.getPayloadType() != this.payloadType) {
+ if (!this.payloadTypes.contains(packet.getPayloadType())) {
// Silently discard packets of wrong payload.
return;
}
View
6 src/main/java/com/biasedbit/efflux/session/MultiParticipantSession.java
@@ -22,6 +22,7 @@
import com.biasedbit.efflux.participant.RtpParticipant;
import org.jboss.netty.handler.execution.OrderedMemoryAwareThreadPoolExecutor;
import org.jboss.netty.util.HashedWheelTimer;
+import java.util.Collection;
/**
* A regular RTP session, as described in RFC3550.
@@ -52,6 +53,11 @@ public MultiParticipantSession(String id, int payloadType, RtpParticipant localP
HashedWheelTimer timer, OrderedMemoryAwareThreadPoolExecutor executor) {
super(id, payloadType, localParticipant, timer, executor);
}
+
+ public MultiParticipantSession(String id, Collection<Integer> payloadTypes, RtpParticipant localParticipant,
+ HashedWheelTimer timer, OrderedMemoryAwareThreadPoolExecutor executor) {
+ super(id, payloadTypes, localParticipant, timer, executor);
+ }
// AbstractRtpSession ---------------------------------------------------------------------------------------------
View
4 src/main/java/com/biasedbit/efflux/session/RtpSession.java
@@ -22,7 +22,7 @@
import com.biasedbit.efflux.packet.ControlPacket;
import com.biasedbit.efflux.packet.DataPacket;
import com.biasedbit.efflux.participant.RtpParticipant;
-
+import java.util.Set;
import java.util.Map;
/**
@@ -32,7 +32,7 @@
String getId();
- int getPayloadType();
+ Set<Integer> getPayloadType();
boolean init();
View
12 src/main/java/com/biasedbit/efflux/session/SingleParticipantSession.java
@@ -26,6 +26,8 @@
import org.jboss.netty.util.HashedWheelTimer;
import java.net.SocketAddress;
+import java.util.Collections;
+import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -80,11 +82,17 @@ public SingleParticipantSession(String id, int payloadType, RtpParticipant local
RtpParticipant remoteParticipant, HashedWheelTimer timer) {
this(id, payloadType, localParticipant, remoteParticipant, timer, null);
}
-
+
public SingleParticipantSession(String id, int payloadType, RtpParticipant localParticipant,
+ RtpParticipant remoteParticipant, HashedWheelTimer timer,
+ OrderedMemoryAwareThreadPoolExecutor executor) {
+ this(id, Collections.singleton(payloadType), localParticipant, remoteParticipant, timer, executor);
+ }
+
+ public SingleParticipantSession(String id, Collection<Integer> payloadTypes, RtpParticipant localParticipant,
RtpParticipant remoteParticipant, HashedWheelTimer timer,
OrderedMemoryAwareThreadPoolExecutor executor) {
- super(id, payloadType, localParticipant, timer, executor);
+ super(id, payloadTypes, localParticipant, timer, executor);
if (!remoteParticipant.isReceiver()) {
throw new IllegalArgumentException("Remote participant must be a receiver (data & control addresses set)");
}
Something went wrong with that request. Please try again.