Index: webrtc/common_types.cc |
diff --git a/webrtc/common_types.cc b/webrtc/common_types.cc |
index e78a4aacca75f538e663dcf00732a691ad9570f8..b8015cdf37a1339627502a261ef72b582559c210 100644 |
--- a/webrtc/common_types.cc |
+++ b/webrtc/common_types.cc |
@@ -11,6 +11,8 @@ |
#include "webrtc/base/checks.h" |
#include "webrtc/common_types.h" |
+#include "webrtc/base/checks.h" |
stefan-webrtc
2016/11/02 10:26:34
Included twice.
sprang_webrtc
2016/11/02 13:28:32
Oops. Rebase error...
|
+ |
#include <string.h> |
namespace webrtc { |
@@ -59,6 +61,7 @@ VideoCodec::VideoCodec() |
simulcastStream(), |
spatialLayers(), |
mode(kRealtimeVideo), |
+ expect_encode_from_texture(false), |
codecSpecific() {} |
VideoCodecVP8* VideoCodec::VP8() { |
@@ -91,4 +94,85 @@ const VideoCodecH264& VideoCodec::H264() const { |
return codecSpecific.H264; |
} |
+static const char* kPayloadNameVp8 = "VP8"; |
+static const char* kPayloadNameVp9 = "VP9"; |
+static const char* kPayloadNameH264 = "H264"; |
+static const char* kPayloadNameI420 = "I420"; |
+static const char* kPayloadNameRED = "RED"; |
+static const char* kPayloadNameULPFEC = "ULPFEC"; |
+static const char* kPayloadNameGeneric = "Generic"; |
+ |
+rtc::Optional<std::string> CodecTypeToPayloadName(VideoCodecType type) { |
+ switch (type) { |
+ case kVideoCodecVP8: |
+ return rtc::Optional<std::string>(kPayloadNameVp8); |
+ case kVideoCodecVP9: |
+ return rtc::Optional<std::string>(kPayloadNameVp9); |
+ case kVideoCodecH264: |
+ return rtc::Optional<std::string>(kPayloadNameH264); |
+ case kVideoCodecI420: |
+ return rtc::Optional<std::string>(kPayloadNameI420); |
+ case kVideoCodecRED: |
+ return rtc::Optional<std::string>(kPayloadNameRED); |
+ case kVideoCodecULPFEC: |
+ return rtc::Optional<std::string>(kPayloadNameULPFEC); |
+ case kVideoCodecGeneric: |
+ return rtc::Optional<std::string>(kPayloadNameGeneric); |
+ default: |
+ return rtc::Optional<std::string>(); |
+ } |
+} |
+ |
+rtc::Optional<VideoCodecType> PayloadNameToCodecType(const std::string& name) { |
+ if (name == kPayloadNameVp8) |
+ return rtc::Optional<VideoCodecType>(kVideoCodecVP8); |
+ if (name == kPayloadNameVp9) |
+ return rtc::Optional<VideoCodecType>(kVideoCodecVP9); |
+ if (name == kPayloadNameH264) |
+ return rtc::Optional<VideoCodecType>(kVideoCodecH264); |
+ if (name == kPayloadNameI420) |
+ return rtc::Optional<VideoCodecType>(kVideoCodecI420); |
+ if (name == kPayloadNameRED) |
+ return rtc::Optional<VideoCodecType>(kVideoCodecRED); |
+ if (name == kPayloadNameULPFEC) |
+ return rtc::Optional<VideoCodecType>(kVideoCodecULPFEC); |
+ if (name == kPayloadNameGeneric) |
+ return rtc::Optional<VideoCodecType>(kVideoCodecGeneric); |
+ return rtc::Optional<VideoCodecType>(); |
+} |
+ |
+BitrateAllocation::BitrateAllocation() : sum_(0), bitrates_{} {} |
+ |
+bool BitrateAllocation::SetBitrate(size_t spatial_index, |
+ size_t temporal_index, |
+ uint32_t bitrate_bps) { |
+ RTC_DCHECK_LT(spatial_index, static_cast<size_t>(kMaxSpatialLayers)); |
+ RTC_DCHECK_LT(temporal_index, static_cast<size_t>(kMaxTemporalStreams)); |
+ if (bitrate_bps > kMaxBitrateBps || |
stefan-webrtc
2016/11/02 10:26:34
Is it really needed to have a max? Can we use std:
sprang_webrtc
2016/11/02 13:28:32
Done.
|
+ sum_ - bitrates_[spatial_index][temporal_index] + bitrate_bps > |
+ kMaxBitrateBps) { |
+ return false; |
+ } |
+ sum_ -= bitrates_[spatial_index][temporal_index]; |
stefan-webrtc
2016/11/02 10:26:34
Maybe DCHECK that sum_ is greater than bitrates_..
sprang_webrtc
2016/11/02 13:28:32
Done.
|
+ bitrates_[spatial_index][temporal_index] = bitrate_bps; |
+ sum_ += bitrate_bps; |
+ return true; |
+} |
+ |
+uint32_t BitrateAllocation::GetBitrate(size_t spatial_index, |
+ size_t temporal_index) const { |
+ RTC_DCHECK_LT(spatial_index, static_cast<size_t>(kMaxSpatialLayers)); |
+ RTC_DCHECK_LT(temporal_index, static_cast<size_t>(kMaxTemporalStreams)); |
+ return bitrates_[spatial_index][temporal_index]; |
+} |
+ |
+// Get the sum of all the temporal layer for a specific spatial layer. |
+uint32_t BitrateAllocation::GetSpatialLayerSum(size_t spatial_index) const { |
+ RTC_DCHECK_LT(spatial_index, static_cast<size_t>(kMaxSpatialLayers)); |
+ uint32_t sum = 0; |
+ for (int i = 0; i < kMaxTemporalStreams; ++i) |
+ sum += bitrates_[spatial_index][i]; |
+ return sum; |
+} |
+ |
} // namespace webrtc |