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

Side by Side Diff: talk/app/webrtc/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: 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 * libjingle 2 * libjingle
3 * Copyright 2015 Google Inc. 3 * Copyright 2015 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright notice, 8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 srand(time(NULL)); 365 srand(time(NULL));
366 AllowBlockingCalls(); 366 AllowBlockingCalls();
367 } 367 }
368 368
369 int32_t MediaCodecVideoEncoder::InitEncode( 369 int32_t MediaCodecVideoEncoder::InitEncode(
370 const webrtc::VideoCodec* codec_settings, 370 const webrtc::VideoCodec* codec_settings,
371 int32_t /* number_of_cores */, 371 int32_t /* number_of_cores */,
372 size_t /* max_payload_size */) { 372 size_t /* max_payload_size */) {
373 const int kMinWidth = 320; 373 const int kMinWidth = 320;
374 const int kMinHeight = 180; 374 const int kMinHeight = 180;
375 const int kLowQpThresholdDenominator = 3;
376 if (codec_settings == NULL) { 375 if (codec_settings == NULL) {
377 ALOGE << "NULL VideoCodec instance"; 376 ALOGE << "NULL VideoCodec instance";
378 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER; 377 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
379 } 378 }
380 // Factory should guard against other codecs being used with us. 379 // Factory should guard against other codecs being used with us.
381 RTC_CHECK(codec_settings->codecType == codecType_) 380 RTC_CHECK(codec_settings->codecType == codecType_)
382 << "Unsupported codec " << codec_settings->codecType << " for " 381 << "Unsupported codec " << codec_settings->codecType << " for "
383 << codecType_; 382 << codecType_;
384 383
385 ALOGD << "InitEncode request"; 384 ALOGD << "InitEncode request";
386 codec_mode_ = codec_settings->mode; 385 codec_mode_ = codec_settings->mode;
387 scale_ = (codecType_ != kVideoCodecVP9) && (webrtc::field_trial::FindFullName( 386 scale_ = (codecType_ != kVideoCodecVP9) && (webrtc::field_trial::FindFullName(
388 "WebRTC-MediaCodecVideoEncoder-AutomaticResize") == "Enabled"); 387 "WebRTC-MediaCodecVideoEncoder-AutomaticResize") == "Enabled");
389 ALOGD << "Encoder automatic resize " << (scale_ ? "enabled" : "disabled"); 388 ALOGD << "Encoder automatic resize " << (scale_ ? "enabled" : "disabled");
390 if (scale_) { 389 if (scale_) {
391 if (codecType_ == kVideoCodecVP8) { 390 if (codecType_ == kVideoCodecVP8) {
392 // QP is obtained from VP8-bitstream for HW, so the QP corresponds to the 391 // QP is obtained from VP8-bitstream for HW, so the QP corresponds to the
393 // (internal) range: [0, 127]. And we cannot change QP_max in HW, so it is 392 // (internal) range: [0, 127]. And we cannot change QP_max in HW, so it is
394 // always = 127. Note that in SW, QP is that of the user-level range [0, 393 // always = 127. Note that in SW, QP is that of the user-level range [0,
395 // 63]. 394 // 63].
396 const int kMaxQp = 127; 395 const int kLowQpThreshold = 32;
397 const int kBadQpThreshold = 95; 396 const int kBadQpThreshold = 92;
398 quality_scaler_.Init( 397 quality_scaler_.Init(kLowQpThreshold, kBadQpThreshold, false,
399 kMaxQp / kLowQpThresholdDenominator, kBadQpThreshold, false); 398 codec_settings->startBitrate,
399 codec_settings->width, codec_settings->height);
400 } else if (codecType_ == kVideoCodecH264) { 400 } else if (codecType_ == kVideoCodecH264) {
401 // H264 QP is in the range [0, 51]. 401 // H264 QP is in the range [0, 51].
402 const int kMaxQp = 51; 402 const int kMaxQp = 51;
403 const int kLowQpThresholdDenominator = 3;
pbos-webrtc 2016/02/09 20:31:29 Let's just put a constant here without the denomin
AlexG 2016/02/09 23:37:18 Done.
403 const int kBadQpThreshold = 40; 404 const int kBadQpThreshold = 40;
404 quality_scaler_.Init( 405 quality_scaler_.Init(
405 kMaxQp / kLowQpThresholdDenominator, kBadQpThreshold, false); 406 kMaxQp / kLowQpThresholdDenominator, kBadQpThreshold, false,
407 codec_settings->startBitrate,
408 codec_settings->width, codec_settings->height);
406 } else { 409 } else {
407 // When adding codec support to additional hardware codecs, also configure 410 // When adding codec support to additional hardware codecs, also configure
408 // their QP thresholds for scaling. 411 // their QP thresholds for scaling.
409 RTC_NOTREACHED() << "Unsupported codec without configured QP thresholds."; 412 RTC_NOTREACHED() << "Unsupported codec without configured QP thresholds.";
410 } 413 }
411 quality_scaler_.SetMinResolution(kMinWidth, kMinHeight); 414 quality_scaler_.SetMinResolution(kMinWidth, kMinHeight);
412 quality_scaler_.ReportFramerate(codec_settings->maxFramerate); 415 quality_scaler_.ReportFramerate(codec_settings->maxFramerate);
413 } 416 }
414 return codec_thread_->Invoke<int32_t>( 417 return codec_thread_->Invoke<int32_t>(
415 Bind(&MediaCodecVideoEncoder::InitEncodeOnCodecThread, 418 Bind(&MediaCodecVideoEncoder::InitEncodeOnCodecThread,
(...skipping 839 matching lines...) Expand 10 before | Expand all | Expand 10 after
1255 } 1258 }
1256 1259
1257 void MediaCodecVideoEncoderFactory::DestroyVideoEncoder( 1260 void MediaCodecVideoEncoderFactory::DestroyVideoEncoder(
1258 webrtc::VideoEncoder* encoder) { 1261 webrtc::VideoEncoder* encoder) {
1259 ALOGD << "Destroy video encoder."; 1262 ALOGD << "Destroy video encoder.";
1260 delete encoder; 1263 delete encoder;
1261 } 1264 }
1262 1265
1263 } // namespace webrtc_jni 1266 } // namespace webrtc_jni
1264 1267
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698