blob: b13ea9eafc7c407cbd758760980ab43fbb7b626a [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. */
14public class MediaStreamTrack {
15 /** Tracks MediaStreamTrackInterface.TrackState */
perkjc8f952d2016-03-23 00:33:56 -070016 public enum State { LIVE, ENDED }
henrike@webrtc.org28e20752013-07-10 00:45:36 +000017
Magnus Jedvert4fa5da52017-11-27 13:44:38 +010018 // Must be kept in sync with cricket::MediaType.
zhihuangc4adabf2016-12-07 10:36:40 -080019 public enum MediaType {
Magnus Jedvert4fa5da52017-11-27 13:44:38 +010020 MEDIA_TYPE_AUDIO(0),
21 MEDIA_TYPE_VIDEO(1);
22
23 private final int nativeIndex;
24
25 private MediaType(int nativeIndex) {
26 this.nativeIndex = nativeIndex;
27 }
28
29 @CalledByNative("MediaType")
30 int getNative() {
31 return nativeIndex;
32 }
33
34 @CalledByNative("MediaType")
35 static MediaType fromNativeIndex(int nativeIndex) {
36 for (MediaType type : MediaType.values()) {
37 if (type.getNative() == nativeIndex) {
38 return type;
39 }
40 }
41 throw new IllegalArgumentException("Unknown native media type: " + nativeIndex);
42 }
zhihuangc4adabf2016-12-07 10:36:40 -080043 }
44
henrike@webrtc.org28e20752013-07-10 00:45:36 +000045 final long nativeTrack;
46
47 public MediaStreamTrack(long nativeTrack) {
48 this.nativeTrack = nativeTrack;
49 }
50
51 public String id() {
Magnus Jedvert4fa5da52017-11-27 13:44:38 +010052 return getNativeId(nativeTrack);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000053 }
54
55 public String kind() {
Magnus Jedvert4fa5da52017-11-27 13:44:38 +010056 return getNativeKind(nativeTrack);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000057 }
58
59 public boolean enabled() {
Magnus Jedvert4fa5da52017-11-27 13:44:38 +010060 return getNativeEnabled(nativeTrack);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000061 }
62
63 public boolean setEnabled(boolean enable) {
Magnus Jedvert4fa5da52017-11-27 13:44:38 +010064 return setNativeEnabled(nativeTrack, enable);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000065 }
66
67 public State state() {
Magnus Jedvert4fa5da52017-11-27 13:44:38 +010068 return getNativeState(nativeTrack);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000069 }
70
henrike@webrtc.org28e20752013-07-10 00:45:36 +000071 public void dispose() {
magjedb1c74532017-08-27 13:47:20 -070072 JniCommon.nativeReleaseRef(nativeTrack);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000073 }
74
Magnus Jedvert4fa5da52017-11-27 13:44:38 +010075 private static native String getNativeId(long nativeTrack);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000076
Magnus Jedvert4fa5da52017-11-27 13:44:38 +010077 private static native String getNativeKind(long nativeTrack);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000078
Magnus Jedvert4fa5da52017-11-27 13:44:38 +010079 private static native boolean getNativeEnabled(long nativeTrack);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000080
Magnus Jedvert4fa5da52017-11-27 13:44:38 +010081 private static native boolean setNativeEnabled(long nativeTrack, boolean enabled);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000082
Magnus Jedvert4fa5da52017-11-27 13:44:38 +010083 private static native State getNativeState(long nativeTrack);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000084}