rtc 0.9.0

Sans-I/O WebRTC implementation in Rust
Documentation
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
use std::fmt::Display;
use std::io::Cursor;

use sdp::description::session::SessionDescription;
use serde::{Deserialize, Serialize};

use super::sdp_type::RTCSdpType;
use shared::error::Result;

/// Represents a session description in the SDP offer/answer model.
///
/// `RTCSessionDescription` is used to expose local and remote session descriptions
/// in WebRTC. It contains the SDP (Session Description Protocol) text that describes
/// media capabilities, transport addresses, codecs, and other session parameters.
///
/// # Structure
///
/// The session description consists of:
///
/// - **`sdp_type`**: The type of description ([`RTCSdpType`])
/// - **`sdp`**: The SDP content as a string (text format defined in RFC 8866)
/// - **`parsed`**: Internal cached parsed representation (not serialized)
///
/// # Usage Pattern
///
/// Session descriptions are typically:
///
/// 1. Created using [`offer()`](Self::offer), [`answer()`](Self::answer),
///    or [`pranswer()`](Self::pranswer) constructor methods
/// 2. Serialized to JSON for transmission over the signaling channel
/// 3. Deserialized on the remote peer
/// 4. Applied to the peer connection to establish media
///
/// # Examples
///
/// ## Creating an Offer Description
///
/// ```no_run
/// use rtc::peer_connection::sdp::{RTCSessionDescription, RTCSdpType};
///
/// # fn example() -> Result<(), Box<dyn std::error::Error>> {
/// // In a real application, this SDP would come from create_offer()
/// let sdp_text = r#"v=0
/// o=- 123456789 2 IN IP4 127.0.0.1
/// s=-
/// t=0 0
/// m=audio 9 UDP/TLS/RTP/SAVPF 111
/// "#.to_string();
///
/// // Wrap in RTCSessionDescription
/// let offer = RTCSessionDescription::offer(sdp_text)?;
///
/// assert_eq!(offer.sdp_type, RTCSdpType::Offer);
/// println!("Offer ready to send: {}", offer);
/// # Ok(())
/// # }
/// ```
///
/// ## Creating an Answer Description
///
/// ```no_run
/// use rtc::peer_connection::sdp::RTCSessionDescription;
///
/// # fn example() -> Result<(), Box<dyn std::error::Error>> {
/// let sdp_text = "v=0\r\no=- 987654321 2 IN IP4 127.0.0.1\r\n...".to_string();
/// let answer = RTCSessionDescription::answer(sdp_text)?;
///
/// println!("Answer SDP type: {}", answer.sdp_type);
/// # Ok(())
/// # }
/// ```
///
/// ## Signaling Exchange via JSON
///
/// ```no_run
/// use rtc::peer_connection::sdp::{RTCSessionDescription, RTCSdpType};
///
/// # fn example() -> Result<(), Box<dyn std::error::Error>> {
/// // Peer A: Create and serialize offer
/// let offer = RTCSessionDescription::offer("v=0...".to_string())?;
/// let json = serde_json::to_string(&offer)?;
/// // Send json over signaling channel (WebSocket, HTTP, etc.)
///
/// // Peer B: Receive and deserialize offer
/// let received_offer: RTCSessionDescription = serde_json::from_str(&json)?;
/// assert_eq!(received_offer.sdp_type, RTCSdpType::Offer);
///
/// // Peer B: Create answer (after set_remote_description and create_answer)
/// let answer = RTCSessionDescription::answer("v=0...".to_string())?;
/// let answer_json = serde_json::to_string(&answer)?;
/// // Send answer_json back to Peer A
/// # Ok(())
/// # }
/// ```
///
/// ## Parsing SDP Content
///
/// ```no_run
/// use rtc::peer_connection::sdp::RTCSessionDescription;
///
/// # fn example() -> Result<(), Box<dyn std::error::Error>> {
/// let description = RTCSessionDescription::offer("v=0\r\no=- 123 456 IN IP4 0.0.0.0\r\ns=-\r\nt=0 0\r\n".to_string())?;
///
/// // Access the parsed SDP structure
/// let parsed = description.unmarshal()?;
/// println!("Session version: {}", parsed.version);
/// println!("Session name: {}", parsed.session_name);
/// println!("Media sections: {}", parsed.media_descriptions.len());
/// # Ok(())
/// # }
/// ```
///
/// ## Using Provisional Answers
///
/// ```no_run
/// use rtc::peer_connection::sdp::RTCSessionDescription;
///
/// # fn example() -> Result<(), Box<dyn std::error::Error>> {
/// // Send a provisional answer with limited codecs
/// let sdp_text = "v=0\r\no=- 111 222 IN IP4 0.0.0.0\r\n...".to_string();
/// let pranswer = RTCSessionDescription::pranswer(sdp_text.clone())?;
///
/// // Later, send final answer with all negotiated parameters
/// let final_answer = RTCSessionDescription::answer(sdp_text)?;
/// # Ok(())
/// # }
/// ```
///
/// ## Displaying SDP for Debugging
///
/// ```no_run
/// use rtc::peer_connection::sdp::RTCSessionDescription;
///
/// # fn example() -> Result<(), Box<dyn std::error::Error>> {
/// let offer = RTCSessionDescription::offer("v=0\r\no=- 123 456 IN IP4 0.0.0.0\r\ns=-\r\n".to_string())?;
///
/// // Display formats SDP with CRLF converted to LF for readability
/// println!("{}", offer);
/// // Output: type: offer, sdp:
/// // v=0
/// // o=- 123 456 IN IP4 0.0.0.0
/// // s=-
/// # Ok(())
/// # }
/// ```
///
/// # Specifications
///
/// - [W3C RTCSessionDescription]
/// - [MDN RTCSessionDescription]
/// - [RFC 8866] - SDP: Session Description Protocol
/// - [RFC 3264] - Offer/Answer Model with SDP
///
/// [W3C RTCSessionDescription]: https://w3c.github.io/webrtc-pc/#rtcsessiondescription-class
/// [MDN RTCSessionDescription]: https://developer.mozilla.org/en-US/docs/Web/API/RTCSessionDescription
/// [RFC 8866]: https://datatracker.ietf.org/doc/html/rfc8866
/// [RFC 3264]: https://datatracker.ietf.org/doc/html/rfc3264
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct RTCSessionDescription {
    /// The type of this session description (offer, answer, pranswer, or rollback).
    #[serde(rename = "type")]
    pub sdp_type: RTCSdpType,

    /// The SDP content as a string.
    ///
    /// This is the raw SDP text conforming to RFC 8866 format. It contains
    /// session-level and media-level descriptions including codecs, transport
    /// addresses, ICE candidates, and DTLS fingerprints.
    pub sdp: String,

    /// Internal cached parsed SDP structure.
    ///
    /// This field is never initialized by callers and is used internally for
    /// performance optimization. It is not included in JSON serialization.
    #[serde(skip)]
    pub(crate) parsed: Option<SessionDescription>,
}

