Skip to content

Commit

Permalink
REGRESSION (274873@main): Audio is not anchored to WKWebView's spatia…
Browse files Browse the repository at this point in the history
…l location

https://bugs.webkit.org/show_bug.cgi?id=270919
rdar://123800596

Reviewed by Jer Noble.

In 274873@main we added the infrastructure for passing a spatial tracking label from the UI process
to the GPU process. Because a null WTF::String is implicitly converted to @"", this change had the
unintended side effect of setting AVSampleBufferVidoRenderer and AVPlayer's spatial tracking label
to the empty string rather than the default value of nil, breaking spatial tracking for the audio
emitted from WKWebView.

Resolved this by introducing nsStringNilIfNull -- returning nil if the WTF::String is null otherwise
converting it as-is to NSString -- and using it to set spatial tracking labels in MediaPlayerPrivate.

* Source/WTF/wtf/text/WTFString.h:
(WTF::nsStringNilIfNull):
* Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
(WebCore::MediaPlayerPrivateAVFoundationObjC::createAVPlayer):
(WebCore::MediaPlayerPrivateAVFoundationObjC::setSpatialTrackingLabel):
* Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm:
(WebCore::MediaPlayerPrivateMediaSourceAVFObjC::updateSpatialTrackingLabel):

Canonical link: https://commits.webkit.org/276074@main
  • Loading branch information
aestes committed Mar 14, 2024
1 parent 2998964 commit 81afed4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
10 changes: 10 additions & 0 deletions Source/WTF/wtf/text/WTFString.h
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,9 @@ inline void swap(String& a, String& b) { a.swap(b); }
// Used in a small number of places where the long standing behavior has been "nil if empty".
NSString * nsStringNilIfEmpty(const String&);

// Used in a small number of places where null strings should be converted to nil but empty strings should be maintained.
NSString * nsStringNilIfNull(const String&);

#endif

WTF_EXPORT_PRIVATE int codePointCompare(const String&, const String&);
Expand Down Expand Up @@ -517,6 +520,13 @@ inline NSString * nsStringNilIfEmpty(const String& string)
return *string.impl();
}

inline NSString * nsStringNilIfNull(const String& string)
{
if (string.isNull())
return nil;
return *string.impl();
}

#endif

inline bool codePointCompareLessThan(const String& a, const String& b)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1154,7 +1154,7 @@ static URL conformFragmentIdentifierForURL(const URL& url)
}

#if HAVE(SPATIAL_TRACKING_LABEL)
[m_avPlayer _setSTSLabel:m_spatialTrackingLabel];
[m_avPlayer _setSTSLabel:nsStringNilIfNull(m_spatialTrackingLabel)];
#endif

if (m_avPlayerItem)
Expand Down Expand Up @@ -4011,9 +4011,9 @@ void determineChangedTracksFromNewTracksAndOldItems(MediaSelectionGroupAVFObjC*
{
if (m_spatialTrackingLabel == spatialTrackingLabel)
return;
m_spatialTrackingLabel = spatialTrackingLabel;
m_spatialTrackingLabel = WTFMove(spatialTrackingLabel);
if (m_avPlayer)
[m_avPlayer _setSTSLabel:spatialTrackingLabel];
[m_avPlayer _setSTSLabel:nsStringNilIfNull(m_spatialTrackingLabel)];
}
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1677,7 +1677,7 @@ void getSupportedTypes(HashSet<String>& types) const final
if (!m_visible)
[m_sampleBufferDisplayLayer sampleBufferRenderer].STSLabel = session.spatialTrackingLabel;
else
[m_sampleBufferDisplayLayer sampleBufferRenderer].STSLabel = m_spatialTrackingLabel;
[m_sampleBufferDisplayLayer sampleBufferRenderer].STSLabel = nsStringNilIfNull(m_spatialTrackingLabel);
}
#endif

Expand Down

0 comments on commit 81afed4

Please sign in to comment.