| OLD | NEW |
| 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> | |
| 15 #include <string.h> | 14 #include <string.h> |
| 16 | 15 |
| 17 namespace webrtc { | 16 namespace webrtc { |
| 18 | 17 |
| 19 StreamDataCounters::StreamDataCounters() : first_packet_time_ms(-1) {} | 18 StreamDataCounters::StreamDataCounters() : first_packet_time_ms(-1) {} |
| 20 | 19 |
| 21 RTPHeaderExtension::RTPHeaderExtension() | 20 RTPHeaderExtension::RTPHeaderExtension() |
| 22 : hasTransmissionTimeOffset(false), | 21 : hasTransmissionTimeOffset(false), |
| 23 transmissionTimeOffset(0), | 22 transmissionTimeOffset(0), |
| 24 hasAbsoluteSendTime(false), | 23 hasAbsoluteSendTime(false), |
| (...skipping 28 matching lines...) Expand all Loading... |
| 53 startBitrate(0), | 52 startBitrate(0), |
| 54 maxBitrate(0), | 53 maxBitrate(0), |
| 55 minBitrate(0), | 54 minBitrate(0), |
| 56 targetBitrate(0), | 55 targetBitrate(0), |
| 57 maxFramerate(0), | 56 maxFramerate(0), |
| 58 qpMax(0), | 57 qpMax(0), |
| 59 numberOfSimulcastStreams(0), | 58 numberOfSimulcastStreams(0), |
| 60 simulcastStream(), | 59 simulcastStream(), |
| 61 spatialLayers(), | 60 spatialLayers(), |
| 62 mode(kRealtimeVideo), | 61 mode(kRealtimeVideo), |
| 63 expect_encode_from_texture(false), | |
| 64 codecSpecific() {} | 62 codecSpecific() {} |
| 65 | 63 |
| 66 VideoCodecVP8* VideoCodec::VP8() { | 64 VideoCodecVP8* VideoCodec::VP8() { |
| 67 RTC_DCHECK_EQ(codecType, kVideoCodecVP8); | 65 RTC_DCHECK_EQ(codecType, kVideoCodecVP8); |
| 68 return &codecSpecific.VP8; | 66 return &codecSpecific.VP8; |
| 69 } | 67 } |
| 70 | 68 |
| 71 const VideoCodecVP8& VideoCodec::VP8() const { | 69 const VideoCodecVP8& VideoCodec::VP8() const { |
| 72 RTC_DCHECK_EQ(codecType, kVideoCodecVP8); | 70 RTC_DCHECK_EQ(codecType, kVideoCodecVP8); |
| 73 return codecSpecific.VP8; | 71 return codecSpecific.VP8; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 86 VideoCodecH264* VideoCodec::H264() { | 84 VideoCodecH264* VideoCodec::H264() { |
| 87 RTC_DCHECK_EQ(codecType, kVideoCodecH264); | 85 RTC_DCHECK_EQ(codecType, kVideoCodecH264); |
| 88 return &codecSpecific.H264; | 86 return &codecSpecific.H264; |
| 89 } | 87 } |
| 90 | 88 |
| 91 const VideoCodecH264& VideoCodec::H264() const { | 89 const VideoCodecH264& VideoCodec::H264() const { |
| 92 RTC_DCHECK_EQ(codecType, kVideoCodecH264); | 90 RTC_DCHECK_EQ(codecType, kVideoCodecH264); |
| 93 return codecSpecific.H264; | 91 return codecSpecific.H264; |
| 94 } | 92 } |
| 95 | 93 |
| 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 size_t BitrateAllocation::kMaxBitrateBps = | |
| 144 std::numeric_limits<size_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 | |
| 181 } // namespace webrtc | 94 } // namespace webrtc |
| OLD | NEW |