Bug 257016 - Media recorder produces empty chunks
Summary: Media recorder produces empty chunks
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Canvas (show other bugs)
Version: Safari 16
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: youenn fablet
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2023-05-19 03:01 PDT by Jozef
Modified: 2023-05-24 09:19 PDT (History)
5 users (show)

See Also:


Attachments
canvas-bug-mwe (1.01 KB, text/html)
2023-05-19 03:01 PDT, Jozef
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jozef 2023-05-19 03:01:39 PDT
Created attachment 466413 [details]
canvas-bug-mwe

When attaching MediaStream before context in canvas is created then MediaRecorder produces only empty chunks.

Steps to replicate:

1. Open the provided html file
2. Click the button
3. You will see only empty chunks in console
4. Uncomment the line #14 and comment code on line #17
5. Click the button again
6. You will see one non-empty chunk in console
Comment 1 youenn fablet 2023-05-23 02:34:29 PDT
I reproduced the issue.
The difference seems to be that HTMLDocument is made observer of the canvas when it works and not when it works.
It follows that Document::canvasChanged is called which triggers preparation of canvas, which triggers a video frame in the stream.
Comment 2 Radar WebKit Bug Importer 2023-05-23 02:34:47 PDT
<rdar://problem/109705910>
Comment 3 youenn fablet 2023-05-23 02:36:54 PDT
In the failing case, CanvasCaptureMediaStreamTrack::Source::canvasChanged returns early because the rendering context needsPreparationForDisplay returns true.
But the document is not observing the canvas so ends up not triggering the code path of HTMLCanvasElement::prepareForDisplay.
Comment 4 youenn fablet 2023-05-23 03:48:59 PDT
Pull request: https://github.com/WebKit/WebKit/pull/14236
Comment 5 EWS 2023-05-24 09:19:36 PDT
Committed 264478@main (712b8a916d0d): <https://commits.webkit.org/264478@main>

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