blob: 60149dbb70952f6cba3986101ea101f4939dd7d9 [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 */
Magnus Jedvert9060eb12017-12-12 12:52:54 +010016 public enum State {
17 LIVE,
18 ENDED;
19
20 @CalledByNative("State")
21 static State fromNativeIndex(int nativeIndex) {
22 return values()[nativeIndex];
23 }
24 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +000025
Magnus Jedvert4fa5da52017-11-27 13:44:38 +010026 // Must be kept in sync with cricket::MediaType.
zhihuangc4adabf2016-12-07 10:36:40 -080027 public enum MediaType {
Magnus Jedvert4fa5da52017-11-27 13:44:38 +010028 MEDIA_TYPE_AUDIO(0),
29 MEDIA_TYPE_VIDEO(1);
30
31 private final int nativeIndex;
32
33 private MediaType(int nativeIndex) {
34 this.nativeIndex = nativeIndex;
35 }
36
37 @CalledByNative("MediaType")
38 int getNative() {
39 return nativeIndex;
40 }
41
42 @CalledByNative("MediaType")
43 static MediaType fromNativeIndex(int nativeIndex) {
44 for (MediaType type : MediaType.values()) {
45 if (type.getNative() == nativeIndex) {
46 return type;
47 }
48 }
49 throw new IllegalArgumentException("Unknown native media type: " + nativeIndex);
50 }
zhihuangc4adabf2016-12-07 10:36:40 -080051 }
52
henrike@webrtc.org28e20752013-07-10 00:45:36 +000053 final long nativeTrack;
54
55 public MediaStreamTrack(long nativeTrack) {
56 this.nativeTrack = nativeTrack;
57 }
58
59 public String id() {
Magnus Jedvert4fa5da52017-11-27 13:44:38 +010060 return getNativeId(nativeTrack);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000061 }
62
63 public String kind() {
Magnus Jedvert4fa5da52017-11-27 13:44:38 +010064 return getNativeKind(nativeTrack);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000065 }
66
67 public boolean enabled() {
Magnus Jedvert4fa5da52017-11-27 13:44:38 +010068 return getNativeEnabled(nativeTrack);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000069 }
70
71 public boolean setEnabled(boolean enable) {
Magnus Jedvert4fa5da52017-11-27 13:44:38 +010072 return setNativeEnabled(nativeTrack, enable);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000073 }
74
75 public State state() {
Magnus Jedvert4fa5da52017-11-27 13:44:38 +010076 return getNativeState(nativeTrack);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000077 }
78
henrike@webrtc.org28e20752013-07-10 00:45:36 +000079 public void dispose() {
magjedb1c74532017-08-27 13:47:20 -070080 JniCommon.nativeReleaseRef(nativeTrack);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000081 }
82
Magnus Jedvert4fa5da52017-11-27 13:44:38 +010083 private static native String getNativeId(long nativeTrack);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000084
Magnus Jedvert4fa5da52017-11-27 13:44:38 +010085 private static native String getNativeKind(long nativeTrack);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000086
Magnus Jedvert4fa5da52017-11-27 13:44:38 +010087 private static native boolean getNativeEnabled(long nativeTrack);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000088
Magnus Jedvert4fa5da52017-11-27 13:44:38 +010089 private static native boolean setNativeEnabled(long nativeTrack, boolean enabled);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000090
Magnus Jedvert4fa5da52017-11-27 13:44:38 +010091 private static native State getNativeState(long nativeTrack);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000092}