Remove all old suspension logic.
I'm also removing media_optimization_unittest.cc, since it only tested the suspension logic and nothing else. R=pbos@webrtc.org Review URL: https://codereview.webrtc.org/2119503002 . Cr-Commit-Position: refs/heads/master@{#13355}
This commit is contained in:
@ -472,15 +472,6 @@ class VideoCodingModule : public Module {
|
||||
// delayed by at least desired_delay_ms.
|
||||
virtual int SetMinReceiverDelay(int desired_delay_ms) = 0;
|
||||
|
||||
// Lets the sender suspend video when the rate drops below
|
||||
// |threshold_bps|, and turns back on when the rate goes back up above
|
||||
// |threshold_bps| + |window_bps|.
|
||||
virtual void SuspendBelowMinBitrate() = 0;
|
||||
|
||||
// Returns true if SuspendBelowMinBitrate is engaged and the video has been
|
||||
// suspended due to bandwidth limitations; otherwise false.
|
||||
virtual bool VideoSuspended() const = 0;
|
||||
|
||||
virtual void RegisterPostEncodeImageCallback(
|
||||
EncodedImageCallback* post_encode_callback) = 0;
|
||||
// Releases pending decode calls, permitting faster thread shutdown.
|
||||
|
||||
@ -46,11 +46,7 @@ MediaOptimization::MediaOptimization(Clock* clock)
|
||||
encoded_frame_samples_(),
|
||||
avg_sent_bit_rate_bps_(0),
|
||||
avg_sent_framerate_(0),
|
||||
num_layers_(0),
|
||||
suspension_enabled_(false),
|
||||
video_suspended_(false),
|
||||
suspension_threshold_bps_(0),
|
||||
suspension_window_bps_(0) {
|
||||
num_layers_(0) {
|
||||
memset(send_statistics_, 0, sizeof(send_statistics_));
|
||||
memset(incoming_frame_times_, -1, sizeof(incoming_frame_times_));
|
||||
}
|
||||
@ -136,8 +132,6 @@ uint32_t MediaOptimization::SetTargetRates(uint32_t target_bitrate,
|
||||
static_cast<float>(video_target_bitrate_) / 1000.0f;
|
||||
frame_dropper_->SetRates(target_video_bitrate_kbps, incoming_frame_rate_);
|
||||
|
||||
CheckSuspendConditions();
|
||||
|
||||
return video_target_bitrate_;
|
||||
}
|
||||
|
||||
@ -203,29 +197,11 @@ void MediaOptimization::EnableFrameDropper(bool enable) {
|
||||
frame_dropper_->Enable(enable);
|
||||
}
|
||||
|
||||
void MediaOptimization::SuspendBelowMinBitrate(int threshold_bps,
|
||||
int window_bps) {
|
||||
CriticalSectionScoped lock(crit_sect_.get());
|
||||
assert(threshold_bps > 0 && window_bps >= 0);
|
||||
suspension_threshold_bps_ = threshold_bps;
|
||||
suspension_window_bps_ = window_bps;
|
||||
suspension_enabled_ = true;
|
||||
video_suspended_ = false;
|
||||
}
|
||||
|
||||
bool MediaOptimization::IsVideoSuspended() const {
|
||||
CriticalSectionScoped lock(crit_sect_.get());
|
||||
return video_suspended_;
|
||||
}
|
||||
|
||||
bool MediaOptimization::DropFrame() {
|
||||
CriticalSectionScoped lock(crit_sect_.get());
|
||||
UpdateIncomingFrameRate();
|
||||
// Leak appropriate number of bytes.
|
||||
frame_dropper_->Leak((uint32_t)(InputFrameRateInternal() + 0.5f));
|
||||
if (video_suspended_) {
|
||||
return true; // Drop all frames when muted.
|
||||
}
|
||||
return frame_dropper_->DropFrame();
|
||||
}
|
||||
|
||||
@ -311,26 +287,5 @@ void MediaOptimization::ProcessIncomingFrameRate(int64_t now) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MediaOptimization::CheckSuspendConditions() {
|
||||
// Check conditions for SuspendBelowMinBitrate. |video_target_bitrate_| is in
|
||||
// bps.
|
||||
if (suspension_enabled_) {
|
||||
if (!video_suspended_) {
|
||||
// Check if we just went below the threshold.
|
||||
if (video_target_bitrate_ < suspension_threshold_bps_) {
|
||||
video_suspended_ = true;
|
||||
}
|
||||
} else {
|
||||
// Video is already suspended. Check if we just went over the threshold
|
||||
// with a margin.
|
||||
if (video_target_bitrate_ >
|
||||
suspension_threshold_bps_ + suspension_window_bps_) {
|
||||
video_suspended_ = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace media_optimization
|
||||
} // namespace webrtc
|
||||
|
||||
@ -59,13 +59,6 @@ class MediaOptimization {
|
||||
int64_t round_trip_time_ms);
|
||||
|
||||
void EnableFrameDropper(bool enable);
|
||||
|
||||
// Lets the sender suspend video when the rate drops below
|
||||
// |threshold_bps|, and turns back on when the rate goes back up above
|
||||
// |threshold_bps| + |window_bps|.
|
||||
void SuspendBelowMinBitrate(int threshold_bps, int window_bps);
|
||||
bool IsVideoSuspended() const;
|
||||
|
||||
bool DropFrame();
|
||||
|
||||
// Informs Media Optimization of encoded output.
|
||||
@ -133,10 +126,6 @@ class MediaOptimization {
|
||||
uint32_t avg_sent_bit_rate_bps_ GUARDED_BY(crit_sect_);
|
||||
uint32_t avg_sent_framerate_ GUARDED_BY(crit_sect_);
|
||||
int num_layers_ GUARDED_BY(crit_sect_);
|
||||
bool suspension_enabled_ GUARDED_BY(crit_sect_);
|
||||
bool video_suspended_ GUARDED_BY(crit_sect_);
|
||||
int suspension_threshold_bps_ GUARDED_BY(crit_sect_);
|
||||
int suspension_window_bps_ GUARDED_BY(crit_sect_);
|
||||
};
|
||||
} // namespace media_optimization
|
||||
} // namespace webrtc
|
||||
|
||||
@ -1,111 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include "webrtc/modules/video_coding/media_optimization.h"
|
||||
#include "webrtc/system_wrappers/include/clock.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace media_optimization {
|
||||
|
||||
class TestMediaOptimization : public ::testing::Test {
|
||||
protected:
|
||||
enum {
|
||||
kSampleRate = 90000 // RTP timestamps per second.
|
||||
};
|
||||
|
||||
// Note: simulated clock starts at 1 seconds, since parts of webrtc use 0 as
|
||||
// a special case (e.g. frame rate in media optimization).
|
||||
TestMediaOptimization()
|
||||
: clock_(1000),
|
||||
media_opt_(&clock_),
|
||||
frame_time_ms_(33),
|
||||
next_timestamp_(0) {}
|
||||
|
||||
// This method mimics what happens in VideoSender::AddVideoFrame.
|
||||
void AddFrameAndAdvanceTime(uint32_t bitrate_bps, bool expect_frame_drop) {
|
||||
bool frame_dropped = media_opt_.DropFrame();
|
||||
EXPECT_EQ(expect_frame_drop, frame_dropped);
|
||||
if (!frame_dropped) {
|
||||
size_t bytes_per_frame = bitrate_bps * frame_time_ms_ / (8 * 1000);
|
||||
EncodedImage encoded_image;
|
||||
encoded_image._length = bytes_per_frame;
|
||||
encoded_image._timeStamp = next_timestamp_;
|
||||
encoded_image._frameType = kVideoFrameKey;
|
||||
ASSERT_EQ(VCM_OK, media_opt_.UpdateWithEncodedData(encoded_image));
|
||||
}
|
||||
next_timestamp_ += frame_time_ms_ * kSampleRate / 1000;
|
||||
clock_.AdvanceTimeMilliseconds(frame_time_ms_);
|
||||
}
|
||||
|
||||
SimulatedClock clock_;
|
||||
MediaOptimization media_opt_;
|
||||
int frame_time_ms_;
|
||||
uint32_t next_timestamp_;
|
||||
};
|
||||
|
||||
TEST_F(TestMediaOptimization, VerifyMuting) {
|
||||
// Enable video suspension with these limits.
|
||||
// Suspend the video when the rate is below 50 kbps and resume when it gets
|
||||
// above 50 + 10 kbps again.
|
||||
const uint32_t kThresholdBps = 50000;
|
||||
const uint32_t kWindowBps = 10000;
|
||||
media_opt_.SuspendBelowMinBitrate(kThresholdBps, kWindowBps);
|
||||
|
||||
// The video should not be suspended from the start.
|
||||
EXPECT_FALSE(media_opt_.IsVideoSuspended());
|
||||
|
||||
uint32_t target_bitrate_kbps = 100;
|
||||
media_opt_.SetTargetRates(target_bitrate_kbps * 1000,
|
||||
0, // Lossrate.
|
||||
100); // RTT in ms.
|
||||
media_opt_.EnableFrameDropper(true);
|
||||
for (int time = 0; time < 2000; time += frame_time_ms_) {
|
||||
ASSERT_NO_FATAL_FAILURE(AddFrameAndAdvanceTime(target_bitrate_kbps, false));
|
||||
}
|
||||
|
||||
// Set the target rate below the limit for muting.
|
||||
media_opt_.SetTargetRates(kThresholdBps - 1000,
|
||||
0, // Lossrate.
|
||||
100); // RTT in ms.
|
||||
// Expect the muter to engage immediately and stay muted.
|
||||
// Test during 2 seconds.
|
||||
for (int time = 0; time < 2000; time += frame_time_ms_) {
|
||||
EXPECT_TRUE(media_opt_.IsVideoSuspended());
|
||||
ASSERT_NO_FATAL_FAILURE(AddFrameAndAdvanceTime(target_bitrate_kbps, true));
|
||||
}
|
||||
|
||||
// Set the target above the limit for muting, but not above the
|
||||
// limit + window.
|
||||
media_opt_.SetTargetRates(kThresholdBps + 1000,
|
||||
0, // Lossrate.
|
||||
100); // RTT in ms.
|
||||
// Expect the muter to stay muted.
|
||||
// Test during 2 seconds.
|
||||
for (int time = 0; time < 2000; time += frame_time_ms_) {
|
||||
EXPECT_TRUE(media_opt_.IsVideoSuspended());
|
||||
ASSERT_NO_FATAL_FAILURE(AddFrameAndAdvanceTime(target_bitrate_kbps, true));
|
||||
}
|
||||
|
||||
// Set the target above limit + window.
|
||||
media_opt_.SetTargetRates(kThresholdBps + kWindowBps + 1000,
|
||||
0, // Lossrate.
|
||||
100); // RTT in ms.
|
||||
// Expect the muter to disengage immediately.
|
||||
// Test during 2 seconds.
|
||||
for (int time = 0; time < 2000; time += frame_time_ms_) {
|
||||
EXPECT_FALSE(media_opt_.IsVideoSuspended());
|
||||
ASSERT_NO_FATAL_FAILURE(
|
||||
AddFrameAndAdvanceTime((kThresholdBps + kWindowBps) / 1000, false));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace media_optimization
|
||||
} // namespace webrtc
|
||||
@ -152,12 +152,6 @@ class VideoCodingModuleImpl : public VideoCodingModule {
|
||||
return sender_.EnableFrameDropper(enable);
|
||||
}
|
||||
|
||||
void SuspendBelowMinBitrate() override {
|
||||
return sender_.SuspendBelowMinBitrate();
|
||||
}
|
||||
|
||||
bool VideoSuspended() const override { return sender_.VideoSuspended(); }
|
||||
|
||||
int32_t RegisterReceiveCodec(const VideoCodec* receiveCodec,
|
||||
int32_t numberOfCores,
|
||||
bool requireKeyFrame) override {
|
||||
|
||||
@ -89,9 +89,6 @@ class VideoSender : public Module {
|
||||
int32_t IntraFrameRequest(size_t stream_index);
|
||||
int32_t EnableFrameDropper(bool enable);
|
||||
|
||||
void SuspendBelowMinBitrate();
|
||||
bool VideoSuspended() const;
|
||||
|
||||
int64_t TimeUntilNextProcess() override;
|
||||
void Process() override;
|
||||
|
||||
|
||||
@ -364,23 +364,5 @@ int32_t VideoSender::EnableFrameDropper(bool enable) {
|
||||
_mediaOpt.EnableFrameDropper(enable);
|
||||
return VCM_OK;
|
||||
}
|
||||
|
||||
void VideoSender::SuspendBelowMinBitrate() {
|
||||
RTC_DCHECK(main_thread_.CalledOnValidThread());
|
||||
int threshold_bps;
|
||||
if (current_codec_.numberOfSimulcastStreams == 0) {
|
||||
threshold_bps = current_codec_.minBitrate * 1000;
|
||||
} else {
|
||||
threshold_bps = current_codec_.simulcastStream[0].minBitrate * 1000;
|
||||
}
|
||||
// Set the hysteresis window to be at 10% of the threshold, but at least
|
||||
// 10 kbps.
|
||||
int window_bps = std::max(threshold_bps / 10, 10000);
|
||||
_mediaOpt.SuspendBelowMinBitrate(threshold_bps, window_bps);
|
||||
}
|
||||
|
||||
bool VideoSender::VideoSuspended() const {
|
||||
return _mediaOpt.IsVideoSuspended();
|
||||
}
|
||||
} // namespace vcm
|
||||
} // namespace webrtc
|
||||
|
||||
Reference in New Issue
Block a user