2014-12-09 10:36:40 +00:00
|
|
|
/* Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
#ifndef WEBRTC_MODULES_VIDEO_CODING_CODECS_VP8_SCREENSHARE_LAYERS_H_
|
|
|
|
|
#define WEBRTC_MODULES_VIDEO_CODING_CODECS_VP8_SCREENSHARE_LAYERS_H_
|
|
|
|
|
|
2016-11-10 08:30:33 -08:00
|
|
|
#include <list>
|
|
|
|
|
|
|
|
|
|
#include "vpx/vpx_encoder.h"
|
2014-12-17 13:43:55 +00:00
|
|
|
|
2015-06-24 11:24:44 +02:00
|
|
|
#include "webrtc/base/timeutils.h"
|
2014-12-09 10:36:40 +00:00
|
|
|
#include "webrtc/modules/video_coding/codecs/vp8/temporal_layers.h"
|
2015-11-18 23:04:10 +01:00
|
|
|
#include "webrtc/modules/video_coding/utility/frame_dropper.h"
|
2014-12-09 10:36:40 +00:00
|
|
|
#include "webrtc/typedefs.h"
|
|
|
|
|
|
|
|
|
|
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;
|
2015-06-24 11:24:44 +02:00
|
|
|
static const int kTl0Flags;
|
|
|
|
|
static const int kTl1Flags;
|
|
|
|
|
static const int kTl1SyncFlags;
|
2016-04-12 02:45:13 -07:00
|
|
|
static const int kMaxFrameIntervalMs;
|
2014-12-17 10:57:10 +00:00
|
|
|
|
2016-03-01 05:51:16 -08:00
|
|
|
ScreenshareLayers(int num_temporal_layers,
|
|
|
|
|
uint8_t initial_tl0_pic_idx,
|
|
|
|
|
Clock* clock);
|
|
|
|
|
virtual ~ScreenshareLayers();
|
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.
|
2015-06-24 11:24:44 +02:00
|
|
|
int EncodeFlags(uint32_t timestamp) override;
|
2014-12-09 10:36:40 +00:00
|
|
|
|
2016-11-10 08:30:33 -08:00
|
|
|
bool ConfigureBitrates(int bitrate_kbps,
|
|
|
|
|
int max_bitrate_kbps,
|
|
|
|
|
int framerate,
|
|
|
|
|
vpx_codec_enc_cfg_t* cfg) override;
|
2014-12-09 10:36:40 +00:00
|
|
|
|
2015-06-24 11:24:44 +02:00
|
|
|
void PopulateCodecSpecific(bool base_layer_sync,
|
|
|
|
|
CodecSpecificInfoVP8* vp8_info,
|
|
|
|
|
uint32_t timestamp) override;
|
2014-12-09 10:36:40 +00:00
|
|
|
|
2015-06-24 11:24:44 +02:00
|
|
|
void FrameEncoded(unsigned int size, uint32_t timestamp, int qp) override;
|
2014-12-09 10:36:40 +00:00
|
|
|
|
2015-06-24 11:24:44 +02:00
|
|
|
int CurrentLayerId() const override;
|
|
|
|
|
|
2016-11-10 08:30:33 -08:00
|
|
|
// Allows the layers adapter to update the encoder configuration prior to a
|
|
|
|
|
// frame being encoded. Return true if the configuration should be updated
|
|
|
|
|
// and false if now change is needed.
|
|
|
|
|
bool UpdateConfiguration(vpx_codec_enc_cfg_t* cfg) override;
|
|
|
|
|
|
2014-12-09 10:36:40 +00:00
|
|
|
private:
|
2015-06-24 11:24:44 +02:00
|
|
|
bool TimeToSync(int64_t timestamp) 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_;
|
|
|
|
|
bool last_base_layer_sync_;
|
|
|
|
|
uint8_t tl0_pic_idx_;
|
|
|
|
|
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_;
|
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-11-10 08:30:33 -08:00
|
|
|
int frame_rate_;
|
2015-06-24 11:24:44 +02:00
|
|
|
|
|
|
|
|
static const int kMaxNumTemporalLayers = 2;
|
|
|
|
|
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,
|
|
|
|
|
} 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_;
|
2014-12-09 10:36:40 +00:00
|
|
|
};
|
|
|
|
|
} // namespace webrtc
|
|
|
|
|
|
|
|
|
|
#endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_VP8_SCREENSHARE_LAYERS_H_
|