OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 package org.webrtc; | 11 package org.webrtc; |
12 | 12 |
13 /** Java wrapper for a C++ RtpReceiverInterface. */ | 13 /** Java wrapper for a C++ RtpReceiverInterface. */ |
14 public class RtpReceiver { | 14 public class RtpReceiver { |
15 /** Java wrapper for a C++ RtpReceiverObserverInterface*/ | 15 /** Java wrapper for a C++ RtpReceiverObserverInterface*/ |
16 public static interface Observer { | 16 public static interface Observer { |
17 // Called when the first audio or video packet is received. | 17 // Called when the first audio or video packet is received. |
18 public void onFirstPacketReceived(MediaStreamTrack.MediaType media_type); | 18 public void onFirstPacketReceived(MediaStreamTrack.MediaType media_type); |
19 } | 19 } |
20 | 20 |
21 final long nativeRtpReceiver; | 21 final long nativeRtpReceiver; |
22 private long nativeObserver; | 22 private long nativeObserver; |
23 | 23 |
24 private MediaStreamTrack cachedTrack; | 24 private final MediaStreamTrack cachedTrack; |
25 | 25 |
26 public RtpReceiver(long nativeRtpReceiver) { | 26 public RtpReceiver(long nativeRtpReceiver) { |
27 this.nativeRtpReceiver = nativeRtpReceiver; | 27 this.nativeRtpReceiver = nativeRtpReceiver; |
| 28 // We can assume that an RtpReceiver always has an associated track. |
28 long track = nativeGetTrack(nativeRtpReceiver); | 29 long track = nativeGetTrack(nativeRtpReceiver); |
29 // We can assume that an RtpReceiver always has an associated track. | 30 String kind = MediaStreamTrack.nativeKind(track); |
30 cachedTrack = new MediaStreamTrack(track); | 31 if (kind.equals("audio")) { |
| 32 cachedTrack = new AudioTrack(track); |
| 33 } else if (kind.equals("video")) { |
| 34 cachedTrack = new VideoTrack(track); |
| 35 } else { |
| 36 throw new IllegalStateException("unexpected kind " + kind); |
| 37 } |
31 } | 38 } |
32 | 39 |
33 public MediaStreamTrack track() { | 40 public MediaStreamTrack track() { |
34 return cachedTrack; | 41 return cachedTrack; |
35 } | 42 } |
36 | 43 |
37 public boolean setParameters(RtpParameters parameters) { | 44 public boolean setParameters(RtpParameters parameters) { |
38 return nativeSetParameters(nativeRtpReceiver, parameters); | 45 return nativeSetParameters(nativeRtpReceiver, parameters); |
39 } | 46 } |
40 | 47 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 private static native RtpParameters nativeGetParameters(long nativeRtpReceiver
); | 80 private static native RtpParameters nativeGetParameters(long nativeRtpReceiver
); |
74 | 81 |
75 private static native String nativeId(long nativeRtpReceiver); | 82 private static native String nativeId(long nativeRtpReceiver); |
76 | 83 |
77 private static native void free(long nativeRtpReceiver); | 84 private static native void free(long nativeRtpReceiver); |
78 | 85 |
79 private static native long nativeSetObserver(long nativeRtpReceiver, Observer
observer); | 86 private static native long nativeSetObserver(long nativeRtpReceiver, Observer
observer); |
80 | 87 |
81 private static native long nativeUnsetObserver(long nativeRtpReceiver, long na
tiveObserver); | 88 private static native long nativeUnsetObserver(long nativeRtpReceiver, long na
tiveObserver); |
82 }; | 89 }; |
OLD | NEW |