MediaOptimization: Remove unneeded member variable: video_target_bitrate_

Remove unimplemented function declaration CheckSuspendConditions.

Make UpdateWithEncodedData void (always returning ok).

Rename user_frame_rate_ -> max_frame_rate_


Bug: none
Change-Id: I2eb5419a670e31d417f1bec8c163839c01f8c1fa
Reviewed-on: https://webrtc-review.googlesource.com/20500
Reviewed-by: Rasmus Brandt <brandtr@webrtc.org>
Commit-Queue: Åsa Persson <asapersson@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#20612}
This commit is contained in:
Åsa Persson
2017-11-08 11:33:37 +01:00
committed by Commit Bot
parent 7281f92e72
commit b52a4d90c2
4 changed files with 49 additions and 78 deletions

View File

@ -17,13 +17,15 @@
namespace webrtc {
namespace media_optimization {
namespace {
const int64_t kFrameHistoryWinMs = 2000;
} // namespace
MediaOptimization::MediaOptimization(Clock* clock)
: clock_(clock),
max_bit_rate_(0),
user_frame_rate_(0),
max_frame_rate_(0),
frame_dropper_(new FrameDropper),
video_target_bitrate_(0),
incoming_frame_rate_(0) {
memset(incoming_frame_times_, -1, sizeof(incoming_frame_times_));
}
@ -38,52 +40,49 @@ void MediaOptimization::Reset() {
incoming_frame_rate_ = 0.0;
frame_dropper_->Reset();
frame_dropper_->SetRates(0, 0);
video_target_bitrate_ = 0;
user_frame_rate_ = 0;
max_frame_rate_ = 0;
}
void MediaOptimization::SetEncodingData(int32_t max_bit_rate,
uint32_t target_bitrate,
uint32_t frame_rate) {
uint32_t max_frame_rate) {
rtc::CritScope lock(&crit_sect_);
SetEncodingDataInternal(max_bit_rate, frame_rate, target_bitrate);
SetEncodingDataInternal(max_bit_rate, max_frame_rate, target_bitrate);
}
void MediaOptimization::SetEncodingDataInternal(int32_t max_bit_rate,
uint32_t frame_rate,
uint32_t max_frame_rate,
uint32_t target_bitrate) {
// Everything codec specific should be reset here since this means the codec
// has changed.
max_bit_rate_ = max_bit_rate;
video_target_bitrate_ = target_bitrate;
max_frame_rate_ = static_cast<float>(max_frame_rate);
float target_bitrate_kbps = static_cast<float>(target_bitrate) / 1000.0f;
frame_dropper_->Reset();
frame_dropper_->SetRates(target_bitrate_kbps, static_cast<float>(frame_rate));
user_frame_rate_ = static_cast<float>(frame_rate);
frame_dropper_->SetRates(target_bitrate_kbps, max_frame_rate_);
}
uint32_t MediaOptimization::SetTargetRates(uint32_t target_bitrate) {
rtc::CritScope lock(&crit_sect_);
video_target_bitrate_ = target_bitrate;
// Cap target video bitrate to codec maximum.
if (max_bit_rate_ > 0 && video_target_bitrate_ > max_bit_rate_) {
video_target_bitrate_ = max_bit_rate_;
int video_target_bitrate = target_bitrate;
if (max_bit_rate_ > 0 && video_target_bitrate > max_bit_rate_) {
video_target_bitrate = max_bit_rate_;
}
// Update encoding rates following protection settings.
float target_video_bitrate_kbps =
static_cast<float>(video_target_bitrate_) / 1000.0f;
static_cast<float>(video_target_bitrate) / 1000.0f;
float framerate = incoming_frame_rate_;
if (framerate == 0.0) {
// No framerate estimate available, use configured max framerate instead.
framerate = user_frame_rate_;
framerate = max_frame_rate_;
}
frame_dropper_->SetRates(target_video_bitrate_kbps, framerate);
return video_target_bitrate_;
return video_target_bitrate;
}
uint32_t MediaOptimization::InputFrameRate() {
@ -98,7 +97,7 @@ uint32_t MediaOptimization::InputFrameRateInternal() {
return framerate;
}
int32_t MediaOptimization::UpdateWithEncodedData(
void MediaOptimization::UpdateWithEncodedData(
const EncodedImage& encoded_image) {
size_t encoded_length = encoded_image._length;
rtc::CritScope lock(&crit_sect_);
@ -106,7 +105,6 @@ int32_t MediaOptimization::UpdateWithEncodedData(
const bool delta_frame = encoded_image._frameType != kVideoFrameKey;
frame_dropper_->Fill(encoded_length, delta_frame);
}
return VCM_OK;
}
void MediaOptimization::EnableFrameDropper(bool enable) {

View File

@ -11,7 +11,6 @@
#ifndef MODULES_VIDEO_CODING_MEDIA_OPTIMIZATION_H_
#define MODULES_VIDEO_CODING_MEDIA_OPTIMIZATION_H_
#include <list>
#include <memory>
#include "modules/include/module_common_types.h"
@ -23,7 +22,6 @@ namespace webrtc {
class Clock;
class FrameDropper;
class VCMContentMetricsProcessing;
namespace media_optimization {
@ -38,10 +36,10 @@ class MediaOptimization {
// Informs media optimization of initial encoding state.
// TODO(perkj): Deprecate SetEncodingData once its not used for stats in
// VieEncoder.
// VideoStreamEncoder.
void SetEncodingData(int32_t max_bit_rate,
uint32_t bit_rate,
uint32_t frame_rate);
uint32_t max_frame_rate);
// Sets target rates for the encoder given the channel parameters.
// Input: |target bitrate| - the encoder target bitrate in bits/s.
@ -52,27 +50,21 @@ class MediaOptimization {
// Informs Media Optimization of encoded output.
// TODO(perkj): Deprecate SetEncodingData once its not used for stats in
// VieEncoder.
int32_t UpdateWithEncodedData(const EncodedImage& encoded_image);
// VideoStreamEncoder.
void UpdateWithEncodedData(const EncodedImage& encoded_image);
// InputFrameRate 0 = no frame rate estimate available.
uint32_t InputFrameRate();
private:
enum { kFrameCountHistorySize = 90 };
enum { kFrameHistoryWinMs = 2000 };
void UpdateIncomingFrameRate() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
void ProcessIncomingFrameRate(int64_t now)
RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
// Checks conditions for suspending the video. The method compares
// |video_target_bitrate_| with the threshold values for suspension, and
// changes the state of |video_suspended_| accordingly.
void CheckSuspendConditions() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
void SetEncodingDataInternal(int32_t max_bit_rate,
uint32_t frame_rate,
uint32_t max_frame_rate,
uint32_t bit_rate)
RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
@ -81,11 +73,10 @@ class MediaOptimization {
// Protect all members.
rtc::CriticalSection crit_sect_;
Clock* clock_ RTC_GUARDED_BY(crit_sect_);
Clock* const clock_ RTC_GUARDED_BY(crit_sect_);
int32_t max_bit_rate_ RTC_GUARDED_BY(crit_sect_);
float user_frame_rate_ RTC_GUARDED_BY(crit_sect_);
float max_frame_rate_ RTC_GUARDED_BY(crit_sect_);
std::unique_ptr<FrameDropper> frame_dropper_ RTC_GUARDED_BY(crit_sect_);
int video_target_bitrate_ RTC_GUARDED_BY(crit_sect_);
float incoming_frame_rate_ RTC_GUARDED_BY(crit_sect_);
int64_t incoming_frame_times_[kFrameCountHistorySize] RTC_GUARDED_BY(
crit_sect_);

View File

@ -12,8 +12,6 @@
#include <algorithm>
#include "rtc_base/logging.h"
namespace webrtc {
namespace {
@ -52,15 +50,6 @@ FrameDropper::FrameDropper()
Reset();
}
FrameDropper::FrameDropper(float max_drop_duration_secs)
: key_frame_ratio_(kDefaultKeyFrameRatioAlpha),
delta_frame_size_avg_kbits_(kDefaultFrameSizeAlpha),
drop_ratio_(kDefaultDropRatioAlpha, kDefaultDropRatioValue),
enabled_(true),
max_drop_duration_secs_(max_drop_duration_secs) {
Reset();
}
void FrameDropper::Reset() {
key_frame_ratio_.Reset(kDefaultKeyFrameRatioAlpha);
key_frame_ratio_.Apply(1.0f, kDefaultKeyFrameRatioValue);
@ -94,8 +83,8 @@ void FrameDropper::Fill(size_t framesize_bytes, bool delta_frame) {
if (!delta_frame) {
key_frame_ratio_.Apply(1.0, 1.0);
// Do not spread if we are already doing it (or we risk dropping bits that
// need accumulation). Given we compute the key
// frame ratio and spread based on that, this should not normally happen.
// need accumulation). Given we compute the key frame ratio and spread
// based on that, this should not normally happen.
if (large_frame_accumulation_count_ == 0) {
if (key_frame_ratio_.filtered() > 1e-5 &&
1 / key_frame_ratio_.filtered() < large_frame_accumulation_spread_) {
@ -158,16 +147,15 @@ void FrameDropper::Leak(uint32_t input_framerate) {
void FrameDropper::UpdateRatio() {
if (accumulator_ > 1.3f * accumulator_max_) {
// Too far above accumulator max, react faster
// Too far above accumulator max, react faster.
drop_ratio_.UpdateBase(0.8f);
} else {
// Go back to normal reaction
// Go back to normal reaction.
drop_ratio_.UpdateBase(0.9f);
}
if (accumulator_ > accumulator_max_) {
// We are above accumulator max, and should ideally
// drop a frame. Increase the dropRatio and drop
// the frame later.
// We are above accumulator max, and should ideally drop a frame. Increase
// the drop_ratio_ and drop the frame later.
if (was_below_max_) {
drop_next_ = true;
}
@ -180,8 +168,7 @@ void FrameDropper::UpdateRatio() {
}
// This function signals when to drop frames to the caller. It makes use of the
// dropRatio
// to smooth out the drops over time.
// drop_ratio_ to smooth out the drops over time.
bool FrameDropper::DropFrame() {
if (!enabled_) {
return false;
@ -192,7 +179,7 @@ bool FrameDropper::DropFrame() {
}
if (drop_ratio_.filtered() >= 0.5f) { // Drops per keep
// limit is the number of frames we should drop between each kept frame
// Limit is the number of frames we should drop between each kept frame
// to keep our drop ratio. limit is positive in this case.
float denom = 1.0f - drop_ratio_.filtered();
if (denom < 1e-5) {
@ -221,7 +208,7 @@ bool FrameDropper::DropFrame() {
}
} else if (drop_ratio_.filtered() > 0.0f &&
drop_ratio_.filtered() < 0.5f) { // Keeps per drop
// limit is the number of frames we should keep between each drop
// Limit is the number of frames we should keep between each drop
// in order to keep the drop ratio. limit is negative in this case,
// and the drop_count_ is also negative.
float denom = drop_ratio_.filtered();

View File

@ -24,41 +24,36 @@ namespace webrtc {
class FrameDropper {
public:
FrameDropper();
explicit FrameDropper(float max_time_drops);
virtual ~FrameDropper() {}
// Resets the FrameDropper to its initial state.
// This means that the frameRateWeight is set to its
// default value as well.
virtual void Reset();
virtual void Enable(bool enable);
// Answers the question if it's time to drop a frame
// if we want to reach a given frame rate. Must be
// called for every frame.
// Answers the question if it's time to drop a frame if we want to reach a
// given frame rate. Must be called for every frame.
//
// Return value : True if we should drop the current frame
// Return value : True if we should drop the current frame.
virtual bool DropFrame();
// Updates the FrameDropper with the size of the latest encoded
// frame. The FrameDropper calculates a new drop ratio (can be
// seen as the probability to drop a frame) and updates its
// internal statistics.
// Updates the FrameDropper with the size of the latest encoded frame.
// The FrameDropper calculates a new drop ratio (can be seen as the
// probability to drop a frame) and updates its internal statistics.
//
// Input:
// - frameSizeBytes : The size of the latest frame
// returned from the encoder.
// - deltaFrame : True if the encoder returned
// a key frame.
virtual void Fill(size_t frameSizeBytes, bool deltaFrame);
// - framesize_bytes : The size of the latest frame returned
// from the encoder.
// - delta_frame : True if the encoder returned a key frame.
virtual void Fill(size_t framesize_bytes, bool delta_frame);
virtual void Leak(uint32_t inputFrameRate);
virtual void Leak(uint32_t input_framerate);
// Sets the target bit rate and the frame rate produced by
// the camera.
// Sets the target bit rate and the frame rate produced by the camera.
//
// Input:
// - bitRate : The target bit rate
virtual void SetRates(float bitRate, float incoming_frame_rate);
// - bitrate : The target bit rate.
virtual void SetRates(float bitrate, float incoming_frame_rate);
private:
void UpdateRatio();