 Chromium Code Reviews
 Chromium Code Reviews Issue 2405463002:
  Testing of FileVideoCapturer  (Closed)
    
  
    Issue 2405463002:
  Testing of FileVideoCapturer  (Closed) 
  | 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 | |
| 25 public class FileVideoCapturerTest extends InstrumentationTestCase { | |
| 26 private static class Frame { | |
| 27 public byte[] data; | |
| 28 public int width; | |
| 29 public int height; | |
| 30 } | |
| 31 | |
| 32 public class MockCapturerObserver implements VideoCapturer.CapturerObserver { | |
| 33 private final ArrayList<Frame> frameDatas = new ArrayList<Frame>(); | |
| 34 | |
| 35 @Override | |
| 36 public void onCapturerStarted(boolean success) { | |
| 37 assertTrue(success); | |
| 38 } | |
| 39 | |
| 40 @Override | |
| 41 public void onCapturerStopped() { | |
| 42 // Empty on purpose. | |
| 43 } | |
| 44 | |
| 45 @Override | |
| 46 public synchronized void onByteBufferFrameCaptured( | |
| 47 byte[] data, int width, int height, int rotation, long timeStamp) { | |
| 48 Frame frame = new Frame(); | |
| 49 frame.data = data; | |
| 50 frame.width = width; | |
| 51 frame.height = height; | |
| 52 assertTrue(data.length != 0); | |
| 53 frameDatas.add(frame); | |
| 54 notify(); | |
| 55 } | |
| 56 | |
| 57 @Override | |
| 58 public void onTextureFrameCaptured(int width, int height, int oesTextureId, | |
| 59 float[] transformMatrix, int rotation, long timestamp) { | |
| 60 // Empty on purpose. | |
| 61 } | |
| 62 | |
| 63 public synchronized ArrayList<Frame> getMinimumFramesBlocking(int minFrames) | |
| 64 throws InterruptedException { | |
| 65 while (frameDatas.size() < minFrames) { | |
| 66 wait(); | |
| 67 } | |
| 68 return new ArrayList<Frame>(frameDatas); | |
| 69 } | |
| 70 } | |
| 71 | |
| 72 @SmallTest | |
| 73 public void testVideoCaptureFromFile() throws InterruptedException, IOExceptio n { | |
| 74 final int FRAME_WIDTH = 4; | |
| 75 final int FRAME_HEIGHT = 4; | |
| 76 final FileVideoCapturer fileVideoCapturer = new FileVideoCapturer( | |
| 77 "/sdcard/chromium_tests_root/webrtc/examples/androidtests/src/org/appspo t/apprtc/test/capturetestvideo.y4m"); | |
| 78 final MockCapturerObserver capturerObserver = new MockCapturerObserver(); | |
| 79 fileVideoCapturer.initialize(null, null, capturerObserver); | |
| 80 fileVideoCapturer.startCapture(FRAME_WIDTH, FRAME_HEIGHT, 33); | |
| 81 | |
| 82 final String[] expectedFrames = {"54484953204953204A55535420534F4D5845542020 547845", | |
| 83 "544845205345434F4E44204652414D457220747179772E65", | |
| 84 "4845524520495320544845205448524941444D2045462152"}; | |
| 85 | |
| 86 final ArrayList<Frame> frameDatas; | |
| 87 frameDatas = capturerObserver.getMinimumFramesBlocking(expectedFrames.length ); | |
| 88 | |
| 89 assertTrue(expectedFrames.length == frameDatas.size()); | |
| 
magjed_webrtc
2016/10/26 11:20:00
nit: Use assertEquals instead
 | |
| 90 | |
| 91 fileVideoCapturer.stopCapture(); | |
| 92 fileVideoCapturer.dispose(); | |
| 93 | |
| 94 for (int i = 0; i < expectedFrames.length; ++i) { | |
| 95 Frame frame = frameDatas.get(i); | |
| 96 | |
| 97 assertEquals(FRAME_WIDTH, frame.width); | |
| 98 assertEquals(FRAME_HEIGHT, frame.height); | |
| 99 assertEquals(FRAME_WIDTH * FRAME_HEIGHT * 3 / 2, frame.data.length); | |
| 100 | |
| 101 StringBuilder builder = new StringBuilder(); | |
| 102 for (byte b : frame.data) { | |
| 103 builder.append(String.format("%02X", b)); | |
| 104 } | |
| 105 | |
| 106 assertEquals(expectedFrames[i], builder.toString()); | |
| 107 } | |
| 108 } | |
| 109 } | |
| OLD | NEW |