Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: e1a97f1a75b69bd460d5387e2f3880bd5924a58c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
package org.jivesoftware.smackx.jingle;

/**
 * Represents a payload type.
 * 
 * @author Alvaro Saurin
 */
public class PayloadType {

	public static int MAX_FIXED_PT = 95;

	public static int INVALID_PT = 65535;

	private int id;

	private String name;

	private int channels;

	/**
	 * Constructor with Id, name and number of channels
	 * 
	 * @param id The identifier
	 * @param name A name
	 * @param channels The number of channels
	 */
	public PayloadType(final int id, final String name, final int channels) {
		super();
		this.id = id;
		this.name = name;
		this.channels = channels;
	}

	/**
	 * Default constructor.
	 */
	public PayloadType() {
		this(INVALID_PT, null, 1);
	}

	/**
	 * Constructor with Id and name
	 * 
	 * @param id The identification
	 * @param name A name
	 */
	public PayloadType(final int id, final String name) {
		this(id, name, 1);
	}

	/**
	 * Copy constructor
	 * 
	 * @param pt The other payload type.
	 */
	public PayloadType(final PayloadType pt) {
		this(pt.getId(), pt.getName(), pt.getChannels());
	}

	/**
	 * Get the ID.
	 * 
	 * @return the ID
	 */
	public int getId() {
		return id;
	}

	/**
	 * Set the ID.
	 * 
	 * @param id ID
	 */
	public void setId(final int id) {
		this.id = id;
	}

	/**
	 * Get the printable name.
	 * 
	 * @return printable name for the payload type
	 */
	public String getName() {
		return name;
	}

	/**
	 * Set the printable name.
	 * 
	 * @param name the printable name
	 */
	public void setName(final String name) {
		this.name = name;
	}

	/**
	 * Get the number of channels used by this payload type.
	 * 
	 * @return the number of channels
	 */
	public int getChannels() {
		return channels;
	}

	/**
	 * Set the numer of channels for a payload type.
	 * 
	 * @param channels The number of channels
	 */
	public void setChannels(final int channels) {
		this.channels = channels;
	}

	/**
	 * Return true if the Payload type is not valid
	 * 
	 * @return true if the payload type is invalid
	 */
	public boolean isNull() {
		if (getId() == INVALID_PT) {
			return true;
		} else if (getName() == null) {
			return true;
		}
		return false;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#hashCode()
	 */
	public int hashCode() {
		final int PRIME = 31;
		int result = 1;
		result = PRIME * result + getChannels();
		result = PRIME * result + getId();
		result = PRIME * result + (getName() == null ? 0 : getName().hashCode());
		return result;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	public boolean equals(final Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		final PayloadType other = (PayloadType) obj;
		if (getChannels() != other.getChannels()) {
			return false;
		}
		if (getId() != other.getId()) {
			return false;
		}

		// Compare names only for dynamic payload types
		if (getId() > MAX_FIXED_PT) {
			if (getName() == null) {
				if (other.getName() != null) {
					return false;
				}
			} else if (!getName().equals(other.getName())) {
				return false;
			}
		}
		
		return true;
	}

	/**
	 * Audio payload type.
	 */
	public static class Audio extends PayloadType {
		private int clockRate;

		/**
		 * Constructor with all the attributes of an Audio payload type
		 * 
		 * @param id The identifier
		 * @param name The name assigned to this payload type
		 * @param channels The number of channels
		 * @param rate The clock rate
		 */
		public Audio(final int id, final String name, final int channels, final int rate) {
			super(id, name, channels);
			clockRate = rate;
		}

		/**
		 * Empty constructor.
		 */
		public Audio() {
			super();
			clockRate = 0;
		}

		/**
		 * Constructor with Id and name
		 * 
		 * @param id the Id for the payload type
		 * @param name the name of the payload type
		 */
		public Audio(final int id, final String name) {
			super(id, name);
			clockRate = 0;
		}

		/**
		 * Copy constructor
		 * 
		 * @param pt the other payload type
		 */
		public Audio(final PayloadType pt) {
			super(pt);
			clockRate = 0;
		}

		/**
		 * Copy constructor
		 * 
		 * @param pt the other payload type
		 */
		public Audio(final PayloadType.Audio pt) {
			super(pt);
			clockRate = pt.getClockRate();
		}

		/**
		 * Get the sampling clockRate for a payload type
		 * 
		 * @return The sampling clockRate
		 */
		public int getClockRate() {
			return clockRate;
		}

		/**
		 * Set tha sampling clockRate for a playload type.
		 * 
		 * @param rate The sampling clockRate
		 */
		public void setClockRate(final int rate) {
			clockRate = rate;
		}

		/*
		 * (non-Javadoc)
		 * 
		 * @see java.lang.Object#hashCode()
		 */
		public int hashCode() {
			final int PRIME = 31;
			int result = super.hashCode();
			result = PRIME * result + getClockRate();
			return result;
		}

		/*
		 * (non-Javadoc)
		 * 
		 * @see java.lang.Object#equals(java.lang.Object)
		 */
		public boolean equals(final Object obj) {
			if (this == obj) {
				return true;
			}
			if (!super.equals(obj)) {
				return false;
			}
			if (getClass() != obj.getClass()) {
				return false;
			}
			final Audio other = (Audio) obj;
			if (getClockRate() != other.getClockRate()) {
				return false;
			}
			return true;
		}
	}
}

Back to the top