Title: [267366] trunk
Revision
267366
Author
you...@apple.com
Date
2020-09-21 13:57:17 -0700 (Mon, 21 Sep 2020)

Log Message

[iOS] MediaRecorder incorrect screen orientation handling
https://bugs.webkit.org/show_bug.cgi?id=198912
<rdar://problem/51802521>

Reviewed by Eric Carlson.

Source/WebCore:

Update MediaRecorderPrivateWriterCocoa to pass a MediaSample down to handle rotation.
Set AVAssetWriterInput transform according the first MediaSample rotation value.

Test: http/wpt/mediarecorder/video-rotation.html

* platform/mediarecorder/MediaRecorderPrivateAVFImpl.cpp:
(WebCore::MediaRecorderPrivateAVFImpl::videoSampleAvailable):
* platform/mediarecorder/cocoa/MediaRecorderPrivateWriterCocoa.h:
* platform/mediarecorder/cocoa/MediaRecorderPrivateWriterCocoa.mm:
(WebCore::MediaRecorderPrivateWriter::appendVideoSampleBuffer):

Source/WebKit:

* GPUProcess/webrtc/RemoteMediaRecorder.cpp:
(WebKit::RemoteMediaRecorder::videoSampleAvailable):

LayoutTests:

* http/wpt/mediarecorder/video-rotation-expected.txt: Added.
* http/wpt/mediarecorder/video-rotation.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (267365 => 267366)


--- trunk/LayoutTests/ChangeLog	2020-09-21 20:55:50 UTC (rev 267365)
+++ trunk/LayoutTests/ChangeLog	2020-09-21 20:57:17 UTC (rev 267366)
@@ -1,3 +1,14 @@
+2020-09-21  Youenn Fablet  <you...@apple.com>
+
+        [iOS] MediaRecorder incorrect screen orientation handling
+        https://bugs.webkit.org/show_bug.cgi?id=198912
+        <rdar://problem/51802521>
+
+        Reviewed by Eric Carlson.
+
+        * http/wpt/mediarecorder/video-rotation-expected.txt: Added.
+        * http/wpt/mediarecorder/video-rotation.html: Added.
+
 2020-09-20  Darin Adler  <da...@apple.com>
 
         Selection API: A few more refinements to DOMSelection and VisibleSelection to pass all WPT tests

Added: trunk/LayoutTests/http/wpt/mediarecorder/video-rotation-expected.txt (0 => 267366)


--- trunk/LayoutTests/http/wpt/mediarecorder/video-rotation-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/wpt/mediarecorder/video-rotation-expected.txt	2020-09-21 20:57:17 UTC (rev 267366)
@@ -0,0 +1,4 @@
+
+
+PASS Record a rotated video 
+

Added: trunk/LayoutTests/http/wpt/mediarecorder/video-rotation.html (0 => 267366)


--- trunk/LayoutTests/http/wpt/mediarecorder/video-rotation.html	                        (rev 0)
+++ trunk/LayoutTests/http/wpt/mediarecorder/video-rotation.html	2020-09-21 20:57:17 UTC (rev 267366)
@@ -0,0 +1,45 @@
+<!doctype html>
+<html>
+    <head>
+        <meta charset="utf-8">
+        <title>Testing video rotation in media recorder</title>
+        <script src=""
+        <script src=""
+    </head>
+    <body>
+        <video id="recordedVideo" autoplay playsInline width="320" height="240"></video>
+        <script>
+promise_test(async (test) => {
+    const stream = await navigator.mediaDevices.getUserMedia({video: true });
+    let expectedWidth = 640;
+    let expectedHeight = 480;
+
+    if (window.internals) {
+        window.internals.setCameraMediaStreamTrackOrientation(stream.getVideoTracks()[0], 90);
+        testRunner.setMockCameraOrientation(90);
+
+        expectedWidth = 480;
+        expectedHeight = 640;
+    }
+
+    const recorder = new MediaRecorder(stream);
+    const promise = new Promise((resolve, reject) => {
+        recorder._ondataavailable_ = (e) => resolve(e.data);
+        setTimeout(() => reject("datavailable event timed out"), 5000);
+    });
+    recorder.start();
+    setTimeout(() => recorder.stop(), 1000);
+    const blob = await promise;
+
+    const url = ""
+    recordedVideo.src = ""
+    await recordedVideo.play();
+
+    URL.revokeObjectURL(url);
+
+    assert_equals(recordedVideo.videoWidth, expectedWidth, "recorded video width");
+    assert_equals(recordedVideo.videoHeight, expectedHeight, "recorded video height");
+}, "Record a rotated video");
+        </script>
+    </body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (267365 => 267366)


