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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 using webrtc::kVideoCodecVP8; | 50 using webrtc::kVideoCodecVP8; |
51 using webrtc::kVideoCodecVP9; | 51 using webrtc::kVideoCodecVP9; |
52 using webrtc::QualityScaler; | 52 using webrtc::QualityScaler; |
53 | 53 |
54 namespace webrtc_jni { | 54 namespace webrtc_jni { |
55 | 55 |
56 // H.264 start code length. | 56 // H.264 start code length. |
57 #define H264_SC_LENGTH 4 | 57 #define H264_SC_LENGTH 4 |
58 // Maximum allowed NALUs in one output frame. | 58 // Maximum allowed NALUs in one output frame. |
59 #define MAX_NALUS_PERFRAME 32 | 59 #define MAX_NALUS_PERFRAME 32 |
60 // Maximum supported HW video encoder resolution. | |
61 #define MAX_VIDEO_WIDTH 1280 | |
62 #define MAX_VIDEO_HEIGHT 1280 | |
63 // Maximum supported HW video encoder fps. | 60 // Maximum supported HW video encoder fps. |
64 #define MAX_VIDEO_FPS 30 | 61 #define MAX_VIDEO_FPS 30 |
65 // Maximum allowed fps value in SetRates() call. | 62 // Maximum allowed fps value in SetRates() call. |
66 #define MAX_ALLOWED_VIDEO_FPS 60 | 63 #define MAX_ALLOWED_VIDEO_FPS 60 |
67 // Maximum allowed frames in encoder input queue. | 64 // Maximum allowed frames in encoder input queue. |
68 #define MAX_ENCODER_Q_SIZE 2 | 65 #define MAX_ENCODER_Q_SIZE 2 |
69 // Maximum amount of dropped frames caused by full encoder queue - exceeding | 66 // Maximum amount of dropped frames caused by full encoder queue - exceeding |
70 // this threshold means that encoder probably got stuck and need to be reset. | 67 // this threshold means that encoder probably got stuck and need to be reset. |
71 #define ENCODER_STALL_FRAMEDROP_THRESHOLD 60 | 68 #define ENCODER_STALL_FRAMEDROP_THRESHOLD 60 |
72 | 69 |
(...skipping 1230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1303 ScopedLocalRefFrame local_ref_frame(jni); | 1300 ScopedLocalRefFrame local_ref_frame(jni); |
1304 jclass j_encoder_class = FindClass(jni, "org/webrtc/MediaCodecVideoEncoder"); | 1301 jclass j_encoder_class = FindClass(jni, "org/webrtc/MediaCodecVideoEncoder"); |
1305 supported_codecs_.clear(); | 1302 supported_codecs_.clear(); |
1306 | 1303 |
1307 bool is_vp8_hw_supported = jni->CallStaticBooleanMethod( | 1304 bool is_vp8_hw_supported = jni->CallStaticBooleanMethod( |
1308 j_encoder_class, | 1305 j_encoder_class, |
1309 GetStaticMethodID(jni, j_encoder_class, "isVp8HwSupported", "()Z")); | 1306 GetStaticMethodID(jni, j_encoder_class, "isVp8HwSupported", "()Z")); |
1310 CHECK_EXCEPTION(jni); | 1307 CHECK_EXCEPTION(jni); |
1311 if (is_vp8_hw_supported) { | 1308 if (is_vp8_hw_supported) { |
1312 ALOGD << "VP8 HW Encoder supported."; | 1309 ALOGD << "VP8 HW Encoder supported."; |
1313 supported_codecs_.push_back(VideoCodec(kVideoCodecVP8, "VP8", | 1310 supported_codecs_.push_back(cricket::VideoCodec("VP8")); |
1314 MAX_VIDEO_WIDTH, MAX_VIDEO_HEIGHT, MAX_VIDEO_FPS)); | |
1315 } | 1311 } |
1316 | 1312 |
1317 bool is_vp9_hw_supported = jni->CallStaticBooleanMethod( | 1313 bool is_vp9_hw_supported = jni->CallStaticBooleanMethod( |
1318 j_encoder_class, | 1314 j_encoder_class, |
1319 GetStaticMethodID(jni, j_encoder_class, "isVp9HwSupported", "()Z")); | 1315 GetStaticMethodID(jni, j_encoder_class, "isVp9HwSupported", "()Z")); |
1320 CHECK_EXCEPTION(jni); | 1316 CHECK_EXCEPTION(jni); |
1321 if (is_vp9_hw_supported) { | 1317 if (is_vp9_hw_supported) { |
1322 ALOGD << "VP9 HW Encoder supported."; | 1318 ALOGD << "VP9 HW Encoder supported."; |
1323 supported_codecs_.push_back(VideoCodec(kVideoCodecVP9, "VP9", | 1319 supported_codecs_.push_back(cricket::VideoCodec("VP9")); |
1324 MAX_VIDEO_WIDTH, MAX_VIDEO_HEIGHT, MAX_VIDEO_FPS)); | |
1325 } | 1320 } |
1326 | 1321 |
1327 bool is_h264_hw_supported = jni->CallStaticBooleanMethod( | 1322 bool is_h264_hw_supported = jni->CallStaticBooleanMethod( |
1328 j_encoder_class, | 1323 j_encoder_class, |
1329 GetStaticMethodID(jni, j_encoder_class, "isH264HwSupported", "()Z")); | 1324 GetStaticMethodID(jni, j_encoder_class, "isH264HwSupported", "()Z")); |
1330 CHECK_EXCEPTION(jni); | 1325 CHECK_EXCEPTION(jni); |
1331 if (is_h264_hw_supported) { | 1326 if (is_h264_hw_supported) { |
1332 ALOGD << "H.264 HW Encoder supported."; | 1327 ALOGD << "H.264 HW Encoder supported."; |
1333 supported_codecs_.push_back(VideoCodec(kVideoCodecH264, "H264", | 1328 supported_codecs_.push_back(cricket::VideoCodec("H264")); |
1334 MAX_VIDEO_WIDTH, MAX_VIDEO_HEIGHT, MAX_VIDEO_FPS)); | |
1335 } | 1329 } |
1336 } | 1330 } |
1337 | 1331 |
1338 MediaCodecVideoEncoderFactory::~MediaCodecVideoEncoderFactory() { | 1332 MediaCodecVideoEncoderFactory::~MediaCodecVideoEncoderFactory() { |
1339 ALOGD << "MediaCodecVideoEncoderFactory dtor"; | 1333 ALOGD << "MediaCodecVideoEncoderFactory dtor"; |
1340 if (egl_context_) { | 1334 if (egl_context_) { |
1341 JNIEnv* jni = AttachCurrentThreadIfNeeded(); | 1335 JNIEnv* jni = AttachCurrentThreadIfNeeded(); |
1342 jni->DeleteGlobalRef(egl_context_); | 1336 jni->DeleteGlobalRef(egl_context_); |
1343 } | 1337 } |
1344 } | 1338 } |
1345 | 1339 |
1346 void MediaCodecVideoEncoderFactory::SetEGLContext( | 1340 void MediaCodecVideoEncoderFactory::SetEGLContext( |
1347 JNIEnv* jni, jobject egl_context) { | 1341 JNIEnv* jni, jobject egl_context) { |
1348 ALOGD << "MediaCodecVideoEncoderFactory::SetEGLContext"; | 1342 ALOGD << "MediaCodecVideoEncoderFactory::SetEGLContext"; |
1349 if (egl_context_) { | 1343 if (egl_context_) { |
1350 jni->DeleteGlobalRef(egl_context_); | 1344 jni->DeleteGlobalRef(egl_context_); |
1351 egl_context_ = nullptr; | 1345 egl_context_ = nullptr; |
1352 } | 1346 } |
1353 egl_context_ = jni->NewGlobalRef(egl_context); | 1347 egl_context_ = jni->NewGlobalRef(egl_context); |
1354 if (CheckException(jni)) { | 1348 if (CheckException(jni)) { |
1355 ALOGE << "error calling NewGlobalRef for EGL Context."; | 1349 ALOGE << "error calling NewGlobalRef for EGL Context."; |
1356 } | 1350 } |
1357 } | 1351 } |
1358 | 1352 |
1359 webrtc::VideoEncoder* MediaCodecVideoEncoderFactory::CreateVideoEncoder( | 1353 webrtc::VideoEncoder* MediaCodecVideoEncoderFactory::CreateVideoEncoder( |
1360 VideoCodecType type) { | 1354 const cricket::VideoCodec& codec) { |
1361 if (supported_codecs_.empty()) { | 1355 if (supported_codecs_.empty()) { |
1362 ALOGW << "No HW video encoder for type " << (int)type; | 1356 ALOGW << "No HW video encoder for codec " << codec.name; |
1363 return nullptr; | 1357 return nullptr; |
1364 } | 1358 } |
1365 for (std::vector<VideoCodec>::const_iterator it = supported_codecs_.begin(); | 1359 if (IsCodecSupported(supported_codecs_, codec)) { |
1366 it != supported_codecs_.end(); ++it) { | 1360 ALOGD << "Create HW video encoder for " << codec.name; |
1367 if (it->type == type) { | 1361 const VideoCodecType type = cricket::CodecTypeFromName(codec.name); |
1368 ALOGD << "Create HW video encoder for type " << (int)type << | 1362 return new MediaCodecVideoEncoder(AttachCurrentThreadIfNeeded(), type, |
1369 " (" << it->name << ")."; | 1363 egl_context_); |
1370 return new MediaCodecVideoEncoder(AttachCurrentThreadIfNeeded(), type, | |
1371 egl_context_); | |
1372 } | |
1373 } | 1364 } |
1374 ALOGW << "Can not find HW video encoder for type " << (int)type; | 1365 ALOGW << "Can not find HW video encoder for type " << codec.name; |
1375 return nullptr; | 1366 return nullptr; |
1376 } | 1367 } |
1377 | 1368 |
1378 const std::vector<MediaCodecVideoEncoderFactory::VideoCodec>& | 1369 const std::vector<cricket::VideoCodec>& |
1379 MediaCodecVideoEncoderFactory::codecs() const { | 1370 MediaCodecVideoEncoderFactory::supported_codecs() const { |
1380 return supported_codecs_; | 1371 return supported_codecs_; |
1381 } | 1372 } |
1382 | 1373 |
1383 void MediaCodecVideoEncoderFactory::DestroyVideoEncoder( | 1374 void MediaCodecVideoEncoderFactory::DestroyVideoEncoder( |
1384 webrtc::VideoEncoder* encoder) { | 1375 webrtc::VideoEncoder* encoder) { |
1385 ALOGD << "Destroy video encoder."; | 1376 ALOGD << "Destroy video encoder."; |
1386 delete encoder; | 1377 delete encoder; |
1387 } | 1378 } |
1388 | 1379 |
1389 } // namespace webrtc_jni | 1380 } // namespace webrtc_jni |
OLD | NEW |