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

Side by Side Diff: webrtc/examples/androidtests/src/org/appspot/apprtc/test/FileVideoCapturerTest.java

Issue 2405463002: Testing of FileVideoCapturer (Closed)
Patch Set: Created 4 years, 2 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
OLDNEW
(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 public class MockCapturerObserver implements VideoCapturer.CapturerObserver {
kjellander_webrtc 2016/10/07 20:24:02 nit: add blank line
33 //private ArrayList<byte[]> frameDatas = new ArrayList<byte[]>();
kjellander_webrtc 2016/10/07 20:24:02 Remove commented code.
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 }
53
54 public void onTextureFrameCaptured(
55 int width, int height, int oesTextureId, float[] transformMatrix, int ro tation,
56 long timestamp) {
57 // Empty on purpose
58 }
59
60 public void onOutputFormatRequest(int width, int height, int framerate) {
61 // Empty on purpose
62 }
63
64 public synchronized ArrayList<Frame> getFrames() {
65 return new ArrayList<Frame>(frameDatas);
66 }
67 }
68
69 char toHex(int x) {
70 if (x >= 10) {
71 return (char)((x-10) + (int)'A');
72 }
73 return (char)(x + (int)'0');
74 }
75 @SmallTest
kjellander_webrtc 2016/10/07 20:24:02 nit: add blank line
76 public void testVideoCaptureFromFile() throws InterruptedException, IOExceptio n {
77 FileVideoCapturer fileVideoCapturer = new FileVideoCapturer("/storage/emulat ed/0/reference_video_640x360_30fps_4frames.y4m");
kjellander_webrtc 2016/10/07 20:24:02 I think this should be either /sdcard/chromium_tes
78 MockCapturerObserver capturerObserver = new MockCapturerObserver();
79 fileVideoCapturer.initialize(null, null, capturerObserver);
80 fileVideoCapturer.startCapture(4, 4, 33);
81 Thread.sleep(1000);
kjellander_webrtc 2016/10/07 20:24:02 Is there another way to implement this instead of
82 fileVideoCapturer.stopCapture();
83
84 String[] expectedFrames = {
85 "EBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEEDD1E0 D10100D1EDDEEEBEBEEDD1E0D10100D1EDDEEEBEBEBEBEBEBEBEBEBEBEBEBEBEBEEDD1E0D1010101 0101010100D1EDDEEEBEBEEDD1E0D10100D1EDDEEEBEBEB",
86 "EBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEEDD1E0 D10100D1EDDEEEBEBEEDD1E0D10100D1EDDEEEBEBEBEBEBEBEBEBEBEBEBEBEBEBEEDD1E0D1010101 0101010100D1EDDEEEBEBEEDD1E0D10100D1EDDEEEBEBEB",
87 "EBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEEDD1E0 D10100D1EDDEEEBEBEEDD1E0D10100D1EDDEEEBEBEBEBEBEBEBEBEBEBEBEBEBEBEEDD1E0D1010101 0101010100D1EDDEEEBEBEEDD1E0D10100D1EDDEEEBEBEB",
88 "EBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEEDD1E0 D10100D1EDDEEEBEBEEDD1E0D10100D1EDDEEEBEBEBEBEBEBEBEBEBEBEBEBEBEBEEDD1E0D1010101 0101010100D1EDDEEEBEBEEDD1E0D10100D1EDDEEEBEBEB"};
89
90 // TODO use monitor to start verification when enough frames have been colle cted.
91 ArrayList<Frame> frameDatas = capturerObserver.getFrames();
92 assertTrue(4 < frameDatas.size());
93
94 final int FRAME_WIDTH = 640;
kjellander_webrtc 2016/10/07 20:24:02 move these constants up to line 77 so it's easier
95 final int FRAME_HEIGHT = 360;
96 for (int i=0; i<expectedFrames.length; ++i) {
97 Frame frame = frameDatas.get(i);
98 Random random = new Random(42*i);
99
100 assertEquals(FRAME_WIDTH, frame.width);
101 assertEquals(FRAME_HEIGHT, frame.height);
102 assertEquals(FRAME_WIDTH * FRAME_HEIGHT * 3 / 2, frame.data.length);
103
104 StringBuilder b = new StringBuilder();
105 for (int k = 0; k < expectedFrames[i].length() / 2; ++k) {
106 int pos = random.nextInt(frame.data.length);
107 int v = frame.data[pos] & 0xFF;
108 b.append(String.format("%02X", frame.data[k]));
109 }
110
111 assertEquals(expectedFrames[i], b.toString());
112 }
113 }
114 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698