← All reports

VideoFrames cannot be created asynchronously in WebContent process

Component: WebKit GPU Process media | 6d5870d

Source/WebKit/GPUProcess/media/RemoteVideoFrameObjectHeap.cpp

+void RemoteVideoFrameObjectHeap::add(RemoteVideoFrameReference reference, Ref<WebCore::VideoFrame>&& frame)
+{
+ auto success = m_heap.add(reference, WTF::move(frame));
+ ASSERT_UNUSED(success, success);
+}
...
+static constexpr Seconds defaultTimeout = 10_s;
...
- return m_heap.read(WTF::move(read), 0_s);
+ auto timeout = isInGPUProcessObjectIdentifierDomain(read.identifier().toUInt64()) ? 0_s : defaultTimeout;
+ return m_heap.read(WTF::move(read), timeout);

GPU process의 RemoteVideoFrameObjectHeap은 RemoteVideoFrameReference ID를 살아 있는 VideoFrame 객체에 매핑합니다. WebContent 쪽은 이 frame들을 가리키는 RemoteVideoFrameProxy 객체를 보유합니다. 이후 frame을 그리거나 encode, sampling해야 할 때 해당 reference를 GPU process로 다시 전달합니다. WebGL, 2D canvas, WebGPU external texture, WebRTC encoder가 여기에 해당합니다.

이전에는 GPU process가 ID를 동기적으로 할당하고 reply에 담아 반환했습니다. 이 ID는 ObjectIdentifier domain에서 발급되는데, GPU process가 재시작되면 같은 base부터 다시 발급을 시작합니다. 그래서 이미 종료된 GPU process가 발급한 ID가 새 process에서는 전혀 무관한 frame을 가리킬 수 있습니다.

이번 변경으로 WebContent가 요청하는 frame에 대해서는 reference를 WebContent가 직접 할당하게 되었습니다. 할당된 reference는 RemoteGraphicsContextGL::SurfaceBufferToVideoFrame, RemoteAudioVideoRendererProxyManager::CurrentVideoFrame, RemoteMediaPlayerProxy::VideoFrameForCurrentTimeIfChanged에 새 인자로 추가되어 전달됩니다. GPU process는 새로 추가된 add(reference, frame)으로 frame을 저장하고, RemoteVideoFrameProxy::properties()로 reply를 구성합니다.

한편 GPU process가 자체적으로 생성하는 frame은 여전히 GPU process가 할당한 reference를 사용합니다. metadata, WebRTC decoder 출력, capture가 여기에 속합니다. 다만 이 reference는 이제 PushVideoFrameMetadata, CompletedDecoding, VideoFrameAvailable의 별도 인자로 전달됩니다. 또한 RemoteVideoFrameProxy::newReadReference()와 SharedVideoFrameWriter::write()가 IPC connection을 인자로 받도록 변경되었습니다. frame이 다른 GPU process connection에 묶여 있으면 두 함수 모두 실패합니다.

Before:                                   After:
WebContent        GPUProcess              WebContent             GPUProcess
  │ Request ───────► │                      │ reserve ref (WCP domain)
  │                  ├ heap.add(frame)→ref  │ Request(ref) ───────► │
  │ ◄── Properties(ref) ┤                   │                       ├ props = properties(frame)
  │ (blocks for ID)                         │ ◄── Properties ───────┤ heap.add(ref, frame)
                                            │ newReadReference(conn) -> fails if frame bound
                                            │   to a different GPUP connection

WebContent에서 reference를 미리 확보해 두면, fast path에서 video frame reference를 비동기적으로 생성할 수 있습니다. 더 빠른 frame 전달을 위한 기반 작업인 셈입니다. 이제 GPU process는 신뢰도가 낮은 WebContent process가 정한 ID로 frame을 등록하며, 이 경로는 WebGL, media player, audio/video renderer entry point 전반에 걸쳐 있습니다. 최상위 bit 기준으로 domain을 나눈 덕분에 두 process의 ID는 서로 충돌하지 않습니다. 또한 connection binding이 이전 GPU process에서 넘어온 stale ID를 걸러냅니다.

신뢰 관계에서 바뀐 지점은 ID가 이제 renderer에서 온다는 것입니다. 따라서 점검의 초점은 GPU process가 직접 발급하지 않은 ID를 어떻게 다루는지에 맞춰집니다.