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.webrtc; | |
12 | |
13 import static org.junit.Assert.assertEquals; | |
14 | |
15 import android.os.Environment; | |
16 import android.support.test.filters.SmallTest; | |
17 import java.io.File; | |
18 import java.io.IOException; | |
19 import java.io.RandomAccessFile; | |
20 import java.lang.Thread; | |
21 import java.nio.ByteBuffer; | |
22 import java.nio.charset.StandardCharsets; | |
23 import java.util.ArrayList; | |
24 import java.util.Random; | |
25 import org.chromium.base.test.BaseJUnit4ClassRunner; | |
26 import org.junit.Test; | |
27 import org.junit.runner.RunWith; | |
28 | |
29 @RunWith(BaseJUnit4ClassRunner.class) | |
30 public class VideoFileRendererTest { | |
31 @Test | |
32 @SmallTest | |
33 public void testYuvRenderingToFile() throws InterruptedException, IOException
{ | |
34 EglBase eglBase = EglBase.create(); | |
35 final String videoOutPath = Environment.getExternalStorageDirectory().getPat
h() | |
36 + "/chromium_tests_root/testvideoout.y4m"; | |
37 int frameWidth = 4; | |
38 int frameHeight = 4; | |
39 VideoFileRenderer videoFileRenderer = | |
40 new VideoFileRenderer(videoOutPath, frameWidth, frameHeight, eglBase.get
EglBaseContext()); | |
41 | |
42 String[] frames = { | |
43 "THIS IS JUST SOME TEXT x", "THE SECOND FRAME qwerty.", "HERE IS THE THR
ID FRAME!"}; | |
44 | |
45 for (String frameStr : frames) { | |
46 int[] planeSizes = { | |
47 frameWidth * frameWidth, frameWidth * frameHeight / 4, frameWidth * fr
ameHeight / 4}; | |
48 | |
49 byte[] frameBytes = frameStr.getBytes(StandardCharsets.US_ASCII); | |
50 ByteBuffer[] yuvPlanes = new ByteBuffer[3]; | |
51 int pos = 0; | |
52 for (int i = 0; i < 3; i++) { | |
53 yuvPlanes[i] = ByteBuffer.allocateDirect(planeSizes[i]); | |
54 yuvPlanes[i].put(frameBytes, pos, planeSizes[i]); | |
55 pos += planeSizes[i]; | |
56 } | |
57 | |
58 int[] yuvStrides = {frameWidth, frameWidth / 2, frameWidth / 2}; | |
59 | |
60 VideoRenderer.I420Frame frame = | |
61 new VideoRenderer.I420Frame(frameWidth, frameHeight, 0, yuvStrides, yu
vPlanes, 0); | |
62 | |
63 videoFileRenderer.renderFrame(frame); | |
64 } | |
65 videoFileRenderer.release(); | |
66 | |
67 RandomAccessFile writtenFile = new RandomAccessFile(videoOutPath, "r"); | |
68 try { | |
69 int length = (int) writtenFile.length(); | |
70 byte[] data = new byte[length]; | |
71 writtenFile.readFully(data); | |
72 String fileContent = new String(data, StandardCharsets.US_ASCII); | |
73 String expected = "YUV4MPEG2 C420 W4 H4 Ip F30:1 A1:1\n" | |
74 + "FRAME\n" | |
75 + "THIS IS JUST SOME TEXT xFRAME\n" | |
76 + "THE SECOND FRAME qwerty.FRAME\n" | |
77 + "HERE IS THE THRID FRAME!"; | |
78 assertEquals(expected, fileContent); | |
79 } finally { | |
80 writtenFile.close(); | |
81 } | |
82 | |
83 new File(videoOutPath).delete(); | |
84 } | |
85 } | |
OLD | NEW |