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 */ |
perkj | c8f952d | 2016-03-23 00:33:56 -0700 | [diff] [blame] | 16 | public enum State { LIVE, ENDED } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 17 | |
Magnus Jedvert | 4fa5da5 | 2017-11-27 13:44:38 +0100 | [diff] [blame] | 18 | // Must be kept in sync with cricket::MediaType. |
zhihuang | c4adabf | 2016-12-07 10:36:40 -0800 | [diff] [blame] | 19 | public enum MediaType { |
Magnus Jedvert | 4fa5da5 | 2017-11-27 13:44:38 +0100 | [diff] [blame] | 20 | 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 | } |
zhihuang | c4adabf | 2016-12-07 10:36:40 -0800 | [diff] [blame] | 43 | } |
| 44 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 45 | final long nativeTrack; |
| 46 | |
| 47 | public MediaStreamTrack(long nativeTrack) { |
| 48 | this.nativeTrack = nativeTrack; |
| 49 | } |
| 50 | |
| 51 | public String id() { |
Magnus Jedvert | 4fa5da5 | 2017-11-27 13:44:38 +0100 | [diff] [blame] | 52 | return getNativeId(nativeTrack); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | public String kind() { |
Magnus Jedvert | 4fa5da5 | 2017-11-27 13:44:38 +0100 | [diff] [blame] | 56 | return getNativeKind(nativeTrack); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | public boolean enabled() { |
Magnus Jedvert | 4fa5da5 | 2017-11-27 13:44:38 +0100 | [diff] [blame] | 60 | return getNativeEnabled(nativeTrack); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | public boolean setEnabled(boolean enable) { |
Magnus Jedvert | 4fa5da5 | 2017-11-27 13:44:38 +0100 | [diff] [blame] | 64 | return setNativeEnabled(nativeTrack, enable); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | public State state() { |
Magnus Jedvert | 4fa5da5 | 2017-11-27 13:44:38 +0100 | [diff] [blame] | 68 | return getNativeState(nativeTrack); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 69 | } |
| 70 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 71 | public void dispose() { |
magjed | b1c7453 | 2017-08-27 13:47:20 -0700 | [diff] [blame] | 72 | JniCommon.nativeReleaseRef(nativeTrack); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 73 | } |
| 74 | |
Magnus Jedvert | 4fa5da5 | 2017-11-27 13:44:38 +0100 | [diff] [blame] | 75 | private static native String getNativeId(long nativeTrack); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 76 | |
Magnus Jedvert | 4fa5da5 | 2017-11-27 13:44:38 +0100 | [diff] [blame] | 77 | private static native String getNativeKind(long nativeTrack); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 78 | |
Magnus Jedvert | 4fa5da5 | 2017-11-27 13:44:38 +0100 | [diff] [blame] | 79 | private static native boolean getNativeEnabled(long nativeTrack); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 80 | |
Magnus Jedvert | 4fa5da5 | 2017-11-27 13:44:38 +0100 | [diff] [blame] | 81 | private static native boolean setNativeEnabled(long nativeTrack, boolean enabled); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 82 | |
Magnus Jedvert | 4fa5da5 | 2017-11-27 13:44:38 +0100 | [diff] [blame] | 83 | private static native State getNativeState(long nativeTrack); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 84 | } |