Index: webrtc/api/rtpreceiver.cc |
diff --git a/webrtc/api/rtpreceiver.cc b/webrtc/api/rtpreceiver.cc |
index 8fde438ba7b1d5e9bab020afc278d7a827d74298..882bc2be8d4b46e6daf1575af5c34d7d3d9fb650 100644 |
--- a/webrtc/api/rtpreceiver.cc |
+++ b/webrtc/api/rtpreceiver.cc |
@@ -21,24 +21,22 @@ |
AudioRtpReceiver::AudioRtpReceiver(MediaStreamInterface* stream, |
const std::string& track_id, |
uint32_t ssrc, |
- cricket::VoiceChannel* channel) |
+ AudioProviderInterface* provider) |
: id_(track_id), |
ssrc_(ssrc), |
- channel_(channel), |
+ provider_(provider), |
track_(AudioTrackProxy::Create( |
rtc::Thread::Current(), |
AudioTrack::Create(track_id, |
- RemoteAudioSource::Create(ssrc, channel)))), |
+ RemoteAudioSource::Create(ssrc, provider)))), |
cached_track_enabled_(track_->enabled()) { |
RTC_DCHECK(track_->GetSource()->remote()); |
track_->RegisterObserver(this); |
track_->GetSource()->RegisterAudioObserver(this); |
Reconfigure(); |
stream->AddTrack(track_); |
- if (channel_) { |
- channel_->SignalFirstPacketReceived.connect( |
- this, &AudioRtpReceiver::OnFirstPacketReceived); |
- } |
+ provider_->SignalFirstAudioPacketReceived.connect( |
+ this, &AudioRtpReceiver::OnFirstAudioPacketReceived); |
} |
AudioRtpReceiver::~AudioRtpReceiver() { |
@@ -55,78 +53,48 @@ |
} |
void AudioRtpReceiver::OnSetVolume(double volume) { |
- RTC_DCHECK(volume >= 0 && volume <= 10); |
- cached_volume_ = volume; |
- if (!channel_) { |
- LOG(LS_ERROR) << "AudioRtpReceiver::OnSetVolume: No audio channel exists."; |
- return; |
- } |
// When the track is disabled, the volume of the source, which is the |
// corresponding WebRtc Voice Engine channel will be 0. So we do not allow |
// setting the volume to the source when the track is disabled. |
- if (!stopped_ && track_->enabled()) { |
- RTC_DCHECK(channel_->SetOutputVolume(ssrc_, cached_volume_)); |
- } |
+ if (provider_ && track_->enabled()) |
+ provider_->SetAudioPlayoutVolume(ssrc_, volume); |
} |
RtpParameters AudioRtpReceiver::GetParameters() const { |
- if (!channel_ || stopped_) { |
- return RtpParameters(); |
- } |
- return channel_->GetRtpReceiveParameters(ssrc_); |
+ return provider_->GetAudioRtpReceiveParameters(ssrc_); |
} |
bool AudioRtpReceiver::SetParameters(const RtpParameters& parameters) { |
TRACE_EVENT0("webrtc", "AudioRtpReceiver::SetParameters"); |
- if (!channel_ || stopped_) { |
- return false; |
- } |
- return channel_->SetRtpReceiveParameters(ssrc_, parameters); |
+ return provider_->SetAudioRtpReceiveParameters(ssrc_, parameters); |
} |
void AudioRtpReceiver::Stop() { |
// TODO(deadbeef): Need to do more here to fully stop receiving packets. |
- if (stopped_) { |
+ if (!provider_) { |
return; |
} |
- if (channel_) { |
- // Allow that SetOutputVolume fail. This is the normal case when the |
- // underlying media channel has already been deleted. |
- channel_->SetOutputVolume(ssrc_, 0); |
- } |
- stopped_ = true; |
+ provider_->SetAudioPlayout(ssrc_, false); |
+ provider_ = nullptr; |
} |
void AudioRtpReceiver::Reconfigure() { |
- RTC_DCHECK(!stopped_); |
- if (!channel_) { |
- LOG(LS_ERROR) << "AudioRtpReceiver::Reconfigure: No audio channel exists."; |
+ if (!provider_) { |
return; |
} |
- RTC_DCHECK( |
- channel_->SetOutputVolume(ssrc_, track_->enabled() ? cached_volume_ : 0)); |
+ provider_->SetAudioPlayout(ssrc_, track_->enabled()); |
} |
void AudioRtpReceiver::SetObserver(RtpReceiverObserverInterface* observer) { |
observer_ = observer; |
- // Deliver any notifications the observer may have missed by being set late. |
+ // If received the first packet before setting the observer, call the |
+ // observer. |
if (received_first_packet_) { |
observer_->OnFirstPacketReceived(media_type()); |
} |
} |
-void AudioRtpReceiver::SetChannel(cricket::VoiceChannel* channel) { |
- if (channel_) { |
- channel_->SignalFirstPacketReceived.disconnect(this); |
- } |
- channel_ = channel; |
- if (channel_) { |
- channel_->SignalFirstPacketReceived.connect( |
- this, &AudioRtpReceiver::OnFirstPacketReceived); |
- } |
-} |
- |
-void AudioRtpReceiver::OnFirstPacketReceived(cricket::BaseChannel* channel) { |
+void AudioRtpReceiver::OnFirstAudioPacketReceived() { |
if (observer_) { |
observer_->OnFirstPacketReceived(media_type()); |
} |
@@ -137,10 +105,10 @@ |
const std::string& track_id, |
rtc::Thread* worker_thread, |
uint32_t ssrc, |
- cricket::VideoChannel* channel) |
+ VideoProviderInterface* provider) |
: id_(track_id), |
ssrc_(ssrc), |
- channel_(channel), |
+ provider_(provider), |
source_(new RefCountedObject<VideoTrackSource>(&broadcaster_, |
true /* remote */)), |
track_(VideoTrackProxy::Create( |
@@ -152,77 +120,48 @@ |
worker_thread, |
source_)))) { |
source_->SetState(MediaSourceInterface::kLive); |
- if (!channel_) { |
- LOG(LS_ERROR) |
- << "VideoRtpReceiver::VideoRtpReceiver: No video channel exists."; |
- } else { |
- RTC_DCHECK(channel_->SetSink(ssrc_, &broadcaster_)); |
- } |
+ provider_->SetVideoPlayout(ssrc_, true, &broadcaster_); |
stream->AddTrack(track_); |
- if (channel_) { |
- channel_->SignalFirstPacketReceived.connect( |
- this, &VideoRtpReceiver::OnFirstPacketReceived); |
- } |
+ provider_->SignalFirstVideoPacketReceived.connect( |
+ this, &VideoRtpReceiver::OnFirstVideoPacketReceived); |
} |
VideoRtpReceiver::~VideoRtpReceiver() { |
// Since cricket::VideoRenderer is not reference counted, |
- // we need to remove it from the channel before we are deleted. |
+ // we need to remove it from the provider before we are deleted. |
Stop(); |
} |
RtpParameters VideoRtpReceiver::GetParameters() const { |
- if (!channel_ || stopped_) { |
- return RtpParameters(); |
- } |
- return channel_->GetRtpReceiveParameters(ssrc_); |
+ return provider_->GetVideoRtpReceiveParameters(ssrc_); |
} |
bool VideoRtpReceiver::SetParameters(const RtpParameters& parameters) { |
TRACE_EVENT0("webrtc", "VideoRtpReceiver::SetParameters"); |
- if (!channel_ || stopped_) { |
- return false; |
- } |
- return channel_->SetRtpReceiveParameters(ssrc_, parameters); |
+ return provider_->SetVideoRtpReceiveParameters(ssrc_, parameters); |
} |
void VideoRtpReceiver::Stop() { |
// TODO(deadbeef): Need to do more here to fully stop receiving packets. |
- if (stopped_) { |
+ if (!provider_) { |
return; |
} |
source_->SetState(MediaSourceInterface::kEnded); |
source_->OnSourceDestroyed(); |
- if (!channel_) { |
- LOG(LS_WARNING) << "VideoRtpReceiver::Stop: No video channel exists."; |
- } else { |
- // Allow that SetSink fail. This is the normal case when the underlying |
- // media channel has already been deleted. |
- channel_->SetSink(ssrc_, nullptr); |
- } |
- stopped_ = true; |
+ provider_->SetVideoPlayout(ssrc_, false, nullptr); |
+ provider_ = nullptr; |
} |
void VideoRtpReceiver::SetObserver(RtpReceiverObserverInterface* observer) { |
observer_ = observer; |
- // Deliver any notifications the observer may have missed by being set late. |
+ // If received the first packet before setting the observer, call the |
+ // observer. |
if (received_first_packet_) { |
observer_->OnFirstPacketReceived(media_type()); |
} |
} |
-void VideoRtpReceiver::SetChannel(cricket::VideoChannel* channel) { |
- if (channel_) { |
- channel_->SignalFirstPacketReceived.disconnect(this); |
- } |
- channel_ = channel; |
- if (channel_) { |
- channel_->SignalFirstPacketReceived.connect( |
- this, &VideoRtpReceiver::OnFirstPacketReceived); |
- } |
-} |
- |
-void VideoRtpReceiver::OnFirstPacketReceived(cricket::BaseChannel* channel) { |
+void VideoRtpReceiver::OnFirstVideoPacketReceived() { |
if (observer_) { |
observer_->OnFirstPacketReceived(media_type()); |
} |