From 3ff71de9dae86e957f9a1e6b6d88ffa7d840fadb Mon Sep 17 00:00:00 2001 From: Magnus Jedvert Date: Mon, 17 Dec 2018 10:26:12 +0100 Subject: [PATCH] Android: Add option to mirror vertically in EglRenderer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug: None Change-Id: I4f46f9f0e1fa3805880335ebb6a767b8cb33f8c6 Reviewed-on: https://webrtc-review.googlesource.com/c/114540 Reviewed-by: Sami Kalliomäki Commit-Queue: Magnus Jedvert Cr-Commit-Position: refs/heads/master@{#26028} --- sdk/android/api/org/webrtc/EglRenderer.java | 26 ++++++++++++++------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/sdk/android/api/org/webrtc/EglRenderer.java b/sdk/android/api/org/webrtc/EglRenderer.java index c36952714e..d87c5178f1 100644 --- a/sdk/android/api/org/webrtc/EglRenderer.java +++ b/sdk/android/api/org/webrtc/EglRenderer.java @@ -136,7 +136,9 @@ public class EglRenderer implements VideoSink { private final Object layoutLock = new Object(); private float layoutAspectRatio; // If true, mirrors the video stream horizontally. - private boolean mirror; + private boolean mirrorHorizontally; + // If true, mirrors the video stream vertically. + private boolean mirrorVertically; // These variables are synchronized on |statisticsLock|. private final Object statisticsLock = new Object(); @@ -342,12 +344,22 @@ public class EglRenderer implements VideoSink { } /** - * Set if the video stream should be mirrored or not. + * Set if the video stream should be mirrored horizontally or not. */ public void setMirror(final boolean mirror) { - logD("setMirror: " + mirror); + logD("setMirrorHorizontally: " + mirror); synchronized (layoutLock) { - this.mirror = mirror; + this.mirrorHorizontally = mirror; + } + } + + /** + * Set if the video stream should be mirrored vertically or not. + */ + public void setMirrorVertically(final boolean mirrorVertically) { + logD("setMirrorVertically: " + mirrorVertically); + synchronized (layoutLock) { + this.mirrorVertically = mirrorVertically; } } @@ -621,8 +633,7 @@ public class EglRenderer implements VideoSink { drawMatrix.reset(); drawMatrix.preTranslate(0.5f, 0.5f); - if (mirror) - drawMatrix.preScale(-1f, 1f); + drawMatrix.preScale(mirrorHorizontally ? -1f : 1f, mirrorVertically ? -1f : 1f); drawMatrix.preScale(scaleX, scaleY); drawMatrix.preTranslate(-0.5f, -0.5f); @@ -657,8 +668,7 @@ public class EglRenderer implements VideoSink { drawMatrix.reset(); drawMatrix.preTranslate(0.5f, 0.5f); - if (mirror) - drawMatrix.preScale(-1f, 1f); + drawMatrix.preScale(mirrorHorizontally ? -1f : 1f, mirrorVertically ? -1f : 1f); drawMatrix.preScale(1f, -1f); // We want the output to be upside down for Bitmap. drawMatrix.preTranslate(-0.5f, -0.5f);