| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2015 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 1197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1208 | 1208 |
| 1209 bool is_vp9_hw_supported = jni->CallStaticBooleanMethod( | 1209 bool is_vp9_hw_supported = jni->CallStaticBooleanMethod( |
| 1210 j_encoder_class, | 1210 j_encoder_class, |
| 1211 GetStaticMethodID(jni, j_encoder_class, "isVp9HwSupported", "()Z")); | 1211 GetStaticMethodID(jni, j_encoder_class, "isVp9HwSupported", "()Z")); |
| 1212 CHECK_EXCEPTION(jni); | 1212 CHECK_EXCEPTION(jni); |
| 1213 if (is_vp9_hw_supported) { | 1213 if (is_vp9_hw_supported) { |
| 1214 ALOGD << "VP9 HW Encoder supported."; | 1214 ALOGD << "VP9 HW Encoder supported."; |
| 1215 supported_codecs_.push_back(cricket::VideoCodec("VP9")); | 1215 supported_codecs_.push_back(cricket::VideoCodec("VP9")); |
| 1216 } | 1216 } |
| 1217 | 1217 |
| 1218 // Check if high profile is supported by decoder. If yes, encoder can always | |
| 1219 // fall back to baseline profile as a subset as high profile. | |
| 1220 bool is_h264_high_profile_hw_supported = false; | |
| 1221 if (webrtc::field_trial::FindFullName(kH264HighProfileFieldTrial) == | |
| 1222 "Enabled") { | |
| 1223 is_h264_high_profile_hw_supported = jni->CallStaticBooleanMethod( | |
| 1224 j_decoder_class, | |
| 1225 GetStaticMethodID(jni, j_decoder_class, "isH264HighProfileHwSupported", | |
| 1226 "()Z")); | |
| 1227 CHECK_EXCEPTION(jni); | |
| 1228 } | |
| 1229 if (is_h264_high_profile_hw_supported) { | |
| 1230 ALOGD << "H.264 High Profile HW Encoder supported."; | |
| 1231 // TODO(magjed): Enumerate actual level instead of using hardcoded level | |
| 1232 // 3.1. Level 3.1 is 1280x720@30fps which is enough for now. | |
| 1233 cricket::VideoCodec constrained_high(cricket::kH264CodecName); | |
| 1234 const webrtc::H264::ProfileLevelId constrained_high_profile( | |
| 1235 webrtc::H264::kProfileConstrainedHigh, webrtc::H264::kLevel3_1); | |
| 1236 constrained_high.SetParam( | |
| 1237 cricket::kH264FmtpProfileLevelId, | |
| 1238 *webrtc::H264::ProfileLevelIdToString(constrained_high_profile)); | |
| 1239 constrained_high.SetParam(cricket::kH264FmtpLevelAsymmetryAllowed, "1"); | |
| 1240 constrained_high.SetParam(cricket::kH264FmtpPacketizationMode, "1"); | |
| 1241 supported_codecs_.push_back(constrained_high); | |
| 1242 } | |
| 1243 | |
| 1244 bool is_h264_hw_supported = jni->CallStaticBooleanMethod( | 1218 bool is_h264_hw_supported = jni->CallStaticBooleanMethod( |
| 1245 j_encoder_class, | 1219 j_encoder_class, |
| 1246 GetStaticMethodID(jni, j_encoder_class, "isH264HwSupported", "()Z")); | 1220 GetStaticMethodID(jni, j_encoder_class, "isH264HwSupported", "()Z")); |
| 1247 CHECK_EXCEPTION(jni); | 1221 CHECK_EXCEPTION(jni); |
| 1248 if (is_h264_hw_supported) { | 1222 if (is_h264_hw_supported) { |
| 1249 ALOGD << "H.264 HW Encoder supported."; | 1223 ALOGD << "H.264 HW Encoder supported."; |
| 1250 // TODO(magjed): Push Constrained High profile as well when negotiation is | 1224 // TODO(magjed): Push Constrained High profile as well when negotiation is |
| 1251 // ready, http://crbug/webrtc/6337. We can negotiate Constrained High | 1225 // ready, http://crbug/webrtc/6337. We can negotiate Constrained High |
| 1252 // profile as long as we have decode support for it and still send Baseline | 1226 // profile as long as we have decode support for it and still send Baseline |
| 1253 // since Baseline is a subset of the High profile. | 1227 // since Baseline is a subset of the High profile. |
| 1254 cricket::VideoCodec constrained_baseline(cricket::kH264CodecName); | 1228 cricket::VideoCodec constrained_baseline(cricket::kH264CodecName); |
| 1255 const webrtc::H264::ProfileLevelId constrained_baseline_profile( | 1229 const webrtc::H264::ProfileLevelId constrained_baseline_profile( |
| 1256 webrtc::H264::kProfileConstrainedBaseline, webrtc::H264::kLevel3_1); | 1230 webrtc::H264::kProfileConstrainedBaseline, webrtc::H264::kLevel3_1); |
| 1257 constrained_baseline.SetParam( | 1231 constrained_baseline.SetParam( |
| 1258 cricket::kH264FmtpProfileLevelId, | 1232 cricket::kH264FmtpProfileLevelId, |
| 1259 *webrtc::H264::ProfileLevelIdToString(constrained_baseline_profile)); | 1233 *webrtc::H264::ProfileLevelIdToString(constrained_baseline_profile)); |
| 1260 constrained_baseline.SetParam(cricket::kH264FmtpLevelAsymmetryAllowed, "1"); | 1234 constrained_baseline.SetParam(cricket::kH264FmtpLevelAsymmetryAllowed, "1"); |
| 1261 constrained_baseline.SetParam(cricket::kH264FmtpPacketizationMode, "1"); | 1235 constrained_baseline.SetParam(cricket::kH264FmtpPacketizationMode, "1"); |
| 1262 supported_codecs_.push_back(constrained_baseline); | 1236 supported_codecs_.push_back(constrained_baseline); |
| 1263 } | 1237 } |
| 1238 |
| 1239 // Check if high profile is supported by decoder. If yes, encoder can always |
| 1240 // fall back to baseline profile as a subset as high profile. |
| 1241 supported_codecs_with_h264_hp_ = supported_codecs_; |
| 1242 bool is_h264_high_profile_hw_supported = jni->CallStaticBooleanMethod( |
| 1243 j_decoder_class, |
| 1244 GetStaticMethodID(jni, j_decoder_class, "isH264HighProfileHwSupported", |
| 1245 "()Z")); |
| 1246 CHECK_EXCEPTION(jni); |
| 1247 if (is_h264_high_profile_hw_supported) { |
| 1248 ALOGD << "H.264 High Profile HW Encoder supported."; |
| 1249 // TODO(magjed): Enumerate actual level instead of using hardcoded level |
| 1250 // 3.1. Level 3.1 is 1280x720@30fps which is enough for now. |
| 1251 cricket::VideoCodec constrained_high(cricket::kH264CodecName); |
| 1252 const webrtc::H264::ProfileLevelId constrained_high_profile( |
| 1253 webrtc::H264::kProfileConstrainedHigh, webrtc::H264::kLevel3_1); |
| 1254 constrained_high.SetParam( |
| 1255 cricket::kH264FmtpProfileLevelId, |
| 1256 *webrtc::H264::ProfileLevelIdToString(constrained_high_profile)); |
| 1257 constrained_high.SetParam(cricket::kH264FmtpLevelAsymmetryAllowed, "1"); |
| 1258 constrained_high.SetParam(cricket::kH264FmtpPacketizationMode, "1"); |
| 1259 supported_codecs_with_h264_hp_.push_back(constrained_high); |
| 1260 } |
| 1264 } | 1261 } |
| 1265 | 1262 |
| 1266 MediaCodecVideoEncoderFactory::~MediaCodecVideoEncoderFactory() { | 1263 MediaCodecVideoEncoderFactory::~MediaCodecVideoEncoderFactory() { |
| 1267 ALOGD << "MediaCodecVideoEncoderFactory dtor"; | 1264 ALOGD << "MediaCodecVideoEncoderFactory dtor"; |
| 1268 if (egl_context_) { | 1265 if (egl_context_) { |
| 1269 JNIEnv* jni = AttachCurrentThreadIfNeeded(); | 1266 JNIEnv* jni = AttachCurrentThreadIfNeeded(); |
| 1270 jni->DeleteGlobalRef(egl_context_); | 1267 jni->DeleteGlobalRef(egl_context_); |
| 1271 } | 1268 } |
| 1272 } | 1269 } |
| 1273 | 1270 |
| 1274 void MediaCodecVideoEncoderFactory::SetEGLContext( | 1271 void MediaCodecVideoEncoderFactory::SetEGLContext( |
| 1275 JNIEnv* jni, jobject egl_context) { | 1272 JNIEnv* jni, jobject egl_context) { |
| 1276 ALOGD << "MediaCodecVideoEncoderFactory::SetEGLContext"; | 1273 ALOGD << "MediaCodecVideoEncoderFactory::SetEGLContext"; |
| 1277 if (egl_context_) { | 1274 if (egl_context_) { |
| 1278 jni->DeleteGlobalRef(egl_context_); | 1275 jni->DeleteGlobalRef(egl_context_); |
| 1279 egl_context_ = nullptr; | 1276 egl_context_ = nullptr; |
| 1280 } | 1277 } |
| 1281 egl_context_ = jni->NewGlobalRef(egl_context); | 1278 egl_context_ = jni->NewGlobalRef(egl_context); |
| 1282 if (CheckException(jni)) { | 1279 if (CheckException(jni)) { |
| 1283 ALOGE << "error calling NewGlobalRef for EGL Context."; | 1280 ALOGE << "error calling NewGlobalRef for EGL Context."; |
| 1284 } | 1281 } |
| 1285 } | 1282 } |
| 1286 | 1283 |
| 1287 webrtc::VideoEncoder* MediaCodecVideoEncoderFactory::CreateVideoEncoder( | 1284 webrtc::VideoEncoder* MediaCodecVideoEncoderFactory::CreateVideoEncoder( |
| 1288 const cricket::VideoCodec& codec) { | 1285 const cricket::VideoCodec& codec) { |
| 1289 if (supported_codecs_.empty()) { | 1286 if (supported_codecs().empty()) { |
| 1290 ALOGW << "No HW video encoder for codec " << codec.name; | 1287 ALOGW << "No HW video encoder for codec " << codec.name; |
| 1291 return nullptr; | 1288 return nullptr; |
| 1292 } | 1289 } |
| 1293 if (FindMatchingCodec(supported_codecs_, codec)) { | 1290 if (FindMatchingCodec(supported_codecs(), codec)) { |
| 1294 ALOGD << "Create HW video encoder for " << codec.name; | 1291 ALOGD << "Create HW video encoder for " << codec.name; |
| 1295 JNIEnv* jni = AttachCurrentThreadIfNeeded(); | 1292 JNIEnv* jni = AttachCurrentThreadIfNeeded(); |
| 1296 ScopedLocalRefFrame local_ref_frame(jni); | 1293 ScopedLocalRefFrame local_ref_frame(jni); |
| 1297 return new MediaCodecVideoEncoder(jni, codec, egl_context_); | 1294 return new MediaCodecVideoEncoder(jni, codec, egl_context_); |
| 1298 } | 1295 } |
| 1299 ALOGW << "Can not find HW video encoder for type " << codec.name; | 1296 ALOGW << "Can not find HW video encoder for type " << codec.name; |
| 1300 return nullptr; | 1297 return nullptr; |
| 1301 } | 1298 } |
| 1302 | 1299 |
| 1303 const std::vector<cricket::VideoCodec>& | 1300 const std::vector<cricket::VideoCodec>& |
| 1304 MediaCodecVideoEncoderFactory::supported_codecs() const { | 1301 MediaCodecVideoEncoderFactory::supported_codecs() const { |
| 1305 return supported_codecs_; | 1302 if (webrtc::field_trial::FindFullName(kH264HighProfileFieldTrial) == |
| 1303 "Enabled") |
| 1304 return supported_codecs_with_h264_hp_; |
| 1305 else |
| 1306 return supported_codecs_; |
| 1306 } | 1307 } |
| 1307 | 1308 |
| 1308 void MediaCodecVideoEncoderFactory::DestroyVideoEncoder( | 1309 void MediaCodecVideoEncoderFactory::DestroyVideoEncoder( |
| 1309 webrtc::VideoEncoder* encoder) { | 1310 webrtc::VideoEncoder* encoder) { |
| 1310 ALOGD << "Destroy video encoder."; | 1311 ALOGD << "Destroy video encoder."; |
| 1311 delete encoder; | 1312 delete encoder; |
| 1312 } | 1313 } |
| 1313 | 1314 |
| 1314 } // namespace webrtc_jni | 1315 } // namespace webrtc_jni |
| OLD | NEW |