OLD | NEW |
---|---|
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 Loading... | |
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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 |
103 @SmallTest | 104 @SmallTest |
104 static public void testTexMatrixDefault() { | 105 static public void testLayoutMatrixDefault() { |
105 final float texMatrix[] = new float[16]; | 106 final float layoutMatrix[] = getLayoutMatrix(false, 1.0f, 1.0f); |
106 getTextureMatrix(texMatrix, 0, false, 1.0f, 1.0f); | 107 // Assert: |
107 // TODO(magjed): Every tex matrix contains a vertical flip, because we ignor e the texture | 108 // u' = u. |
108 // transform matrix from the SurfaceTexture (which contains a vertical flip) . Update tests when | 109 // v' = v. |
109 // this is fixed. | 110 MoreAsserts.assertEquals(round(layoutMatrix), new double[] |
111 {1, 0, 0, 0, | |
112 0, 1, 0, 0, | |
113 0, 0, 1, 0, | |
114 0, 0, 0, 1}); | |
115 } | |
116 | |
117 @SmallTest | |
118 static public void testLayoutMatrixMirror() { | |
119 final float layoutMatrix[] = getLayoutMatrix(true, 1.0f, 1.0f); | |
120 // Assert: | |
121 // u' = 1 - u. | |
122 // v' = v. | |
123 MoreAsserts.assertEquals(round(layoutMatrix), new double[] | |
124 {-1, 0, 0, 0, | |
125 0, 1, 0, 0, | |
126 0, 0, 1, 0, | |
127 1, 0, 0, 1}); | |
hbos
2015/09/08 14:08:47
I don't fully understand the matrix values in thes
magjed_webrtc
2015/09/08 15:24:28
Done. Also added comment.
hbos
2015/09/09 08:27:54
Acknowledged.
| |
128 } | |
129 | |
130 @SmallTest | |
131 static public void testLayoutMatrixScale() { | |
132 // Video has aspect ratio 2, but layout is square. This will cause only the center part of the | |
133 // video to be visible, i.e. the u coordinate will go from 0.25 to 0.75 inst ead of from 0 to 1. | |
134 final float layoutMatrix[] = getLayoutMatrix(false, 2.0f, 1.0f); | |
135 // Assert: | |
136 // u' = 0.25 + 0.5 u. | |
137 // v' = v. | |
138 MoreAsserts.assertEquals(round(layoutMatrix), new double[] | |
139 { 0.5, 0, 0, 0, | |
140 0, 1, 0, 0, | |
141 0, 0, 1, 0, | |
142 0.25, 0, 0, 1}); | |
143 } | |
144 | |
145 @SmallTest | |
146 static public void testSamplingMatrixDefault() { | |
147 final float samplingMatrix[] = getSamplingMatrix(null, 0); | |
110 // Assert: | 148 // Assert: |
111 // u' = u. | 149 // u' = u. |
112 // v' = 1 - v. | 150 // v' = 1 - v. |
113 MoreAsserts.assertEquals(round(texMatrix), new double[] | 151 MoreAsserts.assertEquals(round(samplingMatrix), new double[] |
114 {1, 0, 0, 0, | 152 {1, 0, 0, 0, |
115 0, -1, 0, 0, | 153 0, -1, 0, 0, |
116 0, 0, 1, 0, | 154 0, 0, 1, 0, |
117 0, 1, 0, 1}); | 155 0, 1, 0, 1}); |
118 } | 156 } |
119 | 157 |
120 @SmallTest | 158 @SmallTest |
121 static public void testTexMatrixMirror() { | 159 static public void testSamplingMatrixRotation90Deg() { |
122 final float texMatrix[] = new float[16]; | 160 final float samplingMatrix[] = getSamplingMatrix(null, 90); |
123 getTextureMatrix(texMatrix, 0, true, 1.0f, 1.0f); | |
124 // Assert: | 161 // Assert: |
125 // u' = 1 - u. | 162 // u' = 1 - u. |
126 // v' = 1 - v. | 163 // v' = 1 - v. |
127 MoreAsserts.assertEquals(round(texMatrix), new double[] | 164 MoreAsserts.assertEquals(round(samplingMatrix), new double[] |
128 {-1, 0, 0, 0, | 165 { 0, -1, 0, 0, |
129 0, -1, 0, 0, | 166 -1, 0, 0, 0, |
130 0, 0, 1, 0, | 167 0, 0, 1, 0, |
131 1, 1, 0, 1}); | 168 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 } | 169 } |
163 } | 170 } |
OLD | NEW |