Skip to content

Commit 85f3f00

Browse files
[MSE SourceBuffer] Disable audio flush on samples replacement for Spotify (#1244)
With edit lists enabled recently, Spotify started to append the same segment multiple times that to samples replacement and audio flush. As a result audio is breaking on every append. Disable audio flush on samples replacement for Spotify until this is fixed by Spotify
1 parent 8848619 commit 85f3f00

5 files changed

Lines changed: 33 additions & 1 deletion

File tree

Source/WebCore/Modules/mediasource/SourceBuffer.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ SourceBuffer::SourceBuffer(Ref<SourceBufferPrivate>&& sourceBufferPrivate, Media
101101

102102
m_private->setClient(this);
103103
m_private->setIsAttached(true);
104+
105+
if (document().quirks().shouldBypassAudioFlushOnSampleReplacement()) {
106+
m_private->setShouldBypassAudioFlushOnSampleReplacement(true);
107+
}
104108
}
105109

106110
SourceBuffer::~SourceBuffer()

Source/WebCore/page/Quirks.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,4 +1490,22 @@ bool Quirks::shouldDisableLazyImageLoadingQuirk() const
14901490
return m_shouldDisableLazyImageLoadingQuirk.value();
14911491
}
14921492

1493+
#if ENABLE(MEDIA_SOURCE)
1494+
bool Quirks::shouldBypassAudioFlushOnSampleReplacement() const
1495+
{
1496+
if (!needsQuirks())
1497+
return false;
1498+
1499+
if (m_shouldBypassAudioFlushOnSampleReplacementQuirk)
1500+
return m_shouldBypassAudioFlushOnSampleReplacementQuirk.value();
1501+
1502+
auto domain = m_document->securityOrigin().domain().convertToASCIILowercase();
1503+
1504+
m_shouldBypassAudioFlushOnSampleReplacementQuirk =
1505+
(domain.endsWith(".spotify.com"_s) || domain == "tv.scdn.co"_s);
1506+
1507+
return m_shouldBypassAudioFlushOnSampleReplacementQuirk.value();
1508+
}
1509+
#endif
1510+
14931511
}

Source/WebCore/page/Quirks.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ class Quirks {
162162

163163
bool shouldDisableLazyImageLoadingQuirk() const;
164164

165+
#if ENABLE(MEDIA_SOURCE)
166+
bool shouldBypassAudioFlushOnSampleReplacement() const;
167+
#endif
168+
165169
private:
166170
bool needsQuirks() const;
167171

@@ -217,6 +221,10 @@ class Quirks {
217221
mutable std::optional<bool> m_needsVideoShouldMaintainAspectRatioQuirk;
218222
mutable std::optional<bool> m_shouldExposeShowModalDialog;
219223
mutable std::optional<bool> m_shouldDisableLazyImageLoadingQuirk;
224+
#if ENABLE(MEDIA_SOURCE)
225+
mutable std::optional<bool> m_shouldBypassAudioFlushOnSampleReplacementQuirk;
226+
#endif
227+
220228
};
221229

222230
} // namespace WebCore

Source/WebCore/platform/graphics/SourceBufferPrivate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,7 @@ void SourceBufferPrivate::didReceiveSample(Ref<MediaSample>&& originalSample)
10221022
// Only force the TrackBuffer to re-enqueue if the removed ranges overlap with enqueued and possibly
10231023
// not yet displayed samples.
10241024
MediaTime currentTime = currentMediaTime();
1025-
if (trackBuffer.highestEnqueuedPresentationTime().isValid() && currentTime < trackBuffer.highestEnqueuedPresentationTime()) {
1025+
if (trackBuffer.highestEnqueuedPresentationTime().isValid() && currentTime < trackBuffer.highestEnqueuedPresentationTime() && (!hasAudio() || !m_shouldBypassAudioFlushOnSampleReplacement)) {
10261026
PlatformTimeRanges possiblyEnqueuedRanges(currentTime, trackBuffer.highestEnqueuedPresentationTime());
10271027
possiblyEnqueuedRanges.intersectWith(erasedRanges);
10281028
if (possiblyEnqueuedRanges.length())

Source/WebCore/platform/graphics/SourceBufferPrivate.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ class SourceBufferPrivate
130130
virtual const void* sourceBufferLogIdentifier() = 0;
131131
#endif
132132

133+
void setShouldBypassAudioFlushOnSampleReplacement(bool flag) { m_shouldBypassAudioFlushOnSampleReplacement = flag; }
133134
protected:
134135
// The following method should never be called directly and be overridden instead.
135136
WEBCORE_EXPORT virtual void append(Vector<unsigned char>&&);
@@ -193,6 +194,7 @@ class SourceBufferPrivate
193194

194195
bool m_isMediaSourceEnded { false };
195196
RefPtr<TimeRanges> m_buffered;
197+
bool m_shouldBypassAudioFlushOnSampleReplacement { false };
196198
};
197199

198200
} // namespace WebCore

0 commit comments

Comments
 (0)