Skip to content

Conversation

jyavenard
Copy link
Member

@jyavenard jyavenard commented Nov 15, 2023

19836c7

Use NativePromise chaining in place of operations queue in SourceBufferPrivate
https://bugs.webkit.org/show_bug.cgi?id=264854
rdar://118429088

Reviewed by Jer Noble.

By using promise chaining we can remove the need for an operations queue to serialise the tasks.
It also makes the code easier to read/follow as the entire appendBuffer operation is now available at a
glance.
This will simplify making SourceBufferPrivate::append/removeCodedFrames be made asynchronous and use
NativePromise.

* Source/WebCore/platform/graphics/SourceBufferPrivate.cpp:
(WebCore::SourceBufferPrivate::didReceiveInitializationSegment):
(WebCore::SourceBufferPrivate::didUpdateFormatDescriptionForTrackId):
(WebCore::SourceBufferPrivate::didReceiveSample):
(WebCore::SourceBufferPrivate::append):
(WebCore::SourceBufferPrivate::processPendingMediaSamples):
(WebCore::SourceBufferPrivate::processMediaSample):
(WebCore::SourceBufferPrivate::resetParserState):
(WebCore::SourceBufferPrivate::memoryPressure):
(WebCore::SourceBufferPrivate::~SourceBufferPrivate): Deleted.
(WebCore::SourceBufferPrivate::advanceOperationState): Deleted.
(WebCore::SourceBufferPrivate::rewindOperationState): Deleted.
(WebCore::SourceBufferPrivate::processAppendCompletedOperation): Deleted.
(WebCore::SourceBufferPrivate::queueOperation): Deleted.
(WebCore::SourceBufferPrivate::processPendingOperations): Deleted.
(WebCore::SourceBufferPrivate::abortPendingOperations): Deleted.
(WebCore::SourceBufferPrivate::processError): Deleted.
(WebCore::SourceBufferPrivate::processInitOperation): Deleted.
(WebCore::SourceBufferPrivate::processMediaSamplesOperation): Deleted.
* Source/WebCore/platform/graphics/SourceBufferPrivate.h:
* Source/WebCore/platform/graphics/gstreamer/mse/SourceBufferPrivateGStreamer.cpp:
(WebCore::SourceBufferPrivateGStreamer::didReceiveAllPendingSamples): Test that the promise wasn't previously resolved.
fallout from bug 264847.
(WebCore::SourceBufferPrivateGStreamer::appendParsingFailed):

Canonical link: https://commits.webkit.org/270808@main

96a3f81

Misc iOS, tvOS & watchOS macOS Linux Windows
✅ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ❌ 🛠 wpe ✅ 🛠 wincairo
✅ 🧪 bindings ✅ 🛠 ios-sim ✅ 🛠 mac-AS-debug ❌ 🧪 wpe-wk2
✅ 🧪 webkitperl ✅ 🧪 ios-wk2 ✅ 🧪 api-mac ❌ 🧪 api-wpe
🧪 ios-wk2-wpt ✅ 🧪 mac-wk1 ❌ 🛠 gtk
✅ 🧪 api-ios ✅ 🧪 mac-wk2 ❌ 🧪 gtk-wk2
✅ 🛠 tv 🧪 mac-AS-debug-wk2 ❌ 🧪 api-gtk
✅ 🛠 tv-sim
✅ 🛠 🧪 merge ✅ 🛠 watch
✅ 🛠 watch-sim

@jyavenard jyavenard self-assigned this Nov 15, 2023
@jyavenard jyavenard added the Media Bugs related to the HTML 5 Media elements. label Nov 15, 2023
Comment on lines 41 to 46
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional and Vector.h don't appear to be used in the header. Can these be removed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they were used, I added them because compilation broke elsewhere following unified build changes.
We have Vector<PlatformTimeRanges> activeRanges() method .
and we have std::optional<SeekTarget> m_pendingSeekTarget; class member

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pattern is repeated a lot; I assume that -1 will be replaced with a PlatformMediaError in a future patch?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes... The "PR#4" adds PlatformMediaError and those are replaced everywhere

