← All reports

WebCodecs `VideoDecoderConfig` rotation and flip (new feature)

Component: WebCore WebCodecs | d49592f

Source/WebCore/Modules/webcodecs/WebCodecsVideoDecoder.cpp

+ .rotation = parseVideoFrameRotation(config.rotation),
+ .isMirrored = config.flip
...
+ // Decoder는 configuration의 orientation으로 frame을 생성해야 합니다. orientation을 인식하지 못하는 decoder를 위해 여기서 override합니다.
+ frame = frame->updateOrientation(rotation, isMirrored, VideoFrame::ShouldClone::No);
+ auto presentationSize = frame->presentationSize();
...
+ .displayWidth = static_cast<size_t>(frame->rotatedSize().width()),
+ .displayHeight = static_cast<size_t>(frame->rotatedSize().height()),

Source/WebKit/GPUProcess/webrtc/LibWebRTCCodecsProxy.messages.in

+ CreateDecoder(..., struct std::optional<WebCore::PlatformVideoColorSpace> colorSpaceOverride, enum:uint16_t WebCore::VideoFrameRotation rotation, bool isMirrored) -> (bool success);

WebCodecs VideoDecoder는 web content가 decoder를 구성하고 VideoFrame 객체를 받을 수 있게 하는 API입니다. WebKit에서는 이 decoder가 GPU process에 위치하는 경우가 많습니다. 이때 요청은 LibWebRTCCodecs에서 IPC를 거쳐 LibWebRTCCodecsProxy로 전달되고, frame은 CVPixelBuffer 기반 객체로 반환됩니다. 이번 commit에서는 VideoDecoderConfig WebIDL에 rotation과 flip이 추가되었습니다. 두 필드는 WebCodecsVideoFrameRotationEnabled 설정으로 gating됩니다. 먼저 값은 LibWebRTCCodecs와 CreateDecoder IPC 메시지를 거쳐 libwebrtc VPX decoder와 GStreamer decoder까지 전달되도록 구현되었습니다. 이후 decode된 frame은 노출 직전에 orientation이 override됩니다. 한편 LibWebRTCCodecs::createDecoder를 거치는 WebRTC 경로에서는 None/false가 hardcode되어 있습니다.

WebCodecs decoder가 config의 orientation을 반영하게 되면서, AV1, H.264, H.265, VP8, VP9의 WPT orientation 테스트가 FAIL에서 PASS로 바뀌었습니다. 동시에 WebContent에서 GPU로 향하는 decoder 생성 IPC에 web content가 제어할 수 있는 필드가 추가되었습니다.

Narrow: rotation은 enum:uint16_t 형태로 전달됩니다. 따라서 compromised WebContent process가 범위를 벗어난 값을 보냈을 때 GPU process handler가 이를 어떻게 처리하는지 확인할 필요가 있습니다. local, remote, VPX, GStreamer 경로 사이에서 validation이 일관적인지도 함께 살펴봐야 합니다. 또한 90/270 rotation에서는 rotatedSize()(display 크기)와 presentationSize()(coded 크기)가 서로 달라집니다. 이 차이가 visible rect, canvas drawing, copyTo, texture upload와 어떻게 맞물리는지 점검이 필요합니다. 이 지점들에서는 width/height가 뒤바뀌면서 크기 불일치가 발생할 가능성이 있습니다. Wider: LibWebRTCCodecs::completedDecodingCV와 LibWebRTCVPXInternalVideoDecoder::Decoded는 decoder callback thread에서 저장된 rotation 값을 frame에 기록합니다. 그래서 저장된 값의 lifetime과 thread-safety를 확인해야 합니다. 아울러 확장된 createDecoder / createDecoderAndWaitUntilReady / createDecoderInternal signature의 모든 호출 지점이 일관된 값을 전달하는지도 검증이 필요합니다.