Title: [268971] trunk
Revision
268971
Author
[email protected]
Date
2020-10-26 05:50:41 -0700 (Mon, 26 Oct 2020)

Log Message

Add support for VP9 Profile 2 (10-bit color) in WebRTC
https://bugs.webkit.org/show_bug.cgi?id=217673
<rdar://problem/70283885>

Reviewed by Eric Carlson.

Source/ThirdParty/libwebrtc:

Add support for VP9 profile 0 and 2.
This requires correctly handling 10-bit decoded buffers as is done by the MSE code path.

* Configurations/libwebrtc.iOS.exp:
* Configurations/libwebrtc.iOSsim.exp:
* Configurations/libwebrtc.mac.exp:
* Source/webrtc/sdk/WebKit/WebKitUtilities.h:
* Source/webrtc/sdk/WebKit/WebKitUtilities.mm:
(webrtc::pixelBufferFromFrame):
* Source/webrtc/sdk/WebKit/WebKitVP9Decoder.cpp:
(webrtc::WebKitVP9DecoderReceiver::Decoded):
* Source/webrtc/sdk/objc/api/video_codec/RTCVideoEncoderVP9.h:
* Source/webrtc/sdk/objc/api/video_codec/RTCVideoEncoderVP9.mm:
(+[RTCVideoEncoderVP9 vp9Encoder:]):
* Source/webrtc/sdk/objc/components/video_codec/RTCDefaultVideoDecoderFactory.m:
(-[RTCDefaultVideoDecoderFactory supportedCodecs]):
* Source/webrtc/sdk/objc/components/video_codec/RTCDefaultVideoEncoderFactory.m:
(+[RTCDefaultVideoEncoderFactory supportedCodecsWithH265:vp9:]):
(-[RTCDefaultVideoEncoderFactory createEncoder:]):

Source/WebCore:

In case software VP9 decoded buffer is 10 bits, we use kCVPixelFormatType_420YpCbCr10BiPlanarFullRange.

Test: webrtc/vp9-profile2.html

* platform/mediastream/mac/RealtimeIncomingVideoSourceCocoa.h:
* platform/mediastream/mac/RealtimeIncomingVideoSourceCocoa.mm:
(WebCore::RealtimeIncomingVideoSourceCocoa::pixelBufferPool):
(WebCore::RealtimeIncomingVideoSourceCocoa::pixelBufferFromVideoFrame):
* platform/mediastream/mac/RealtimeVideoUtilities.h:
* platform/mediastream/mac/RealtimeVideoUtilities.mm:
(WebCore::createPixelBufferPool):

Source/WebKit:

* WebProcess/GPU/webrtc/LibWebRTCCodecs.cpp:
(WebKit::LibWebRTCCodecs::pixelBufferPool):

LayoutTests:

* webrtc/vp9-profile2-expected.txt: Added.
* webrtc/vp9-profile2.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (268970 => 268971)


--- trunk/LayoutTests/ChangeLog	2020-10-26 12:42:18 UTC (rev 268970)
+++ trunk/LayoutTests/ChangeLog	2020-10-26 12:50:41 UTC (rev 268971)
@@ -1,3 +1,14 @@
+2020-10-26  Youenn Fablet  <[email protected]>
+
+        Add support for VP9 Profile 2 (10-bit color) in WebRTC
+        https://bugs.webkit.org/show_bug.cgi?id=217673
+        <rdar://problem/70283885>
+
+        Reviewed by Eric Carlson.
+
+        * webrtc/vp9-profile2-expected.txt: Added.
+        * webrtc/vp9-profile2.html: Added.
+
 2020-10-26  Philippe Normand  <[email protected]>
 
         Unreviewed, GStreamer WebAudio gardening

Added: trunk/LayoutTests/webrtc/vp9-profile2-expected.txt (0 => 268971)


--- trunk/LayoutTests/webrtc/vp9-profile2-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/webrtc/vp9-profile2-expected.txt	2020-10-26 12:50:41 UTC (rev 268971)
@@ -0,0 +1,10 @@
+
+
+PASS VP9 profile 2 in getCapabilities
+PASS Verify VP9 activation
+PASS Setting video exchange
+PASS Ensuring connection state is connected
+PASS Track is enabled, video should not be black
+PASS Track is disabled, video should be black
+PASS Track is enabled, video should not be black 2
+

Added: trunk/LayoutTests/webrtc/vp9-profile2.html (0 => 268971)


