Chromium Code Reviews| Index: webrtc/common_types.cc |
| diff --git a/webrtc/common_types.cc b/webrtc/common_types.cc |
| index e78a4aacca75f538e663dcf00732a691ad9570f8..c2374beffa3919911732d627b2153b77816b078a 100644 |
| --- a/webrtc/common_types.cc |
| +++ b/webrtc/common_types.cc |
| @@ -11,6 +11,7 @@ |
| #include "webrtc/base/checks.h" |
| #include "webrtc/common_types.h" |
| +#include <limits> |
| #include <string.h> |
| namespace webrtc { |
| @@ -59,6 +60,7 @@ VideoCodec::VideoCodec() |
| simulcastStream(), |
| spatialLayers(), |
| mode(kRealtimeVideo), |
| + expect_encode_from_texture(false), |
| codecSpecific() {} |
| VideoCodecVP8* VideoCodec::VP8() { |
| @@ -91,4 +93,89 @@ 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>(); |
| +} |
| + |
| +const size_t BitrateAllocation::kMaxBitrateBps = |
| + std::numeric_limits<size_t>::max(); |
| + |
| +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)); |
| + RTC_DCHECK_LE(bitrates_[spatial_index][temporal_index], sum_); |
| + size_t new_bitrate_sum_bps = sum_; |
| + new_bitrate_sum_bps -= bitrates_[spatial_index][temporal_index]; |
| + new_bitrate_sum_bps += bitrate_bps; |
| + if (new_bitrate_sum_bps > kMaxBitrateBps) |
|
stefan-webrtc
2016/11/03 13:34:58
Now the question is, can this ever happen when new
sprang_webrtc
2016/11/03 14:36:59
Alright, let's do uint64_t instead then.
stefan-webrtc
2016/11/03 15:32:08
Hehe... Or can we just assume it's safe? I just me
|
| + return false; |
| + |
| + bitrates_[spatial_index][temporal_index] = bitrate_bps; |
| + sum_ = static_cast<uint32_t>(new_bitrate_sum_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 |