impl Display for RTCSessionDescription {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(
            f,
            "type: {}, sdp:\n{}",
            self.sdp_type,
            self.sdp.replace("\r\n", "\n")
        )
    }
}

impl RTCSessionDescription {
    /// Creates an answer session description from SDP text.
    ///
    /// This constructor validates and parses the SDP, wrapping it in an
    /// `RTCSessionDescription` with type [`RTCSdpType::Answer`]. Use this
    /// when creating the final response to an offer.
    ///
    /// # Parameters
    ///
    /// - `sdp`: The SDP content as a string (RFC 8866 format)
    ///
    /// # Returns
    ///
    /// Returns `Ok(RTCSessionDescription)` if the SDP is valid, or `Err` if
    /// parsing fails.
    ///
    /// # Examples
    ///
    /// ```no_run
    /// use rtc::peer_connection::sdp::{RTCSessionDescription, RTCSdpType};
    ///
    /// # fn example() -> Result<(), Box<dyn std::error::Error>> {
    /// // Typically this SDP comes from create_answer()
    /// let sdp = r#"v=0
    /// o=- 987654321 2 IN IP4 192.168.1.100
    /// s=-
    /// t=0 0
    /// m=audio 9 UDP/TLS/RTP/SAVPF 111
    /// "#.to_string();
    ///
    /// let answer = RTCSessionDescription::answer(sdp)?;
    /// assert_eq!(answer.sdp_type, RTCSdpType::Answer);
    ///
    /// // The SDP is automatically validated and parsed (internally)
    /// // Access parsed structure with unmarshal()
    /// let parsed = answer.unmarshal()?;
    /// println!("Answer has {} media section(s)", parsed.media_descriptions.len());
    /// # Ok(())
    /// # }
    /// ```
    pub fn answer(sdp: String) -> Result<RTCSessionDescription> {
        let mut desc = RTCSessionDescription {
            sdp,
            sdp_type: RTCSdpType::Answer,
            parsed: None,
        };

        let parsed = desc.unmarshal()?;
        desc.parsed = Some(parsed);

        Ok(desc)
    }

