2011-07-07 08:21:25 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2011 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2015-11-18 23:04:10 +01:00
|
|
|
#ifndef WEBRTC_MODULES_VIDEO_CODING_UTILITY_FRAME_DROPPER_H_
|
|
|
|
|
#define WEBRTC_MODULES_VIDEO_CODING_UTILITY_FRAME_DROPPER_H_
|
2011-07-07 08:21:25 +00:00
|
|
|
|
Use size_t more consistently for packet/payload lengths.
See design doc at https://docs.google.com/a/chromium.org/document/d/1I6nmE9D_BmCY-IoV6MDPY2V6WYpEI-dg2apWXTfZyUI/edit?usp=sharing for more information.
This CL was reviewed and approved in pieces in the following CLs:
https://webrtc-codereview.appspot.com/24209004/
https://webrtc-codereview.appspot.com/24229004/
https://webrtc-codereview.appspot.com/24259004/
https://webrtc-codereview.appspot.com/25109004/
https://webrtc-codereview.appspot.com/26099004/
https://webrtc-codereview.appspot.com/27069004/
https://webrtc-codereview.appspot.com/27969004/
https://webrtc-codereview.appspot.com/27989004/
https://webrtc-codereview.appspot.com/29009004/
https://webrtc-codereview.appspot.com/30929004/
https://webrtc-codereview.appspot.com/30939004/
https://webrtc-codereview.appspot.com/31999004/
Committing as TBR to the original reviewers.
BUG=chromium:81439
TEST=none
TBR=pthatcher,henrik.lundin,tina.legrand,stefan,tkchin,glaznev,kjellander,perkj,mflodman,henrika,asapersson,niklas.enbom
Review URL: https://webrtc-codereview.appspot.com/23129004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7726 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-11-20 22:28:14 +00:00
|
|
|
#include <cstddef>
|
|
|
|
|
|
2017-07-06 19:44:34 +02:00
|
|
|
#include "webrtc/rtc_base/numerics/exp_filter.h"
|
2013-02-18 14:40:18 +00:00
|
|
|
#include "webrtc/typedefs.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-11-18 23:04:10 +01:00
|
|
|
namespace webrtc {
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
// The Frame Dropper implements a variant of the leaky bucket algorithm
|
|
|
|
|
// for keeping track of when to drop frames to avoid bit rate
|
|
|
|
|
// over use when the encoder can't keep its bit rate.
|
2015-11-18 23:04:10 +01:00
|
|
|
class FrameDropper {
|
|
|
|
|
public:
|
2015-12-21 08:23:20 -08:00
|
|
|
FrameDropper();
|
|
|
|
|
explicit FrameDropper(float max_time_drops);
|
|
|
|
|
virtual ~FrameDropper() {}
|
2013-02-18 14:40:18 +00:00
|
|
|
|
2015-12-21 08:23:20 -08:00
|
|
|
// Resets the FrameDropper to its initial state.
|
|
|
|
|
// This means that the frameRateWeight is set to its
|
|
|
|
|
// default value as well.
|
|
|
|
|
virtual void Reset();
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-12-21 08:23:20 -08:00
|
|
|
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.
|
|
|
|
|
//
|
|
|
|
|
// 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.
|
|
|
|
|
//
|
|
|
|
|
// 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);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-12-21 08:23:20 -08:00
|
|
|
virtual void Leak(uint32_t inputFrameRate);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-12-21 08:23:20 -08:00
|
|
|
// 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);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-11-18 23:04:10 +01:00
|
|
|
private:
|
2015-12-21 08:23:20 -08:00
|
|
|
void UpdateRatio();
|
|
|
|
|
void CapAccumulator();
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-03-06 23:22:33 -08:00
|
|
|
rtc::ExpFilter key_frame_ratio_;
|
|
|
|
|
rtc::ExpFilter delta_frame_size_avg_kbits_;
|
|
|
|
|
|
|
|
|
|
// Key frames and large delta frames are not immediately accumulated in the
|
|
|
|
|
// bucket since they can immediately overflow the bucket leading to large
|
|
|
|
|
// drops on the following packets that may be much smaller. Instead these
|
|
|
|
|
// large frames are accumulated over several frames when the bucket leaks.
|
|
|
|
|
|
|
|
|
|
// |large_frame_accumulation_spread_| represents the number of frames over
|
|
|
|
|
// which a large frame is accumulated.
|
|
|
|
|
float large_frame_accumulation_spread_;
|
|
|
|
|
// |large_frame_accumulation_count_| represents the number of frames left
|
|
|
|
|
// to finish accumulating a large frame.
|
|
|
|
|
int large_frame_accumulation_count_;
|
|
|
|
|
// |large_frame_accumulation_chunk_size_| represents the size of a single
|
|
|
|
|
// chunk for large frame accumulation.
|
|
|
|
|
float large_frame_accumulation_chunk_size_;
|
|
|
|
|
|
|
|
|
|
float accumulator_;
|
|
|
|
|
float accumulator_max_;
|
|
|
|
|
float target_bitrate_;
|
|
|
|
|
bool drop_next_;
|
|
|
|
|
rtc::ExpFilter drop_ratio_;
|
|
|
|
|
int drop_count_;
|
|
|
|
|
float incoming_frame_rate_;
|
|
|
|
|
bool was_below_max_;
|
|
|
|
|
bool enabled_;
|
|
|
|
|
const float max_drop_duration_secs_;
|
|
|
|
|
};
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-07-03 15:12:26 +00:00
|
|
|
} // namespace webrtc
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-11-18 23:04:10 +01:00
|
|
|
#endif // WEBRTC_MODULES_VIDEO_CODING_UTILITY_FRAME_DROPPER_H_
|