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

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

Issue 2977643002: Add texture support to HardwareVideoDecoder. (Closed)
Patch Set: Remove unused variables, add comments, and fix the 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 side-by-side diff with in-line comments
Download patch
Index: webrtc/sdk/android/instrumentationtests/src/org/webrtc/HardwareVideoDecoderTest.java
diff --git a/webrtc/sdk/android/instrumentationtests/src/org/webrtc/HardwareVideoDecoderTest.java b/webrtc/sdk/android/instrumentationtests/src/org/webrtc/HardwareVideoDecoderTest.java
index bb889de3dfd57bd4ccfb3458c3532c8308876e0a..6c9d0b7b5c11e9cfa28d1c41a76154abdb3f548f 100644
--- a/webrtc/sdk/android/instrumentationtests/src/org/webrtc/HardwareVideoDecoderTest.java
+++ b/webrtc/sdk/android/instrumentationtests/src/org/webrtc/HardwareVideoDecoderTest.java
@@ -11,6 +11,8 @@
package org.webrtc;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
import android.annotation.TargetApi;
import android.graphics.Matrix;
@@ -44,13 +46,35 @@ public final class HardwareVideoDecoderTest {
return;
}
- HardwareVideoDecoderFactory decoderFactory = new HardwareVideoDecoderFactory();
+ HardwareVideoDecoderFactory decoderFactory = new HardwareVideoDecoderFactory(null);
VideoDecoder decoder = decoderFactory.createDecoder(supportedCodecs[0].name);
assertEquals(decoder.initDecode(SETTINGS, null), VideoCodecStatus.OK);
assertEquals(decoder.release(), VideoCodecStatus.OK);
}
+ @Test
+ @MediumTest
+ public void testInitializeUsingTextures() {
+ HardwareVideoEncoderFactory encoderFactory =
+ new HardwareVideoEncoderFactory(ENABLE_INTEL_VP8_ENCODER, ENABLE_H264_HIGH_PROFILE);
+ VideoCodecInfo[] supportedCodecs = encoderFactory.getSupportedCodecs();
+ if (supportedCodecs.length == 0) {
+ Log.i(TAG, "No hardware encoding support, skipping testInitialize");
+ return;
+ }
+
+ EglBase14 eglBase = new EglBase14(null, EglBase.CONFIG_PLAIN);
+ HardwareVideoDecoderFactory decoderFactory =
+ new HardwareVideoDecoderFactory(eglBase.getEglBaseContext());
+
+ VideoDecoder decoder = decoderFactory.createDecoder(supportedCodecs[0].name);
+ assertEquals(decoder.initDecode(SETTINGS, null), VideoCodecStatus.OK);
+ assertEquals(decoder.release(), VideoCodecStatus.OK);
+
+ eglBase.release();
+ }
+
@Test
@MediumTest
public void testDecode() throws InterruptedException {
@@ -63,7 +87,7 @@ public final class HardwareVideoDecoderTest {
}
// Set up the decoder.
- HardwareVideoDecoderFactory decoderFactory = new HardwareVideoDecoderFactory();
+ HardwareVideoDecoderFactory decoderFactory = new HardwareVideoDecoderFactory(null);
VideoDecoder decoder = decoderFactory.createDecoder(supportedCodecs[0].name);
final long presentationTimestampUs = 20000;
@@ -74,6 +98,7 @@ public final class HardwareVideoDecoderTest {
VideoDecoder.Callback decodeCallback = new VideoDecoder.Callback() {
@Override
public void onDecodedFrame(VideoFrame frame, Integer decodeTimeMs, Integer qp) {
+ frame.retain();
decoded.set(frame);
decodeDone.countDown();
}
@@ -97,7 +122,7 @@ public final class HardwareVideoDecoderTest {
VideoCodecStatus.OK);
// First, encode a frame.
- VideoFrame.I420Buffer buffer = new I420BufferImpl(SETTINGS.width, SETTINGS.height);
+ VideoFrame.I420Buffer buffer = I420BufferImpl.allocate(SETTINGS.width, SETTINGS.height);
VideoFrame frame =
new VideoFrame(buffer, rotation, presentationTimestampUs * 1000, new Matrix());
VideoEncoder.EncodeInfo info = new VideoEncoder.EncodeInfo(
@@ -120,7 +145,92 @@ public final class HardwareVideoDecoderTest {
assertEquals(frame.getWidth(), SETTINGS.width);
assertEquals(frame.getHeight(), SETTINGS.height);
+ frame.release();
+ assertEquals(decoder.release(), VideoCodecStatus.OK);
+ assertEquals(encoder.release(), VideoCodecStatus.OK);
+ }
+
+ @Test
+ @MediumTest
+ public void testDecodeUsingTextures() throws InterruptedException {
+ HardwareVideoEncoderFactory encoderFactory =
+ new HardwareVideoEncoderFactory(ENABLE_INTEL_VP8_ENCODER, ENABLE_H264_HIGH_PROFILE);
+ VideoCodecInfo[] supportedCodecs = encoderFactory.getSupportedCodecs();
+ if (supportedCodecs.length == 0) {
+ Log.i(TAG, "No hardware encoding support, skipping testEncodeYuvBuffer");
+ return;
+ }
+
+ // Set up the decoder.
+ EglBase14 eglBase = new EglBase14(null, EglBase.CONFIG_PLAIN);
+ HardwareVideoDecoderFactory decoderFactory =
+ new HardwareVideoDecoderFactory(eglBase.getEglBaseContext());
+ VideoDecoder decoder = decoderFactory.createDecoder(supportedCodecs[0].name);
+
+ final long presentationTimestampUs = 20000;
+ final int rotation = 270;
+
+ final CountDownLatch decodeDone = new CountDownLatch(1);
+ final AtomicReference<VideoFrame> decoded = new AtomicReference<>();
+ VideoDecoder.Callback decodeCallback = new VideoDecoder.Callback() {
+ @Override
+ public void onDecodedFrame(VideoFrame frame, Integer decodeTimeMs, Integer qp) {
+ frame.retain();
+ decoded.set(frame);
+ decodeDone.countDown();
+ }
+ };
+ assertEquals(decoder.initDecode(SETTINGS, decodeCallback), VideoCodecStatus.OK);
+
+ // Set up an encoder to produce a valid encoded frame.
+ VideoEncoder encoder = encoderFactory.createEncoder(supportedCodecs[0]);
+ final CountDownLatch encodeDone = new CountDownLatch(1);
+ final AtomicReference<EncodedImage> encoded = new AtomicReference<>();
+ VideoEncoder.Callback encodeCallback = new VideoEncoder.Callback() {
+ @Override
+ public void onEncodedFrame(EncodedImage image, VideoEncoder.CodecSpecificInfo info) {
+ encoded.set(image);
+ encodeDone.countDown();
+ }
+ };
+ assertEquals(
+ encoder.initEncode(
+ new VideoEncoder.Settings(1, SETTINGS.width, SETTINGS.height, 300, 30), encodeCallback),
+ VideoCodecStatus.OK);
+
+ // First, encode a frame.
+ VideoFrame.I420Buffer buffer = I420BufferImpl.allocate(SETTINGS.width, SETTINGS.height);
+ VideoFrame frame =
+ new VideoFrame(buffer, rotation, presentationTimestampUs * 1000, new Matrix());
+ VideoEncoder.EncodeInfo info = new VideoEncoder.EncodeInfo(
+ new EncodedImage.FrameType[] {EncodedImage.FrameType.VideoFrameKey});
+
+ assertEquals(encoder.encode(frame, info), VideoCodecStatus.OK);
+
+ ThreadUtils.awaitUninterruptibly(encodeDone);
+
+ // Now decode the frame.
+ assertEquals(
+ decoder.decode(encoded.get(), new VideoDecoder.DecodeInfo(false, 0)), VideoCodecStatus.OK);
+
+ ThreadUtils.awaitUninterruptibly(decodeDone);
+
+ frame = decoded.get();
+ assertEquals(frame.getRotation(), rotation);
+ assertEquals(frame.getTimestampNs(), presentationTimestampUs * 1000);
+ // TODO(mellem): Compare the matrix to whatever we expect to get back?
+ assertNotNull(frame.getTransformMatrix());
+ assertEquals(frame.getWidth(), SETTINGS.width);
+ assertEquals(frame.getHeight(), SETTINGS.height);
+
+ assertTrue(frame.getBuffer() instanceof VideoFrame.TextureBuffer);
+ VideoFrame.TextureBuffer textureBuffer = (VideoFrame.TextureBuffer) frame.getBuffer();
+ assertEquals(textureBuffer.getType(), VideoFrame.TextureBuffer.Type.OES);
+
assertEquals(decoder.release(), VideoCodecStatus.OK);
assertEquals(encoder.release(), VideoCodecStatus.OK);
+
+ frame.release();
+ eglBase.release();
}
}

Powered by Google App Engine
This is Rietveld 408576698