    /// Creates an offer session description from SDP text.
    ///
    /// This constructor validates and parses the SDP, wrapping it in an
    /// `RTCSessionDescription` with type [`RTCSdpType::Offer`]. Use this
    /// when creating the initial offer to start negotiation.
    ///
    /// # Parameters
    ///
    /// - `sdp`: The SDP content as a string (RFC 8866 format)
    ///
    /// # Returns
    ///
    /// Returns `Ok(RTCSessionDescription)` if the SDP is valid, or `Err` if
    /// parsing fails.
    ///
    /// # Examples
    ///
    /// ```no_run
    /// use rtc::peer_connection::sdp::{RTCSessionDescription, RTCSdpType};
    ///
    /// # fn example() -> Result<(), Box<dyn std::error::Error>> {
    /// // Typically this SDP comes from create_offer()
    /// let sdp = r#"v=0
    /// o=- 123456789 2 IN IP4 192.168.1.1
    /// s=-
    /// t=0 0
    /// m=video 9 UDP/TLS/RTP/SAVPF 96
    /// "#.to_string();
    ///
    /// let offer = RTCSessionDescription::offer(sdp)?;
    /// assert_eq!(offer.sdp_type, RTCSdpType::Offer);
    ///
    /// // Parsed structure is available immediately
    /// let parsed = offer.unmarshal()?;
    /// println!("Offer has {} media section(s)", parsed.media_descriptions.len());
    /// # Ok(())
    /// # }
    /// ```
    pub fn offer(sdp: String) -> Result<RTCSessionDescription> {
        let mut desc = RTCSessionDescription {
            sdp,
            sdp_type: RTCSdpType::Offer,
            parsed: None,
        };

        let parsed = desc.unmarshal()?;
        desc.parsed = Some(parsed);

        Ok(desc)
    }

