Skip to content

Commit 2ac597c

Browse files
committed
Missing a=msid in offer after setting codec preferences https://bugs.webkit.org/show_bug.cgi?id=275157
Reviewed by Philippe Normand. When setting codec preferences on GstWebRTCRTPTransceiver, the caps object did not contain an "a-msid" field, which causes the offer created by the webrtcbin containing that transceiver to not include an `a=msid` line for it. The issue is fixed by reusing the `a-msid` field from the pre-existent codec preference, if one exists. * LayoutTests/webrtc/msid-setCodecPreferences-expected.txt: Added. * LayoutTests/webrtc/msid-setCodecPreferences.html: Added. * Source/WebCore/Modules/mediastream/gstreamer/GStreamerRtpTransceiverBackend.cpp: (WebCore::getMsidFromCurrentCodecPreferences): (WebCore::GStreamerRtpTransceiverBackend::setCodecPreferences): Canonical link: https://commits.webkit.org/279746@main
1 parent fd293f7 commit 2ac597c

3 files changed

Lines changed: 49 additions & 2 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
PASS msid present in offer SDP after setting codec preferences
3+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Testing basic video exchange from offerer to receiver</title>
6+
<script src="../resources/testharness.js"></script>
7+
<script src="../resources/testharnessreport.js"></script>
8+
</head>
9+
<body>
10+
<script src ="routines.js"></script>
11+
<script>
12+
var track, firstConnection, secondConnection;
13+
promise_test(async (test) => {
14+
if (window.testRunner)
15+
testRunner.setUserMediaPermission(true);
16+
17+
let pc = new RTCPeerConnection();
18+
let stream = await navigator.mediaDevices.getUserMedia({ video: true });
19+
let track = stream.getVideoTracks()[0];
20+
pc.addTrack(track, stream);
21+
pc.getTransceivers()[0].setCodecPreferences([{mimeType: "video/VP8", clockRate: 90000}]);
22+
let offer = await pc.createOffer();
23+
assert_true(offer.sdp.includes(`a=msid:${stream.id} ${track.id}`), 'offer SDP includes a=msid line');
24+
}, "msid present in offer SDP after setting codec preferences");
25+
</script>
26+
</body>
27+
</html>

Source/WebCore/Modules/mediastream/gstreamer/GStreamerRtpTransceiverBackend.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ bool GStreamerRtpTransceiverBackend::stopped() const
109109
return m_isStopped;
110110
}
111111

112-
static inline WARN_UNUSED_RETURN ExceptionOr<GstCaps*> toRtpCodecCapability(const RTCRtpCodecCapability& codec, int& dynamicPayloadType)
112+
static inline WARN_UNUSED_RETURN ExceptionOr<GstCaps*> toRtpCodecCapability(const RTCRtpCodecCapability& codec, int& dynamicPayloadType, const char* msid)
113113
{
114114
if (!codec.mimeType.startsWith("video/"_s) && !codec.mimeType.startsWith("audio/"_s))
115115
return Exception { ExceptionCode::InvalidModificationError, "RTCRtpCodecCapability bad mimeType"_s };
@@ -135,16 +135,33 @@ static inline WARN_UNUSED_RETURN ExceptionOr<GstCaps*> toRtpCodecCapability(cons
135135
}
136136
}
137137

138+
if (msid)
139+
gst_caps_set_simple(caps, "a-msid", G_TYPE_STRING, msid, nullptr);
140+
138141
GST_DEBUG("Codec capability: %" GST_PTR_FORMAT, caps);
139142
return caps;
140143
}
141144

145+
static GUniquePtr<char> getMsidFromCurrentCodecPreferences(GstWebRTCRTPTransceiver* transceiver)
146+
{
147+
GRefPtr<GstCaps> currentCaps;
148+
GUniquePtr<char> msid;
149+
g_object_get(transceiver, "codec-preferences", &currentCaps.outPtr(), nullptr);
150+
GST_TRACE_OBJECT(transceiver, "Current codec preferences: %" GST_PTR_FORMAT, currentCaps.get());
151+
if (gst_caps_get_size(currentCaps.get()) > 0) {
152+
auto* s = gst_caps_get_structure(currentCaps.get(), 0);
153+
msid = GUniquePtr<char>(g_strdup(gst_structure_get_string(s, "a-msid")));
154+
}
155+
return msid;
156+
}
157+
142158
ExceptionOr<void> GStreamerRtpTransceiverBackend::setCodecPreferences(const Vector<RTCRtpCodecCapability>& codecs)
143159
{
144160
auto gstCodecs = adoptGRef(gst_caps_new_empty());
161+
GUniquePtr<char> msid = getMsidFromCurrentCodecPreferences(m_rtcTransceiver.get());
145162
int dynamicPayloadType = 96;
146163
for (auto& codec : codecs) {
147-
auto result = toRtpCodecCapability(codec, dynamicPayloadType);
164+
auto result = toRtpCodecCapability(codec, dynamicPayloadType, msid.get());
148165
if (result.hasException())
149166
return result.releaseException();
150167
gst_caps_append(gstCodecs.get(), result.releaseReturnValue());

0 commit comments

Comments
 (0)