Throw IllegalStateException if native objects are used after dispose.

This makes it easier to debug issues related to double dispose /
use after dispose.

Bug: webrtc:7566, webrtc:8297
Change-Id: I07429b2b794deabb62b5f3ea1cf92eea6f66a149
Reviewed-on: https://webrtc-review.googlesource.com/102540
Commit-Queue: Sami Kalliomäki <sakal@webrtc.org>
Reviewed-by: Paulina Hensman <phensman@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#24894}
This commit is contained in:
Sami Kalliomäki
2018-09-28 14:38:21 +02:00
committed by Commit Bot
parent dca5a2ca73
commit ee05e90297
15 changed files with 213 additions and 35 deletions

View File

@ -13,7 +13,6 @@ package org.webrtc;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.webrtc.RtpParameters.Encoding;
/**
* Java wrapper for a C++ RtpTransceiverInterface.
@ -96,7 +95,7 @@ public class RtpTransceiver {
}
}
private final long nativeRtpTransceiver;
private long nativeRtpTransceiver;
private RtpSender cachedSender;
private RtpReceiver cachedReceiver;
@ -112,6 +111,7 @@ public class RtpTransceiver {
* type as well.
*/
public MediaStreamTrack.MediaType getMediaType() {
checkRtpTransceiverExists();
return nativeGetMediaType(nativeRtpTransceiver);
}
@ -122,6 +122,7 @@ public class RtpTransceiver {
* https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-mid
*/
public String getMid() {
checkRtpTransceiverExists();
return nativeGetMid(nativeRtpTransceiver);
}
@ -153,6 +154,7 @@ public class RtpTransceiver {
* https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-stopped
*/
public boolean isStopped() {
checkRtpTransceiverExists();
return nativeStopped(nativeRtpTransceiver);
}
@ -162,6 +164,7 @@ public class RtpTransceiver {
* https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-direction
*/
public RtpTransceiverDirection getDirection() {
checkRtpTransceiverExists();
return nativeDirection(nativeRtpTransceiver);
}
@ -172,6 +175,7 @@ public class RtpTransceiver {
* https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-currentdirection
*/
public RtpTransceiverDirection getCurrentDirection() {
checkRtpTransceiverExists();
return nativeCurrentDirection(nativeRtpTransceiver);
}
@ -183,6 +187,7 @@ public class RtpTransceiver {
* https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-direction
*/
public void setDirection(RtpTransceiverDirection rtpTransceiverDirection) {
checkRtpTransceiverExists();
nativeSetDirection(nativeRtpTransceiver, rtpTransceiverDirection);
}
@ -192,14 +197,23 @@ public class RtpTransceiver {
* https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-stop
*/
public void stop() {
checkRtpTransceiverExists();
nativeStop(nativeRtpTransceiver);
}
@CalledByNative
public void dispose() {
checkRtpTransceiverExists();
cachedSender.dispose();
cachedReceiver.dispose();
JniCommon.nativeReleaseRef(nativeRtpTransceiver);
nativeRtpTransceiver = 0;
}
private void checkRtpTransceiverExists() {
if (nativeRtpTransceiver == 0) {
throw new IllegalStateException("RtpTransceiver has been disposed.");
}
}
private static native MediaStreamTrack.MediaType nativeGetMediaType(long rtpTransceiver);