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

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

Issue 2405463002: Testing of FileVideoCapturer (Closed)
Patch Set: Merging to be up to date with master 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
« no previous file with comments | « webrtc/examples/BUILD.gn ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 {
sakal 2016/10/19 10:59:32 Have you looked into if it possible to make this a
mandermo 2016/10/19 17:02:03 The problem is that native code is used by FileVid
27 private static class Frame {
28 byte[] data;
sakal 2016/10/19 10:59:32 nit: make these public
mandermo 2016/10/19 17:02:03 Done.
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(
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) {
61 // Empty on purpose
62 }
63
64 public synchronized ArrayList<Frame> getFrames() {
sakal 2016/10/19 10:59:32 This is never actually used, please remove.
mandermo 2016/10/19 17:02:03 Done.
65 return new ArrayList<Frame>(frameDatas);
66 }
67
68 public synchronized ArrayList<Frame> getMinimumFramesBlocking(int minFrames)
69 throws InterruptedException {
70 while (frameDatas.size() < minFrames) {
71 wait();
72 }
73 return new ArrayList<Frame>(frameDatas);
74 }
75 }
76
77 @SmallTest
78 public void testVideoCaptureFromFile() throws InterruptedException, IOExceptio n {
79 final int FRAME_WIDTH = 640;
80 final int FRAME_HEIGHT = 360;
81 FileVideoCapturer fileVideoCapturer = new FileVideoCapturer(
82 "/sdcard/chromium_tests_root/resources/reference_video_640x360_30fps_4fr ames.y4m");
83 MockCapturerObserver capturerObserver = new MockCapturerObserver();
84 fileVideoCapturer.initialize(null, null, capturerObserver);
85 fileVideoCapturer.startCapture(4, 4, 33);
86
87 String[] expectedFrames = {
88 "7C543C7D7C6C86B31055787FA03F5CE7B0507D5AA42A7B5E867E4462977F99707F958DA DA67F7D7B8F6B5535939BA98F2C307D73757C7A4A7A44897DEA84A37A7C647F7F7C6677B37AB71E9 C7C5775497D986C49C2398D80827EDE707D7F876988782D72",
89 "86808A91829B8042762FA4EB8B3BA17480597F2E91A9657F7F7FA1697CED8087DB79865 D6A6F32EA332D7E8072876F7676757B7DE07D7E7F83947874702132AF717E25777339A4816D727D3 D80CB5C7987967F38467D745932445526807F7C7F7290B29B",
90 "6D4A4F7F52847760358C71EB7F42AB789B6E3E6E35679A437E473E407F4677A87B5F8F5 092447F82837F7E727980763D857D217E368982837F4661C8807B76A2AF7A91733B847D7DEBBC804 66F816E80B35976738F7C4355877680EE431F0D7DA223807E",
91 "7FCE8B938B4B88847F227D29909E8F837EC3525C3D807E91738E8A733D36885326743A8 08680B47E57804AAB72413824776A367628EB784F3A7DD8EB7A6731935E95685B7C408081A7EB7DE 4528D9A1F9195892E7D457880887A308C8C106A91D38F7E7E"};
92
93 ArrayList<Frame> frameDatas;
94 try {
95 frameDatas = capturerObserver.getMinimumFramesBlocking(expectedFrames.leng th);
96 } catch (InterruptedException e) {
97 throw new RuntimeException(e);
98 }
99 assertTrue(expectedFrames.length <= frameDatas.size());
100
101 fileVideoCapturer.stopCapture();
102
103 for (int i = 0; i < expectedFrames.length; ++i) {
104 Frame frame = frameDatas.get(i);
105 Random random = new Random(42 * i);
106
107 assertEquals(FRAME_WIDTH, frame.width);
108 assertEquals(FRAME_HEIGHT, frame.height);
109 assertEquals(FRAME_WIDTH * FRAME_HEIGHT * 3 / 2, frame.data.length);
110
111 StringBuilder builder = new StringBuilder();
112 for (int k = 0; k < expectedFrames[i].length() / 2; ++k) {
113 int pos = random.nextInt(frame.data.length);
114 builder.append(String.format("%02X", frame.data[pos]));
115 }
116
117 assertEquals(expectedFrames[i], builder.toString());
118 }
119 }
120 }
OLDNEW
« no previous file with comments | « webrtc/examples/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698