--- trunk/LayoutTests/webrtc/vp9-profile2.html	                        (rev 0)
+++ trunk/LayoutTests/webrtc/vp9-profile2.html	2020-10-26 12:50:41 UTC (rev 268971)
@@ -0,0 +1,90 @@
+<!doctype html>
+<html>
+    <head>
+        <meta charset="utf-8">
+        <title>VP9 in WebRTC</title>
+        <script src=""
+        <script src=""
+    </head>
+    <body>
+        <video id="video" autoplay playsInline width="320" height="240"></video>
+        <canvas id="canvas1" width="320" height="240"></canvas>
+        <canvas id="canvas2" width="320" height="240"></canvas>
+        <canvas id="canvas3" width="320" height="240"></canvas>
+        <script src =""
+        <script>
+let vp9Profile2;
+test(() => {
+    codecs = RTCRtpSender.getCapabilities("video").codecs;
+    vp9Profiles = codecs.filter(codec => { return codec.mimeType === "video/VP9" && codec.sdpFmtpLine === "profile-id=2"; });
+    assert_equals(vp9Profiles.length, 1);
+    vp9Profile2 = vp9Profiles[0];
+}, "VP9 profile 2 in getCapabilities");
+
+if (vp9Profile2) {
+    promise_test(async (test) => {
+        const pc = new RTCPeerConnection();
+        const transceiver = pc.addTransceiver("video");
+        transceiver.setCodecPreferences([vp9Profile2]);
+        const description = await pc.createOffer();
+        pc.close();
+        assert_true(description.sdp.indexOf("VP9") !== -1, "VP9 codec is in the SDP");
+    }, "Verify VP9 activation")
+
+    var track;
+    var remoteTrack;
+    var receivingConnection;
+    var sendingConnection;
+    promise_test((test) => {
+        return navigator.mediaDevices.getUserMedia({video: {width: 320, height: 240, facingMode: "environment"}}).then((localStream) => {
+            return new Promise((resolve, reject) => {
+                track = localStream.getVideoTracks()[0];
+
+                createConnections((firstConnection) => {
+                    sendingConnection = firstConnection;
+                    firstConnection.addTrack(track, localStream);
+                    firstConnection.getTransceivers()[0].setCodecPreferences([vp9Profile2]);
+                }, (secondConnection) => {
+                    receivingConnection = secondConnection;
+                    secondConnection._ontrack_ = (trackEvent) => {
+                        remoteTrack = trackEvent.track;
+                        resolve(trackEvent.streams[0]);
+                    };
+                });
+                setTimeout(() => reject("Test timed out"), 5000);
+            });
+        }).then((remoteStream) => {
+            video.srcObject = remoteStream;
+            return video.play();
+        });
+    }, "Setting video exchange");
+
+    promise_test(() => {
+        if (receivingConnection.connectionState === "connected")
+            return Promise.resolve();
+        return new Promise((resolve, reject) => {
+            receivingConnection._onconnectionstatechange_ = () => {
+                if (receivingConnection.connectionState === "connected")
+                    resolve();
+            };
+            setTimeout(() => reject("Test timed out"), 5000);
+        });
+    }, "Ensuring connection state is connected");
+
+    promise_test((test) => {
+        return checkVideoBlack(false, canvas1, video);
+    }, "Track is enabled, video should not be black");
+
+    promise_test((test) => {
+        track.enabled = false;
+        return checkVideoBlack(true, canvas2, video);
+    }, "Track is disabled, video should be black");
+
+    promise_test((test) => {
+        track.enabled = true;
+        return checkVideoBlack(false, canvas2, video);
+    }, "Track is enabled, video should not be black 2");
+}
+        </script>
+    </body>
+</html>

Modified: trunk/Source/ThirdParty/libwebrtc/ChangeLog (268970 => 268971)


--- trunk/Source/ThirdParty/libwebrtc/ChangeLog	2020-10-26 12:42:18 UTC (rev 268970)
+++ trunk/Source/ThirdParty/libwebrtc/ChangeLog	2020-10-26 12:50:41 UTC (rev 268971)
@@ -1,3 +1,31 @@
+2020-10-26  Youenn Fablet  <[email protected]>
+
+        Add support for VP9 Profile 2 (10-bit color) in WebRTC
+        https://bugs.webkit.org/show_bug.cgi?id=217673
+        <rdar://problem/70283885>
+
+        Reviewed by Eric Carlson.
+
+        Add support for VP9 profile 0 and 2.
+        This requires correctly handling 10-bit decoded buffers as is done by the MSE code path.
+
+        * Configurations/libwebrtc.iOS.exp:
+        * Configurations/libwebrtc.iOSsim.exp:
+        * Configurations/libwebrtc.mac.exp:
+        * Source/webrtc/sdk/WebKit/WebKitUtilities.h:
+        * Source/webrtc/sdk/WebKit/WebKitUtilities.mm:
+        (webrtc::pixelBufferFromFrame):
+        * Source/webrtc/sdk/WebKit/WebKitVP9Decoder.cpp:
+        (webrtc::WebKitVP9DecoderReceiver::Decoded):
+        * Source/webrtc/sdk/objc/api/video_codec/RTCVideoEncoderVP9.h:
+        * Source/webrtc/sdk/objc/api/video_codec/RTCVideoEncoderVP9.mm:
+        (+[RTCVideoEncoderVP9 vp9Encoder:]):
+        * Source/webrtc/sdk/objc/components/video_codec/RTCDefaultVideoDecoderFactory.m:
+        (-[RTCDefaultVideoDecoderFactory supportedCodecs]):
+        * Source/webrtc/sdk/objc/components/video_codec/RTCDefaultVideoEncoderFactory.m:
+        (+[RTCDefaultVideoEncoderFactory supportedCodecsWithH265:vp9:]):
+        (-[RTCDefaultVideoEncoderFactory createEncoder:]):
+
 2020-10-24  Jer Noble  <[email protected]>
 
         [BigSur] Appending a new WebM init segment between Cluster elements throws an error

