Skip to content

Commit 1f6ec0c

Browse files
committed
Use sender_id as default msid app_data
1 parent b22d21c commit 1f6ec0c

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

lib/ex_webrtc/rtp_transceiver.ex

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ defmodule ExWebRTC.RTPTransceiver do
558558
else: transceiver.sender.codecs
559559

560560
get_sender_attrs(
561-
transceiver.sender.track,
561+
transceiver.sender,
562562
codecs,
563563
transceiver.sender.ssrc,
564564
transceiver.sender.rtx_ssrc
@@ -577,11 +577,11 @@ defmodule ExWebRTC.RTPTransceiver do
577577
end
578578

579579
@doc false
580-
defp get_sender_attrs(track, codecs, ssrc, rtx_ssrc) do
580+
defp get_sender_attrs(sender, codecs, ssrc, rtx_ssrc) do
581581
# According to RFC 8829 sec. 5.2.1, track IDs should not be included.
582582
# However, most browsers support track IDs in MSID. We will follow this practice.
583583
msid_attrs =
584-
case track do
584+
case sender.track do
585585
%MediaStreamTrack{streams: streams, id: id} when streams != [] ->
586586
Enum.map(streams, &ExSDP.Attribute.MSID.new(&1, id))
587587

@@ -594,26 +594,26 @@ defmodule ExWebRTC.RTPTransceiver do
594594
[]
595595
end
596596

597-
ssrc_attrs = get_ssrc_attrs(codecs, ssrc, rtx_ssrc, track)
597+
ssrc_attrs = get_ssrc_attrs(codecs, ssrc, rtx_ssrc, sender)
598598

599599
msid_attrs ++ ssrc_attrs
600600
end
601601

602-
defp get_ssrc_attrs(codecs, ssrc, rtx_ssrc, track) do
602+
defp get_ssrc_attrs(codecs, ssrc, rtx_ssrc, sender) do
603603
codec = Enum.any?(codecs, fn codec -> not String.ends_with?(codec.mime_type, "/rtx") end)
604604
rtx_codec = Enum.any?(codecs, fn codec -> String.ends_with?(codec.mime_type, "/rtx") end)
605605

606-
do_get_ssrc_attrs(codec, rtx_codec, ssrc, rtx_ssrc, track)
606+
do_get_ssrc_attrs(codec, rtx_codec, ssrc, rtx_ssrc, sender)
607607
end
608608

609609
# we didn't manage to negotiate any codec
610-
defp do_get_ssrc_attrs(false, _rtx_codec, _ssrc, _rtx_ssrc, _track) do
610+
defp do_get_ssrc_attrs(false, _rtx_codec, _ssrc, _rtx_ssrc, _sender) do
611611
[]
612612
end
613613

614614
# we have a codec but not rtx codec
615-
defp do_get_ssrc_attrs(_codec, false, ssrc, _rtx_ssrc, track) do
616-
case track do
615+
defp do_get_ssrc_attrs(_codec, false, ssrc, _rtx_ssrc, sender) do
616+
case sender.track do
617617
%MediaStreamTrack{streams: streams, id: id} when streams != [] ->
618618
Enum.map(streams, fn stream ->
619619
%ExSDP.Attribute.SSRC{id: ssrc, attribute: "msid", value: "#{stream} #{id}"}
@@ -623,16 +623,18 @@ defmodule ExWebRTC.RTPTransceiver do
623623
[%ExSDP.Attribute.SSRC{id: ssrc, attribute: "msid", value: "- #{id}"}]
624624

625625
nil ->
626-
[%ExSDP.Attribute.SSRC{id: ssrc, attribute: "msid", value: "- -"}]
626+
# If the track_id is missing, we will default to using the sender_id, following Chromium's approach:
627+
# See: https://source.chromium.org/chromium/chromium/src/+/main:third_party/webrtc/pc/sdp_offer_answer.cc;l=739;drc=b8b5768e5d0d1c2a84fe4896eae884d97fd1131e;bpv=1;bpt=1
628+
[%ExSDP.Attribute.SSRC{id: ssrc, attribute: "msid", value: "- #{sender.id}"}]
627629
end
628630
end
629631

630632
# we have both codec and rtx codec
631-
defp do_get_ssrc_attrs(_codec, _rtx_codec, ssrc, rtx_ssrc, track) do
633+
defp do_get_ssrc_attrs(_codec, _rtx_codec, ssrc, rtx_ssrc, sender) do
632634
fid = %ExSDP.Attribute.SSRCGroup{semantics: "FID", ssrcs: [ssrc, rtx_ssrc]}
633635

634636
ssrc_attrs =
635-
case track do
637+
case sender.track do
636638
%MediaStreamTrack{streams: streams, id: id} when streams != [] ->
637639
{ssrc_attrs, rtx_ssrc_attrs} =
638640
Enum.reduce(streams, {[], []}, fn stream, {ssrc_attrs, rtx_ssrc_attrs} ->
@@ -662,8 +664,8 @@ defmodule ExWebRTC.RTPTransceiver do
662664

663665
nil ->
664666
[
665-
%ExSDP.Attribute.SSRC{id: ssrc, attribute: "msid", value: "- -"},
666-
%ExSDP.Attribute.SSRC{id: rtx_ssrc, attribute: "msid", value: "- -"}
667+
%ExSDP.Attribute.SSRC{id: ssrc, attribute: "msid", value: "- #{sender.id}"},
668+
%ExSDP.Attribute.SSRC{id: rtx_ssrc, attribute: "msid", value: "- #{sender.id}"}
667669
]
668670
end
669671

test/ex_webrtc/rtp_transceiver_test.exs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,9 @@ defmodule ExWebRTC.RTPTransceiverTest do
199199
assert [] = ExSDP.get_attributes(mline, ExSDP.Attribute.MSID)
200200

201201
assert [
202-
%ExSDP.Attribute.SSRC{id: @ssrc, attribute: "msid", value: "- -"},
203-
%ExSDP.Attribute.SSRC{id: @rtx_ssrc, attribute: "msid", value: "- -"}
204-
] = ExSDP.get_attributes(mline, ExSDP.Attribute.SSRC)
202+
%ExSDP.Attribute.SSRC{id: @ssrc, attribute: "msid", value: "- #{tr.sender.id}"},
203+
%ExSDP.Attribute.SSRC{id: @rtx_ssrc, attribute: "msid", value: "- #{tr.sender.id}"}
204+
] == ExSDP.get_attributes(mline, ExSDP.Attribute.SSRC)
205205
end
206206
end
207207

0 commit comments

Comments
 (0)