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