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. */ |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 14 | @JNINamespace("webrtc::jni") |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 15 | public class MediaStreamTrack { |
| 16 | /** Tracks MediaStreamTrackInterface.TrackState */ |
Magnus Jedvert | 9060eb1 | 2017-12-12 12:52:54 +0100 | [diff] [blame] | 17 | 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.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 26 | |
Magnus Jedvert | 4fa5da5 | 2017-11-27 13:44:38 +0100 | [diff] [blame] | 27 | // Must be kept in sync with cricket::MediaType. |
zhihuang | c4adabf | 2016-12-07 10:36:40 -0800 | [diff] [blame] | 28 | public enum MediaType { |
Magnus Jedvert | 4fa5da5 | 2017-11-27 13:44:38 +0100 | [diff] [blame] | 29 | 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 | } |
zhihuang | c4adabf | 2016-12-07 10:36:40 -0800 | [diff] [blame] | 52 | } |
| 53 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 54 | final long nativeTrack; |
| 55 | |
| 56 | public MediaStreamTrack(long nativeTrack) { |
| 57 | this.nativeTrack = nativeTrack; |
| 58 | } |
| 59 | |
| 60 | public String id() { |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 61 | return nativeGetId(nativeTrack); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | public String kind() { |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 65 | return nativeGetKind(nativeTrack); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | public boolean enabled() { |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 69 | return nativeGetEnabled(nativeTrack); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | public boolean setEnabled(boolean enable) { |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 73 | return nativeSetEnabled(nativeTrack, enable); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | public State state() { |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 77 | return nativeGetState(nativeTrack); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 78 | } |
| 79 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 80 | public void dispose() { |
magjed | b1c7453 | 2017-08-27 13:47:20 -0700 | [diff] [blame] | 81 | JniCommon.nativeReleaseRef(nativeTrack); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 82 | } |
| 83 | |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 84 | 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.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 89 | } |