@@ -545,33 +545,17 @@ pub(crate) async fn add_transceiver_sdp(
545
545
if let Some ( sender) = mt. sender ( ) . await {
546
546
let send_parameters = sender. get_parameters ( ) . await ;
547
547
if let Some ( track) = sender. track ( ) . await {
548
+ // Get the different encodings expressed first
548
549
for encoding in send_parameters. encodings . iter ( ) {
549
550
media = media. with_media_source (
550
551
encoding. ssrc ,
551
552
track. stream_id ( ) . to_owned ( ) , /* cname */
552
553
track. stream_id ( ) . to_owned ( ) , /* streamLabel */
553
554
track. id ( ) . to_owned ( ) ,
554
555
) ;
555
-
556
- // Send msid based on the configured track if we haven't already
557
- // sent on this sender. If we have sent we must keep the msid line consistent, this
558
- // is handled below.
559
- if !is_plan_b {
560
- // We need this?
561
- // related streams don't exist any more in pion (and nor should they?)
562
-
563
- // I this should become obsolete
564
- if sender. initial_track_id ( ) . is_none ( ) {
565
- media = media. with_property_attribute ( format ! (
566
- "msid:{} {}" ,
567
- track. stream_id( ) ,
568
- track. id( )
569
- ) ) ;
570
- sender. set_initial_track_id ( track. id ( ) . to_string ( ) ) ?;
571
- }
572
- }
573
556
}
574
557
558
+ // Then tell the world about simulcast
575
559
if send_parameters. encodings . len ( ) > 1 {
576
560
let mut send_rids: Vec < String > = vec ! [ ] ;
577
561
@@ -586,10 +570,43 @@ pub(crate) async fn add_transceiver_sdp(
586
570
s. push_str ( send_rids. join ( ";" ) . as_ref ( ) ) ;
587
571
media = media. with_value_attribute ( "simulcast" . into ( ) , s) ;
588
572
}
573
+ // Send msid based on the configured track if we haven't already
574
+ // sent on this sender. If we have sent we must keep the msid line consistent, this
575
+ // is handled below.
576
+ // And now when we 'break', the above will have been printed properly still?
577
+ if !is_plan_b && sender. initial_track_id ( ) . is_none ( ) {
578
+ for stream_id in sender. associated_media_stream_ids ( ) {
579
+ media = media. with_property_attribute ( format ! (
580
+ "msid:{} {}" ,
581
+ stream_id,
582
+ track. id( )
583
+ ) ) ;
584
+ }
585
+ sender. set_initial_track_id ( track. id ( ) . to_string ( ) ) ?;
586
+ break ;
587
+ }
588
+ }
589
+ if !is_plan_b {
590
+ if let Some ( track_id) = sender. initial_track_id ( ) {
591
+ // After we have include an msid attribute in an offer it must stay the same for
592
+ // all subsequent offer even if the track or transceiver direction changes.
593
+ //
594
+ // [RFC 8829 Section 5.2.2](https://datatracker.ietf.org/doc/html/rfc8829#section-5.2.2)
595
+ //
596
+ // For RtpTransceivers that are not stopped, the "a=msid" line or
597
+ // lines MUST stay the same if they are present in the current
598
+ // description, regardless of changes to the transceiver's direction
599
+ // or track. If no "a=msid" line is present in the current
600
+ // description, "a=msid" line(s) MUST be generated according to the
601
+ // same rules as for an initial offer.
602
+ for stream_id in sender. associated_media_stream_ids ( ) {
603
+ media = media
604
+ . with_property_attribute ( format ! ( "msid:{} {}" , stream_id, track_id) ) ;
605
+ }
606
+
607
+ break ;
608
+ }
589
609
}
590
- }
591
- if !is_plan_b {
592
- break ;
593
610
}
594
611
}
595
612
0 commit comments