henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 2 | * Copyright 2013 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 4 | * 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.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | package org.webrtc; |
| 12 | |
| 13 | /** Java wrapper for a C++ MediaStreamTrackInterface. */ |
| 14 | public class MediaStreamTrack { |
| 15 | /** Tracks MediaStreamTrackInterface.TrackState */ |
Magnus Jedvert | 9060eb1 | 2017-12-12 12:52:54 +0100 | [diff] [blame^] | 16 | 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.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 25 | |
Magnus Jedvert | 4fa5da5 | 2017-11-27 13:44:38 +0100 | [diff] [blame] | 26 | // Must be kept in sync with cricket::MediaType. |
zhihuang | c4adabf | 2016-12-07 10:36:40 -0800 | [diff] [blame] | 27 | public enum MediaType { |
Magnus Jedvert | 4fa5da5 | 2017-11-27 13:44:38 +0100 | [diff] [blame] | 28 | 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 | } |
zhihuang | c4adabf | 2016-12-07 10:36:40 -0800 | [diff] [blame] | 51 | } |
| 52 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 53 | final long nativeTrack; |
| 54 | |
| 55 | public MediaStreamTrack(long nativeTrack) { |
| 56 | this.nativeTrack = nativeTrack; |
| 57 | } |
| 58 | |
| 59 | public String id() { |
Magnus Jedvert | 4fa5da5 | 2017-11-27 13:44:38 +0100 | [diff] [blame] | 60 | return getNativeId(nativeTrack); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | public String kind() { |
Magnus Jedvert | 4fa5da5 | 2017-11-27 13:44:38 +0100 | [diff] [blame] | 64 | return getNativeKind(nativeTrack); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | public boolean enabled() { |
Magnus Jedvert | 4fa5da5 | 2017-11-27 13:44:38 +0100 | [diff] [blame] | 68 | return getNativeEnabled(nativeTrack); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | public boolean setEnabled(boolean enable) { |
Magnus Jedvert | 4fa5da5 | 2017-11-27 13:44:38 +0100 | [diff] [blame] | 72 | return setNativeEnabled(nativeTrack, enable); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | public State state() { |
Magnus Jedvert | 4fa5da5 | 2017-11-27 13:44:38 +0100 | [diff] [blame] | 76 | return getNativeState(nativeTrack); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 77 | } |
| 78 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 79 | public void dispose() { |
magjed | b1c7453 | 2017-08-27 13:47:20 -0700 | [diff] [blame] | 80 | JniCommon.nativeReleaseRef(nativeTrack); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 81 | } |
| 82 | |
Magnus Jedvert | 4fa5da5 | 2017-11-27 13:44:38 +0100 | [diff] [blame] | 83 | private static native String getNativeId(long nativeTrack); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 84 | |
Magnus Jedvert | 4fa5da5 | 2017-11-27 13:44:38 +0100 | [diff] [blame] | 85 | private static native String getNativeKind(long nativeTrack); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 86 | |
Magnus Jedvert | 4fa5da5 | 2017-11-27 13:44:38 +0100 | [diff] [blame] | 87 | private static native boolean getNativeEnabled(long nativeTrack); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 88 | |
Magnus Jedvert | 4fa5da5 | 2017-11-27 13:44:38 +0100 | [diff] [blame] | 89 | private static native boolean setNativeEnabled(long nativeTrack, boolean enabled); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 90 | |
Magnus Jedvert | 4fa5da5 | 2017-11-27 13:44:38 +0100 | [diff] [blame] | 91 | private static native State getNativeState(long nativeTrack); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 92 | } |