Name change on channel and channel_id for consistency.

Bug: webrtc:12111
Change-Id: I5ea5f7b73ab8493bcbb67bc0144e0c261aedc1ed
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/192000
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Commit-Queue: Tim Na <natim@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#32597}
This commit is contained in:
Tim Na 2020-11-11 14:04:40 -08:00 committed by Commit Bot
parent 5d55597932
commit 428432d09e
2 changed files with 89 additions and 77 deletions

View File

@ -117,7 +117,7 @@ bool VoipCore::Init(rtc::scoped_refptr<AudioEncoderFactory> encoder_factory,
absl::optional<ChannelId> VoipCore::CreateChannel(
Transport* transport,
absl::optional<uint32_t> local_ssrc) {
absl::optional<ChannelId> channel;
absl::optional<ChannelId> channel_id;
// Set local ssrc to random if not set by caller.
if (!local_ssrc) {
@ -125,7 +125,7 @@ absl::optional<ChannelId> VoipCore::CreateChannel(
local_ssrc = random.Rand<uint32_t>();
}
rtc::scoped_refptr<AudioChannel> audio_channel =
rtc::scoped_refptr<AudioChannel> channel =
new rtc::RefCountedObject<AudioChannel>(
transport, local_ssrc.value(), task_queue_factory_.get(),
process_thread_.get(), audio_mixer_.get(), decoder_factory_);
@ -139,8 +139,8 @@ absl::optional<ChannelId> VoipCore::CreateChannel(
// Start process thread if the channel is the first one.
start_process_thread = channels_.empty();
channel = static_cast<ChannelId>(next_channel_id_);
channels_[*channel] = audio_channel;
channel_id = static_cast<ChannelId>(next_channel_id_);
channels_[*channel_id] = channel;
next_channel_id_++;
if (next_channel_id_ >= kMaxChannelId) {
next_channel_id_ = 0;
@ -148,40 +148,40 @@ absl::optional<ChannelId> VoipCore::CreateChannel(
}
// Set ChannelId in audio channel for logging/debugging purpose.
audio_channel->SetId(*channel);
channel->SetId(*channel_id);
if (start_process_thread) {
process_thread_->Start();
}
return channel;
return channel_id;
}
void VoipCore::ReleaseChannel(ChannelId channel) {
void VoipCore::ReleaseChannel(ChannelId channel_id) {
// Destroy channel outside of the lock.
rtc::scoped_refptr<AudioChannel> audio_channel;
rtc::scoped_refptr<AudioChannel> channel;
bool no_channels_after_release = false;
{
MutexLock lock(&lock_);
auto iter = channels_.find(channel);
auto iter = channels_.find(channel_id);
if (iter != channels_.end()) {
audio_channel = std::move(iter->second);
channel = std::move(iter->second);
channels_.erase(iter);
}
no_channels_after_release = channels_.empty();
}
if (!audio_channel) {
RTC_LOG(LS_WARNING) << "Channel " << channel << " not found";
if (!channel) {
RTC_LOG(LS_WARNING) << "Channel " << channel_id << " not found";
}
if (no_channels_after_release) {
// Release audio channel first to have it DeRegisterModule first.
audio_channel = nullptr;
channel = nullptr;
process_thread_->Stop();
// Make sure to stop playout on ADM if it is playing.
@ -193,19 +193,19 @@ void VoipCore::ReleaseChannel(ChannelId channel) {
}
}
rtc::scoped_refptr<AudioChannel> VoipCore::GetChannel(ChannelId channel) {
rtc::scoped_refptr<AudioChannel> audio_channel;
rtc::scoped_refptr<AudioChannel> VoipCore::GetChannel(ChannelId channel_id) {
rtc::scoped_refptr<AudioChannel> channel;
{
MutexLock lock(&lock_);
auto iter = channels_.find(channel);
auto iter = channels_.find(channel_id);
if (iter != channels_.end()) {
audio_channel = iter->second;
channel = iter->second;
}
}
if (!audio_channel) {
RTC_LOG(LS_ERROR) << "Channel " << channel << " not found";
if (!channel) {
RTC_LOG(LS_ERROR) << "Channel " << channel_id << " not found";
}
return audio_channel;
return channel;
}
bool VoipCore::UpdateAudioTransportWithSenders() {
@ -263,37 +263,40 @@ bool VoipCore::UpdateAudioTransportWithSenders() {
return true;
}
bool VoipCore::StartSend(ChannelId channel) {
auto audio_channel = GetChannel(channel);
if (!audio_channel || !audio_channel->StartSend()) {
bool VoipCore::StartSend(ChannelId channel_id) {
rtc::scoped_refptr<AudioChannel> channel = GetChannel(channel_id);
if (!channel || !channel->StartSend()) {
return false;
}
return UpdateAudioTransportWithSenders();
}
bool VoipCore::StopSend(ChannelId channel) {
auto audio_channel = GetChannel(channel);
if (!audio_channel) {
bool VoipCore::StopSend(ChannelId channel_id) {
rtc::scoped_refptr<AudioChannel> channel = GetChannel(channel_id);
if (!channel) {
return false;
}
audio_channel->StopSend();
channel->StopSend();
return UpdateAudioTransportWithSenders();
}
bool VoipCore::StartPlayout(ChannelId channel) {
auto audio_channel = GetChannel(channel);
if (!audio_channel) {
bool VoipCore::StartPlayout(ChannelId channel_id) {
rtc::scoped_refptr<AudioChannel> channel = GetChannel(channel_id);
if (!channel) {
return false;
}
if (audio_channel->IsPlaying()) {
if (channel->IsPlaying()) {
return true;
}
if (!audio_channel->StartPlay()) {
if (!channel->StartPlay()) {
return false;
}
@ -310,77 +313,86 @@ bool VoipCore::StartPlayout(ChannelId channel) {
return true;
}
bool VoipCore::StopPlayout(ChannelId channel) {
auto audio_channel = GetChannel(channel);
if (!audio_channel) {
bool VoipCore::StopPlayout(ChannelId channel_id) {
rtc::scoped_refptr<AudioChannel> channel = GetChannel(channel_id);
if (!channel) {
return false;
}
audio_channel->StopPlay();
channel->StopPlay();
return true;
}
void VoipCore::ReceivedRTPPacket(ChannelId channel,
void VoipCore::ReceivedRTPPacket(ChannelId channel_id,
rtc::ArrayView<const uint8_t> rtp_packet) {
// Failure to locate channel is logged internally in GetChannel.
if (auto audio_channel = GetChannel(channel)) {
audio_channel->ReceivedRTPPacket(rtp_packet);
rtc::scoped_refptr<AudioChannel> channel = GetChannel(channel_id);
if (channel) {
channel->ReceivedRTPPacket(rtp_packet);
}
}
void VoipCore::ReceivedRTCPPacket(ChannelId channel,
void VoipCore::ReceivedRTCPPacket(ChannelId channel_id,
rtc::ArrayView<const uint8_t> rtcp_packet) {
// Failure to locate channel is logged internally in GetChannel.
if (auto audio_channel = GetChannel(channel)) {
audio_channel->ReceivedRTCPPacket(rtcp_packet);
rtc::scoped_refptr<AudioChannel> channel = GetChannel(channel_id);
if (channel) {
channel->ReceivedRTCPPacket(rtcp_packet);
}
}
void VoipCore::SetSendCodec(ChannelId channel,
void VoipCore::SetSendCodec(ChannelId channel_id,
int payload_type,
const SdpAudioFormat& encoder_format) {
// Failure to locate channel is logged internally in GetChannel.
if (auto audio_channel = GetChannel(channel)) {
rtc::scoped_refptr<AudioChannel> channel = GetChannel(channel_id);
if (channel) {
auto encoder = encoder_factory_->MakeAudioEncoder(
payload_type, encoder_format, absl::nullopt);
audio_channel->SetEncoder(payload_type, encoder_format, std::move(encoder));
channel->SetEncoder(payload_type, encoder_format, std::move(encoder));
}
}
void VoipCore::SetReceiveCodecs(
ChannelId channel,
ChannelId channel_id,
const std::map<int, SdpAudioFormat>& decoder_specs) {
// Failure to locate channel is logged internally in GetChannel.
if (auto audio_channel = GetChannel(channel)) {
audio_channel->SetReceiveCodecs(decoder_specs);
rtc::scoped_refptr<AudioChannel> channel = GetChannel(channel_id);
if (channel) {
channel->SetReceiveCodecs(decoder_specs);
}
}
void VoipCore::RegisterTelephoneEventType(ChannelId channel,
void VoipCore::RegisterTelephoneEventType(ChannelId channel_id,
int rtp_payload_type,
int sample_rate_hz) {
// Failure to locate channel is logged internally in GetChannel.
if (auto audio_channel = GetChannel(channel)) {
audio_channel->RegisterTelephoneEventType(rtp_payload_type, sample_rate_hz);
rtc::scoped_refptr<AudioChannel> channel = GetChannel(channel_id);
if (channel) {
channel->RegisterTelephoneEventType(rtp_payload_type, sample_rate_hz);
}
}
bool VoipCore::SendDtmfEvent(ChannelId channel,
bool VoipCore::SendDtmfEvent(ChannelId channel_id,
DtmfEvent dtmf_event,
int duration_ms) {
// Failure to locate channel is logged internally in GetChannel.
if (auto audio_channel = GetChannel(channel)) {
return audio_channel->SendTelephoneEvent(static_cast<int>(dtmf_event),
duration_ms);
rtc::scoped_refptr<AudioChannel> channel = GetChannel(channel_id);
if (channel) {
return channel->SendTelephoneEvent(static_cast<int>(dtmf_event),
duration_ms);
}
return false;
}
absl::optional<IngressStatistics> VoipCore::GetIngressStatistics(
ChannelId channel) {
if (auto audio_channel = GetChannel(channel)) {
return audio_channel->GetIngressStatistics();
ChannelId channel_id) {
rtc::scoped_refptr<AudioChannel> channel = GetChannel(channel_id);
if (channel) {
return channel->GetIngressStatistics();
}
return absl::nullopt;
}

View File

@ -78,42 +78,42 @@ class VoipCore : public VoipEngine,
absl::optional<ChannelId> CreateChannel(
Transport* transport,
absl::optional<uint32_t> local_ssrc) override;
void ReleaseChannel(ChannelId channel) override;
bool StartSend(ChannelId channel) override;
bool StopSend(ChannelId channel) override;
bool StartPlayout(ChannelId channel) override;
bool StopPlayout(ChannelId channel) override;
void ReleaseChannel(ChannelId channel_id) override;
bool StartSend(ChannelId channel_id) override;
bool StopSend(ChannelId channel_id) override;
bool StartPlayout(ChannelId channel_id) override;
bool StopPlayout(ChannelId channel_id) override;
// Implements VoipNetwork interfaces.
void ReceivedRTPPacket(ChannelId channel,
void ReceivedRTPPacket(ChannelId channel_id,
rtc::ArrayView<const uint8_t> rtp_packet) override;
void ReceivedRTCPPacket(ChannelId channel,
void ReceivedRTCPPacket(ChannelId channel_id,
rtc::ArrayView<const uint8_t> rtcp_packet) override;
// Implements VoipCodec interfaces.
void SetSendCodec(ChannelId channel,
void SetSendCodec(ChannelId channel_id,
int payload_type,
const SdpAudioFormat& encoder_format) override;
void SetReceiveCodecs(
ChannelId channel,
ChannelId channel_id,
const std::map<int, SdpAudioFormat>& decoder_specs) override;
// Implements VoipDtmf interfaces.
void RegisterTelephoneEventType(ChannelId channel,
void RegisterTelephoneEventType(ChannelId channel_id,
int rtp_payload_type,
int sample_rate_hz) override;
bool SendDtmfEvent(ChannelId channel,
bool SendDtmfEvent(ChannelId channel_id,
DtmfEvent dtmf_event,
int duration_ms) override;
// Implements VoipStatistics interfaces.
absl::optional<IngressStatistics> GetIngressStatistics(
ChannelId channel) override;
ChannelId channel_id) override;
private:
// Fetches the corresponding AudioChannel assigned with given |channel|.
// Returns nullptr if not found.
rtc::scoped_refptr<AudioChannel> GetChannel(ChannelId channel);
rtc::scoped_refptr<AudioChannel> GetChannel(ChannelId channel_id);
// Updates AudioTransportImpl with a new set of actively sending AudioSender
// (AudioEgress). This needs to be invoked whenever StartSend/StopSend is