2011-07-07 08:21:25 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2011 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2013-05-21 13:52:32 +00:00
|
|
|
#include "webrtc/voice_engine/channel_manager.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
Reland of Delete class SSRCDatabase, and its global ssrc registry. (patchset #1 id:1 of https://codereview.webrtc.org/2700413002/ )
Reason for revert:
Intend to fix perf problem and reland.
Original issue's description:
> Revert of Delete class SSRCDatabase, and its global ssrc registry. (patchset #20 id:370001 of https://codereview.webrtc.org/2644303002/ )
>
> Reason for revert:
> Breaks webrtc_perf_tests reliably:
> https://build.chromium.org/p/client.webrtc.perf/builders/Android32%20Tests%20%28L%20Nexus5%29/builds/1780
> https://build.chromium.org/p/client.webrtc.perf/builders/Android32%20Tests%20%28L%20Nexus4%29/builds/178
>
> We're actively working on getting a quick version of webrtc_perf_tests up on the trybots again to prevent breakages like this: https://bugs.chromium.org/p/webrtc/issues/detail?id=7101
>
> Original issue's description:
> > Delete class SSRCDatabase, and its global ssrc registry,
> > and the method RTPSender::GenerateNewSSRC.
> >
> > It's now mandatory for higher layers to call SetSSRC, RTPSender
> > no longer allocates any ssrc by default.
> >
> > BUG=webrtc:4306,webrtc:6887
> >
> > Review-Url: https://codereview.webrtc.org/2644303002
> > Cr-Commit-Position: refs/heads/master@{#16670}
> > Committed: https://chromium.googlesource.com/external/webrtc/+/b78d4d13835f628e722a57abae2bf06ba3655921
>
> TBR=solenberg@webrtc.org,stefan@webrtc.org,danilchap@webrtc.org,ivoc@webrtc.org,nisse@webrtc.org
> NOTRY=True
> BUG=webrtc:4306,webrtc:6887
>
> Review-Url: https://codereview.webrtc.org/2700413002
> Cr-Commit-Position: refs/heads/master@{#16693}
> Committed: https://chromium.googlesource.com/external/webrtc/+/b5848ecbf5f7b310108546ec6b858fe93452f58e
TBR=solenberg@webrtc.org,stefan@webrtc.org,danilchap@webrtc.org,ivoc@webrtc.org,kjellander@webrtc.org,kjellander@google.com
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=webrtc:4306,webrtc:6887
Review-Url: https://codereview.webrtc.org/2702203002
Cr-Commit-Position: refs/heads/master@{#16737}
2017-02-21 03:40:24 -08:00
|
|
|
#include "webrtc/base/timeutils.h"
|
2013-08-07 17:57:36 +00:00
|
|
|
#include "webrtc/voice_engine/channel.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-08-07 17:57:36 +00:00
|
|
|
namespace webrtc {
|
|
|
|
|
namespace voe {
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-08-07 17:57:36 +00:00
|
|
|
ChannelOwner::ChannelOwner(class Channel* channel)
|
|
|
|
|
: channel_ref_(new ChannelRef(channel)) {}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-08-07 17:57:36 +00:00
|
|
|
ChannelOwner::ChannelOwner(const ChannelOwner& channel_owner)
|
|
|
|
|
: channel_ref_(channel_owner.channel_ref_) {
|
|
|
|
|
++channel_ref_->ref_count;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-08-07 17:57:36 +00:00
|
|
|
ChannelOwner::~ChannelOwner() {
|
|
|
|
|
if (--channel_ref_->ref_count == 0)
|
|
|
|
|
delete channel_ref_;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-08-07 17:57:36 +00:00
|
|
|
ChannelOwner& ChannelOwner::operator=(const ChannelOwner& other) {
|
|
|
|
|
if (other.channel_ref_ == channel_ref_)
|
|
|
|
|
return *this;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-08-07 17:57:36 +00:00
|
|
|
if (--channel_ref_->ref_count == 0)
|
|
|
|
|
delete channel_ref_;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-08-07 17:57:36 +00:00
|
|
|
channel_ref_ = other.channel_ref_;
|
|
|
|
|
++channel_ref_->ref_count;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-08-07 17:57:36 +00:00
|
|
|
return *this;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-08-07 17:57:36 +00:00
|
|
|
ChannelOwner::ChannelRef::ChannelRef(class Channel* channel)
|
|
|
|
|
: channel(channel), ref_count(1) {}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-09-07 07:34:41 -07:00
|
|
|
ChannelManager::ChannelManager(uint32_t instance_id)
|
Reland of Delete class SSRCDatabase, and its global ssrc registry. (patchset #1 id:1 of https://codereview.webrtc.org/2700413002/ )
Reason for revert:
Intend to fix perf problem and reland.
Original issue's description:
> Revert of Delete class SSRCDatabase, and its global ssrc registry. (patchset #20 id:370001 of https://codereview.webrtc.org/2644303002/ )
>
> Reason for revert:
> Breaks webrtc_perf_tests reliably:
> https://build.chromium.org/p/client.webrtc.perf/builders/Android32%20Tests%20%28L%20Nexus5%29/builds/1780
> https://build.chromium.org/p/client.webrtc.perf/builders/Android32%20Tests%20%28L%20Nexus4%29/builds/178
>
> We're actively working on getting a quick version of webrtc_perf_tests up on the trybots again to prevent breakages like this: https://bugs.chromium.org/p/webrtc/issues/detail?id=7101
>
> Original issue's description:
> > Delete class SSRCDatabase, and its global ssrc registry,
> > and the method RTPSender::GenerateNewSSRC.
> >
> > It's now mandatory for higher layers to call SetSSRC, RTPSender
> > no longer allocates any ssrc by default.
> >
> > BUG=webrtc:4306,webrtc:6887
> >
> > Review-Url: https://codereview.webrtc.org/2644303002
> > Cr-Commit-Position: refs/heads/master@{#16670}
> > Committed: https://chromium.googlesource.com/external/webrtc/+/b78d4d13835f628e722a57abae2bf06ba3655921
>
> TBR=solenberg@webrtc.org,stefan@webrtc.org,danilchap@webrtc.org,ivoc@webrtc.org,nisse@webrtc.org
> NOTRY=True
> BUG=webrtc:4306,webrtc:6887
>
> Review-Url: https://codereview.webrtc.org/2700413002
> Cr-Commit-Position: refs/heads/master@{#16693}
> Committed: https://chromium.googlesource.com/external/webrtc/+/b5848ecbf5f7b310108546ec6b858fe93452f58e
TBR=solenberg@webrtc.org,stefan@webrtc.org,danilchap@webrtc.org,ivoc@webrtc.org,kjellander@webrtc.org,kjellander@google.com
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=webrtc:4306,webrtc:6887
Review-Url: https://codereview.webrtc.org/2702203002
Cr-Commit-Position: refs/heads/master@{#16737}
2017-02-21 03:40:24 -08:00
|
|
|
: instance_id_(instance_id),
|
|
|
|
|
last_channel_id_(-1),
|
|
|
|
|
random_(rtc::TimeNanos()) {}
|
2013-08-07 17:57:36 +00:00
|
|
|
|
2016-05-30 08:11:28 -07:00
|
|
|
ChannelOwner ChannelManager::CreateChannel(
|
2016-09-07 07:34:41 -07:00
|
|
|
const VoEBase::ChannelConfig& config) {
|
2013-08-07 17:57:36 +00:00
|
|
|
Channel* channel;
|
2016-09-07 07:34:41 -07:00
|
|
|
Channel::CreateChannel(channel, ++last_channel_id_, instance_id_, config);
|
Reland of Delete class SSRCDatabase, and its global ssrc registry. (patchset #1 id:1 of https://codereview.webrtc.org/2700413002/ )
Reason for revert:
Intend to fix perf problem and reland.
Original issue's description:
> Revert of Delete class SSRCDatabase, and its global ssrc registry. (patchset #20 id:370001 of https://codereview.webrtc.org/2644303002/ )
>
> Reason for revert:
> Breaks webrtc_perf_tests reliably:
> https://build.chromium.org/p/client.webrtc.perf/builders/Android32%20Tests%20%28L%20Nexus5%29/builds/1780
> https://build.chromium.org/p/client.webrtc.perf/builders/Android32%20Tests%20%28L%20Nexus4%29/builds/178
>
> We're actively working on getting a quick version of webrtc_perf_tests up on the trybots again to prevent breakages like this: https://bugs.chromium.org/p/webrtc/issues/detail?id=7101
>
> Original issue's description:
> > Delete class SSRCDatabase, and its global ssrc registry,
> > and the method RTPSender::GenerateNewSSRC.
> >
> > It's now mandatory for higher layers to call SetSSRC, RTPSender
> > no longer allocates any ssrc by default.
> >
> > BUG=webrtc:4306,webrtc:6887
> >
> > Review-Url: https://codereview.webrtc.org/2644303002
> > Cr-Commit-Position: refs/heads/master@{#16670}
> > Committed: https://chromium.googlesource.com/external/webrtc/+/b78d4d13835f628e722a57abae2bf06ba3655921
>
> TBR=solenberg@webrtc.org,stefan@webrtc.org,danilchap@webrtc.org,ivoc@webrtc.org,nisse@webrtc.org
> NOTRY=True
> BUG=webrtc:4306,webrtc:6887
>
> Review-Url: https://codereview.webrtc.org/2700413002
> Cr-Commit-Position: refs/heads/master@{#16693}
> Committed: https://chromium.googlesource.com/external/webrtc/+/b5848ecbf5f7b310108546ec6b858fe93452f58e
TBR=solenberg@webrtc.org,stefan@webrtc.org,danilchap@webrtc.org,ivoc@webrtc.org,kjellander@webrtc.org,kjellander@google.com
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=webrtc:4306,webrtc:6887
Review-Url: https://codereview.webrtc.org/2702203002
Cr-Commit-Position: refs/heads/master@{#16737}
2017-02-21 03:40:24 -08:00
|
|
|
// TODO(solenberg): Delete this, users should configure ssrc
|
|
|
|
|
// explicitly.
|
|
|
|
|
channel->SetLocalSSRC(random_.Rand<uint32_t>());
|
|
|
|
|
|
2013-08-07 17:57:36 +00:00
|
|
|
ChannelOwner channel_owner(channel);
|
|
|
|
|
|
2016-01-21 10:37:37 -08:00
|
|
|
rtc::CritScope crit(&lock_);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-08-07 17:57:36 +00:00
|
|
|
channels_.push_back(channel_owner);
|
|
|
|
|
|
|
|
|
|
return channel_owner;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-08-07 17:57:36 +00:00
|
|
|
ChannelOwner ChannelManager::GetChannel(int32_t channel_id) {
|
2016-01-21 10:37:37 -08:00
|
|
|
rtc::CritScope crit(&lock_);
|
2013-08-07 17:57:36 +00:00
|
|
|
|
|
|
|
|
for (size_t i = 0; i < channels_.size(); ++i) {
|
|
|
|
|
if (channels_[i].channel()->ChannelId() == channel_id)
|
|
|
|
|
return channels_[i];
|
|
|
|
|
}
|
|
|
|
|
return ChannelOwner(NULL);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-08-07 17:57:36 +00:00
|
|
|
void ChannelManager::GetAllChannels(std::vector<ChannelOwner>* channels) {
|
2016-01-21 10:37:37 -08:00
|
|
|
rtc::CritScope crit(&lock_);
|
2013-08-07 17:57:36 +00:00
|
|
|
|
|
|
|
|
*channels = channels_;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-08-07 17:57:36 +00:00
|
|
|
void ChannelManager::DestroyChannel(int32_t channel_id) {
|
|
|
|
|
assert(channel_id >= 0);
|
2013-08-08 17:32:21 +00:00
|
|
|
// Holds a reference to a channel, this is used so that we never delete
|
|
|
|
|
// Channels while holding a lock, but rather when the method returns.
|
|
|
|
|
ChannelOwner reference(NULL);
|
|
|
|
|
{
|
2016-01-21 10:37:37 -08:00
|
|
|
rtc::CritScope crit(&lock_);
|
2015-05-13 14:14:42 +02:00
|
|
|
std::vector<ChannelOwner>::iterator to_delete = channels_.end();
|
|
|
|
|
for (auto it = channels_.begin(); it != channels_.end(); ++it) {
|
|
|
|
|
Channel* channel = it->channel();
|
|
|
|
|
// For channels associated with the channel to be deleted, disassociate
|
|
|
|
|
// with that channel.
|
|
|
|
|
channel->DisassociateSendChannel(channel_id);
|
|
|
|
|
|
|
|
|
|
if (channel->ChannelId() == channel_id) {
|
|
|
|
|
to_delete = it;
|
2013-08-08 17:32:21 +00:00
|
|
|
}
|
2013-08-07 17:57:36 +00:00
|
|
|
}
|
2015-05-13 14:14:42 +02:00
|
|
|
if (to_delete != channels_.end()) {
|
|
|
|
|
reference = *to_delete;
|
|
|
|
|
channels_.erase(to_delete);
|
|
|
|
|
}
|
2013-08-07 17:57:36 +00:00
|
|
|
}
|
2017-03-21 02:31:51 -07:00
|
|
|
if (reference.channel()) {
|
|
|
|
|
// Ensure the channel is torn down now, on this thread, since a reference
|
|
|
|
|
// may still be held on a different thread (e.g. in the audio capture
|
|
|
|
|
// thread).
|
|
|
|
|
reference.channel()->Terminate();
|
|
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-08-07 17:57:36 +00:00
|
|
|
void ChannelManager::DestroyAllChannels() {
|
2013-08-08 17:32:21 +00:00
|
|
|
// Holds references so that Channels are not destroyed while holding this
|
|
|
|
|
// lock, but rather when the method returns.
|
|
|
|
|
std::vector<ChannelOwner> references;
|
|
|
|
|
{
|
2016-01-21 10:37:37 -08:00
|
|
|
rtc::CritScope crit(&lock_);
|
2013-08-08 17:32:21 +00:00
|
|
|
references = channels_;
|
|
|
|
|
channels_.clear();
|
|
|
|
|
}
|
2017-03-21 02:31:51 -07:00
|
|
|
for (auto& owner : references) {
|
|
|
|
|
if (owner.channel())
|
|
|
|
|
owner.channel()->Terminate();
|
|
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-08-07 17:57:36 +00:00
|
|
|
size_t ChannelManager::NumOfChannels() const {
|
2016-01-21 10:37:37 -08:00
|
|
|
rtc::CritScope crit(&lock_);
|
2013-08-07 17:57:36 +00:00
|
|
|
return channels_.size();
|
|
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-08-07 17:57:36 +00:00
|
|
|
ChannelManager::Iterator::Iterator(ChannelManager* channel_manager)
|
|
|
|
|
: iterator_pos_(0) {
|
|
|
|
|
channel_manager->GetAllChannels(&channels_);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-08-07 17:57:36 +00:00
|
|
|
Channel* ChannelManager::Iterator::GetChannel() {
|
|
|
|
|
if (iterator_pos_ < channels_.size())
|
|
|
|
|
return channels_[iterator_pos_].channel();
|
|
|
|
|
return NULL;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-08-07 17:57:36 +00:00
|
|
|
bool ChannelManager::Iterator::IsValid() {
|
|
|
|
|
return iterator_pos_ < channels_.size();
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-08-07 17:57:36 +00:00
|
|
|
void ChannelManager::Iterator::Increment() {
|
|
|
|
|
++iterator_pos_;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-07-03 15:12:26 +00:00
|
|
|
} // namespace voe
|
|
|
|
|
} // namespace webrtc
|