Modified: trunk/Source/ThirdParty/libwebrtc/Configurations/libwebrtc.iOS.exp (268970 => 268971)


--- trunk/Source/ThirdParty/libwebrtc/Configurations/libwebrtc.iOS.exp	2020-10-26 12:42:18 UTC (rev 268970)
+++ trunk/Source/ThirdParty/libwebrtc/Configurations/libwebrtc.iOS.exp	2020-10-26 12:50:41 UTC (rev 268971)
@@ -109,7 +109,7 @@
 __ZN6webrtc29setH264HardwareEncoderAllowedEb
 __ZN6webrtc31setH264LowLatencyEncoderEnabledEb
 __ZN6webrtc24registerWebKitVP9DecoderEv
-__ZN6webrtc20pixelBufferFromFrameERKNS_10VideoFrameERKNSt3__18functionIFP10__CVBuffermmEEE
+__ZN6webrtc20pixelBufferFromFrameERKNS_10VideoFrameERKNSt3__18functionIFP10__CVBuffermmNS_10BufferTypeEEEE
 __ZN6webrtc18pixelBufferToFrameEP10__CVBuffer
 __ZN3rtc24BasicPacketSocketFactory19CreateAsyncResolverEv
 __ZN3rtc24BasicPacketSocketFactoryC2Ev

Modified: trunk/Source/ThirdParty/libwebrtc/Configurations/libwebrtc.iOSsim.exp (268970 => 268971)


--- trunk/Source/ThirdParty/libwebrtc/Configurations/libwebrtc.iOSsim.exp	2020-10-26 12:42:18 UTC (rev 268970)
+++ trunk/Source/ThirdParty/libwebrtc/Configurations/libwebrtc.iOSsim.exp	2020-10-26 12:50:41 UTC (rev 268971)
@@ -109,7 +109,7 @@
 __ZN6webrtc29setH264HardwareEncoderAllowedEb
 __ZN6webrtc31setH264LowLatencyEncoderEnabledEb
 __ZN6webrtc24registerWebKitVP9DecoderEv
-__ZN6webrtc20pixelBufferFromFrameERKNS_10VideoFrameERKNSt3__18functionIFP10__CVBuffermmEEE
+__ZN6webrtc20pixelBufferFromFrameERKNS_10VideoFrameERKNSt3__18functionIFP10__CVBuffermmNS_10BufferTypeEEEE
 __ZN6webrtc18pixelBufferToFrameEP10__CVBuffer
 __ZN3rtc24BasicPacketSocketFactory19CreateAsyncResolverEv
 __ZN3rtc24BasicPacketSocketFactoryC2Ev

Modified: trunk/Source/ThirdParty/libwebrtc/Configurations/libwebrtc.mac.exp (268970 => 268971)


--- trunk/Source/ThirdParty/libwebrtc/Configurations/libwebrtc.mac.exp	2020-10-26 12:42:18 UTC (rev 268970)
+++ trunk/Source/ThirdParty/libwebrtc/Configurations/libwebrtc.mac.exp	2020-10-26 12:50:41 UTC (rev 268971)
@@ -109,7 +109,7 @@
 __ZN6webrtc29setH264HardwareEncoderAllowedEb
 __ZN6webrtc31setH264LowLatencyEncoderEnabledEb
 __ZN6webrtc24registerWebKitVP9DecoderEv
-__ZN6webrtc20pixelBufferFromFrameERKNS_10VideoFrameERKNSt3__18functionIFP10__CVBuffermmEEE
+__ZN6webrtc20pixelBufferFromFrameERKNS_10VideoFrameERKNSt3__18functionIFP10__CVBuffermmNS_10BufferTypeEEEE
 __ZN6webrtc18pixelBufferToFrameEP10__CVBuffer
 __ZN3rtc24BasicPacketSocketFactory19CreateAsyncResolverEv
 __ZN3rtc24BasicPacketSocketFactoryC2Ev

Modified: trunk/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/WebKit/WebKitUtilities.h (268970 => 268971)


--- trunk/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/WebKit/WebKitUtilities.h	2020-10-26 12:42:18 UTC (rev 268970)
+++ trunk/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/WebKit/WebKitUtilities.h	2020-10-26 12:50:41 UTC (rev 268971)
@@ -55,9 +55,8 @@
 void setH264LowLatencyEncoderEnabled(bool);
 bool isH264LowLatencyEncoderEnabled();
 
