2016-10-20 04:54:48 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2016-12-19 01:13:46 -08:00
|
|
|
#include "webrtc/call/flexfec_receive_stream_impl.h"
|
2016-10-20 04:54:48 -07:00
|
|
|
|
2016-12-21 06:37:18 -08:00
|
|
|
#include <utility>
|
|
|
|
|
|
2016-10-20 04:54:48 -07:00
|
|
|
#include "webrtc/base/checks.h"
|
|
|
|
|
#include "webrtc/base/logging.h"
|
|
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
std::string FlexfecReceiveStream::Stats::ToString(int64_t time_ms) const {
|
|
|
|
|
std::stringstream ss;
|
|
|
|
|
ss << "FlexfecReceiveStream stats: " << time_ms
|
|
|
|
|
<< ", {flexfec_bitrate_bps: " << flexfec_bitrate_bps << "}";
|
|
|
|
|
return ss.str();
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-08 04:17:53 -08:00
|
|
|
std::string FlexfecReceiveStream::Config::ToString() const {
|
|
|
|
|
std::stringstream ss;
|
|
|
|
|
ss << "{payload_type: " << payload_type;
|
|
|
|
|
ss << ", remote_ssrc: " << remote_ssrc;
|
|
|
|
|
ss << ", local_ssrc: " << local_ssrc;
|
|
|
|
|
ss << ", protected_media_ssrcs: [";
|
|
|
|
|
size_t i = 0;
|
|
|
|
|
for (; i + 1 < protected_media_ssrcs.size(); ++i)
|
|
|
|
|
ss << protected_media_ssrcs[i] << ", ";
|
|
|
|
|
if (!protected_media_ssrcs.empty())
|
|
|
|
|
ss << protected_media_ssrcs[i];
|
|
|
|
|
ss << "], transport_cc: " << (transport_cc ? "on" : "off");
|
2016-12-21 06:37:18 -08:00
|
|
|
ss << ", rtp_header_extensions: [";
|
2016-12-08 04:17:53 -08:00
|
|
|
i = 0;
|
2016-12-21 06:37:18 -08:00
|
|
|
for (; i + 1 < rtp_header_extensions.size(); ++i)
|
|
|
|
|
ss << rtp_header_extensions[i].ToString() << ", ";
|
|
|
|
|
if (!rtp_header_extensions.empty())
|
|
|
|
|
ss << rtp_header_extensions[i].ToString();
|
2016-12-08 04:17:53 -08:00
|
|
|
ss << "]}";
|
|
|
|
|
return ss.str();
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-20 04:54:48 -07:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
// TODO(brandtr): Update this function when we support multistream protection.
|
2016-11-15 05:26:45 -08:00
|
|
|
std::unique_ptr<FlexfecReceiver> MaybeCreateFlexfecReceiver(
|
|
|
|
|
const FlexfecReceiveStream::Config& config,
|
2016-12-21 06:37:18 -08:00
|
|
|
RecoveredPacketReceiver* recovered_packet_receiver) {
|
2016-12-08 04:17:53 -08:00
|
|
|
if (config.payload_type < 0) {
|
2016-11-15 05:26:45 -08:00
|
|
|
LOG(LS_WARNING) << "Invalid FlexFEC payload type given. "
|
|
|
|
|
<< "This FlexfecReceiveStream will therefore be useless.";
|
2016-10-20 04:54:48 -07:00
|
|
|
return nullptr;
|
2016-11-15 05:26:45 -08:00
|
|
|
}
|
2016-12-08 04:17:53 -08:00
|
|
|
RTC_DCHECK_GE(config.payload_type, 0);
|
|
|
|
|
RTC_DCHECK_LE(config.payload_type, 127);
|
|
|
|
|
if (config.remote_ssrc == 0) {
|
2016-11-15 05:26:45 -08:00
|
|
|
LOG(LS_WARNING) << "Invalid FlexFEC SSRC given. "
|
|
|
|
|
<< "This FlexfecReceiveStream will therefore be useless.";
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
if (config.protected_media_ssrcs.empty()) {
|
|
|
|
|
LOG(LS_WARNING) << "No protected media SSRC supplied. "
|
|
|
|
|
<< "This FlexfecReceiveStream will therefore be useless.";
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (config.protected_media_ssrcs.size() > 1) {
|
2016-10-20 04:54:48 -07:00
|
|
|
LOG(LS_WARNING)
|
|
|
|
|
<< "The supplied FlexfecConfig contained multiple protected "
|
|
|
|
|
"media streams, but our implementation currently only "
|
2016-11-15 05:26:45 -08:00
|
|
|
"supports protecting a single media stream. "
|
|
|
|
|
"To avoid confusion, disabling FlexFEC completely.";
|
|
|
|
|
return nullptr;
|
2016-10-20 04:54:48 -07:00
|
|
|
}
|
2016-11-15 05:26:45 -08:00
|
|
|
RTC_DCHECK_EQ(1U, config.protected_media_ssrcs.size());
|
|
|
|
|
return std::unique_ptr<FlexfecReceiver>(
|
2016-12-08 04:17:53 -08:00
|
|
|
new FlexfecReceiver(config.remote_ssrc, config.protected_media_ssrcs[0],
|
2016-12-21 06:37:18 -08:00
|
|
|
recovered_packet_receiver));
|
2016-10-20 04:54:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
2016-12-19 01:13:46 -08:00
|
|
|
FlexfecReceiveStreamImpl::FlexfecReceiveStreamImpl(
|
2016-12-08 04:14:24 -08:00
|
|
|
const Config& config,
|
2016-12-21 06:37:18 -08:00
|
|
|
RecoveredPacketReceiver* recovered_packet_receiver)
|
2016-10-20 04:54:48 -07:00
|
|
|
: started_(false),
|
2016-12-08 04:14:24 -08:00
|
|
|
config_(config),
|
2016-11-15 05:26:45 -08:00
|
|
|
receiver_(
|
2016-12-21 06:37:18 -08:00
|
|
|
MaybeCreateFlexfecReceiver(config_, recovered_packet_receiver)) {
|
2016-12-19 01:13:46 -08:00
|
|
|
LOG(LS_INFO) << "FlexfecReceiveStreamImpl: " << config_.ToString();
|
2016-10-20 04:54:48 -07:00
|
|
|
}
|
|
|
|
|
|
2016-12-19 01:13:46 -08:00
|
|
|
FlexfecReceiveStreamImpl::~FlexfecReceiveStreamImpl() {
|
|
|
|
|
LOG(LS_INFO) << "~FlexfecReceiveStreamImpl: " << config_.ToString();
|
2016-10-20 04:54:48 -07:00
|
|
|
Stop();
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-19 01:13:46 -08:00
|
|
|
bool FlexfecReceiveStreamImpl::AddAndProcessReceivedPacket(
|
2016-12-21 06:37:18 -08:00
|
|
|
RtpPacketReceived packet) {
|
2016-10-20 04:54:48 -07:00
|
|
|
{
|
|
|
|
|
rtc::CritScope cs(&crit_);
|
|
|
|
|
if (!started_)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (!receiver_)
|
|
|
|
|
return false;
|
2016-12-21 06:37:18 -08:00
|
|
|
return receiver_->AddAndProcessReceivedPacket(std::move(packet));
|
2016-10-20 04:54:48 -07:00
|
|
|
}
|
|
|
|
|
|
2016-12-19 01:13:46 -08:00
|
|
|
void FlexfecReceiveStreamImpl::Start() {
|
2016-10-20 04:54:48 -07:00
|
|
|
rtc::CritScope cs(&crit_);
|
|
|
|
|
started_ = true;
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-19 01:13:46 -08:00
|
|
|
void FlexfecReceiveStreamImpl::Stop() {
|
2016-10-20 04:54:48 -07:00
|
|
|
rtc::CritScope cs(&crit_);
|
|
|
|
|
started_ = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO(brandtr): Implement this member function when we have designed the
|
|
|
|
|
// stats for FlexFEC.
|
2016-12-19 01:13:46 -08:00
|
|
|
FlexfecReceiveStreamImpl::Stats FlexfecReceiveStreamImpl::GetStats() const {
|
|
|
|
|
return FlexfecReceiveStream::Stats();
|
2016-10-20 04:54:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|