OLD | NEW |
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2014 Google Inc. | 3 * Copyright 2014 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, |
(...skipping 14 matching lines...) Expand all Loading... |
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 */ | 26 */ |
27 | 27 |
28 package org.webrtc; | 28 package org.webrtc; |
29 | 29 |
30 import android.media.MediaCodec; | 30 import android.media.MediaCodec; |
31 import android.media.MediaCodecInfo; | 31 import android.media.MediaCodecInfo; |
32 import android.media.MediaCodecInfo.CodecCapabilities; | 32 import android.media.MediaCodecInfo.CodecCapabilities; |
33 import android.media.MediaCodecList; | 33 import android.media.MediaCodecList; |
34 import android.media.MediaFormat; | 34 import android.media.MediaFormat; |
| 35 import android.opengl.EGLContext; |
| 36 import android.opengl.GLES11Ext; |
| 37 import android.opengl.GLES20; |
35 import android.os.Build; | 38 import android.os.Build; |
36 import android.view.Surface; | 39 import android.view.Surface; |
37 | 40 |
38 import org.webrtc.Logging; | 41 import org.webrtc.Logging; |
39 | 42 |
40 import java.nio.ByteBuffer; | 43 import java.nio.ByteBuffer; |
41 import java.util.Arrays; | 44 import java.util.Arrays; |
42 import java.util.List; | 45 import java.util.List; |
43 import java.util.concurrent.TimeUnit; | 46 import java.util.concurrent.TimeUnit; |
44 | 47 |
(...skipping 10 matching lines...) Expand all Loading... |
55 private static final String TAG = "MediaCodecVideoDecoder"; | 58 private static final String TAG = "MediaCodecVideoDecoder"; |
56 | 59 |
57 // Tracks webrtc::VideoCodecType. | 60 // Tracks webrtc::VideoCodecType. |
58 public enum VideoCodecType { | 61 public enum VideoCodecType { |
59 VIDEO_CODEC_VP8, | 62 VIDEO_CODEC_VP8, |
60 VIDEO_CODEC_VP9, | 63 VIDEO_CODEC_VP9, |
61 VIDEO_CODEC_H264 | 64 VIDEO_CODEC_H264 |
62 } | 65 } |
63 | 66 |
64 private static final int DEQUEUE_INPUT_TIMEOUT = 500000; // 500 ms timeout. | 67 private static final int DEQUEUE_INPUT_TIMEOUT = 500000; // 500 ms timeout. |
65 private static Thread mediaCodecThread; | 68 private Thread mediaCodecThread; |
66 private MediaCodec mediaCodec; | 69 private MediaCodec mediaCodec; |
67 private ByteBuffer[] inputBuffers; | 70 private ByteBuffer[] inputBuffers; |
68 private ByteBuffer[] outputBuffers; | 71 private ByteBuffer[] outputBuffers; |
69 private static final String VP8_MIME_TYPE = "video/x-vnd.on2.vp8"; | 72 private static final String VP8_MIME_TYPE = "video/x-vnd.on2.vp8"; |
70 private static final String H264_MIME_TYPE = "video/avc"; | 73 private static final String H264_MIME_TYPE = "video/avc"; |
71 // List of supported HW VP8 decoders. | 74 // List of supported HW VP8 decoders. |
72 private static final String[] supportedVp8HwCodecPrefixes = | 75 private static final String[] supportedVp8HwCodecPrefixes = |
73 {"OMX.qcom.", "OMX.Nvidia.", "OMX.Exynos.", "OMX.Intel." }; | 76 {"OMX.qcom.", "OMX.Nvidia.", "OMX.Exynos.", "OMX.Intel." }; |
74 // List of supported HW H.264 decoders. | 77 // List of supported HW H.264 decoders. |
75 private static final String[] supportedH264HwCodecPrefixes = | 78 private static final String[] supportedH264HwCodecPrefixes = |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 } | 168 } |
166 | 169 |
167 public static boolean isVp8HwSupported() { | 170 public static boolean isVp8HwSupported() { |
168 return findDecoder(VP8_MIME_TYPE, supportedVp8HwCodecPrefixes) != null; | 171 return findDecoder(VP8_MIME_TYPE, supportedVp8HwCodecPrefixes) != null; |
169 } | 172 } |
170 | 173 |
171 public static boolean isH264HwSupported() { | 174 public static boolean isH264HwSupported() { |
172 return findDecoder(H264_MIME_TYPE, supportedH264HwCodecPrefixes) != null; | 175 return findDecoder(H264_MIME_TYPE, supportedH264HwCodecPrefixes) != null; |
173 } | 176 } |
174 | 177 |
175 public static void printStackTrace() { | |
176 if (mediaCodecThread != null) { | |
177 StackTraceElement[] mediaCodecStackTraces = mediaCodecThread.getStackTrace
(); | |
178 if (mediaCodecStackTraces.length > 0) { | |
179 Logging.d(TAG, "MediaCodecVideoDecoder stacks trace:"); | |
180 for (StackTraceElement stackTrace : mediaCodecStackTraces) { | |
181 Logging.d(TAG, stackTrace.toString()); | |
182 } | |
183 } | |
184 } | |
185 } | |
186 | |
187 private void checkOnMediaCodecThread() throws IllegalStateException { | 178 private void checkOnMediaCodecThread() throws IllegalStateException { |
188 if (mediaCodecThread.getId() != Thread.currentThread().getId()) { | 179 if (mediaCodecThread.getId() != Thread.currentThread().getId()) { |
189 throw new IllegalStateException( | 180 throw new IllegalStateException( |
190 "MediaCodecVideoDecoder previously operated on " + mediaCodecThread + | 181 "MediaCodecVideoDecoder previously operated on " + mediaCodecThread + |
191 " but is now called on " + Thread.currentThread()); | 182 " but is now called on " + Thread.currentThread()); |
192 } | 183 } |
193 } | 184 } |
194 | 185 |
195 // Pass null in |surfaceTextureHelper| to configure the codec for ByteBuffer o
utput. | 186 // Pass null in |surfaceTextureHelper| to configure the codec for ByteBuffer o
utput. |
196 private boolean initDecode( | 187 private boolean initDecode( |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 // MediaCodec.CodecException upon codec error. | 450 // MediaCodec.CodecException upon codec error. |
460 private void returnDecodedByteBuffer(int index) | 451 private void returnDecodedByteBuffer(int index) |
461 throws IllegalStateException, MediaCodec.CodecException { | 452 throws IllegalStateException, MediaCodec.CodecException { |
462 checkOnMediaCodecThread(); | 453 checkOnMediaCodecThread(); |
463 if (useSurface) { | 454 if (useSurface) { |
464 throw new IllegalStateException("returnDecodedByteBuffer() called for surf
ace decoding."); | 455 throw new IllegalStateException("returnDecodedByteBuffer() called for surf
ace decoding."); |
465 } | 456 } |
466 mediaCodec.releaseOutputBuffer(index, false /* render */); | 457 mediaCodec.releaseOutputBuffer(index, false /* render */); |
467 } | 458 } |
468 } | 459 } |
OLD | NEW |