    /// Creates a provisional answer session description from SDP text.
    ///
    /// This constructor validates and parses the SDP, wrapping it in an
    /// `RTCSessionDescription` with type [`RTCSdpType::Pranswer`]. Use this
    /// when you want to send a preliminary answer before the final answer,
    /// allowing early media to flow.
    ///
    /// # Parameters
    ///
    /// - `sdp`: The SDP content as a string (RFC 8866 format)
    ///
    /// # Returns
    ///
    /// Returns `Ok(RTCSessionDescription)` if the SDP is valid, or `Err` if
    /// parsing fails.
    ///
    /// # Examples
    ///
    /// ```no_run
    /// use rtc::peer_connection::sdp::{RTCSessionDescription, RTCSdpType};
    ///
    /// # fn example() -> Result<(), Box<dyn std::error::Error>> {
    /// // Send provisional answer with a subset of codecs
    /// let early_sdp = r#"v=0
    /// o=- 555555555 2 IN IP4 192.168.1.50
    /// s=-
    /// t=0 0
    /// m=audio 9 UDP/TLS/RTP/SAVPF 0
    /// "#.to_string();
    ///
    /// let pranswer = RTCSessionDescription::pranswer(early_sdp)?;
    /// assert_eq!(pranswer.sdp_type, RTCSdpType::Pranswer);
    ///
    /// // Later, send final answer with all negotiated parameters
    /// // let final_answer = RTCSessionDescription::answer(final_sdp)?;
    /// # Ok(())
    /// # }
    /// ```
    ///
    /// # Note
    ///
    /// Provisional answers are less commonly used in modern WebRTC. Consider
    /// whether sending a final answer immediately is more appropriate for your
    /// use case.
    pub fn pranswer(sdp: String) -> Result<RTCSessionDescription> {
        let mut desc = RTCSessionDescription {
            sdp,
            sdp_type: RTCSdpType::Pranswer,
            parsed: None,
        };

        let parsed = desc.unmarshal()?;
        desc.parsed = Some(parsed);

        Ok(desc)
    }

    /// Creates a rollback session description.
    ///
    /// This constructor creates an `RTCSessionDescription` with type
    /// [`RTCSdpType::Rollback`]. Rollback is used to revert a pending
    /// local or remote description and return the signaling state to Stable.
    ///
    /// Per WebRTC specification (RFC 8829 §5.7), rollback descriptions
    /// typically have empty SDP content. This is used to abort an in-progress
    /// negotiation, such as when implementing Perfect Negotiation collision
    /// resolution.
    ///
    /// # Parameters
    ///
    /// - `sdp`: Optional SDP content. Per spec, this should typically be
    ///   `None` or an empty string. If provided and non-empty, the SDP will
    ///   be parsed and validated.
    ///
    /// # Returns
    ///
    /// Returns `Ok(RTCSessionDescription)` with type Rollback. If non-empty
    /// SDP is provided and parsing fails, returns `Err`.
    ///
    /// # Use Cases
    ///
    /// - **Perfect Negotiation (Polite Peer)**: When a collision is detected,
    ///   the polite peer calls `set_local_description(rollback)` to abort its
    ///   pending offer before accepting the remote offer.
    ///
    /// - **Perfect Negotiation (Offer Rejection)**: When rejecting a remote
    ///   offer, call `set_remote_description(rollback)` to return to Stable
    ///   state without completing negotiation.
    ///
    /// - **Signaling State Transitions**: Enables these rollback transitions:
    ///   - HaveLocalOffer → Stable (SetLocal with rollback)
    ///   - HaveRemoteOffer → Stable (SetRemote with rollback)
    ///
    /// # Examples
    ///
    /// ```no_run
    /// use rtc::peer_connection::sdp::{RTCSessionDescription, RTCSdpType};
    /// use rtc::peer_connection::RTCPeerConnectionBuilder;
    ///
    /// # fn example() -> Result<(), Box<dyn std::error::Error>> {
    /// # let mut pc = RTCPeerConnectionBuilder::new().build()?;
    /// // Create a rollback description (typically with empty SDP)
    /// let rollback = RTCSessionDescription::rollback(None)?;
    /// assert_eq!(rollback.sdp_type, RTCSdpType::Rollback);
    /// assert_eq!(rollback.sdp, "");
    ///
    /// // Use case: Polite peer rolling back local offer on collision
    /// // (assumes peer is currently in HaveLocalOffer state)
    /// pc.set_local_description(rollback)?;
    /// // Now back in Stable state, ready to accept remote offer
    /// # Ok(())
    /// # }
    /// ```
    ///
    /// # Specification
    ///
    /// Implements rollback as specified in:
    /// - RFC 8829 (JSEP) §5.7: Rollback
    /// - W3C WebRTC 1.0 §4.4.1.6: Set the RTCSessionDescription
    pub fn rollback(sdp: Option<String>) -> Result<RTCSessionDescription> {
        let mut desc = RTCSessionDescription {
            sdp: if let Some(sdp) = sdp {
                sdp
            } else {
                "".to_string()
            },
            sdp_type: RTCSdpType::Rollback,
            parsed: None,
        };

        if !desc.sdp.is_empty() {
            let parsed = desc.unmarshal()?;
            desc.parsed = Some(parsed);
        }

        Ok(desc)
    }

