OLD | NEW |
1 /* Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 1 /* Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
2 * | 2 * |
3 * Use of this source code is governed by a BSD-style license | 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 | 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 | 5 * tree. An additional intellectual property rights grant can be found |
6 * in the file PATENTS. All contributing project authors may | 6 * in the file PATENTS. All contributing project authors may |
7 * be found in the AUTHORS file in the root of the source tree. | 7 * be found in the AUTHORS file in the root of the source tree. |
8 */ | 8 */ |
9 #ifndef WEBRTC_MODULES_VIDEO_CODING_CODECS_VP8_SCREENSHARE_LAYERS_H_ | 9 #ifndef WEBRTC_MODULES_VIDEO_CODING_CODECS_VP8_SCREENSHARE_LAYERS_H_ |
10 #define WEBRTC_MODULES_VIDEO_CODING_CODECS_VP8_SCREENSHARE_LAYERS_H_ | 10 #define WEBRTC_MODULES_VIDEO_CODING_CODECS_VP8_SCREENSHARE_LAYERS_H_ |
11 | 11 |
12 #include <vector> | 12 #include <list> |
| 13 |
| 14 #include "vpx/vpx_encoder.h" |
13 | 15 |
14 #include "webrtc/base/timeutils.h" | 16 #include "webrtc/base/timeutils.h" |
15 #include "webrtc/modules/video_coding/codecs/vp8/temporal_layers.h" | 17 #include "webrtc/modules/video_coding/codecs/vp8/temporal_layers.h" |
16 #include "webrtc/modules/video_coding/utility/frame_dropper.h" | 18 #include "webrtc/modules/video_coding/utility/frame_dropper.h" |
17 #include "webrtc/typedefs.h" | 19 #include "webrtc/typedefs.h" |
18 | 20 |
19 namespace webrtc { | 21 namespace webrtc { |
20 | 22 |
21 struct CodecSpecificInfoVP8; | 23 struct CodecSpecificInfoVP8; |
22 class Clock; | 24 class Clock; |
23 | 25 |
24 class ScreenshareLayers : public TemporalLayers { | 26 class ScreenshareLayers : public TemporalLayers { |
25 public: | 27 public: |
26 static const double kMaxTL0FpsReduction; | 28 static const double kMaxTL0FpsReduction; |
27 static const double kAcceptableTargetOvershoot; | 29 static const double kAcceptableTargetOvershoot; |
28 static const int kTl0Flags; | 30 static const int kTl0Flags; |
29 static const int kTl1Flags; | 31 static const int kTl1Flags; |
30 static const int kTl1SyncFlags; | 32 static const int kTl1SyncFlags; |
31 static const int kMaxFrameIntervalMs; | 33 static const int kMaxFrameIntervalMs; |
32 | 34 |
33 ScreenshareLayers(int num_temporal_layers, | 35 ScreenshareLayers(int num_temporal_layers, |
34 uint8_t initial_tl0_pic_idx, | 36 uint8_t initial_tl0_pic_idx, |
35 Clock* clock); | 37 Clock* clock); |
36 virtual ~ScreenshareLayers(); | 38 virtual ~ScreenshareLayers(); |
37 | 39 |
38 // Returns the recommended VP8 encode flags needed. May refresh the decoder | 40 // Returns the recommended VP8 encode flags needed. May refresh the decoder |
39 // and/or update the reference buffers. | 41 // and/or update the reference buffers. |
40 int EncodeFlags(uint32_t timestamp) override; | 42 int EncodeFlags(uint32_t timestamp) override; |
41 | 43 |
42 // Update state based on new bitrate target and incoming framerate. | 44 bool ConfigureBitrates(int bitrate_kbps, |
43 // Returns the bitrate allocation for the active temporal layers. | 45 int max_bitrate_kbps, |
44 std::vector<uint32_t> OnRatesUpdated(int bitrate_kbps, | 46 int framerate, |
45 int max_bitrate_kbps, | 47 vpx_codec_enc_cfg_t* cfg) override; |
46 int framerate) override; | |
47 | |
48 // Update the encoder configuration with target bitrates or other parameters. | |
49 // Returns true iff the configuration was actually modified. | |
50 bool UpdateConfiguration(vpx_codec_enc_cfg_t* cfg) override; | |
51 | 48 |
52 void PopulateCodecSpecific(bool base_layer_sync, | 49 void PopulateCodecSpecific(bool base_layer_sync, |
53 CodecSpecificInfoVP8* vp8_info, | 50 CodecSpecificInfoVP8* vp8_info, |
54 uint32_t timestamp) override; | 51 uint32_t timestamp) override; |
55 | 52 |
56 void FrameEncoded(unsigned int size, uint32_t timestamp, int qp) override; | 53 void FrameEncoded(unsigned int size, uint32_t timestamp, int qp) override; |
57 | 54 |
58 int CurrentLayerId() const override; | 55 int CurrentLayerId() const override; |
59 | 56 |
| 57 // Allows the layers adapter to update the encoder configuration prior to a |
| 58 // frame being encoded. Return true if the configuration should be updated |
| 59 // and false if now change is needed. |
| 60 bool UpdateConfiguration(vpx_codec_enc_cfg_t* cfg) override; |
| 61 |
60 private: | 62 private: |
61 bool TimeToSync(int64_t timestamp) const; | 63 bool TimeToSync(int64_t timestamp) const; |
62 | 64 |
63 Clock* const clock_; | 65 Clock* const clock_; |
64 | 66 |
65 int number_of_temporal_layers_; | 67 int number_of_temporal_layers_; |
66 bool last_base_layer_sync_; | 68 bool last_base_layer_sync_; |
67 uint8_t tl0_pic_idx_; | 69 uint8_t tl0_pic_idx_; |
68 int active_layer_; | 70 int active_layer_; |
69 int64_t last_timestamp_; | 71 int64_t last_timestamp_; |
70 int64_t last_sync_timestamp_; | 72 int64_t last_sync_timestamp_; |
71 int64_t last_emitted_tl0_timestamp_; | 73 int64_t last_emitted_tl0_timestamp_; |
72 rtc::TimestampWrapAroundHandler time_wrap_handler_; | 74 rtc::TimestampWrapAroundHandler time_wrap_handler_; |
73 int min_qp_; | 75 int min_qp_; |
74 int max_qp_; | 76 int max_qp_; |
75 uint32_t max_debt_bytes_; | 77 uint32_t max_debt_bytes_; |
76 int framerate_; | 78 int frame_rate_; |
77 bool bitrate_updated_; | |
78 | 79 |
79 static const int kMaxNumTemporalLayers = 2; | 80 static const int kMaxNumTemporalLayers = 2; |
80 struct TemporalLayer { | 81 struct TemporalLayer { |
81 TemporalLayer() | 82 TemporalLayer() |
82 : state(State::kNormal), | 83 : state(State::kNormal), |
83 enhanced_max_qp(-1), | 84 enhanced_max_qp(-1), |
84 last_qp(-1), | 85 last_qp(-1), |
85 debt_bytes_(0), | 86 debt_bytes_(0), |
86 target_rate_kbps_(0) {} | 87 target_rate_kbps_(0) {} |
87 | 88 |
(...skipping 22 matching lines...) Loading... |
110 int64_t num_overshoots_ = 0; | 111 int64_t num_overshoots_ = 0; |
111 int64_t tl0_qp_sum_ = 0; | 112 int64_t tl0_qp_sum_ = 0; |
112 int64_t tl1_qp_sum_ = 0; | 113 int64_t tl1_qp_sum_ = 0; |
113 int64_t tl0_target_bitrate_sum_ = 0; | 114 int64_t tl0_target_bitrate_sum_ = 0; |
114 int64_t tl1_target_bitrate_sum_ = 0; | 115 int64_t tl1_target_bitrate_sum_ = 0; |
115 } stats_; | 116 } stats_; |
116 }; | 117 }; |
117 } // namespace webrtc | 118 } // namespace webrtc |
118 | 119 |
119 #endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_VP8_SCREENSHARE_LAYERS_H_ | 120 #endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_VP8_SCREENSHARE_LAYERS_H_ |
OLD | NEW |