Modified media_opt and qm_select to allow for robustness settings

based on the content metrics. Re-organized the class structure in qm_select
into a resolution class and robustness settings class, both derived from
a main (qm/content analysis) class.
Review URL: http://webrtc-codereview.appspot.com/55006

git-svn-id: http://webrtc.googlecode.com/svn/trunk@188 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
marpan@google.com
2011-07-12 17:12:57 +00:00
parent 6bed064e2f
commit 86548c62e9
7 changed files with 425 additions and 311 deletions

View File

@@ -13,25 +13,19 @@
#include "typedefs.h"
#include "common_types.h"
/************************/
/* Quality Modes */
/**********************/
/******************************************************/
/* Quality Modes: Resolution and Robustness settings */
/******************************************************/
namespace webrtc
{
struct VideoContentMetrics;
struct VCMQualityMode
struct VCMResolutionScale
{
VCMQualityMode():spatialWidthFact(1), spatialHeightFact(1),
VCMResolutionScale(): spatialWidthFact(1), spatialHeightFact(1),
temporalFact(1){}
void Reset()
{
spatialWidthFact = 1;
spatialHeightFact = 1;
temporalFact = 1;
}
WebRtc_UWord16 spatialWidthFact;
WebRtc_UWord16 spatialHeightFact;
@@ -59,53 +53,20 @@ struct VCMContFeature
VCMMagValues level;
};
class VCMQmSelect
// QmMethod class: main class for resolution and robustness settings
class VCMQmMethod
{
public:
VCMQmSelect();
~VCMQmSelect();
VCMQmMethod();
~VCMQmMethod();
// Initialize:
WebRtc_Word32 Initialize(float bitRate, float userFrameRate,
WebRtc_UWord32 width, WebRtc_UWord32 height);
// Allow the user to set preferences: favor frame rate/resolution
WebRtc_Word32 SetPreferences(WebRtc_Word8 resolPref);
// Extract ST (spatio-temporal) QM behavior and make decision
// Inputs: qm: Reference to the quality modes pointer
WebRtc_Word32 SelectQuality(VCMQualityMode** qm);
// Update QM with actual bit rate
// (size of the latest encoded frame) and frame type.
void UpdateEncodedSize(WebRtc_Word64 encodedSize,
FrameType encodedFrameType);
// Update QM with new bit/frame/loss rates from SetTargetRates
void UpdateRates(float targetBitRate, float avgSentRate,
float incomingFrameRate, WebRtc_UWord8 packetLoss);
// Update QM with the content metrics
void UpdateContent(const VideoContentMetrics* contentMetrics);
// Adjust FEC rate based on content
WebRtc_UWord8 AdjustFecFactor(WebRtc_UWord8 codeRateDelta, float totalRate,
float frameRate, WebRtc_UWord16 rttTime,
WebRtc_UWord8 packetLoss);
// Select 1x2,2x2,2x2 spatial sampling mode
WebRtc_Word32 SelectSpatialDirectionMode(float transRate);
// Reset values prior to QMSelect
// Reset values
void ResetQM();
virtual void Reset() = 0;
// Reset rate quantities and counter values after every QMSelect call
void ResetRates();
// Reset all
void Reset();
private:
// Update with the content metrics
void UpdateContent(const VideoContentMetrics* contentMetrics);
// Compute spatial texture magnitude and level
void Spatial();
@@ -119,36 +80,84 @@ private:
// Compute coherence magnitude and level
void Coherence();
// Set the max rate for QM selection
WebRtc_Word32 SetMaxRateForQM(WebRtc_UWord32 width, WebRtc_UWord32 height);
// Get the imageType (CIF, VGA, HD, etc) for the system width/height
WebRtc_Word8 GetImageType(WebRtc_UWord32 width, WebRtc_UWord32 height);
// Content Data
const VideoContentMetrics* _contentMetrics;
const VideoContentMetrics* _contentMetrics;
// Encoder rate control parameters, network parameters
// Encoder and native frame sizes, frame rate, aspect ratio, imageType
WebRtc_UWord32 _width;
WebRtc_UWord32 _height;
WebRtc_UWord32 _nativeWidth;
WebRtc_UWord32 _nativeHeight;
WebRtc_UWord32 _nativeFrameRate;
float _aspectRatio;
// Image type for the current encoder system size.
WebRtc_UWord8 _imageType;
// Content L/M/H values. stationary flag
VCMContFeature _motion;
VCMContFeature _spatial;
VCMContFeature _coherence;
bool _stationaryMotion;
bool _init;
};
// Resolution settings class
class VCMQmResolution : public VCMQmMethod
{
public:
VCMQmResolution();
~VCMQmResolution();
// Reset all quantities
virtual void Reset();
// Reset rate quantities and counter values after every Select Quality call
void ResetRates();
// Initialize rate control quantities after re-init of encoder.
WebRtc_Word32 Initialize(float bitRate, float userFrameRate,
WebRtc_UWord32 width, WebRtc_UWord32 height);
// Update QM with actual bit rate (size of the latest encoded frame)
// and frame type, after every encoded frame.
void UpdateEncodedSize(WebRtc_Word64 encodedSize,
FrameType encodedFrameType);
// Update QM with new bit/frame/loss rates every ~1 sec from SetTargetRates
void UpdateRates(float targetBitRate, float avgSentRate,
float incomingFrameRate, WebRtc_UWord8 packetLoss);
// Extract ST (spatio-temporal) QM behavior and make decision
// Inputs: qm: Reference to the quality modes pointer
// Output: the spatial and/or temporal scale change
WebRtc_Word32 SelectResolution(VCMResolutionScale** qm);
// Select 1x2,2x2,2x2 spatial sampling mode
WebRtc_Word32 SelectSpatialDirectionMode(float transRate);
private:
// Encoder rate control parameter
float _targetBitRate;
float _userFrameRate;
float _incomingFrameRate;
float _perFrameBandwidth;
float _bufferLevel;
// Data accumulated every ~1sec from MediaOpt
float _sumTargetRate;
float _sumIncomingFrameRate;
float _sumSeqRateMM;
float _sumFrameRateMM;
float _sumPacketLoss;
float _prevTotalRate;
WebRtc_UWord16 _prevRttTime;
WebRtc_UWord8 _prevPacketLoss;
WebRtc_Word64 _sumEncodedBytes;
// Encoder and native frame sizes
WebRtc_UWord32 _width;
WebRtc_UWord32 _height;
WebRtc_UWord32 _nativeWidth;
WebRtc_UWord32 _nativeHeight;
// Resolution state parameters
WebRtc_UWord8 _stateDecFactorSpatial;
WebRtc_UWord32 _nativeFrameRate;
WebRtc_UWord8 _stateDecFactorTemp;
// Counters
@@ -157,24 +166,36 @@ private:
WebRtc_UWord32 _updateRateCnt;
WebRtc_UWord32 _lowBufferCnt;
// Content L/M/H values
VCMContFeature _motion;
VCMContFeature _spatial;
VCMContFeature _coherence;
bool _stationaryMotion;
VCMResolutionScale* _qm;
};
// Aspect ratio
float _aspectRatio;
// Robustness settings class
// Max rate to saturate the transitionalRate
WebRtc_UWord32 _maxRateQM;
WebRtc_UWord8 _imageType;
class VCMQmRobustness : public VCMQmMethod
{
public:
VCMQmRobustness();
~VCMQmRobustness();
// User preference for resolution or qmax change
WebRtc_UWord8 _userResolutionPref;
bool _init;
VCMQualityMode* _qm;
virtual void Reset();
// Adjust FEC rate based on content: every ~1 sec from SetTargetRates
WebRtc_UWord8 AdjustFecFactor(WebRtc_UWord8 codeRateDelta, float totalRate,
float frameRate, WebRtc_UWord32 rttTime,
WebRtc_UWord8 packetLoss);
// Set the UEP protection on/off
bool SetUepProtection(WebRtc_UWord8 codeRateDelta, float totalRate,
WebRtc_UWord8 packetLoss, bool frameType);
private:
// Previous state of network parameters
float _prevTotalRate;
WebRtc_UWord32 _prevRttTime;
WebRtc_UWord8 _prevPacketLoss;
// Previous FEC rate
WebRtc_UWord8 _prevCodeRateDelta;
};
} // namespace webrtc