OLD | NEW |
---|---|
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2015 Google Inc. | 3 * Copyright 2015 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
11 * this list of conditions and the following disclaimer in the documentation | 11 * this list of conditions and the following disclaimer in the documentation |
12 * and/or other materials provided with the distribution. | 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 | 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. | 14 * derived from this software without specific prior written permission. |
15 * | 15 * |
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED | 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 | 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO | 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | 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, | 22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | 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 | 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 */ | 26 */ |
27 package org.webrtc; | 27 package org.webrtc; |
28 | 28 |
29 import java.nio.ByteBuffer; | 29 import java.nio.ByteBuffer; |
30 | 30 import android.annotation.TargetApi; |
31 import android.opengl.GLES11Ext; | |
32 import android.opengl.GLES20; | |
33 import android.os.Build; | |
31 import android.test.ActivityTestCase; | 34 import android.test.ActivityTestCase; |
32 import android.test.suitebuilder.annotation.SmallTest; | 35 import android.test.suitebuilder.annotation.SmallTest; |
33 import android.util.Log; | 36 import android.util.Log; |
magjed_webrtc
2015/11/18 13:12:52
The import order is wrong.
"Import statements are
perkj_webrtc
2015/11/18 14:51:20
We strictly don't do
| |
37 import org.webrtc.MediaCodecVideoEncoder.OutputBufferInfo; | |
38 import javax.microedition.khronos.egl.EGL10; | |
34 | 39 |
35 import org.webrtc.MediaCodecVideoEncoder.OutputBufferInfo; | 40 @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) |
36 | |
37 public final class MediaCodecVideoEncoderTest extends ActivityTestCase { | 41 public final class MediaCodecVideoEncoderTest extends ActivityTestCase { |
38 final static String TAG = "MediaCodecVideoEncoderTest"; | 42 final static String TAG = "MediaCodecVideoEncoderTest"; |
39 | 43 |
40 @SmallTest | 44 @SmallTest |
41 public static void testInitReleaseUsingByteBuffer() { | 45 public static void testReInitializeUsingByteBuffer() { |
magjed_webrtc
2015/11/18 13:12:52
Why did you modify this test in this CL? And why d
perkj_webrtc
2015/11/18 14:51:20
this is how we use it from c++ sometimes. It felt
magjed_webrtc
2015/11/18 15:38:12
Yeah maybe. I don't know much about our testing 's
| |
42 if (!MediaCodecVideoEncoder.isVp8HwSupported()) { | 46 if (!MediaCodecVideoEncoder.isVp8HwSupported()) { |
43 Log.i(TAG, | 47 Log.i(TAG, |
44 "Hardware does not support VP8 encoding, skipping testInitReleaseUsi ngByteBuffer"); | 48 "Hardware does not support VP8 encoding, skipping testInitReleaseUsi ngByteBuffer"); |
45 return; | 49 return; |
46 } | 50 } |
47 MediaCodecVideoEncoder encoder = new MediaCodecVideoEncoder(); | 51 MediaCodecVideoEncoder encoder = new MediaCodecVideoEncoder(); |
48 assertTrue(encoder.initEncode( | 52 assertTrue(encoder.initEncode( |
49 MediaCodecVideoEncoder.VideoCodecType.VIDEO_CODEC_VP8, 640, 480, 300, 30 )); | 53 MediaCodecVideoEncoder.VideoCodecType.VIDEO_CODEC_VP8, 640, 480, 300, 30 , null)); |
54 encoder.release(); | |
55 assertTrue(encoder.initEncode( | |
56 MediaCodecVideoEncoder.VideoCodecType.VIDEO_CODEC_VP8, 640, 480, 300, 30 , null)); | |
50 encoder.release(); | 57 encoder.release(); |
51 } | 58 } |
52 | 59 |
60 @SmallTest | |
61 public static void testReInitilizeUsingTextures() { | |
62 if (!MediaCodecVideoEncoder.isVp8HwSupportedUsingTextures()) { | |
63 Log.i(TAG, "hardware does not support VP8 encoding, skipping testEncoderUs ingTextures"); | |
64 return; | |
65 } | |
66 MediaCodecVideoEncoder encoder = new MediaCodecVideoEncoder(); | |
67 assertTrue(encoder.initEncode( | |
68 MediaCodecVideoEncoder.VideoCodecType.VIDEO_CODEC_VP8, 640, 480, 300, 30 , | |
69 EGL10.EGL_NO_CONTEXT)); | |
70 encoder.release(); | |
71 assertTrue(encoder.initEncode( | |
72 MediaCodecVideoEncoder.VideoCodecType.VIDEO_CODEC_VP8, 640, 480, 300, 30 , | |
73 EGL10.EGL_NO_CONTEXT)); | |
74 encoder.release(); | |
75 } | |
76 | |
53 @SmallTest | 77 @SmallTest |
54 public static void testEncoderUsingByteBuffer() throws InterruptedException { | 78 public static void testEncoderUsingByteBuffer() throws InterruptedException { |
55 if (!MediaCodecVideoEncoder.isVp8HwSupported()) { | 79 if (!MediaCodecVideoEncoder.isVp8HwSupported()) { |
56 Log.i(TAG, "Hardware does not support VP8 encoding, skipping testEncoderUs ingByteBuffer"); | 80 Log.i(TAG, "Hardware does not support VP8 encoding, skipping testEncoderUs ingByteBuffer"); |
57 return; | 81 return; |
58 } | 82 } |
59 | 83 |
60 final int width = 640; | 84 final int width = 640; |
61 final int height = 480; | 85 final int height = 480; |
62 final int min_size = width * height * 3 / 2; | 86 final int min_size = width * height * 3 / 2; |
63 final long presentationTimestampUs = 2; | 87 final long presentationTimestampUs = 2; |
64 | 88 |
65 MediaCodecVideoEncoder encoder = new MediaCodecVideoEncoder(); | 89 MediaCodecVideoEncoder encoder = new MediaCodecVideoEncoder(); |
66 | 90 |
67 assertTrue(encoder.initEncode( | 91 assertTrue(encoder.initEncode( |
68 MediaCodecVideoEncoder.VideoCodecType.VIDEO_CODEC_VP8, width, height, 30 0, 30)); | 92 MediaCodecVideoEncoder.VideoCodecType.VIDEO_CODEC_VP8, width, height, 30 0, 30, null)); |
69 ByteBuffer[] inputBuffers = encoder.getInputBuffers(); | 93 ByteBuffer[] inputBuffers = encoder.getInputBuffers(); |
70 assertNotNull(inputBuffers); | 94 assertNotNull(inputBuffers); |
71 assertTrue(min_size <= inputBuffers[0].capacity()); | 95 assertTrue(min_size <= inputBuffers[0].capacity()); |
72 | 96 |
73 int bufferIndex; | 97 int bufferIndex; |
74 do { | 98 do { |
75 Thread.sleep(10); | 99 Thread.sleep(10); |
76 bufferIndex = encoder.dequeueInputBuffer(); | 100 bufferIndex = encoder.dequeueInputBuffer(); |
77 } while (bufferIndex == -1); // |-1| is returned when there is no buffer ava ilable yet. | 101 } while (bufferIndex == -1); // |-1| is returned when there is no buffer ava ilable yet. |
78 | 102 |
79 assertTrue(bufferIndex >= 0); | 103 assertTrue(bufferIndex >= 0); |
80 assertTrue(bufferIndex < inputBuffers.length); | 104 assertTrue(bufferIndex < inputBuffers.length); |
81 assertTrue(encoder.encodeBuffer(true, bufferIndex, min_size, presentationTim estampUs)); | 105 assertTrue(encoder.encodeBuffer(true, bufferIndex, min_size, presentationTim estampUs)); |
82 | 106 |
83 OutputBufferInfo info; | 107 OutputBufferInfo info; |
84 do { | 108 do { |
85 info = encoder.dequeueOutputBuffer(); | 109 info = encoder.dequeueOutputBuffer(); |
86 Thread.sleep(10); | 110 Thread.sleep(10); |
87 } while (info == null); | 111 } while (info == null); |
88 assertTrue(info.index >= 0); | 112 assertTrue(info.index >= 0); |
89 assertEquals(presentationTimestampUs, info.presentationTimestampUs); | 113 assertEquals(presentationTimestampUs, info.presentationTimestampUs); |
90 assertTrue(info.buffer.capacity() > 0); | 114 assertTrue(info.buffer.capacity() > 0); |
91 encoder.releaseOutputBuffer(info.index); | 115 encoder.releaseOutputBuffer(info.index); |
92 | 116 |
93 encoder.release(); | 117 encoder.release(); |
94 } | 118 } |
119 | |
120 @SmallTest | |
121 public static void testEncoderUsingTextures() throws InterruptedException { | |
122 if (!MediaCodecVideoEncoder.isVp8HwSupportedUsingTextures()) { | |
123 Log.i(TAG, "Hardware does not support VP8 encoding, skipping testEncoderUs ingTextures"); | |
124 return; | |
125 } | |
126 | |
127 final int width = 640; | |
128 final int height = 480; | |
129 final long presentationTs = 2; | |
130 | |
131 final EglBase eglOesBase = new EglBase(EGL10.EGL_NO_CONTEXT, EglBase.ConfigT ype.PLAIN); | |
magjed_webrtc
2015/11/18 13:12:52
You must make |eglOesBase| current, otherwise it h
perkj_webrtc
2015/11/18 14:51:20
not sure I understand.
magjed_webrtc
2015/11/18 15:38:12
First, you need a current EGLContext for all GLES
| |
132 int oesTextureId = GlUtil.generateTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES) ; | |
133 | |
134 MediaCodecVideoEncoder encoder = new MediaCodecVideoEncoder(); | |
135 | |
136 assertTrue(encoder.initEncode( | |
137 MediaCodecVideoEncoder.VideoCodecType.VIDEO_CODEC_VP8, width, height, 30 0, 30, | |
138 eglOesBase.getContext())); | |
139 assertTrue(encoder.encodeTexture(true, oesTextureId, RendererCommon.identity Matrix(), | |
140 presentationTs)); | |
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 encoder.releaseOutputBuffer(info.index); | |
153 | |
154 encoder.release(); | |
155 eglOesBase.release(); | |
156 } | |
95 } | 157 } |
OLD | NEW |