webrtc_m130/pc/channel.cc

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

1398 lines
50 KiB
C++
Raw Normal View History

/*
* Copyright 2004 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.
*/
#include "pc/channel.h"
#include <iterator>
#include <utility>
#include "absl/algorithm/container.h"
#include "absl/memory/memory.h"
#include "api/call/audio_sink.h"
#include "api/transport/media/media_transport_config.h"
#include "media/base/media_constants.h"
#include "media/base/rtp_utils.h"
#include "modules/rtp_rtcp/source/rtp_packet_received.h"
#include "p2p/base/packet_transport_internal.h"
#include "pc/channel_manager.h"
#include "pc/rtp_media_utils.h"
#include "rtc_base/bind.h"
#include "rtc_base/byte_order.h"
#include "rtc_base/checks.h"
#include "rtc_base/copy_on_write_buffer.h"
#include "rtc_base/dscp.h"
#include "rtc_base/logging.h"
#include "rtc_base/network_route.h"
#include "rtc_base/strings/string_builder.h"
#include "rtc_base/trace_event.h"
namespace cricket {
using rtc::Bind;
using rtc::UniqueRandomIdGenerator;
using webrtc::SdpType;
namespace {
struct SendPacketMessageData : public rtc::MessageData {
rtc::CopyOnWriteBuffer packet;
rtc::PacketOptions options;
};
// Finds a stream based on target's Primary SSRC or RIDs.
// This struct is used in BaseChannel::UpdateLocalStreams_w.
struct StreamFinder {
explicit StreamFinder(const StreamParams* target) : target_(target) {
RTC_DCHECK(target);
}
bool operator()(const StreamParams& sp) const {
if (target_->has_ssrcs() && sp.has_ssrcs()) {
return sp.has_ssrc(target_->first_ssrc());
}
if (!target_->has_rids() && !sp.has_rids()) {
return false;
}
const std::vector<RidDescription>& target_rids = target_->rids();
const std::vector<RidDescription>& source_rids = sp.rids();
if (source_rids.size() != target_rids.size()) {
return false;
}
// Check that all RIDs match.
return std::equal(source_rids.begin(), source_rids.end(),
target_rids.begin(),
[](const RidDescription& lhs, const RidDescription& rhs) {
return lhs.rid == rhs.rid;
});
}
const StreamParams* target_;
};
} // namespace
enum {
MSG_SEND_RTP_PACKET = 1,
MSG_SEND_RTCP_PACKET,
MSG_READYTOSENDDATA,
MSG_DATARECEIVED,
MSG_FIRSTPACKETRECEIVED,
};
static void SafeSetError(const std::string& message, std::string* error_desc) {
if (error_desc) {
*error_desc = message;
}
}
template <class Codec>
void RtpParametersFromMediaDescription(
const MediaContentDescriptionImpl<Codec>* desc,
const RtpHeaderExtensions& extensions,
RtpParameters<Codec>* params) {
// TODO(pthatcher): Remove this once we're sure no one will give us
// a description without codecs. Currently the ORTC implementation is relying
// on this.
if (desc->has_codecs()) {
params->codecs = desc->codecs();
}
// TODO(pthatcher): See if we really need
// rtp_header_extensions_set() and remove it if we don't.
if (desc->rtp_header_extensions_set()) {
params->extensions = extensions;
}
params->rtcp.reduced_size = desc->rtcp_reduced_size();
params->rtcp.remote_estimate = desc->remote_estimate();
}
template <class Codec>
void RtpSendParametersFromMediaDescription(
const MediaContentDescriptionImpl<Codec>* desc,
const RtpHeaderExtensions& extensions,
RtpSendParameters<Codec>* send_params) {
RtpParametersFromMediaDescription(desc, extensions, send_params);
send_params->max_bandwidth_bps = desc->bandwidth();
send_params->extmap_allow_mixed = desc->extmap_allow_mixed();
}
BaseChannel::BaseChannel(rtc::Thread* worker_thread,
rtc::Thread* network_thread,
rtc::Thread* signaling_thread,
std::unique_ptr<MediaChannel> media_channel,
Reland of TransportController refactoring. (patchset #1 id:1 of https://codereview.webrtc.org/1358413003/ ) Reason for revert: This CL just landed: https://codereview.chromium.org/1323243006/ Which fixes the FYI bots for the original CL, and breaks them for this revert. Original issue's description: > Revert of TransportController refactoring. (patchset #6 id:100001 of https://codereview.webrtc.org/1350523003/ ) > > Reason for revert: > This CL causes problems with the WebRTC-in-Chromium FYI bots. Presumably it needs to be done in several steps, where removed files are emptied instead of removed in the first step. > > Original issue's description: > > TransportController refactoring. > > > > Getting rid of TransportProxy, and in its place adding a > > TransportController class which will facilitate access to and manage > > the lifetimes of Transports. These Transports will now be accessed > > solely from the worker thread, simplifying their implementation. > > > > This refactoring also pulls Transport-related code out of BaseSession. > > Which means that BaseChannels will now rely on the TransportController > > interface to create channels, rather than BaseSession. > > > > Committed: https://crrev.com/47ee2f3b9f33e8938948c482c921d4e13a3acd83 > > Cr-Commit-Position: refs/heads/master@{#10022} > > TBR=pthatcher@webrtc.org,deadbeef@webrtc.org > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > > Committed: https://crrev.com/a81a42f584baa0d93a4b93da9632415e8922450c > Cr-Commit-Position: refs/heads/master@{#10024} TBR=pthatcher@webrtc.org,torbjorng@webrtc.org NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true Review URL: https://codereview.webrtc.org/1361773005 Cr-Commit-Position: refs/heads/master@{#10036}
2015-09-23 11:50:27 -07:00
const std::string& content_name,
bool srtp_required,
webrtc::CryptoOptions crypto_options,
UniqueRandomIdGenerator* ssrc_generator)
: worker_thread_(worker_thread),
network_thread_(network_thread),
signaling_thread_(signaling_thread),
content_name_(content_name),
srtp_required_(srtp_required),
crypto_options_(crypto_options),
media_channel_(std::move(media_channel)),
ssrc_generator_(ssrc_generator) {
RTC_DCHECK_RUN_ON(worker_thread_);
RTC_DCHECK(ssrc_generator_);
demuxer_criteria_.mid = content_name;
RTC_LOG(LS_INFO) << "Created channel for " << content_name;
}
BaseChannel::~BaseChannel() {
TRACE_EVENT0("webrtc", "BaseChannel::~BaseChannel");
RTC_DCHECK_RUN_ON(worker_thread_);
if (media_transport_config_.media_transport) {
media_transport_config_.media_transport->RemoveNetworkChangeCallback(this);
}
// Eats any outstanding messages or packets.
worker_thread_->Clear(&invoker_);
worker_thread_->Clear(this);
// We must destroy the media channel before the transport channel, otherwise
// the media channel may try to send on the dead transport channel. NULLing
// is not an effective strategy since the sends will come on another thread.
media_channel_.reset();
RTC_LOG(LS_INFO) << "Destroyed channel: " << content_name_;
}
bool BaseChannel::ConnectToRtpTransport() {
RTC_DCHECK(rtp_transport_);
if (!RegisterRtpDemuxerSink()) {
return false;
}
rtp_transport_->SignalReadyToSend.connect(
this, &BaseChannel::OnTransportReadyToSend);
// If media transport is used, it's responsible for providing network
// route changed callbacks.
if (!media_transport_config_.media_transport) {
rtp_transport_->SignalNetworkRouteChanged.connect(
this, &BaseChannel::OnNetworkRouteChanged);
}
// TODO(bugs.webrtc.org/9719): Media transport should also be used to provide
// 'writable' state here.
rtp_transport_->SignalWritableState.connect(this,
&BaseChannel::OnWritableState);
rtp_transport_->SignalSentPacket.connect(this,
&BaseChannel::SignalSentPacket_n);
return true;
}
void BaseChannel::DisconnectFromRtpTransport() {
RTC_DCHECK(rtp_transport_);
rtp_transport_->UnregisterRtpDemuxerSink(this);
rtp_transport_->SignalReadyToSend.disconnect(this);
rtp_transport_->SignalNetworkRouteChanged.disconnect(this);
rtp_transport_->SignalWritableState.disconnect(this);
rtp_transport_->SignalSentPacket.disconnect(this);
}
void BaseChannel::Init_w(
webrtc::RtpTransportInternal* rtp_transport,
const webrtc::MediaTransportConfig& media_transport_config) {
RTC_DCHECK_RUN_ON(worker_thread_);
media_transport_config_ = media_transport_config;
network_thread_->Invoke<void>(
RTC_FROM_HERE, [this, rtp_transport] { SetRtpTransport(rtp_transport); });
// Both RTP and RTCP channels should be set, we can call SetInterface on
// the media channel and it can set network options.
media_channel_->SetInterface(this, media_transport_config);
RTC_LOG(LS_INFO) << "BaseChannel::Init_w, media_transport_config="
<< media_transport_config.DebugString();
if (media_transport_config_.media_transport) {
media_transport_config_.media_transport->AddNetworkChangeCallback(this);
}
}
void BaseChannel::Deinit() {
RTC_DCHECK(worker_thread_->IsCurrent());
Reland "Reland "Propagate media transport to media channel."" This is a reland of da65ed2adcfa57ff3288ce01c1602c973fcab00d Original change's description: > Reland "Propagate media transport to media channel." > > This reverts commit 37cf2455a420124b341ad06ac27fa3c4dbd29d3c. > > Reason for revert: <INSERT REASONING HERE> > > Original change's description: > > Revert "Propagate media transport to media channel." > > > > This reverts commit 8c16f745ab92cb6d305283e87fa8a661ae500ce4. > > > > Reason for revert: Breaks downstream project > > > > Original change's description: > > > Propagate media transport to media channel. > > > > > > 1. Pass media transport factory to JSEP transport controller. > > > 2. Pass media transport to voice media channel. > > > 3. Add basic unit test that make sure if peer connection is created with media transport, it is propagated to voice media channel. > > > > > > Change-Id: Ie922db78ade0efd893e019cd2b4441a9947a2f71 > > > Bug: webrtc:9719 > > > Reviewed-on: https://webrtc-review.googlesource.com/c/105542 > > > Reviewed-by: Steve Anton <steveanton@webrtc.org> > > > Reviewed-by: Niels Moller <nisse@webrtc.org> > > > Reviewed-by: Peter Slatala <psla@webrtc.org> > > > Commit-Queue: Anton Sukhanov <sukhanov@google.com> > > > Cr-Commit-Position: refs/heads/master@{#25152} > > > > TBR=steveanton@webrtc.org,nisse@webrtc.org,psla@webrtc.org,sukhanov@google.com > > > > # Not skipping CQ checks because original CL landed > 1 day ago. > > > > Bug: webrtc:9719 > > Change-Id: Ic78cdc142a2145682ad74eac8b72c71c50f0a5c1 > > Reviewed-on: https://webrtc-review.googlesource.com/c/105840 > > Reviewed-by: Oleh Prypin <oprypin@webrtc.org> > > Commit-Queue: Oleh Prypin <oprypin@webrtc.org> > > Cr-Commit-Position: refs/heads/master@{#25154} > > TBR=steveanton@webrtc.org,oprypin@webrtc.org,nisse@webrtc.org,sukhanov@webrtc.org,psla@webrtc.org,sukhanov@google.com > > Change-Id: I505ff3451eae81573531faef155ff35d7f894022 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: webrtc:9719 > Reviewed-on: https://webrtc-review.googlesource.com/c/106500 > Reviewed-by: Anton Sukhanov <sukhanov@webrtc.org> > Commit-Queue: Anton Sukhanov <sukhanov@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#25220} Bug: webrtc:9719 Tbr: Steve Anton <steveanton@webrtc.org> Tbr: Niels Moller <nisse@webrtc.org> Change-Id: Ib45691ba8be9abb89ff8c6dac1861bdf59be4c8d Reviewed-on: https://webrtc-review.googlesource.com/c/106561 Commit-Queue: Anton Sukhanov <sukhanov@webrtc.org> Reviewed-by: Peter Slatala <psla@webrtc.org> Cr-Commit-Position: refs/heads/master@{#25240}
2018-10-17 13:15:42 -07:00
media_channel_->SetInterface(/*iface=*/nullptr,
webrtc::MediaTransportConfig());
// Packets arrive on the network thread, processing packets calls virtual
// functions, so need to stop this process in Deinit that is called in
// derived classes destructor.
network_thread_->Invoke<void>(RTC_FROM_HERE, [&] {
Revert "Reland "Replace BundleFilter with RtpDemuxer in RtpTransport."" This reverts commit 27f3bf512827b483f9e0c67ce76362d83faa1950. Reason for revert: Broken internal project. Original change's description: > Reland "Replace BundleFilter with RtpDemuxer in RtpTransport." > > This reverts commit 97d5e5b32c77bf550f1d788454f2db10ac9fbb1c. > > Reason for revert: <INSERT REASONING HERE> > > Original change's description: > > Revert "Replace BundleFilter with RtpDemuxer in RtpTransport." > > > > This reverts commit ea8b62a3e74fe91cd6bf66304839cd5677880a4e. > > > > Reason for revert: Broke chromium tests. > > Original change's description: > > > Replace BundleFilter with RtpDemuxer in RtpTransport. > > > > > > BundleFilter is replaced by RtpDemuxer in RtpTransport for payload > > > type-based demuxing. RtpTransport will support MID-based demuxing later. > > > > > > Each BaseChannel has its own RTP demuxing criteria and when connecting > > > to the RtpTransport, BaseChannel will register itself as a demuxer sink. > > > > > > The inheritance model is changed. New inheritance chain: > > > DtlsSrtpTransport->SrtpTransport->RtpTranpsort > > > > > > NOTE: > > > When RTCP packets are received, Call::DeliverRtcp will be called for > > > multiple times (webrtc:9035) which is an existing issue. With this CL, > > > it will become more of a problem and should be fixed. > > > > > > Bug: webrtc:8587 > > > Change-Id: I1d8a00443bd4bcbacc56e5e19b7294205cdc38f0 > > > Reviewed-on: https://webrtc-review.googlesource.com/61360 > > > Commit-Queue: Zhi Huang <zhihuang@webrtc.org> > > > Reviewed-by: Steve Anton <steveanton@webrtc.org> > > > Reviewed-by: Taylor Brandstetter <deadbeef@webrtc.org> > > > Cr-Commit-Position: refs/heads/master@{#22613} > > > > TBR=steveanton@webrtc.org,deadbeef@webrtc.org,zhihuang@webrtc.org > > > > Change-Id: If245da9d1ce970ac8dab7f45015e9b268a5dbcbd > > No-Presubmit: true > > No-Tree-Checks: true > > No-Try: true > > Bug: webrtc:8587 > > Reviewed-on: https://webrtc-review.googlesource.com/64860 > > Reviewed-by: Zhi Huang <zhihuang@webrtc.org> > > Commit-Queue: Zhi Huang <zhihuang@webrtc.org> > > Cr-Commit-Position: refs/heads/master@{#22614} > > TBR=steveanton@webrtc.org,deadbeef@webrtc.org,zhihuang@webrtc.org > > Change-Id: I3c272588ab4388ecadc4edc6786d5195c701855f > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: webrtc:8587 > Reviewed-on: https://webrtc-review.googlesource.com/64862 > Commit-Queue: Zhi Huang <zhihuang@webrtc.org> > Reviewed-by: Zhi Huang <zhihuang@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#22615} TBR=steveanton@webrtc.org,deadbeef@webrtc.org,zhihuang@webrtc.org # Not skipping CQ checks because original CL landed > 1 day ago. Bug: webrtc:8587 Change-Id: I694ce9a039ed52c5961cdc0cba57587bed4cbde4 Reviewed-on: https://webrtc-review.googlesource.com/65381 Reviewed-by: Zhi Huang <zhihuang@webrtc.org> Commit-Queue: Zhi Huang <zhihuang@webrtc.org> Cr-Commit-Position: refs/heads/master@{#22665}
2018-03-29 00:08:03 +00:00
FlushRtcpMessages_n();
Reland "Replace BundleFilter with RtpDemuxer in RtpTransport." This reverts commit 97d5e5b32c77bf550f1d788454f2db10ac9fbb1c. Reason for revert: <INSERT REASONING HERE> Original change's description: > Revert "Replace BundleFilter with RtpDemuxer in RtpTransport." > > This reverts commit ea8b62a3e74fe91cd6bf66304839cd5677880a4e. > > Reason for revert: Broke chromium tests. > Original change's description: > > Replace BundleFilter with RtpDemuxer in RtpTransport. > > > > BundleFilter is replaced by RtpDemuxer in RtpTransport for payload > > type-based demuxing. RtpTransport will support MID-based demuxing later. > > > > Each BaseChannel has its own RTP demuxing criteria and when connecting > > to the RtpTransport, BaseChannel will register itself as a demuxer sink. > > > > The inheritance model is changed. New inheritance chain: > > DtlsSrtpTransport->SrtpTransport->RtpTranpsort > > > > NOTE: > > When RTCP packets are received, Call::DeliverRtcp will be called for > > multiple times (webrtc:9035) which is an existing issue. With this CL, > > it will become more of a problem and should be fixed. > > > > Bug: webrtc:8587 > > Change-Id: I1d8a00443bd4bcbacc56e5e19b7294205cdc38f0 > > Reviewed-on: https://webrtc-review.googlesource.com/61360 > > Commit-Queue: Zhi Huang <zhihuang@webrtc.org> > > Reviewed-by: Steve Anton <steveanton@webrtc.org> > > Reviewed-by: Taylor Brandstetter <deadbeef@webrtc.org> > > Cr-Commit-Position: refs/heads/master@{#22613} > > TBR=steveanton@webrtc.org,deadbeef@webrtc.org,zhihuang@webrtc.org > > Change-Id: If245da9d1ce970ac8dab7f45015e9b268a5dbcbd > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: webrtc:8587 > Reviewed-on: https://webrtc-review.googlesource.com/64860 > Reviewed-by: Zhi Huang <zhihuang@webrtc.org> > Commit-Queue: Zhi Huang <zhihuang@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#22614} TBR=steveanton@webrtc.org,deadbeef@webrtc.org,zhihuang@webrtc.org Change-Id: I3c272588ab4388ecadc4edc6786d5195c701855f No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: webrtc:8587 Reviewed-on: https://webrtc-review.googlesource.com/64862 Commit-Queue: Zhi Huang <zhihuang@webrtc.org> Reviewed-by: Zhi Huang <zhihuang@webrtc.org> Cr-Commit-Position: refs/heads/master@{#22615}
2018-03-26 21:37:23 -07:00
if (rtp_transport_) {
DisconnectFromRtpTransport();
Revert "Reland "Replace BundleFilter with RtpDemuxer in RtpTransport."" This reverts commit 27f3bf512827b483f9e0c67ce76362d83faa1950. Reason for revert: Broken internal project. Original change's description: > Reland "Replace BundleFilter with RtpDemuxer in RtpTransport." > > This reverts commit 97d5e5b32c77bf550f1d788454f2db10ac9fbb1c. > > Reason for revert: <INSERT REASONING HERE> > > Original change's description: > > Revert "Replace BundleFilter with RtpDemuxer in RtpTransport." > > > > This reverts commit ea8b62a3e74fe91cd6bf66304839cd5677880a4e. > > > > Reason for revert: Broke chromium tests. > > Original change's description: > > > Replace BundleFilter with RtpDemuxer in RtpTransport. > > > > > > BundleFilter is replaced by RtpDemuxer in RtpTransport for payload > > > type-based demuxing. RtpTransport will support MID-based demuxing later. > > > > > > Each BaseChannel has its own RTP demuxing criteria and when connecting > > > to the RtpTransport, BaseChannel will register itself as a demuxer sink. > > > > > > The inheritance model is changed. New inheritance chain: > > > DtlsSrtpTransport->SrtpTransport->RtpTranpsort > > > > > > NOTE: > > > When RTCP packets are received, Call::DeliverRtcp will be called for > > > multiple times (webrtc:9035) which is an existing issue. With this CL, > > > it will become more of a problem and should be fixed. > > > > > > Bug: webrtc:8587 > > > Change-Id: I1d8a00443bd4bcbacc56e5e19b7294205cdc38f0 > > > Reviewed-on: https://webrtc-review.googlesource.com/61360 > > > Commit-Queue: Zhi Huang <zhihuang@webrtc.org> > > > Reviewed-by: Steve Anton <steveanton@webrtc.org> > > > Reviewed-by: Taylor Brandstetter <deadbeef@webrtc.org> > > > Cr-Commit-Position: refs/heads/master@{#22613} > > > > TBR=steveanton@webrtc.org,deadbeef@webrtc.org,zhihuang@webrtc.org > > > > Change-Id: If245da9d1ce970ac8dab7f45015e9b268a5dbcbd > > No-Presubmit: true > > No-Tree-Checks: true > > No-Try: true > > Bug: webrtc:8587 > > Reviewed-on: https://webrtc-review.googlesource.com/64860 > > Reviewed-by: Zhi Huang <zhihuang@webrtc.org> > > Commit-Queue: Zhi Huang <zhihuang@webrtc.org> > > Cr-Commit-Position: refs/heads/master@{#22614} > > TBR=steveanton@webrtc.org,deadbeef@webrtc.org,zhihuang@webrtc.org > > Change-Id: I3c272588ab4388ecadc4edc6786d5195c701855f > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: webrtc:8587 > Reviewed-on: https://webrtc-review.googlesource.com/64862 > Commit-Queue: Zhi Huang <zhihuang@webrtc.org> > Reviewed-by: Zhi Huang <zhihuang@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#22615} TBR=steveanton@webrtc.org,deadbeef@webrtc.org,zhihuang@webrtc.org # Not skipping CQ checks because original CL landed > 1 day ago. Bug: webrtc:8587 Change-Id: I694ce9a039ed52c5961cdc0cba57587bed4cbde4 Reviewed-on: https://webrtc-review.googlesource.com/65381 Reviewed-by: Zhi Huang <zhihuang@webrtc.org> Commit-Queue: Zhi Huang <zhihuang@webrtc.org> Cr-Commit-Position: refs/heads/master@{#22665}
2018-03-29 00:08:03 +00:00
}
// Clear pending read packets/messages.
network_thread_->Clear(&invoker_);
network_thread_->Clear(this);
});
}
bool BaseChannel::SetRtpTransport(webrtc::RtpTransportInternal* rtp_transport) {
if (rtp_transport == rtp_transport_) {
return true;
}
if (!network_thread_->IsCurrent()) {
return network_thread_->Invoke<bool>(RTC_FROM_HERE, [this, rtp_transport] {
return SetRtpTransport(rtp_transport);
});
}
Revert "Reland "Replace BundleFilter with RtpDemuxer in RtpTransport."" This reverts commit 27f3bf512827b483f9e0c67ce76362d83faa1950. Reason for revert: Broken internal project. Original change's description: > Reland "Replace BundleFilter with RtpDemuxer in RtpTransport." > > This reverts commit 97d5e5b32c77bf550f1d788454f2db10ac9fbb1c. > > Reason for revert: <INSERT REASONING HERE> > > Original change's description: > > Revert "Replace BundleFilter with RtpDemuxer in RtpTransport." > > > > This reverts commit ea8b62a3e74fe91cd6bf66304839cd5677880a4e. > > > > Reason for revert: Broke chromium tests. > > Original change's description: > > > Replace BundleFilter with RtpDemuxer in RtpTransport. > > > > > > BundleFilter is replaced by RtpDemuxer in RtpTransport for payload > > > type-based demuxing. RtpTransport will support MID-based demuxing later. > > > > > > Each BaseChannel has its own RTP demuxing criteria and when connecting > > > to the RtpTransport, BaseChannel will register itself as a demuxer sink. > > > > > > The inheritance model is changed. New inheritance chain: > > > DtlsSrtpTransport->SrtpTransport->RtpTranpsort > > > > > > NOTE: > > > When RTCP packets are received, Call::DeliverRtcp will be called for > > > multiple times (webrtc:9035) which is an existing issue. With this CL, > > > it will become more of a problem and should be fixed. > > > > > > Bug: webrtc:8587 > > > Change-Id: I1d8a00443bd4bcbacc56e5e19b7294205cdc38f0 > > > Reviewed-on: https://webrtc-review.googlesource.com/61360 > > > Commit-Queue: Zhi Huang <zhihuang@webrtc.org> > > > Reviewed-by: Steve Anton <steveanton@webrtc.org> > > > Reviewed-by: Taylor Brandstetter <deadbeef@webrtc.org> > > > Cr-Commit-Position: refs/heads/master@{#22613} > > > > TBR=steveanton@webrtc.org,deadbeef@webrtc.org,zhihuang@webrtc.org > > > > Change-Id: If245da9d1ce970ac8dab7f45015e9b268a5dbcbd > > No-Presubmit: true > > No-Tree-Checks: true > > No-Try: true > > Bug: webrtc:8587 > > Reviewed-on: https://webrtc-review.googlesource.com/64860 > > Reviewed-by: Zhi Huang <zhihuang@webrtc.org> > > Commit-Queue: Zhi Huang <zhihuang@webrtc.org> > > Cr-Commit-Position: refs/heads/master@{#22614} > > TBR=steveanton@webrtc.org,deadbeef@webrtc.org,zhihuang@webrtc.org > > Change-Id: I3c272588ab4388ecadc4edc6786d5195c701855f > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: webrtc:8587 > Reviewed-on: https://webrtc-review.googlesource.com/64862 > Commit-Queue: Zhi Huang <zhihuang@webrtc.org> > Reviewed-by: Zhi Huang <zhihuang@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#22615} TBR=steveanton@webrtc.org,deadbeef@webrtc.org,zhihuang@webrtc.org # Not skipping CQ checks because original CL landed > 1 day ago. Bug: webrtc:8587 Change-Id: I694ce9a039ed52c5961cdc0cba57587bed4cbde4 Reviewed-on: https://webrtc-review.googlesource.com/65381 Reviewed-by: Zhi Huang <zhihuang@webrtc.org> Commit-Queue: Zhi Huang <zhihuang@webrtc.org> Cr-Commit-Position: refs/heads/master@{#22665}
2018-03-29 00:08:03 +00:00
if (rtp_transport_) {
DisconnectFromRtpTransport();
}
rtp_transport_ = rtp_transport;
if (rtp_transport_) {
transport_name_ = rtp_transport_->transport_name();
if (!ConnectToRtpTransport()) {
RTC_LOG(LS_ERROR) << "Failed to connect to the new RtpTransport.";
return false;
}
OnTransportReadyToSend(rtp_transport_->IsReadyToSend());
UpdateWritableState_n();
// Set the cached socket options.
for (const auto& pair : socket_options_) {
rtp_transport_->SetRtpOption(pair.first, pair.second);
}
if (!rtp_transport_->rtcp_mux_enabled()) {
for (const auto& pair : rtcp_socket_options_) {
rtp_transport_->SetRtcpOption(pair.first, pair.second);
}
}
}
return true;
}
bool BaseChannel::Enable(bool enable) {
worker_thread_->Invoke<void>(
RTC_FROM_HERE,
Bind(enable ? &BaseChannel::EnableMedia_w : &BaseChannel::DisableMedia_w,
this));
return true;
}
bool BaseChannel::SetLocalContent(const MediaContentDescription* content,
SdpType type,
std::string* error_desc) {
TRACE_EVENT0("webrtc", "BaseChannel::SetLocalContent");
return InvokeOnWorker<bool>(
RTC_FROM_HERE,
Bind(&BaseChannel::SetLocalContent_w, this, content, type, error_desc));
}
bool BaseChannel::SetRemoteContent(const MediaContentDescription* content,
SdpType type,
std::string* error_desc) {
TRACE_EVENT0("webrtc", "BaseChannel::SetRemoteContent");
return InvokeOnWorker<bool>(
RTC_FROM_HERE,
Bind(&BaseChannel::SetRemoteContent_w, this, content, type, error_desc));
}
bool BaseChannel::IsReadyToReceiveMedia_w() const {
// Receive data if we are enabled and have local content,
return enabled() &&
webrtc::RtpTransceiverDirectionHasRecv(local_content_direction_);
}
bool BaseChannel::IsReadyToSendMedia_w() const {
// Need to access some state updated on the network thread.
return network_thread_->Invoke<bool>(
RTC_FROM_HERE, Bind(&BaseChannel::IsReadyToSendMedia_n, this));
}
bool BaseChannel::IsReadyToSendMedia_n() const {
// Send outgoing data if we are enabled, have local and remote content,
// and we have had some form of connectivity.
return enabled() &&
webrtc::RtpTransceiverDirectionHasRecv(remote_content_direction_) &&
webrtc::RtpTransceiverDirectionHasSend(local_content_direction_) &&
was_ever_writable();
}
bool BaseChannel::SendPacket(rtc::CopyOnWriteBuffer* packet,
const rtc::PacketOptions& options) {
return SendPacket(false, packet, options);
}
bool BaseChannel::SendRtcp(rtc::CopyOnWriteBuffer* packet,
const rtc::PacketOptions& options) {
return SendPacket(true, packet, options);
}
int BaseChannel::SetOption(SocketType type,
rtc::Socket::Option opt,
int value) {
return network_thread_->Invoke<int>(
RTC_FROM_HERE, Bind(&BaseChannel::SetOption_n, this, type, opt, value));
}
int BaseChannel::SetOption_n(SocketType type,
rtc::Socket::Option opt,
int value) {
RTC_DCHECK(network_thread_->IsCurrent());
RTC_DCHECK(rtp_transport_);
switch (type) {
case ST_RTP:
Reland of TransportController refactoring. (patchset #1 id:1 of https://codereview.webrtc.org/1358413003/ ) Reason for revert: This CL just landed: https://codereview.chromium.org/1323243006/ Which fixes the FYI bots for the original CL, and breaks them for this revert. Original issue's description: > Revert of TransportController refactoring. (patchset #6 id:100001 of https://codereview.webrtc.org/1350523003/ ) > > Reason for revert: > This CL causes problems with the WebRTC-in-Chromium FYI bots. Presumably it needs to be done in several steps, where removed files are emptied instead of removed in the first step. > > Original issue's description: > > TransportController refactoring. > > > > Getting rid of TransportProxy, and in its place adding a > > TransportController class which will facilitate access to and manage > > the lifetimes of Transports. These Transports will now be accessed > > solely from the worker thread, simplifying their implementation. > > > > This refactoring also pulls Transport-related code out of BaseSession. > > Which means that BaseChannels will now rely on the TransportController > > interface to create channels, rather than BaseSession. > > > > Committed: https://crrev.com/47ee2f3b9f33e8938948c482c921d4e13a3acd83 > > Cr-Commit-Position: refs/heads/master@{#10022} > > TBR=pthatcher@webrtc.org,deadbeef@webrtc.org > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > > Committed: https://crrev.com/a81a42f584baa0d93a4b93da9632415e8922450c > Cr-Commit-Position: refs/heads/master@{#10024} TBR=pthatcher@webrtc.org,torbjorng@webrtc.org NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true Review URL: https://codereview.webrtc.org/1361773005 Cr-Commit-Position: refs/heads/master@{#10036}
2015-09-23 11:50:27 -07:00
socket_options_.push_back(
std::pair<rtc::Socket::Option, int>(opt, value));
return rtp_transport_->SetRtpOption(opt, value);
case ST_RTCP:
Reland of TransportController refactoring. (patchset #1 id:1 of https://codereview.webrtc.org/1358413003/ ) Reason for revert: This CL just landed: https://codereview.chromium.org/1323243006/ Which fixes the FYI bots for the original CL, and breaks them for this revert. Original issue's description: > Revert of TransportController refactoring. (patchset #6 id:100001 of https://codereview.webrtc.org/1350523003/ ) > > Reason for revert: > This CL causes problems with the WebRTC-in-Chromium FYI bots. Presumably it needs to be done in several steps, where removed files are emptied instead of removed in the first step. > > Original issue's description: > > TransportController refactoring. > > > > Getting rid of TransportProxy, and in its place adding a > > TransportController class which will facilitate access to and manage > > the lifetimes of Transports. These Transports will now be accessed > > solely from the worker thread, simplifying their implementation. > > > > This refactoring also pulls Transport-related code out of BaseSession. > > Which means that BaseChannels will now rely on the TransportController > > interface to create channels, rather than BaseSession. > > > > Committed: https://crrev.com/47ee2f3b9f33e8938948c482c921d4e13a3acd83 > > Cr-Commit-Position: refs/heads/master@{#10022} > > TBR=pthatcher@webrtc.org,deadbeef@webrtc.org > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > > Committed: https://crrev.com/a81a42f584baa0d93a4b93da9632415e8922450c > Cr-Commit-Position: refs/heads/master@{#10024} TBR=pthatcher@webrtc.org,torbjorng@webrtc.org NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true Review URL: https://codereview.webrtc.org/1361773005 Cr-Commit-Position: refs/heads/master@{#10036}
2015-09-23 11:50:27 -07:00
rtcp_socket_options_.push_back(
std::pair<rtc::Socket::Option, int>(opt, value));
return rtp_transport_->SetRtcpOption(opt, value);
}
return -1;
}
void BaseChannel::OnWritableState(bool writable) {
RTC_DCHECK(network_thread_->IsCurrent());
if (writable) {
ChannelWritable_n();
} else {
ChannelNotWritable_n();
}
}
void BaseChannel::OnNetworkRouteChanged(
absl::optional<rtc::NetworkRoute> network_route) {
RTC_LOG(LS_INFO) << "Network route was changed.";
RTC_DCHECK(network_thread_->IsCurrent());
rtc::NetworkRoute new_route;
if (network_route) {
new_route = *(network_route);
}
// Note: When the RTCP-muxing is not enabled, RTCP transport and RTP transport
// use the same transport name and MediaChannel::OnNetworkRouteChanged cannot
// work correctly. Intentionally leave it broken to simplify the code and
// encourage the users to stop using non-muxing RTCP.
invoker_.AsyncInvoke<void>(RTC_FROM_HERE, worker_thread_, [=] {
media_channel_->OnNetworkRouteChanged(transport_name_, new_route);
});
}
void BaseChannel::OnTransportReadyToSend(bool ready) {
invoker_.AsyncInvoke<void>(RTC_FROM_HERE, worker_thread_,
[=] { media_channel_->OnReadyToSend(ready); });
}
bool BaseChannel::SendPacket(bool rtcp,
rtc::CopyOnWriteBuffer* packet,
const rtc::PacketOptions& options) {
// Until all the code is migrated to use RtpPacketType instead of bool.
RtpPacketType packet_type = rtcp ? RtpPacketType::kRtcp : RtpPacketType::kRtp;
// SendPacket gets called from MediaEngine, on a pacer or an encoder thread.
// If the thread is not our network thread, we will post to our network
// so that the real work happens on our network. This avoids us having to
// synchronize access to all the pieces of the send path, including
// SRTP and the inner workings of the transport channels.
// The only downside is that we can't return a proper failure code if
// needed. Since UDP is unreliable anyway, this should be a non-issue.
if (!network_thread_->IsCurrent()) {
// Avoid a copy by transferring the ownership of the packet data.
int message_id = rtcp ? MSG_SEND_RTCP_PACKET : MSG_SEND_RTP_PACKET;
SendPacketMessageData* data = new SendPacketMessageData;
data->packet = std::move(*packet);
data->options = options;
network_thread_->Post(RTC_FROM_HERE, this, message_id, data);
return true;
}
TRACE_EVENT0("webrtc", "BaseChannel::SendPacket");
// Now that we are on the correct thread, ensure we have a place to send this
// packet before doing anything. (We might get RTCP packets that we don't
// intend to send.) If we've negotiated RTCP mux, send RTCP over the RTP
// transport.
if (!rtp_transport_ || !rtp_transport_->IsWritable(rtcp)) {
return false;
}
// Protect ourselves against crazy data.
if (!IsValidRtpPacketSize(packet_type, packet->size())) {
RTC_LOG(LS_ERROR) << "Dropping outgoing " << content_name_ << " "
<< RtpPacketTypeToString(packet_type)
<< " packet: wrong size=" << packet->size();
return false;
}
if (!srtp_active()) {
if (srtp_required_) {
// The audio/video engines may attempt to send RTCP packets as soon as the
// streams are created, so don't treat this as an error for RTCP.
// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=6809
if (rtcp) {
return false;
}
// However, there shouldn't be any RTP packets sent before SRTP is set up
// (and SetSend(true) is called).
RTC_LOG(LS_ERROR)
<< "Can't send outgoing RTP packet when SRTP is inactive"
<< " and crypto is required";
RTC_NOTREACHED();
return false;
}
std::string packet_type = rtcp ? "RTCP" : "RTP";
RTC_LOG(LS_WARNING) << "Sending an " << packet_type
<< " packet without encryption.";
}
// Bon voyage.
return rtcp ? rtp_transport_->SendRtcpPacket(packet, options, PF_SRTP_BYPASS)
: rtp_transport_->SendRtpPacket(packet, options, PF_SRTP_BYPASS);
}
void BaseChannel::OnRtpPacket(const webrtc::RtpPacketReceived& parsed_packet) {
// Take packet time from the |parsed_packet|.
// RtpPacketReceived.arrival_time_ms = (timestamp_us + 500) / 1000;
int64_t packet_time_us = -1;
if (parsed_packet.arrival_time_ms() > 0) {
packet_time_us = parsed_packet.arrival_time_ms() * 1000;
}
if (!has_received_packet_) {
has_received_packet_ = true;
signaling_thread()->Post(RTC_FROM_HERE, this, MSG_FIRSTPACKETRECEIVED);
}
if (!srtp_active() && srtp_required_) {
// Our session description indicates that SRTP is required, but we got a
// packet before our SRTP filter is active. This means either that
// a) we got SRTP packets before we received the SDES keys, in which case
// we can't decrypt it anyway, or
// b) we got SRTP packets before DTLS completed on both the RTP and RTCP
// transports, so we haven't yet extracted keys, even if DTLS did
// complete on the transport that the packets are being sent on. It's
// really good practice to wait for both RTP and RTCP to be good to go
// before sending media, to prevent weird failure modes, so it's fine
// for us to just eat packets here. This is all sidestepped if RTCP mux
// is used anyway.
RTC_LOG(LS_WARNING) << "Can't process incoming RTP packet when "
"SRTP is inactive and crypto is required";
return;
}
auto packet_buffer = parsed_packet.Buffer();
invoker_.AsyncInvoke<void>(
RTC_FROM_HERE, worker_thread_, [this, packet_buffer, packet_time_us] {
RTC_DCHECK(worker_thread_->IsCurrent());
media_channel_->OnPacketReceived(packet_buffer, packet_time_us);
});
}
void BaseChannel::UpdateRtpHeaderExtensionMap(
const RtpHeaderExtensions& header_extensions) {
RTC_DCHECK(rtp_transport_);
// Update the header extension map on network thread in case there is data
// race.
// TODO(zhihuang): Add an rtc::ThreadChecker make sure to RtpTransport won't
// be accessed from different threads.
//
// NOTE: This doesn't take the BUNDLE case in account meaning the RTP header
// extension maps are not merged when BUNDLE is enabled. This is fine because
// the ID for MID should be consistent among all the RTP transports.
network_thread_->Invoke<void>(RTC_FROM_HERE, [this, &header_extensions] {
rtp_transport_->UpdateRtpHeaderExtensionMap(header_extensions);
});
}
bool BaseChannel::RegisterRtpDemuxerSink() {
RTC_DCHECK(rtp_transport_);
return network_thread_->Invoke<bool>(RTC_FROM_HERE, [this] {
return rtp_transport_->RegisterRtpDemuxerSink(demuxer_criteria_, this);
});
}
void BaseChannel::EnableMedia_w() {
RTC_DCHECK(worker_thread_ == rtc::Thread::Current());
if (enabled_)
return;
RTC_LOG(LS_INFO) << "Channel enabled";
enabled_ = true;
UpdateMediaSendRecvState_w();
}
void BaseChannel::DisableMedia_w() {
RTC_DCHECK(worker_thread_ == rtc::Thread::Current());
if (!enabled_)
return;
RTC_LOG(LS_INFO) << "Channel disabled";
enabled_ = false;
UpdateMediaSendRecvState_w();
}
void BaseChannel::UpdateWritableState_n() {
if (rtp_transport_->IsWritable(/*rtcp=*/true) &&
rtp_transport_->IsWritable(/*rtcp=*/false)) {
ChannelWritable_n();
Reland of TransportController refactoring. (patchset #1 id:1 of https://codereview.webrtc.org/1358413003/ ) Reason for revert: This CL just landed: https://codereview.chromium.org/1323243006/ Which fixes the FYI bots for the original CL, and breaks them for this revert. Original issue's description: > Revert of TransportController refactoring. (patchset #6 id:100001 of https://codereview.webrtc.org/1350523003/ ) > > Reason for revert: > This CL causes problems with the WebRTC-in-Chromium FYI bots. Presumably it needs to be done in several steps, where removed files are emptied instead of removed in the first step. > > Original issue's description: > > TransportController refactoring. > > > > Getting rid of TransportProxy, and in its place adding a > > TransportController class which will facilitate access to and manage > > the lifetimes of Transports. These Transports will now be accessed > > solely from the worker thread, simplifying their implementation. > > > > This refactoring also pulls Transport-related code out of BaseSession. > > Which means that BaseChannels will now rely on the TransportController > > interface to create channels, rather than BaseSession. > > > > Committed: https://crrev.com/47ee2f3b9f33e8938948c482c921d4e13a3acd83 > > Cr-Commit-Position: refs/heads/master@{#10022} > > TBR=pthatcher@webrtc.org,deadbeef@webrtc.org > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > > Committed: https://crrev.com/a81a42f584baa0d93a4b93da9632415e8922450c > Cr-Commit-Position: refs/heads/master@{#10024} TBR=pthatcher@webrtc.org,torbjorng@webrtc.org NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true Review URL: https://codereview.webrtc.org/1361773005 Cr-Commit-Position: refs/heads/master@{#10036}
2015-09-23 11:50:27 -07:00
} else {
ChannelNotWritable_n();
Reland of TransportController refactoring. (patchset #1 id:1 of https://codereview.webrtc.org/1358413003/ ) Reason for revert: This CL just landed: https://codereview.chromium.org/1323243006/ Which fixes the FYI bots for the original CL, and breaks them for this revert. Original issue's description: > Revert of TransportController refactoring. (patchset #6 id:100001 of https://codereview.webrtc.org/1350523003/ ) > > Reason for revert: > This CL causes problems with the WebRTC-in-Chromium FYI bots. Presumably it needs to be done in several steps, where removed files are emptied instead of removed in the first step. > > Original issue's description: > > TransportController refactoring. > > > > Getting rid of TransportProxy, and in its place adding a > > TransportController class which will facilitate access to and manage > > the lifetimes of Transports. These Transports will now be accessed > > solely from the worker thread, simplifying their implementation. > > > > This refactoring also pulls Transport-related code out of BaseSession. > > Which means that BaseChannels will now rely on the TransportController > > interface to create channels, rather than BaseSession. > > > > Committed: https://crrev.com/47ee2f3b9f33e8938948c482c921d4e13a3acd83 > > Cr-Commit-Position: refs/heads/master@{#10022} > > TBR=pthatcher@webrtc.org,deadbeef@webrtc.org > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > > Committed: https://crrev.com/a81a42f584baa0d93a4b93da9632415e8922450c > Cr-Commit-Position: refs/heads/master@{#10024} TBR=pthatcher@webrtc.org,torbjorng@webrtc.org NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true Review URL: https://codereview.webrtc.org/1361773005 Cr-Commit-Position: refs/heads/master@{#10036}
2015-09-23 11:50:27 -07:00
}
}
void BaseChannel::ChannelWritable_n() {
RTC_DCHECK(network_thread_->IsCurrent());
if (writable_) {
return;
}
RTC_LOG(LS_INFO) << "Channel writable (" << content_name_ << ")"
<< (was_ever_writable_ ? "" : " for the first time");
was_ever_writable_ = true;
writable_ = true;
UpdateMediaSendRecvState();
}
void BaseChannel::ChannelNotWritable_n() {
RTC_DCHECK(network_thread_->IsCurrent());
if (!writable_)
return;
RTC_LOG(LS_INFO) << "Channel not writable (" << content_name_ << ")";
writable_ = false;
UpdateMediaSendRecvState();
}
bool BaseChannel::AddRecvStream_w(const StreamParams& sp) {
RTC_DCHECK(worker_thread() == rtc::Thread::Current());
return media_channel()->AddRecvStream(sp);
}
bool BaseChannel::RemoveRecvStream_w(uint32_t ssrc) {
RTC_DCHECK(worker_thread() == rtc::Thread::Current());
return media_channel()->RemoveRecvStream(ssrc);
}
void BaseChannel::ResetUnsignaledRecvStream_w() {
RTC_DCHECK(worker_thread() == rtc::Thread::Current());
media_channel()->ResetUnsignaledRecvStream();
}
bool BaseChannel::UpdateLocalStreams_w(const std::vector<StreamParams>& streams,
SdpType type,
std::string* error_desc) {
// In the case of RIDs (where SSRCs are not negotiated), this method will
// generate an SSRC for each layer in StreamParams. That representation will
// be stored internally in |local_streams_|.
// In subsequent offers, the same stream can appear in |streams| again
// (without the SSRCs), so it should be looked up using RIDs (if available)
// and then by primary SSRC.
// In both scenarios, it is safe to assume that the media channel will be
// created with a StreamParams object with SSRCs. However, it is not safe to
// assume that |local_streams_| will always have SSRCs as there are scenarios
// in which niether SSRCs or RIDs are negotiated.
// Check for streams that have been removed.
bool ret = true;
for (const StreamParams& old_stream : local_streams_) {
if (!old_stream.has_ssrcs() ||
GetStream(streams, StreamFinder(&old_stream))) {
continue;
}
if (!media_channel()->RemoveSendStream(old_stream.first_ssrc())) {
rtc::StringBuilder desc;
desc << "Failed to remove send stream with ssrc "
<< old_stream.first_ssrc() << ".";
SafeSetError(desc.str(), error_desc);
ret = false;
}
}
// Check for new streams.
std::vector<StreamParams> all_streams;
for (const StreamParams& stream : streams) {
StreamParams* existing = GetStream(local_streams_, StreamFinder(&stream));
if (existing) {
// Parameters cannot change for an existing stream.
all_streams.push_back(*existing);
continue;
}
all_streams.push_back(stream);
StreamParams& new_stream = all_streams.back();
if (!new_stream.has_ssrcs() && !new_stream.has_rids()) {
continue;
}
RTC_DCHECK(new_stream.has_ssrcs() || new_stream.has_rids());
if (new_stream.has_ssrcs() && new_stream.has_rids()) {
rtc::StringBuilder desc;
desc << "Failed to add send stream: " << new_stream.first_ssrc()
<< ". Stream has both SSRCs and RIDs.";
SafeSetError(desc.str(), error_desc);
ret = false;
continue;
}
// At this point we use the legacy simulcast group in StreamParams to
// indicate that we want multiple layers to the media channel.
if (!new_stream.has_ssrcs()) {
// TODO(bugs.webrtc.org/10250): Indicate if flex is desired here.
new_stream.GenerateSsrcs(new_stream.rids().size(), /* rtx = */ true,
/* flex_fec = */ false, ssrc_generator_);
}
if (media_channel()->AddSendStream(new_stream)) {
RTC_LOG(LS_INFO) << "Add send stream ssrc: " << new_stream.ssrcs[0];
} else {
rtc::StringBuilder desc;
desc << "Failed to add send stream ssrc: " << new_stream.first_ssrc();
SafeSetError(desc.str(), error_desc);
ret = false;
}
}
local_streams_ = all_streams;
return ret;
}
bool BaseChannel::UpdateRemoteStreams_w(
const std::vector<StreamParams>& streams,
SdpType type,
std::string* error_desc) {
// Check for streams that have been removed.
bool ret = true;
for (const StreamParams& old_stream : remote_streams_) {
// If we no longer have an unsignaled stream, we would like to remove
// the unsignaled stream params that are cached.
if (!old_stream.has_ssrcs() && !HasStreamWithNoSsrcs(streams)) {
ResetUnsignaledRecvStream_w();
RTC_LOG(LS_INFO) << "Reset unsignaled remote stream.";
} else if (old_stream.has_ssrcs() &&
!GetStreamBySsrc(streams, old_stream.first_ssrc())) {
if (RemoveRecvStream_w(old_stream.first_ssrc())) {
RTC_LOG(LS_INFO) << "Remove remote ssrc: " << old_stream.first_ssrc();
} else {
rtc::StringBuilder desc;
desc << "Failed to remove remote stream with ssrc "
<< old_stream.first_ssrc() << ".";
SafeSetError(desc.str(), error_desc);
ret = false;
}
}
}
demuxer_criteria_.ssrcs.clear();
// Check for new streams.
for (const StreamParams& new_stream : streams) {
// We allow a StreamParams with an empty list of SSRCs, in which case the
// MediaChannel will cache the parameters and use them for any unsignaled
// stream received later.
if ((!new_stream.has_ssrcs() && !HasStreamWithNoSsrcs(remote_streams_)) ||
!GetStreamBySsrc(remote_streams_, new_stream.first_ssrc())) {
if (AddRecvStream_w(new_stream)) {
RTC_LOG(LS_INFO) << "Add remote ssrc: "
<< (new_stream.has_ssrcs()
? std::to_string(new_stream.first_ssrc())
: "unsignaled");
} else {
rtc::StringBuilder desc;
desc << "Failed to add remote stream ssrc: "
<< (new_stream.has_ssrcs()
? std::to_string(new_stream.first_ssrc())
: "unsignaled");
SafeSetError(desc.str(), error_desc);
ret = false;
}
}
// Update the receiving SSRCs.
demuxer_criteria_.ssrcs.insert(new_stream.ssrcs.begin(),
new_stream.ssrcs.end());
}
// Re-register the sink to update the receiving ssrcs.
RegisterRtpDemuxerSink();
remote_streams_ = streams;
return ret;
}
RtpHeaderExtensions BaseChannel::GetFilteredRtpHeaderExtensions(
const RtpHeaderExtensions& extensions) {
RTC_DCHECK(rtp_transport_);
Reland "Move CryptoOptions to api/crypto from rtc_base/sslstreamadapter.h" Promotes rtc::CryptoOptions to webrtc::CryptoOptions converting it from class that only handles SRTP configuration to a more generic structure that can be used and extended for all per peer connection CryptoOptions that can be on a given PeerConnection. Now all SRTP related options are under webrtc::CryptoOptions::Srtp and can be accessed as crypto_options.srtp.whatever_option_name. This is more inline with other structures we have in WebRTC such as VideoConfig. As additional features are added over time this will allow the structure to remain compartmentalized and concerned components can only request a subset of the overall configuration structure e.g: void MySrtpFunction(const webrtc::CryptoOptions::Srtp& srtp_config); In addition to this it made little sense for sslstreamadapter.h to hold all Srtp related configuration options. The header has become loo large and takes on too many responsibilities and spilting this up will lead to more maintainable code going forward. This will be used in a future CL to enable configuration options for the newly supported Frame Crypto. Reland Fix: - cryptooptions.h - now has enable_aes128_sha1_32_crypto_cipher as an optional root level configuration. - peerconnectionfactory - If this optional is set will now overwrite the underyling value. This along with the other field will be deprecated once dependent projects are updated. TBR=sakal@webrtc.org,kthelgason@webrtc.org,emadomara@webrtc.org,qingsi@webrtc.org Bug: webrtc:9681 Change-Id: Iaa6b741baafb85d352e42f54226119f19d97151d Reviewed-on: https://webrtc-review.googlesource.com/c/105560 Reviewed-by: Benjamin Wright <benwright@webrtc.org> Reviewed-by: Steve Anton <steveanton@webrtc.org> Reviewed-by: Emad Omara <emadomara@webrtc.org> Commit-Queue: Benjamin Wright <benwright@webrtc.org> Cr-Commit-Position: refs/heads/master@{#25135}
2018-10-11 15:33:17 -07:00
if (crypto_options_.srtp.enable_encrypted_rtp_header_extensions) {
RtpHeaderExtensions filtered;
absl::c_copy_if(extensions, std::back_inserter(filtered),
[](const webrtc::RtpExtension& extension) {
return !extension.encrypt;
});
return filtered;
}
return webrtc::RtpExtension::FilterDuplicateNonEncrypted(extensions);
}
void BaseChannel::OnMessage(rtc::Message* pmsg) {
TRACE_EVENT0("webrtc", "BaseChannel::OnMessage");
switch (pmsg->message_id) {
case MSG_SEND_RTP_PACKET:
case MSG_SEND_RTCP_PACKET: {
RTC_DCHECK(network_thread_->IsCurrent());
SendPacketMessageData* data =
static_cast<SendPacketMessageData*>(pmsg->pdata);
bool rtcp = pmsg->message_id == MSG_SEND_RTCP_PACKET;
SendPacket(rtcp, &data->packet, data->options);
delete data;
break;
}
case MSG_FIRSTPACKETRECEIVED: {
SignalFirstPacketReceived_(this);
break;
}
}
}
void BaseChannel::AddHandledPayloadType(int payload_type) {
demuxer_criteria_.payload_types.insert(static_cast<uint8_t>(payload_type));
}
void BaseChannel::ClearHandledPayloadTypes() {
demuxer_criteria_.payload_types.clear();
}
void BaseChannel::FlushRtcpMessages_n() {
// Flush all remaining RTCP messages. This should only be called in
// destructor.
RTC_DCHECK(network_thread_->IsCurrent());
rtc::MessageList rtcp_messages;
network_thread_->Clear(this, MSG_SEND_RTCP_PACKET, &rtcp_messages);
for (const auto& message : rtcp_messages) {
network_thread_->Send(RTC_FROM_HERE, this, MSG_SEND_RTCP_PACKET,
message.pdata);
}
}
void BaseChannel::SignalSentPacket_n(const rtc::SentPacket& sent_packet) {
RTC_DCHECK(network_thread_->IsCurrent());
invoker_.AsyncInvoke<void>(RTC_FROM_HERE, worker_thread_,
[this, sent_packet] {
RTC_DCHECK(worker_thread_->IsCurrent());
SignalSentPacket(sent_packet);
});
}
VoiceChannel::VoiceChannel(rtc::Thread* worker_thread,
rtc::Thread* network_thread,
rtc::Thread* signaling_thread,
std::unique_ptr<VoiceMediaChannel> media_channel,
const std::string& content_name,
bool srtp_required,
webrtc::CryptoOptions crypto_options,
UniqueRandomIdGenerator* ssrc_generator)
: BaseChannel(worker_thread,
network_thread,
signaling_thread,
std::move(media_channel),
Reland of TransportController refactoring. (patchset #1 id:1 of https://codereview.webrtc.org/1358413003/ ) Reason for revert: This CL just landed: https://codereview.chromium.org/1323243006/ Which fixes the FYI bots for the original CL, and breaks them for this revert. Original issue's description: > Revert of TransportController refactoring. (patchset #6 id:100001 of https://codereview.webrtc.org/1350523003/ ) > > Reason for revert: > This CL causes problems with the WebRTC-in-Chromium FYI bots. Presumably it needs to be done in several steps, where removed files are emptied instead of removed in the first step. > > Original issue's description: > > TransportController refactoring. > > > > Getting rid of TransportProxy, and in its place adding a > > TransportController class which will facilitate access to and manage > > the lifetimes of Transports. These Transports will now be accessed > > solely from the worker thread, simplifying their implementation. > > > > This refactoring also pulls Transport-related code out of BaseSession. > > Which means that BaseChannels will now rely on the TransportController > > interface to create channels, rather than BaseSession. > > > > Committed: https://crrev.com/47ee2f3b9f33e8938948c482c921d4e13a3acd83 > > Cr-Commit-Position: refs/heads/master@{#10022} > > TBR=pthatcher@webrtc.org,deadbeef@webrtc.org > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > > Committed: https://crrev.com/a81a42f584baa0d93a4b93da9632415e8922450c > Cr-Commit-Position: refs/heads/master@{#10024} TBR=pthatcher@webrtc.org,torbjorng@webrtc.org NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true Review URL: https://codereview.webrtc.org/1361773005 Cr-Commit-Position: refs/heads/master@{#10036}
2015-09-23 11:50:27 -07:00
content_name,
srtp_required,
crypto_options,
ssrc_generator) {}
VoiceChannel::~VoiceChannel() {
if (media_transport()) {
media_transport()->SetFirstAudioPacketReceivedObserver(nullptr);
}
TRACE_EVENT0("webrtc", "VoiceChannel::~VoiceChannel");
// this can't be done in the base class, since it calls a virtual
DisableMedia_w();
Deinit();
}
void BaseChannel::UpdateMediaSendRecvState() {
RTC_DCHECK(network_thread_->IsCurrent());
invoker_.AsyncInvoke<void>(RTC_FROM_HERE, worker_thread_,
[this] { UpdateMediaSendRecvState_w(); });
}
void BaseChannel::OnNetworkRouteChanged(
const rtc::NetworkRoute& network_route) {
OnNetworkRouteChanged(absl::make_optional(network_route));
}
void VoiceChannel::Init_w(
webrtc::RtpTransportInternal* rtp_transport,
const webrtc::MediaTransportConfig& media_transport_config) {
BaseChannel::Init_w(rtp_transport, media_transport_config);
if (media_transport_config.media_transport) {
media_transport_config.media_transport->SetFirstAudioPacketReceivedObserver(
this);
}
}
void VoiceChannel::OnFirstAudioPacketReceived(int64_t channel_id) {
has_received_packet_ = true;
signaling_thread()->Post(RTC_FROM_HERE, this, MSG_FIRSTPACKETRECEIVED);
}
void VoiceChannel::UpdateMediaSendRecvState_w() {
// Render incoming data if we're the active call, and we have the local
// content. We receive data on the default channel and multiplexed streams.
bool recv = IsReadyToReceiveMedia_w();
media_channel()->SetPlayout(recv);
// Send outgoing data if we're the active call, we have the remote content,
// and we have had some form of connectivity.
bool send = IsReadyToSendMedia_w();
media_channel()->SetSend(send);
RTC_LOG(LS_INFO) << "Changing voice state, recv=" << recv << " send=" << send;
}
bool VoiceChannel::SetLocalContent_w(const MediaContentDescription* content,
SdpType type,
std::string* error_desc) {
TRACE_EVENT0("webrtc", "VoiceChannel::SetLocalContent_w");
RTC_DCHECK_RUN_ON(worker_thread());
RTC_LOG(LS_INFO) << "Setting local voice description";
RTC_DCHECK(content);
if (!content) {
SafeSetError("Can't find audio content in local description.", error_desc);
return false;
}
const AudioContentDescription* audio = content->as_audio();
RtpHeaderExtensions rtp_header_extensions =
GetFilteredRtpHeaderExtensions(audio->rtp_header_extensions());
UpdateRtpHeaderExtensionMap(rtp_header_extensions);
media_channel()->SetExtmapAllowMixed(audio->extmap_allow_mixed());
AudioRecvParameters recv_params = last_recv_params_;
RtpParametersFromMediaDescription(audio, rtp_header_extensions, &recv_params);
if (!media_channel()->SetRecvParameters(recv_params)) {
SafeSetError("Failed to set local audio description recv parameters.",
error_desc);
return false;
}
if (webrtc::RtpTransceiverDirectionHasRecv(audio->direction())) {
for (const AudioCodec& codec : audio->codecs()) {
AddHandledPayloadType(codec.id);
}
// Need to re-register the sink to update the handled payload.
if (!RegisterRtpDemuxerSink()) {
RTC_LOG(LS_ERROR) << "Failed to set up audio demuxing.";
return false;
}
}
last_recv_params_ = recv_params;
// TODO(pthatcher): Move local streams into AudioSendParameters, and
// only give it to the media channel once we have a remote
// description too (without a remote description, we won't be able
// to send them anyway).
if (!UpdateLocalStreams_w(audio->streams(), type, error_desc)) {
SafeSetError("Failed to set local audio description streams.", error_desc);
return false;
}
set_local_content_direction(content->direction());
UpdateMediaSendRecvState_w();
return true;
}
bool VoiceChannel::SetRemoteContent_w(const MediaContentDescription* content,
SdpType type,
std::string* error_desc) {
TRACE_EVENT0("webrtc", "VoiceChannel::SetRemoteContent_w");
RTC_DCHECK_RUN_ON(worker_thread());
RTC_LOG(LS_INFO) << "Setting remote voice description";
RTC_DCHECK(content);
if (!content) {
SafeSetError("Can't find audio content in remote description.", error_desc);
return false;
}
const AudioContentDescription* audio = content->as_audio();
RtpHeaderExtensions rtp_header_extensions =
GetFilteredRtpHeaderExtensions(audio->rtp_header_extensions());
AudioSendParameters send_params = last_send_params_;
RtpSendParametersFromMediaDescription(audio, rtp_header_extensions,
&send_params);
send_params.mid = content_name();
bool parameters_applied = media_channel()->SetSendParameters(send_params);
if (!parameters_applied) {
SafeSetError("Failed to set remote audio description send parameters.",
error_desc);
return false;
}
last_send_params_ = send_params;
if (!webrtc::RtpTransceiverDirectionHasSend(content->direction())) {
RTC_DLOG(LS_VERBOSE) << "SetRemoteContent_w: remote side will not send - "
"disable payload type demuxing";
ClearHandledPayloadTypes();
if (!RegisterRtpDemuxerSink()) {
RTC_LOG(LS_ERROR) << "Failed to update audio demuxing.";
return false;
}
}
// TODO(pthatcher): Move remote streams into AudioRecvParameters,
// and only give it to the media channel once we have a local
// description too (without a local description, we won't be able to
// recv them anyway).
if (!UpdateRemoteStreams_w(audio->streams(), type, error_desc)) {
SafeSetError("Failed to set remote audio description streams.", error_desc);
return false;
}
set_remote_content_direction(content->direction());
UpdateMediaSendRecvState_w();
return true;
}
VideoChannel::VideoChannel(rtc::Thread* worker_thread,
rtc::Thread* network_thread,
rtc::Thread* signaling_thread,
std::unique_ptr<VideoMediaChannel> media_channel,
const std::string& content_name,
bool srtp_required,
webrtc::CryptoOptions crypto_options,
UniqueRandomIdGenerator* ssrc_generator)
: BaseChannel(worker_thread,
network_thread,
signaling_thread,
std::move(media_channel),
Reland of TransportController refactoring. (patchset #1 id:1 of https://codereview.webrtc.org/1358413003/ ) Reason for revert: This CL just landed: https://codereview.chromium.org/1323243006/ Which fixes the FYI bots for the original CL, and breaks them for this revert. Original issue's description: > Revert of TransportController refactoring. (patchset #6 id:100001 of https://codereview.webrtc.org/1350523003/ ) > > Reason for revert: > This CL causes problems with the WebRTC-in-Chromium FYI bots. Presumably it needs to be done in several steps, where removed files are emptied instead of removed in the first step. > > Original issue's description: > > TransportController refactoring. > > > > Getting rid of TransportProxy, and in its place adding a > > TransportController class which will facilitate access to and manage > > the lifetimes of Transports. These Transports will now be accessed > > solely from the worker thread, simplifying their implementation. > > > > This refactoring also pulls Transport-related code out of BaseSession. > > Which means that BaseChannels will now rely on the TransportController > > interface to create channels, rather than BaseSession. > > > > Committed: https://crrev.com/47ee2f3b9f33e8938948c482c921d4e13a3acd83 > > Cr-Commit-Position: refs/heads/master@{#10022} > > TBR=pthatcher@webrtc.org,deadbeef@webrtc.org > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > > Committed: https://crrev.com/a81a42f584baa0d93a4b93da9632415e8922450c > Cr-Commit-Position: refs/heads/master@{#10024} TBR=pthatcher@webrtc.org,torbjorng@webrtc.org NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true Review URL: https://codereview.webrtc.org/1361773005 Cr-Commit-Position: refs/heads/master@{#10036}
2015-09-23 11:50:27 -07:00
content_name,
srtp_required,
crypto_options,
ssrc_generator) {}
VideoChannel::~VideoChannel() {
TRACE_EVENT0("webrtc", "VideoChannel::~VideoChannel");
// this can't be done in the base class, since it calls a virtual
DisableMedia_w();
Deinit();
}
void VideoChannel::UpdateMediaSendRecvState_w() {
// Send outgoing data if we're the active call, we have the remote content,
// and we have had some form of connectivity.
bool send = IsReadyToSendMedia_w();
if (!media_channel()->SetSend(send)) {
RTC_LOG(LS_ERROR) << "Failed to SetSend on video channel";
// TODO(gangji): Report error back to server.
}
RTC_LOG(LS_INFO) << "Changing video state, send=" << send;
}
void VideoChannel::FillBitrateInfo(BandwidthEstimationInfo* bwe_info) {
InvokeOnWorker<void>(RTC_FROM_HERE, Bind(&VideoMediaChannel::FillBitrateInfo,
media_channel(), bwe_info));
}
bool VideoChannel::SetLocalContent_w(const MediaContentDescription* content,
SdpType type,
std::string* error_desc) {
TRACE_EVENT0("webrtc", "VideoChannel::SetLocalContent_w");
RTC_DCHECK_RUN_ON(worker_thread());
RTC_LOG(LS_INFO) << "Setting local video description";
RTC_DCHECK(content);
if (!content) {
SafeSetError("Can't find video content in local description.", error_desc);
return false;
}
const VideoContentDescription* video = content->as_video();
RtpHeaderExtensions rtp_header_extensions =
GetFilteredRtpHeaderExtensions(video->rtp_header_extensions());
UpdateRtpHeaderExtensionMap(rtp_header_extensions);
media_channel()->SetExtmapAllowMixed(video->extmap_allow_mixed());
VideoRecvParameters recv_params = last_recv_params_;
RtpParametersFromMediaDescription(video, rtp_header_extensions, &recv_params);
VideoSendParameters send_params = last_send_params_;
bool needs_send_params_update = false;
if (type == SdpType::kAnswer || type == SdpType::kPrAnswer) {
for (auto& send_codec : send_params.codecs) {
auto* recv_codec = FindMatchingCodec(recv_params.codecs, send_codec);
if (recv_codec) {
if (!recv_codec->packetization && send_codec.packetization) {
send_codec.packetization.reset();
needs_send_params_update = true;
} else if (recv_codec->packetization != send_codec.packetization) {
SafeSetError(
"Failed to set local answer due to invalid codec packetization.",
error_desc);
return false;
}
}
}
}
if (!media_channel()->SetRecvParameters(recv_params)) {
SafeSetError("Failed to set local video description recv parameters.",
error_desc);
return false;
}
if (webrtc::RtpTransceiverDirectionHasRecv(video->direction())) {
for (const VideoCodec& codec : video->codecs()) {
AddHandledPayloadType(codec.id);
}
// Need to re-register the sink to update the handled payload.
if (!RegisterRtpDemuxerSink()) {
RTC_LOG(LS_ERROR) << "Failed to set up video demuxing.";
return false;
}
}
last_recv_params_ = recv_params;
if (needs_send_params_update) {
if (!media_channel()->SetSendParameters(send_params)) {
SafeSetError("Failed to set send parameters.", error_desc);
return false;
}
last_send_params_ = send_params;
}
// TODO(pthatcher): Move local streams into VideoSendParameters, and
// only give it to the media channel once we have a remote
// description too (without a remote description, we won't be able
// to send them anyway).
if (!UpdateLocalStreams_w(video->streams(), type, error_desc)) {
SafeSetError("Failed to set local video description streams.", error_desc);
return false;
}
set_local_content_direction(content->direction());
UpdateMediaSendRecvState_w();
return true;
}
bool VideoChannel::SetRemoteContent_w(const MediaContentDescription* content,
SdpType type,
std::string* error_desc) {
TRACE_EVENT0("webrtc", "VideoChannel::SetRemoteContent_w");
RTC_DCHECK_RUN_ON(worker_thread());
RTC_LOG(LS_INFO) << "Setting remote video description";
RTC_DCHECK(content);
if (!content) {
SafeSetError("Can't find video content in remote description.", error_desc);
return false;
}
const VideoContentDescription* video = content->as_video();
RtpHeaderExtensions rtp_header_extensions =
GetFilteredRtpHeaderExtensions(video->rtp_header_extensions());
VideoSendParameters send_params = last_send_params_;
RtpSendParametersFromMediaDescription(video, rtp_header_extensions,
&send_params);
if (video->conference_mode()) {
send_params.conference_mode = true;
}
send_params.mid = content_name();
VideoRecvParameters recv_params = last_recv_params_;
bool needs_recv_params_update = false;
if (type == SdpType::kAnswer || type == SdpType::kPrAnswer) {
for (auto& recv_codec : recv_params.codecs) {
auto* send_codec = FindMatchingCodec(send_params.codecs, recv_codec);
if (send_codec) {
if (!send_codec->packetization && recv_codec.packetization) {
recv_codec.packetization.reset();
needs_recv_params_update = true;
} else if (send_codec->packetization != recv_codec.packetization) {
SafeSetError(
"Failed to set remote answer due to invalid codec packetization.",
error_desc);
return false;
}
}
}
}
if (!media_channel()->SetSendParameters(send_params)) {
SafeSetError("Failed to set remote video description send parameters.",
error_desc);
return false;
}
last_send_params_ = send_params;
if (needs_recv_params_update) {
if (!media_channel()->SetRecvParameters(recv_params)) {
SafeSetError("Failed to set recv parameters.", error_desc);
return false;
}
last_recv_params_ = recv_params;
}
if (!webrtc::RtpTransceiverDirectionHasSend(content->direction())) {
RTC_DLOG(LS_VERBOSE) << "SetRemoteContent_w: remote side will not send - "
"disable payload type demuxing";
ClearHandledPayloadTypes();
if (!RegisterRtpDemuxerSink()) {
RTC_LOG(LS_ERROR) << "Failed to update video demuxing.";
return false;
}
}
// TODO(pthatcher): Move remote streams into VideoRecvParameters,
// and only give it to the media channel once we have a local
// description too (without a local description, we won't be able to
// recv them anyway).
if (!UpdateRemoteStreams_w(video->streams(), type, error_desc)) {
SafeSetError("Failed to set remote video description streams.", error_desc);
return false;
}
set_remote_content_direction(content->direction());
UpdateMediaSendRecvState_w();
return true;
}
RtpDataChannel::RtpDataChannel(rtc::Thread* worker_thread,
rtc::Thread* network_thread,
rtc::Thread* signaling_thread,
std::unique_ptr<DataMediaChannel> media_channel,
const std::string& content_name,
bool srtp_required,
webrtc::CryptoOptions crypto_options,
UniqueRandomIdGenerator* ssrc_generator)
: BaseChannel(worker_thread,
network_thread,
signaling_thread,
std::move(media_channel),
Reland of TransportController refactoring. (patchset #1 id:1 of https://codereview.webrtc.org/1358413003/ ) Reason for revert: This CL just landed: https://codereview.chromium.org/1323243006/ Which fixes the FYI bots for the original CL, and breaks them for this revert. Original issue's description: > Revert of TransportController refactoring. (patchset #6 id:100001 of https://codereview.webrtc.org/1350523003/ ) > > Reason for revert: > This CL causes problems with the WebRTC-in-Chromium FYI bots. Presumably it needs to be done in several steps, where removed files are emptied instead of removed in the first step. > > Original issue's description: > > TransportController refactoring. > > > > Getting rid of TransportProxy, and in its place adding a > > TransportController class which will facilitate access to and manage > > the lifetimes of Transports. These Transports will now be accessed > > solely from the worker thread, simplifying their implementation. > > > > This refactoring also pulls Transport-related code out of BaseSession. > > Which means that BaseChannels will now rely on the TransportController > > interface to create channels, rather than BaseSession. > > > > Committed: https://crrev.com/47ee2f3b9f33e8938948c482c921d4e13a3acd83 > > Cr-Commit-Position: refs/heads/master@{#10022} > > TBR=pthatcher@webrtc.org,deadbeef@webrtc.org > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > > Committed: https://crrev.com/a81a42f584baa0d93a4b93da9632415e8922450c > Cr-Commit-Position: refs/heads/master@{#10024} TBR=pthatcher@webrtc.org,torbjorng@webrtc.org NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true Review URL: https://codereview.webrtc.org/1361773005 Cr-Commit-Position: refs/heads/master@{#10036}
2015-09-23 11:50:27 -07:00
content_name,
srtp_required,
crypto_options,
ssrc_generator) {}
RtpDataChannel::~RtpDataChannel() {
TRACE_EVENT0("webrtc", "RtpDataChannel::~RtpDataChannel");
// this can't be done in the base class, since it calls a virtual
DisableMedia_w();
Deinit();
}
void RtpDataChannel::Init_w(
webrtc::RtpTransportInternal* rtp_transport,
const webrtc::MediaTransportConfig& media_transport_config) {
BaseChannel::Init_w(rtp_transport, media_transport_config);
media_channel()->SignalDataReceived.connect(this,
&RtpDataChannel::OnDataReceived);
media_channel()->SignalReadyToSend.connect(
this, &RtpDataChannel::OnDataChannelReadyToSend);
}
bool RtpDataChannel::SendData(const SendDataParams& params,
const rtc::CopyOnWriteBuffer& payload,
SendDataResult* result) {
return InvokeOnWorker<bool>(
RTC_FROM_HERE, Bind(&DataMediaChannel::SendData, media_channel(), params,
payload, result));
}
bool RtpDataChannel::CheckDataChannelTypeFromContent(
Reland "Reland "Version 2 "Refactoring DataContentDescription class""" This reverts commit 46afbf9481fbcc939c998c898ca1031ce41cc6b1. Reason for revert: Tightened protocol name handling. Original change's description: > Revert "Reland "Version 2 "Refactoring DataContentDescription class""" > > This reverts commit 37f2b43274a0d718de53a4cfcf02226356edcf6e. > > Reason for revert: fuzzer failures > > Original change's description: > > Reland "Version 2 "Refactoring DataContentDescription class"" > > > > This is a reland of 14b2758726879d21671a21291dfed8fb4fd5c21c > > > > Original change's description: > > > Version 2 "Refactoring DataContentDescription class" > > > > > > (substantial changes since version 1) > > > > > > This CL splits the cricket::DataContentDescription class into > > > two classes: cricket::RtpDataContentDescription (used for RTP data) > > > and cricket::SctpDataContentDescription (used for SCTP only). > > > > > > SctpDataContentDescription no longer inherits from > > > MediaContentDescriptionImpl, and no longer contains "codecs". > > > > > > Due to usage of internal interfaces by consumers, shimming the old > > > DataContentDescription API is needed. > > > > > > A new cricket::DataContentDescription class is defined, which is > > > a shim over RtpDataContentDescription and SctpDataContentDescription. > > > It exposes as little functionality as possible, but supports the > > > concerned consumer's usage > > > > > > Design document: > > > https://docs.google.com/document/d/1H5LfQxJA2ikMWTQ8FZ3_GAmaXM7knfVQWiSz6ph8VQ0/edit# > > > > > > Version 1 reviewed-on: https://webrtc-review.googlesource.com/c/src/+/132700 > > > Bug: webrtc:10358 Change-Id: Ia9fb8f4679e082e3d18fbbb6b03fc13a08e06110 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/136581 Reviewed-by: Henrik Boström <hbos@webrtc.org> Reviewed-by: Steve Anton <steveanton@webrtc.org> Commit-Queue: Harald Alvestrand <hta@webrtc.org> Cr-Commit-Position: refs/heads/master@{#27933}
2019-05-13 13:36:16 +02:00
const RtpDataContentDescription* content,
Revert of Separating SCTP code from BaseChannel/MediaChannel. (patchset #14 id:240001 of https://codereview.webrtc.org/2564333002/ ) Reason for revert: Hitting DCHECK in chromium's WebrtcTransportTest.TerminateDataChannel and WebrtcTransportTest.DataStreamLate. Will investigate and reland. Original issue's description: > Separating SCTP code from BaseChannel/MediaChannel. > > The BaseChannel code is geared around RTP; the presence of media engines, > send and receive streams, SRTP, SDP directional attribute negotiation, etc. > It doesn't make sense to use it for SCTP as well. This separation should make > future work both on BaseChannel and the SCTP code paths easier. > > SctpDataEngine now becomes SctpTransport, and is used by WebRtcSession > directly. cricket::DataChannel is also renamed, to RtpDataChannel, so it > doesn't get confused with webrtc::DataChannel any more. > > Beyond just moving code around, some consequences of this CL: > - We'll now stop using the worker thread for SCTP. Packets will be > processed right on the network thread instead. > - The SDP directional attribute is ignored, as it's supposed to be. > > BUG=None > > Review-Url: https://codereview.webrtc.org/2564333002 > Cr-Commit-Position: refs/heads/master@{#15906} > Committed: https://chromium.googlesource.com/external/webrtc/+/67b3bbe639645ab719972682359acda303d94454 TBR=pthatcher@webrtc.org # Skipping CQ checks because original CL landed less than 1 days ago. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=None Review-Url: https://codereview.webrtc.org/2614813003 Cr-Commit-Position: refs/heads/master@{#15908}
2017-01-04 20:28:21 -08:00
std::string* error_desc) {
bool is_sctp = ((content->protocol() == kMediaProtocolSctp) ||
(content->protocol() == kMediaProtocolDtlsSctp));
// It's been set before, but doesn't match. That's bad.
if (is_sctp) {
SafeSetError("Data channel type mismatch. Expected RTP, got SCTP.",
error_desc);
return false;
}
return true;
Revert of Separating SCTP code from BaseChannel/MediaChannel. (patchset #14 id:240001 of https://codereview.webrtc.org/2564333002/ ) Reason for revert: Hitting DCHECK in chromium's WebrtcTransportTest.TerminateDataChannel and WebrtcTransportTest.DataStreamLate. Will investigate and reland. Original issue's description: > Separating SCTP code from BaseChannel/MediaChannel. > > The BaseChannel code is geared around RTP; the presence of media engines, > send and receive streams, SRTP, SDP directional attribute negotiation, etc. > It doesn't make sense to use it for SCTP as well. This separation should make > future work both on BaseChannel and the SCTP code paths easier. > > SctpDataEngine now becomes SctpTransport, and is used by WebRtcSession > directly. cricket::DataChannel is also renamed, to RtpDataChannel, so it > doesn't get confused with webrtc::DataChannel any more. > > Beyond just moving code around, some consequences of this CL: > - We'll now stop using the worker thread for SCTP. Packets will be > processed right on the network thread instead. > - The SDP directional attribute is ignored, as it's supposed to be. > > BUG=None > > Review-Url: https://codereview.webrtc.org/2564333002 > Cr-Commit-Position: refs/heads/master@{#15906} > Committed: https://chromium.googlesource.com/external/webrtc/+/67b3bbe639645ab719972682359acda303d94454 TBR=pthatcher@webrtc.org # Skipping CQ checks because original CL landed less than 1 days ago. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=None Review-Url: https://codereview.webrtc.org/2614813003 Cr-Commit-Position: refs/heads/master@{#15908}
2017-01-04 20:28:21 -08:00
}
bool RtpDataChannel::SetLocalContent_w(const MediaContentDescription* content,
SdpType type,
std::string* error_desc) {
TRACE_EVENT0("webrtc", "RtpDataChannel::SetLocalContent_w");
RTC_DCHECK_RUN_ON(worker_thread());
RTC_LOG(LS_INFO) << "Setting local data description";
RTC_DCHECK(content);
if (!content) {
SafeSetError("Can't find data content in local description.", error_desc);
return false;
}
Reland "Reland "Version 2 "Refactoring DataContentDescription class""" This reverts commit 46afbf9481fbcc939c998c898ca1031ce41cc6b1. Reason for revert: Tightened protocol name handling. Original change's description: > Revert "Reland "Version 2 "Refactoring DataContentDescription class""" > > This reverts commit 37f2b43274a0d718de53a4cfcf02226356edcf6e. > > Reason for revert: fuzzer failures > > Original change's description: > > Reland "Version 2 "Refactoring DataContentDescription class"" > > > > This is a reland of 14b2758726879d21671a21291dfed8fb4fd5c21c > > > > Original change's description: > > > Version 2 "Refactoring DataContentDescription class" > > > > > > (substantial changes since version 1) > > > > > > This CL splits the cricket::DataContentDescription class into > > > two classes: cricket::RtpDataContentDescription (used for RTP data) > > > and cricket::SctpDataContentDescription (used for SCTP only). > > > > > > SctpDataContentDescription no longer inherits from > > > MediaContentDescriptionImpl, and no longer contains "codecs". > > > > > > Due to usage of internal interfaces by consumers, shimming the old > > > DataContentDescription API is needed. > > > > > > A new cricket::DataContentDescription class is defined, which is > > > a shim over RtpDataContentDescription and SctpDataContentDescription. > > > It exposes as little functionality as possible, but supports the > > > concerned consumer's usage > > > > > > Design document: > > > https://docs.google.com/document/d/1H5LfQxJA2ikMWTQ8FZ3_GAmaXM7knfVQWiSz6ph8VQ0/edit# > > > > > > Version 1 reviewed-on: https://webrtc-review.googlesource.com/c/src/+/132700 > > > Bug: webrtc:10358 Change-Id: Ia9fb8f4679e082e3d18fbbb6b03fc13a08e06110 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/136581 Reviewed-by: Henrik Boström <hbos@webrtc.org> Reviewed-by: Steve Anton <steveanton@webrtc.org> Commit-Queue: Harald Alvestrand <hta@webrtc.org> Cr-Commit-Position: refs/heads/master@{#27933}
2019-05-13 13:36:16 +02:00
const RtpDataContentDescription* data = content->as_rtp_data();
if (!CheckDataChannelTypeFromContent(data, error_desc)) {
return false;
}
RtpHeaderExtensions rtp_header_extensions =
GetFilteredRtpHeaderExtensions(data->rtp_header_extensions());
DataRecvParameters recv_params = last_recv_params_;
RtpParametersFromMediaDescription(data, rtp_header_extensions, &recv_params);
if (!media_channel()->SetRecvParameters(recv_params)) {
SafeSetError("Failed to set remote data description recv parameters.",
error_desc);
return false;
}
for (const DataCodec& codec : data->codecs()) {
AddHandledPayloadType(codec.id);
}
// Need to re-register the sink to update the handled payload.
if (!RegisterRtpDemuxerSink()) {
RTC_LOG(LS_ERROR) << "Failed to set up data demuxing.";
return false;
}
last_recv_params_ = recv_params;
// TODO(pthatcher): Move local streams into DataSendParameters, and
// only give it to the media channel once we have a remote
// description too (without a remote description, we won't be able
// to send them anyway).
if (!UpdateLocalStreams_w(data->streams(), type, error_desc)) {
SafeSetError("Failed to set local data description streams.", error_desc);
return false;
}
set_local_content_direction(content->direction());
UpdateMediaSendRecvState_w();
return true;
}
bool RtpDataChannel::SetRemoteContent_w(const MediaContentDescription* content,
SdpType type,
std::string* error_desc) {
TRACE_EVENT0("webrtc", "RtpDataChannel::SetRemoteContent_w");
RTC_DCHECK_RUN_ON(worker_thread());
RTC_LOG(LS_INFO) << "Setting remote data description";
RTC_DCHECK(content);
if (!content) {
SafeSetError("Can't find data content in remote description.", error_desc);
return false;
}
Reland "Reland "Version 2 "Refactoring DataContentDescription class""" This reverts commit 46afbf9481fbcc939c998c898ca1031ce41cc6b1. Reason for revert: Tightened protocol name handling. Original change's description: > Revert "Reland "Version 2 "Refactoring DataContentDescription class""" > > This reverts commit 37f2b43274a0d718de53a4cfcf02226356edcf6e. > > Reason for revert: fuzzer failures > > Original change's description: > > Reland "Version 2 "Refactoring DataContentDescription class"" > > > > This is a reland of 14b2758726879d21671a21291dfed8fb4fd5c21c > > > > Original change's description: > > > Version 2 "Refactoring DataContentDescription class" > > > > > > (substantial changes since version 1) > > > > > > This CL splits the cricket::DataContentDescription class into > > > two classes: cricket::RtpDataContentDescription (used for RTP data) > > > and cricket::SctpDataContentDescription (used for SCTP only). > > > > > > SctpDataContentDescription no longer inherits from > > > MediaContentDescriptionImpl, and no longer contains "codecs". > > > > > > Due to usage of internal interfaces by consumers, shimming the old > > > DataContentDescription API is needed. > > > > > > A new cricket::DataContentDescription class is defined, which is > > > a shim over RtpDataContentDescription and SctpDataContentDescription. > > > It exposes as little functionality as possible, but supports the > > > concerned consumer's usage > > > > > > Design document: > > > https://docs.google.com/document/d/1H5LfQxJA2ikMWTQ8FZ3_GAmaXM7knfVQWiSz6ph8VQ0/edit# > > > > > > Version 1 reviewed-on: https://webrtc-review.googlesource.com/c/src/+/132700 > > > Bug: webrtc:10358 Change-Id: Ia9fb8f4679e082e3d18fbbb6b03fc13a08e06110 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/136581 Reviewed-by: Henrik Boström <hbos@webrtc.org> Reviewed-by: Steve Anton <steveanton@webrtc.org> Commit-Queue: Harald Alvestrand <hta@webrtc.org> Cr-Commit-Position: refs/heads/master@{#27933}
2019-05-13 13:36:16 +02:00
const RtpDataContentDescription* data = content->as_rtp_data();
if (!data) {
RTC_LOG(LS_INFO) << "Accepting and ignoring non-RTP content description";
return true;
}
// If the remote data doesn't have codecs, it must be empty, so ignore it.
if (!data->has_codecs()) {
return true;
}
if (!CheckDataChannelTypeFromContent(data, error_desc)) {
return false;
}
RtpHeaderExtensions rtp_header_extensions =
GetFilteredRtpHeaderExtensions(data->rtp_header_extensions());
RTC_LOG(LS_INFO) << "Setting remote data description";
DataSendParameters send_params = last_send_params_;
RtpSendParametersFromMediaDescription<DataCodec>(data, rtp_header_extensions,
&send_params);
if (!media_channel()->SetSendParameters(send_params)) {
SafeSetError("Failed to set remote data description send parameters.",
error_desc);
return false;
}
last_send_params_ = send_params;
// TODO(pthatcher): Move remote streams into DataRecvParameters,
// and only give it to the media channel once we have a local
// description too (without a local description, we won't be able to
// recv them anyway).
if (!UpdateRemoteStreams_w(data->streams(), type, error_desc)) {
SafeSetError("Failed to set remote data description streams.", error_desc);
return false;
}
set_remote_content_direction(content->direction());
UpdateMediaSendRecvState_w();
return true;
}
void RtpDataChannel::UpdateMediaSendRecvState_w() {
// Render incoming data if we're the active call, and we have the local
// content. We receive data on the default channel and multiplexed streams.
bool recv = IsReadyToReceiveMedia_w();
if (!media_channel()->SetReceive(recv)) {
RTC_LOG(LS_ERROR) << "Failed to SetReceive on data channel";
}
// Send outgoing data if we're the active call, we have the remote content,
// and we have had some form of connectivity.
bool send = IsReadyToSendMedia_w();
if (!media_channel()->SetSend(send)) {
RTC_LOG(LS_ERROR) << "Failed to SetSend on data channel";
}
// Trigger SignalReadyToSendData asynchronously.
OnDataChannelReadyToSend(send);
RTC_LOG(LS_INFO) << "Changing data state, recv=" << recv << " send=" << send;
}
void RtpDataChannel::OnMessage(rtc::Message* pmsg) {
switch (pmsg->message_id) {
case MSG_READYTOSENDDATA: {
DataChannelReadyToSendMessageData* data =
static_cast<DataChannelReadyToSendMessageData*>(pmsg->pdata);
ready_to_send_data_ = data->data();
SignalReadyToSendData(ready_to_send_data_);
delete data;
break;
}
case MSG_DATARECEIVED: {
DataReceivedMessageData* data =
static_cast<DataReceivedMessageData*>(pmsg->pdata);
SignalDataReceived(data->params, data->payload);
delete data;
break;
}
default:
BaseChannel::OnMessage(pmsg);
break;
}
}
void RtpDataChannel::OnDataReceived(const ReceiveDataParams& params,
const char* data,
size_t len) {
DataReceivedMessageData* msg = new DataReceivedMessageData(params, data, len);
signaling_thread()->Post(RTC_FROM_HERE, this, MSG_DATARECEIVED, msg);
}
void RtpDataChannel::OnDataChannelReadyToSend(bool writable) {
// This is usded for congestion control to indicate that the stream is ready
// to send by the MediaChannel, as opposed to OnReadyToSend, which indicates
// that the transport channel is ready.
signaling_thread()->Post(RTC_FROM_HERE, this, MSG_READYTOSENDDATA,
new DataChannelReadyToSendMessageData(writable));
}
} // namespace cricket