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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 int32_t Release() override; | 114 int32_t Release() override; |
115 int32_t SetChannelParameters(uint32_t /* packet_loss */, | 115 int32_t SetChannelParameters(uint32_t /* packet_loss */, |
116 int64_t /* rtt */) override; | 116 int64_t /* rtt */) override; |
117 int32_t SetRates(uint32_t new_bit_rate, uint32_t frame_rate) override; | 117 int32_t SetRates(uint32_t new_bit_rate, uint32_t frame_rate) override; |
118 | 118 |
119 // rtc::MessageHandler implementation. | 119 // rtc::MessageHandler implementation. |
120 void OnMessage(rtc::Message* msg) override; | 120 void OnMessage(rtc::Message* msg) override; |
121 | 121 |
122 void OnDroppedFrame() override; | 122 void OnDroppedFrame() override; |
123 | 123 |
124 int GetTargetFramerate() override; | |
125 | |
126 bool SupportsNativeHandle() const override { return egl_context_ != nullptr; } | 124 bool SupportsNativeHandle() const override { return egl_context_ != nullptr; } |
127 const char* ImplementationName() const override; | 125 const char* ImplementationName() const override; |
128 | 126 |
129 private: | 127 private: |
130 // CHECK-fail if not running on |codec_thread_|. | 128 // CHECK-fail if not running on |codec_thread_|. |
131 void CheckOnCodecThread(); | 129 void CheckOnCodecThread(); |
132 | 130 |
133 private: | 131 private: |
134 // ResetCodecOnCodecThread() calls ReleaseOnCodecThread() and | 132 // ResetCodecOnCodecThread() calls ReleaseOnCodecThread() and |
135 // InitEncodeOnCodecThread() in an attempt to restore the codec to an | 133 // InitEncodeOnCodecThread() in an attempt to restore the codec to an |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 ALOGD << "Encoder automatic resize " << (scale_ ? "enabled" : "disabled"); | 388 ALOGD << "Encoder automatic resize " << (scale_ ? "enabled" : "disabled"); |
391 | 389 |
392 if (scale_) { | 390 if (scale_) { |
393 if (codecType_ == kVideoCodecVP8) { | 391 if (codecType_ == kVideoCodecVP8) { |
394 // QP is obtained from VP8-bitstream for HW, so the QP corresponds to the | 392 // QP is obtained from VP8-bitstream for HW, so the QP corresponds to the |
395 // (internal) range: [0, 127]. And we cannot change QP_max in HW, so it is | 393 // (internal) range: [0, 127]. And we cannot change QP_max in HW, so it is |
396 // always = 127. Note that in SW, QP is that of the user-level range [0, | 394 // always = 127. Note that in SW, QP is that of the user-level range [0, |
397 // 63]. | 395 // 63]. |
398 const int kLowQpThreshold = 29; | 396 const int kLowQpThreshold = 29; |
399 const int kBadQpThreshold = 100; | 397 const int kBadQpThreshold = 100; |
400 quality_scaler_.Init(kLowQpThreshold, kBadQpThreshold, false, | 398 quality_scaler_.Init(kLowQpThreshold, kBadQpThreshold, |
401 codec_settings->startBitrate, codec_settings->width, | 399 codec_settings->startBitrate, codec_settings->width, |
402 codec_settings->height, | 400 codec_settings->height, |
403 codec_settings->maxFramerate); | 401 codec_settings->maxFramerate); |
404 } else if (codecType_ == kVideoCodecH264) { | 402 } else if (codecType_ == kVideoCodecH264) { |
405 // H264 QP is in the range [0, 51]. | 403 // H264 QP is in the range [0, 51]. |
406 const int kLowQpThreshold = 24; | 404 const int kLowQpThreshold = 24; |
407 const int kBadQpThreshold = 39; | 405 const int kBadQpThreshold = 39; |
408 quality_scaler_.Init(kLowQpThreshold, kBadQpThreshold, false, | 406 quality_scaler_.Init(kLowQpThreshold, kBadQpThreshold, |
409 codec_settings->startBitrate, codec_settings->width, | 407 codec_settings->startBitrate, codec_settings->width, |
410 codec_settings->height, | 408 codec_settings->height, |
411 codec_settings->maxFramerate); | 409 codec_settings->maxFramerate); |
412 } else { | 410 } else { |
413 // When adding codec support to additional hardware codecs, also configure | 411 // When adding codec support to additional hardware codecs, also configure |
414 // their QP thresholds for scaling. | 412 // their QP thresholds for scaling. |
415 RTC_NOTREACHED() << "Unsupported codec without configured QP thresholds."; | 413 RTC_NOTREACHED() << "Unsupported codec without configured QP thresholds."; |
416 scale_ = false; | 414 scale_ = false; |
417 } | 415 } |
418 QualityScaler::Resolution res = quality_scaler_.GetScaledResolution(); | 416 QualityScaler::Resolution res = quality_scaler_.GetScaledResolution(); |
(...skipping 750 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1169 } | 1167 } |
1170 return -1; | 1168 return -1; |
1171 } | 1169 } |
1172 | 1170 |
1173 void MediaCodecVideoEncoder::OnDroppedFrame() { | 1171 void MediaCodecVideoEncoder::OnDroppedFrame() { |
1174 // Report dropped frame to quality_scaler_. | 1172 // Report dropped frame to quality_scaler_. |
1175 if (scale_) | 1173 if (scale_) |
1176 quality_scaler_.ReportDroppedFrame(); | 1174 quality_scaler_.ReportDroppedFrame(); |
1177 } | 1175 } |
1178 | 1176 |
1179 int MediaCodecVideoEncoder::GetTargetFramerate() { | |
1180 return scale_ ? quality_scaler_.GetTargetFramerate() : -1; | |
1181 } | |
1182 | |
1183 const char* MediaCodecVideoEncoder::ImplementationName() const { | 1177 const char* MediaCodecVideoEncoder::ImplementationName() const { |
1184 return "MediaCodec"; | 1178 return "MediaCodec"; |
1185 } | 1179 } |
1186 | 1180 |
1187 MediaCodecVideoEncoderFactory::MediaCodecVideoEncoderFactory() | 1181 MediaCodecVideoEncoderFactory::MediaCodecVideoEncoderFactory() |
1188 : egl_context_(nullptr) { | 1182 : egl_context_(nullptr) { |
1189 JNIEnv* jni = AttachCurrentThreadIfNeeded(); | 1183 JNIEnv* jni = AttachCurrentThreadIfNeeded(); |
1190 ScopedLocalRefFrame local_ref_frame(jni); | 1184 ScopedLocalRefFrame local_ref_frame(jni); |
1191 jclass j_encoder_class = FindClass(jni, "org/webrtc/MediaCodecVideoEncoder"); | 1185 jclass j_encoder_class = FindClass(jni, "org/webrtc/MediaCodecVideoEncoder"); |
1192 supported_codecs_.clear(); | 1186 supported_codecs_.clear(); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1267 return supported_codecs_; | 1261 return supported_codecs_; |
1268 } | 1262 } |
1269 | 1263 |
1270 void MediaCodecVideoEncoderFactory::DestroyVideoEncoder( | 1264 void MediaCodecVideoEncoderFactory::DestroyVideoEncoder( |
1271 webrtc::VideoEncoder* encoder) { | 1265 webrtc::VideoEncoder* encoder) { |
1272 ALOGD << "Destroy video encoder."; | 1266 ALOGD << "Destroy video encoder."; |
1273 delete encoder; | 1267 delete encoder; |
1274 } | 1268 } |
1275 | 1269 |
1276 } // namespace webrtc_jni | 1270 } // namespace webrtc_jni |
OLD | NEW |