OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license | |
5 * that can be found in the LICENSE file in the root of the source | |
6 * tree. An additional intellectual property rights grant can be found | |
7 * in the file PATENTS. All contributing project authors may | |
8 * be found in the AUTHORS file in the root of the source tree. | |
9 */ | |
10 | |
11 package org.appspot.apprtc.test; | |
12 | |
13 import android.test.InstrumentationTestCase; | |
14 import android.test.suitebuilder.annotation.LargeTest; | |
15 import android.test.suitebuilder.annotation.MediumTest; | |
16 import android.test.suitebuilder.annotation.SmallTest; | |
17 | |
18 import org.webrtc.FileVideoCapturer; | |
19 import org.webrtc.VideoCapturer; | |
20 | |
21 import java.io.IOException; | |
22 import java.lang.Thread; | |
23 import java.util.ArrayList; | |
24 import java.util.Random; | |
25 | |
26 public class FileVideoCapturerTest extends InstrumentationTestCase { | |
27 private static class Frame { | |
28 public byte[] data; | |
29 public int width; | |
30 public int height; | |
31 } | |
32 | |
33 public class MockCapturerObserver implements VideoCapturer.CapturerObserver { | |
34 private ArrayList<Frame> frameDatas = new ArrayList<Frame>(); | |
magjed_webrtc
2016/10/20 14:55:33
Make this variable final.
mandermo
2016/10/24 18:08:02
Done.
| |
35 | |
36 public void onCapturerStarted(boolean success) { | |
magjed_webrtc
2016/10/20 14:55:33
Annotate every function with @Override.
mandermo
2016/10/24 18:08:02
Done.
| |
37 // Empty on purpose | |
magjed_webrtc
2016/10/20 14:55:33
assertTrue on success
mandermo
2016/10/24 18:08:02
Done.
| |
38 } | |
39 | |
40 public void onCapturerStopped() { | |
41 // Empty on purpose | |
magjed_webrtc
2016/10/20 14:55:33
Add a dot at the end of every sentence in comments
mandermo
2016/10/24 18:08:02
Done.
| |
42 } | |
43 | |
44 public synchronized void onByteBufferFrameCaptured( | |
45 byte[] data, int width, int height, int rotation, long timeStamp) { | |
46 Frame frame = new Frame(); | |
47 frame.data = data; | |
48 frame.width = width; | |
49 frame.height = height; | |
50 assertTrue(data.length != 0); | |
51 frameDatas.add(frame); | |
52 notify(); | |
53 } | |
54 | |
55 public void onTextureFrameCaptured(int width, int height, int oesTextureId, | |
56 float[] transformMatrix, int rotation, long timestamp) { | |
57 // Empty on purpose | |
58 } | |
59 | |
60 public void onOutputFormatRequest(int width, int height, int framerate) { | |
magjed_webrtc
2016/10/20 14:55:33
This function is no longer part of the interface,
| |
61 // Empty on purpose | |
62 } | |
63 | |
64 public synchronized ArrayList<Frame> getMinimumFramesBlocking(int minFrames) | |
65 throws InterruptedException { | |
66 while (frameDatas.size() < minFrames) { | |
67 wait(); | |
68 } | |
69 return new ArrayList<Frame>(frameDatas); | |
70 } | |
71 } | |
72 | |
73 @SmallTest | |
74 public void testVideoCaptureFromFile() throws InterruptedException, IOExceptio n { | |
75 final int FRAME_WIDTH = 640; | |
76 final int FRAME_HEIGHT = 360; | |
77 FileVideoCapturer fileVideoCapturer = new FileVideoCapturer( | |
78 "/sdcard/chromium_tests_root/resources/reference_video_640x360_30fps_4fr ames.y4m"); | |
79 MockCapturerObserver capturerObserver = new MockCapturerObserver(); | |
80 fileVideoCapturer.initialize(null, null, capturerObserver); | |
81 fileVideoCapturer.startCapture(4, 4, 33); | |
82 | |
83 // The expected data at the pseudo randomly choosen positions | |
84 String[] expectedFrames = { | |
85 "7C543C7D7C6C86B31055787FA03F5CE7B0507D5AA42A7B5E867E4462977F99707F95", | |
86 "CF864F7F7E6C416975871E687673857CA56B88DA7E6F4D991C62A4B7537B7D978E95", | |
87 "918CA66F877DDE7473A8817E7F7C7E38807D7971E7977F6B877D417B7E7C808E408F", | |
88 "597D8B4772436380A6388380B6AC7E869E58B46A7B78AB722E6C298B6C66A8678375"}; | |
89 | |
90 ArrayList<Frame> frameDatas; | |
91 try { | |
92 frameDatas = capturerObserver.getMinimumFramesBlocking(expectedFrames.leng th); | |
93 } catch (InterruptedException e) { | |
94 throw new RuntimeException(e); | |
95 } | |
96 assertTrue(expectedFrames.length == frameDatas.size()); | |
97 | |
98 fileVideoCapturer.stopCapture(); | |
99 fileVideoCapturer.dispose(); | |
100 | |
101 for (int i = 0; i < expectedFrames.length; ++i) { | |
magjed_webrtc
2016/10/20 14:55:33
Since it's impossible to verify this manually anyw
mandermo
2016/10/24 18:08:02
Now use hashing approach. Using small file is also
magjed_webrtc
2016/10/25 08:02:47
Yes, a small file would be optimal. Can you do the
| |
102 Frame frame = frameDatas.get(i); | |
103 // Same seed everytime | |
104 Random random = new Random(i); | |
105 | |
106 assertEquals(FRAME_WIDTH, frame.width); | |
107 assertEquals(FRAME_HEIGHT, frame.height); | |
108 assertEquals(FRAME_WIDTH * FRAME_HEIGHT * 3 / 2, frame.data.length); | |
109 | |
110 StringBuilder builder = new StringBuilder(); | |
111 for (int k = 0; k < expectedFrames[i].length() / 2; ++k) { | |
112 int pos = random.nextInt(frame.data.length); | |
113 builder.append(String.format("%02X", frame.data[pos])); | |
114 } | |
115 | |
116 assertEquals(expectedFrames[i], builder.toString()); | |
117 } | |
118 } | |
119 } | |
OLD | NEW |