Comment on lines 199 to 202
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this could just be removed entirely.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes indeed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be -1? (Or it doesn't matter because this will be a PlatformMediaError in the future.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the optional.h from above needs to move here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like sendWithPromisedReply(...) should have a variant that doesn't take a lambda, and just creates and returns a GenericPromise with the result.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sendWithPromisedReply doesn't take anything, it returns a NativePromise. You don't have to act on the promise

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue is returning the IPC error code; this wasn't handled before, and code always assumed that sending an IPC message was successful. We needed a way to pass that error. Merging the error code with the PlatformMediaError would be nice, but I don't know how that will play for consistency.

sendWithMediaPromisedReply could do that maybe

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto here. For a result that's an optional<>, it could create or reject based on whether the optional has a value.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the result is an Expected<T, U> The IPC Promise wraps the type set in the messages.in file, and an IPCError as exception.

It forces you to deal with the error if there's one.

@jyavenard jyavenard added merge-queue Applied to send a pull request to merge-queue and removed merge-queue Applied to send a pull request to merge-queue labels Nov 15, 2023
@jyavenard jyavenard force-pushed the bz/264854_Use_NativePromise_chaining_in_place_of_operations_queue_in_SourceBufferPrivate branch from 61a0298 to 506ce07 Compare November 15, 2023 22:09
@jyavenard jyavenard force-pushed the bz/264854_Use_NativePromise_chaining_in_place_of_operations_queue_in_SourceBufferPrivate branch from 506ce07 to 4db2465 Compare November 15, 2023 22:40
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Nov 15, 2023
@jyavenard jyavenard removed the merging-blocked Applied to prevent a change from being merged label Nov 15, 2023
@jyavenard jyavenard force-pushed the bz/264854_Use_NativePromise_chaining_in_place_of_operations_queue_in_SourceBufferPrivate branch from 4db2465 to 8a6a086 Compare November 15, 2023 23:19
@jyavenard jyavenard force-pushed the bz/264854_Use_NativePromise_chaining_in_place_of_operations_queue_in_SourceBufferPrivate branch from 8a6a086 to 9aedfbe Compare November 16, 2023 00:12
@jyavenard jyavenard force-pushed the bz/264854_Use_NativePromise_chaining_in_place_of_operations_queue_in_SourceBufferPrivate branch from 9aedfbe to 0e53637 Compare November 16, 2023 00:59
@jyavenard jyavenard force-pushed the bz/264854_Use_NativePromise_chaining_in_place_of_operations_queue_in_SourceBufferPrivate branch from 0e53637 to 96a3f81 Compare November 16, 2023 03:04
@jyavenard jyavenard added the merge-queue Applied to send a pull request to merge-queue label Nov 16, 2023
@webkit-commit-queue webkit-commit-queue force-pushed the bz/264854_Use_NativePromise_chaining_in_place_of_operations_queue_in_SourceBufferPrivate branch from 96a3f81 to 543ec10 Compare November 16, 2023 06:10
…erPrivate

https://bugs.webkit.org/show_bug.cgi?id=264854
rdar://118429088

Reviewed by Jer Noble.

By using promise chaining we can remove the need for an operations queue to serialise the tasks.
It also makes the code easier to read/follow as the entire appendBuffer operation is now available at a
glance.
This will simplify making SourceBufferPrivate::append/removeCodedFrames be made asynchronous and use
NativePromise.

* Source/WebCore/platform/graphics/SourceBufferPrivate.cpp:
(WebCore::SourceBufferPrivate::didReceiveInitializationSegment):
(WebCore::SourceBufferPrivate::didUpdateFormatDescriptionForTrackId):
(WebCore::SourceBufferPrivate::didReceiveSample):
(WebCore::SourceBufferPrivate::append):
(WebCore::SourceBufferPrivate::processPendingMediaSamples):
(WebCore::SourceBufferPrivate::processMediaSample):
(WebCore::SourceBufferPrivate::resetParserState):
(WebCore::SourceBufferPrivate::memoryPressure):
(WebCore::SourceBufferPrivate::~SourceBufferPrivate): Deleted.
(WebCore::SourceBufferPrivate::advanceOperationState): Deleted.
(WebCore::SourceBufferPrivate::rewindOperationState): Deleted.
(WebCore::SourceBufferPrivate::processAppendCompletedOperation): Deleted.
(WebCore::SourceBufferPrivate::queueOperation): Deleted.
(WebCore::SourceBufferPrivate::processPendingOperations): Deleted.
(WebCore::SourceBufferPrivate::abortPendingOperations): Deleted.
(WebCore::SourceBufferPrivate::processError): Deleted.
(WebCore::SourceBufferPrivate::processInitOperation): Deleted.
(WebCore::SourceBufferPrivate::processMediaSamplesOperation): Deleted.
* Source/WebCore/platform/graphics/SourceBufferPrivate.h:
* Source/WebCore/platform/graphics/gstreamer/mse/SourceBufferPrivateGStreamer.cpp:
(WebCore::SourceBufferPrivateGStreamer::didReceiveAllPendingSamples): Test that the promise wasn't previously resolved.
fallout from bug 264847.
(WebCore::SourceBufferPrivateGStreamer::appendParsingFailed):

Canonical link: https://commits.webkit.org/270808@main
@webkit-commit-queue webkit-commit-queue force-pushed the bz/264854_Use_NativePromise_chaining_in_place_of_operations_queue_in_SourceBufferPrivate branch from 543ec10 to 19836c7 Compare November 16, 2023 06:15
@webkit-commit-queue webkit-commit-queue merged commit 19836c7 into WebKit:main Nov 16, 2023
@webkit-commit-queue
Copy link
Collaborator

Committed 270808@main (19836c7): https://commits.webkit.org/270808@main

Reviewed commits have been landed. Closing PR #20516 and removing active labels.

@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Nov 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Media Bugs related to the HTML 5 Media elements.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants