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

Side by Side Diff: webrtc/common_types.cc

Issue 2434073003: Extract bitrate allocation of spatial/temporal layers out of codec impl. (Closed)
Patch Set: Addressed comments. Moved VideoCodec creation to factory class. 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
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 "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...
15
14 #include <string.h> 16 #include <string.h>
15 17
16 namespace webrtc { 18 namespace webrtc {
17 19
18 StreamDataCounters::StreamDataCounters() : first_packet_time_ms(-1) {} 20 StreamDataCounters::StreamDataCounters() : first_packet_time_ms(-1) {}
19 21
20 RTPHeaderExtension::RTPHeaderExtension() 22 RTPHeaderExtension::RTPHeaderExtension()
21 : hasTransmissionTimeOffset(false), 23 : hasTransmissionTimeOffset(false),
22 transmissionTimeOffset(0), 24 transmissionTimeOffset(0),
23 hasAbsoluteSendTime(false), 25 hasAbsoluteSendTime(false),
(...skipping 28 matching lines...) Expand all
52 startBitrate(0), 54 startBitrate(0),
53 maxBitrate(0), 55 maxBitrate(0),
54 minBitrate(0), 56 minBitrate(0),
55 targetBitrate(0), 57 targetBitrate(0),
56 maxFramerate(0), 58 maxFramerate(0),
57 qpMax(0), 59 qpMax(0),
58 numberOfSimulcastStreams(0), 60 numberOfSimulcastStreams(0),
59 simulcastStream(), 61 simulcastStream(),
60 spatialLayers(), 62 spatialLayers(),
61 mode(kRealtimeVideo), 63 mode(kRealtimeVideo),
64 expect_encode_from_texture(false),
62 codecSpecific() {} 65 codecSpecific() {}
63 66
64 VideoCodecVP8* VideoCodec::VP8() { 67 VideoCodecVP8* VideoCodec::VP8() {
65 RTC_DCHECK_EQ(codecType, kVideoCodecVP8); 68 RTC_DCHECK_EQ(codecType, kVideoCodecVP8);
66 return &codecSpecific.VP8; 69 return &codecSpecific.VP8;
67 } 70 }
68 71
69 const VideoCodecVP8& VideoCodec::VP8() const { 72 const VideoCodecVP8& VideoCodec::VP8() const {
70 RTC_DCHECK_EQ(codecType, kVideoCodecVP8); 73 RTC_DCHECK_EQ(codecType, kVideoCodecVP8);
71 return codecSpecific.VP8; 74 return codecSpecific.VP8;
(...skipping 12 matching lines...) Expand all
84 VideoCodecH264* VideoCodec::H264() { 87 VideoCodecH264* VideoCodec::H264() {
85 RTC_DCHECK_EQ(codecType, kVideoCodecH264); 88 RTC_DCHECK_EQ(codecType, kVideoCodecH264);
86 return &codecSpecific.H264; 89 return &codecSpecific.H264;
87 } 90 }
88 91
89 const VideoCodecH264& VideoCodec::H264() const { 92 const VideoCodecH264& VideoCodec::H264() const {
90 RTC_DCHECK_EQ(codecType, kVideoCodecH264); 93 RTC_DCHECK_EQ(codecType, kVideoCodecH264);
91 return codecSpecific.H264; 94 return codecSpecific.H264;
92 } 95 }
93 96
97 static const char* kPayloadNameVp8 = "VP8";
98 static const char* kPayloadNameVp9 = "VP9";
99 static const char* kPayloadNameH264 = "H264";
100 static const char* kPayloadNameI420 = "I420";
101 static const char* kPayloadNameRED = "RED";
102 static const char* kPayloadNameULPFEC = "ULPFEC";
103 static const char* kPayloadNameGeneric = "Generic";
104
105 rtc::Optional<std::string> CodecTypeToPayloadName(VideoCodecType type) {
106 switch (type) {
107 case kVideoCodecVP8:
108 return rtc::Optional<std::string>(kPayloadNameVp8);
109 case kVideoCodecVP9:
110 return rtc::Optional<std::string>(kPayloadNameVp9);
111 case kVideoCodecH264:
112 return rtc::Optional<std::string>(kPayloadNameH264);
113 case kVideoCodecI420:
114 return rtc::Optional<std::string>(kPayloadNameI420);
115 case kVideoCodecRED:
116 return rtc::Optional<std::string>(kPayloadNameRED);
117 case kVideoCodecULPFEC:
118 return rtc::Optional<std::string>(kPayloadNameULPFEC);
119 case kVideoCodecGeneric:
120 return rtc::Optional<std::string>(kPayloadNameGeneric);
121 default:
122 return rtc::Optional<std::string>();
123 }
124 }
125
126 rtc::Optional<VideoCodecType> PayloadNameToCodecType(const std::string& name) {
127 if (name == kPayloadNameVp8)
128 return rtc::Optional<VideoCodecType>(kVideoCodecVP8);
129 if (name == kPayloadNameVp9)
130 return rtc::Optional<VideoCodecType>(kVideoCodecVP9);
131 if (name == kPayloadNameH264)
132 return rtc::Optional<VideoCodecType>(kVideoCodecH264);
133 if (name == kPayloadNameI420)
134 return rtc::Optional<VideoCodecType>(kVideoCodecI420);
135 if (name == kPayloadNameRED)
136 return rtc::Optional<VideoCodecType>(kVideoCodecRED);
137 if (name == kPayloadNameULPFEC)
138 return rtc::Optional<VideoCodecType>(kVideoCodecULPFEC);
139 if (name == kPayloadNameGeneric)
140 return rtc::Optional<VideoCodecType>(kVideoCodecGeneric);
141 return rtc::Optional<VideoCodecType>();
142 }
143
144 BitrateAllocation::BitrateAllocation() : sum_(0), bitrates_{} {}
145
146 bool BitrateAllocation::SetBitrate(size_t spatial_index,
147 size_t temporal_index,
148 uint32_t bitrate_bps) {
149 RTC_DCHECK_LT(spatial_index, static_cast<size_t>(kMaxSpatialLayers));
150 RTC_DCHECK_LT(temporal_index, static_cast<size_t>(kMaxTemporalStreams));
151 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.
152 sum_ - bitrates_[spatial_index][temporal_index] + bitrate_bps >
153 kMaxBitrateBps) {
154 return false;
155 }
156 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.
157 bitrates_[spatial_index][temporal_index] = bitrate_bps;
158 sum_ += bitrate_bps;
159 return true;
160 }
161
162 uint32_t BitrateAllocation::GetBitrate(size_t spatial_index,
163 size_t temporal_index) const {
164 RTC_DCHECK_LT(spatial_index, static_cast<size_t>(kMaxSpatialLayers));
165 RTC_DCHECK_LT(temporal_index, static_cast<size_t>(kMaxTemporalStreams));
166 return bitrates_[spatial_index][temporal_index];
167 }
168
169 // Get the sum of all the temporal layer for a specific spatial layer.
170 uint32_t BitrateAllocation::GetSpatialLayerSum(size_t spatial_index) const {
171 RTC_DCHECK_LT(spatial_index, static_cast<size_t>(kMaxSpatialLayers));
172 uint32_t sum = 0;
173 for (int i = 0; i < kMaxTemporalStreams; ++i)
174 sum += bitrates_[spatial_index][i];
175 return sum;
176 }
177
94 } // namespace webrtc 178 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698