| 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 |
| 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) { |
| 53 if (config.payload_type < 0) { | 55 if (config.payload_type < 0) { |
| 54 LOG(LS_WARNING) << "Invalid FlexFEC payload type given. " | 56 LOG(LS_WARNING) << "Invalid FlexFEC payload type given. " |
| 55 << "This FlexfecReceiveStream will therefore be useless."; | 57 << "This FlexfecReceiveStream will therefore be useless."; |
| 56 return nullptr; | 58 return nullptr; |
| 57 } | 59 } |
| 58 RTC_DCHECK_GE(config.payload_type, 0); | 60 RTC_DCHECK_GE(config.payload_type, 0); |
| 59 RTC_DCHECK_LE(config.payload_type, 127); | 61 RTC_DCHECK_LE(config.payload_type, 127); |
| 60 if (config.remote_ssrc == 0) { | 62 if (config.remote_ssrc == 0) { |
| 61 LOG(LS_WARNING) << "Invalid FlexFEC SSRC given. " | 63 LOG(LS_WARNING) << "Invalid FlexFEC SSRC given. " |
| 62 << "This FlexfecReceiveStream will therefore be useless."; | 64 << "This FlexfecReceiveStream will therefore be useless."; |
| 63 return nullptr; | 65 return nullptr; |
| 64 } | 66 } |
| 65 if (config.protected_media_ssrcs.empty()) { | 67 if (config.protected_media_ssrcs.empty()) { |
| 66 LOG(LS_WARNING) << "No protected media SSRC supplied. " | 68 LOG(LS_WARNING) << "No protected media SSRC supplied. " |
| 67 << "This FlexfecReceiveStream will therefore be useless."; | 69 << "This FlexfecReceiveStream will therefore be useless."; |
| 68 return nullptr; | 70 return nullptr; |
| 69 } | 71 } |
| 70 | 72 |
| 71 if (config.protected_media_ssrcs.size() > 1) { | 73 if (config.protected_media_ssrcs.size() > 1) { |
| 72 LOG(LS_WARNING) | 74 LOG(LS_WARNING) |
| 73 << "The supplied FlexfecConfig contained multiple protected " | 75 << "The supplied FlexfecConfig contained multiple protected " |
| 74 "media streams, but our implementation currently only " | 76 "media streams, but our implementation currently only " |
| 75 "supports protecting a single media stream. " | 77 "supports protecting a single media stream. " |
| 76 "To avoid confusion, disabling FlexFEC completely."; | 78 "To avoid confusion, disabling FlexFEC completely."; |
| 77 return nullptr; | 79 return nullptr; |
| 78 } | 80 } |
| 79 RTC_DCHECK_EQ(1U, config.protected_media_ssrcs.size()); | 81 RTC_DCHECK_EQ(1U, config.protected_media_ssrcs.size()); |
| 80 return std::unique_ptr<FlexfecReceiver>( | 82 return std::unique_ptr<FlexfecReceiver>( |
| 81 new FlexfecReceiver(config.remote_ssrc, config.protected_media_ssrcs[0], | 83 new FlexfecReceiver(config.remote_ssrc, config.protected_media_ssrcs[0], |
| 82 recovered_packet_callback)); | 84 recovered_packet_receiver)); |
| 83 } | 85 } |
| 84 | 86 |
| 85 } // namespace | 87 } // namespace |
| 86 | 88 |
| 87 FlexfecReceiveStreamImpl::FlexfecReceiveStreamImpl( | 89 FlexfecReceiveStreamImpl::FlexfecReceiveStreamImpl( |
| 88 const Config& config, | 90 const Config& config, |
| 89 RecoveredPacketReceiver* recovered_packet_callback) | 91 RecoveredPacketReceiver* recovered_packet_receiver) |
| 90 : started_(false), | 92 : started_(false), |
| 91 config_(config), | 93 config_(config), |
| 92 receiver_( | 94 receiver_( |
| 93 MaybeCreateFlexfecReceiver(config_, recovered_packet_callback)) { | 95 MaybeCreateFlexfecReceiver(config_, recovered_packet_receiver)) { |
| 94 LOG(LS_INFO) << "FlexfecReceiveStreamImpl: " << config_.ToString(); | 96 LOG(LS_INFO) << "FlexfecReceiveStreamImpl: " << config_.ToString(); |
| 95 } | 97 } |
| 96 | 98 |
| 97 FlexfecReceiveStreamImpl::~FlexfecReceiveStreamImpl() { | 99 FlexfecReceiveStreamImpl::~FlexfecReceiveStreamImpl() { |
| 98 LOG(LS_INFO) << "~FlexfecReceiveStreamImpl: " << config_.ToString(); | 100 LOG(LS_INFO) << "~FlexfecReceiveStreamImpl: " << config_.ToString(); |
| 99 Stop(); | 101 Stop(); |
| 100 } | 102 } |
| 101 | 103 |
| 102 bool FlexfecReceiveStreamImpl::AddAndProcessReceivedPacket( | 104 bool FlexfecReceiveStreamImpl::AddAndProcessReceivedPacket( |
| 103 const uint8_t* packet, | 105 RtpPacketReceived packet) { |
| 104 size_t packet_length) { | |
| 105 { | 106 { |
| 106 rtc::CritScope cs(&crit_); | 107 rtc::CritScope cs(&crit_); |
| 107 if (!started_) | 108 if (!started_) |
| 108 return false; | 109 return false; |
| 109 } | 110 } |
| 110 if (!receiver_) | 111 if (!receiver_) |
| 111 return false; | 112 return false; |
| 112 return receiver_->AddAndProcessReceivedPacket(packet, packet_length); | 113 return receiver_->AddAndProcessReceivedPacket(std::move(packet)); |
| 113 } | 114 } |
| 114 | 115 |
| 115 void FlexfecReceiveStreamImpl::Start() { | 116 void FlexfecReceiveStreamImpl::Start() { |
| 116 rtc::CritScope cs(&crit_); | 117 rtc::CritScope cs(&crit_); |
| 117 started_ = true; | 118 started_ = true; |
| 118 } | 119 } |
| 119 | 120 |
| 120 void FlexfecReceiveStreamImpl::Stop() { | 121 void FlexfecReceiveStreamImpl::Stop() { |
| 121 rtc::CritScope cs(&crit_); | 122 rtc::CritScope cs(&crit_); |
| 122 started_ = false; | 123 started_ = false; |
| 123 } | 124 } |
| 124 | 125 |
| 125 // TODO(brandtr): Implement this member function when we have designed the | 126 // TODO(brandtr): Implement this member function when we have designed the |
| 126 // stats for FlexFEC. | 127 // stats for FlexFEC. |
| 127 FlexfecReceiveStreamImpl::Stats FlexfecReceiveStreamImpl::GetStats() const { | 128 FlexfecReceiveStreamImpl::Stats FlexfecReceiveStreamImpl::GetStats() const { |
| 128 return FlexfecReceiveStream::Stats(); | 129 return FlexfecReceiveStream::Stats(); |
| 129 } | 130 } |
| 130 | 131 |
| 131 } // namespace webrtc | 132 } // namespace webrtc |
| OLD | NEW |