2015-10-06 12:29:25 -07:00
|
|
|
/*
|
2016-02-10 07:54:43 -08:00
|
|
|
* Copyright 2015 The WebRTC project authors. All Rights Reserved.
|
2015-10-06 12:29:25 -07:00
|
|
|
*
|
2016-02-10 07:54:43 -08:00
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
2015-10-06 12:29:25 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package org.webrtc;
|
|
|
|
|
|
|
|
|
|
/** Java wrapper for a C++ RtpSenderInterface. */
|
2017-12-20 15:12:10 +01:00
|
|
|
@JNINamespace("webrtc::jni")
|
2015-10-06 12:29:25 -07:00
|
|
|
public class RtpSender {
|
|
|
|
|
final long nativeRtpSender;
|
|
|
|
|
|
|
|
|
|
private MediaStreamTrack cachedTrack;
|
2016-01-07 15:11:25 -08:00
|
|
|
private boolean ownsTrack = true;
|
2015-10-06 12:29:25 -07:00
|
|
|
|
2017-02-01 21:53:09 -08:00
|
|
|
private final DtmfSender dtmfSender;
|
|
|
|
|
|
2017-12-07 14:07:20 +01:00
|
|
|
@CalledByNative
|
2015-10-06 12:29:25 -07:00
|
|
|
public RtpSender(long nativeRtpSender) {
|
|
|
|
|
this.nativeRtpSender = nativeRtpSender;
|
2017-12-20 15:12:10 +01:00
|
|
|
long track = nativeGetTrack(nativeRtpSender);
|
2015-10-06 12:29:25 -07:00
|
|
|
// It may be possible for an RtpSender to be created without a track.
|
2017-02-01 21:53:09 -08:00
|
|
|
cachedTrack = (track != 0) ? new MediaStreamTrack(track) : null;
|
|
|
|
|
|
2017-12-20 15:12:10 +01:00
|
|
|
long nativeDtmfSender = nativeGetDtmfSender(nativeRtpSender);
|
2017-02-01 21:53:09 -08:00
|
|
|
dtmfSender = (nativeDtmfSender != 0) ? new DtmfSender(nativeDtmfSender) : null;
|
2015-10-06 12:29:25 -07:00
|
|
|
}
|
|
|
|
|
|
2017-08-09 08:40:10 -07:00
|
|
|
/**
|
|
|
|
|
* Starts sending a new track, without requiring additional SDP negotiation.
|
|
|
|
|
* <p>
|
|
|
|
|
* Note: This is equivalent to replaceTrack in the official WebRTC API. It
|
|
|
|
|
* was just implemented before the standards group settled on a name.
|
|
|
|
|
*
|
|
|
|
|
* @param takeOwnership If true, the RtpSender takes ownership of the track
|
|
|
|
|
* from the caller, and will auto-dispose of it when no
|
|
|
|
|
* longer needed. |takeOwnership| should only be used if
|
|
|
|
|
* the caller owns the track; it is not appropriate when
|
|
|
|
|
* the track is owned by, for example, another RtpSender
|
|
|
|
|
* or a MediaStream.
|
|
|
|
|
* @return true on success and false on failure.
|
|
|
|
|
*/
|
2016-01-07 15:11:25 -08:00
|
|
|
public boolean setTrack(MediaStreamTrack track, boolean takeOwnership) {
|
2017-12-20 15:12:10 +01:00
|
|
|
if (!nativeSetTrack(nativeRtpSender, (track == null) ? 0 : track.nativeTrack)) {
|
2016-01-07 15:11:25 -08:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (cachedTrack != null && ownsTrack) {
|
2015-10-06 12:29:25 -07:00
|
|
|
cachedTrack.dispose();
|
|
|
|
|
}
|
|
|
|
|
cachedTrack = track;
|
2016-01-07 15:11:25 -08:00
|
|
|
ownsTrack = takeOwnership;
|
|
|
|
|
return true;
|
2015-10-06 12:29:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public MediaStreamTrack track() {
|
|
|
|
|
return cachedTrack;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-24 19:36:46 -07:00
|
|
|
public boolean setParameters(RtpParameters parameters) {
|
2017-12-20 15:12:10 +01:00
|
|
|
return nativeSetParameters(nativeRtpSender, parameters);
|
2016-03-24 19:36:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public RtpParameters getParameters() {
|
2017-12-20 15:12:10 +01:00
|
|
|
return nativeGetParameters(nativeRtpSender);
|
2016-03-24 19:36:46 -07:00
|
|
|
}
|
|
|
|
|
|
2015-10-06 12:29:25 -07:00
|
|
|
public String id() {
|
2017-12-20 15:12:10 +01:00
|
|
|
return nativeGetId(nativeRtpSender);
|
2015-10-06 12:29:25 -07:00
|
|
|
}
|
|
|
|
|
|
2017-02-01 21:53:09 -08:00
|
|
|
public DtmfSender dtmf() {
|
|
|
|
|
return dtmfSender;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-06 12:29:25 -07:00
|
|
|
public void dispose() {
|
2017-02-01 21:53:09 -08:00
|
|
|
if (dtmfSender != null) {
|
|
|
|
|
dtmfSender.dispose();
|
|
|
|
|
}
|
2016-01-07 15:11:25 -08:00
|
|
|
if (cachedTrack != null && ownsTrack) {
|
2015-10-06 12:29:25 -07:00
|
|
|
cachedTrack.dispose();
|
|
|
|
|
}
|
2017-08-27 13:47:20 -07:00
|
|
|
JniCommon.nativeReleaseRef(nativeRtpSender);
|
2015-10-06 12:29:25 -07:00
|
|
|
}
|
|
|
|
|
|
2017-12-20 15:12:10 +01:00
|
|
|
private static native boolean nativeSetTrack(long rtpSender, long nativeTrack);
|
2015-10-06 12:29:25 -07:00
|
|
|
|
|
|
|
|
// This should increment the reference count of the track.
|
|
|
|
|
// Will be released in dispose() or setTrack().
|
2017-12-20 15:12:10 +01:00
|
|
|
private static native long nativeGetTrack(long rtpSender);
|
2015-10-06 12:29:25 -07:00
|
|
|
|
2017-02-01 21:53:09 -08:00
|
|
|
// This should increment the reference count of the DTMF sender.
|
|
|
|
|
// Will be released in dispose().
|
2017-12-20 15:12:10 +01:00
|
|
|
private static native long nativeGetDtmfSender(long rtpSender);
|
2017-02-01 21:53:09 -08:00
|
|
|
|
2017-12-20 15:12:10 +01:00
|
|
|
private static native boolean nativeSetParameters(long rtpSender, RtpParameters parameters);
|
2016-03-24 19:36:46 -07:00
|
|
|
|
2017-12-20 15:12:10 +01:00
|
|
|
private static native RtpParameters nativeGetParameters(long rtpSender);
|
2016-03-24 19:36:46 -07:00
|
|
|
|
2017-12-20 15:12:10 +01:00
|
|
|
private static native String nativeGetId(long rtpSender);
|
2015-10-06 12:29:25 -07:00
|
|
|
};
|