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

Side by Side Diff: talk/app/webrtc/androidtests/src/org/webrtc/MediaCodecVideoEncoderTest.java

Issue 1406203002: Reland "Prepare MediaCodecVideoEncoder for surface textures."" (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Moved getting inputbuffer to before storing pending frames. Created 5 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 * libjingle
3 * Copyright 2015 Google Inc.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27 package org.webrtc;
28
29 import java.nio.ByteBuffer;
30
31 import android.test.ActivityTestCase;
32 import android.test.suitebuilder.annotation.SmallTest;
33 import android.util.Log;
34
35 import org.webrtc.MediaCodecVideoEncoder.OutputBufferInfo;
36
37 public final class MediaCodecVideoEncoderTest extends ActivityTestCase {
38 final static String TAG = "MediaCodecVideoEncoderTest";
39
40 @SmallTest
41 public static void testInitReleaseUsingByteBuffer() {
42 if (!MediaCodecVideoEncoder.isVp8HwSupported()) {
43 Log.i(TAG,
44 "Hardware does not support VP8 encoding, skipping testInitReleaseUsi ngByteBuffer");
45 return;
46 }
47 MediaCodecVideoEncoder encoder = new MediaCodecVideoEncoder();
48 assertTrue(encoder.initEncode(
49 MediaCodecVideoEncoder.VideoCodecType.VIDEO_CODEC_VP8, 640, 480, 300, 30 ));
50 encoder.release();
51 }
52
53 @SmallTest
54 public static void testEncoderUsingByteBuffer() throws InterruptedException {
55 if (!MediaCodecVideoEncoder.isVp8HwSupported()) {
56 Log.i(TAG, "Hardware does not support VP8 encoding, skipping testEncoderUs ingByteBuffer");
57 return;
58 }
59
60 final int width = 640;
61 final int height = 480;
62 final int min_size = width * height * 3 / 2;
63 final long presentationTimestampUs = 2;
64
65 MediaCodecVideoEncoder encoder = new MediaCodecVideoEncoder();
66
67 assertTrue(encoder.initEncode(
68 MediaCodecVideoEncoder.VideoCodecType.VIDEO_CODEC_VP8, width, height, 30 0, 30));
69 ByteBuffer[] inputBuffers = encoder.getInputBuffers();
70 assertNotNull(inputBuffers);
71 assertTrue(min_size <= inputBuffers[0].capacity());
72
73 int bufferIndex;
74 do {
75 Thread.sleep(10);
76 bufferIndex = encoder.dequeueInputBuffer();
77 } while (bufferIndex == -1); // |-1| is returned when there is no buffer ava ilable yet.
78
79 assertTrue(bufferIndex >= 0);
80 assertTrue(bufferIndex < inputBuffers.length);
81 assertTrue(encoder.encodeBuffer(true, bufferIndex, min_size, presentationTim estampUs));
82
83 OutputBufferInfo info;
84 do {
85 info = encoder.dequeueOutputBuffer();
86 Thread.sleep(10);
87 } while (info == null);
88 assertTrue(info.index >= 0);
89 assertEquals(presentationTimestampUs, info.presentationTimestampUs);
90 assertTrue(info.buffer.capacity() > 0);
91 encoder.releaseOutputBuffer(info.index);
92
93 encoder.release();
94 }
95 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698