Index: webrtc/modules/video_coding/video_bitrate_allocator_factory.cc |
diff --git a/webrtc/modules/video_coding/video_bitrate_allocator_factory.cc b/webrtc/modules/video_coding/video_bitrate_allocator_factory.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..d97755c8a3344b979250522214a16fdd14da8be8 |
--- /dev/null |
+++ b/webrtc/modules/video_coding/video_bitrate_allocator_factory.cc |
@@ -0,0 +1,71 @@ |
+/* |
+ * Copyright (c) 2016 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. |
+ */ |
+ |
+#include "webrtc/modules/video_coding/include/video_bitrate_allocator_factory.h" |
+ |
+#include "webrtc/base/basictypes.h" |
+#include "webrtc/common_video/include/video_bitrate_allocator.h" |
+#include "webrtc/common_types.h" |
+#include "webrtc/modules/video_coding/codecs/vp8/screenshare_layers.h" |
+#include "webrtc/modules/video_coding/codecs/vp8/temporal_layers.h" |
+#include "webrtc/modules/video_coding/utility/simulcast_rate_allocator.h" |
+#include "webrtc/modules/video_coding/utility/default_video_bitrate_allocator.h" |
+#include "webrtc/system_wrappers/include/clock.h" |
+ |
+namespace webrtc { |
+ |
+struct ScreenshareTemporalLayersFactory : webrtc::TemporalLayersFactory { |
+ ScreenshareTemporalLayersFactory() {} |
+ virtual ~ScreenshareTemporalLayersFactory() {} |
+ |
+ virtual webrtc::TemporalLayers* Create(int simulcast_id, |
+ int num_temporal_layers, |
+ uint8_t initial_tl0_pic_idx) const { |
+ webrtc::TemporalLayers* tl = new webrtc::ScreenshareLayers( |
+ num_temporal_layers, rand(), webrtc::Clock::GetRealTimeClock()); |
+ if (listener_) |
+ listener_->OnTemporalLayersCreated(simulcast_id, tl); |
+ return tl; |
+ } |
+}; |
+ |
+std::unique_ptr<VideoBitrateAllocator> |
+VideoBitrateAllocatorFactory::GetBitrateAllocator(VideoCodec* codec) { |
perkj_webrtc
2016/10/27 12:57:31
it feels weird that GetBitrateAllocator take a non
sprang_webrtc
2016/11/01 18:03:16
I don't think it makes sense to have the rate allo
|
+ std::unique_ptr<VideoBitrateAllocator> rate_allocator; |
+ |
+ switch (codec->codecType) { |
+ case kVideoCodecVP8: { |
+ // Set up default VP8 temporal layer factory, if not provided. |
+ std::unique_ptr<TemporalLayersFactory> tl_factory; |
+ if (!codec->codecSpecific.VP8.tl_factory) { |
+ if (codec->mode == kScreensharing && |
+ codec->numberOfSimulcastStreams == 1 && |
+ codec->codecSpecific.VP8.numberOfTemporalLayers == 2) { |
+ // Conference mode temporal layering for screen content. |
+ tl_factory.reset(new ScreenshareTemporalLayersFactory()); |
+ } else { |
+ // Standard video temporal layers. |
+ tl_factory.reset(new TemporalLayersFactory()); |
+ } |
+ codec->codecSpecific.VP8.tl_factory = tl_factory.get(); |
+ } |
+ rate_allocator.reset( |
+ new SimulcastRateAllocator(*codec, std::move(tl_factory))); |
+ codec->codecSpecific.VP8.tl_factory->SetListener( |
+ static_cast<SimulcastRateAllocator*>(rate_allocator.get())); |
+ } break; |
+ default: |
+ rate_allocator.reset(new DefaultVideoBitrateAllocator(*codec)); |
+ } |
+ |
+ return rate_allocator; |
+} |
+ |
+} // namespace webrtc |