-CVPixelBufferRef pixelBufferFromFrame(const VideoFrame&, const std::function<CVPixelBufferRef(size_t, size_t)>&);
+enum class BufferType { I420, I010 };
+CVPixelBufferRef pixelBufferFromFrame(const VideoFrame&, const std::function<CVPixelBufferRef(size_t, size_t, BufferType)>&);
 rtc::scoped_refptr<webrtc::VideoFrameBuffer> pixelBufferToFrame(CVPixelBufferRef);
 
-CVPixelBufferPoolRef createPixelBufferPool(size_t width, size_t height);
-
 }

Modified: trunk/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/WebKit/WebKitUtilities.mm (268970 => 268971)


--- trunk/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/WebKit/WebKitUtilities.mm	2020-10-26 12:42:18 UTC (rev 268970)
+++ trunk/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/WebKit/WebKitUtilities.mm	2020-10-26 12:50:41 UTC (rev 268971)
@@ -26,6 +26,7 @@
 #include "WebKitUtilities.h"
 
 #include "native/src/objc_frame_buffer.h"
+#include "rtc_base/logging.h"
 #include "third_party/libyuv/include/libyuv/convert_from.h"
 #include "libyuv/cpu_id.h"
 #include "libyuv/row.h"
@@ -197,21 +198,30 @@
     return true;
 }
 
-CVPixelBufferRef pixelBufferFromFrame(const VideoFrame& frame, const std::function<CVPixelBufferRef(size_t, size_t)>& makePixelBuffer)
+CVPixelBufferRef pixelBufferFromFrame(const VideoFrame& frame, const std::function<CVPixelBufferRef(size_t, size_t, BufferType)>& makePixelBuffer)
 {
-    if (frame.video_frame_buffer()->type() != VideoFrameBuffer::Type::kNative) {
-        auto pixelBuffer = makePixelBuffer(frame.video_frame_buffer()->width(), frame.video_frame_buffer()->height());
-        if (!pixelBuffer)
+    auto buffer = frame.video_frame_buffer();
+    if (buffer->type() != VideoFrameBuffer::Type::kNative) {
+        auto type = buffer->type();
+        if (type != VideoFrameBuffer::Type::kI420 && type != VideoFrameBuffer::Type::kI010) {
+            RTC_LOG(WARNING) << "Video frame buffer type is not expected.";
             return nullptr;
+        }
 
-        if (frame.video_frame_buffer()->type() == VideoFrameBuffer::Type::kI420)
-            CopyVideoFrameToPixelBuffer(frame.video_frame_buffer()->GetI420(), pixelBuffer);
-        else if (frame.video_frame_buffer()->type() == VideoFrameBuffer::Type::kI010)
-            CopyVideoFrameToPixelBuffer(frame.video_frame_buffer()->GetI010(), pixelBuffer);
+        auto pixelBuffer = makePixelBuffer(buffer->width(), buffer->height(), type == VideoFrameBuffer::Type::kI420 ? BufferType::I420 : BufferType::I010);
+        if (!pixelBuffer) {
+            RTC_LOG(WARNING) << "Pixel buffer creation failed.";
+            return nullptr;
+        }
+
+        if (type == VideoFrameBuffer::Type::kI420)
+            CopyVideoFrameToPixelBuffer(buffer->GetI420(), pixelBuffer);
+        else
+            CopyVideoFrameToPixelBuffer(buffer->GetI010(), pixelBuffer);
         return pixelBuffer;
     }
 
-    auto *frameBuffer = static_cast<ObjCFrameBuffer*>(frame.video_frame_buffer().get())->wrapped_frame_buffer();
+    auto *frameBuffer = static_cast<ObjCFrameBuffer*>(buffer.get())->wrapped_frame_buffer();
     if (![frameBuffer isKindOfClass:[RTCCVPixelBuffer class]])
         return nullptr;
 
@@ -219,29 +229,4 @@
     return rtcPixelBuffer.pixelBuffer;
 }
 
-CVPixelBufferPoolRef createPixelBufferPool(size_t width, size_t height)
-{
-    const OSType videoCaptureFormat = kCVPixelFormatType_420YpCbCr8BiPlanarFullRange;
-    auto pixelAttributes = @{
-        (__bridge NSString *)kCVPixelBufferWidthKey: @(width),
-        (__bridge NSString *)kCVPixelBufferHeightKey: @(height),
-        (__bridge NSString *)kCVPixelBufferPixelFormatTypeKey: @(videoCaptureFormat),
-        (__bridge NSString *)kCVPixelBufferCGImageCompatibilityKey: @NO,
-#if defined(WEBRTC_IOS)
-        (__bridge NSString *)kCVPixelFormatOpenGLESCompatibility : @YES,
-#else
-        (__bridge NSString *)kCVPixelBufferOpenGLCompatibilityKey : @YES,
-#endif
-        (__bridge NSString *)kCVPixelBufferIOSurfacePropertiesKey : @{ }
-    };
-
-    CVPixelBufferPoolRef pool = nullptr;
-    auto status = CVPixelBufferPoolCreate(kCFAllocatorDefault, nullptr, (__bridge CFDictionaryRef)pixelAttributes, &pool);
-
-    if (status != kCVReturnSuccess)
-        return nullptr;
-
-    return pool;
 }
-
-}

