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

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

Issue 2405463002: Testing of FileVideoCapturer (Closed)
Patch Set: Merge branch 'master' into with_yuv_file_reader Created 4 years, 1 month 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.nio.charset.StandardCharsets;
24 import java.util.ArrayList;
25 import java.util.Arrays;
26
27 public class FileVideoCapturerTest extends InstrumentationTestCase {
28 private static class Frame {
29 public byte[] data;
30 public int width;
31 public int height;
32 }
33
34 public class MockCapturerObserver implements VideoCapturer.CapturerObserver {
35 private final ArrayList<Frame> frameDatas = new ArrayList<Frame>();
36
37 @Override
38 public void onCapturerStarted(boolean success) {
39 assertTrue(success);
40 }
41
42 @Override
43 public void onCapturerStopped() {
44 // Empty on purpose.
45 }
46
47 @Override
48 public synchronized void onByteBufferFrameCaptured(
49 byte[] data, int width, int height, int rotation, long timeStamp) {
50 Frame frame = new Frame();
51 frame.data = data;
52 frame.width = width;
53 frame.height = height;
54 assertTrue(data.length != 0);
55 frameDatas.add(frame);
56 notify();
57 }
58
59 @Override
60 public void onTextureFrameCaptured(int width, int height, int oesTextureId,
61 float[] transformMatrix, int rotation, long timestamp) {
62 // Empty on purpose.
63 }
64
65 public synchronized ArrayList<Frame> getMinimumFramesBlocking(int minFrames)
66 throws InterruptedException {
67 while (frameDatas.size() < minFrames) {
68 wait();
69 }
70 return new ArrayList<Frame>(frameDatas);
71 }
72 }
73
74 @SmallTest
75 public void testVideoCaptureFromFile() throws InterruptedException, IOExceptio n {
76 final int FRAME_WIDTH = 4;
77 final int FRAME_HEIGHT = 4;
78 final FileVideoCapturer fileVideoCapturer = new FileVideoCapturer(
79 "/sdcard/chromium_tests_root/webrtc/examples/androidtests/src/org/appspo t/apprtc/test/"
80 + "capturetestvideo.y4m");
81 final MockCapturerObserver capturerObserver = new MockCapturerObserver();
82 fileVideoCapturer.initialize(null, null, capturerObserver);
83 fileVideoCapturer.startCapture(FRAME_WIDTH, FRAME_HEIGHT, 33);
84
85 final String[] expectedFrames = {
86 "THIS IS JUST SOME TEXT x", "THE SECOND FRAME qwerty.", "HERE IS THE THR ID FRAME!"};
87
88 final ArrayList<Frame> frameDatas;
89 frameDatas = capturerObserver.getMinimumFramesBlocking(expectedFrames.length );
90
91 assertEquals(expectedFrames.length, frameDatas.size());
92
93 fileVideoCapturer.stopCapture();
94 fileVideoCapturer.dispose();
95
96 for (int i = 0; i < expectedFrames.length; ++i) {
97 Frame frame = frameDatas.get(i);
98
99 assertEquals(FRAME_WIDTH, frame.width);
100 assertEquals(FRAME_HEIGHT, frame.height);
101 assertEquals(FRAME_WIDTH * FRAME_HEIGHT * 3 / 2, frame.data.length);
102
103 byte[] expectedNV12Bytes = new byte[frame.data.length];
104 FileVideoCapturer.nativeI420ToNV21(expectedFrames[i].getBytes(StandardChar sets.US_ASCII),
105 FRAME_WIDTH, FRAME_HEIGHT, expectedNV12Bytes);
106
107 assertTrue(Arrays.equals(expectedNV12Bytes, frame.data));
108 }
109 }
110 }
OLDNEW
« no previous file with comments | « webrtc/examples/BUILD.gn ('k') | webrtc/examples/androidtests/src/org/appspot/apprtc/test/capturetestvideo.y4m » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698