2015-09-24 16:47:53 -07:00
|
|
|
/*
|
2016-02-10 07:54:43 -08:00
|
|
|
* Copyright 2015 The WebRTC project authors. All Rights Reserved.
|
2015-09-24 16:47:53 -07:00
|
|
|
*
|
2016-02-10 07:54:43 -08:00
|
|
|
* 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.
|
2015-09-24 16:47:53 -07:00
|
|
|
*/
|
|
|
|
|
|
2017-01-23 04:56:25 -08:00
|
|
|
#include "webrtc/pc/rtpreceiver.h"
|
2015-09-24 16:47:53 -07:00
|
|
|
|
2016-03-10 18:32:00 +01:00
|
|
|
#include "webrtc/api/mediastreamtrackproxy.h"
|
2016-04-07 07:45:54 -07:00
|
|
|
#include "webrtc/api/videosourceproxy.h"
|
2017-01-23 04:56:25 -08:00
|
|
|
#include "webrtc/pc/audiotrack.h"
|
|
|
|
|
#include "webrtc/pc/videotrack.h"
|
2017-07-06 19:44:34 +02:00
|
|
|
#include "webrtc/rtc_base/trace_event.h"
|
2015-09-28 16:53:55 -07:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
2017-02-25 18:15:09 -08:00
|
|
|
AudioRtpReceiver::AudioRtpReceiver(const std::string& track_id,
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
uint32_t ssrc,
|
2016-06-27 16:30:35 -07:00
|
|
|
cricket::VoiceChannel* channel)
|
2016-03-24 03:16:19 -07:00
|
|
|
: id_(track_id),
|
2015-09-28 16:53:55 -07:00
|
|
|
ssrc_(ssrc),
|
2016-06-27 16:30:35 -07:00
|
|
|
channel_(channel),
|
2016-03-24 03:16:19 -07:00
|
|
|
track_(AudioTrackProxy::Create(
|
|
|
|
|
rtc::Thread::Current(),
|
|
|
|
|
AudioTrack::Create(track_id,
|
2016-06-27 16:30:35 -07:00
|
|
|
RemoteAudioSource::Create(ssrc, channel)))),
|
2016-03-24 03:16:19 -07:00
|
|
|
cached_track_enabled_(track_->enabled()) {
|
2015-12-15 04:27:11 -08:00
|
|
|
RTC_DCHECK(track_->GetSource()->remote());
|
2015-09-28 16:53:55 -07:00
|
|
|
track_->RegisterObserver(this);
|
|
|
|
|
track_->GetSource()->RegisterAudioObserver(this);
|
|
|
|
|
Reconfigure();
|
2016-06-27 16:30:35 -07:00
|
|
|
if (channel_) {
|
|
|
|
|
channel_->SignalFirstPacketReceived.connect(
|
|
|
|
|
this, &AudioRtpReceiver::OnFirstPacketReceived);
|
|
|
|
|
}
|
2015-09-28 16:53:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AudioRtpReceiver::~AudioRtpReceiver() {
|
|
|
|
|
track_->GetSource()->UnregisterAudioObserver(this);
|
|
|
|
|
track_->UnregisterObserver(this);
|
|
|
|
|
Stop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AudioRtpReceiver::OnChanged() {
|
|
|
|
|
if (cached_track_enabled_ != track_->enabled()) {
|
|
|
|
|
cached_track_enabled_ = track_->enabled();
|
|
|
|
|
Reconfigure();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AudioRtpReceiver::OnSetVolume(double volume) {
|
2016-06-27 16:30:35 -07:00
|
|
|
RTC_DCHECK(volume >= 0 && volume <= 10);
|
|
|
|
|
cached_volume_ = volume;
|
|
|
|
|
if (!channel_) {
|
|
|
|
|
LOG(LS_ERROR) << "AudioRtpReceiver::OnSetVolume: No audio channel exists.";
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-09-28 16:53:55 -07:00
|
|
|
// 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.
|
2016-06-27 16:30:35 -07:00
|
|
|
if (!stopped_ && track_->enabled()) {
|
|
|
|
|
if (!channel_->SetOutputVolume(ssrc_, cached_volume_)) {
|
2017-01-12 02:24:27 -08:00
|
|
|
RTC_NOTREACHED();
|
2016-06-27 16:30:35 -07:00
|
|
|
}
|
|
|
|
|
}
|
2015-09-28 16:53:55 -07:00
|
|
|
}
|
|
|
|
|
|
2016-05-16 11:40:30 -07:00
|
|
|
RtpParameters AudioRtpReceiver::GetParameters() const {
|
2016-06-27 16:30:35 -07:00
|
|
|
if (!channel_ || stopped_) {
|
|
|
|
|
return RtpParameters();
|
|
|
|
|
}
|
|
|
|
|
return channel_->GetRtpReceiveParameters(ssrc_);
|
2016-05-16 11:40:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AudioRtpReceiver::SetParameters(const RtpParameters& parameters) {
|
|
|
|
|
TRACE_EVENT0("webrtc", "AudioRtpReceiver::SetParameters");
|
2016-06-27 16:30:35 -07:00
|
|
|
if (!channel_ || stopped_) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return channel_->SetRtpReceiveParameters(ssrc_, parameters);
|
2016-05-16 11:40:30 -07:00
|
|
|
}
|
|
|
|
|
|
2016-06-06 14:27:39 -07:00
|
|
|
void AudioRtpReceiver::Stop() {
|
|
|
|
|
// TODO(deadbeef): Need to do more here to fully stop receiving packets.
|
2016-06-27 16:30:35 -07:00
|
|
|
if (stopped_) {
|
2016-06-06 14:27:39 -07:00
|
|
|
return;
|
|
|
|
|
}
|
2016-06-27 16:30:35 -07:00
|
|
|
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;
|
2016-06-06 14:27:39 -07:00
|
|
|
}
|
|
|
|
|
|
Reland of Implemented the GetSources() in native code. (patchset #1 id:1 of https://codereview.webrtc.org/2809613002/ )
Reason for revert:
Re-land, reverting did not fix bug.
https://bugs.chromium.org/p/webrtc/issues/detail?id=7465
Original issue's description:
> Revert of Implemented the GetSources() in native code. (patchset #11 id:510001 of https://codereview.webrtc.org/2770233003/ )
>
> Reason for revert:
> Suspected of WebRtcApprtcBrowserTest.MANUAL_WorksOnApprtc breakage, see
>
> https://bugs.chromium.org/p/webrtc/issues/detail?id=7465
>
> Original issue's description:
> > Added the GetSources() to the RtpReceiverInterface and implemented
> > it for the AudioRtpReceiver.
> >
> > This method returns a vector of RtpSource(both CSRC source and SSRC
> > source) which contains the ID of a source, the timestamp, the source
> > type (SSRC or CSRC) and the audio level.
> >
> > The RtpSource objects are buffered and maintained by the
> > RtpReceiver in webrtc/modules/rtp_rtcp/. When the method is called,
> > the info of the contributing source will be pulled along the object
> > chain:
> > AudioRtpReceiver -> VoiceChannel -> WebRtcVoiceMediaChannel ->
> > AudioReceiveStream -> voe::Channel -> RtpRtcp module
> >
> > Spec:https://w3c.github.io/webrtc-pc/archives/20151006/webrtc.html#widl-RTCRtpReceiver-getContributingSources-sequence-RTCRtpContributingSource
> >
> > BUG=chromium:703122
> > TBR=stefan@webrtc.org, danilchap@webrtc.org
> >
> > Review-Url: https://codereview.webrtc.org/2770233003
> > Cr-Commit-Position: refs/heads/master@{#17591}
> > Committed: https://chromium.googlesource.com/external/webrtc/+/292084c3765d9f3ee406ca2ec86eae206b540053
>
> TBR=deadbeef@webrtc.org,solenberg@webrtc.org,hbos@webrtc.org,philipel@webrtc.org,stefan@webrtc.org,danilchap@webrtc.org,zhihuang@webrtc.org
> # Not skipping CQ checks because original CL landed more than 1 days ago.
> BUG=chromium:703122
>
> Review-Url: https://codereview.webrtc.org/2809613002
> Cr-Commit-Position: refs/heads/master@{#17616}
> Committed: https://chromium.googlesource.com/external/webrtc/+/fbcc5cb3869d1370008e40f24fc03ac8fb69c675
TBR=deadbeef@webrtc.org,solenberg@webrtc.org,philipel@webrtc.org,stefan@webrtc.org,danilchap@webrtc.org,zhihuang@webrtc.org,olka@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=chromium:703122
Review-Url: https://codereview.webrtc.org/2810623003
Cr-Commit-Position: refs/heads/master@{#17621}
2017-04-10 07:39:05 -07:00
|
|
|
std::vector<RtpSource> AudioRtpReceiver::GetSources() const {
|
|
|
|
|
return channel_->GetSources(ssrc_);
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-28 16:53:55 -07:00
|
|
|
void AudioRtpReceiver::Reconfigure() {
|
2016-06-27 16:30:35 -07:00
|
|
|
RTC_DCHECK(!stopped_);
|
|
|
|
|
if (!channel_) {
|
|
|
|
|
LOG(LS_ERROR) << "AudioRtpReceiver::Reconfigure: No audio channel exists.";
|
2015-09-28 16:53:55 -07:00
|
|
|
return;
|
|
|
|
|
}
|
2016-06-27 16:30:35 -07:00
|
|
|
if (!channel_->SetOutputVolume(ssrc_,
|
|
|
|
|
track_->enabled() ? cached_volume_ : 0)) {
|
2017-01-12 02:24:27 -08:00
|
|
|
RTC_NOTREACHED();
|
2016-06-27 16:30:35 -07:00
|
|
|
}
|
2015-09-28 16:53:55 -07:00
|
|
|
}
|
|
|
|
|
|
2016-06-14 11:47:14 -07:00
|
|
|
void AudioRtpReceiver::SetObserver(RtpReceiverObserverInterface* observer) {
|
|
|
|
|
observer_ = observer;
|
2016-06-27 16:30:35 -07:00
|
|
|
// Deliver any notifications the observer may have missed by being set late.
|
2016-12-07 10:36:40 -08:00
|
|
|
if (received_first_packet_ && observer_) {
|
2016-06-14 11:47:14 -07:00
|
|
|
observer_->OnFirstPacketReceived(media_type());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-27 16:30:35 -07:00
|
|
|
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) {
|
2016-06-14 11:47:14 -07:00
|
|
|
if (observer_) {
|
|
|
|
|
observer_->OnFirstPacketReceived(media_type());
|
|
|
|
|
}
|
|
|
|
|
received_first_packet_ = true;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-25 18:15:09 -08:00
|
|
|
VideoRtpReceiver::VideoRtpReceiver(const std::string& track_id,
|
2016-03-10 18:32:00 +01:00
|
|
|
rtc::Thread* worker_thread,
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
uint32_t ssrc,
|
2016-06-27 16:30:35 -07:00
|
|
|
cricket::VideoChannel* channel)
|
2016-03-10 18:32:00 +01:00
|
|
|
: id_(track_id),
|
|
|
|
|
ssrc_(ssrc),
|
2016-06-27 16:30:35 -07:00
|
|
|
channel_(channel),
|
2016-03-10 18:32:00 +01:00
|
|
|
source_(new RefCountedObject<VideoTrackSource>(&broadcaster_,
|
|
|
|
|
true /* remote */)),
|
|
|
|
|
track_(VideoTrackProxy::Create(
|
|
|
|
|
rtc::Thread::Current(),
|
2016-04-07 07:45:54 -07:00
|
|
|
worker_thread,
|
|
|
|
|
VideoTrack::Create(
|
|
|
|
|
track_id,
|
|
|
|
|
VideoTrackSourceProxy::Create(rtc::Thread::Current(),
|
|
|
|
|
worker_thread,
|
2017-07-31 23:22:01 -07:00
|
|
|
source_),
|
|
|
|
|
worker_thread))) {
|
2016-03-10 18:32:00 +01:00
|
|
|
source_->SetState(MediaSourceInterface::kLive);
|
2016-06-27 16:30:35 -07:00
|
|
|
if (!channel_) {
|
|
|
|
|
LOG(LS_ERROR)
|
|
|
|
|
<< "VideoRtpReceiver::VideoRtpReceiver: No video channel exists.";
|
|
|
|
|
} else {
|
|
|
|
|
if (!channel_->SetSink(ssrc_, &broadcaster_)) {
|
2017-01-12 02:24:27 -08:00
|
|
|
RTC_NOTREACHED();
|
2016-06-27 16:30:35 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (channel_) {
|
|
|
|
|
channel_->SignalFirstPacketReceived.connect(
|
|
|
|
|
this, &VideoRtpReceiver::OnFirstPacketReceived);
|
|
|
|
|
}
|
2015-09-28 16:53:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VideoRtpReceiver::~VideoRtpReceiver() {
|
|
|
|
|
// Since cricket::VideoRenderer is not reference counted,
|
2016-06-27 16:30:35 -07:00
|
|
|
// we need to remove it from the channel before we are deleted.
|
2015-09-28 16:53:55 -07:00
|
|
|
Stop();
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-06 14:27:39 -07:00
|
|
|
RtpParameters VideoRtpReceiver::GetParameters() const {
|
2016-06-27 16:30:35 -07:00
|
|
|
if (!channel_ || stopped_) {
|
|
|
|
|
return RtpParameters();
|
|
|
|
|
}
|
|
|
|
|
return channel_->GetRtpReceiveParameters(ssrc_);
|
2016-06-06 14:27:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool VideoRtpReceiver::SetParameters(const RtpParameters& parameters) {
|
|
|
|
|
TRACE_EVENT0("webrtc", "VideoRtpReceiver::SetParameters");
|
2016-06-27 16:30:35 -07:00
|
|
|
if (!channel_ || stopped_) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return channel_->SetRtpReceiveParameters(ssrc_, parameters);
|
2016-06-06 14:27:39 -07:00
|
|
|
}
|
|
|
|
|
|
2015-09-28 16:53:55 -07:00
|
|
|
void VideoRtpReceiver::Stop() {
|
|
|
|
|
// TODO(deadbeef): Need to do more here to fully stop receiving packets.
|
2016-06-27 16:30:35 -07:00
|
|
|
if (stopped_) {
|
2015-09-28 16:53:55 -07:00
|
|
|
return;
|
|
|
|
|
}
|
2016-03-10 18:32:00 +01:00
|
|
|
source_->SetState(MediaSourceInterface::kEnded);
|
|
|
|
|
source_->OnSourceDestroyed();
|
2016-06-27 16:30:35 -07:00
|
|
|
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;
|
2015-09-28 16:53:55 -07:00
|
|
|
}
|
|
|
|
|
|
2016-06-14 11:47:14 -07:00
|
|
|
void VideoRtpReceiver::SetObserver(RtpReceiverObserverInterface* observer) {
|
|
|
|
|
observer_ = observer;
|
2016-06-27 16:30:35 -07:00
|
|
|
// Deliver any notifications the observer may have missed by being set late.
|
2016-12-07 10:36:40 -08:00
|
|
|
if (received_first_packet_ && observer_) {
|
2016-06-14 11:47:14 -07:00
|
|
|
observer_->OnFirstPacketReceived(media_type());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-27 16:30:35 -07:00
|
|
|
void VideoRtpReceiver::SetChannel(cricket::VideoChannel* channel) {
|
|
|
|
|
if (channel_) {
|
|
|
|
|
channel_->SignalFirstPacketReceived.disconnect(this);
|
|
|
|
|
channel_->SetSink(ssrc_, nullptr);
|
|
|
|
|
}
|
|
|
|
|
channel_ = channel;
|
|
|
|
|
if (channel_) {
|
|
|
|
|
if (!channel_->SetSink(ssrc_, &broadcaster_)) {
|
2017-01-12 02:24:27 -08:00
|
|
|
RTC_NOTREACHED();
|
2016-06-27 16:30:35 -07:00
|
|
|
}
|
|
|
|
|
channel_->SignalFirstPacketReceived.connect(
|
|
|
|
|
this, &VideoRtpReceiver::OnFirstPacketReceived);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VideoRtpReceiver::OnFirstPacketReceived(cricket::BaseChannel* channel) {
|
2016-06-14 11:47:14 -07:00
|
|
|
if (observer_) {
|
|
|
|
|
observer_->OnFirstPacketReceived(media_type());
|
|
|
|
|
}
|
|
|
|
|
received_first_packet_ = true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-28 16:53:55 -07:00
|
|
|
} // namespace webrtc
|