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 byte[] data; | |
29 int width; | |
30 int height; | |
31 } | |
32 | |
33 public class MockCapturerObserver implements VideoCapturer.CapturerObserver { | |
34 private ArrayList<Frame> frameDatas = new ArrayList<Frame>(); | |
35 | |
36 public void onCapturerStarted(boolean success) { | |
37 // Empty on purpose | |
38 } | |
39 | |
40 public void onCapturerStopped() { | |
41 // Empty on purpose | |
42 } | |
43 | |
44 public synchronized void onByteBufferFrameCaptured(byte[] data, int width, i nt height, int rotation, | |
45 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( | |
56 int width, int height, int oesTextureId, float[] transformMatrix, int ro tation, | |
57 long timestamp) { | |
58 // Empty on purpose | |
59 } | |
60 | |
61 public void onOutputFormatRequest(int width, int height, int framerate) { | |
62 // Empty on purpose | |
63 } | |
64 | |
65 public synchronized ArrayList<Frame> getFrames() { | |
66 return new ArrayList<Frame>(frameDatas); | |
67 } | |
68 | |
69 public synchronized ArrayList<Frame> getMinimunFramesBlocking( | |
kjellander_webrtc
2016/10/12 01:00:23
getMinimunFramesBlocking -> getMinimumFramesBlocki
| |
70 int minFrames) throws InterruptedException { | |
71 while (frameDatas.size() < minFrames) { | |
72 wait(); | |
73 } | |
74 return new ArrayList<Frame>(frameDatas); | |
75 } | |
76 } | |
77 | |
78 @SmallTest | |
79 public void testVideoCaptureFromFile() throws InterruptedException, IOExceptio n { | |
80 final int FRAME_WIDTH = 640; | |
81 final int FRAME_HEIGHT = 360; | |
82 FileVideoCapturer fileVideoCapturer = new FileVideoCapturer("/storage/emulat ed/0/reference_video_640x360_30fps_4frames.y4m"); | |
83 MockCapturerObserver capturerObserver = new MockCapturerObserver(); | |
84 fileVideoCapturer.initialize(null, null, capturerObserver); | |
85 fileVideoCapturer.startCapture(4, 4, 33); | |
86 | |
87 String[] expectedFrames = { | |
88 "EBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEEDD1E0 D10100D1EDDEEEBEBEEDD1E0D10100D1EDDEEEBEBEBEBEBEBEBEBEBEBEBEBEBEBEEDD1E0D1010101 0101010100D1EDDEEEBEBEEDD1E0D10100D1EDDEEEBEBEB", | |
89 "EBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEEDD1E0 D10100D1EDDEEEBEBEEDD1E0D10100D1EDDEEEBEBEBEBEBEBEBEBEBEBEBEBEBEBEEDD1E0D1010101 0101010100D1EDDEEEBEBEEDD1E0D10100D1EDDEEEBEBEB", | |
90 "EBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEEDD1E0 D10100D1EDDEEEBEBEEDD1E0D10100D1EDDEEEBEBEBEBEBEBEBEBEBEBEBEBEBEBEEDD1E0D1010101 0101010100D1EDDEEEBEBEEDD1E0D10100D1EDDEEEBEBEB", | |
91 "EBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEEDD1E0 D10100D1EDDEEEBEBEEDD1E0D10100D1EDDEEEBEBEBEBEBEBEBEBEBEBEBEBEBEBEEDD1E0D1010101 0101010100D1EDDEEEBEBEEDD1E0D10100D1EDDEEEBEBEB"}; | |
92 | |
93 ArrayList<Frame> frameDatas; | |
94 try { | |
95 frameDatas = capturerObserver.getMinimunFramesBlocking(expectedFrames.leng th); | |
96 } | |
97 catch (InterruptedException e) { | |
kjellander_webrtc
2016/10/12 01:00:23
move to line above, e.g.
} catch (InterruptedExcep
| |
98 throw new RuntimeException(e); | |
99 } | |
100 assertTrue(expectedFrames.length <= frameDatas.size()); | |
101 | |
102 fileVideoCapturer.stopCapture(); | |
103 | |
104 for (int i=0; i<expectedFrames.length; ++i) { | |
105 Frame frame = frameDatas.get(i); | |
106 Random random = new Random(42*i); | |
107 | |
108 assertEquals(FRAME_WIDTH, frame.width); | |
109 assertEquals(FRAME_HEIGHT, frame.height); | |
110 assertEquals(FRAME_WIDTH * FRAME_HEIGHT * 3 / 2, frame.data.length); | |
111 | |
112 StringBuilder b = new StringBuilder(); | |
113 for (int k = 0; k < expectedFrames[i].length() / 2; ++k) { | |
114 int pos = random.nextInt(frame.data.length); | |
115 int v = frame.data[pos] & 0xFF; | |
116 b.append(String.format("%02X", frame.data[k])); | |
117 } | |
118 | |
119 assertEquals(expectedFrames[i], b.toString()); | |
120 } | |
121 } | |
122 } | |
OLD | NEW |