| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 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/call/flexfec_receive_stream.h" | 11 #include "webrtc/call/flexfec_receive_stream.h" |
| 12 | 12 |
| 13 #include <utility> |
| 14 |
| 13 #include "webrtc/base/checks.h" | 15 #include "webrtc/base/checks.h" |
| 14 #include "webrtc/base/logging.h" | 16 #include "webrtc/base/logging.h" |
| 15 | 17 |
| 16 namespace webrtc { | 18 namespace webrtc { |
| 17 | 19 |
| 18 std::string FlexfecReceiveStream::Stats::ToString(int64_t time_ms) const { | 20 std::string FlexfecReceiveStream::Stats::ToString(int64_t time_ms) const { |
| 19 std::stringstream ss; | 21 std::stringstream ss; |
| 20 ss << "FlexfecReceiveStream stats: " << time_ms | 22 ss << "FlexfecReceiveStream stats: " << time_ms |
| 21 << ", {flexfec_bitrate_bps: " << flexfec_bitrate_bps << "}"; | 23 << ", {flexfec_bitrate_bps: " << flexfec_bitrate_bps << "}"; |
| 22 return ss.str(); | 24 return ss.str(); |
| 23 } | 25 } |
| 24 | 26 |
| 25 std::string FlexfecReceiveStream::Config::ToString() const { | 27 std::string FlexfecReceiveStream::Config::ToString() const { |
| 26 std::stringstream ss; | 28 std::stringstream ss; |
| 27 ss << "{payload_type: " << payload_type; | 29 ss << "{payload_type: " << payload_type; |
| 28 ss << ", remote_ssrc: " << remote_ssrc; | 30 ss << ", remote_ssrc: " << remote_ssrc; |
| 29 ss << ", local_ssrc: " << local_ssrc; | 31 ss << ", local_ssrc: " << local_ssrc; |
| 30 ss << ", protected_media_ssrcs: ["; | 32 ss << ", protected_media_ssrcs: ["; |
| 31 size_t i = 0; | 33 size_t i = 0; |
| 32 for (; i + 1 < protected_media_ssrcs.size(); ++i) | 34 for (; i + 1 < protected_media_ssrcs.size(); ++i) |
| 33 ss << protected_media_ssrcs[i] << ", "; | 35 ss << protected_media_ssrcs[i] << ", "; |
| 34 if (!protected_media_ssrcs.empty()) | 36 if (!protected_media_ssrcs.empty()) |
| 35 ss << protected_media_ssrcs[i]; | 37 ss << protected_media_ssrcs[i]; |
| 36 ss << "], transport_cc: " << (transport_cc ? "on" : "off"); | 38 ss << "], transport_cc: " << (transport_cc ? "on" : "off"); |
| 37 ss << ", extensions: ["; | 39 ss << ", rtp_header_extensions: ["; |
| 38 i = 0; | 40 i = 0; |
| 39 for (; i + 1 < extensions.size(); ++i) | 41 for (; i + 1 < rtp_header_extensions.size(); ++i) |
| 40 ss << extensions[i].ToString() << ", "; | 42 ss << rtp_header_extensions[i].ToString() << ", "; |
| 41 if (!extensions.empty()) | 43 if (!rtp_header_extensions.empty()) |
| 42 ss << extensions[i].ToString(); | 44 ss << rtp_header_extensions[i].ToString(); |
| 43 ss << "]}"; | 45 ss << "]}"; |
| 44 return ss.str(); | 46 return ss.str(); |
| 45 } | 47 } |
| 46 | 48 |
| 47 namespace { | 49 namespace { |
| 48 | 50 |
| 49 // TODO(brandtr): Update this function when we support multistream protection. | 51 // TODO(brandtr): Update this function when we support multistream protection. |
| 50 std::unique_ptr<FlexfecReceiver> MaybeCreateFlexfecReceiver( | 52 std::unique_ptr<FlexfecReceiver> MaybeCreateFlexfecReceiver( |
| 51 const FlexfecReceiveStream::Config& config, | 53 const FlexfecReceiveStream::Config& config, |
| 52 RecoveredPacketReceiver* recovered_packet_callback) { | 54 RecoveredPacketReceiver* recovered_packet_receiver, |
| 55 RemoteBitrateEstimator* remote_bitrate_estimator) { |
| 53 if (config.payload_type < 0) { | 56 if (config.payload_type < 0) { |
| 54 LOG(LS_WARNING) << "Invalid FlexFEC payload type given. " | 57 LOG(LS_WARNING) << "Invalid FlexFEC payload type given. " |
| 55 << "This FlexfecReceiveStream will therefore be useless."; | 58 << "This FlexfecReceiveStream will therefore be useless."; |
| 56 return nullptr; | 59 return nullptr; |
| 57 } | 60 } |
| 58 RTC_DCHECK_GE(config.payload_type, 0); | 61 RTC_DCHECK_GE(config.payload_type, 0); |
| 59 RTC_DCHECK_LE(config.payload_type, 127); | 62 RTC_DCHECK_LE(config.payload_type, 127); |
| 60 if (config.remote_ssrc == 0) { | 63 if (config.remote_ssrc == 0) { |
| 61 LOG(LS_WARNING) << "Invalid FlexFEC SSRC given. " | 64 LOG(LS_WARNING) << "Invalid FlexFEC SSRC given. " |
| 62 << "This FlexfecReceiveStream will therefore be useless."; | 65 << "This FlexfecReceiveStream will therefore be useless."; |
| 63 return nullptr; | 66 return nullptr; |
| 64 } | 67 } |
| 65 if (config.protected_media_ssrcs.empty()) { | 68 if (config.protected_media_ssrcs.empty()) { |
| 66 LOG(LS_WARNING) << "No protected media SSRC supplied. " | 69 LOG(LS_WARNING) << "No protected media SSRC supplied. " |
| 67 << "This FlexfecReceiveStream will therefore be useless."; | 70 << "This FlexfecReceiveStream will therefore be useless."; |
| 68 return nullptr; | 71 return nullptr; |
| 69 } | 72 } |
| 70 | 73 |
| 71 if (config.protected_media_ssrcs.size() > 1) { | 74 if (config.protected_media_ssrcs.size() > 1) { |
| 72 LOG(LS_WARNING) | 75 LOG(LS_WARNING) |
| 73 << "The supplied FlexfecConfig contained multiple protected " | 76 << "The supplied FlexfecConfig contained multiple protected " |
| 74 "media streams, but our implementation currently only " | 77 "media streams, but our implementation currently only " |
| 75 "supports protecting a single media stream. " | 78 "supports protecting a single media stream. " |
| 76 "To avoid confusion, disabling FlexFEC completely."; | 79 "To avoid confusion, disabling FlexFEC completely."; |
| 77 return nullptr; | 80 return nullptr; |
| 78 } | 81 } |
| 79 RTC_DCHECK_EQ(1U, config.protected_media_ssrcs.size()); | 82 RTC_DCHECK_EQ(1U, config.protected_media_ssrcs.size()); |
| 80 return std::unique_ptr<FlexfecReceiver>( | 83 return std::unique_ptr<FlexfecReceiver>( |
| 81 new FlexfecReceiver(config.remote_ssrc, config.protected_media_ssrcs[0], | 84 new FlexfecReceiver(config.remote_ssrc, config.protected_media_ssrcs[0], |
| 82 recovered_packet_callback)); | 85 recovered_packet_receiver, remote_bitrate_estimator)); |
| 83 } | 86 } |
| 84 | 87 |
| 85 } // namespace | 88 } // namespace |
| 86 | 89 |
| 87 namespace internal { | 90 namespace internal { |
| 88 | 91 |
| 89 FlexfecReceiveStream::FlexfecReceiveStream( | 92 FlexfecReceiveStream::FlexfecReceiveStream( |
| 90 const Config& config, | 93 const Config& config, |
| 91 RecoveredPacketReceiver* recovered_packet_callback) | 94 RecoveredPacketReceiver* recovered_packet_receiver, |
| 95 RemoteBitrateEstimator* remote_bitrate_estimator) |
| 92 : started_(false), | 96 : started_(false), |
| 93 config_(config), | 97 config_(config), |
| 94 receiver_( | 98 receiver_(MaybeCreateFlexfecReceiver(config_, |
| 95 MaybeCreateFlexfecReceiver(config_, recovered_packet_callback)) { | 99 recovered_packet_receiver, |
| 100 remote_bitrate_estimator)) { |
| 96 LOG(LS_INFO) << "FlexfecReceiveStream: " << config_.ToString(); | 101 LOG(LS_INFO) << "FlexfecReceiveStream: " << config_.ToString(); |
| 97 } | 102 } |
| 98 | 103 |
| 99 FlexfecReceiveStream::~FlexfecReceiveStream() { | 104 FlexfecReceiveStream::~FlexfecReceiveStream() { |
| 100 LOG(LS_INFO) << "~FlexfecReceiveStream: " << config_.ToString(); | 105 LOG(LS_INFO) << "~FlexfecReceiveStream: " << config_.ToString(); |
| 101 Stop(); | 106 Stop(); |
| 102 } | 107 } |
| 103 | 108 |
| 104 bool FlexfecReceiveStream::AddAndProcessReceivedPacket(const uint8_t* packet, | 109 bool FlexfecReceiveStream::AddAndProcessReceivedPacket( |
| 105 size_t packet_length) { | 110 RtpPacketReceived packet) { |
| 106 { | 111 { |
| 107 rtc::CritScope cs(&crit_); | 112 rtc::CritScope cs(&crit_); |
| 108 if (!started_) | 113 if (!started_) |
| 109 return false; | 114 return false; |
| 110 } | 115 } |
| 111 if (!receiver_) | 116 if (!receiver_) |
| 112 return false; | 117 return false; |
| 113 return receiver_->AddAndProcessReceivedPacket(packet, packet_length); | 118 return receiver_->AddAndProcessReceivedPacket(std::move(packet)); |
| 114 } | 119 } |
| 115 | 120 |
| 116 void FlexfecReceiveStream::Start() { | 121 void FlexfecReceiveStream::Start() { |
| 117 rtc::CritScope cs(&crit_); | 122 rtc::CritScope cs(&crit_); |
| 118 started_ = true; | 123 started_ = true; |
| 119 } | 124 } |
| 120 | 125 |
| 121 void FlexfecReceiveStream::Stop() { | 126 void FlexfecReceiveStream::Stop() { |
| 122 rtc::CritScope cs(&crit_); | 127 rtc::CritScope cs(&crit_); |
| 123 started_ = false; | 128 started_ = false; |
| 124 } | 129 } |
| 125 | 130 |
| 126 // TODO(brandtr): Implement this member function when we have designed the | 131 // TODO(brandtr): Implement this member function when we have designed the |
| 127 // stats for FlexFEC. | 132 // stats for FlexFEC. |
| 128 FlexfecReceiveStream::Stats FlexfecReceiveStream::GetStats() const { | 133 FlexfecReceiveStream::Stats FlexfecReceiveStream::GetStats() const { |
| 129 return webrtc::FlexfecReceiveStream::Stats(); | 134 return webrtc::FlexfecReceiveStream::Stats(); |
| 130 } | 135 } |
| 131 | 136 |
| 132 } // namespace internal | 137 } // namespace internal |
| 133 | 138 |
| 134 } // namespace webrtc | 139 } // namespace webrtc |
| OLD | NEW |