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

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

Issue 2977643002: Add texture support to HardwareVideoDecoder. (Closed)
Patch Set: 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.assertNotNull;
15 import static org.junit.Assert.assertTrue;
14 16
15 import android.annotation.TargetApi; 17 import android.annotation.TargetApi;
16 import android.graphics.Matrix; 18 import android.graphics.Matrix;
17 import android.support.test.filters.MediumTest; 19 import android.support.test.filters.MediumTest;
18 import android.util.Log; 20 import android.util.Log;
19 import java.util.concurrent.atomic.AtomicReference; 21 import java.util.concurrent.atomic.AtomicReference;
20 import java.util.concurrent.CountDownLatch; 22 import java.util.concurrent.CountDownLatch;
21 import org.chromium.base.test.BaseJUnit4ClassRunner; 23 import org.chromium.base.test.BaseJUnit4ClassRunner;
22 import org.junit.Test; 24 import org.junit.Test;
23 import org.junit.runner.RunWith; 25 import org.junit.runner.RunWith;
(...skipping 13 matching lines...) Expand all
37 @MediumTest 39 @MediumTest
38 public void testInitialize() { 40 public void testInitialize() {
39 HardwareVideoEncoderFactory encoderFactory = 41 HardwareVideoEncoderFactory encoderFactory =
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 = encoderFactory.getSupportedCodecs(); 43 VideoCodecInfo[] supportedCodecs = encoderFactory.getSupportedCodecs();
42 if (supportedCodecs.length == 0) { 44 if (supportedCodecs.length == 0) {
43 Log.i(TAG, "No hardware encoding support, skipping testInitialize"); 45 Log.i(TAG, "No hardware encoding support, skipping testInitialize");
44 return; 46 return;
45 } 47 }
46 48
47 HardwareVideoDecoderFactory decoderFactory = new HardwareVideoDecoderFactory (); 49 HardwareVideoDecoderFactory decoderFactory = new HardwareVideoDecoderFactory (null);
48 50
49 VideoDecoder decoder = decoderFactory.createDecoder(supportedCodecs[0].name) ; 51 VideoDecoder decoder = decoderFactory.createDecoder(supportedCodecs[0].name) ;
50 assertEquals(decoder.initDecode(SETTINGS, null), VideoCodecStatus.OK); 52 assertEquals(decoder.initDecode(SETTINGS, null), VideoCodecStatus.OK);
51 assertEquals(decoder.release(), VideoCodecStatus.OK); 53 assertEquals(decoder.release(), VideoCodecStatus.OK);
52 } 54 }
53 55
54 @Test 56 @Test
55 @MediumTest 57 @MediumTest
58 public void testInitializeUsingTextures() {
59 HardwareVideoEncoderFactory encoderFactory =
60 new HardwareVideoEncoderFactory(ENABLE_INTEL_VP8_ENCODER, ENABLE_H264_HI GH_PROFILE);
61 VideoCodecInfo[] supportedCodecs = encoderFactory.getSupportedCodecs();
62 if (supportedCodecs.length == 0) {
63 Log.i(TAG, "No hardware encoding support, skipping testInitialize");
64 return;
65 }
66
67 EglBase14 eglBase = new EglBase14(null, EglBase.CONFIG_PLAIN);
68 SurfaceTextureHelper surfaceTextureHelper =
69 SurfaceTextureHelper.create("texture-thread", eglBase.getEglBaseContext( ));
70
71 HardwareVideoDecoderFactory decoderFactory =
72 new HardwareVideoDecoderFactory(surfaceTextureHelper);
73
74 VideoDecoder decoder = decoderFactory.createDecoder(supportedCodecs[0].name) ;
75 assertEquals(decoder.initDecode(SETTINGS, null), VideoCodecStatus.OK);
76 assertEquals(decoder.release(), VideoCodecStatus.OK);
77
78 surfaceTextureHelper.dispose();
79 eglBase.release();
80 }
81
82 @Test
83 @MediumTest
56 public void testDecode() throws InterruptedException { 84 public void testDecode() throws InterruptedException {
57 HardwareVideoEncoderFactory encoderFactory = 85 HardwareVideoEncoderFactory encoderFactory =
58 new HardwareVideoEncoderFactory(ENABLE_INTEL_VP8_ENCODER, ENABLE_H264_HI GH_PROFILE); 86 new HardwareVideoEncoderFactory(ENABLE_INTEL_VP8_ENCODER, ENABLE_H264_HI GH_PROFILE);
59 VideoCodecInfo[] supportedCodecs = encoderFactory.getSupportedCodecs(); 87 VideoCodecInfo[] supportedCodecs = encoderFactory.getSupportedCodecs();
60 if (supportedCodecs.length == 0) { 88 if (supportedCodecs.length == 0) {
61 Log.i(TAG, "No hardware encoding support, skipping testEncodeYuvBuffer"); 89 Log.i(TAG, "No hardware encoding support, skipping testEncodeYuvBuffer");
62 return; 90 return;
63 } 91 }
64 92
65 // Set up the decoder. 93 // Set up the decoder.
66 HardwareVideoDecoderFactory decoderFactory = new HardwareVideoDecoderFactory (); 94 HardwareVideoDecoderFactory decoderFactory = new HardwareVideoDecoderFactory (null);
67 VideoDecoder decoder = decoderFactory.createDecoder(supportedCodecs[0].name) ; 95 VideoDecoder decoder = decoderFactory.createDecoder(supportedCodecs[0].name) ;
68 96
69 final long presentationTimestampUs = 20000; 97 final long presentationTimestampUs = 20000;
70 final int rotation = 270; 98 final int rotation = 270;
71 99
72 final CountDownLatch decodeDone = new CountDownLatch(1); 100 final CountDownLatch decodeDone = new CountDownLatch(1);
73 final AtomicReference<VideoFrame> decoded = new AtomicReference<>(); 101 final AtomicReference<VideoFrame> decoded = new AtomicReference<>();
74 VideoDecoder.Callback decodeCallback = new VideoDecoder.Callback() { 102 VideoDecoder.Callback decodeCallback = new VideoDecoder.Callback() {
75 @Override 103 @Override
76 public void onDecodedFrame(VideoFrame frame, Integer decodeTimeMs, Integer qp) { 104 public void onDecodedFrame(VideoFrame frame, Integer decodeTimeMs, Integer qp) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 frame = decoded.get(); 144 frame = decoded.get();
117 assertEquals(frame.getRotation(), rotation); 145 assertEquals(frame.getRotation(), rotation);
118 assertEquals(frame.getTimestampNs(), presentationTimestampUs * 1000); 146 assertEquals(frame.getTimestampNs(), presentationTimestampUs * 1000);
119 assertEquals(frame.getTransformMatrix(), new Matrix()); 147 assertEquals(frame.getTransformMatrix(), new Matrix());
120 assertEquals(frame.getWidth(), SETTINGS.width); 148 assertEquals(frame.getWidth(), SETTINGS.width);
121 assertEquals(frame.getHeight(), SETTINGS.height); 149 assertEquals(frame.getHeight(), SETTINGS.height);
122 150
123 assertEquals(decoder.release(), VideoCodecStatus.OK); 151 assertEquals(decoder.release(), VideoCodecStatus.OK);
124 assertEquals(encoder.release(), VideoCodecStatus.OK); 152 assertEquals(encoder.release(), VideoCodecStatus.OK);
125 } 153 }
154
155 @Test
156 @MediumTest
157 public void testDecodeUsingTextures() throws InterruptedException {
158 HardwareVideoEncoderFactory encoderFactory =
159 new HardwareVideoEncoderFactory(ENABLE_INTEL_VP8_ENCODER, ENABLE_H264_HI GH_PROFILE);
160 VideoCodecInfo[] supportedCodecs = encoderFactory.getSupportedCodecs();
161 if (supportedCodecs.length == 0) {
162 Log.i(TAG, "No hardware encoding support, skipping testEncodeYuvBuffer");
163 return;
164 }
165
166 // Set up the decoder.
167 EglBase14 eglBase = new EglBase14(null, EglBase.CONFIG_PLAIN);
168 SurfaceTextureHelper surfaceTextureHelper =
169 SurfaceTextureHelper.create("texture-thread", eglBase.getEglBaseContext( ));
170
171 HardwareVideoDecoderFactory decoderFactory =
172 new HardwareVideoDecoderFactory(surfaceTextureHelper);
173 VideoDecoder decoder = decoderFactory.createDecoder(supportedCodecs[0].name) ;
174
175 final long presentationTimestampUs = 20000;
176 final int rotation = 270;
177
178 final CountDownLatch decodeDone = new CountDownLatch(1);
179 final AtomicReference<VideoFrame> decoded = new AtomicReference<>();
180 VideoDecoder.Callback decodeCallback = new VideoDecoder.Callback() {
181 @Override
182 public void onDecodedFrame(VideoFrame frame, Integer decodeTimeMs, Integer qp) {
183 decoded.set(frame);
sakal 2017/07/17 13:44:56 I think we should retain the frame here and releas
mellem 2017/07/17 21:57:15 Done.
184 decodeDone.countDown();
185 }
186 };
187 assertEquals(decoder.initDecode(SETTINGS, decodeCallback), VideoCodecStatus. OK);
188
189 // Set up an encoder to produce a valid encoded frame.
190 VideoEncoder encoder = encoderFactory.createEncoder(supportedCodecs[0]);
191 final CountDownLatch encodeDone = new CountDownLatch(1);
192 final AtomicReference<EncodedImage> encoded = new AtomicReference<>();
193 VideoEncoder.Callback encodeCallback = new VideoEncoder.Callback() {
194 @Override
195 public void onEncodedFrame(EncodedImage image, VideoEncoder.CodecSpecificI nfo info) {
196 encoded.set(image);
197 encodeDone.countDown();
198 }
199 };
200 assertEquals(
201 encoder.initEncode(
202 new VideoEncoder.Settings(1, SETTINGS.width, SETTINGS.height, 300, 3 0), encodeCallback),
203 VideoCodecStatus.OK);
204
205 // First, encode a frame.
206 VideoFrame.I420Buffer buffer = new I420BufferImpl(SETTINGS.width, SETTINGS.h eight);
207 VideoFrame frame =
208 new VideoFrame(buffer, rotation, presentationTimestampUs * 1000, new Mat rix());
209 VideoEncoder.EncodeInfo info = new VideoEncoder.EncodeInfo(
210 new EncodedImage.FrameType[] {EncodedImage.FrameType.VideoFrameKey});
211
212 assertEquals(encoder.encode(frame, info), VideoCodecStatus.OK);
213
214 ThreadUtils.awaitUninterruptibly(encodeDone);
215
216 // Now decode the frame.
217 assertEquals(
218 decoder.decode(encoded.get(), new VideoDecoder.DecodeInfo(false, 0)), Vi deoCodecStatus.OK);
219
220 ThreadUtils.awaitUninterruptibly(decodeDone);
221
222 frame = decoded.get();
223 assertEquals(frame.getRotation(), rotation);
224 assertEquals(frame.getTimestampNs(), presentationTimestampUs * 1000);
225 // TODO(mellem): Compare the matrix to whatever we expect to get back?
226 assertNotNull(frame.getTransformMatrix());
227 assertEquals(frame.getWidth(), SETTINGS.width);
228 assertEquals(frame.getHeight(), SETTINGS.height);
229
230 assertTrue(frame.getBuffer() instanceof VideoFrame.TextureBuffer);
231 VideoFrame.TextureBuffer textureBuffer = (VideoFrame.TextureBuffer) frame.ge tBuffer();
232 assertEquals(textureBuffer.getType(), VideoFrame.TextureBuffer.Type.OES);
233
234 assertEquals(decoder.release(), VideoCodecStatus.OK);
235 assertEquals(encoder.release(), VideoCodecStatus.OK);
236
237 surfaceTextureHelper.dispose();
238 eglBase.release();
239 }
126 } 240 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698