8
8
//
9
9
// History:
10
10
// 20 Oct 2005 Aaron Clauson Created.
11
+ // rj2: save raw string of SDP, in case there is something in it, that can't be parsed
11
12
//
12
13
// Notes:
13
14
//
@@ -120,6 +121,8 @@ public class SDP
120
121
121
122
public decimal Version = SDP_PROTOCOL_VERSION ;
122
123
124
+ private string m_rawSdp = null ;
125
+
123
126
// Owner fields.
124
127
public string Username = "-" ; // Username of the session originator.
125
128
public string SessionId = "-" ; // Unique Id for the session.
@@ -174,63 +177,65 @@ public static SDP ParseSDPDescription(string sdpDescription)
174
177
if ( sdpDescription != null && sdpDescription . Trim ( ) . Length > 0 )
175
178
{
176
179
SDP sdp = new SDP ( ) ;
180
+ sdp . m_rawSdp = sdpDescription ;
177
181
SDPMediaAnnouncement activeAnnouncement = null ;
178
182
179
183
string [ ] sdpLines = Regex . Split ( sdpDescription , CRLF ) ;
180
184
181
185
foreach ( string sdpLine in sdpLines )
182
186
{
183
- if ( sdpLine . Trim ( ) . StartsWith ( "v=" ) )
187
+ string sdpLineTrimmed = sdpLine . Trim ( ) ;
188
+ if ( sdpLineTrimmed . StartsWith ( "v=" ) )
184
189
{
185
- if ( ! Decimal . TryParse ( sdpLine . Substring ( 2 ) , out sdp . Version ) )
190
+ if ( ! Decimal . TryParse ( sdpLineTrimmed . Substring ( 2 ) , out sdp . Version ) )
186
191
{
187
192
logger . LogWarning ( "The Version value in an SDP description could not be parsed as a decimal: " + sdpLine + "." ) ;
188
193
}
189
194
}
190
- else if ( sdpLine . Trim ( ) . StartsWith ( "o=" ) )
195
+ else if ( sdpLineTrimmed . StartsWith ( "o=" ) )
191
196
{
192
- string [ ] ownerFields = sdpLine . Substring ( 2 ) . Split ( ' ' ) ;
197
+ string [ ] ownerFields = sdpLineTrimmed . Substring ( 2 ) . Split ( ' ' ) ;
193
198
sdp . Username = ownerFields [ 0 ] ;
194
199
sdp . SessionId = ownerFields [ 1 ] ;
195
200
Int32 . TryParse ( ownerFields [ 2 ] , out sdp . AnnouncementVersion ) ;
196
201
sdp . NetworkType = ownerFields [ 3 ] ;
197
202
sdp . AddressType = ownerFields [ 4 ] ;
198
203
sdp . Address = ownerFields [ 5 ] ;
199
204
}
200
- else if ( sdpLine . Trim ( ) . StartsWith ( "s=" ) )
205
+ else if ( sdpLineTrimmed . StartsWith ( "s=" ) )
201
206
{
202
- sdp . SessionName = sdpLine . Substring ( 2 ) ;
207
+ sdp . SessionName = sdpLineTrimmed . Substring ( 2 ) ;
203
208
}
204
- else if ( sdpLine . Trim ( ) . StartsWith ( "c=" ) )
209
+ else if ( sdpLineTrimmed . StartsWith ( "c=" ) )
205
210
{
206
211
if ( sdp . Connection == null )
207
212
{
208
- sdp . Connection = SDPConnectionInformation . ParseConnectionInformation ( sdpLine ) ;
213
+ sdp . Connection = SDPConnectionInformation . ParseConnectionInformation ( sdpLineTrimmed ) ;
209
214
}
210
215
211
216
if ( activeAnnouncement != null )
212
217
{
213
- activeAnnouncement . Connection = SDPConnectionInformation . ParseConnectionInformation ( sdpLine ) ;
218
+ activeAnnouncement . Connection = SDPConnectionInformation . ParseConnectionInformation ( sdpLineTrimmed ) ;
214
219
}
215
220
}
216
- else if ( sdpLine . Trim ( ) . StartsWith ( "b=" ) )
221
+ else if ( sdpLineTrimmed . StartsWith ( "b=" ) )
217
222
{
218
223
if ( activeAnnouncement != null )
219
224
{
220
- activeAnnouncement . BandwidthAttributes . Add ( sdpLine . Substring ( 2 ) ) ;
225
+ activeAnnouncement . BandwidthAttributes . Add ( sdpLineTrimmed . Substring ( 2 ) ) ;
221
226
}
222
227
else
223
228
{
224
- sdp . BandwidthAttributes . Add ( sdpLine . Substring ( 2 ) ) ;
229
+ sdp . BandwidthAttributes . Add ( sdpLineTrimmed . Substring ( 2 ) ) ;
225
230
}
226
231
}
227
- else if ( sdpLine . Trim ( ) . StartsWith ( "t=" ) )
232
+ else if ( sdpLineTrimmed . StartsWith ( "t=" ) )
228
233
{
229
- sdp . Timing = sdpLine . Substring ( 2 ) ;
234
+ sdp . Timing = sdpLineTrimmed . Substring ( 2 ) ;
230
235
}
231
- else if ( sdpLine . Trim ( ) . StartsWith ( "m=" ) )
236
+ else if ( sdpLineTrimmed . StartsWith ( "m=" ) )
232
237
{
233
- Match mediaMatch = Regex . Match ( sdpLine . Substring ( 2 ) . Trim ( ) , @"(?<type>\w+)\s+(?<port>\d+)\s+(?<transport>\S+)(\s*)(?<formats>.*)$" ) ;
238
+ Match mediaMatch = Regex . Match ( sdpLineTrimmed . Substring ( 2 ) , @"(?<type>\w+)\s+(?<port>\d+)\s+(?<transport>\S+)(\s*)(?<formats>.*)$" ) ;
234
239
if ( mediaMatch . Success )
235
240
{
236
241
SDPMediaAnnouncement announcement = new SDPMediaAnnouncement ( ) ;
@@ -244,22 +249,22 @@ public static SDP ParseSDPDescription(string sdpDescription)
244
249
}
245
250
else
246
251
{
247
- logger . LogWarning ( "A media line in SDP was invalid: " + sdpLine . Substring ( 2 ) + "." ) ;
252
+ logger . LogWarning ( "A media line in SDP was invalid: " + sdpLineTrimmed . Substring ( 2 ) + "." ) ;
248
253
}
249
254
}
250
- else if ( sdpLine . Trim ( ) . StartsWith ( "a=" + ICE_UFRAG_ATTRIBUTE_PREFIX ) )
255
+ else if ( sdpLineTrimmed . StartsWith ( "a=" + ICE_UFRAG_ATTRIBUTE_PREFIX ) )
251
256
{
252
- sdp . IceUfrag = sdpLine . Substring ( sdpLine . IndexOf ( ':' ) + 1 ) ;
257
+ sdp . IceUfrag = sdpLineTrimmed . Substring ( sdpLineTrimmed . IndexOf ( ':' ) + 1 ) ;
253
258
}
254
- else if ( sdpLine . Trim ( ) . StartsWith ( "a=" + ICE_PWD_ATTRIBUTE_PREFIX ) )
259
+ else if ( sdpLineTrimmed . StartsWith ( "a=" + ICE_PWD_ATTRIBUTE_PREFIX ) )
255
260
{
256
- sdp . IcePwd = sdpLine . Substring ( sdpLine . IndexOf ( ':' ) + 1 ) ;
261
+ sdp . IcePwd = sdpLineTrimmed . Substring ( sdpLineTrimmed . IndexOf ( ':' ) + 1 ) ;
257
262
}
258
- else if ( sdpLine . Trim ( ) . StartsWith ( SDPMediaAnnouncement . MEDIA_FORMAT_ATTRIBUE_PREFIX ) )
263
+ else if ( sdpLineTrimmed . StartsWith ( SDPMediaAnnouncement . MEDIA_FORMAT_ATTRIBUE_PREFIX ) )
259
264
{
260
265
if ( activeAnnouncement != null )
261
266
{
262
- Match formatAttributeMatch = Regex . Match ( sdpLine . Trim ( ) , SDPMediaAnnouncement . MEDIA_FORMAT_ATTRIBUE_PREFIX + @"(?<id>\d+)\s+(?<attribute>.*)$" ) ;
267
+ Match formatAttributeMatch = Regex . Match ( sdpLineTrimmed , SDPMediaAnnouncement . MEDIA_FORMAT_ATTRIBUE_PREFIX + @"(?<id>\d+)\s+(?<attribute>.*)$" ) ;
263
268
if ( formatAttributeMatch . Success )
264
269
{
265
270
int formatID ;
@@ -274,19 +279,19 @@ public static SDP ParseSDPDescription(string sdpDescription)
274
279
}
275
280
else
276
281
{
277
- activeAnnouncement . AddExtra ( sdpLine ) ;
282
+ activeAnnouncement . AddExtra ( sdpLineTrimmed ) ;
278
283
}
279
284
}
280
285
else
281
286
{
282
287
logger . LogWarning ( "There was no active media announcement for a media format attribute, ignoring." ) ;
283
288
}
284
289
}
285
- else if ( sdpLine . Trim ( ) . StartsWith ( SDPMediaAnnouncement . MEDIA_FORMAT_PARAMETERS_ATTRIBUE_PREFIX ) )
290
+ else if ( sdpLineTrimmed . StartsWith ( SDPMediaAnnouncement . MEDIA_FORMAT_PARAMETERS_ATTRIBUE_PREFIX ) )
286
291
{
287
292
if ( activeAnnouncement != null )
288
293
{
289
- Match formatAttributeMatch = Regex . Match ( sdpLine . Trim ( ) , SDPMediaAnnouncement . MEDIA_FORMAT_PARAMETERS_ATTRIBUE_PREFIX + @"(?<id>\d+)\s+(?<attribute>.*)$" ) ;
294
+ Match formatAttributeMatch = Regex . Match ( sdpLineTrimmed , SDPMediaAnnouncement . MEDIA_FORMAT_PARAMETERS_ATTRIBUE_PREFIX + @"(?<id>\d+)\s+(?<attribute>.*)$" ) ;
290
295
if ( formatAttributeMatch . Success )
291
296
{
292
297
int formatID ;
@@ -301,22 +306,22 @@ public static SDP ParseSDPDescription(string sdpDescription)
301
306
}
302
307
else
303
308
{
304
- activeAnnouncement . AddExtra ( sdpLine ) ;
309
+ activeAnnouncement . AddExtra ( sdpLineTrimmed ) ;
305
310
}
306
311
}
307
312
else
308
313
{
309
314
logger . LogWarning ( "There was no active media announcement for a media format parameter attribute, ignoring." ) ;
310
315
}
311
316
}
312
- else if ( sdpLine . Trim ( ) . StartsWith ( "a=" + ICE_CANDIDATE_ATTRIBUTE_PREFIX ) )
317
+ else if ( sdpLineTrimmed . StartsWith ( "a=" + ICE_CANDIDATE_ATTRIBUTE_PREFIX ) )
313
318
{
314
319
if ( sdp . IceCandidates == null )
315
320
{
316
321
sdp . IceCandidates = new List < IceCandidate > ( ) ;
317
322
}
318
323
319
- sdp . IceCandidates . Add ( IceCandidate . Parse ( sdpLine . Substring ( sdpLine . IndexOf ( ':' ) + 1 ) ) ) ;
324
+ sdp . IceCandidates . Add ( IceCandidate . Parse ( sdpLineTrimmed . Substring ( sdpLineTrimmed . IndexOf ( ':' ) + 1 ) ) ) ;
320
325
}
321
326
else if ( MediaStreamStatusType . IsMediaStreamStatusAttribute ( sdpLine . Trim ( ) , out var mediaStreamStatus ) )
322
327
{
@@ -333,11 +338,11 @@ public static SDP ParseSDPDescription(string sdpDescription)
333
338
{
334
339
if ( activeAnnouncement != null )
335
340
{
336
- activeAnnouncement . AddExtra ( sdpLine ) ;
341
+ activeAnnouncement . AddExtra ( sdpLineTrimmed ) ;
337
342
}
338
343
else
339
344
{
340
- sdp . AddExtra ( sdpLine ) ;
345
+ sdp . AddExtra ( sdpLineTrimmed ) ;
341
346
}
342
347
}
343
348
}
@@ -364,6 +369,14 @@ public void AddExtra(string attribute)
364
369
}
365
370
}
366
371
372
+ public string RawString ( )
373
+ {
374
+ if ( string . IsNullOrWhiteSpace ( this . m_rawSdp ) )
375
+ {
376
+ return this . ToString ( ) ;
377
+ }
378
+ return this . m_rawSdp ;
379
+ }
367
380
public override string ToString ( )
368
381
{
369
382
string sdp =
0 commit comments