1 /* 2 * libjingle 3 * Copyright 2013 Google Inc. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, 9 * this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright notice, 11 * this list of conditions and the following disclaimer in the documentation 12 * and/or other materials provided with the distribution. 13 * 3. The name of the author may not be used to endorse or promote products 14 * derived from this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28 package org.webrtc; 29 30 /** Java wrapper for a C++ MediaStreamTrackInterface. */ 31 public class MediaStreamTrack { 32 /** Tracks MediaStreamTrackInterface.TrackState */ 33 public enum State { 34 INITIALIZING, LIVE, ENDED, FAILED 35 } 36 37 final long nativeTrack; 38 MediaStreamTrack(long nativeTrack)39 public MediaStreamTrack(long nativeTrack) { 40 this.nativeTrack = nativeTrack; 41 } 42 id()43 public String id() { 44 return nativeId(nativeTrack); 45 } 46 kind()47 public String kind() { 48 return nativeKind(nativeTrack); 49 } 50 enabled()51 public boolean enabled() { 52 return nativeEnabled(nativeTrack); 53 } 54 setEnabled(boolean enable)55 public boolean setEnabled(boolean enable) { 56 return nativeSetEnabled(nativeTrack, enable); 57 } 58 state()59 public State state() { 60 return nativeState(nativeTrack); 61 } 62 setState(State newState)63 public boolean setState(State newState) { 64 return nativeSetState(nativeTrack, newState.ordinal()); 65 } 66 dispose()67 public void dispose() { 68 free(nativeTrack); 69 } 70 nativeId(long nativeTrack)71 private static native String nativeId(long nativeTrack); 72 nativeKind(long nativeTrack)73 private static native String nativeKind(long nativeTrack); 74 nativeEnabled(long nativeTrack)75 private static native boolean nativeEnabled(long nativeTrack); 76 nativeSetEnabled( long nativeTrack, boolean enabled)77 private static native boolean nativeSetEnabled( 78 long nativeTrack, boolean enabled); 79 nativeState(long nativeTrack)80 private static native State nativeState(long nativeTrack); 81 nativeSetState( long nativeTrack, int newState)82 private static native boolean nativeSetState( 83 long nativeTrack, int newState); 84 free(long nativeTrack)85 private static native void free(long nativeTrack); 86 } 87