Bug 1243607: make webrtc bitrate prefs take precedence over automatic bitrate selection r=pkerr

--HG--
extra : commitid : HtWKNcs82ul
This commit is contained in:
Randell Jesup 2016-01-27 21:55:42 -05:00
Родитель 686f68bed4
Коммит fd24a3b3e7
3 изменённых файлов: 59 добавлений и 26 удалений

Просмотреть файл

@ -90,9 +90,9 @@ WebrtcVideoConduit::WebrtcVideoConduit():
mNumReceivingStreams(1),
mVideoLatencyTestEnable(false),
mVideoLatencyAvg(0),
mMinBitrate(200),
mStartBitrate(300),
mMaxBitrate(2000),
mMinBitrate(0),
mStartBitrate(0),
mMaxBitrate(0),
mCodecMode(webrtc::kRealtimeVideo)
{}
@ -286,6 +286,15 @@ WebrtcVideoConduit::InitMain()
if (temp >= 0) {
mMaxBitrate = temp;
}
if (mMinBitrate != 0 && mMinBitrate < webrtc::kViEMinCodecBitrate) {
mMinBitrate = webrtc::kViEMinCodecBitrate;
}
if (mStartBitrate < mMinBitrate) {
mStartBitrate = mMinBitrate;
}
if (mStartBitrate > mMaxBitrate) {
mStartBitrate = mMaxBitrate;
}
bool use_loadmanager = false;
(void) NS_WARN_IF(NS_FAILED(branch->GetBoolPref("media.navigator.load_adapt", &use_loadmanager)));
if (use_loadmanager) {
@ -961,6 +970,7 @@ WebrtcVideoConduit::ConfigureRecvMediaCodecs(
struct ResolutionAndBitrateLimits {
uint32_t resolution_in_mb;
uint16_t min_bitrate;
uint16_t start_bitrate;
uint16_t max_bitrate;
};
@ -974,19 +984,19 @@ struct ResolutionAndBitrateLimits {
// XXX Populate this based on a pref (which we should consider sorting because
// people won't assume they need to).
static ResolutionAndBitrateLimits kResolutionAndBitrateLimits[] = {
{MB_OF(1920, 1200), 1500, 10000}, // >HD (3K, 4K, etc)
{MB_OF(1280, 720), 1200, 5000}, // HD ~1080-1200
{MB_OF(800, 480), 600, 2500}, // HD ~720
{std::max(MB_OF(400, 240), MB_OF(352, 288)), 200, 1300}, // VGA, WVGA
{MB_OF(176, 144), 100, 500}, // WQVGA, CIF
{0 , 40, 250} // QCIF and below
{MB_OF(1920, 1200), 1500, 2000, 10000}, // >HD (3K, 4K, etc)
{MB_OF(1280, 720), 1200, 1500, 5000}, // HD ~1080-1200
{MB_OF(800, 480), 600, 800, 2500}, // HD ~720
{std::max(MB_OF(400, 240), MB_OF(352, 288)), 200, 300, 1300}, // VGA, WVGA
{MB_OF(176, 144), 100, 150, 500}, // WQVGA, CIF
{0 , 40, 80, 250} // QCIF and below
};
static void
SelectBandwidth(webrtc::VideoCodec& vie_codec,
unsigned short width,
unsigned short height,
mozilla::Atomic<int32_t, mozilla::Relaxed>& aLastFramerateTenths)
void
WebrtcVideoConduit::SelectBandwidth(webrtc::VideoCodec& vie_codec,
unsigned short width,
unsigned short height,
mozilla::Atomic<int32_t, mozilla::Relaxed>& aLastFramerateTenths)
{
// max bandwidth should be proportional (not linearly!) to resolution, and
// proportional (perhaps linearly, or close) to current frame rate.
@ -999,6 +1009,7 @@ SelectBandwidth(webrtc::VideoCodec& vie_codec,
for (ResolutionAndBitrateLimits resAndLimits : kResolutionAndBitrateLimits) {
if (fs > resAndLimits.resolution_in_mb) {
vie_codec.minBitrate = resAndLimits.min_bitrate;
vie_codec.startBitrate = resAndLimits.start_bitrate;
vie_codec.maxBitrate = resAndLimits.max_bitrate;
break;
}
@ -1010,17 +1021,28 @@ SelectBandwidth(webrtc::VideoCodec& vie_codec,
// Now linear reduction/increase based on fps (max 60fps i.e. doubling)
if (framerate >= 10) {
vie_codec.minBitrate = vie_codec.minBitrate * (framerate/30);
vie_codec.startBitrate = vie_codec.startBitrate * (framerate/30);
vie_codec.maxBitrate = vie_codec.maxBitrate * (framerate/30);
} else {
// At low framerates, don't reduce bandwidth as much - cut slope to 1/2.
// Mostly this would be ultra-low-light situations/mobile or screensharing.
vie_codec.minBitrate = vie_codec.minBitrate * ((10-(framerate/2))/30);
vie_codec.startBitrate = vie_codec.startBitrate * ((10-(framerate/2))/30);
vie_codec.maxBitrate = vie_codec.maxBitrate * ((10-(framerate/2))/30);
}
if (mMinBitrate && mMinBitrate > vie_codec.minBitrate) {
vie_codec.minBitrate = mMinBitrate;
}
// If we try to set a minimum bitrate that is too low, ViE will reject it.
vie_codec.minBitrate = std::max((unsigned int) webrtc::kViEMinCodecBitrate,
vie_codec.minBitrate);
if (mStartBitrate && mStartBitrate > vie_codec.startBitrate) {
vie_codec.startBitrate = mStartBitrate;
}
if (mMaxBitrate && mMaxBitrate > vie_codec.maxBitrate) {
vie_codec.maxBitrate = mMaxBitrate;
}
}
static void ConstrainPreservingAspectRatioExact(uint32_t max_fs,
@ -1781,9 +1803,12 @@ WebrtcVideoConduit::CodecConfigToWebRTCCodec(const VideoCodecConfig* codecInfo,
cinst.maxFramerate = DEFAULT_VIDEO_MAX_FRAMERATE;
}
cinst.minBitrate = mMinBitrate;
cinst.startBitrate = mStartBitrate;
cinst.maxBitrate = mMaxBitrate;
// Defaults if rates aren't forced by pref. Typically defaults are
// overridden on the first video frame.
cinst.minBitrate = mMinBitrate ? mMinBitrate : 200;
cinst.startBitrate = mStartBitrate ? mStartBitrate : 300;
cinst.targetBitrate = cinst.startBitrate;
cinst.maxBitrate = mMaxBitrate ? mMaxBitrate : 2000;
if (cinst.codecType == webrtc::kVideoCodecH264)
{

Просмотреть файл

@ -138,6 +138,17 @@ public:
virtual MediaConduitErrorCode SetReceiverTransport(RefPtr<TransportInterface> aTransport) override;
/**
* Function to set the encoding bitrate limits based on incoming frame size and rate
* @param vie_codec: codec config structure to modify
* @param width, height: dimensions of the frame
* @param aLastFramerateTenths: holds the current input framerate
*/
void SelectBandwidth(webrtc::VideoCodec& vie_codec,
unsigned short width,
unsigned short height,
mozilla::Atomic<int32_t, mozilla::Relaxed>& aLastFramerateTenths);
/**
* Function to select and change the encoding resolution based on incoming frame size
* and current available bandwidth.

Просмотреть файл

@ -394,11 +394,6 @@ pref("media.navigator.video.h264.max_mbps", 11880); // CIF@30fps
pref("media.peerconnection.video.h264_enabled", false);
pref("media.peerconnection.video.vp9_enabled", false);
pref("media.getusermedia.aec", 4);
// Gonk typically captures at QVGA, and so min resolution is QQVGA or
// 160x120; 100Kbps is plenty for that.
pref("media.peerconnection.video.min_bitrate", 100);
pref("media.peerconnection.video.start_bitrate", 220);
pref("media.peerconnection.video.max_bitrate", 1000);
#else
pref("media.navigator.video.default_width",0); // adaptive default
pref("media.navigator.video.default_height",0); // adaptive default
@ -412,12 +407,14 @@ pref("media.navigator.video.h264.max_mbps", 0);
pref("media.peerconnection.video.h264_enabled", false);
pref("media.getusermedia.aec", 1);
pref("media.getusermedia.browser.enabled", true);
#endif
// Gonk typically captures at QVGA, and so min resolution is QQVGA or
// 160x120; 100Kbps is plenty for that.
// Desktop is typically VGA capture or more; and qm_select will not drop resolution
// below 1/2 in each dimension (or so), so QVGA (320x200) is the lowest here usually.
pref("media.peerconnection.video.min_bitrate", 200);
pref("media.peerconnection.video.start_bitrate", 300);
pref("media.peerconnection.video.max_bitrate", 2000);
#endif
pref("media.peerconnection.video.min_bitrate", 0);
pref("media.peerconnection.video.start_bitrate", 0);
pref("media.peerconnection.video.max_bitrate", 0);
pref("media.navigator.audio.fake_frequency", 1000);
pref("media.navigator.permission.disabled", false);
pref("media.peerconnection.simulcast", true);