    /// Parses the SDP text into a structured format.
    ///
    /// This method deserializes the SDP string into a parsed
    /// [`SessionDescription`](sdp::description::session::SessionDescription)
    /// structure that provides programmatic access to session and media
    /// attributes. The parsed structure is also cached internally for
    /// performance.
    ///
    /// # Returns
    ///
    /// Returns `Ok(SessionDescription)` containing the parsed SDP structure,
    /// or `Err` if the SDP is malformed.
    ///
    /// # Examples
    ///
    /// ```no_run
    /// use rtc::peer_connection::sdp::RTCSessionDescription;
    ///
    /// # fn example() -> Result<(), Box<dyn std::error::Error>> {
    /// let offer = RTCSessionDescription::offer(
    ///     "v=0\r\no=- 123 456 IN IP4 0.0.0.0\r\ns=WebRTC Session\r\nt=0 0\r\n".to_string()
    /// )?;
    ///
    /// // Parse SDP to access structure
    /// let parsed = offer.unmarshal()?;
    /// println!("SDP version: {}", parsed.version);
    /// println!("Session name: {}", parsed.session_name);
    /// println!("Number of media sections: {}", parsed.media_descriptions.len());
    ///
    /// // Can be called multiple times (returns same result)
    /// let parsed_again = offer.unmarshal()?;
    /// assert_eq!(parsed.version, parsed_again.version);
    /// # Ok(())
    /// # }
    /// ```
    ///
    /// # Performance
    ///
    /// This method parses the SDP each time it's called. For repeated access,
    /// consider caching the result.
    pub fn unmarshal(&self) -> Result<SessionDescription> {
        let mut reader = Cursor::new(self.sdp.as_bytes());
        let parsed = SessionDescription::unmarshal(&mut reader)?;
        Ok(parsed)
    }
}

#[cfg(test)]
mod test {
    use super::*;

    #[test]
    fn test_session_description_json() {
        let tests = vec![
            (
                RTCSessionDescription {
                    sdp_type: RTCSdpType::Offer,
                    sdp: "sdp".to_owned(),
                    parsed: None,
                },
                r#"{"type":"offer","sdp":"sdp"}"#,
            ),
            (
                RTCSessionDescription {
                    sdp_type: RTCSdpType::Pranswer,
                    sdp: "sdp".to_owned(),
                    parsed: None,
                },
                r#"{"type":"pranswer","sdp":"sdp"}"#,
            ),
            (
                RTCSessionDescription {
                    sdp_type: RTCSdpType::Answer,
                    sdp: "sdp".to_owned(),
                    parsed: None,
                },
                r#"{"type":"answer","sdp":"sdp"}"#,
            ),
            (
                RTCSessionDescription {
                    sdp_type: RTCSdpType::Rollback,
                    sdp: "sdp".to_owned(),
                    parsed: None,
                },
                r#"{"type":"rollback","sdp":"sdp"}"#,
            ),
            (
                RTCSessionDescription {
                    sdp_type: RTCSdpType::Unspecified,
                    sdp: "sdp".to_owned(),
                    parsed: None,
                },
                r#"{"type":"Unspecified","sdp":"sdp"}"#,
            ),
        ];

        for (desc, expected_string) in tests {
            let result = serde_json::to_string(&desc);
            assert!(result.is_ok(), "testCase: marshal err: {result:?}");
            let desc_data = result.unwrap();
            assert_eq!(desc_data, expected_string, "string is not expected");

            let result = serde_json::from_str::<RTCSessionDescription>(&desc_data);
            assert!(result.is_ok(), "testCase: unmarshal err: {result:?}");
            if let Ok(sd) = result {
                assert!(sd.sdp == desc.sdp && sd.sdp_type == desc.sdp_type);
            }
        }
    }

