Skip to content

Commit

Permalink
Remove access from MediaPlayerPrivateMediaSource to MediaSourcePrivat…
Browse files Browse the repository at this point in the history
…e::buffered

https://bugs.webkit.org/show_bug.cgi?id=269560
rdar://problem/123074982

Reviewed by Youenn Fablet.

When a MediaSource object is in use, the HTMLMediaElement retrieves the buffered
directly from it rather than from the MediaPlayer/MediaPlayerPrivate.

As such, we don't need to implement the buffered method for the MediaPlayerPrivateMediaSourceX.

No change in observable behaviour, Covered by existing tests.
* Source/WebCore/Modules/mediasource/MediaSource.cpp:
(WebCore::MediaSource::buffered const):
(WebCore::MediaSource::hasBufferedTime):
* Source/WebCore/Modules/mediasource/MediaSource.h:
* Source/WebCore/html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::mediaPlayerBufferedTimeRangesChanged):
* Source/WebCore/platform/graphics/MediaSourcePrivate.cpp:
(WebCore::MediaSourcePrivate::hasFutureTime const):
(WebCore::MediaSourcePrivate::duration const):
(WebCore::MediaSourcePrivate::buffered const):
* Source/WebCore/platform/graphics/MediaSourcePrivate.h:
* Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm:
(WebCore::MediaPlayerPrivateMediaSourceAVFObjC::buffered const):
* Source/WebCore/platform/graphics/gstreamer/mse/MediaPlayerPrivateGStreamerMSE.cpp:
(WebCore::MediaPlayerPrivateGStreamerMSE::buffered const):
* Source/WebCore/platform/mock/mediasource/MockMediaPlayerMediaSource.cpp:
(WebCore::MockMediaPlayerMediaSource::buffered const):
(WebCore::MockMediaPlayerMediaSource::advanceCurrentTime):

Canonical link: https://commits.webkit.org/274824@main
  • Loading branch information
jyavenard committed Feb 16, 2024
1 parent 6619d9b commit 06c2726
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 17 deletions.
4 changes: 2 additions & 2 deletions Source/WebCore/Modules/mediasource/MediaSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ MediaTime MediaSource::currentTime() const
return m_private->currentTime();
}

const PlatformTimeRanges& MediaSource::buffered() const
PlatformTimeRanges MediaSource::buffered() const
{
assertIsCurrent(m_dispatcher);

Expand Down Expand Up @@ -404,7 +404,7 @@ bool MediaSource::hasBufferedTime(const MediaTime& time)
if (time > duration())
return false;

auto& ranges = m_private->buffered();
auto ranges = m_private->buffered();
if (!ranges.length())
return false;

Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/Modules/mediasource/MediaSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class MediaSource
bool isEnded() const;
void sourceBufferDidChangeActiveState(SourceBuffer&, bool);
MediaTime duration() const;
const PlatformTimeRanges& buffered() const;
PlatformTimeRanges buffered() const;

enum class EndOfStreamError { Network, Decode };
void streamEndedWithError(std::optional<EndOfStreamError>);
Expand Down
6 changes: 2 additions & 4 deletions Source/WebCore/html/HTMLMediaElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8033,13 +8033,11 @@ void HTMLMediaElement::mediaPlayerBufferedTimeRangesChanged()
if (!track->shouldPurgeCuesFromUnbufferedRanges())
continue;

auto& buffered =
track->removeCuesNotInTimeRanges(
#if ENABLE(MEDIA_SOURCE)
m_mediaSource ? m_mediaSource->buffered() :
#endif
m_player->buffered();

track->removeCuesNotInTimeRanges(buffered);
m_player->buffered());
}
});
}
Expand Down
6 changes: 3 additions & 3 deletions Source/WebCore/platform/graphics/MediaSourcePrivate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ bool MediaSourcePrivate::hasFutureTime(const MediaTime& currentTime) const
if (currentTime >= duration())
return false;

auto& ranges = buffered();
auto ranges = buffered();
MediaTime nearest = ranges.nearest(currentTime);
if (abs(nearest - currentTime) > timeFudgeFactor())
return false;
Expand Down Expand Up @@ -73,7 +73,7 @@ RefPtr<MediaSourcePrivateClient> MediaSourcePrivate::client() const
return m_client.get();
}

const MediaTime& MediaSourcePrivate::duration() const
MediaTime MediaSourcePrivate::duration() const
{
Locker locker { m_lock };

Expand Down Expand Up @@ -163,7 +163,7 @@ void MediaSourcePrivate::bufferedChanged(const PlatformTimeRanges& buffered)
m_buffered = buffered;
}

const PlatformTimeRanges& MediaSourcePrivate::buffered() const
PlatformTimeRanges MediaSourcePrivate::buffered() const
{
Locker locker { m_lock };

Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/platform/graphics/MediaSourcePrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ class WEBCORE_EXPORT MediaSourcePrivate
virtual void setTimeFudgeFactor(const MediaTime& fudgeFactor) { m_timeFudgeFactor = fudgeFactor; }
MediaTime timeFudgeFactor() const { return m_timeFudgeFactor; }

const MediaTime& duration() const;
const PlatformTimeRanges& buffered() const;
MediaTime duration() const;
PlatformTimeRanges buffered() const;

bool hasFutureTime(const MediaTime& currentTime) const;
bool hasAudio() const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,8 @@ void getSupportedTypes(HashSet<String>& types) const final

const PlatformTimeRanges& MediaPlayerPrivateMediaSourceAVFObjC::buffered() const
{
return m_mediaSourcePrivate ? m_mediaSourcePrivate->buffered() : PlatformTimeRanges::emptyRanges();
ASSERT_NOT_REACHED();
return PlatformTimeRanges::emptyRanges();
}

bool MediaPlayerPrivateMediaSourceAVFObjC::didLoadingProgress() const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,7 @@ void MediaPlayerPrivateGStreamerMSE::didPreroll()

const PlatformTimeRanges& MediaPlayerPrivateGStreamerMSE::buffered() const
{
if (m_mediaSourcePrivate)
return m_mediaSourcePrivate->buffered();
ASSERT_NOT_REACHED();
return PlatformTimeRanges::emptyRanges();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ MediaTime MockMediaPlayerMediaSource::maxTimeSeekable() const

const PlatformTimeRanges& MockMediaPlayerMediaSource::buffered() const
{
return m_mediaSourcePrivate ? m_mediaSourcePrivate->buffered() : PlatformTimeRanges::emptyRanges();
ASSERT_NOT_REACHED();
return PlatformTimeRanges::emptyRanges();
}

bool MockMediaPlayerMediaSource::didLoadingProgress() const
Expand Down Expand Up @@ -247,7 +248,7 @@ void MockMediaPlayerMediaSource::advanceCurrentTime()
if (!m_mediaSourcePrivate)
return;

auto& buffered = m_mediaSourcePrivate->buffered();
auto buffered = m_mediaSourcePrivate->buffered();
size_t pos = buffered.find(m_currentTime);
if (pos == notFound)
return;
Expand Down

0 comments on commit 06c2726

Please sign in to comment.