Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: talk/app/webrtc/androidtests/src/org/webrtc/RendererCommonTest.java

Issue 1318153007: Android video rendering: Apply SurfaceTexture.getTransformationMatrix() (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Change to updateLayoutMatrix() Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | talk/app/webrtc/java/android/org/webrtc/RendererCommon.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * libjingle 2 * libjingle
3 * Copyright 2015 Google Inc. 3 * Copyright 2015 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright notice, 8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
(...skipping 17 matching lines...) Expand all
28 package org.webrtc; 28 package org.webrtc;
29 29
30 import android.test.ActivityTestCase; 30 import android.test.ActivityTestCase;
31 import android.test.MoreAsserts; 31 import android.test.MoreAsserts;
32 import android.test.suitebuilder.annotation.SmallTest; 32 import android.test.suitebuilder.annotation.SmallTest;
33 33
34 import android.graphics.Point; 34 import android.graphics.Point;
35 35
36 import static org.webrtc.RendererCommon.ScalingType.*; 36 import static org.webrtc.RendererCommon.ScalingType.*;
37 import static org.webrtc.RendererCommon.getDisplaySize; 37 import static org.webrtc.RendererCommon.getDisplaySize;
38 import static org.webrtc.RendererCommon.getTextureMatrix; 38 import static org.webrtc.RendererCommon.getLayoutMatrix;
39 import static org.webrtc.RendererCommon.getSamplingMatrix;
39 40
40 public class RendererCommonTest extends ActivityTestCase { 41 public class RendererCommonTest extends ActivityTestCase {
41 @SmallTest 42 @SmallTest
42 static public void testDisplaySizeNoFrame() { 43 static public void testDisplaySizeNoFrame() {
43 assertEquals(getDisplaySize(SCALE_ASPECT_FIT, 0.0f, 0, 0), new Point(0, 0)); 44 assertEquals(getDisplaySize(SCALE_ASPECT_FIT, 0.0f, 0, 0), new Point(0, 0));
44 assertEquals(getDisplaySize(SCALE_ASPECT_FILL, 0.0f, 0, 0), new Point(0, 0)) ; 45 assertEquals(getDisplaySize(SCALE_ASPECT_FILL, 0.0f, 0, 0), new Point(0, 0)) ;
45 assertEquals(getDisplaySize(SCALE_ASPECT_BALANCED, 0.0f, 0, 0), new Point(0, 0)); 46 assertEquals(getDisplaySize(SCALE_ASPECT_BALANCED, 0.0f, 0, 0), new Point(0, 0));
46 } 47 }
47 48
48 @SmallTest 49 @SmallTest
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 // Only keep 2 rounded decimals to make float comparison robust. 94 // Only keep 2 rounded decimals to make float comparison robust.
94 static private double[] round(float[] array) { 95 static private double[] round(float[] array) {
95 assertEquals(array.length, 16); 96 assertEquals(array.length, 16);
96 final double[] doubleArray = new double[16]; 97 final double[] doubleArray = new double[16];
97 for (int i = 0; i < 16; ++i) { 98 for (int i = 0; i < 16; ++i) {
98 doubleArray[i] = Math.round(100 * array[i]) / 100.0; 99 doubleArray[i] = Math.round(100 * array[i]) / 100.0;
99 } 100 }
100 return doubleArray; 101 return doubleArray;
101 } 102 }
102 103
104 // Brief summary about matrix transformations:
105 // A coordinate p = [u, v, 0, 1] is transformed by matrix m like this p' = [u' , v', 0, 1] = m * p.
106 // OpenGL uses column-major order, so:
107 // u' = u * m[0] + v * m[4] + m[12].
108 // v' = u * m[1] + v * m[5] + m[13].
109
103 @SmallTest 110 @SmallTest
104 static public void testTexMatrixDefault() { 111 static public void testLayoutMatrixDefault() {
105 final float texMatrix[] = new float[16]; 112 final float layoutMatrix[] = getLayoutMatrix(false, 1.0f, 1.0f);
106 getTextureMatrix(texMatrix, 0, false, 1.0f, 1.0f); 113 // Assert:
107 // TODO(magjed): Every tex matrix contains a vertical flip, because we ignor e the texture 114 // u' = u.
108 // transform matrix from the SurfaceTexture (which contains a vertical flip) . Update tests when 115 // v' = v.
109 // this is fixed. 116 MoreAsserts.assertEquals(round(layoutMatrix), new double[]
117 {1, 0, 0, 0,
118 0, 1, 0, 0,
119 0, 0, 1, 0,
120 0, 0, 0, 1});
121 }
122
123 @SmallTest
124 static public void testLayoutMatrixMirror() {
125 final float layoutMatrix[] = getLayoutMatrix(true, 1.0f, 1.0f);
126 // Assert:
127 // u' = 1 - u.
128 // v' = v.
129 MoreAsserts.assertEquals(round(layoutMatrix), new double[]
130 {-1, 0, 0, 0,
131 0, 1, 0, 0,
132 0, 0, 1, 0,
133 1, 0, 0, 1});
134 }
135
136 @SmallTest
137 static public void testLayoutMatrixScale() {
138 // Video has aspect ratio 2, but layout is square. This will cause only the center part of the
139 // video to be visible, i.e. the u coordinate will go from 0.25 to 0.75 inst ead of from 0 to 1.
140 final float layoutMatrix[] = getLayoutMatrix(false, 2.0f, 1.0f);
141 // Assert:
142 // u' = 0.25 + 0.5 u.
143 // v' = v.
144 MoreAsserts.assertEquals(round(layoutMatrix), new double[]
145 { 0.5, 0, 0, 0,
146 0, 1, 0, 0,
147 0, 0, 1, 0,
148 0.25, 0, 0, 1});
149 }
150
151 @SmallTest
152 static public void testSamplingMatrixDefault() {
153 final float samplingMatrix[] = getSamplingMatrix(null, 0);
110 // Assert: 154 // Assert:
111 // u' = u. 155 // u' = u.
112 // v' = 1 - v. 156 // v' = 1 - v.
113 MoreAsserts.assertEquals(round(texMatrix), new double[] 157 MoreAsserts.assertEquals(round(samplingMatrix), new double[]
114 {1, 0, 0, 0, 158 {1, 0, 0, 0,
115 0, -1, 0, 0, 159 0, -1, 0, 0,
116 0, 0, 1, 0, 160 0, 0, 1, 0,
117 0, 1, 0, 1}); 161 0, 1, 0, 1});
118 } 162 }
119 163
120 @SmallTest 164 @SmallTest
121 static public void testTexMatrixMirror() { 165 static public void testSamplingMatrixRotation90Deg() {
122 final float texMatrix[] = new float[16]; 166 final float samplingMatrix[] = getSamplingMatrix(null, 90);
123 getTextureMatrix(texMatrix, 0, true, 1.0f, 1.0f);
124 // Assert: 167 // Assert:
125 // u' = 1 - u. 168 // u' = 1 - u.
126 // v' = 1 - v. 169 // v' = 1 - v.
127 MoreAsserts.assertEquals(round(texMatrix), new double[] 170 MoreAsserts.assertEquals(round(samplingMatrix), new double[]
128 {-1, 0, 0, 0, 171 { 0, -1, 0, 0,
129 0, -1, 0, 0, 172 -1, 0, 0, 0,
130 0, 0, 1, 0, 173 0, 0, 1, 0,
131 1, 1, 0, 1}); 174 1, 1, 0, 1});
132 }
133
134 @SmallTest
135 static public void testTexMatrixRotation90Deg() {
136 final float texMatrix[] = new float[16];
137 getTextureMatrix(texMatrix, 90, false, 1.0f, 1.0f);
138 // Assert:
139 // u' = 1 - v.
140 // v' = 1 - u.
141 MoreAsserts.assertEquals(round(texMatrix), new double[]
142 {0, -1, 0, 0,
143 -1, 0, 0, 0,
144 0, 0, 1, 0,
145 1, 1, 0, 1});
146 }
147
148 @SmallTest
149 static public void testTexMatrixScale() {
150 final float texMatrix[] = new float[16];
151 // Video has aspect ratio 2, but layout is square. This will cause only the center part of the
152 // video to be visible, i.e. the u coordinate will go from 0.25 to 0.75 inst ead of from 0 to 1.
153 getTextureMatrix(texMatrix, 0, false, 2.0f, 1.0f);
154 // Assert:
155 // u' = 0.25 + 0.5 u.
156 // v' = 1 - v.
157 MoreAsserts.assertEquals(round(texMatrix), new double[]
158 {0.5, 0, 0, 0,
159 0, -1, 0, 0,
160 0, 0, 1, 0,
161 0.25, 1, 0, 1});
162 } 175 }
163 } 176 }
OLDNEW
« no previous file with comments | « no previous file | talk/app/webrtc/java/android/org/webrtc/RendererCommon.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698