2014-12-09 10:36:40 +00:00
|
|
|
/* Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
|
2017-10-02 10:08:25 +02:00
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
2017-09-15 06:47:31 +02:00
|
|
|
#ifndef MODULES_VIDEO_CODING_CODECS_VP8_SCREENSHARE_LAYERS_H_
|
|
|
|
|
#define MODULES_VIDEO_CODING_CODECS_VP8_SCREENSHARE_LAYERS_H_
|
2014-12-09 10:36:40 +00:00
|
|
|
|
2018-10-03 11:05:16 +02:00
|
|
|
#include <map>
|
|
|
|
|
#include <memory>
|
2016-11-16 16:41:30 +01:00
|
|
|
#include <vector>
|
2014-12-17 13:43:55 +00:00
|
|
|
|
2018-10-03 11:05:16 +02:00
|
|
|
#include "modules/video_coding/codecs/vp8/include/temporal_layers_checker.h"
|
2018-10-01 18:47:03 +02:00
|
|
|
#include "modules/video_coding/codecs/vp8/include/vp8_temporal_layers.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/video_coding/utility/frame_dropper.h"
|
|
|
|
|
#include "rtc_base/rate_statistics.h"
|
|
|
|
|
#include "rtc_base/timeutils.h"
|
2014-12-09 10:36:40 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
struct CodecSpecificInfoVP8;
|
2016-03-01 05:51:16 -08:00
|
|
|
class Clock;
|
2014-12-09 10:36:40 +00:00
|
|
|
|
|
|
|
|
class ScreenshareLayers : public TemporalLayers {
|
|
|
|
|
public:
|
2014-12-17 10:57:10 +00:00
|
|
|
static const double kMaxTL0FpsReduction;
|
|
|
|
|
static const double kAcceptableTargetOvershoot;
|
2016-04-12 02:45:13 -07:00
|
|
|
static const int kMaxFrameIntervalMs;
|
2014-12-17 10:57:10 +00:00
|
|
|
|
2018-06-21 16:16:38 +02:00
|
|
|
ScreenshareLayers(int num_temporal_layers,
|
|
|
|
|
Clock* clock);
|
2018-09-10 10:48:01 +02:00
|
|
|
~ScreenshareLayers() override;
|
|
|
|
|
|
|
|
|
|
bool SupportsEncoderFrameDropping() const override;
|
2014-12-09 10:36:40 +00:00
|
|
|
|
|
|
|
|
// Returns the recommended VP8 encode flags needed. May refresh the decoder
|
|
|
|
|
// and/or update the reference buffers.
|
2018-08-13 16:05:33 +02:00
|
|
|
TemporalLayers::FrameConfig UpdateLayerConfig(
|
|
|
|
|
uint32_t rtp_timestamp) override;
|
2014-12-09 10:36:40 +00:00
|
|
|
|
2018-03-19 18:25:10 +01:00
|
|
|
// New target bitrate, per temporal layer.
|
|
|
|
|
void OnRatesUpdated(const std::vector<uint32_t>& bitrates_bps,
|
|
|
|
|
int framerate_fps) override;
|
2016-11-16 16:41:30 +01:00
|
|
|
|
|
|
|
|
// Update the encoder configuration with target bitrates or other parameters.
|
|
|
|
|
// Returns true iff the configuration was actually modified.
|
2018-01-24 10:25:15 +01:00
|
|
|
bool UpdateConfiguration(Vp8EncoderConfig* cfg) override;
|
2014-12-09 10:36:40 +00:00
|
|
|
|
2018-10-03 11:05:16 +02:00
|
|
|
void OnEncodeDone(uint32_t rtp_timestamp,
|
|
|
|
|
size_t size_bytes,
|
|
|
|
|
bool is_keyframe,
|
|
|
|
|
int qp,
|
|
|
|
|
CodecSpecificInfoVP8* vp8_info) override;
|
2014-12-09 10:36:40 +00:00
|
|
|
|
|
|
|
|
private:
|
2017-05-23 07:47:55 -07:00
|
|
|
enum class TemporalLayerState : int { kDrop, kTl0, kTl1, kTl1Sync };
|
2017-05-04 06:39:04 -07:00
|
|
|
|
2015-06-24 11:24:44 +02:00
|
|
|
bool TimeToSync(int64_t timestamp) const;
|
2016-11-25 08:09:43 -08:00
|
|
|
uint32_t GetCodecTargetBitrateKbps() const;
|
2014-12-09 10:36:40 +00:00
|
|
|
|
2016-03-01 05:51:16 -08:00
|
|
|
Clock* const clock_;
|
|
|
|
|
|
2014-12-09 10:36:40 +00:00
|
|
|
int number_of_temporal_layers_;
|
|
|
|
|
int active_layer_;
|
2015-06-24 11:24:44 +02:00
|
|
|
int64_t last_timestamp_;
|
2014-12-09 10:36:40 +00:00
|
|
|
int64_t last_sync_timestamp_;
|
2016-04-12 02:45:13 -07:00
|
|
|
int64_t last_emitted_tl0_timestamp_;
|
2018-01-12 11:00:21 +01:00
|
|
|
int64_t last_frame_time_ms_;
|
2015-06-24 11:24:44 +02:00
|
|
|
rtc::TimestampWrapAroundHandler time_wrap_handler_;
|
|
|
|
|
int min_qp_;
|
|
|
|
|
int max_qp_;
|
|
|
|
|
uint32_t max_debt_bytes_;
|
2016-12-28 05:58:07 -08:00
|
|
|
|
2018-10-03 11:05:16 +02:00
|
|
|
std::map<uint32_t, TemporalLayers::FrameConfig> pending_frame_configs_;
|
|
|
|
|
|
2016-12-28 05:58:07 -08:00
|
|
|
// Configured max framerate.
|
2018-06-18 10:48:16 +02:00
|
|
|
absl::optional<uint32_t> target_framerate_;
|
2016-12-28 05:58:07 -08:00
|
|
|
// Incoming framerate from capturer.
|
2018-06-18 10:48:16 +02:00
|
|
|
absl::optional<uint32_t> capture_framerate_;
|
2016-12-28 05:58:07 -08:00
|
|
|
// Tracks what framerate we actually encode, and drops frames on overshoot.
|
|
|
|
|
RateStatistics encode_framerate_;
|
2016-11-16 16:41:30 +01:00
|
|
|
bool bitrate_updated_;
|
2015-06-24 11:24:44 +02:00
|
|
|
|
2017-01-26 06:12:26 -08:00
|
|
|
static constexpr int kMaxNumTemporalLayers = 2;
|
2015-06-24 11:24:44 +02:00
|
|
|
struct TemporalLayer {
|
|
|
|
|
TemporalLayer()
|
|
|
|
|
: state(State::kNormal),
|
|
|
|
|
enhanced_max_qp(-1),
|
|
|
|
|
last_qp(-1),
|
|
|
|
|
debt_bytes_(0),
|
|
|
|
|
target_rate_kbps_(0) {}
|
|
|
|
|
|
|
|
|
|
enum class State {
|
|
|
|
|
kNormal,
|
|
|
|
|
kDropped,
|
|
|
|
|
kReencoded,
|
|
|
|
|
kQualityBoost,
|
2018-08-13 16:05:33 +02:00
|
|
|
kKeyFrame
|
2015-06-24 11:24:44 +02:00
|
|
|
} state;
|
|
|
|
|
|
|
|
|
|
int enhanced_max_qp;
|
|
|
|
|
int last_qp;
|
|
|
|
|
uint32_t debt_bytes_;
|
|
|
|
|
uint32_t target_rate_kbps_;
|
|
|
|
|
|
|
|
|
|
void UpdateDebt(int64_t delta_ms);
|
|
|
|
|
} layers_[kMaxNumTemporalLayers];
|
2016-03-01 05:51:16 -08:00
|
|
|
|
|
|
|
|
void UpdateHistograms();
|
|
|
|
|
// Data for histogram statistics.
|
|
|
|
|
struct Stats {
|
|
|
|
|
int64_t first_frame_time_ms_ = -1;
|
|
|
|
|
int64_t num_tl0_frames_ = 0;
|
|
|
|
|
int64_t num_tl1_frames_ = 0;
|
|
|
|
|
int64_t num_dropped_frames_ = 0;
|
|
|
|
|
int64_t num_overshoots_ = 0;
|
|
|
|
|
int64_t tl0_qp_sum_ = 0;
|
|
|
|
|
int64_t tl1_qp_sum_ = 0;
|
|
|
|
|
int64_t tl0_target_bitrate_sum_ = 0;
|
|
|
|
|
int64_t tl1_target_bitrate_sum_ = 0;
|
|
|
|
|
} stats_;
|
2018-10-03 11:05:16 +02:00
|
|
|
|
|
|
|
|
// Optional utility used to verify reference validity.
|
|
|
|
|
std::unique_ptr<TemporalLayersChecker> checker_;
|
2014-12-09 10:36:40 +00:00
|
|
|
};
|
|
|
|
|
} // namespace webrtc
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#endif // MODULES_VIDEO_CODING_CODECS_VP8_SCREENSHARE_LAYERS_H_
|