Modified: trunk/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/WebKit/WebKitVP9Decoder.cpp (268970 => 268971)


--- trunk/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/WebKit/WebKitVP9Decoder.cpp	2020-10-26 12:42:18 UTC (rev 268970)
+++ trunk/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/WebKit/WebKitVP9Decoder.cpp	2020-10-26 12:50:41 UTC (rev 268971)
@@ -362,7 +362,7 @@
 
 int32_t WebKitVP9DecoderReceiver::Decoded(VideoFrame& frame)
 {
-    auto pixelBuffer = pixelBufferFromFrame(frame, [this](size_t width, size_t height) -> CVPixelBufferRef {
+    auto pixelBuffer = pixelBufferFromFrame(frame, [this](size_t width, size_t height, BufferType) -> CVPixelBufferRef {
         CVPixelBufferRef pixelBuffer = nullptr;
         if (CVPixelBufferPoolCreatePixelBuffer(kCFAllocatorDefault, m_pixelBufferPool, &pixelBuffer) == kCVReturnSuccess)
             return pixelBuffer;

Modified: trunk/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/objc/api/video_codec/RTCVideoEncoderVP9.h (268970 => 268971)


--- trunk/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/objc/api/video_codec/RTCVideoEncoderVP9.h	2020-10-26 12:42:18 UTC (rev 268970)
+++ trunk/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/objc/api/video_codec/RTCVideoEncoderVP9.h	2020-10-26 12:50:41 UTC (rev 268971)
@@ -11,6 +11,7 @@
 #import <Foundation/Foundation.h>
 
 #import "RTCMacros.h"
+#import "RTCVideoCodecInfo.h"
 #import "RTCVideoEncoder.h"
 
 RTC_OBJC_EXPORT
@@ -21,6 +22,6 @@
  * RTCPeerConnectionFactory. Even though it implements the RTCVideoEncoder protocol, it can not be
  * used independently from the RTCPeerConnectionFactory.
  */
-+ (id<RTCVideoEncoder>)vp9Encoder;
++ (id<RTCVideoEncoder>)vp9Encoder:(RTCVideoCodecInfo *)codecInfo;
 
 @end

Modified: trunk/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/objc/api/video_codec/RTCVideoEncoderVP9.mm (268970 => 268971)


--- trunk/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/objc/api/video_codec/RTCVideoEncoderVP9.mm	2020-10-26 12:42:18 UTC (rev 268970)
+++ trunk/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/objc/api/video_codec/RTCVideoEncoderVP9.mm	2020-10-26 12:50:41 UTC (rev 268971)
@@ -15,12 +15,13 @@
 #import "RTCWrappedNativeVideoEncoder.h"
 
 #include "modules/video_coding/codecs/vp9/include/vp9.h"
+#include "sdk/objc/api/peerconnection/RTCVideoCodecInfo+Private.h"
 
 @implementation RTCVideoEncoderVP9
 
-+ (id<RTCVideoEncoder>)vp9Encoder {
++ (id<RTCVideoEncoder>)vp9Encoder:(RTCVideoCodecInfo *)codecInfo {
   return [[RTCWrappedNativeVideoEncoder alloc]
-      initWithNativeEncoder:std::unique_ptr<webrtc::VideoEncoder>(webrtc::VP9Encoder::Create())];
+      initWithNativeEncoder:std::unique_ptr<webrtc::VideoEncoder>(webrtc::VP9Encoder::Create(cricket::VideoCodec(codecInfo.nativeSdpVideoFormat)))];
 }
 
 @end

Modified: trunk/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/objc/components/video_codec/RTCDefaultVideoDecoderFactory.m (268970 => 268971)


--- trunk/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/objc/components/video_codec/RTCDefaultVideoDecoderFactory.m	2020-10-26 12:42:18 UTC (rev 268970)
+++ trunk/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/objc/components/video_codec/RTCDefaultVideoDecoderFactory.m	2020-10-26 12:50:41 UTC (rev 268971)
@@ -79,8 +79,13 @@
   [codecs addObject:vp8Info];
 #if defined(RTC_ENABLE_VP9)
   if (_supportsVP9) {
-    RTCVideoCodecInfo *vp9Info = [[RTCVideoCodecInfo alloc] initWithName:kRTCVideoCodecVp9Name];
-    [codecs addObject:vp9Info];
+    [codecs addObject:[[RTCVideoCodecInfo alloc] initWithName:kRTCVideoCodecVp9Name parameters: @{
+      @"profile-id" : @"0",
+    }]];
+
+    [codecs addObject:[[RTCVideoCodecInfo alloc] initWithName:kRTCVideoCodecVp9Name parameters: @{
+      @"profile-id" : @"2",
+    }]];
   }
 #endif
 

Modified: trunk/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/objc/components/video_codec/RTCDefaultVideoEncoderFactory.m (268970 => 268971)


--- trunk/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/objc/components/video_codec/RTCDefaultVideoEncoderFactory.m	2020-10-26 12:42:18 UTC (rev 268970)
+++ trunk/Source/ThirdParty/libwebrtc/Source/webrtc/sdk/objc/components/video_codec/RTCDefaultVideoEncoderFactory.m	2020-10-26 12:50:41 UTC (rev 268971)
@@ -77,8 +77,13 @@
 
 #if defined(RTC_ENABLE_VP9)
   if (supportsVP9) {
-    RTCVideoCodecInfo *vp9Info = [[RTCVideoCodecInfo alloc] initWithName:kRTCVideoCodecVp9Name];
-    [codecs addObject:vp9Info];
+    [codecs addObject:[[RTCVideoCodecInfo alloc] initWithName:kRTCVideoCodecVp9Name parameters: @{
+      @"profile-id" : @"0",
+    }]];
+
+    [codecs addObject:[[RTCVideoCodecInfo alloc] initWithName:kRTCVideoCodecVp9Name parameters: @{
+      @"profile-id" : @"2",
+    }]];
   }
 #endif
 
@@ -92,7 +97,7 @@
     return [RTCVideoEncoderVP8 vp8Encoder];
 #if defined(RTC_ENABLE_VP9)
   } else if ([info.name isEqualToString:kRTCVideoCodecVp9Name]) {
-    return [RTCVideoEncoderVP9 vp9Encoder];
+    return [RTCVideoEncoderVP9 vp9Encoder:info];
 #endif
 #if !defined(DISABLE_H265)
   } else if (@available(iOS 11, *)) {

Modified: trunk/Source/WebCore/ChangeLog (268970 => 268971)


--- trunk/Source/WebCore/ChangeLog	2020-10-26 12:42:18 UTC (rev 268970)
+++ trunk/Source/WebCore/ChangeLog	2020-10-26 12:50:41 UTC (rev 268971)
@@ -1,5 +1,25 @@
 2020-10-26  Youenn Fablet  <[email protected]>
 
+        Add support for VP9 Profile 2 (10-bit color) in WebRTC
+        https://bugs.webkit.org/show_bug.cgi?id=217673
+        <rdar://problem/70283885>
+
+        Reviewed by Eric Carlson.
+
+        In case software VP9 decoded buffer is 10 bits, we use kCVPixelFormatType_420YpCbCr10BiPlanarFullRange.
+
+        Test: webrtc/vp9-profile2.html
+
+        * platform/mediastream/mac/RealtimeIncomingVideoSourceCocoa.h:
+        * platform/mediastream/mac/RealtimeIncomingVideoSourceCocoa.mm:
+        (WebCore::RealtimeIncomingVideoSourceCocoa::pixelBufferPool):
+        (WebCore::RealtimeIncomingVideoSourceCocoa::pixelBufferFromVideoFrame):
+        * platform/mediastream/mac/RealtimeVideoUtilities.h:
+        * platform/mediastream/mac/RealtimeVideoUtilities.mm:
+        (WebCore::createPixelBufferPool):
+
+2020-10-26  Youenn Fablet  <[email protected]>
+
         Remove MediaPlayer::m_visible
         https://bugs.webkit.org/show_bug.cgi?id=217810
 

Modified: trunk/Source/WebCore/platform/mediastream/mac/RealtimeIncomingVideoSourceCocoa.h (268970 => 268971)


--- trunk/Source/WebCore/platform/mediastream/mac/RealtimeIncomingVideoSourceCocoa.h	2020-10-26 12:42:18 UTC (rev 268970)
+++ trunk/Source/WebCore/platform/mediastream/mac/RealtimeIncomingVideoSourceCocoa.h	2020-10-26 12:50:41 UTC (rev 268971)
@@ -35,6 +35,10 @@
 using CVPixelBufferPoolRef = struct __CVPixelBufferPool*;
 using CVPixelBufferRef = struct __CVBuffer*;
 
+namespace webrtc {
+enum class BufferType;
+};
+
 namespace WebCore {
 
 class RealtimeIncomingVideoSourceCocoa final : public RealtimeIncomingVideoSource {
@@ -44,7 +48,7 @@
 private:
     RealtimeIncomingVideoSourceCocoa(rtc::scoped_refptr<webrtc::VideoTrackInterface>&&, String&&);
     RetainPtr<CVPixelBufferRef> pixelBufferFromVideoFrame(const webrtc::VideoFrame&);
-    CVPixelBufferPoolRef pixelBufferPool(size_t width, size_t height);
+    CVPixelBufferPoolRef pixelBufferPool(size_t width, size_t height, webrtc::BufferType);
 
     // rtc::VideoSinkInterface
     void OnFrame(const webrtc::VideoFrame&) final;
@@ -58,6 +62,7 @@
     RetainPtr<CVPixelBufferPoolRef> m_pixelBufferPool;
     size_t m_pixelBufferPoolWidth { 0 };
     size_t m_pixelBufferPoolHeight { 0 };
+    webrtc::BufferType m_pixelBufferPoolBufferType;
 };
 
 RetainPtr<CVPixelBufferRef> createBlackPixelBuffer(size_t width, size_t height);

Modified: trunk/Source/WebCore/platform/mediastream/mac/RealtimeIncomingVideoSourceCocoa.mm (268970 => 268971)


--- trunk/Source/WebCore/platform/mediastream/mac/RealtimeIncomingVideoSourceCocoa.mm	2020-10-26 12:42:18 UTC (rev 268970)
+++ trunk/Source/WebCore/platform/mediastream/mac/RealtimeIncomingVideoSourceCocoa.mm	2020-10-26 12:50:41 UTC (rev 268971)
@@ -88,12 +88,21 @@
     return adoptCF(pixelBuffer);
 }
 
-CVPixelBufferPoolRef RealtimeIncomingVideoSourceCocoa::pixelBufferPool(size_t width, size_t height)
+CVPixelBufferPoolRef RealtimeIncomingVideoSourceCocoa::pixelBufferPool(size_t width, size_t height, webrtc::BufferType bufferType)
 {
-    if (!m_pixelBufferPool || m_pixelBufferPoolWidth != width || m_pixelBufferPoolHeight != height) {
-        m_pixelBufferPool = createPixelBufferPool(width, height);
+    if (!m_pixelBufferPool || m_pixelBufferPoolWidth != width || m_pixelBufferPoolHeight != height || m_pixelBufferPoolBufferType != bufferType) {
+        OSType poolBufferType;
+        switch (bufferType) {
+        case webrtc::BufferType::I420:
+            poolBufferType = kCVPixelFormatType_420YpCbCr8BiPlanarFullRange;
+            break;
+        case webrtc::BufferType::I010:
+            poolBufferType = kCVPixelFormatType_420YpCbCr10BiPlanarFullRange;
+        }
+        m_pixelBufferPool = createPixelBufferPool(width, height, poolBufferType);
         m_pixelBufferPoolWidth = width;
         m_pixelBufferPoolHeight = height;
+        m_pixelBufferPoolBufferType = bufferType;
     }
     return m_pixelBufferPool.get();
 }
@@ -110,8 +119,8 @@
     }
 
     RetainPtr<CVPixelBufferRef> newPixelBuffer;
-    return webrtc::pixelBufferFromFrame(frame, [this, &newPixelBuffer](size_t width, size_t height) -> CVPixelBufferRef {
-        auto pixelBufferPool = this->pixelBufferPool(width, height);
+    return webrtc::pixelBufferFromFrame(frame, [this, &newPixelBuffer](size_t width, size_t height, webrtc::BufferType bufferType) -> CVPixelBufferRef {
+        auto pixelBufferPool = this->pixelBufferPool(width, height, bufferType);
         if (!pixelBufferPool)
             return nullptr;
 

Modified: trunk/Source/WebCore/platform/mediastream/mac/RealtimeVideoUtilities.h (268970 => 268971)


--- trunk/Source/WebCore/platform/mediastream/mac/RealtimeVideoUtilities.h	2020-10-26 12:42:18 UTC (rev 268970)
+++ trunk/Source/WebCore/platform/mediastream/mac/RealtimeVideoUtilities.h	2020-10-26 12:50:41 UTC (rev 268971)
@@ -41,7 +41,7 @@
 #endif
 }
 
-WEBCORE_EXPORT RetainPtr<CVPixelBufferPoolRef> createPixelBufferPool(size_t width, size_t height);
+WEBCORE_EXPORT RetainPtr<CVPixelBufferPoolRef> createPixelBufferPool(size_t width, size_t height, OSType);
 WEBCORE_EXPORT RetainPtr<CVPixelBufferRef> createPixelBufferFromPool(CVPixelBufferPoolRef);
 
 }

Modified: trunk/Source/WebCore/platform/mediastream/mac/RealtimeVideoUtilities.mm (268970 => 268971)


--- trunk/Source/WebCore/platform/mediastream/mac/RealtimeVideoUtilities.mm	2020-10-26 12:42:18 UTC (rev 268970)
+++ trunk/Source/WebCore/platform/mediastream/mac/RealtimeVideoUtilities.mm	2020-10-26 12:50:41 UTC (rev 268971)
@@ -30,9 +30,8 @@
 
 namespace WebCore {
 
-RetainPtr<CVPixelBufferPoolRef> createPixelBufferPool(size_t width, size_t height)
+RetainPtr<CVPixelBufferPoolRef> createPixelBufferPool(size_t width, size_t height, OSType videoCaptureFormat)
 {
-    const OSType videoCaptureFormat = kCVPixelFormatType_420YpCbCr8BiPlanarFullRange;
     auto pixelAttributes = @{
         (__bridge NSString *)kCVPixelBufferWidthKey: @(width),
         (__bridge NSString *)kCVPixelBufferHeightKey: @(height),

Modified: trunk/Source/WebKit/ChangeLog (268970 => 268971)


--- trunk/Source/WebKit/ChangeLog	2020-10-26 12:42:18 UTC (rev 268970)
+++ trunk/Source/WebKit/ChangeLog	2020-10-26 12:50:41 UTC (rev 268971)
@@ -1,3 +1,14 @@
+2020-10-26  Youenn Fablet  <[email protected]>
+
+        Add support for VP9 Profile 2 (10-bit color) in WebRTC
+        https://bugs.webkit.org/show_bug.cgi?id=217673
+        <rdar://problem/70283885>
+
+        Reviewed by Eric Carlson.
+
+        * WebProcess/GPU/webrtc/LibWebRTCCodecs.cpp:
+        (WebKit::LibWebRTCCodecs::pixelBufferPool):
+
 2020-10-26  Zan Dobersek  <[email protected]>
 
         Remove Accelerated2dCanvasEnabled WebPreferences entry

Modified: trunk/Source/WebKit/WebProcess/GPU/webrtc/LibWebRTCCodecs.cpp (268970 => 268971)


--- trunk/Source/WebKit/WebProcess/GPU/webrtc/LibWebRTCCodecs.cpp	2020-10-26 12:42:18 UTC (rev 268970)
+++ trunk/Source/WebKit/WebProcess/GPU/webrtc/LibWebRTCCodecs.cpp	2020-10-26 12:50:41 UTC (rev 268971)
@@ -113,8 +113,16 @@
 static int32_t encodeVideoFrame(webrtc::WebKitVideoEncoder encoder, const webrtc::VideoFrame& frame, bool shouldEncodeAsKeyFrame)
 {
     RetainPtr<CVPixelBufferRef> newPixelBuffer;
-    auto pixelBuffer = webrtc::pixelBufferFromFrame(frame, [&newPixelBuffer](size_t width, size_t height) -> CVPixelBufferRef {
-        auto pixelBufferPool = WebProcess::singleton().libWebRTCCodecs().pixelBufferPool(width, height);
+    auto pixelBuffer = webrtc::pixelBufferFromFrame(frame, [&newPixelBuffer](size_t width, size_t height, webrtc::BufferType bufferType) -> CVPixelBufferRef {
+        OSType poolBufferType;
+        switch (bufferType) {
+        case webrtc::BufferType::I420:
+            poolBufferType = kCVPixelFormatType_420YpCbCr8BiPlanarFullRange;
+            break;
+        case webrtc::BufferType::I010:
+            poolBufferType = kCVPixelFormatType_420YpCbCr10BiPlanarFullRange;
+        }
+        auto pixelBufferPool = WebProcess::singleton().libWebRTCCodecs().pixelBufferPool(width, height, poolBufferType);
         if (!pixelBufferPool)
             return nullptr;
 
@@ -359,10 +367,10 @@
     webrtc::RemoteVideoEncoder::encodeComplete(encoder->encodedImageCallback, const_cast<uint8_t*>(data.data()), data.size(), info, fragmentationHeader.value());
 }
 
-CVPixelBufferPoolRef LibWebRTCCodecs::pixelBufferPool(size_t width, size_t height)
+CVPixelBufferPoolRef LibWebRTCCodecs::pixelBufferPool(size_t width, size_t height, OSType type)
 {
     if (!m_pixelBufferPool || m_pixelBufferPoolWidth != width || m_pixelBufferPoolHeight != height) {
-        m_pixelBufferPool = createPixelBufferPool(width, height);
+        m_pixelBufferPool = createPixelBufferPool(width, height, type);
         m_pixelBufferPoolWidth = width;
         m_pixelBufferPoolHeight = height;
     }

Modified: trunk/Source/WebKit/WebProcess/GPU/webrtc/LibWebRTCCodecs.h (268970 => 268971)


--- trunk/Source/WebKit/WebProcess/GPU/webrtc/LibWebRTCCodecs.h	2020-10-26 12:42:18 UTC (rev 268970)
+++ trunk/Source/WebKit/WebProcess/GPU/webrtc/LibWebRTCCodecs.h	2020-10-26 12:50:41 UTC (rev 268971)
@@ -94,7 +94,7 @@
     void registerEncodeFrameCallback(Encoder&, void* encodedImageCallback);
     void setEncodeRates(Encoder&, uint32_t bitRate, uint32_t frameRate);
     
-    CVPixelBufferPoolRef pixelBufferPool(size_t width, size_t height);
+    CVPixelBufferPoolRef pixelBufferPool(size_t width, size_t height, OSType);
 
     void didReceiveMessage(IPC::Connection&, IPC::Decoder&) final;
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to