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

Side by Side Diff: webrtc/sdk/android/api/org/webrtc/HardwareVideoEncoderFactory.java

Issue 2977153003: Add texture support to HardwareVideoEncoder. (Closed)
Patch Set: Fix logging and 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 unified diff | Download patch
« no previous file with comments | « no previous file | webrtc/sdk/android/api/org/webrtc/RendererCommon.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 48
49 // Supported H264 profile ids and levels. 49 // Supported H264 profile ids and levels.
50 private static final String H264_PROFILE_CONSTRAINED_BASELINE = "4200"; 50 private static final String H264_PROFILE_CONSTRAINED_BASELINE = "4200";
51 private static final String H264_PROFILE_CONSTRAINED_HIGH = "640c"; 51 private static final String H264_PROFILE_CONSTRAINED_HIGH = "640c";
52 private static final String H264_LEVEL_3_1 = "1f"; // 31 in hex. 52 private static final String H264_LEVEL_3_1 = "1f"; // 31 in hex.
53 private static final String H264_CONSTRAINED_BASELINE_3_1 = 53 private static final String H264_CONSTRAINED_BASELINE_3_1 =
54 H264_PROFILE_CONSTRAINED_BASELINE + H264_LEVEL_3_1; 54 H264_PROFILE_CONSTRAINED_BASELINE + H264_LEVEL_3_1;
55 private static final String H264_CONSTRAINED_HIGH_3_1 = 55 private static final String H264_CONSTRAINED_HIGH_3_1 =
56 H264_PROFILE_CONSTRAINED_HIGH + H264_LEVEL_3_1; 56 H264_PROFILE_CONSTRAINED_HIGH + H264_LEVEL_3_1;
57 57
58 private final EglBase14.Context sharedContext;
58 private final boolean enableIntelVp8Encoder; 59 private final boolean enableIntelVp8Encoder;
59 private final boolean enableH264HighProfile; 60 private final boolean enableH264HighProfile;
60 61
61 public HardwareVideoEncoderFactory(boolean enableIntelVp8Encoder, boolean enab leH264HighProfile) { 62 public HardwareVideoEncoderFactory(
63 EglBase.Context sharedContext, boolean enableIntelVp8Encoder, boolean enab leH264HighProfile) {
64 // Texture mode requires EglBase14.
65 if (sharedContext instanceof EglBase14.Context) {
66 this.sharedContext = (EglBase14.Context) sharedContext;
67 } else {
68 Logging.w(TAG, "No shared EglBase.Context. Encoders will not use texture mode.");
69 this.sharedContext = null;
70 }
62 this.enableIntelVp8Encoder = enableIntelVp8Encoder; 71 this.enableIntelVp8Encoder = enableIntelVp8Encoder;
63 this.enableH264HighProfile = enableH264HighProfile; 72 this.enableH264HighProfile = enableH264HighProfile;
64 } 73 }
65 74
75 @Deprecated
76 public HardwareVideoEncoderFactory(boolean enableIntelVp8Encoder, boolean enab leH264HighProfile) {
77 this(null, enableIntelVp8Encoder, enableH264HighProfile);
78 }
79
66 @Override 80 @Override
67 public VideoEncoder createEncoder(VideoCodecInfo input) { 81 public VideoEncoder createEncoder(VideoCodecInfo input) {
68 VideoCodecType type = VideoCodecType.valueOf(input.name); 82 VideoCodecType type = VideoCodecType.valueOf(input.name);
69 MediaCodecInfo info = findCodecForType(type); 83 MediaCodecInfo info = findCodecForType(type);
70 84
71 if (info == null) { 85 if (info == null) {
72 return null; // No support for this type. 86 return null; // No support for this type.
73 } 87 }
74 88
75 String codecName = info.getName(); 89 String codecName = info.getName();
76 String mime = type.mimeType(); 90 String mime = type.mimeType();
77 int colorFormat = MediaCodecUtils.selectColorFormat( 91 int colorFormat = MediaCodecUtils.selectColorFormat(sharedContext == null
78 MediaCodecUtils.ENCODER_COLOR_FORMATS, info.getCapabilitiesForType(mime) ); 92 ? MediaCodecUtils.ENCODER_COLOR_FORMATS
93 : MediaCodecUtils.TEXTURE_COLOR_FORMATS,
94 info.getCapabilitiesForType(mime));
79 95
80 return new HardwareVideoEncoder(codecName, type, colorFormat, getKeyFrameInt ervalSec(type), 96 return new HardwareVideoEncoder(codecName, type, colorFormat, getKeyFrameInt ervalSec(type),
81 getForcedKeyFrameIntervalMs(type, codecName), createBitrateAdjuster(type , codecName)); 97 getForcedKeyFrameIntervalMs(type, codecName), createBitrateAdjuster(type , codecName),
98 sharedContext);
82 } 99 }
83 100
84 @Override 101 @Override
85 public VideoCodecInfo[] getSupportedCodecs() { 102 public VideoCodecInfo[] getSupportedCodecs() {
86 List<VideoCodecInfo> supportedCodecInfos = new ArrayList<VideoCodecInfo>(); 103 List<VideoCodecInfo> supportedCodecInfos = new ArrayList<VideoCodecInfo>();
87 // Generate a list of supported codecs in order of preference: 104 // Generate a list of supported codecs in order of preference:
88 // VP8, VP9, H264 (high profile), and H264 (baseline profile). 105 // VP8, VP9, H264 (high profile), and H264 (baseline profile).
89 for (VideoCodecType type : 106 for (VideoCodecType type :
90 new VideoCodecType[] {VideoCodecType.VP8, VideoCodecType.VP9, VideoCodec Type.H264}) { 107 new VideoCodecType[] {VideoCodecType.VP8, VideoCodecType.VP9, VideoCodec Type.H264}) {
91 MediaCodecInfo codec = findCodecForType(type); 108 MediaCodecInfo codec = findCodecForType(type);
(...skipping 28 matching lines...) Expand all
120 } 137 }
121 return null; // No support for this type. 138 return null; // No support for this type.
122 } 139 }
123 140
124 // Returns true if the given MediaCodecInfo indicates a supported encoder for the given type. 141 // Returns true if the given MediaCodecInfo indicates a supported encoder for the given type.
125 private boolean isSupportedCodec(MediaCodecInfo info, VideoCodecType type) { 142 private boolean isSupportedCodec(MediaCodecInfo info, VideoCodecType type) {
126 if (!MediaCodecUtils.codecSupportsType(info, type)) { 143 if (!MediaCodecUtils.codecSupportsType(info, type)) {
127 return false; 144 return false;
128 } 145 }
129 // Check for a supported color format. 146 // Check for a supported color format.
130 if (MediaCodecUtils.selectColorFormat( 147 if (MediaCodecUtils.selectColorFormat(sharedContext == null
131 MediaCodecUtils.ENCODER_COLOR_FORMATS, info.getCapabilitiesForType(t ype.mimeType())) 148 ? MediaCodecUtils.ENCODER_COLOR_FORMATS
149 : MediaCodecUtils.TEXTURE_COLOR_FORMATS,
150 info.getCapabilitiesForType(type.mimeType()))
132 == null) { 151 == null) {
133 return false; 152 return false;
134 } 153 }
135 return isHardwareSupportedInCurrentSdk(info, type); 154 return isHardwareSupportedInCurrentSdk(info, type);
136 } 155 }
137 156
138 // Returns true if the given MediaCodecInfo indicates a hardware module that i s supported on the 157 // Returns true if the given MediaCodecInfo indicates a hardware module that i s supported on the
139 // current SDK. 158 // current SDK.
140 private boolean isHardwareSupportedInCurrentSdk(MediaCodecInfo info, VideoCode cType type) { 159 private boolean isHardwareSupportedInCurrentSdk(MediaCodecInfo info, VideoCode cType type) {
141 switch (type) { 160 switch (type) {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 properties.put(H264_FMTP_LEVEL_ASYMMETRY_ALLOWED, "1"); 253 properties.put(H264_FMTP_LEVEL_ASYMMETRY_ALLOWED, "1");
235 properties.put(H264_FMTP_PACKETIZATION_MODE, "1"); 254 properties.put(H264_FMTP_PACKETIZATION_MODE, "1");
236 properties.put(H264_FMTP_PROFILE_LEVEL_ID, 255 properties.put(H264_FMTP_PROFILE_LEVEL_ID,
237 highProfile ? H264_CONSTRAINED_HIGH_3_1 : H264_CONSTRAINED_BASELINE_ 3_1); 256 highProfile ? H264_CONSTRAINED_HIGH_3_1 : H264_CONSTRAINED_BASELINE_ 3_1);
238 return properties; 257 return properties;
239 default: 258 default:
240 throw new IllegalArgumentException("Unsupported codec: " + type); 259 throw new IllegalArgumentException("Unsupported codec: " + type);
241 } 260 }
242 } 261 }
243 } 262 }
OLDNEW
« no previous file with comments | « no previous file | webrtc/sdk/android/api/org/webrtc/RendererCommon.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698