blob: c479917fc2fbd09982385cfeb90cd9d284c3e60b [file] [log] [blame]
pbos@webrtc.org9115cde2014-12-09 10:36:401/* Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
Ilya Nikolaevskiybf352982017-10-02 08:08:252 *
3 * Use of this source code is governed by a BSD-style license
4 * that can be found in the LICENSE file in the root of the source
5 * tree. An additional intellectual property rights grant can be found
6 * in the file PATENTS. All contributing project authors may
7 * be found in the AUTHORS file in the root of the source tree.
8 */
Mirko Bonadei92ea95e2017-09-15 04:47:319#ifndef MODULES_VIDEO_CODING_CODECS_VP8_SCREENSHARE_LAYERS_H_
10#define MODULES_VIDEO_CODING_CODECS_VP8_SCREENSHARE_LAYERS_H_
pbos@webrtc.org9115cde2014-12-09 10:36:4011
Erik Språng08127a92016-11-16 15:41:3012#include <vector>
pbos@webrtc.orge728ee02014-12-17 13:43:5513
Mirko Bonadei92ea95e2017-09-15 04:47:3114#include "modules/video_coding/codecs/vp8/temporal_layers.h"
15#include "modules/video_coding/utility/frame_dropper.h"
16#include "rtc_base/rate_statistics.h"
17#include "rtc_base/timeutils.h"
Mirko Bonadei71207422017-09-15 11:58:0918#include "typedefs.h" // NOLINT(build/include)
pbos@webrtc.org9115cde2014-12-09 10:36:4019
pbos@webrtc.org9115cde2014-12-09 10:36:4020namespace webrtc {
21
22struct CodecSpecificInfoVP8;
sprangb0fdfea2016-03-01 13:51:1623class Clock;
pbos@webrtc.org9115cde2014-12-09 10:36:4024
25class ScreenshareLayers : public TemporalLayers {
26 public:
sprang@webrtc.org70f74f32014-12-17 10:57:1027 static const double kMaxTL0FpsReduction;
28 static const double kAcceptableTargetOvershoot;
sprangafe1f742016-04-12 09:45:1329 static const int kMaxFrameIntervalMs;
sprang@webrtc.org70f74f32014-12-17 10:57:1030
sprangb0fdfea2016-03-01 13:51:1631 ScreenshareLayers(int num_temporal_layers,
sprangb0fdfea2016-03-01 13:51:1632 Clock* clock);
33 virtual ~ScreenshareLayers();
pbos@webrtc.org9115cde2014-12-09 10:36:4034
35 // Returns the recommended VP8 encode flags needed. May refresh the decoder
36 // and/or update the reference buffers.
pbos18ad1d42017-05-04 12:04:4637 TemporalLayers::FrameConfig UpdateLayerConfig(uint32_t timestamp) override;
pbos@webrtc.org9115cde2014-12-09 10:36:4038
Erik Språngbb60a3a2018-03-19 17:25:1039 // New target bitrate, per temporal layer.
40 void OnRatesUpdated(const std::vector<uint32_t>& bitrates_bps,
41 int framerate_fps) override;
Erik Språng08127a92016-11-16 15:41:3042
43 // Update the encoder configuration with target bitrates or other parameters.
44 // Returns true iff the configuration was actually modified.
Anders Carlssonbeabdcb2018-01-24 09:25:1545 bool UpdateConfiguration(Vp8EncoderConfig* cfg) override;
pbos@webrtc.org9115cde2014-12-09 10:36:4046
Erik Språng2c4c9142015-06-24 09:24:4447 void PopulateCodecSpecific(bool base_layer_sync,
pbos18ad1d42017-05-04 12:04:4648 const TemporalLayers::FrameConfig& tl_config,
Erik Språng2c4c9142015-06-24 09:24:4449 CodecSpecificInfoVP8* vp8_info,
50 uint32_t timestamp) override;
pbos@webrtc.org9115cde2014-12-09 10:36:4051
Peter Boström1436c832017-03-27 19:01:4952 void FrameEncoded(unsigned int size, int qp) override;
pbos@webrtc.org9115cde2014-12-09 10:36:4053
pbos@webrtc.org9115cde2014-12-09 10:36:4054 private:
sprang916170a2017-05-23 14:47:5555 enum class TemporalLayerState : int { kDrop, kTl0, kTl1, kTl1Sync };
pbos51f083c2017-05-04 13:39:0456
Erik Språng2c4c9142015-06-24 09:24:4457 bool TimeToSync(int64_t timestamp) const;
sprangc7805db2016-11-25 16:09:4358 uint32_t GetCodecTargetBitrateKbps() const;
pbos@webrtc.org9115cde2014-12-09 10:36:4059
sprangb0fdfea2016-03-01 13:51:1660 Clock* const clock_;
61
pbos@webrtc.org9115cde2014-12-09 10:36:4062 int number_of_temporal_layers_;
63 bool last_base_layer_sync_;
pbos@webrtc.org9115cde2014-12-09 10:36:4064 int active_layer_;
Erik Språng2c4c9142015-06-24 09:24:4465 int64_t last_timestamp_;
pbos@webrtc.org9115cde2014-12-09 10:36:4066 int64_t last_sync_timestamp_;
sprangafe1f742016-04-12 09:45:1367 int64_t last_emitted_tl0_timestamp_;
Erik Språng27a457d2018-01-12 10:00:2168 int64_t last_frame_time_ms_;
Erik Språng2c4c9142015-06-24 09:24:4469 rtc::TimestampWrapAroundHandler time_wrap_handler_;
70 int min_qp_;
71 int max_qp_;
72 uint32_t max_debt_bytes_;
sprangac4a90d2016-12-28 13:58:0773
74 // Configured max framerate.
75 rtc::Optional<uint32_t> target_framerate_;
76 // Incoming framerate from capturer.
sprang0ad0de62017-01-11 13:01:3277 rtc::Optional<uint32_t> capture_framerate_;
sprangac4a90d2016-12-28 13:58:0778 // Tracks what framerate we actually encode, and drops frames on overshoot.
79 RateStatistics encode_framerate_;
Erik Språng08127a92016-11-16 15:41:3080 bool bitrate_updated_;
Erik Språng2c4c9142015-06-24 09:24:4481
sprang429600d2017-01-26 14:12:2682 static constexpr int kMaxNumTemporalLayers = 2;
Erik Språng2c4c9142015-06-24 09:24:4483 struct TemporalLayer {
84 TemporalLayer()
85 : state(State::kNormal),
86 enhanced_max_qp(-1),
87 last_qp(-1),
88 debt_bytes_(0),
89 target_rate_kbps_(0) {}
90
91 enum class State {
92 kNormal,
93 kDropped,
94 kReencoded,
95 kQualityBoost,
96 } state;
97
98 int enhanced_max_qp;
99 int last_qp;
100 uint32_t debt_bytes_;
101 uint32_t target_rate_kbps_;
102
103 void UpdateDebt(int64_t delta_ms);
104 } layers_[kMaxNumTemporalLayers];
sprangb0fdfea2016-03-01 13:51:16105
106 void UpdateHistograms();
107 // Data for histogram statistics.
108 struct Stats {
109 int64_t first_frame_time_ms_ = -1;
110 int64_t num_tl0_frames_ = 0;
111 int64_t num_tl1_frames_ = 0;
112 int64_t num_dropped_frames_ = 0;
113 int64_t num_overshoots_ = 0;
114 int64_t tl0_qp_sum_ = 0;
115 int64_t tl1_qp_sum_ = 0;
116 int64_t tl0_target_bitrate_sum_ = 0;
117 int64_t tl1_target_bitrate_sum_ = 0;
118 } stats_;
pbos@webrtc.org9115cde2014-12-09 10:36:40119};
120} // namespace webrtc
121
Mirko Bonadei92ea95e2017-09-15 04:47:31122#endif // MODULES_VIDEO_CODING_CODECS_VP8_SCREENSHARE_LAYERS_H_