|
16 | 16 |
|
17 | 17 | package dev.onvoid.webrtc; |
18 | 18 |
|
| 19 | +import static java.util.Objects.requireNonNull; |
| 20 | + |
| 21 | +import java.util.Objects; |
| 22 | + |
19 | 23 | /** |
20 | | - * Describes supported RTP header extensions. |
| 24 | + * Describes an RTP header extension: one that WebRTC supports, as {@link |
| 25 | + * RTCRtpCapabilities#getHeaderExtensions()} lists them, or one of a |
| 26 | + * transceiver, with the direction it is to be negotiated in. |
21 | 27 | * |
22 | 28 | * @author Alex Andres |
| 29 | + * |
| 30 | + * @see RTCRtpTransceiver#setHeaderExtensionsToNegotiate(java.util.List) |
23 | 31 | */ |
24 | 32 | public class RTCRtpHeaderExtensionCapability { |
25 | 33 |
|
26 | | - /** |
27 | | - * The URI of the RTP header extension. |
28 | | - */ |
29 | 34 | private final String uri; |
30 | 35 |
|
| 36 | + private final RTCRtpTransceiverDirection direction; |
| 37 | + |
31 | 38 |
|
32 | 39 | /** |
33 | | - * Creates an instance of RTCRtpHeaderExtensionCapability with the specified |
34 | | - * RTP header extension URI. |
| 40 | + * Creates a header extension to be negotiated in both directions. |
35 | 41 | * |
36 | | - * @param uri The URI of the RTP header extension. |
| 42 | + * @param uri The URI of the header extension. |
37 | 43 | */ |
38 | 44 | public RTCRtpHeaderExtensionCapability(String uri) { |
39 | | - this.uri = uri; |
| 45 | + this(uri, RTCRtpTransceiverDirection.SEND_RECV); |
40 | 46 | } |
41 | 47 |
|
42 | 48 | /** |
43 | | - * Returns the URI of the supported RTP header extension by the system. |
| 49 | + * Creates a header extension to be negotiated in the given direction. |
| 50 | + * {@link RTCRtpTransceiverDirection#STOPPED} keeps it out of the |
| 51 | + * negotiation. |
44 | 52 | * |
45 | | - * @return The URI of the RTP header extension. |
| 53 | + * @param uri The URI of the header extension. |
| 54 | + * @param direction The direction to negotiate it in. |
| 55 | + */ |
| 56 | + public RTCRtpHeaderExtensionCapability(String uri, RTCRtpTransceiverDirection direction) { |
| 57 | + this.uri = requireNonNull(uri, "uri"); |
| 58 | + this.direction = requireNonNull(direction, "direction"); |
| 59 | + } |
| 60 | + |
| 61 | + /** |
| 62 | + * @return The URI of the header extension, e.g. {@code |
| 63 | + * urn:ietf:params:rtp-hdrext:sdes:mid}. |
46 | 64 | */ |
47 | 65 | public String getUri() { |
48 | 66 | return uri; |
49 | 67 | } |
50 | 68 |
|
| 69 | + /** |
| 70 | + * @return The direction the header extension is negotiated in, or {@link |
| 71 | + * RTCRtpTransceiverDirection#STOPPED} if it is not negotiated. |
| 72 | + */ |
| 73 | + public RTCRtpTransceiverDirection getDirection() { |
| 74 | + return direction; |
| 75 | + } |
| 76 | + |
| 77 | + /** |
| 78 | + * Returns the same header extension with another direction, e.g. to stop |
| 79 | + * one in the list of {@link |
| 80 | + * RTCRtpTransceiver#getHeaderExtensionsToNegotiate()}. |
| 81 | + * |
| 82 | + * @param direction The direction to negotiate it in. |
| 83 | + * |
| 84 | + * @return The header extension with that direction. |
| 85 | + */ |
| 86 | + public RTCRtpHeaderExtensionCapability withDirection(RTCRtpTransceiverDirection direction) { |
| 87 | + return new RTCRtpHeaderExtensionCapability(uri, direction); |
| 88 | + } |
| 89 | + |
| 90 | + @Override |
| 91 | + public boolean equals(Object obj) { |
| 92 | + if (this == obj) { |
| 93 | + return true; |
| 94 | + } |
| 95 | + if (!(obj instanceof RTCRtpHeaderExtensionCapability)) { |
| 96 | + return false; |
| 97 | + } |
| 98 | + |
| 99 | + RTCRtpHeaderExtensionCapability other = (RTCRtpHeaderExtensionCapability) obj; |
| 100 | + |
| 101 | + return uri.equals(other.uri) && direction == other.direction; |
| 102 | + } |
| 103 | + |
| 104 | + @Override |
| 105 | + public int hashCode() { |
| 106 | + return Objects.hash(uri, direction); |
| 107 | + } |
| 108 | + |
51 | 109 | @Override |
52 | 110 | public String toString() { |
53 | | - return String.format("%s [uri=%s]", |
54 | | - RTCRtpHeaderExtensionCapability.class.getSimpleName(), uri); |
| 111 | + return String.format("%s [uri=%s, direction=%s]", |
| 112 | + RTCRtpHeaderExtensionCapability.class.getSimpleName(), uri, direction); |
55 | 113 | } |
56 | 114 | } |
0 commit comments