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

Side by Side Diff: webrtc/sdk/android/instrumentationtests/src/org/webrtc/HardwareVideoEncoderTest.java

Issue 2977153003: Add texture support to HardwareVideoEncoder. (Closed)
Patch Set: Fix logging and matrix helper Created 3 years, 5 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
1 /* 1 /*
2 * Copyright 2017 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2017 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 package org.webrtc; 11 package org.webrtc;
12 12
13 import static org.junit.Assert.assertEquals; 13 import static org.junit.Assert.assertEquals;
14 import static org.junit.Assert.assertTrue; 14 import static org.junit.Assert.assertTrue;
15 15
16 import android.annotation.TargetApi; 16 import android.annotation.TargetApi;
17 import android.graphics.Matrix; 17 import android.graphics.Matrix;
18 import android.opengl.GLES11Ext;
19 import android.opengl.GLES20;
18 import android.support.test.filters.SmallTest; 20 import android.support.test.filters.SmallTest;
19 import android.util.Log; 21 import android.util.Log;
20 import java.nio.ByteBuffer; 22 import java.nio.ByteBuffer;
21 import java.util.concurrent.CountDownLatch; 23 import java.util.concurrent.CountDownLatch;
22 import org.chromium.base.test.BaseJUnit4ClassRunner; 24 import org.chromium.base.test.BaseJUnit4ClassRunner;
23 import org.junit.Test; 25 import org.junit.Test;
24 import org.junit.runner.RunWith; 26 import org.junit.runner.RunWith;
25 27
26 @TargetApi(16) 28 @TargetApi(16)
27 @RunWith(BaseJUnit4ClassRunner.class) 29 @RunWith(BaseJUnit4ClassRunner.class)
28 public class HardwareVideoEncoderTest { 30 public class HardwareVideoEncoderTest {
29 final static String TAG = "MediaCodecVideoEncoderTest"; 31 final static String TAG = "MediaCodecVideoEncoderTest";
30 32
31 private static final boolean ENABLE_INTEL_VP8_ENCODER = true; 33 private static final boolean ENABLE_INTEL_VP8_ENCODER = true;
32 private static final boolean ENABLE_H264_HIGH_PROFILE = true; 34 private static final boolean ENABLE_H264_HIGH_PROFILE = true;
33 private static final VideoEncoder.Settings SETTINGS = new VideoEncoder.Setting s( 35 private static final VideoEncoder.Settings SETTINGS = new VideoEncoder.Setting s(
34 1 /* core */, 640 /* width */, 480 /* height */, 300 /* kbps */, 30 /* fps */); 36 1 /* core */, 640 /* width */, 480 /* height */, 300 /* kbps */, 30 /* fps */);
35 37
36 @Test 38 @Test
37 @SmallTest 39 @SmallTest
38 public void testInitializeUsingYuvBuffer() { 40 public void testInitializeUsingYuvBuffer() {
39 HardwareVideoEncoderFactory factory = 41 HardwareVideoEncoderFactory factory =
40 new HardwareVideoEncoderFactory(ENABLE_INTEL_VP8_ENCODER, ENABLE_H264_HI GH_PROFILE); 42 new HardwareVideoEncoderFactory(ENABLE_INTEL_VP8_ENCODER, ENABLE_H264_HI GH_PROFILE);
41 VideoCodecInfo[] supportedCodecs = factory.getSupportedCodecs(); 43 VideoCodecInfo[] supportedCodecs = factory.getSupportedCodecs();
42 if (supportedCodecs.length == 0) { 44 if (supportedCodecs.length == 0) {
43 Log.w(TAG, "No hardware encoding support, skipping testInitializeUsingYuvB uffer"); 45 Log.w(TAG, "No hardware encoding support, skipping testInitializeUsingYuvB uffer");
44 return; 46 return;
45 } 47 }
46 VideoEncoder encoder = factory.createEncoder(supportedCodecs[0]); 48 VideoEncoder encoder = factory.createEncoder(supportedCodecs[0]);
47 assertEquals(encoder.initEncode(SETTINGS, null), VideoCodecStatus.OK); 49 assertEquals(VideoCodecStatus.OK, encoder.initEncode(SETTINGS, null));
48 assertEquals(encoder.release(), VideoCodecStatus.OK); 50 assertEquals(VideoCodecStatus.OK, encoder.release());
49 } 51 }
50 52
51 @Test 53 @Test
54 @SmallTest
55 public void testInitializeUsingTextures() {
56 EglBase14 eglBase = new EglBase14(null, EglBase.CONFIG_PLAIN);
57 HardwareVideoEncoderFactory factory = new HardwareVideoEncoderFactory(
58 eglBase.getEglBaseContext(), ENABLE_INTEL_VP8_ENCODER, ENABLE_H264_HIGH_ PROFILE);
59 VideoCodecInfo[] supportedCodecs = factory.getSupportedCodecs();
60 if (supportedCodecs.length == 0) {
61 Log.w(TAG, "No hardware encoding support, skipping testInitializeUsingText ures");
62 return;
63 }
64 VideoEncoder encoder = factory.createEncoder(supportedCodecs[0]);
65 assertEquals(VideoCodecStatus.OK, encoder.initEncode(SETTINGS, null));
66 assertEquals(VideoCodecStatus.OK, encoder.release());
67 eglBase.release();
68 }
69
70 @Test
52 @SmallTest 71 @SmallTest
53 public void testEncodeYuvBuffer() throws InterruptedException { 72 public void testEncodeYuvBuffer() throws InterruptedException {
54 HardwareVideoEncoderFactory factory = 73 HardwareVideoEncoderFactory factory =
55 new HardwareVideoEncoderFactory(ENABLE_INTEL_VP8_ENCODER, ENABLE_H264_HI GH_PROFILE); 74 new HardwareVideoEncoderFactory(ENABLE_INTEL_VP8_ENCODER, ENABLE_H264_HI GH_PROFILE);
56 VideoCodecInfo[] supportedCodecs = factory.getSupportedCodecs(); 75 VideoCodecInfo[] supportedCodecs = factory.getSupportedCodecs();
57 if (supportedCodecs.length == 0) { 76 if (supportedCodecs.length == 0) {
58 Log.w(TAG, "No hardware encoding support, skipping testEncodeYuvBuffer"); 77 Log.w(TAG, "No hardware encoding support, skipping testEncodeYuvBuffer");
59 return; 78 return;
60 } 79 }
61 80
(...skipping 24 matching lines...) Expand all
86 new VideoFrame(buffer, 0 /* rotation */, presentationTimestampUs * 1000, new Matrix()); 105 new VideoFrame(buffer, 0 /* rotation */, presentationTimestampUs * 1000, new Matrix());
87 VideoEncoder.EncodeInfo info = new VideoEncoder.EncodeInfo( 106 VideoEncoder.EncodeInfo info = new VideoEncoder.EncodeInfo(
88 new EncodedImage.FrameType[] {EncodedImage.FrameType.VideoFrameKey}); 107 new EncodedImage.FrameType[] {EncodedImage.FrameType.VideoFrameKey});
89 108
90 assertEquals(encoder.encode(frame, info), VideoCodecStatus.OK); 109 assertEquals(encoder.encode(frame, info), VideoCodecStatus.OK);
91 110
92 ThreadUtils.awaitUninterruptibly(encodeDone); 111 ThreadUtils.awaitUninterruptibly(encodeDone);
93 112
94 assertEquals(encoder.release(), VideoCodecStatus.OK); 113 assertEquals(encoder.release(), VideoCodecStatus.OK);
95 } 114 }
115
116 @Test
117 @SmallTest
118 public void testEncodeTextures() throws InterruptedException {
119 final EglBase14 eglOesBase = new EglBase14(null, EglBase.CONFIG_PIXEL_BUFFER );
120 HardwareVideoEncoderFactory factory = new HardwareVideoEncoderFactory(
121 eglOesBase.getEglBaseContext(), ENABLE_INTEL_VP8_ENCODER, ENABLE_H264_HI GH_PROFILE);
122 VideoCodecInfo[] supportedCodecs = factory.getSupportedCodecs();
123 if (supportedCodecs.length == 0) {
124 Log.w(TAG, "No hardware encoding support, skipping testEncodeTextures");
125 return;
126 }
127
128 eglOesBase.createDummyPbufferSurface();
129 eglOesBase.makeCurrent();
130 final int oesTextureId = GlUtil.generateTexture(GLES11Ext.GL_TEXTURE_EXTERNA L_OES);
131
132 VideoEncoder encoder = factory.createEncoder(supportedCodecs[0]);
133
134 final long presentationTimestampUs = 20000;
135 final CountDownLatch encodeDone = new CountDownLatch(1);
136
137 VideoEncoder.Callback callback = new VideoEncoder.Callback() {
138 @Override
139 public void onEncodedFrame(EncodedImage image, VideoEncoder.CodecSpecificI nfo info) {
140 assertTrue(image.buffer.capacity() > 0);
141 assertEquals(image.encodedWidth, SETTINGS.width);
142 assertEquals(image.encodedHeight, SETTINGS.height);
143 assertEquals(image.captureTimeMs, presentationTimestampUs / 1000);
144 assertEquals(image.frameType, EncodedImage.FrameType.VideoFrameKey);
145 assertEquals(image.rotation, 0);
146 assertTrue(image.completeFrame);
147
148 encodeDone.countDown();
149 }
150 };
151
152 assertEquals(encoder.initEncode(SETTINGS, callback), VideoCodecStatus.OK);
153
154 VideoFrame.TextureBuffer buffer = new VideoFrame.TextureBuffer() {
155 @Override
156 public VideoFrame.TextureBuffer.Type getType() {
157 return VideoFrame.TextureBuffer.Type.OES;
158 }
159
160 @Override
161 public int getTextureId() {
162 return oesTextureId;
163 }
164
165 @Override
166 public int getWidth() {
167 return SETTINGS.width;
168 }
169
170 @Override
171 public int getHeight() {
172 return SETTINGS.height;
173 }
174
175 @Override
176 public VideoFrame.I420Buffer toI420() {
177 return null;
178 }
179
180 @Override
181 public void retain() {}
182
183 @Override
184 public void release() {}
185 };
186 VideoFrame frame =
187 new VideoFrame(buffer, 0 /* rotation */, presentationTimestampUs * 1000, new Matrix());
188 VideoEncoder.EncodeInfo info = new VideoEncoder.EncodeInfo(
189 new EncodedImage.FrameType[] {EncodedImage.FrameType.VideoFrameKey});
190
191 assertEquals(encoder.encode(frame, info), VideoCodecStatus.OK);
192 GlUtil.checkNoGLES2Error("encodeTexture");
193
194 // It should be Ok to delete the texture after calling encodeTexture.
195 GLES20.glDeleteTextures(1, new int[] {oesTextureId}, 0);
196
197 ThreadUtils.awaitUninterruptibly(encodeDone);
198
199 assertEquals(encoder.release(), VideoCodecStatus.OK);
200 eglOesBase.release();
201 }
96 } 202 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698