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