Skip to content

Commit

Permalink
[MSE] SourceBufferPrivate::didUpdateFormatDescriptionForTrackId can r…
Browse files Browse the repository at this point in the history
…un out of order.

https://bugs.webkit.org/show_bug.cgi?id=264799
rdar://118380017

Reviewed by Youenn Fablet.

Ensure the track format description is processed after the init segment by queuing an operation
instead of running the callback immediately.

Covered by existing tests (which were disabled)

* LayoutTests/platform/mac/TestExpectations:
* Source/WebCore/platform/graphics/SourceBufferPrivate.cpp:
(WebCore::SourceBufferPrivate::didUpdateFormatDescriptionForTrackId):
(WebCore::SourceBufferPrivate::processPendingOperations):
* Source/WebCore/platform/graphics/SourceBufferPrivate.h:
* Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm:
(WebCore::SourceBufferPrivateAVFObjC::didUpdateFormatDescriptionForTrackId):

Canonical link: https://commits.webkit.org/270703@main
  • Loading branch information
jyavenard committed Nov 14, 2023
1 parent 2d5fd91 commit 49ba5f0
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 17 deletions.
5 changes: 0 additions & 5 deletions LayoutTests/platform/mac/TestExpectations
Original file line number Diff line number Diff line change
Expand Up @@ -2403,11 +2403,6 @@ webkit.org/b/255788 [ Ventura+ Debug ] tiled-drawing/scrolling/scroll-snap/scrol

webkit.org/b/256108 media/video-audio-session-mode.html [ Failure ]

# VP9 is not supported on all Intel HW
[ x86_64 ] media/media-source/media-source-webm-configuration-change.html [ Pass Failure ]
[ x86_64 ] media/media-source/media-source-webm-configuration-framerate.html [ Pass Failure ]
[ x86_64 ] media/media-source/media-source-webm-configuration-vp9-header-color.html [ Pass Failure ]

webkit.org/b/258181 [ Debug ] inspector/debugger/async-stack-trace-truncate.html [ Slow Failure ]

# webkit.org/b/258328 Umbrella Bug: Batch mark expectations slowing down EWS
Expand Down
8 changes: 8 additions & 0 deletions Source/WebCore/platform/graphics/SourceBufferPrivate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,12 @@ void SourceBufferPrivate::didReceiveInitializationSegment(InitializationSegment&
m_pendingOperations.append({ WTFMove(initOperation) });
}

void SourceBufferPrivate::didUpdateFormatDescriptionForTrackId(Ref<TrackInfo>&& formatDescription, uint64_t trackId, CompletionHandler<void(Ref<TrackInfo>&&, uint64_t)>&& completionHandler)
{
auto updateFormatDescriptionOperation = UpdateFormatDescriptionOperation { WTFMove(formatDescription), trackId, WTFMove(completionHandler) };
m_pendingOperations.append({ WTFMove(updateFormatDescriptionOperation) });
}

bool SourceBufferPrivate::validateInitializationSegment(const SourceBufferPrivateClient::InitializationSegment& segment)
{
// * If more than one track for a single type are present (ie 2 audio tracks), then the Track
Expand Down Expand Up @@ -741,6 +747,8 @@ void SourceBufferPrivate::processPendingOperations()
auto operation = m_pendingOperations.takeFirst();
std::visit(WTF::makeVisitor([&](InitOperation&& initOperation) {
processInitOperation(WTFMove(initOperation));
}, [&](UpdateFormatDescriptionOperation&& operation) {
operation.completionHandler(WTFMove(operation.formatDescription), operation.trackId);
}, [&](SamplesVector&& samples) {
processMediaSamplesOperation(WTFMove(samples));
}, [&](ResetParserOperation&&) {
Expand Down
8 changes: 7 additions & 1 deletion Source/WebCore/platform/graphics/SourceBufferPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,17 @@ class SourceBufferPrivate
Function<bool(InitializationSegment&)> check;
CompletionHandler<void(ReceiveResult)> completionHandler;
};
struct UpdateFormatDescriptionOperation {
Ref<TrackInfo> formatDescription;
uint64_t trackId;
CompletionHandler<void(Ref<TrackInfo>&&, uint64_t)> completionHandler;
};
using SamplesVector = Vector<Ref<MediaSample>>;
struct AppendCompletedOperation {
size_t abortCount { 0 };
Function<void()> preTask;
};
using Operation = std::variant<AppendBufferOperation, InitOperation, SamplesVector, ResetParserOperation, AppendCompletedOperation, ErrorOperation>;
using Operation = std::variant<AppendBufferOperation, InitOperation, UpdateFormatDescriptionOperation, SamplesVector, ResetParserOperation, AppendCompletedOperation, ErrorOperation>;
void queueOperation(Operation&&);

MediaTime currentMediaTime() const;
Expand All @@ -212,6 +217,7 @@ class SourceBufferPrivate
// that would prevent `this` to be deleted in case the SourceBufferClient detaches itself while an initialization
// is pending. Take a WeakPtr instead.
WEBCORE_EXPORT void didReceiveInitializationSegment(InitializationSegment&&, Function<bool(InitializationSegment&)>&&, CompletionHandler<void(ReceiveResult)>&&);
WEBCORE_EXPORT void didUpdateFormatDescriptionForTrackId(Ref<TrackInfo>&&, uint64_t, CompletionHandler<void(Ref<TrackInfo>&&, uint64_t)>&&);
WEBCORE_EXPORT void didReceiveSample(Ref<MediaSample>&&);
WEBCORE_EXPORT void setBufferedRanges(PlatformTimeRanges&&, CompletionHandler<void()>&& completionHandler = [] { });
void provideMediaData(const AtomString& trackID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,18 +527,23 @@ static bool sampleBufferRenderersSupportKeySession()

void SourceBufferPrivateAVFObjC::didUpdateFormatDescriptionForTrackId(Ref<TrackInfo>&& formatDescription, uint64_t trackId)
{
if (is<VideoInfo>(formatDescription)) {
auto result = m_videoTracks.find(AtomString::number(trackId));
if (result != m_videoTracks.end())
result->value->setFormatDescription(downcast<VideoInfo>(formatDescription.get()));
return;
}
SourceBufferPrivate::didUpdateFormatDescriptionForTrackId(WTFMove(formatDescription), trackId, [weakThis = WeakPtr { *this }, this](Ref<TrackInfo>&& formatDescription, uint64_t trackId) {
if (!weakThis)
return;

if (is<AudioInfo>(formatDescription)) {
auto result = m_audioTracks.find(AtomString::number(trackId));
if (result != m_audioTracks.end())
result->value->setFormatDescription(downcast<AudioInfo>(formatDescription.get()));
}
if (is<VideoInfo>(formatDescription)) {
auto result = m_videoTracks.find(AtomString::number(trackId));
if (result != m_videoTracks.end())
result->value->setFormatDescription(downcast<VideoInfo>(formatDescription.get()));
return;
}

if (is<AudioInfo>(formatDescription)) {
auto result = m_audioTracks.find(AtomString::number(trackId));
if (result != m_audioTracks.end())
result->value->setFormatDescription(downcast<AudioInfo>(formatDescription.get()));
}
});
}

void SourceBufferPrivateAVFObjC::willProvideContentKeyRequestInitializationDataForTrackID(uint64_t trackID)
Expand Down

0 comments on commit 49ba5f0

Please sign in to comment.