Refactoring temporal layers implementation and adding VideoCodecMode for easier control of codec settings.

Review URL: https://webrtc-codereview.appspot.com/1105007

git-svn-id: http://webrtc.googlecode.com/svn/trunk@3528 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
stefan@webrtc.org
2013-02-18 14:40:18 +00:00
parent 3897255b63
commit eb91792cfd
20 changed files with 322 additions and 148 deletions

View File

@ -0,0 +1,58 @@
/*
* 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.
*/
#ifndef WEBRTC_MODULES_VIDEO_CODING_UTILITY_INCLUDE_EXP_FILTER_H_
#define WEBRTC_MODULES_VIDEO_CODING_UTILITY_INCLUDE_EXP_FILTER_H_
namespace webrtc
{
/**********************/
/* ExpFilter class */
/**********************/
class VCMExpFilter
{
public:
VCMExpFilter(float alpha, float max = -1.0) : _alpha(alpha), _filtered(-1.0), _max(max) {}
// Resets the filter to its initial state, and resets alpha to the given value
//
// Input:
// - alpha : the new value of the filter factor base.
void Reset(float alpha);
// Applies the filter with the given exponent on the provided sample
//
// Input:
// - exp : Exponent T in y(k) = alpha^T * y(k-1) + (1 - alpha^T) * x(k)
// - sample : x(k) in the above filter equation
float Apply(float exp, float sample);
// Return current filtered value: y(k)
//
// Return value : The current filter output
float Value() const;
// Change the filter factor base
//
// Input:
// - alpha : The new filter factor base.
void UpdateBase(float alpha);
private:
float _alpha; // Filter factor base
float _filtered; // Current filter output
const float _max;
}; // end of ExpFilter class
} // namespace webrtc
#endif // WEBRTC_MODULES_VIDEO_CODING_UTILITY_INCLUDE_EXP_FILTER_H_

View File

@ -0,0 +1,96 @@
/*
* 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.
*/
#ifndef WEBRTC_MODULES_VIDEO_CODING_UTILITY_INCLUDE_FRAME_DROPPER_H_
#define WEBRTC_MODULES_VIDEO_CODING_UTILITY_INCLUDE_FRAME_DROPPER_H_
#include "webrtc/modules/video_coding/utility/include/exp_filter.h"
#include "webrtc/typedefs.h"
namespace webrtc
{
// 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.
class FrameDropper
{
public:
FrameDropper();
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.
//
// 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(WebRtc_UWord32 frameSizeBytes, bool deltaFrame);
virtual void Leak(WebRtc_UWord32 inputFrameRate);
void UpdateNack(WebRtc_UWord32 nackBytes);
// 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);
// Return value : The current average frame rate produced
// if the DropFrame() function is used as
// instruction of when to drop frames.
virtual float ActualFrameRate(WebRtc_UWord32 inputFrameRate) const;
private:
void FillBucket(float inKbits, float outKbits);
void UpdateRatio();
void CapAccumulator();
VCMExpFilter _keyFrameSizeAvgKbits;
VCMExpFilter _keyFrameRatio;
float _keyFrameSpreadFrames;
WebRtc_Word32 _keyFrameCount;
float _accumulator;
float _accumulatorMax;
float _targetBitRate;
bool _dropNext;
VCMExpFilter _dropRatio;
WebRtc_Word32 _dropCount;
float _windowSize;
float _incoming_frame_rate;
bool _wasBelowMax;
bool _enabled;
bool _fastMode;
float _cap_buffer_size;
float _max_time_drops;
}; // end of VCMFrameDropper class
} // namespace webrtc
#endif // WEBRTC_MODULES_VIDEO_CODING_UTILITY_INCLUDE_FRAME_DROPPER_H_

View File

@ -0,0 +1,41 @@
/*
* 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.
*/
#ifndef WEBRTC_MODULES_VIDEO_CODING_UTILITY_INCLUDE_MOCK_MOCK_FRAME_DROPPER_H_
#define WEBRTC_MODULES_VIDEO_CODING_UTILITY_INCLUDE_MOCK_MOCK_FRAME_DROPPER_H_
#include <string>
#include "gmock/gmock.h"
#include "webrtc/modules/video_coding/utility/include/frame_dropper.h"
#include "webrtc/typedefs.h"
namespace webrtc {
class MockFrameDropper : public FrameDropper {
public:
MOCK_METHOD0(Reset,
void());
MOCK_METHOD1(Enable,
void(bool enable));
MOCK_METHOD0(DropFrame,
bool());
MOCK_METHOD2(Fill,
void(WebRtc_UWord32 frameSizeBytes, bool deltaFrame));
MOCK_METHOD1(Leak,
void(WebRtc_UWord32 inputFrameRate));
MOCK_METHOD2(SetRates,
void(float bitRate, float incoming_frame_rate));
MOCK_CONST_METHOD1(ActualFrameRate,
float(WebRtc_UWord32 inputFrameRate));
};
} // namespace webrtc
#endif // WEBRTC_MODULES_VIDEO_CODING_UTILITY_INCLUDE_MOCK_MOCK_FRAME_DROPPER_H_