blob: 449ca75dbd1732049e93e1222eabbb5adbe00ae4 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2013 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00009 */
10
11package org.webrtc;
12
13/** Java wrapper for a C++ MediaStreamTrackInterface. */
Magnus Jedvert84d8ae52017-12-20 15:12:10 +010014@JNINamespace("webrtc::jni")
henrike@webrtc.org28e20752013-07-10 00:45:36 +000015public class MediaStreamTrack {
16 /** Tracks MediaStreamTrackInterface.TrackState */
Magnus Jedvert9060eb12017-12-12 12:52:54 +010017 public enum State {
18 LIVE,
19 ENDED;
20
21 @CalledByNative("State")
22 static State fromNativeIndex(int nativeIndex) {
23 return values()[nativeIndex];
24 }
25 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +000026
Magnus Jedvert4fa5da52017-11-27 13:44:38 +010027 // Must be kept in sync with cricket::MediaType.
zhihuangc4adabf2016-12-07 10:36:40 -080028 public enum MediaType {
Magnus Jedvert4fa5da52017-11-27 13:44:38 +010029 MEDIA_TYPE_AUDIO(0),
30 MEDIA_TYPE_VIDEO(1);
31
32 private final int nativeIndex;
33
34 private MediaType(int nativeIndex) {
35 this.nativeIndex = nativeIndex;
36 }
37
38 @CalledByNative("MediaType")
39 int getNative() {
40 return nativeIndex;
41 }
42
43 @CalledByNative("MediaType")
44 static MediaType fromNativeIndex(int nativeIndex) {
45 for (MediaType type : MediaType.values()) {
46 if (type.getNative() == nativeIndex) {
47 return type;
48 }
49 }
50 throw new IllegalArgumentException("Unknown native media type: " + nativeIndex);
51 }
zhihuangc4adabf2016-12-07 10:36:40 -080052 }
53
henrike@webrtc.org28e20752013-07-10 00:45:36 +000054 final long nativeTrack;
55
56 public MediaStreamTrack(long nativeTrack) {
57 this.nativeTrack = nativeTrack;
58 }
59
60 public String id() {
Magnus Jedvert84d8ae52017-12-20 15:12:10 +010061 return nativeGetId(nativeTrack);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000062 }
63
64 public String kind() {
Magnus Jedvert84d8ae52017-12-20 15:12:10 +010065 return nativeGetKind(nativeTrack);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000066 }
67
68 public boolean enabled() {
Magnus Jedvert84d8ae52017-12-20 15:12:10 +010069 return nativeGetEnabled(nativeTrack);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000070 }
71
72 public boolean setEnabled(boolean enable) {
Magnus Jedvert84d8ae52017-12-20 15:12:10 +010073 return nativeSetEnabled(nativeTrack, enable);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000074 }
75
76 public State state() {
Magnus Jedvert84d8ae52017-12-20 15:12:10 +010077 return nativeGetState(nativeTrack);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000078 }
79
henrike@webrtc.org28e20752013-07-10 00:45:36 +000080 public void dispose() {
magjedb1c74532017-08-27 13:47:20 -070081 JniCommon.nativeReleaseRef(nativeTrack);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000082 }
83
Magnus Jedvert84d8ae52017-12-20 15:12:10 +010084 private static native String nativeGetId(long track);
85 private static native String nativeGetKind(long track);
86 private static native boolean nativeGetEnabled(long track);
87 private static native boolean nativeSetEnabled(long track, boolean enabled);
88 private static native State nativeGetState(long track);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000089}