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++ RtpSenderInterface. */ | 13 /** Java wrapper for a C++ RtpSenderInterface. */ |
14 public class RtpSender { | 14 public class RtpSender { |
15 final long nativeRtpSender; | 15 final long nativeRtpSender; |
16 | 16 |
17 private MediaStreamTrack cachedTrack; | 17 private MediaStreamTrack cachedTrack; |
18 private boolean ownsTrack = true; | 18 private boolean ownsTrack = true; |
19 | 19 |
| 20 private final DtmfSender dtmfSender; |
| 21 |
20 public RtpSender(long nativeRtpSender) { | 22 public RtpSender(long nativeRtpSender) { |
21 this.nativeRtpSender = nativeRtpSender; | 23 this.nativeRtpSender = nativeRtpSender; |
22 long track = nativeGetTrack(nativeRtpSender); | 24 long track = nativeGetTrack(nativeRtpSender); |
23 // It may be possible for an RtpSender to be created without a track. | 25 // It may be possible for an RtpSender to be created without a track. |
24 cachedTrack = (track == 0) ? null : new MediaStreamTrack(track); | 26 cachedTrack = (track != 0) ? new MediaStreamTrack(track) : null; |
| 27 |
| 28 long nativeDtmfSender = nativeGetDtmfSender(nativeRtpSender); |
| 29 dtmfSender = (nativeDtmfSender != 0) ? new DtmfSender(nativeDtmfSender) : nu
ll; |
25 } | 30 } |
26 | 31 |
27 // If |takeOwnership| is true, the RtpSender takes ownership of the track | 32 // If |takeOwnership| is true, the RtpSender takes ownership of the track |
28 // from the caller, and will auto-dispose of it when no longer needed. | 33 // from the caller, and will auto-dispose of it when no longer needed. |
29 // |takeOwnership| should only be used if the caller owns the track; it is | 34 // |takeOwnership| should only be used if the caller owns the track; it is |
30 // not appropriate when the track is owned by, for example, another RtpSender | 35 // not appropriate when the track is owned by, for example, another RtpSender |
31 // or a MediaStream. | 36 // or a MediaStream. |
32 public boolean setTrack(MediaStreamTrack track, boolean takeOwnership) { | 37 public boolean setTrack(MediaStreamTrack track, boolean takeOwnership) { |
33 if (!nativeSetTrack(nativeRtpSender, (track == null) ? 0 : track.nativeTrack
)) { | 38 if (!nativeSetTrack(nativeRtpSender, (track == null) ? 0 : track.nativeTrack
)) { |
34 return false; | 39 return false; |
(...skipping 15 matching lines...) Expand all Loading... |
50 } | 55 } |
51 | 56 |
52 public RtpParameters getParameters() { | 57 public RtpParameters getParameters() { |
53 return nativeGetParameters(nativeRtpSender); | 58 return nativeGetParameters(nativeRtpSender); |
54 } | 59 } |
55 | 60 |
56 public String id() { | 61 public String id() { |
57 return nativeId(nativeRtpSender); | 62 return nativeId(nativeRtpSender); |
58 } | 63 } |
59 | 64 |
| 65 public DtmfSender dtmf() { |
| 66 return dtmfSender; |
| 67 } |
| 68 |
60 public void dispose() { | 69 public void dispose() { |
| 70 if (dtmfSender != null) { |
| 71 dtmfSender.dispose(); |
| 72 } |
61 if (cachedTrack != null && ownsTrack) { | 73 if (cachedTrack != null && ownsTrack) { |
62 cachedTrack.dispose(); | 74 cachedTrack.dispose(); |
63 } | 75 } |
64 free(nativeRtpSender); | 76 free(nativeRtpSender); |
65 } | 77 } |
66 | 78 |
67 private static native boolean nativeSetTrack(long nativeRtpSender, long native
Track); | 79 private static native boolean nativeSetTrack(long nativeRtpSender, long native
Track); |
68 | 80 |
69 // This should increment the reference count of the track. | 81 // This should increment the reference count of the track. |
70 // Will be released in dispose() or setTrack(). | 82 // Will be released in dispose() or setTrack(). |
71 private static native long nativeGetTrack(long nativeRtpSender); | 83 private static native long nativeGetTrack(long nativeRtpSender); |
72 | 84 |
| 85 // This should increment the reference count of the DTMF sender. |
| 86 // Will be released in dispose(). |
| 87 private static native long nativeGetDtmfSender(long nativeRtpSender); |
| 88 |
73 private static native boolean nativeSetParameters(long nativeRtpSender, RtpPar
ameters parameters); | 89 private static native boolean nativeSetParameters(long nativeRtpSender, RtpPar
ameters parameters); |
74 | 90 |
75 private static native RtpParameters nativeGetParameters(long nativeRtpSender); | 91 private static native RtpParameters nativeGetParameters(long nativeRtpSender); |
76 | 92 |
77 private static native String nativeId(long nativeRtpSender); | 93 private static native String nativeId(long nativeRtpSender); |
78 | 94 |
79 private static native void free(long nativeRtpSender); | 95 private static native void free(long nativeRtpSender); |
80 }; | 96 }; |
OLD | NEW |