Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions bootstrap/src/main/config/mediaserver.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,19 @@
MA 02110-1301 USA, or see the FSF site: http://www.fsf.org. -->
<mediaserver>
<network>
<!-- address where the server will be bound to for (S)RTP/WebRTC traffic-->
<bindAddress>127.0.0.1</bindAddress>
<!-- Address used for SDP oferrs. If this field is empty, then bind Address is used instead. Note server will not bind to this address-->
<externalAddress>127.0.0.1</externalAddress>
<!-- Address used for WebRTC - only sessions in SDP. Note that server will not bind to this address. If this is not set, then bindAddress is used instead -->
<webRtcAddress>127.0.0.1</webRtcAddress>
<network>127.0.0.1</network>
<subnet>255.255.255.255</subnet>
<sbc>false</sbc>
</network>

<controller protocol="mgcp">
<!-- Address where the MGCP stack will be bound to-->
<address>127.0.0.1</address>
<port>2427</port>
<endpoints>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public MediaServerConfiguration load(String filepath) {
private static void configureNetwork(HierarchicalConfiguration<ImmutableNode> src, NetworkConfiguration dst) {
dst.setBindAddress(src.getString("bindAddress", NetworkConfiguration.BIND_ADDRESS));
dst.setExternalAddress(src.getString("externalAddress", NetworkConfiguration.EXTERNAL_ADDRESS));
dst.setWebRTCAddress(src.getString("webRtcAddress", NetworkConfiguration.WEB_RTC_ADDRESS));
dst.setNetwork(src.getString("network", NetworkConfiguration.NETWORK));
dst.setSubnet(src.getString("subnet", NetworkConfiguration.SUBNET));
dst.setSbc(src.getBoolean("sbc", NetworkConfiguration.SBC));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public UdpManager get() {
udpManager.setBindAddress(config.getNetworkConfiguration().getBindAddress());
udpManager.setLocalBindAddress(config.getControllerConfiguration().getAddress());
udpManager.setExternalAddress(config.getNetworkConfiguration().getExternalAddress());
udpManager.setWebRTCAddress(config.getNetworkConfiguration().getWebRTCAddress());
udpManager.setLocalNetwork(config.getNetworkConfiguration().getNetwork());
udpManager.setLocalSubnet(config.getNetworkConfiguration().getSubnet());
udpManager.setUseSbc(config.getNetworkConfiguration().isSbc());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,12 @@ private void setOtherPartyInboundCall() throws IOException {
setupAudioChannelInbound(remoteAudio);
}

boolean isWebRtc = this.remoteSdp.containsIce();

// Generate SDP answer
String bindAddress = this.local ? this.channelsManager
.getLocalBindAddress() : this.channelsManager.getBindAddress();
String externalAddress = this.channelsManager.getUdpManager()
.getExternalAddress();
String externalAddress = isWebRtc ? this.channelsManager.getUdpManager().getWebRTCAddress() : this.channelsManager.getUdpManager().getExternalAddress();
if (this.audioChannel.isOpen()) {
this.localSdp = SdpFactory.buildSdp(false, bindAddress, externalAddress,
this.audioChannel);
Expand Down Expand Up @@ -420,9 +421,8 @@ public void generateOffer(boolean webrtc) throws IOException {
}

// generate SDP offer based on audio channel
String bindAddress = this.local ? this.channelsManager.getLocalBindAddress() : this.channelsManager
.getBindAddress();
String externalAddress = this.channelsManager.getUdpManager().getExternalAddress();
String bindAddress = this.local ? this.channelsManager.getLocalBindAddress() : this.channelsManager.getBindAddress();
String externalAddress = webrtc ? this.channelsManager.getUdpManager().getWebRTCAddress() : this.channelsManager.getUdpManager().getExternalAddress();
this.localSdp = SdpFactory.buildSdp(true, bindAddress, externalAddress, this.audioChannel);
this.remoteSdp = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public long perform() {
} catch (UnknownPackageException e) {
throw new MgcpCommandException(MgcpResponseCode.CAN_NOT_DETECT_EVENT, new Text(e.getMessage()));
} catch (Exception e) {
e.printStackTrace();
logger.error("Unexpected Exception while performing notification request CMD: " + request.toString(), e);
throw new MgcpCommandException(MgcpResponseCode.TRANSIENT_ERROR, new Text(e.getMessage()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ public class NetworkConfiguration {

public static final String BIND_ADDRESS = "127.0.0.1";
public static final String EXTERNAL_ADDRESS = "";
public static final String WEB_RTC_ADDRESS = "";
public static final String NETWORK = "127.0.0.1";
public static final String SUBNET = "255.255.255.255";
public static final boolean SBC = false;

private String bindAddress;
private String externalAddress;
private String webRTCAddress;
private String network;
private String subnet;
private boolean sbc;
Expand Down Expand Up @@ -98,4 +100,11 @@ public void setSbc(boolean sbc) {
this.sbc = sbc;
}

public String getWebRTCAddress() {
return webRTCAddress;
}

public void setWebRTCAddress(String webRTCAddress) {
this.webRTCAddress = webRTCAddress;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public class UdpManager {
private String bindAddress;
private String localBindAddress;
private String externalAddress;
private String webRTCAddress;

private byte[] localNetwork;
private IPAddressType currNetworkType;
Expand Down Expand Up @@ -156,6 +157,15 @@ public void setExternalAddress(String externalAddress) {
this.externalAddress = externalAddress;
}

/** gets and sets address used in WebRTC **/
public String getWebRTCAddress() {
return webRTCAddress;
}

public void setWebRTCAddress(String webRTCAddress) {
this.webRTCAddress = webRTCAddress;
}

/**
* Modify rtp timeout.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,10 @@ public String getExternalAddress() {
return this.udpManager.getExternalAddress();
}

public String getWebRTCAddress() {
return this.udpManager.getWebRTCAddress();
}

public boolean hasExternalAddress() {
return notEmpty(this.udpManager.getExternalAddress());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,17 @@ public String getExternalAddress() {
}
return "";
}

public String getWebRTCAddress() {
if (this.rtpChannel.isBound()) {
if (this.rtpChannel.getWebRTCAddress() != null && !this.rtpChannel.getWebRTCAddress().isEmpty()) {
return this.rtpChannel.getWebRTCAddress();
} else {
return this.rtpChannel.getExternalAddress();
}
}
return "";
}

/**
* Gets the address the RTP channel is bound to.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static SessionDescription buildSdp(boolean offer, String localAddress, St
// Media Descriptions
boolean ice = false;
for (MediaChannel channel : channels) {
MediaDescriptionField md = buildMediaDescription(channel, offer);
MediaDescriptionField md = buildMediaDescription(channel, offer, originAddress);
md.setSession(sd);
sd.addMediaDescription(md);

Expand Down Expand Up @@ -122,17 +122,16 @@ public static void rejectMediaField(SessionDescription answer, MediaDescriptionF
* The channel to read information from
* @return The SDP media description
*/
public static MediaDescriptionField buildMediaDescription(MediaChannel channel, boolean offer) {
public static MediaDescriptionField buildMediaDescription(MediaChannel channel, boolean offer, String originAddress) {
MediaDescriptionField md = new MediaDescriptionField();

md.setMedia(channel.getMediaType());
md.setPort(channel.getRtpPort());
MediaProfile profile = channel.isDtlsEnabled() ? MediaProfile.RTP_SAVPF : MediaProfile.RTP_AVP;
md.setProtocol(profile.getProfile());
final String externalAddress = channel.getExternalAddress() == null || channel.getExternalAddress().isEmpty() ? null : channel.getExternalAddress();
md.setConnection(new ConnectionField("IN", "IP4", externalAddress != null ? externalAddress : channel.getRtpAddress()));
md.setConnection(new ConnectionField("IN", "IP4", originAddress));
md.setPtime(new PacketTimeAttribute(20));
md.setRtcp(new RtcpAttribute(channel.getRtcpPort(), "IN", "IP4", externalAddress != null ? externalAddress : channel.getRtcpAddress()));
md.setRtcp(new RtcpAttribute(channel.getRtcpPort(), "IN", "IP4", originAddress));
if (channel.isRtcpMux()) {
md.setRtcpMux(new RtcpMuxAttribute());
}
Expand All @@ -143,12 +142,12 @@ public static MediaDescriptionField buildMediaDescription(MediaChannel channel,
md.setIcePwd(new IcePwdAttribute(channel.getIcePwd()));

// Fix connection address based on default (only) candidate
md.getConnection().setAddress(externalAddress != null ? externalAddress : channel.getRtpAddress());
md.getConnection().setAddress(originAddress);
md.setPort(channel.getRtpPort());

// Fix RTCP if rtcp-mux is used
if(channel.isRtcpMux()) {
md.getRtcp().setAddress(externalAddress != null ? externalAddress : channel.getRtpAddress());
md.getRtcp().setAddress(originAddress);
md.getRtcp().setPort(channel.getRtpPort());
}

Expand All @@ -157,13 +156,13 @@ public static MediaDescriptionField buildMediaDescription(MediaChannel channel,
if(!channel.isRtcpMux()) {
md.addCandidate(processHostCandidate(channel, IceComponent.RTCP_ID));
}
if(channel.getExternalAddress() != null && !channel.getExternalAddress().isEmpty()) {
// Add SRFLX candidate
md.addCandidate(processSrflxCandidate(channel, IceComponent.RTP_ID));
if(!channel.isRtcpMux()) {
md.addCandidate(processSrflxCandidate(channel, IceComponent.RTCP_ID));
}

if(channel.getWebRTCAddress() != null && !channel.getWebRTCAddress().isEmpty()) {
// Add SRFLX candidate from WebRTC address
md.addCandidate(processSrflxCandidate(channel, IceComponent.RTP_ID));
if(!channel.isRtcpMux()) {
md.addCandidate(processSrflxCandidate(channel, IceComponent.RTCP_ID));
}
}

// List<LocalCandidateWrapper> rtpCandidates = channel.getRtpCandidates();
Expand Down Expand Up @@ -300,7 +299,7 @@ private static CandidateAttribute processHostCandidate(MediaChannel candidate, s
private static CandidateAttribute processSrflxCandidate(MediaChannel candidate, short componentId) {
CandidateAttribute candidateSdp = processHostCandidate(candidate, componentId);
candidateSdp.setCandidateType(CandidateAttribute.TYP_SRFLX);
candidateSdp.setAddress(candidate.getExternalAddress());
candidateSdp.setAddress(candidate.getWebRTCAddress());

switch (componentId) {
case IceComponent.RTP_ID:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void testSipCallNonRtcpMux() throws IllegalStateException, IOException, I
String localAddress = localChannel.rtpChannel.getLocalHost();
int localRtpPort = localChannel.rtpChannel.getLocalPort();
int localRtcpPort = localChannel.rtcpChannel.getLocalPort();
MediaDescriptionField audioOffer = SdpFactory.buildMediaDescription(localChannel, true);
MediaDescriptionField audioOffer = SdpFactory.buildMediaDescription(localChannel, true, localAddress);

// activate "remote" channel and bind it to local address
// there will be two underlying channels for RTP and RTCP
Expand All @@ -114,7 +114,7 @@ public void testSipCallNonRtcpMux() throws IllegalStateException, IOException, I
String remoteAddress = remoteChannel.rtpChannel.getLocalHost();
int remoteRtpPort = remoteChannel.rtpChannel.getLocalPort();
int remoteRtcpPort = remoteChannel.rtcpChannel.getLocalPort();
MediaDescriptionField audioAnswer = SdpFactory.buildMediaDescription(remoteChannel, false);
MediaDescriptionField audioAnswer = SdpFactory.buildMediaDescription(remoteChannel, false, localAddress);

// ... remote peer receives SDP offer from local peer
// negotiate codecs with local peer
Expand Down Expand Up @@ -163,7 +163,7 @@ public void testSipCallWithRtcpMux() throws IllegalStateException, IOException,

String localAddress = localChannel.rtpChannel.getLocalHost();
int localPort = localChannel.rtpChannel.getLocalPort();
MediaDescriptionField audioOffer = SdpFactory.buildMediaDescription(localChannel, true);
MediaDescriptionField audioOffer = SdpFactory.buildMediaDescription(localChannel, true, localAddress);

// activate "remote" channel and bind it to local address
// there will be two underlying channels for RTP and RTCP
Expand All @@ -172,7 +172,7 @@ public void testSipCallWithRtcpMux() throws IllegalStateException, IOException,

String remoteAddress = remoteChannel.rtpChannel.getLocalHost();
int remotePort = remoteChannel.rtpChannel.getLocalPort();
MediaDescriptionField audioAnswer = SdpFactory.buildMediaDescription(remoteChannel, false);
MediaDescriptionField audioAnswer = SdpFactory.buildMediaDescription(remoteChannel, false, localAddress);

// ... remote peer receives SDP offer from local peer
// negotiate codecs with local peer
Expand Down