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 | 9 |
10 #include <stdlib.h> | 10 #include <stdlib.h> |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 layer_ids_length_(0), | 94 layer_ids_length_(0), |
95 layer_ids_(NULL), | 95 layer_ids_(NULL), |
96 encode_flags_length_(0), | 96 encode_flags_length_(0), |
97 encode_flags_(NULL) { | 97 encode_flags_(NULL) { |
98 assert(max_temporal_layers_ >= 1); | 98 assert(max_temporal_layers_ >= 1); |
99 assert(max_temporal_layers_ <= 3); | 99 assert(max_temporal_layers_ <= 3); |
100 } | 100 } |
101 | 101 |
102 virtual ~RealTimeTemporalLayers() {} | 102 virtual ~RealTimeTemporalLayers() {} |
103 | 103 |
104 bool ConfigureBitrates(int bitrate_kbit, | 104 virtual bool ConfigureBitrates(int bitrate_kbit, |
105 int max_bitrate_kbit, | 105 int max_bitrate_kbit, |
106 int framerate, | 106 int framerate, |
107 vpx_codec_enc_cfg_t* cfg) override { | 107 vpx_codec_enc_cfg_t* cfg) { |
108 temporal_layers_ = | 108 temporal_layers_ = |
109 CalculateNumberOfTemporalLayers(temporal_layers_, framerate); | 109 CalculateNumberOfTemporalLayers(temporal_layers_, framerate); |
110 temporal_layers_ = std::min(temporal_layers_, max_temporal_layers_); | 110 temporal_layers_ = std::min(temporal_layers_, max_temporal_layers_); |
111 assert(temporal_layers_ >= 1 && temporal_layers_ <= 3); | 111 assert(temporal_layers_ >= 1 && temporal_layers_ <= 3); |
112 | 112 |
113 cfg->ts_number_layers = temporal_layers_; | 113 cfg->ts_number_layers = temporal_layers_; |
114 for (int tl = 0; tl < temporal_layers_; ++tl) { | 114 for (int tl = 0; tl < temporal_layers_; ++tl) { |
115 cfg->ts_target_bitrate[tl] = | 115 cfg->ts_target_bitrate[tl] = |
116 bitrate_kbit * kVp8LayerRateAlloction[temporal_layers_ - 1][tl]; | 116 bitrate_kbit * kVp8LayerRateAlloction[temporal_layers_ - 1][tl]; |
117 } | 117 } |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 | 177 |
178 default: | 178 default: |
179 assert(false); | 179 assert(false); |
180 return false; | 180 return false; |
181 } | 181 } |
182 memcpy(cfg->ts_layer_id, layer_ids_, | 182 memcpy(cfg->ts_layer_id, layer_ids_, |
183 sizeof(unsigned int) * layer_ids_length_); | 183 sizeof(unsigned int) * layer_ids_length_); |
184 return true; | 184 return true; |
185 } | 185 } |
186 | 186 |
187 int EncodeFlags(uint32_t timestamp) override { | 187 virtual int EncodeFlags(uint32_t timestamp) { |
188 frame_counter_++; | 188 frame_counter_++; |
189 return CurrentEncodeFlags(); | 189 return CurrentEncodeFlags(); |
190 } | 190 } |
191 | 191 |
192 int CurrentEncodeFlags() const { | 192 int CurrentEncodeFlags() const { |
193 assert(encode_flags_length_ > 0 && encode_flags_ != NULL); | 193 assert(encode_flags_length_ > 0 && encode_flags_ != NULL); |
194 int index = frame_counter_ % encode_flags_length_; | 194 int index = frame_counter_ % encode_flags_length_; |
195 assert(index >= 0 && index < encode_flags_length_); | 195 assert(index >= 0 && index < encode_flags_length_); |
196 return encode_flags_[index]; | 196 return encode_flags_[index]; |
197 } | 197 } |
198 | 198 |
199 int CurrentLayerId() const override { | 199 virtual int CurrentLayerId() const { |
200 assert(layer_ids_length_ > 0 && layer_ids_ != NULL); | 200 assert(layer_ids_length_ > 0 && layer_ids_ != NULL); |
201 int index = frame_counter_ % layer_ids_length_; | 201 int index = frame_counter_ % layer_ids_length_; |
202 assert(index >= 0 && index < layer_ids_length_); | 202 assert(index >= 0 && index < layer_ids_length_); |
203 return layer_ids_[index]; | 203 return layer_ids_[index]; |
204 } | 204 } |
205 | 205 |
206 void PopulateCodecSpecific(bool base_layer_sync, | 206 virtual void PopulateCodecSpecific(bool base_layer_sync, |
207 CodecSpecificInfoVP8* vp8_info, | 207 CodecSpecificInfoVP8* vp8_info, |
208 uint32_t timestamp) override { | 208 uint32_t timestamp) { |
209 assert(temporal_layers_ > 0); | 209 assert(temporal_layers_ > 0); |
210 | 210 |
211 if (temporal_layers_ == 1) { | 211 if (temporal_layers_ == 1) { |
212 vp8_info->temporalIdx = kNoTemporalIdx; | 212 vp8_info->temporalIdx = kNoTemporalIdx; |
213 vp8_info->layerSync = false; | 213 vp8_info->layerSync = false; |
214 vp8_info->tl0PicIdx = kNoTl0PicIdx; | 214 vp8_info->tl0PicIdx = kNoTl0PicIdx; |
215 } else { | 215 } else { |
216 if (base_layer_sync) { | 216 if (base_layer_sync) { |
217 vp8_info->temporalIdx = 0; | 217 vp8_info->temporalIdx = 0; |
218 vp8_info->layerSync = true; | 218 vp8_info->layerSync = true; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 const int* encode_flags_; | 268 const int* encode_flags_; |
269 }; | 269 }; |
270 } // namespace | 270 } // namespace |
271 | 271 |
272 TemporalLayers* RealTimeTemporalLayersFactory::Create( | 272 TemporalLayers* RealTimeTemporalLayersFactory::Create( |
273 int max_temporal_layers, | 273 int max_temporal_layers, |
274 uint8_t initial_tl0_pic_idx) const { | 274 uint8_t initial_tl0_pic_idx) const { |
275 return new RealTimeTemporalLayers(max_temporal_layers, initial_tl0_pic_idx); | 275 return new RealTimeTemporalLayers(max_temporal_layers, initial_tl0_pic_idx); |
276 } | 276 } |
277 } // namespace webrtc | 277 } // namespace webrtc |
OLD | NEW |