OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright 2015 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 package org.webrtc; | |
11 | |
12 import org.webrtc.MediaCodecVideoEncoder.OutputBufferInfo; | |
13 | |
14 import android.annotation.TargetApi; | |
15 import android.opengl.GLES11Ext; | |
16 import android.opengl.GLES20; | |
17 import android.os.Build; | |
18 import android.test.ActivityTestCase; | |
19 import android.test.suitebuilder.annotation.SmallTest; | |
20 import android.util.Log; | |
21 | |
22 import java.nio.ByteBuffer; | |
23 | |
24 @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) | |
25 public final class MediaCodecVideoEncoderTest extends ActivityTestCase { | |
26 final static String TAG = "MediaCodecVideoEncoderTest"; | |
27 | |
28 @SmallTest | |
29 public static void testInitializeUsingByteBuffer() { | |
30 if (!MediaCodecVideoEncoder.isVp8HwSupported()) { | |
31 Log.i(TAG, "Hardware does not support VP8 encoding, skipping testInitRelea
seUsingByteBuffer"); | |
32 return; | |
33 } | |
34 MediaCodecVideoEncoder encoder = new MediaCodecVideoEncoder(); | |
35 assertTrue(encoder.initEncode( | |
36 MediaCodecVideoEncoder.VideoCodecType.VIDEO_CODEC_VP8, 640, 480, 300, 30
, null)); | |
37 encoder.release(); | |
38 } | |
39 | |
40 @SmallTest | |
41 public static void testInitilizeUsingTextures() { | |
42 if (!MediaCodecVideoEncoder.isVp8HwSupportedUsingTextures()) { | |
43 Log.i(TAG, "hardware does not support VP8 encoding, skipping testEncoderUs
ingTextures"); | |
44 return; | |
45 } | |
46 EglBase14 eglBase = new EglBase14(null, EglBase.CONFIG_PLAIN); | |
47 MediaCodecVideoEncoder encoder = new MediaCodecVideoEncoder(); | |
48 assertTrue(encoder.initEncode(MediaCodecVideoEncoder.VideoCodecType.VIDEO_CO
DEC_VP8, 640, 480, | |
49 300, 30, eglBase.getEglBaseContext())); | |
50 encoder.release(); | |
51 eglBase.release(); | |
52 } | |
53 | |
54 @SmallTest | |
55 public static void testInitializeUsingByteBufferReInitilizeUsingTextures() { | |
56 if (!MediaCodecVideoEncoder.isVp8HwSupportedUsingTextures()) { | |
57 Log.i(TAG, "hardware does not support VP8 encoding, skipping testEncoderUs
ingTextures"); | |
58 return; | |
59 } | |
60 MediaCodecVideoEncoder encoder = new MediaCodecVideoEncoder(); | |
61 assertTrue(encoder.initEncode( | |
62 MediaCodecVideoEncoder.VideoCodecType.VIDEO_CODEC_VP8, 640, 480, 300, 30
, null)); | |
63 encoder.release(); | |
64 EglBase14 eglBase = new EglBase14(null, EglBase.CONFIG_PLAIN); | |
65 assertTrue(encoder.initEncode(MediaCodecVideoEncoder.VideoCodecType.VIDEO_CO
DEC_VP8, 640, 480, | |
66 300, 30, eglBase.getEglBaseContext())); | |
67 encoder.release(); | |
68 eglBase.release(); | |
69 } | |
70 | |
71 @SmallTest | |
72 public static void testEncoderUsingByteBuffer() throws InterruptedException { | |
73 if (!MediaCodecVideoEncoder.isVp8HwSupported()) { | |
74 Log.i(TAG, "Hardware does not support VP8 encoding, skipping testEncoderUs
ingByteBuffer"); | |
75 return; | |
76 } | |
77 | |
78 final int width = 640; | |
79 final int height = 480; | |
80 final int min_size = width * height * 3 / 2; | |
81 final long presentationTimestampUs = 2; | |
82 | |
83 MediaCodecVideoEncoder encoder = new MediaCodecVideoEncoder(); | |
84 | |
85 assertTrue(encoder.initEncode( | |
86 MediaCodecVideoEncoder.VideoCodecType.VIDEO_CODEC_VP8, width, height, 30
0, 30, null)); | |
87 ByteBuffer[] inputBuffers = encoder.getInputBuffers(); | |
88 assertNotNull(inputBuffers); | |
89 assertTrue(min_size <= inputBuffers[0].capacity()); | |
90 | |
91 int bufferIndex; | |
92 do { | |
93 Thread.sleep(10); | |
94 bufferIndex = encoder.dequeueInputBuffer(); | |
95 } while (bufferIndex == -1); // |-1| is returned when there is no buffer ava
ilable yet. | |
96 | |
97 assertTrue(bufferIndex >= 0); | |
98 assertTrue(bufferIndex < inputBuffers.length); | |
99 assertTrue(encoder.encodeBuffer(true, bufferIndex, min_size, presentationTim
estampUs)); | |
100 | |
101 OutputBufferInfo info; | |
102 do { | |
103 info = encoder.dequeueOutputBuffer(); | |
104 Thread.sleep(10); | |
105 } while (info == null); | |
106 assertTrue(info.index >= 0); | |
107 assertEquals(presentationTimestampUs, info.presentationTimestampUs); | |
108 assertTrue(info.buffer.capacity() > 0); | |
109 encoder.releaseOutputBuffer(info.index); | |
110 | |
111 encoder.release(); | |
112 } | |
113 | |
114 @SmallTest | |
115 public static void testEncoderUsingTextures() throws InterruptedException { | |
116 if (!MediaCodecVideoEncoder.isVp8HwSupportedUsingTextures()) { | |
117 Log.i(TAG, "Hardware does not support VP8 encoding, skipping testEncoderUs
ingTextures"); | |
118 return; | |
119 } | |
120 | |
121 final int width = 640; | |
122 final int height = 480; | |
123 final long presentationTs = 2; | |
124 | |
125 final EglBase14 eglOesBase = new EglBase14(null, EglBase.CONFIG_PIXEL_BUFFER
); | |
126 eglOesBase.createDummyPbufferSurface(); | |
127 eglOesBase.makeCurrent(); | |
128 int oesTextureId = GlUtil.generateTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES)
; | |
129 | |
130 // TODO(perkj): This test is week since we don't fill the texture with valid
data with correct | |
131 // width and height and verify the encoded data. Fill the OES texture and fi
gure out a way to | |
132 // verify that the output make sense. | |
133 | |
134 MediaCodecVideoEncoder encoder = new MediaCodecVideoEncoder(); | |
135 | |
136 assertTrue(encoder.initEncode(MediaCodecVideoEncoder.VideoCodecType.VIDEO_CO
DEC_VP8, width, | |
137 height, 300, 30, eglOesBase.getEglBaseContext())); | |
138 assertTrue( | |
139 encoder.encodeTexture(true, oesTextureId, RendererCommon.identityMatrix(
), presentationTs)); | |
140 GlUtil.checkNoGLES2Error("encodeTexture"); | |
141 | |
142 // It should be Ok to delete the texture after calling encodeTexture. | |
143 GLES20.glDeleteTextures(1, new int[] {oesTextureId}, 0); | |
144 | |
145 OutputBufferInfo info = encoder.dequeueOutputBuffer(); | |
146 while (info == null) { | |
147 info = encoder.dequeueOutputBuffer(); | |
148 Thread.sleep(20); | |
149 } | |
150 assertTrue(info.index != -1); | |
151 assertTrue(info.buffer.capacity() > 0); | |
152 assertEquals(presentationTs, info.presentationTimestampUs); | |
153 encoder.releaseOutputBuffer(info.index); | |
154 | |
155 encoder.release(); | |
156 eglOesBase.release(); | |
157 } | |
158 } | |
OLD | NEW |