Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(221)

Unified Diff: webrtc/common_types.cc

Issue 2510583002: Reland #2 of Issue 2434073003: Extract bitrate allocation ... (Closed)
Patch Set: Addressed comments Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/common_types.h ('k') | webrtc/common_video/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/common_types.cc
diff --git a/webrtc/common_types.cc b/webrtc/common_types.cc
index e78a4aacca75f538e663dcf00732a691ad9570f8..3f8d877fd2db668b7531827637b58e604d6dbfb8 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 uint32_t BitrateAllocation::kMaxBitrateBps =
+ std::numeric_limits<uint32_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_);
+ uint64_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)
+ 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
« no previous file with comments | « webrtc/common_types.h ('k') | webrtc/common_video/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698