Incoming video source doesn't propogate frame rotation
authoreric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 31 Mar 2017 22:50:47 +0000 (22:50 +0000)
committereric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 31 Mar 2017 22:50:47 +0000 (22:50 +0000)
https://bugs.webkit.org/show_bug.cgi?id=170364

Reviewed by Youenn Fablet.

No new tests, the mock video source doesn't support rotation. Test will be added when
this is fixed in https://bugs.webkit.org/show_bug.cgi?id=169822. The changes were
verified manually.

* platform/mediastream/mac/RealtimeIncomingVideoSource.cpp:
(WebCore::RealtimeIncomingVideoSource::OnFrame): Convert frame rotation to sample
orientation and swap width and height when necessary.
(WebCore::RealtimeIncomingVideoSource::processNewSample):
* platform/mediastream/mac/RealtimeIncomingVideoSource.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@214694 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/mediastream/mac/RealtimeIncomingVideoSource.cpp
Source/WebCore/platform/mediastream/mac/RealtimeIncomingVideoSource.h

index 777d0bc..7318521 100644 (file)
@@ -1,3 +1,20 @@
+2017-03-31  Eric Carlson  <eric.carlson@apple.com>
+
+        Incoming video source doesn't propogate frame rotation
+        https://bugs.webkit.org/show_bug.cgi?id=170364
+
+        Reviewed by Youenn Fablet.
+
+        No new tests, the mock video source doesn't support rotation. Test will be added when
+        this is fixed in https://bugs.webkit.org/show_bug.cgi?id=169822. The changes were 
+        verified manually.
+
+        * platform/mediastream/mac/RealtimeIncomingVideoSource.cpp:
+        (WebCore::RealtimeIncomingVideoSource::OnFrame): Convert frame rotation to sample
+        orientation and swap width and height when necessary.
+        (WebCore::RealtimeIncomingVideoSource::processNewSample):
+        * platform/mediastream/mac/RealtimeIncomingVideoSource.h:
+
 2017-03-31  Chris Dumez  <cdumez@apple.com>
 
         Possible null dereference under SourceBuffer::sourceBufferPrivateDidReceiveSample()
index eb526d1..a2a0735 100644 (file)
@@ -170,13 +170,32 @@ void RealtimeIncomingVideoSource::OnFrame(const webrtc::VideoFrame& frame)
 
     unsigned width = frame.width();
     unsigned height = frame.height();
+
+    MediaSample::VideoOrientation orientation;
+    switch (frame.rotation()) {
+    case webrtc::kVideoRotation_0:
+        orientation = MediaSample::VideoOrientation::Portrait;
+        break;
+    case webrtc::kVideoRotation_180:
+        orientation = MediaSample::VideoOrientation::PortraitUpsideDown;
+        break;
+    case webrtc::kVideoRotation_90:
+        orientation = MediaSample::VideoOrientation::LandscapeRight;
+        std::swap(width, height);
+        break;
+    case webrtc::kVideoRotation_270:
+        orientation = MediaSample::VideoOrientation::LandscapeLeft;
+        std::swap(width, height);
+        break;
+    }
+
     RefPtr<RealtimeIncomingVideoSource> protectedThis(this);
-    callOnMainThread([protectedThis = WTFMove(protectedThis), sample = WTFMove(sample), width, height] {
-        protectedThis->processNewSample(sample.get(), width, height);
+    callOnMainThread([protectedThis = WTFMove(protectedThis), sample = WTFMove(sample), width, height, orientation] {
+        protectedThis->processNewSample(sample.get(), width, height, orientation);
     });
 }
 
-void RealtimeIncomingVideoSource::processNewSample(CMSampleBufferRef sample, unsigned width, unsigned height)
+void RealtimeIncomingVideoSource::processNewSample(CMSampleBufferRef sample, unsigned width, unsigned height, MediaSample::VideoOrientation orientation)
 {
     m_buffer = sample;
     if (width != m_currentSettings.width() || height != m_currentSettings.height()) {
@@ -185,7 +204,7 @@ void RealtimeIncomingVideoSource::processNewSample(CMSampleBufferRef sample, uns
         settingsDidChange();
     }
 
-    videoSampleAvailable(MediaSampleAVFObjC::create(sample));
+    videoSampleAvailable(MediaSampleAVFObjC::create(sample, orientation));
 }
 
 RefPtr<RealtimeMediaSourceCapabilities> RealtimeIncomingVideoSource::capabilities() const
index 29d7076..2fff8b6 100644 (file)
@@ -64,7 +64,7 @@ private:
     MediaConstraints& constraints() { return *m_constraints.get(); }
     RealtimeMediaSourceSupportedConstraints& supportedConstraints();
 
-    void processNewSample(CMSampleBufferRef, unsigned, unsigned);
+    void processNewSample(CMSampleBufferRef, unsigned, unsigned, MediaSample::VideoOrientation);
 
     bool isProducingData() const final { return m_isProducingData && m_buffer; }
     bool applySize(const IntSize&) final { return true; }