Bug 257016

Summary: Media recorder produces empty chunks
Product: WebKit Reporter: Jozef <32jojo32>
Component: CanvasAssignee: youenn fablet <youennf>
Status: RESOLVED FIXED    
Severity: Normal CC: dino, eric.carlson, jer.noble, webkit-bug-importer, youennf
Priority: P2 Keywords: InRadar
Version: Safari 16   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
canvas-bug-mwe none

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.