Break FrameConfig out of Vp8TemporalLayers
FrameConfig is not specific to temporal layers. Anything that can control referenced/updated buffers could potentially use it. Bug: webrtc:10259 Change-Id: I04ed177ee884693798c3b69e35fd4255ce1e9062 Reviewed-on: https://webrtc-review.googlesource.com/c/120355 Reviewed-by: Erik Språng <sprang@webrtc.org> Commit-Queue: Elad Alon <eladalon@webrtc.org> Cr-Commit-Position: refs/heads/master@{#26448}
This commit is contained in:
@ -22,11 +22,20 @@
|
||||
|
||||
namespace webrtc {
|
||||
namespace {
|
||||
static const int kOneSecond90Khz = 90000;
|
||||
static const int kMinTimeBetweenSyncs = kOneSecond90Khz * 2;
|
||||
static const int kMaxTimeBetweenSyncs = kOneSecond90Khz * 4;
|
||||
static const int kQpDeltaThresholdForSync = 8;
|
||||
static const int kMinBitrateKbpsForQpBoost = 500;
|
||||
using Buffer = Vp8FrameConfig::Buffer;
|
||||
using BufferFlags = Vp8FrameConfig::BufferFlags;
|
||||
|
||||
constexpr BufferFlags kNone = Vp8FrameConfig::BufferFlags::kNone;
|
||||
constexpr BufferFlags kReference = Vp8FrameConfig::BufferFlags::kReference;
|
||||
constexpr BufferFlags kUpdate = Vp8FrameConfig::BufferFlags::kUpdate;
|
||||
constexpr BufferFlags kReferenceAndUpdate =
|
||||
Vp8FrameConfig::BufferFlags::kReferenceAndUpdate;
|
||||
|
||||
constexpr int kOneSecond90Khz = 90000;
|
||||
constexpr int kMinTimeBetweenSyncs = kOneSecond90Khz * 2;
|
||||
constexpr int kMaxTimeBetweenSyncs = kOneSecond90Khz * 4;
|
||||
constexpr int kQpDeltaThresholdForSync = 8;
|
||||
constexpr int kMinBitrateKbpsForQpBoost = 500;
|
||||
} // namespace
|
||||
|
||||
const double ScreenshareLayers::kMaxTL0FpsReduction = 2.5;
|
||||
@ -68,8 +77,7 @@ bool ScreenshareLayers::SupportsEncoderFrameDropping() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
Vp8TemporalLayers::FrameConfig ScreenshareLayers::UpdateLayerConfig(
|
||||
uint32_t timestamp) {
|
||||
Vp8FrameConfig ScreenshareLayers::UpdateLayerConfig(uint32_t timestamp) {
|
||||
auto it = pending_frame_configs_.find(timestamp);
|
||||
if (it != pending_frame_configs_.end()) {
|
||||
// Drop and re-encode, reuse the previous config.
|
||||
@ -79,8 +87,8 @@ Vp8TemporalLayers::FrameConfig ScreenshareLayers::UpdateLayerConfig(
|
||||
if (number_of_temporal_layers_ <= 1) {
|
||||
// No flags needed for 1 layer screenshare.
|
||||
// TODO(pbos): Consider updating only last, and not all buffers.
|
||||
Vp8TemporalLayers::FrameConfig tl_config(
|
||||
kReferenceAndUpdate, kReferenceAndUpdate, kReferenceAndUpdate);
|
||||
Vp8FrameConfig tl_config(kReferenceAndUpdate, kReferenceAndUpdate,
|
||||
kReferenceAndUpdate);
|
||||
pending_frame_configs_[timestamp] = tl_config;
|
||||
return tl_config;
|
||||
}
|
||||
@ -100,7 +108,7 @@ Vp8TemporalLayers::FrameConfig ScreenshareLayers::UpdateLayerConfig(
|
||||
// averaging window, or if frame interval is below 90% of desired value,
|
||||
// drop frame.
|
||||
if (encode_framerate_.Rate(now_ms).value_or(0) > *target_framerate_)
|
||||
return Vp8TemporalLayers::FrameConfig(kNone, kNone, kNone);
|
||||
return Vp8FrameConfig(kNone, kNone, kNone);
|
||||
|
||||
// Primarily check if frame interval is too short using frame timestamps,
|
||||
// as if they are correct they won't be affected by queuing in webrtc.
|
||||
@ -108,7 +116,7 @@ Vp8TemporalLayers::FrameConfig ScreenshareLayers::UpdateLayerConfig(
|
||||
kOneSecond90Khz / *target_framerate_;
|
||||
if (last_timestamp_ != -1 && ts_diff > 0) {
|
||||
if (ts_diff < 85 * expected_frame_interval_90khz / 100) {
|
||||
return Vp8TemporalLayers::FrameConfig(kNone, kNone, kNone);
|
||||
return Vp8FrameConfig(kNone, kNone, kNone);
|
||||
}
|
||||
} else {
|
||||
// Timestamps looks off, use realtime clock here instead.
|
||||
@ -116,7 +124,7 @@ Vp8TemporalLayers::FrameConfig ScreenshareLayers::UpdateLayerConfig(
|
||||
if (last_frame_time_ms_ != -1 &&
|
||||
now_ms - last_frame_time_ms_ <
|
||||
(85 * expected_frame_interval_ms) / 100) {
|
||||
return Vp8TemporalLayers::FrameConfig(kNone, kNone, kNone);
|
||||
return Vp8FrameConfig(kNone, kNone, kNone);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -182,30 +190,28 @@ Vp8TemporalLayers::FrameConfig ScreenshareLayers::UpdateLayerConfig(
|
||||
RTC_NOTREACHED();
|
||||
}
|
||||
|
||||
Vp8TemporalLayers::FrameConfig tl_config;
|
||||
Vp8FrameConfig tl_config;
|
||||
// TODO(pbos): Consider referencing but not updating the 'alt' buffer for all
|
||||
// layers.
|
||||
switch (layer_state) {
|
||||
case TemporalLayerState::kDrop:
|
||||
tl_config = Vp8TemporalLayers::FrameConfig(kNone, kNone, kNone);
|
||||
tl_config = Vp8FrameConfig(kNone, kNone, kNone);
|
||||
break;
|
||||
case TemporalLayerState::kTl0:
|
||||
// TL0 only references and updates 'last'.
|
||||
tl_config =
|
||||
Vp8TemporalLayers::FrameConfig(kReferenceAndUpdate, kNone, kNone);
|
||||
tl_config = Vp8FrameConfig(kReferenceAndUpdate, kNone, kNone);
|
||||
tl_config.packetizer_temporal_idx = 0;
|
||||
break;
|
||||
case TemporalLayerState::kTl1:
|
||||
// TL1 references both 'last' and 'golden' but only updates 'golden'.
|
||||
tl_config = Vp8TemporalLayers::FrameConfig(kReference,
|
||||
kReferenceAndUpdate, kNone);
|
||||
tl_config = Vp8FrameConfig(kReference, kReferenceAndUpdate, kNone);
|
||||
tl_config.packetizer_temporal_idx = 1;
|
||||
break;
|
||||
case TemporalLayerState::kTl1Sync:
|
||||
// Predict from only TL0 to allow participants to switch to the high
|
||||
// bitrate stream. Updates 'golden' so that TL1 can continue to refer to
|
||||
// and update 'golden' from this point on.
|
||||
tl_config = Vp8TemporalLayers::FrameConfig(kReference, kUpdate, kNone);
|
||||
tl_config = Vp8FrameConfig(kReference, kUpdate, kNone);
|
||||
tl_config.packetizer_temporal_idx = 1;
|
||||
break;
|
||||
}
|
||||
@ -266,7 +272,7 @@ void ScreenshareLayers::OnEncodeDone(uint32_t rtp_timestamp,
|
||||
return;
|
||||
}
|
||||
|
||||
absl::optional<FrameConfig> frame_config;
|
||||
absl::optional<Vp8FrameConfig> frame_config;
|
||||
auto it = pending_frame_configs_.find(rtp_timestamp);
|
||||
if (it != pending_frame_configs_.end()) {
|
||||
frame_config = it->second;
|
||||
|
||||
Reference in New Issue
Block a user