OLD | NEW |
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 Loading... |
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 HardwareVideoDecoderFactory decoderFactory = |
| 69 new HardwareVideoDecoderFactory(eglBase.getEglBaseContext()); |
| 70 |
| 71 VideoDecoder decoder = decoderFactory.createDecoder(supportedCodecs[0].name)
; |
| 72 assertEquals(decoder.initDecode(SETTINGS, null), VideoCodecStatus.OK); |
| 73 assertEquals(decoder.release(), VideoCodecStatus.OK); |
| 74 |
| 75 eglBase.release(); |
| 76 } |
| 77 |
| 78 @Test |
| 79 @MediumTest |
56 public void testDecode() throws InterruptedException { | 80 public void testDecode() throws InterruptedException { |
57 HardwareVideoEncoderFactory encoderFactory = | 81 HardwareVideoEncoderFactory encoderFactory = |
58 new HardwareVideoEncoderFactory(ENABLE_INTEL_VP8_ENCODER, ENABLE_H264_HI
GH_PROFILE); | 82 new HardwareVideoEncoderFactory(ENABLE_INTEL_VP8_ENCODER, ENABLE_H264_HI
GH_PROFILE); |
59 VideoCodecInfo[] supportedCodecs = encoderFactory.getSupportedCodecs(); | 83 VideoCodecInfo[] supportedCodecs = encoderFactory.getSupportedCodecs(); |
60 if (supportedCodecs.length == 0) { | 84 if (supportedCodecs.length == 0) { |
61 Log.i(TAG, "No hardware encoding support, skipping testEncodeYuvBuffer"); | 85 Log.i(TAG, "No hardware encoding support, skipping testEncodeYuvBuffer"); |
62 return; | 86 return; |
63 } | 87 } |
64 | 88 |
65 // Set up the decoder. | 89 // Set up the decoder. |
66 HardwareVideoDecoderFactory decoderFactory = new HardwareVideoDecoderFactory
(); | 90 HardwareVideoDecoderFactory decoderFactory = new HardwareVideoDecoderFactory
(null); |
67 VideoDecoder decoder = decoderFactory.createDecoder(supportedCodecs[0].name)
; | 91 VideoDecoder decoder = decoderFactory.createDecoder(supportedCodecs[0].name)
; |
68 | 92 |
69 final long presentationTimestampUs = 20000; | 93 final long presentationTimestampUs = 20000; |
70 final int rotation = 270; | 94 final int rotation = 270; |
71 | 95 |
72 final CountDownLatch decodeDone = new CountDownLatch(1); | 96 final CountDownLatch decodeDone = new CountDownLatch(1); |
73 final AtomicReference<VideoFrame> decoded = new AtomicReference<>(); | 97 final AtomicReference<VideoFrame> decoded = new AtomicReference<>(); |
74 VideoDecoder.Callback decodeCallback = new VideoDecoder.Callback() { | 98 VideoDecoder.Callback decodeCallback = new VideoDecoder.Callback() { |
75 @Override | 99 @Override |
76 public void onDecodedFrame(VideoFrame frame, Integer decodeTimeMs, Integer
qp) { | 100 public void onDecodedFrame(VideoFrame frame, Integer decodeTimeMs, Integer
qp) { |
| 101 frame.retain(); |
77 decoded.set(frame); | 102 decoded.set(frame); |
78 decodeDone.countDown(); | 103 decodeDone.countDown(); |
79 } | 104 } |
80 }; | 105 }; |
81 assertEquals(decoder.initDecode(SETTINGS, decodeCallback), VideoCodecStatus.
OK); | 106 assertEquals(decoder.initDecode(SETTINGS, decodeCallback), VideoCodecStatus.
OK); |
82 | 107 |
83 // Set up an encoder to produce a valid encoded frame. | 108 // Set up an encoder to produce a valid encoded frame. |
84 VideoEncoder encoder = encoderFactory.createEncoder(supportedCodecs[0]); | 109 VideoEncoder encoder = encoderFactory.createEncoder(supportedCodecs[0]); |
85 final CountDownLatch encodeDone = new CountDownLatch(1); | 110 final CountDownLatch encodeDone = new CountDownLatch(1); |
86 final AtomicReference<EncodedImage> encoded = new AtomicReference<>(); | 111 final AtomicReference<EncodedImage> encoded = new AtomicReference<>(); |
87 VideoEncoder.Callback encodeCallback = new VideoEncoder.Callback() { | 112 VideoEncoder.Callback encodeCallback = new VideoEncoder.Callback() { |
88 @Override | 113 @Override |
89 public void onEncodedFrame(EncodedImage image, VideoEncoder.CodecSpecificI
nfo info) { | 114 public void onEncodedFrame(EncodedImage image, VideoEncoder.CodecSpecificI
nfo info) { |
90 encoded.set(image); | 115 encoded.set(image); |
91 encodeDone.countDown(); | 116 encodeDone.countDown(); |
92 } | 117 } |
93 }; | 118 }; |
94 assertEquals( | 119 assertEquals( |
95 encoder.initEncode( | 120 encoder.initEncode( |
96 new VideoEncoder.Settings(1, SETTINGS.width, SETTINGS.height, 300, 3
0), encodeCallback), | 121 new VideoEncoder.Settings(1, SETTINGS.width, SETTINGS.height, 300, 3
0), encodeCallback), |
97 VideoCodecStatus.OK); | 122 VideoCodecStatus.OK); |
98 | 123 |
99 // First, encode a frame. | 124 // First, encode a frame. |
100 VideoFrame.I420Buffer buffer = new I420BufferImpl(SETTINGS.width, SETTINGS.h
eight); | 125 VideoFrame.I420Buffer buffer = I420BufferImpl.allocate(SETTINGS.width, SETTI
NGS.height); |
101 VideoFrame frame = | 126 VideoFrame frame = |
102 new VideoFrame(buffer, rotation, presentationTimestampUs * 1000, new Mat
rix()); | 127 new VideoFrame(buffer, rotation, presentationTimestampUs * 1000, new Mat
rix()); |
103 VideoEncoder.EncodeInfo info = new VideoEncoder.EncodeInfo( | 128 VideoEncoder.EncodeInfo info = new VideoEncoder.EncodeInfo( |
104 new EncodedImage.FrameType[] {EncodedImage.FrameType.VideoFrameKey}); | 129 new EncodedImage.FrameType[] {EncodedImage.FrameType.VideoFrameKey}); |
105 | 130 |
106 assertEquals(encoder.encode(frame, info), VideoCodecStatus.OK); | 131 assertEquals(encoder.encode(frame, info), VideoCodecStatus.OK); |
107 | 132 |
108 ThreadUtils.awaitUninterruptibly(encodeDone); | 133 ThreadUtils.awaitUninterruptibly(encodeDone); |
109 | 134 |
110 // Now decode the frame. | 135 // Now decode the frame. |
111 assertEquals( | 136 assertEquals( |
112 decoder.decode(encoded.get(), new VideoDecoder.DecodeInfo(false, 0)), Vi
deoCodecStatus.OK); | 137 decoder.decode(encoded.get(), new VideoDecoder.DecodeInfo(false, 0)), Vi
deoCodecStatus.OK); |
113 | 138 |
114 ThreadUtils.awaitUninterruptibly(decodeDone); | 139 ThreadUtils.awaitUninterruptibly(decodeDone); |
115 | 140 |
116 frame = decoded.get(); | 141 frame = decoded.get(); |
117 assertEquals(frame.getRotation(), rotation); | 142 assertEquals(frame.getRotation(), rotation); |
118 assertEquals(frame.getTimestampNs(), presentationTimestampUs * 1000); | 143 assertEquals(frame.getTimestampNs(), presentationTimestampUs * 1000); |
119 assertEquals(frame.getTransformMatrix(), new Matrix()); | 144 assertEquals(frame.getTransformMatrix(), new Matrix()); |
120 assertEquals(frame.getWidth(), SETTINGS.width); | 145 assertEquals(frame.getWidth(), SETTINGS.width); |
121 assertEquals(frame.getHeight(), SETTINGS.height); | 146 assertEquals(frame.getHeight(), SETTINGS.height); |
122 | 147 |
| 148 frame.release(); |
123 assertEquals(decoder.release(), VideoCodecStatus.OK); | 149 assertEquals(decoder.release(), VideoCodecStatus.OK); |
124 assertEquals(encoder.release(), VideoCodecStatus.OK); | 150 assertEquals(encoder.release(), VideoCodecStatus.OK); |
125 } | 151 } |
| 152 |
| 153 @Test |
| 154 @MediumTest |
| 155 public void testDecodeUsingTextures() throws InterruptedException { |
| 156 HardwareVideoEncoderFactory encoderFactory = |
| 157 new HardwareVideoEncoderFactory(ENABLE_INTEL_VP8_ENCODER, ENABLE_H264_HI
GH_PROFILE); |
| 158 VideoCodecInfo[] supportedCodecs = encoderFactory.getSupportedCodecs(); |
| 159 if (supportedCodecs.length == 0) { |
| 160 Log.i(TAG, "No hardware encoding support, skipping testEncodeYuvBuffer"); |
| 161 return; |
| 162 } |
| 163 |
| 164 // Set up the decoder. |
| 165 EglBase14 eglBase = new EglBase14(null, EglBase.CONFIG_PLAIN); |
| 166 HardwareVideoDecoderFactory decoderFactory = |
| 167 new HardwareVideoDecoderFactory(eglBase.getEglBaseContext()); |
| 168 VideoDecoder decoder = decoderFactory.createDecoder(supportedCodecs[0].name)
; |
| 169 |
| 170 final long presentationTimestampUs = 20000; |
| 171 final int rotation = 270; |
| 172 |
| 173 final CountDownLatch decodeDone = new CountDownLatch(1); |
| 174 final AtomicReference<VideoFrame> decoded = new AtomicReference<>(); |
| 175 VideoDecoder.Callback decodeCallback = new VideoDecoder.Callback() { |
| 176 @Override |
| 177 public void onDecodedFrame(VideoFrame frame, Integer decodeTimeMs, Integer
qp) { |
| 178 frame.retain(); |
| 179 decoded.set(frame); |
| 180 decodeDone.countDown(); |
| 181 } |
| 182 }; |
| 183 assertEquals(decoder.initDecode(SETTINGS, decodeCallback), VideoCodecStatus.
OK); |
| 184 |
| 185 // Set up an encoder to produce a valid encoded frame. |
| 186 VideoEncoder encoder = encoderFactory.createEncoder(supportedCodecs[0]); |
| 187 final CountDownLatch encodeDone = new CountDownLatch(1); |
| 188 final AtomicReference<EncodedImage> encoded = new AtomicReference<>(); |
| 189 VideoEncoder.Callback encodeCallback = new VideoEncoder.Callback() { |
| 190 @Override |
| 191 public void onEncodedFrame(EncodedImage image, VideoEncoder.CodecSpecificI
nfo info) { |
| 192 encoded.set(image); |
| 193 encodeDone.countDown(); |
| 194 } |
| 195 }; |
| 196 assertEquals( |
| 197 encoder.initEncode( |
| 198 new VideoEncoder.Settings(1, SETTINGS.width, SETTINGS.height, 300, 3
0), encodeCallback), |
| 199 VideoCodecStatus.OK); |
| 200 |
| 201 // First, encode a frame. |
| 202 VideoFrame.I420Buffer buffer = I420BufferImpl.allocate(SETTINGS.width, SETTI
NGS.height); |
| 203 VideoFrame frame = |
| 204 new VideoFrame(buffer, rotation, presentationTimestampUs * 1000, new Mat
rix()); |
| 205 VideoEncoder.EncodeInfo info = new VideoEncoder.EncodeInfo( |
| 206 new EncodedImage.FrameType[] {EncodedImage.FrameType.VideoFrameKey}); |
| 207 |
| 208 assertEquals(encoder.encode(frame, info), VideoCodecStatus.OK); |
| 209 |
| 210 ThreadUtils.awaitUninterruptibly(encodeDone); |
| 211 |
| 212 // Now decode the frame. |
| 213 assertEquals( |
| 214 decoder.decode(encoded.get(), new VideoDecoder.DecodeInfo(false, 0)), Vi
deoCodecStatus.OK); |
| 215 |
| 216 ThreadUtils.awaitUninterruptibly(decodeDone); |
| 217 |
| 218 frame = decoded.get(); |
| 219 assertEquals(frame.getRotation(), rotation); |
| 220 assertEquals(frame.getTimestampNs(), presentationTimestampUs * 1000); |
| 221 // TODO(mellem): Compare the matrix to whatever we expect to get back? |
| 222 assertNotNull(frame.getTransformMatrix()); |
| 223 assertEquals(frame.getWidth(), SETTINGS.width); |
| 224 assertEquals(frame.getHeight(), SETTINGS.height); |
| 225 |
| 226 assertTrue(frame.getBuffer() instanceof VideoFrame.TextureBuffer); |
| 227 VideoFrame.TextureBuffer textureBuffer = (VideoFrame.TextureBuffer) frame.ge
tBuffer(); |
| 228 assertEquals(textureBuffer.getType(), VideoFrame.TextureBuffer.Type.OES); |
| 229 |
| 230 assertEquals(decoder.release(), VideoCodecStatus.OK); |
| 231 assertEquals(encoder.release(), VideoCodecStatus.OK); |
| 232 |
| 233 frame.release(); |
| 234 eglBase.release(); |
| 235 } |
126 } | 236 } |
OLD | NEW |