--- trunk/Source/WebCore/ChangeLog	2020-09-21 20:55:50 UTC (rev 267365)
+++ trunk/Source/WebCore/ChangeLog	2020-09-21 20:57:17 UTC (rev 267366)
@@ -1,3 +1,22 @@
+2020-09-21  Youenn Fablet  <you...@apple.com>
+
+        [iOS] MediaRecorder incorrect screen orientation handling
+        https://bugs.webkit.org/show_bug.cgi?id=198912
+        <rdar://problem/51802521>
+
+        Reviewed by Eric Carlson.
+
+        Update MediaRecorderPrivateWriterCocoa to pass a MediaSample down to handle rotation.
+        Set AVAssetWriterInput transform according the first MediaSample rotation value.
+
+        Test: http/wpt/mediarecorder/video-rotation.html
+
+        * platform/mediarecorder/MediaRecorderPrivateAVFImpl.cpp:
+        (WebCore::MediaRecorderPrivateAVFImpl::videoSampleAvailable):
+        * platform/mediarecorder/cocoa/MediaRecorderPrivateWriterCocoa.h:
+        * platform/mediarecorder/cocoa/MediaRecorderPrivateWriterCocoa.mm:
+        (WebCore::MediaRecorderPrivateWriter::appendVideoSampleBuffer):
+
 2020-09-21  Keith Miller  <keith_mil...@apple.com>
 
         Functions should consistently enumerate length before name

Modified: trunk/Source/WebCore/platform/mediarecorder/MediaRecorderPrivateAVFImpl.cpp (267365 => 267366)


--- trunk/Source/WebCore/platform/mediarecorder/MediaRecorderPrivateAVFImpl.cpp	2020-09-21 20:55:50 UTC (rev 267365)
+++ trunk/Source/WebCore/platform/mediarecorder/MediaRecorderPrivateAVFImpl.cpp	2020-09-21 20:57:17 UTC (rev 267366)
@@ -70,7 +70,7 @@
 
 void MediaRecorderPrivateAVFImpl::videoSampleAvailable(MediaSample& sampleBuffer)
 {
-    m_writer->appendVideoSampleBuffer(sampleBuffer.platformSample().sample.cmSampleBuffer);
+    m_writer->appendVideoSampleBuffer(sampleBuffer);
 }
 
 void MediaRecorderPrivateAVFImpl::audioSamplesAvailable(const WTF::MediaTime& mediaTime, const PlatformAudioData& data, const AudioStreamDescription& description, size_t sampleCount)

Modified: trunk/Source/WebCore/platform/mediarecorder/cocoa/MediaRecorderPrivateWriterCocoa.h (267365 => 267366)


--- trunk/Source/WebCore/platform/mediarecorder/cocoa/MediaRecorderPrivateWriterCocoa.h	2020-09-21 20:55:50 UTC (rev 267365)
+++ trunk/Source/WebCore/platform/mediarecorder/cocoa/MediaRecorderPrivateWriterCocoa.h	2020-09-21 20:57:17 UTC (rev 267366)
@@ -56,6 +56,7 @@
 
 class AudioSampleBufferCompressor;
 class AudioStreamDescription;
+class MediaSample;
 class MediaStreamTrackPrivate;
 class PlatformAudioData;
 class VideoSampleBufferCompressor;
@@ -66,7 +67,7 @@
     static RefPtr<MediaRecorderPrivateWriter> create(bool hasAudio, bool hasVideo, const MediaRecorderPrivateOptions&);
     ~MediaRecorderPrivateWriter();
 