    /*TODO: #[tokio::test]
    async fn test_session_description_answer() -> Result<()> {
        let mut m = MediaEngine::default();
        m.register_default_codecs()?;
        let api = APIBuilder::new().with_media_engine(m).build();

        let offer_pc = api.new_peer_connection(RTCConfiguration::default()).await?;
        let answer_pc = api.new_peer_connection(RTCConfiguration::default()).await?;

        let _ = offer_pc.create_data_channel("foo", None).await?;
        let offer = offer_pc.create_offer(None).await?;
        answer_pc.set_remote_description(offer).await?;

        let answer = answer_pc.create_answer(None).await?;

        let desc = RTCSessionDescription::answer(answer.sdp.clone())?;

        assert!(desc.sdp_type == RTCSdpType::Answer);
        assert!(desc.parsed.is_some());

        assert_eq!(answer.unmarshal()?.marshal(), desc.unmarshal()?.marshal());

        Ok(())
    }

    #[tokio::test]
    async fn test_session_description_offer() -> Result<()> {
        let mut m = MediaEngine::default();
        m.register_default_codecs()?;
        let api = APIBuilder::new().with_media_engine(m).build();

        let pc = api.new_peer_connection(RTCConfiguration::default()).await?;
        let offer = pc.create_offer(None).await?;

        let desc = RTCSessionDescription::offer(offer.sdp.clone())?;

        assert!(desc.sdp_type == RTCSdpType::Offer);
        assert!(desc.parsed.is_some());

        assert_eq!(offer.unmarshal()?.marshal(), desc.unmarshal()?.marshal());

        Ok(())
    }

    #[tokio::test]
    async fn test_session_description_pranswer() -> Result<()> {
        let mut m = MediaEngine::default();
        m.register_default_codecs()?;
        let api = APIBuilder::new().with_media_engine(m).build();

        let offer_pc = api.new_peer_connection(RTCConfiguration::default()).await?;
        let answer_pc = api.new_peer_connection(RTCConfiguration::default()).await?;

        let _ = offer_pc.create_data_channel("foo", None).await?;
        let offer = offer_pc.create_offer(None).await?;
        answer_pc.set_remote_description(offer).await?;

        let answer = answer_pc.create_answer(None).await?;

        let desc = RTCSessionDescription::pranswer(answer.sdp)?;

        assert!(desc.sdp_type == RTCSdpType::Pranswer);
        assert!(desc.parsed.is_some());

        Ok(())
    }

    #[tokio::test]
    async fn test_session_description_unmarshal() -> Result<()> {
        let mut m = MediaEngine::default();
        m.register_default_codecs()?;
        let api = APIBuilder::new().with_media_engine(m).build();

        let pc = api.new_peer_connection(RTCConfiguration::default()).await?;

        let offer = pc.create_offer(None).await?;

        let desc = RTCSessionDescription {
            sdp_type: offer.sdp_type,
            sdp: offer.sdp,
            ..Default::default()
        };

        assert!(desc.parsed.is_none());

        let parsed1 = desc.unmarshal()?;
        let parsed2 = desc.unmarshal()?;

        pc.close().await?;

        // check if the two parsed results _really_ match, could be affected by internal caching
        assert_eq!(parsed1.marshal(), parsed2.marshal());

        Ok(())
    }*/
}