| 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 337 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   348   srand(time(NULL)); |   348   srand(time(NULL)); | 
|   349   AllowBlockingCalls(); |   349   AllowBlockingCalls(); | 
|   350 } |   350 } | 
|   351  |   351  | 
|   352 int32_t MediaCodecVideoEncoder::InitEncode( |   352 int32_t MediaCodecVideoEncoder::InitEncode( | 
|   353     const webrtc::VideoCodec* codec_settings, |   353     const webrtc::VideoCodec* codec_settings, | 
|   354     int32_t /* number_of_cores */, |   354     int32_t /* number_of_cores */, | 
|   355     size_t /* max_payload_size */) { |   355     size_t /* max_payload_size */) { | 
|   356   const int kMinWidth = 320; |   356   const int kMinWidth = 320; | 
|   357   const int kMinHeight = 180; |   357   const int kMinHeight = 180; | 
|   358   const int kLowQpThresholdDenominator = 3; |  | 
|   359   if (codec_settings == NULL) { |   358   if (codec_settings == NULL) { | 
|   360     ALOGE << "NULL VideoCodec instance"; |   359     ALOGE << "NULL VideoCodec instance"; | 
|   361     return WEBRTC_VIDEO_CODEC_ERR_PARAMETER; |   360     return WEBRTC_VIDEO_CODEC_ERR_PARAMETER; | 
|   362   } |   361   } | 
|   363   // Factory should guard against other codecs being used with us. |   362   // Factory should guard against other codecs being used with us. | 
|   364   RTC_CHECK(codec_settings->codecType == codecType_) |   363   RTC_CHECK(codec_settings->codecType == codecType_) | 
|   365       << "Unsupported codec " << codec_settings->codecType << " for " |   364       << "Unsupported codec " << codec_settings->codecType << " for " | 
|   366       << codecType_; |   365       << codecType_; | 
|   367  |   366  | 
|   368   ALOGD << "InitEncode request"; |   367   ALOGD << "InitEncode request"; | 
|   369   codec_mode_ = codec_settings->mode; |   368   codec_mode_ = codec_settings->mode; | 
|   370   scale_ = (codecType_ != kVideoCodecVP9) && (webrtc::field_trial::FindFullName( |   369   scale_ = (codecType_ != kVideoCodecVP9) && (webrtc::field_trial::FindFullName( | 
|   371         "WebRTC-MediaCodecVideoEncoder-AutomaticResize") == "Enabled"); |   370         "WebRTC-MediaCodecVideoEncoder-AutomaticResize") == "Enabled"); | 
|   372   ALOGD << "Encoder automatic resize " << (scale_ ? "enabled" : "disabled"); |   371   ALOGD << "Encoder automatic resize " << (scale_ ? "enabled" : "disabled"); | 
|   373   if (scale_) { |   372   if (scale_) { | 
|   374     if (codecType_ == kVideoCodecVP8) { |   373     if (codecType_ == kVideoCodecVP8) { | 
|   375       // QP is obtained from VP8-bitstream for HW, so the QP corresponds to the |   374       // QP is obtained from VP8-bitstream for HW, so the QP corresponds to the | 
|   376       // (internal) range: [0, 127]. And we cannot change QP_max in HW, so it is |   375       // (internal) range: [0, 127]. And we cannot change QP_max in HW, so it is | 
|   377       // always = 127. Note that in SW, QP is that of the user-level range [0, |   376       // always = 127. Note that in SW, QP is that of the user-level range [0, | 
|   378       // 63]. |   377       // 63]. | 
|   379       const int kMaxQp = 127; |   378       const int kLowQpThreshold = 32; | 
|   380       const int kBadQpThreshold = 95; |   379       const int kBadQpThreshold = 92; | 
|   381       quality_scaler_.Init( |   380       quality_scaler_.Init(kLowQpThreshold, kBadQpThreshold, false, | 
|   382           kMaxQp / kLowQpThresholdDenominator, kBadQpThreshold, false); |   381           codec_settings->startBitrate, | 
 |   382           codec_settings->width, codec_settings->height); | 
|   383     } else if (codecType_ == kVideoCodecH264) { |   383     } else if (codecType_ == kVideoCodecH264) { | 
|   384       // H264 QP is in the range [0, 51]. |   384       // H264 QP is in the range [0, 51]. | 
|   385       const int kMaxQp = 51; |   385       const int kLowQpThreshold = 17; | 
|   386       const int kBadQpThreshold = 40; |   386       const int kBadQpThreshold = 40; | 
|   387       quality_scaler_.Init( |   387       quality_scaler_.Init(kLowQpThreshold, kBadQpThreshold, false, | 
|   388           kMaxQp / kLowQpThresholdDenominator, kBadQpThreshold, false); |   388           codec_settings->startBitrate, | 
 |   389           codec_settings->width, codec_settings->height); | 
|   389     } else { |   390     } else { | 
|   390       // When adding codec support to additional hardware codecs, also configure |   391       // When adding codec support to additional hardware codecs, also configure | 
|   391       // their QP thresholds for scaling. |   392       // their QP thresholds for scaling. | 
|   392       RTC_NOTREACHED() << "Unsupported codec without configured QP thresholds."; |   393       RTC_NOTREACHED() << "Unsupported codec without configured QP thresholds."; | 
|   393     } |   394     } | 
|   394     quality_scaler_.SetMinResolution(kMinWidth, kMinHeight); |   395     quality_scaler_.SetMinResolution(kMinWidth, kMinHeight); | 
|   395     quality_scaler_.ReportFramerate(codec_settings->maxFramerate); |   396     quality_scaler_.ReportFramerate(codec_settings->maxFramerate); | 
|   396   } |   397   } | 
|   397   return codec_thread_->Invoke<int32_t>( |   398   return codec_thread_->Invoke<int32_t>( | 
|   398       Bind(&MediaCodecVideoEncoder::InitEncodeOnCodecThread, |   399       Bind(&MediaCodecVideoEncoder::InitEncodeOnCodecThread, | 
| (...skipping 839 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1238 } |  1239 } | 
|  1239  |  1240  | 
|  1240 void MediaCodecVideoEncoderFactory::DestroyVideoEncoder( |  1241 void MediaCodecVideoEncoderFactory::DestroyVideoEncoder( | 
|  1241     webrtc::VideoEncoder* encoder) { |  1242     webrtc::VideoEncoder* encoder) { | 
|  1242   ALOGD << "Destroy video encoder."; |  1243   ALOGD << "Destroy video encoder."; | 
|  1243   delete encoder; |  1244   delete encoder; | 
|  1244 } |  1245 } | 
|  1245  |  1246  | 
|  1246 }  // namespace webrtc_jni |  1247 }  // namespace webrtc_jni | 
|  1247  |  1248  | 
| OLD | NEW |