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

Side by Side Diff: webrtc/api/java/jni/androidmediaencoder_jni.cc

Issue 1672173002: Add initial bitrate and frame resolution parameters to quality scaler. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Adding constants Created 4 years, 10 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 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
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,
399 this, 400 this,
400 codec_settings->width, 401 codec_settings->width,
pbos-webrtc 2016/02/19 19:17:09 Can you make sure that these get called with the n
AlexG 2016/02/19 20:07:46 Done.
401 codec_settings->height, 402 codec_settings->height,
402 codec_settings->startBitrate, 403 codec_settings->startBitrate,
403 codec_settings->maxFramerate, 404 codec_settings->maxFramerate,
404 false /* use_surface */)); 405 false /* use_surface */));
405 } 406 }
406 407
407 int32_t MediaCodecVideoEncoder::Encode( 408 int32_t MediaCodecVideoEncoder::Encode(
408 const webrtc::VideoFrame& frame, 409 const webrtc::VideoFrame& frame,
409 const webrtc::CodecSpecificInfo* /* codec_specific_info */, 410 const webrtc::CodecSpecificInfo* /* codec_specific_info */,
410 const std::vector<webrtc::FrameType>* frame_types) { 411 const std::vector<webrtc::FrameType>* frame_types) {
(...skipping 834 matching lines...) Expand 10 before | Expand all | Expand 10 after
1245 } 1246 }
1246 1247
1247 void MediaCodecVideoEncoderFactory::DestroyVideoEncoder( 1248 void MediaCodecVideoEncoderFactory::DestroyVideoEncoder(
1248 webrtc::VideoEncoder* encoder) { 1249 webrtc::VideoEncoder* encoder) {
1249 ALOGD << "Destroy video encoder."; 1250 ALOGD << "Destroy video encoder.";
1250 delete encoder; 1251 delete encoder;
1251 } 1252 }
1252 1253
1253 } // namespace webrtc_jni 1254 } // namespace webrtc_jni
1254 1255
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698