123 lines
3.2 KiB
Java
123 lines
3.2 KiB
Java
|
package org.webrtc;
|
||
|
|
||
|
import androidx.annotation.Nullable;
|
||
|
import c.d.b.a.a;
|
||
|
public class MediaStreamTrack {
|
||
|
public static final String AUDIO_TRACK_KIND = "audio";
|
||
|
public static final String VIDEO_TRACK_KIND = "video";
|
||
|
private long nativeTrack;
|
||
|
|
||
|
public enum MediaType {
|
||
|
MEDIA_TYPE_AUDIO(0),
|
||
|
MEDIA_TYPE_VIDEO(1);
|
||
|
|
||
|
private final int nativeIndex;
|
||
|
|
||
|
private MediaType(int i) {
|
||
|
this.nativeIndex = i;
|
||
|
}
|
||
|
|
||
|
@CalledByNative("MediaType")
|
||
|
public static MediaType fromNativeIndex(int i) {
|
||
|
MediaType[] values = values();
|
||
|
for (int i2 = 0; i2 < 2; i2++) {
|
||
|
MediaType mediaType = values[i2];
|
||
|
if (mediaType.getNative() == i) {
|
||
|
return mediaType;
|
||
|
}
|
||
|
}
|
||
|
throw new IllegalArgumentException(a.j("Unknown native media type: ", i));
|
||
|
}
|
||
|
|
||
|
@CalledByNative("MediaType")
|
||
|
public int getNative() {
|
||
|
return this.nativeIndex;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public enum State {
|
||
|
LIVE,
|
||
|
ENDED;
|
||
|
|
||
|
@CalledByNative("State")
|
||
|
public static State fromNativeIndex(int i) {
|
||
|
return values()[i];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public MediaStreamTrack(long j) {
|
||
|
if (j != 0) {
|
||
|
this.nativeTrack = j;
|
||
|
return;
|
||
|
}
|
||
|
throw new IllegalArgumentException("nativeTrack may not be null");
|
||
|
}
|
||
|
|
||
|
private void checkMediaStreamTrackExists() {
|
||
|
if (this.nativeTrack == 0) {
|
||
|
throw new IllegalStateException("MediaStreamTrack has been disposed.");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@Nullable
|
||
|
public static MediaStreamTrack createMediaStreamTrack(long j) {
|
||
|
if (j == 0) {
|
||
|
return null;
|
||
|
}
|
||
|
String nativeGetKind = nativeGetKind(j);
|
||
|
if (nativeGetKind.equals("audio")) {
|
||
|
return new AudioTrack(j);
|
||
|
}
|
||
|
if (nativeGetKind.equals("video")) {
|
||
|
return new VideoTrack(j);
|
||
|
}
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
private static native boolean nativeGetEnabled(long j);
|
||
|
|
||
|
private static native String nativeGetId(long j);
|
||
|
|
||
|
private static native String nativeGetKind(long j);
|
||
|
|
||
|
private static native State nativeGetState(long j);
|
||
|
|
||
|
private static native boolean nativeSetEnabled(long j, boolean z2);
|
||
|
|
||
|
public void dispose() {
|
||
|
checkMediaStreamTrackExists();
|
||
|
JniCommon.nativeReleaseRef(this.nativeTrack);
|
||
|
this.nativeTrack = 0;
|
||
|
}
|
||
|
|
||
|
public boolean enabled() {
|
||
|
checkMediaStreamTrackExists();
|
||
|
return nativeGetEnabled(this.nativeTrack);
|
||
|
}
|
||
|
|
||
|
public long getNativeMediaStreamTrack() {
|
||
|
checkMediaStreamTrackExists();
|
||
|
return this.nativeTrack;
|
||
|
}
|
||
|
|
||
|
public String id() {
|
||
|
checkMediaStreamTrackExists();
|
||
|
return nativeGetId(this.nativeTrack);
|
||
|
}
|
||
|
|
||
|
public String kind() {
|
||
|
checkMediaStreamTrackExists();
|
||
|
return nativeGetKind(this.nativeTrack);
|
||
|
}
|
||
|
|
||
|
public boolean setEnabled(boolean z2) {
|
||
|
checkMediaStreamTrackExists();
|
||
|
return nativeSetEnabled(this.nativeTrack, z2);
|
||
|
}
|
||
|
|
||
|
public State state() {
|
||
|
checkMediaStreamTrackExists();
|
||
|
return nativeGetState(this.nativeTrack);
|
||
|
}
|
||
|
}
|