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 android.annotation.TargetApi; |
30 | 30 import android.opengl.GLES11Ext; |
31 import android.opengl.GLES20; | |
32 import android.os.Build; | |
31 import android.test.ActivityTestCase; | 33 import android.test.ActivityTestCase; |
32 import android.test.suitebuilder.annotation.SmallTest; | 34 import android.test.suitebuilder.annotation.SmallTest; |
33 import android.util.Log; | 35 import android.util.Log; |
36 import java.nio.ByteBuffer; | |
37 import javax.microedition.khronos.egl.EGL10; | |
34 | 38 |
35 import org.webrtc.MediaCodecVideoEncoder.OutputBufferInfo; | 39 import org.webrtc.MediaCodecVideoEncoder.OutputBufferInfo; |
36 | 40 |
41 @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) | |
37 public final class MediaCodecVideoEncoderTest extends ActivityTestCase { | 42 public final class MediaCodecVideoEncoderTest extends ActivityTestCase { |
38 final static String TAG = "MediaCodecVideoEncoderTest"; | 43 final static String TAG = "MediaCodecVideoEncoderTest"; |
39 | 44 |
40 @SmallTest | 45 @SmallTest |
41 public static void testInitReleaseUsingByteBuffer() { | 46 public static void testReInitializeUsingByteBuffer() { |
42 if (!MediaCodecVideoEncoder.isVp8HwSupported()) { | 47 if (!MediaCodecVideoEncoder.isVp8HwSupported()) { |
43 Log.i(TAG, | 48 Log.i(TAG, |
44 "Hardware does not support VP8 encoding, skipping testInitReleaseUsi ngByteBuffer"); | 49 "Hardware does not support VP8 encoding, skipping testInitReleaseUsi ngByteBuffer"); |
45 return; | 50 return; |
46 } | 51 } |
47 MediaCodecVideoEncoder encoder = new MediaCodecVideoEncoder(); | 52 MediaCodecVideoEncoder encoder = new MediaCodecVideoEncoder(); |
48 assertTrue(encoder.initEncode( | 53 assertTrue(encoder.initEncode( |
49 MediaCodecVideoEncoder.VideoCodecType.VIDEO_CODEC_VP8, 640, 480, 300, 30 )); | 54 MediaCodecVideoEncoder.VideoCodecType.VIDEO_CODEC_VP8, 640, 480, 300, 30 , null)); |
55 encoder.release(); | |
56 assertTrue(encoder.initEncode( | |
57 MediaCodecVideoEncoder.VideoCodecType.VIDEO_CODEC_VP8, 640, 480, 300, 30 , null)); | |
50 encoder.release(); | 58 encoder.release(); |
51 } | 59 } |
52 | 60 |
61 @SmallTest | |
62 public static void testReInitilizeUsingTextures() { | |
63 if (!MediaCodecVideoEncoder.isVp8HwSupportedUsingTextures()) { | |
64 Log.i(TAG, "hardware does not support VP8 encoding, skipping testEncoderUs ingTextures"); | |
65 return; | |
66 } | |
67 MediaCodecVideoEncoder encoder = new MediaCodecVideoEncoder(); | |
68 assertTrue(encoder.initEncode( | |
69 MediaCodecVideoEncoder.VideoCodecType.VIDEO_CODEC_VP8, 640, 480, 300, 30 , | |
70 EGL10.EGL_NO_CONTEXT)); | |
71 encoder.release(); | |
72 assertTrue(encoder.initEncode( | |
73 MediaCodecVideoEncoder.VideoCodecType.VIDEO_CODEC_VP8, 640, 480, 300, 30 , | |
74 EGL10.EGL_NO_CONTEXT)); | |
75 encoder.release(); | |
76 } | |
77 | |
53 @SmallTest | 78 @SmallTest |
54 public static void testEncoderUsingByteBuffer() throws InterruptedException { | 79 public static void testEncoderUsingByteBuffer() throws InterruptedException { |
55 if (!MediaCodecVideoEncoder.isVp8HwSupported()) { | 80 if (!MediaCodecVideoEncoder.isVp8HwSupported()) { |
56 Log.i(TAG, "Hardware does not support VP8 encoding, skipping testEncoderUs ingByteBuffer"); | 81 Log.i(TAG, "Hardware does not support VP8 encoding, skipping testEncoderUs ingByteBuffer"); |
57 return; | 82 return; |
58 } | 83 } |
59 | 84 |
60 final int width = 640; | 85 final int width = 640; |
61 final int height = 480; | 86 final int height = 480; |
62 final int min_size = width * height * 3 / 2; | 87 final int min_size = width * height * 3 / 2; |
63 final long presentationTimestampUs = 2; | 88 final long presentationTimestampUs = 2; |
64 | 89 |
65 MediaCodecVideoEncoder encoder = new MediaCodecVideoEncoder(); | 90 MediaCodecVideoEncoder encoder = new MediaCodecVideoEncoder(); |
66 | 91 |
67 assertTrue(encoder.initEncode( | 92 assertTrue(encoder.initEncode( |
68 MediaCodecVideoEncoder.VideoCodecType.VIDEO_CODEC_VP8, width, height, 30 0, 30)); | 93 MediaCodecVideoEncoder.VideoCodecType.VIDEO_CODEC_VP8, width, height, 30 0, 30, null)); |
69 ByteBuffer[] inputBuffers = encoder.getInputBuffers(); | 94 ByteBuffer[] inputBuffers = encoder.getInputBuffers(); |
70 assertNotNull(inputBuffers); | 95 assertNotNull(inputBuffers); |
71 assertTrue(min_size <= inputBuffers[0].capacity()); | 96 assertTrue(min_size <= inputBuffers[0].capacity()); |
72 | 97 |
73 int bufferIndex; | 98 int bufferIndex; |
74 do { | 99 do { |
75 Thread.sleep(10); | 100 Thread.sleep(10); |
76 bufferIndex = encoder.dequeueInputBuffer(); | 101 bufferIndex = encoder.dequeueInputBuffer(); |
77 } while (bufferIndex == -1); // |-1| is returned when there is no buffer ava ilable yet. | 102 } while (bufferIndex == -1); // |-1| is returned when there is no buffer ava ilable yet. |
78 | 103 |
79 assertTrue(bufferIndex >= 0); | 104 assertTrue(bufferIndex >= 0); |
80 assertTrue(bufferIndex < inputBuffers.length); | 105 assertTrue(bufferIndex < inputBuffers.length); |
81 assertTrue(encoder.encodeBuffer(true, bufferIndex, min_size, presentationTim estampUs)); | 106 assertTrue(encoder.encodeBuffer(true, bufferIndex, min_size, presentationTim estampUs)); |
82 | 107 |
83 OutputBufferInfo info; | 108 OutputBufferInfo info; |
84 do { | 109 do { |
85 info = encoder.dequeueOutputBuffer(); | 110 info = encoder.dequeueOutputBuffer(); |
86 Thread.sleep(10); | 111 Thread.sleep(10); |
87 } while (info == null); | 112 } while (info == null); |
88 assertTrue(info.index >= 0); | 113 assertTrue(info.index >= 0); |
89 assertEquals(presentationTimestampUs, info.presentationTimestampUs); | 114 assertEquals(presentationTimestampUs, info.presentationTimestampUs); |
90 assertTrue(info.buffer.capacity() > 0); | 115 assertTrue(info.buffer.capacity() > 0); |
91 encoder.releaseOutputBuffer(info.index); | 116 encoder.releaseOutputBuffer(info.index); |
92 | 117 |
93 encoder.release(); | 118 encoder.release(); |
94 } | 119 } |
120 | |
121 @SmallTest | |
122 public static void testEncoderUsingTextures() throws InterruptedException { | |
123 if (!MediaCodecVideoEncoder.isVp8HwSupportedUsingTextures()) { | |
124 Log.i(TAG, "Hardware does not support VP8 encoding, skipping testEncoderUs ingTextures"); | |
125 return; | |
126 } | |
127 | |
128 final int width = 640; | |
129 final int height = 480; | |
130 final long presentationTs = 2; | |
131 | |
132 final EglBase eglOesBase = new EglBase(EGL10.EGL_NO_CONTEXT, EglBase.ConfigT ype.PIXEL_BUFFER); | |
133 eglOesBase.createDummyPbufferSurface(); | |
134 eglOesBase.makeCurrent(); | |
135 int oesTextureId = GlUtil.generateTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES) ; | |
magjed_webrtc
2015/11/18 15:38:12
This texture still does not have any data associat
| |
136 | |
137 MediaCodecVideoEncoder encoder = new MediaCodecVideoEncoder(); | |
138 | |
139 assertTrue(encoder.initEncode( | |
140 MediaCodecVideoEncoder.VideoCodecType.VIDEO_CODEC_VP8, width, height, 30 0, 30, | |
141 eglOesBase.getContext())); | |
142 assertTrue(encoder.encodeTexture(true, oesTextureId, RendererCommon.identity Matrix(), | |
magjed_webrtc
2015/11/18 15:47:31
Another thing, can you call GlUtil.checkNoGLES2Err
perkj_webrtc
2015/11/19 10:40:58
Done.
| |
143 presentationTs)); | |
144 | |
145 // It should be Ok to delete the texture after calling encodeTexture. | |
146 GLES20.glDeleteTextures(1, new int[] {oesTextureId}, 0); | |
147 | |
148 OutputBufferInfo info = encoder.dequeueOutputBuffer(); | |
149 while (info == null) { | |
150 info = encoder.dequeueOutputBuffer(); | |
151 Thread.sleep(20); | |
152 } | |
153 assertTrue(info.index != -1); | |
154 assertTrue(info.buffer.capacity() > 0); | |
155 encoder.releaseOutputBuffer(info.index); | |
156 | |
157 encoder.release(); | |
158 eglOesBase.release(); | |
159 } | |
95 } | 160 } |
OLD | NEW |