MSE-in-Workers: Cross-thread function and tests (#26109)

Includes implementation of CrossThreadMediaSourceAttachment (CTMSA) and
updates to MediaSource and SourceBuffer to use it.

CTMSA owns a lock that it takes on most operations. It also provides a
utility method (RunExclusively()), which is used by the MSE API to take
that same lock during most operations on the API. The same thread
attachment provides a basic version of the same, though no lock is used.

CTMSA understands whether or not it is attached, has ever started
closing, and whether or not either of the attached contexts has ever
destructed. It conditions cross-thread operations to safely behave when
one or both contexts is being destructed.

MediaSource is given its own small lock that it uses to guard its
reference to the attachment instance, when attached. This is required
because attachment start is synchronous on the main thread, even if the
MediaSource is owned by worker context. CTMSA and MediaSource cooperate
to ensure mutex and safety of the two-stage attachment start. In
MediaSource::ContextDestroyed(), further care is taken to prevent
attachment start success when worker context destruction is possibly
racing the main thread's attempt to start attachment.
`context_already_destroyed_`, protected by MediaSource's lock, is used
to prevent that start from succeeding.

MediaSource's context destruction can no longer always assume that
accessing the demuxer via the WebMediaSource (and WebSourceBuffers) is
safe. The worker version of MediaSource context destruction uses the
attachment's RunExclusively() to safely know if it can cleanly Close the
underlying demuxer, or if instead it must do a simpler shutdown.

Future specification work will likely determine some signal to the media
element when the worker-owned MediaSource's context is shutdown, yet the
element itself is still alive. For now, sane results are returned by the
attachment (nothing buffered nor seekable), with no other error
provided. Possible app workarounds might include main and worker
watchdogs and being careful about when the main thread explicitly
terminates the worker.

This experimental implementation attempts to retain
BackgroundVideoOptimization, even for MSE-in-Workers, but does not
support AudioVideoTracks in the worker MediaSource or SourceBuffer.
Plumbing of appropriately-identified track metadata parsed from
initialization segment in the worker is used to populate (and remove)
media element AudioVideoTracks that should agree with the track id's
used internally in WebMediaPlayerImpl to accomplish
BackgroundVideoOptimization.

As a simplification, CTMSA assumes it can be used for at most one
attachment. Effectively, this assumes that the currently on-by-default
MediaSourceRevokeObjectURLOnAttach feature behavior will be always-on
soon. If CTMSA is not unregistered automatically after successful
attachment start (e.g., if that feature is disabled) and if the app
attempts to re-use the corresponding object URL for a later attachment,
that attachment will be rejected by CTMSA. Note that the same-thread
attachment would still allow such re-use when that feature is disabled.

Updated web-test:
  mediasource-worker-attach.html changed to ...-play.html and fixed
New web-test:
  mediasource-worker-play-terminate-worker.html
Manual test: page refreshing while running mediasource-worker-play*.html

BUG=878133

Change-Id: I21f6542b90d51bdc28096500fb1441d202ab4ee8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2459431
Commit-Queue: Matthew Wolenetz <wolenetz@chromium.org>
Reviewed-by: Will Cassella <cassew@google.com>
Cr-Commit-Position: refs/heads/master@{#818174}

Co-authored-by: Matt Wolenetz <wolenetz@chromium.org>
3 files changed
tree: 5cd8edb49cb9696b01a09fb3616894e3544d8a2a
  1. .github/
  2. .well-known/
  3. accelerometer/
  4. accname/
  5. acid/
  6. ambient-light/
  7. animation-worklet/
  8. annotation-model/
  9. annotation-protocol/
  10. annotation-vocab/
  11. apng/
  12. appmanifest/
  13. audio-output/
  14. background-fetch/
  15. BackgroundSync/
  16. badging/
  17. battery-status/
  18. beacon/
  19. bluetooth/
  20. clear-site-data/
  21. client-hints/
  22. clipboard-apis/
  23. common/
  24. compat/
  25. compression/
  26. conformance-checkers/
  27. console/
  28. contacts/
  29. content-dpr/
  30. content-index/
  31. content-security-policy/
  32. contenteditable/
  33. cookie-store/
  34. cookies/
  35. core-aam/
  36. cors/
  37. cors-rfc1918/
  38. credential-management/
  39. css/
  40. custom-elements/
  41. custom-state-pseudo-class/
  42. delegated-ink/
  43. density-size-correction/
  44. deprecation-reporting/
  45. device-memory/
  46. docs/
  47. document-policy/
  48. dom/
  49. domparsing/
  50. domxpath/
  51. dpub-aam/
  52. dpub-aria/
  53. editing/
  54. element-timing/
  55. encoding/
  56. encoding-detection/
  57. encrypted-media/
  58. entries-api/
  59. event-timing/
  60. eventsource/
  61. feature-policy/
  62. fetch/
  63. FileAPI/
  64. focus/
  65. font-access/
  66. fonts/
  67. forced-colors-mode/
  68. fullscreen/
  69. gamepad/
  70. generic-sensor/
  71. geolocation-API/
  72. geolocation-sensor/
  73. graphics-aam/
  74. gyroscope/
  75. hr-time/
  76. html/
  77. html-longdesc/
  78. html-media-capture/
  79. idle-detection/
  80. imagebitmap-renderingcontext/
  81. images/
  82. import-maps/
  83. IndexedDB/
  84. inert/
  85. infrastructure/
  86. input-device-capabilities/
  87. input-events/
  88. installedapp/
  89. interfaces/
  90. intersection-observer/
  91. intervention-reporting/
  92. is-input-pending/
  93. js/
  94. js-self-profiling/
  95. keyboard-lock/
  96. keyboard-map/
  97. largest-contentful-paint/
  98. layout-instability/
  99. lifecycle/
  100. loading/
  101. longtask-timing/
  102. magnetometer/
  103. mathml/
  104. measure-memory/
  105. media/
  106. media-capabilities/
  107. media-feeds/
  108. media-playback-quality/
  109. media-source/
  110. mediacapture-depth/
  111. mediacapture-fromelement/
  112. mediacapture-image/
  113. mediacapture-record/
  114. mediacapture-streams/
  115. mediasession/
  116. merchant-validation/
  117. mimesniff/
  118. mixed-content/
  119. mst-content-hint/
  120. native-file-system/
  121. native-io/
  122. navigation-timing/
  123. netinfo/
  124. network-error-logging/
  125. notifications/
  126. old-tests/
  127. orientation-event/
  128. orientation-sensor/
  129. origin-isolation/
  130. origin-policy/
  131. page-lifecycle/
  132. page-visibility/
  133. paint-timing/
  134. payment-handler/
  135. payment-method-basic-card/
  136. payment-method-id/
  137. payment-request/
  138. performance-timeline/
  139. periodic-background-sync/
  140. permissions/
  141. permissions-request/
  142. permissions-revoke/
  143. picture-in-picture/
  144. pointerevents/
  145. pointerlock/
  146. portals/
  147. preload/
  148. presentation-api/
  149. priority-hints/
  150. proximity/
  151. push-api/
  152. quirks/
  153. raw-sockets/
  154. referrer-policy/
  155. remote-playback/
  156. reporting/
  157. requestidlecallback/
  158. resize-observer/
  159. resource-timing/
  160. resources/
  161. sanitizer-api/
  162. savedata/
  163. screen-capture/
  164. screen-orientation/
  165. screen-wake-lock/
  166. screen_enumeration/
  167. scroll-animations/
  168. scroll-to-text-fragment/
  169. secure-contexts/
  170. secure-payment-confirmation/
  171. selection/
  172. serial/
  173. server-timing/
  174. service-workers/
  175. shadow-dom/
  176. shape-detection/
  177. signed-exchange/
  178. speech-api/
  179. storage/
  180. storage-access-api/
  181. streams/
  182. subresource-integrity/
  183. svg/
  184. svg-aam/
  185. timing-entrytypes-registry/
  186. tools/
  187. touch-events/
  188. trust-tokens/
  189. trusted-types/
  190. ua-client-hints/
  191. uievents/
  192. upgrade-insecure-requests/
  193. url/
  194. user-timing/
  195. vibration/
  196. video-rvfc/
  197. visual-viewport/
  198. wai-aria/
  199. wasm/
  200. web-animations/
  201. web-bundle/
  202. web-locks/
  203. web-nfc/
  204. web-otp/
  205. web-share/
  206. webaudio/
  207. webauthn/
  208. webcodecs/
  209. WebCryptoAPI/
  210. webdriver/
  211. webgl/
  212. webgpu/
  213. webhid/
  214. WebIDL/
  215. webmessaging/
  216. webmidi/
  217. webrtc/
  218. webrtc-extensions/
  219. webrtc-identity/
  220. webrtc-insertable-streams/
  221. webrtc-priority/
  222. webrtc-stats/
  223. webrtc-svc/
  224. websockets/
  225. webstorage/
  226. webtransport/
  227. webusb/
  228. webvr/
  229. webvtt/
  230. webxr/
  231. window-segments/
  232. workers/
  233. worklets/
  234. x-frame-options/
  235. xhr/
  236. xslt/
  237. .azure-pipelines.yml
  238. .codecov.yml
  239. .gitattributes
  240. .gitignore
  241. .mailmap
  242. .pyup.yml
  243. .taskcluster.yml
  244. CODE_OF_CONDUCT.md
  245. CODEOWNERS
  246. CONTRIBUTING.md
  247. LICENSE.md
  248. lint.ignore
  249. README.md
  250. testharness_runner.html
  251. update-built-tests.sh
  252. wpt
  253. wpt.py
README.md

The web-platform-tests Project

Taskcluster CI Status documentation manifest Python 3

The web-platform-tests Project is a cross-browser test suite for the Web-platform stack. Writing tests in a way that allows them to be run in all browsers gives browser projects confidence that they are shipping software that is compatible with other implementations, and that later implementations will be compatible with their implementations. This in turn gives Web authors/developers confidence that they can actually rely on the Web platform to deliver on the promise of working across browsers and devices without needing extra layers of abstraction to paper over the gaps left by specification editors and implementors.

The most important sources of information and activity are:

  • github.com/web-platform-tests/wpt: the canonical location of the project's source code revision history and the discussion forum for changes to the code
  • web-platform-tests.org: the documentation website; details how to set up the project, how to write tests, how to give and receive peer review, how to serve as an administrator, and more
  • wpt.live: a public deployment of the test suite, allowing anyone to run the tests by visiting from an Internet-enabled browser of their choice
  • wpt.fyi: an archive of test results collected from an array of web browsers on a regular basis
  • Real-time chat room: the IRC chat room named #testing on irc.w3.org; includes participants located around the world, but busiest during the European working day; all discussion is archived here
  • Mailing list: a public and low-traffic discussion list
  • RFCs: a repo for requesting comments on substantial changes that would impact other stakeholders or users; people who work on WPT infra are encouraged to watch the repo.

If you'd like clarification about anything, don't hesitate to ask in the chat room or on the mailing list.

Setting Up the Repo

Clone or otherwise get https://github.com/web-platform-tests/wpt.

Note: because of the frequent creation and deletion of branches in this repo, it is recommended to “prune” stale branches when fetching updates, i.e. use git pull --prune (or git fetch -p && git merge).

Running the Tests

See the documentation website and in particular the system setup for running tests locally.

Command Line Tools

The wpt command provides a frontend to a variety of tools for working with and running web-platform-tests. Some of the most useful commands are:

  • wpt serve - For starting the wpt http server
  • wpt run - For running tests in a browser
  • wpt lint - For running the lint against all tests
  • wpt manifest - For updating or generating a MANIFEST.json test manifest
  • wpt install - For installing the latest release of a browser or webdriver server on the local machine.
  • wpt serve-wave - For starting the wpt http server and the WAVE test runner. For more details on how to use the WAVE test runner see the documentation.

Windows Notes

On Windows wpt commands must be prefixed with python or the path to the python binary (if python is not in your %PATH%).

python wpt [command]

Alternatively, you may also use Bash on Ubuntu on Windows in the Windows 10 Anniversary Update build, then access your windows partition from there to launch wpt commands.

Please make sure git and your text editor do not automatically convert line endings, as it will cause lint errors. For git, please set git config core.autocrlf false in your working tree.

Publication

The master branch is automatically synced to http://w3c-test.org/.

Pull requests are automatically mirrored except those that modify sensitive resources (such as .py). The latter require someone with merge access to comment with “LGTM” or “w3c-test:mirror” to indicate the pull request has been checked.

Branches

In the vast majority of cases the only upstream branch that you should need to care about is master. If you see other branches in the repository, you can generally safely ignore them.

Contributing

Save the Web, Write Some Tests!

Absolutely everyone is welcome to contribute to test development. No test is too small or too simple, especially if it corresponds to something for which you've noted an interoperability bug in a browser.

The way to contribute is just as usual:

  • Fork this repository (and make sure you're still relatively in sync with it if you forked a while ago).
  • Create a branch for your changes: git checkout -b topic.
  • Make your changes.
  • Run ./wpt lint as described above.
  • Commit locally and push that to your repo.
  • Create a pull request based on the above.

Issues with web-platform-tests

If you spot an issue with a test and are not comfortable providing a pull request per above to fix it, please file a new issue. Thank you!