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 10 matching lines...) Expand all Loading... |
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | 22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | 23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 */ | 26 */ |
27 | 27 |
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.suitebuilder.annotation.SmallTest; | 32 import android.test.suitebuilder.annotation.SmallTest; |
32 | 33 |
33 import android.graphics.Point; | 34 import android.graphics.Point; |
34 | 35 |
35 import static org.webrtc.RendererCommon.ScalingType.*; | 36 import static org.webrtc.RendererCommon.ScalingType.*; |
36 import static org.webrtc.RendererCommon.getDisplaySize; | 37 import static org.webrtc.RendererCommon.getDisplaySize; |
| 38 import static org.webrtc.RendererCommon.getTextureMatrix; |
37 | 39 |
38 public class RendererCommonTest extends ActivityTestCase { | 40 public class RendererCommonTest extends ActivityTestCase { |
39 @SmallTest | 41 @SmallTest |
40 static public void testDisplaySizeNoFrame() { | 42 static public void testDisplaySizeNoFrame() { |
41 assertEquals(getDisplaySize(SCALE_ASPECT_FIT, 0.0f, 0, 0), new Point(0, 0)); | 43 assertEquals(getDisplaySize(SCALE_ASPECT_FIT, 0.0f, 0, 0), new Point(0, 0)); |
42 assertEquals(getDisplaySize(SCALE_ASPECT_FILL, 0.0f, 0, 0), new Point(0, 0))
; | 44 assertEquals(getDisplaySize(SCALE_ASPECT_FILL, 0.0f, 0, 0), new Point(0, 0))
; |
43 assertEquals(getDisplaySize(SCALE_ASPECT_BALANCED, 0.0f, 0, 0), new Point(0,
0)); | 45 assertEquals(getDisplaySize(SCALE_ASPECT_BALANCED, 0.0f, 0, 0), new Point(0,
0)); |
44 } | 46 } |
45 | 47 |
46 @SmallTest | 48 @SmallTest |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 assertEquals(getDisplaySize(SCALE_ASPECT_FILL, 9.0f / 16, 1280, 720), new Po
int(1280, 720)); | 82 assertEquals(getDisplaySize(SCALE_ASPECT_FILL, 9.0f / 16, 1280, 720), new Po
int(1280, 720)); |
81 assertEquals(getDisplaySize(SCALE_ASPECT_BALANCED, 9.0f / 16, 1280, 720), ne
w Point(720, 720)); | 83 assertEquals(getDisplaySize(SCALE_ASPECT_BALANCED, 9.0f / 16, 1280, 720), ne
w Point(720, 720)); |
82 } | 84 } |
83 | 85 |
84 @SmallTest | 86 @SmallTest |
85 static public void testFourToThreeVideoInSixteenToNineDisplay() { | 87 static public void testFourToThreeVideoInSixteenToNineDisplay() { |
86 assertEquals(getDisplaySize(SCALE_ASPECT_FIT, 4.0f / 3, 1280, 720), new Poin
t(960, 720)); | 88 assertEquals(getDisplaySize(SCALE_ASPECT_FIT, 4.0f / 3, 1280, 720), new Poin
t(960, 720)); |
87 assertEquals(getDisplaySize(SCALE_ASPECT_FILL, 4.0f / 3, 1280, 720), new Poi
nt(1280, 720)); | 89 assertEquals(getDisplaySize(SCALE_ASPECT_FILL, 4.0f / 3, 1280, 720), new Poi
nt(1280, 720)); |
88 assertEquals(getDisplaySize(SCALE_ASPECT_BALANCED, 4.0f / 3, 1280, 720), new
Point(1280, 720)); | 90 assertEquals(getDisplaySize(SCALE_ASPECT_BALANCED, 4.0f / 3, 1280, 720), new
Point(1280, 720)); |
89 } | 91 } |
| 92 |
| 93 // Only keep 2 rounded decimals to make float comparison robust. |
| 94 static private double[] round(float[] array) { |
| 95 assertEquals(array.length, 16); |
| 96 final double[] doubleArray = new double[16]; |
| 97 for (int i = 0; i < 16; ++i) { |
| 98 doubleArray[i] = Math.round(100 * array[i]) / 100.0; |
| 99 } |
| 100 return doubleArray; |
| 101 } |
| 102 |
| 103 @SmallTest |
| 104 static public void testTexMatrixDefault() { |
| 105 final float texMatrix[] = new float[16]; |
| 106 getTextureMatrix(texMatrix, 0, false, 1.0f, 1.0f); |
| 107 // TODO(magjed): Every tex matrix contains a vertical flip, because we ignor
e the texture |
| 108 // transform matrix from the SurfaceTexture (which contains a vertical flip)
. Update tests when |
| 109 // this is fixed. |
| 110 // Assert: |
| 111 // u' = u. |
| 112 // v' = 1 - v. |
| 113 MoreAsserts.assertEquals(round(texMatrix), new double[] |
| 114 {1, 0, 0, 0, |
| 115 0, -1, 0, 0, |
| 116 0, 0, 1, 0, |
| 117 0, 1, 0, 1}); |
| 118 } |
| 119 |
| 120 @SmallTest |
| 121 static public void testTexMatrixMirror() { |
| 122 final float texMatrix[] = new float[16]; |
| 123 getTextureMatrix(texMatrix, 0, true, 1.0f, 1.0f); |
| 124 // Assert: |
| 125 // u' = 1 - u. |
| 126 // v' = 1 - v. |
| 127 MoreAsserts.assertEquals(round(texMatrix), new double[] |
| 128 {-1, 0, 0, 0, |
| 129 0, -1, 0, 0, |
| 130 0, 0, 1, 0, |
| 131 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 } |
90 } | 163 } |
OLD | NEW |