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 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 11 | package org.webrtc; |
| 12 | |
| 13 | /** Java wrapper for a C++ MediaSourceInterface. */ |
| 14 | public class MediaSource { |
| 15 | /** Tracks MediaSourceInterface.SourceState */ |
Magnus Jedvert | 9060eb1 | 2017-12-12 12:52:54 +0100 | [diff] [blame] | 16 | public enum State { |
| 17 | INITIALIZING, |
| 18 | LIVE, |
| 19 | ENDED, |
| 20 | MUTED; |
| 21 | |
| 22 | @CalledByNative("State") |
| 23 | static State fromNativeIndex(int nativeIndex) { |
| 24 | return values()[nativeIndex]; |
| 25 | } |
| 26 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 27 | |
Sami Kalliomäki | ee05e90 | 2018-09-28 14:38:21 +0200 | [diff] [blame] | 28 | private long nativeSource; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 29 | |
| 30 | public MediaSource(long nativeSource) { |
| 31 | this.nativeSource = nativeSource; |
| 32 | } |
| 33 | |
| 34 | public State state() { |
Sami Kalliomäki | ee05e90 | 2018-09-28 14:38:21 +0200 | [diff] [blame] | 35 | checkMediaSourceExists(); |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 36 | return nativeGetState(nativeSource); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 37 | } |
| 38 | |
fischman@webrtc.org | 32001ef | 2013-08-12 23:26:21 +0000 | [diff] [blame] | 39 | public void dispose() { |
Sami Kalliomäki | ee05e90 | 2018-09-28 14:38:21 +0200 | [diff] [blame] | 40 | checkMediaSourceExists(); |
magjed | b1c7453 | 2017-08-27 13:47:20 -0700 | [diff] [blame] | 41 | JniCommon.nativeReleaseRef(nativeSource); |
Sami Kalliomäki | ee05e90 | 2018-09-28 14:38:21 +0200 | [diff] [blame] | 42 | nativeSource = 0; |
| 43 | } |
| 44 | |
| 45 | /** Returns a pointer to webrtc::MediaSourceInterface. */ |
| 46 | protected long getNativeMediaSource() { |
| 47 | checkMediaSourceExists(); |
| 48 | return nativeSource; |
| 49 | } |
| 50 | |
| 51 | private void checkMediaSourceExists() { |
| 52 | if (nativeSource == 0) { |
| 53 | throw new IllegalStateException("MediaSource has been disposed."); |
| 54 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 55 | } |
| 56 | |
Magnus Jedvert | 84d8ae5 | 2017-12-20 15:12:10 +0100 | [diff] [blame] | 57 | private static native State nativeGetState(long pointer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 58 | } |