-    void appendVideoSampleBuffer(CMSampleBufferRef);
+    void appendVideoSampleBuffer(MediaSample&);
     void appendAudioSampleBuffer(const PlatformAudioData&, const AudioStreamDescription&, const WTF::MediaTime&, size_t);
     void stopRecording();
     void fetchData(CompletionHandler<void(RefPtr<SharedBuffer>&&)>&&);
@@ -129,6 +130,7 @@
 
     bool m_isFlushingSamples { false };
     bool m_shouldStopAfterFlushingSamples { false };
+    bool m_firstVideoFrame { false };
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/mediarecorder/cocoa/MediaRecorderPrivateWriterCocoa.mm (267365 => 267366)


--- trunk/Source/WebCore/platform/mediarecorder/cocoa/MediaRecorderPrivateWriterCocoa.mm	2020-09-21 20:55:50 UTC (rev 267365)
+++ trunk/Source/WebCore/platform/mediarecorder/cocoa/MediaRecorderPrivateWriterCocoa.mm	2020-09-21 20:57:17 UTC (rev 267366)
@@ -421,10 +421,19 @@
     return adoptCF(newBuffer);
 }
 
-void MediaRecorderPrivateWriter::appendVideoSampleBuffer(CMSampleBufferRef sampleBuffer)
+void MediaRecorderPrivateWriter::appendVideoSampleBuffer(MediaSample& sample)
 {
+    if (!m_firstVideoFrame) {
+        m_firstVideoFrame = true;
+        if (sample.videoRotation() != MediaSample::VideoRotation::None || sample.videoMirrored()) {
+            auto videoTransform = CGAffineTransformMakeRotation(static_cast<int>(sample.videoRotation()) * M_PI / 180);
+            if (sample.videoMirrored())
+                videoTransform = CGAffineTransformScale(videoTransform, -1, 1);
+            m_videoAssetWriterInput.get().transform = videoTransform;
+        }
+    }
     // FIXME: We should not set the timestamps if they are already set.
-    if (auto bufferWithCurrentTime = copySampleBufferWithCurrentTimeStamp(sampleBuffer))
+    if (auto bufferWithCurrentTime = copySampleBufferWithCurrentTimeStamp(sample.platformSample().sample.cmSampleBuffer))
         m_videoCompressor->addSampleBuffer(bufferWithCurrentTime.get());
 }
 

Modified: trunk/Source/WebKit/ChangeLog (267365 => 267366)


--- trunk/Source/WebKit/ChangeLog	2020-09-21 20:55:50 UTC (rev 267365)
+++ trunk/Source/WebKit/ChangeLog	2020-09-21 20:57:17 UTC (rev 267366)
@@ -1,3 +1,14 @@
+2020-09-21  Youenn Fablet  <you...@apple.com>
+
+        [iOS] MediaRecorder incorrect screen orientation handling
+        https://bugs.webkit.org/show_bug.cgi?id=198912
+        <rdar://problem/51802521>
+
+        Reviewed by Eric Carlson.
+
+        * GPUProcess/webrtc/RemoteMediaRecorder.cpp:
+        (WebKit::RemoteMediaRecorder::videoSampleAvailable):
+
 2020-09-21  Keith Miller  <keith_mil...@apple.com>
 
         Functions should consistently enumerate length before name

Modified: trunk/Source/WebKit/GPUProcess/webrtc/RemoteMediaRecorder.cpp (267365 => 267366)


--- trunk/Source/WebKit/GPUProcess/webrtc/RemoteMediaRecorder.cpp	2020-09-21 20:55:50 UTC (rev 267365)
+++ trunk/Source/WebKit/GPUProcess/webrtc/RemoteMediaRecorder.cpp	2020-09-21 20:57:17 UTC (rev 267366)
@@ -118,7 +118,7 @@
         return;
     }
 
-    m_writer->appendVideoSampleBuffer(sampleBuffer->platformSample().sample.cmSampleBuffer);
+    m_writer->appendVideoSampleBuffer(*sampleBuffer);
 }
 
 void RemoteMediaRecorder::fetchData(CompletionHandler<void(IPC::DataReference&&, const String& mimeType)>&& completionHandler)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to