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.webrtc.MediaCodecUtils.EXYNOS_PREFIX; | 13 import static org.webrtc.MediaCodecUtils.EXYNOS_PREFIX; |
14 import static org.webrtc.MediaCodecUtils.INTEL_PREFIX; | 14 import static org.webrtc.MediaCodecUtils.INTEL_PREFIX; |
15 import static org.webrtc.MediaCodecUtils.NVIDIA_PREFIX; | 15 import static org.webrtc.MediaCodecUtils.NVIDIA_PREFIX; |
16 import static org.webrtc.MediaCodecUtils.QCOM_PREFIX; | 16 import static org.webrtc.MediaCodecUtils.QCOM_PREFIX; |
17 | 17 |
18 import android.media.MediaCodec; | 18 import android.media.MediaCodec; |
19 import android.media.MediaCodecInfo; | 19 import android.media.MediaCodecInfo; |
20 import android.media.MediaCodecInfo.CodecCapabilities; | 20 import android.media.MediaCodecInfo.CodecCapabilities; |
21 import android.media.MediaCodecList; | 21 import android.media.MediaCodecList; |
22 import android.os.Build; | 22 import android.os.Build; |
23 | 23 |
24 /** Factory for Android hardware VideoDecoders. */ | 24 /** Factory for Android hardware VideoDecoders. */ |
25 @SuppressWarnings("deprecation") // API level 16 requires use of deprecated meth
ods. | 25 @SuppressWarnings("deprecation") // API level 16 requires use of deprecated meth
ods. |
26 public class HardwareVideoDecoderFactory implements VideoDecoderFactory { | 26 public class HardwareVideoDecoderFactory implements VideoDecoderFactory { |
27 private static final String TAG = "HardwareVideoDecoderFactory"; | 27 private static final String TAG = "HardwareVideoDecoderFactory"; |
28 | 28 |
| 29 private final EglBase.Context sharedContext; |
| 30 |
| 31 /** Creates a HardwareVideoDecoderFactory that does not use surface textures.
*/ |
| 32 @Deprecated // Not removed yet to avoid breaking callers. |
| 33 public HardwareVideoDecoderFactory() { |
| 34 this(null); |
| 35 } |
| 36 |
| 37 /** |
| 38 * Creates a HardwareVideoDecoderFactory that supports surface texture renderi
ng using the given |
| 39 * shared context. The context may be null. If it is null, then surface supp
ort is disabled. |
| 40 */ |
| 41 public HardwareVideoDecoderFactory(EglBase.Context sharedContext) { |
| 42 this.sharedContext = sharedContext; |
| 43 } |
| 44 |
29 @Override | 45 @Override |
30 public VideoDecoder createDecoder(String codecType) { | 46 public VideoDecoder createDecoder(String codecType) { |
31 VideoCodecType type = VideoCodecType.valueOf(codecType); | 47 VideoCodecType type = VideoCodecType.valueOf(codecType); |
32 MediaCodecInfo info = findCodecForType(type); | 48 MediaCodecInfo info = findCodecForType(type); |
33 | 49 |
34 if (info == null) { | 50 if (info == null) { |
35 return null; // No support for this codec type. | 51 return null; // No support for this codec type. |
36 } | 52 } |
37 | 53 |
38 CodecCapabilities capabilities = info.getCapabilitiesForType(type.mimeType()
); | 54 CodecCapabilities capabilities = info.getCapabilitiesForType(type.mimeType()
); |
39 return new HardwareVideoDecoder(info.getName(), type, | 55 return new HardwareVideoDecoder(info.getName(), type, |
40 MediaCodecUtils.selectColorFormat(MediaCodecUtils.DECODER_COLOR_FORMATS,
capabilities)); | 56 MediaCodecUtils.selectColorFormat(MediaCodecUtils.DECODER_COLOR_FORMATS,
capabilities), |
| 57 sharedContext); |
41 } | 58 } |
42 | 59 |
43 private MediaCodecInfo findCodecForType(VideoCodecType type) { | 60 private MediaCodecInfo findCodecForType(VideoCodecType type) { |
44 // HW decoding is not supported on builds before KITKAT. | 61 // HW decoding is not supported on builds before KITKAT. |
45 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { | 62 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { |
46 return null; | 63 return null; |
47 } | 64 } |
48 | 65 |
49 for (int i = 0; i < MediaCodecList.getCodecCount(); ++i) { | 66 for (int i = 0; i < MediaCodecList.getCodecCount(); ++i) { |
50 MediaCodecInfo info = null; | 67 MediaCodecInfo info = null; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 return name.startsWith(QCOM_PREFIX) || name.startsWith(EXYNOS_PREFIX); | 108 return name.startsWith(QCOM_PREFIX) || name.startsWith(EXYNOS_PREFIX); |
92 case H264: | 109 case H264: |
93 // QCOM, Intel, and Exynos supported for H264. | 110 // QCOM, Intel, and Exynos supported for H264. |
94 return name.startsWith(QCOM_PREFIX) || name.startsWith(INTEL_PREFIX) | 111 return name.startsWith(QCOM_PREFIX) || name.startsWith(INTEL_PREFIX) |
95 || name.startsWith(EXYNOS_PREFIX); | 112 || name.startsWith(EXYNOS_PREFIX); |
96 default: | 113 default: |
97 return false; | 114 return false; |
98 } | 115 } |
99 } | 116 } |
100 } | 117 } |
OLD | NEW |