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

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

Issue 2977153003: Add texture support to HardwareVideoEncoder. (Closed)
Patch Set: 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
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) {
sakal 2017/07/17 12:25:41 I would prefer this just taking in EglBase14.Conte
mellem 2017/07/17 17:49:29 EglBase14 is not part of the api (it's a package-p
66 this.sharedContext = (EglBase14.Context) sharedContext;
67 } else {
68 this.sharedContext = null;
69 }
62 this.enableIntelVp8Encoder = enableIntelVp8Encoder; 70 this.enableIntelVp8Encoder = enableIntelVp8Encoder;
63 this.enableH264HighProfile = enableH264HighProfile; 71 this.enableH264HighProfile = enableH264HighProfile;
64 } 72 }
65 73
74 @Deprecated
75 public HardwareVideoEncoderFactory(boolean enableIntelVp8Encoder, boolean enab leH264HighProfile) {
76 this(null, enableIntelVp8Encoder, enableH264HighProfile);
77 }
78
66 @Override 79 @Override
67 public VideoEncoder createEncoder(VideoCodecInfo input) { 80 public VideoEncoder createEncoder(VideoCodecInfo input) {
68 VideoCodecType type = VideoCodecType.valueOf(input.name); 81 VideoCodecType type = VideoCodecType.valueOf(input.name);
69 MediaCodecInfo info = findCodecForType(type); 82 MediaCodecInfo info = findCodecForType(type);
70 83
71 if (info == null) { 84 if (info == null) {
72 return null; // No support for this type. 85 return null; // No support for this type.
73 } 86 }
74 87
75 String codecName = info.getName(); 88 String codecName = info.getName();
76 String mime = type.mimeType(); 89 String mime = type.mimeType();
77 int colorFormat = MediaCodecUtils.selectColorFormat( 90 int colorFormat = MediaCodecUtils.selectColorFormat(sharedContext == null
78 MediaCodecUtils.ENCODER_COLOR_FORMATS, info.getCapabilitiesForType(mime) ); 91 ? MediaCodecUtils.ENCODER_COLOR_FORMATS
92 : MediaCodecUtils.TEXTURE_COLOR_FORMATS,
93 info.getCapabilitiesForType(mime));
79 94
80 return new HardwareVideoEncoder(codecName, type, colorFormat, getKeyFrameInt ervalSec(type), 95 return new HardwareVideoEncoder(codecName, type, colorFormat, getKeyFrameInt ervalSec(type),
81 getForcedKeyFrameIntervalMs(type, codecName), createBitrateAdjuster(type , codecName)); 96 getForcedKeyFrameIntervalMs(type, codecName), createBitrateAdjuster(type , codecName),
97 sharedContext);
82 } 98 }
83 99
84 @Override 100 @Override
85 public VideoCodecInfo[] getSupportedCodecs() { 101 public VideoCodecInfo[] getSupportedCodecs() {
86 List<VideoCodecInfo> supportedCodecInfos = new ArrayList<VideoCodecInfo>(); 102 List<VideoCodecInfo> supportedCodecInfos = new ArrayList<VideoCodecInfo>();
87 // Generate a list of supported codecs in order of preference: 103 // Generate a list of supported codecs in order of preference:
88 // VP8, VP9, H264 (high profile), and H264 (baseline profile). 104 // VP8, VP9, H264 (high profile), and H264 (baseline profile).
89 for (VideoCodecType type : 105 for (VideoCodecType type :
90 new VideoCodecType[] {VideoCodecType.VP8, VideoCodecType.VP9, VideoCodec Type.H264}) { 106 new VideoCodecType[] {VideoCodecType.VP8, VideoCodecType.VP9, VideoCodec Type.H264}) {
91 MediaCodecInfo codec = findCodecForType(type); 107 MediaCodecInfo codec = findCodecForType(type);
(...skipping 28 matching lines...) Expand all
120 } 136 }
121 return null; // No support for this type. 137 return null; // No support for this type.
122 } 138 }
123 139
124 // Returns true if the given MediaCodecInfo indicates a supported encoder for the given type. 140 // Returns true if the given MediaCodecInfo indicates a supported encoder for the given type.
125 private boolean isSupportedCodec(MediaCodecInfo info, VideoCodecType type) { 141 private boolean isSupportedCodec(MediaCodecInfo info, VideoCodecType type) {
126 if (!MediaCodecUtils.codecSupportsType(info, type)) { 142 if (!MediaCodecUtils.codecSupportsType(info, type)) {
127 return false; 143 return false;
128 } 144 }
129 // Check for a supported color format. 145 // Check for a supported color format.
130 if (MediaCodecUtils.selectColorFormat( 146 if (MediaCodecUtils.selectColorFormat(sharedContext == null
131 MediaCodecUtils.ENCODER_COLOR_FORMATS, info.getCapabilitiesForType(t ype.mimeType())) 147 ? MediaCodecUtils.ENCODER_COLOR_FORMATS
148 : MediaCodecUtils.TEXTURE_COLOR_FORMATS,
149 info.getCapabilitiesForType(type.mimeType()))
132 == null) { 150 == null) {
133 return false; 151 return false;
134 } 152 }
135 return isHardwareSupportedInCurrentSdk(info, type); 153 return isHardwareSupportedInCurrentSdk(info, type);
136 } 154 }
137 155
138 // Returns true if the given MediaCodecInfo indicates a hardware module that i s supported on the 156 // Returns true if the given MediaCodecInfo indicates a hardware module that i s supported on the
139 // current SDK. 157 // current SDK.
140 private boolean isHardwareSupportedInCurrentSdk(MediaCodecInfo info, VideoCode cType type) { 158 private boolean isHardwareSupportedInCurrentSdk(MediaCodecInfo info, VideoCode cType type) {
141 switch (type) { 159 switch (type) {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 properties.put(H264_FMTP_LEVEL_ASYMMETRY_ALLOWED, "1"); 252 properties.put(H264_FMTP_LEVEL_ASYMMETRY_ALLOWED, "1");
235 properties.put(H264_FMTP_PACKETIZATION_MODE, "1"); 253 properties.put(H264_FMTP_PACKETIZATION_MODE, "1");
236 properties.put(H264_FMTP_PROFILE_LEVEL_ID, 254 properties.put(H264_FMTP_PROFILE_LEVEL_ID,
237 highProfile ? H264_CONSTRAINED_HIGH_3_1 : H264_CONSTRAINED_BASELINE_ 3_1); 255 highProfile ? H264_CONSTRAINED_HIGH_3_1 : H264_CONSTRAINED_BASELINE_ 3_1);
238 return properties; 256 return properties;
239 default: 257 default:
240 throw new IllegalArgumentException("Unsupported codec: " + type); 258 throw new IllegalArgumentException("Unsupported codec: " + type);
241 } 259 }
242 } 260 }
243 } 261 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698