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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « webrtc/common_types.h ('k') | webrtc/common_video/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/base/checks.h" 11 #include "webrtc/base/checks.h"
12 #include "webrtc/common_types.h" 12 #include "webrtc/common_types.h"
13 13
14 #include <limits>
14 #include <string.h> 15 #include <string.h>
15 16
16 namespace webrtc { 17 namespace webrtc {
17 18
18 StreamDataCounters::StreamDataCounters() : first_packet_time_ms(-1) {} 19 StreamDataCounters::StreamDataCounters() : first_packet_time_ms(-1) {}
19 20
20 RTPHeaderExtension::RTPHeaderExtension() 21 RTPHeaderExtension::RTPHeaderExtension()
21 : hasTransmissionTimeOffset(false), 22 : hasTransmissionTimeOffset(false),
22 transmissionTimeOffset(0), 23 transmissionTimeOffset(0),
23 hasAbsoluteSendTime(false), 24 hasAbsoluteSendTime(false),
(...skipping 28 matching lines...) Expand all
52 startBitrate(0), 53 startBitrate(0),
53 maxBitrate(0), 54 maxBitrate(0),
54 minBitrate(0), 55 minBitrate(0),
55 targetBitrate(0), 56 targetBitrate(0),
56 maxFramerate(0), 57 maxFramerate(0),
57 qpMax(0), 58 qpMax(0),
58 numberOfSimulcastStreams(0), 59 numberOfSimulcastStreams(0),
59 simulcastStream(), 60 simulcastStream(),
60 spatialLayers(), 61 spatialLayers(),
61 mode(kRealtimeVideo), 62 mode(kRealtimeVideo),
63 expect_encode_from_texture(false),
62 codecSpecific() {} 64 codecSpecific() {}
63 65
64 VideoCodecVP8* VideoCodec::VP8() { 66 VideoCodecVP8* VideoCodec::VP8() {
65 RTC_DCHECK_EQ(codecType, kVideoCodecVP8); 67 RTC_DCHECK_EQ(codecType, kVideoCodecVP8);
66 return &codecSpecific.VP8; 68 return &codecSpecific.VP8;
67 } 69 }
68 70
69 const VideoCodecVP8& VideoCodec::VP8() const { 71 const VideoCodecVP8& VideoCodec::VP8() const {
70 RTC_DCHECK_EQ(codecType, kVideoCodecVP8); 72 RTC_DCHECK_EQ(codecType, kVideoCodecVP8);
71 return codecSpecific.VP8; 73 return codecSpecific.VP8;
(...skipping 12 matching lines...) Expand all
84 VideoCodecH264* VideoCodec::H264() { 86 VideoCodecH264* VideoCodec::H264() {
85 RTC_DCHECK_EQ(codecType, kVideoCodecH264); 87 RTC_DCHECK_EQ(codecType, kVideoCodecH264);
86 return &codecSpecific.H264; 88 return &codecSpecific.H264;
87 } 89 }
88 90
89 const VideoCodecH264& VideoCodec::H264() const { 91 const VideoCodecH264& VideoCodec::H264() const {
90 RTC_DCHECK_EQ(codecType, kVideoCodecH264); 92 RTC_DCHECK_EQ(codecType, kVideoCodecH264);
91 return codecSpecific.H264; 93 return codecSpecific.H264;
92 } 94 }
93 95
96 static const char* kPayloadNameVp8 = "VP8";
97 static const char* kPayloadNameVp9 = "VP9";
98 static const char* kPayloadNameH264 = "H264";
99 static const char* kPayloadNameI420 = "I420";
100 static const char* kPayloadNameRED = "RED";
101 static const char* kPayloadNameULPFEC = "ULPFEC";
102 static const char* kPayloadNameGeneric = "Generic";
103
104 rtc::Optional<std::string> CodecTypeToPayloadName(VideoCodecType type) {
105 switch (type) {
106 case kVideoCodecVP8:
107 return rtc::Optional<std::string>(kPayloadNameVp8);
108 case kVideoCodecVP9:
109 return rtc::Optional<std::string>(kPayloadNameVp9);
110 case kVideoCodecH264:
111 return rtc::Optional<std::string>(kPayloadNameH264);
112 case kVideoCodecI420:
113 return rtc::Optional<std::string>(kPayloadNameI420);
114 case kVideoCodecRED:
115 return rtc::Optional<std::string>(kPayloadNameRED);
116 case kVideoCodecULPFEC:
117 return rtc::Optional<std::string>(kPayloadNameULPFEC);
118 case kVideoCodecGeneric:
119 return rtc::Optional<std::string>(kPayloadNameGeneric);
120 default:
121 return rtc::Optional<std::string>();
122 }
123 }
124
125 rtc::Optional<VideoCodecType> PayloadNameToCodecType(const std::string& name) {
126 if (name == kPayloadNameVp8)
127 return rtc::Optional<VideoCodecType>(kVideoCodecVP8);
128 if (name == kPayloadNameVp9)
129 return rtc::Optional<VideoCodecType>(kVideoCodecVP9);
130 if (name == kPayloadNameH264)
131 return rtc::Optional<VideoCodecType>(kVideoCodecH264);
132 if (name == kPayloadNameI420)
133 return rtc::Optional<VideoCodecType>(kVideoCodecI420);
134 if (name == kPayloadNameRED)
135 return rtc::Optional<VideoCodecType>(kVideoCodecRED);
136 if (name == kPayloadNameULPFEC)
137 return rtc::Optional<VideoCodecType>(kVideoCodecULPFEC);
138 if (name == kPayloadNameGeneric)
139 return rtc::Optional<VideoCodecType>(kVideoCodecGeneric);
140 return rtc::Optional<VideoCodecType>();
141 }
142
143 const uint32_t BitrateAllocation::kMaxBitrateBps =
144 std::numeric_limits<uint32_t>::max();
145
146 BitrateAllocation::BitrateAllocation() : sum_(0), bitrates_{} {}
147
148 bool BitrateAllocation::SetBitrate(size_t spatial_index,
149 size_t temporal_index,
150 uint32_t bitrate_bps) {
151 RTC_DCHECK_LT(spatial_index, static_cast<size_t>(kMaxSpatialLayers));
152 RTC_DCHECK_LT(temporal_index, static_cast<size_t>(kMaxTemporalStreams));
153 RTC_DCHECK_LE(bitrates_[spatial_index][temporal_index], sum_);
154 uint64_t new_bitrate_sum_bps = sum_;
155 new_bitrate_sum_bps -= bitrates_[spatial_index][temporal_index];
156 new_bitrate_sum_bps += bitrate_bps;
157 if (new_bitrate_sum_bps > kMaxBitrateBps)
158 return false;
159
160 bitrates_[spatial_index][temporal_index] = bitrate_bps;
161 sum_ = static_cast<uint32_t>(new_bitrate_sum_bps);
162 return true;
163 }
164
165 uint32_t BitrateAllocation::GetBitrate(size_t spatial_index,
166 size_t temporal_index) const {
167 RTC_DCHECK_LT(spatial_index, static_cast<size_t>(kMaxSpatialLayers));
168 RTC_DCHECK_LT(temporal_index, static_cast<size_t>(kMaxTemporalStreams));
169 return bitrates_[spatial_index][temporal_index];
170 }
171
172 // Get the sum of all the temporal layer for a specific spatial layer.
173 uint32_t BitrateAllocation::GetSpatialLayerSum(size_t spatial_index) const {
174 RTC_DCHECK_LT(spatial_index, static_cast<size_t>(kMaxSpatialLayers));
175 uint32_t sum = 0;
176 for (int i = 0; i < kMaxTemporalStreams; ++i)
177 sum += bitrates_[spatial_index][i];
178 return sum;
179 }
180
94 } // namespace webrtc 181 } // namespace webrtc
OLDNEW
« 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