Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Side by Side Diff: webrtc/api/rtpreceiver.cc

Issue 2046173002: Use VoiceChannel/VideoChannel directly from RtpSender/RtpReceiver. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2015 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/api/rtpreceiver.h" 11 #include "webrtc/api/rtpreceiver.h"
12 12
13 #include "webrtc/api/mediastreamtrackproxy.h" 13 #include "webrtc/api/mediastreamtrackproxy.h"
14 #include "webrtc/api/audiotrack.h" 14 #include "webrtc/api/audiotrack.h"
15 #include "webrtc/api/videosourceproxy.h" 15 #include "webrtc/api/videosourceproxy.h"
16 #include "webrtc/api/videotrack.h" 16 #include "webrtc/api/videotrack.h"
17 #include "webrtc/base/trace_event.h" 17 #include "webrtc/base/trace_event.h"
18 18
19 namespace webrtc { 19 namespace webrtc {
20 20
21 AudioRtpReceiver::AudioRtpReceiver(MediaStreamInterface* stream, 21 AudioRtpReceiver::AudioRtpReceiver(MediaStreamInterface* stream,
22 const std::string& track_id, 22 const std::string& track_id,
23 uint32_t ssrc, 23 uint32_t ssrc,
24 AudioProviderInterface* provider) 24 cricket::VoiceChannel* channel)
25 : id_(track_id), 25 : id_(track_id),
26 ssrc_(ssrc), 26 ssrc_(ssrc),
27 provider_(provider), 27 channel_(channel),
28 track_(AudioTrackProxy::Create( 28 track_(AudioTrackProxy::Create(
29 rtc::Thread::Current(), 29 rtc::Thread::Current(),
30 AudioTrack::Create(track_id, 30 AudioTrack::Create(track_id,
31 RemoteAudioSource::Create(ssrc, provider)))), 31 RemoteAudioSource::Create(ssrc, channel)))),
32 cached_track_enabled_(track_->enabled()) { 32 cached_track_enabled_(track_->enabled()) {
33 RTC_DCHECK(track_->GetSource()->remote()); 33 RTC_DCHECK(track_->GetSource()->remote());
34 track_->RegisterObserver(this); 34 track_->RegisterObserver(this);
35 track_->GetSource()->RegisterAudioObserver(this); 35 track_->GetSource()->RegisterAudioObserver(this);
36 Reconfigure(); 36 Reconfigure();
37 stream->AddTrack(track_); 37 stream->AddTrack(track_);
38 } 38 }
39 39
40 AudioRtpReceiver::~AudioRtpReceiver() { 40 AudioRtpReceiver::~AudioRtpReceiver() {
41 track_->GetSource()->UnregisterAudioObserver(this); 41 track_->GetSource()->UnregisterAudioObserver(this);
42 track_->UnregisterObserver(this); 42 track_->UnregisterObserver(this);
43 Stop(); 43 Stop();
44 } 44 }
45 45
46 void AudioRtpReceiver::OnChanged() { 46 void AudioRtpReceiver::OnChanged() {
47 if (cached_track_enabled_ != track_->enabled()) { 47 if (cached_track_enabled_ != track_->enabled()) {
48 cached_track_enabled_ = track_->enabled(); 48 cached_track_enabled_ = track_->enabled();
49 Reconfigure(); 49 Reconfigure();
50 } 50 }
51 } 51 }
52 52
53 void AudioRtpReceiver::OnSetVolume(double volume) { 53 void AudioRtpReceiver::OnSetVolume(double volume) {
54 RTC_DCHECK(volume >= 0 && volume <= 10);
55 cached_volume_ = volume;
56 if (!channel_) {
57 LOG(LS_ERROR) << "AudioRtpReceiver::OnSetVolume: No audio channel exists.";
58 return;
59 }
54 // When the track is disabled, the volume of the source, which is the 60 // When the track is disabled, the volume of the source, which is the
55 // corresponding WebRtc Voice Engine channel will be 0. So we do not allow 61 // corresponding WebRtc Voice Engine channel will be 0. So we do not allow
56 // setting the volume to the source when the track is disabled. 62 // setting the volume to the source when the track is disabled.
57 if (provider_ && track_->enabled()) 63 if (!stopped_ && track_->enabled()) {
58 provider_->SetAudioPlayoutVolume(ssrc_, volume); 64 RTC_DCHECK(channel_->SetOutputVolume(ssrc_, cached_volume_));
65 }
59 } 66 }
60 67
61 RtpParameters AudioRtpReceiver::GetParameters() const { 68 RtpParameters AudioRtpReceiver::GetParameters() const {
62 return provider_->GetAudioRtpReceiveParameters(ssrc_); 69 if (!channel_ || stopped_) {
70 return RtpParameters();
71 }
72 return channel_->GetRtpReceiveParameters(ssrc_);
63 } 73 }
64 74
65 bool AudioRtpReceiver::SetParameters(const RtpParameters& parameters) { 75 bool AudioRtpReceiver::SetParameters(const RtpParameters& parameters) {
66 TRACE_EVENT0("webrtc", "AudioRtpReceiver::SetParameters"); 76 TRACE_EVENT0("webrtc", "AudioRtpReceiver::SetParameters");
67 return provider_->SetAudioRtpReceiveParameters(ssrc_, parameters); 77 if (!channel_ || stopped_) {
78 return false;
79 }
80 return channel_->SetRtpReceiveParameters(ssrc_, parameters);
68 } 81 }
69 82
70 void AudioRtpReceiver::Stop() { 83 void AudioRtpReceiver::Stop() {
71 // TODO(deadbeef): Need to do more here to fully stop receiving packets. 84 // TODO(deadbeef): Need to do more here to fully stop receiving packets.
72 if (!provider_) { 85 if (stopped_) {
73 return; 86 return;
74 } 87 }
75 provider_->SetAudioPlayout(ssrc_, false); 88 if (channel_) {
76 provider_ = nullptr; 89 // Allow that SetOutputVolume fail. This is the normal case when the
90 // underlying media channel has already been deleted.
91 channel_->SetOutputVolume(ssrc_, 0);
92 }
93 stopped_ = true;
77 } 94 }
78 95
79 void AudioRtpReceiver::Reconfigure() { 96 void AudioRtpReceiver::Reconfigure() {
80 if (!provider_) { 97 RTC_DCHECK(!stopped_);
98 if (!channel_) {
99 LOG(LS_ERROR) << "AudioRtpReceiver::Reconfigure: No audio channel exists.";
81 return; 100 return;
82 } 101 }
83 provider_->SetAudioPlayout(ssrc_, track_->enabled()); 102 RTC_DCHECK(
103 channel_->SetOutputVolume(ssrc_, track_->enabled() ? cached_volume_ : 0));
Taylor Brandstetter 2016/06/07 22:44:43 Previously, SetAudioPlayout would always set the v
84 } 104 }
85 105
86 VideoRtpReceiver::VideoRtpReceiver(MediaStreamInterface* stream, 106 VideoRtpReceiver::VideoRtpReceiver(MediaStreamInterface* stream,
87 const std::string& track_id, 107 const std::string& track_id,
88 rtc::Thread* worker_thread, 108 rtc::Thread* worker_thread,
89 uint32_t ssrc, 109 uint32_t ssrc,
90 VideoProviderInterface* provider) 110 cricket::VideoChannel* channel)
91 : id_(track_id), 111 : id_(track_id),
92 ssrc_(ssrc), 112 ssrc_(ssrc),
93 provider_(provider), 113 channel_(channel),
94 source_(new RefCountedObject<VideoTrackSource>(&broadcaster_, 114 source_(new RefCountedObject<VideoTrackSource>(&broadcaster_,
95 true /* remote */)), 115 true /* remote */)),
96 track_(VideoTrackProxy::Create( 116 track_(VideoTrackProxy::Create(
97 rtc::Thread::Current(), 117 rtc::Thread::Current(),
98 worker_thread, 118 worker_thread,
99 VideoTrack::Create( 119 VideoTrack::Create(
100 track_id, 120 track_id,
101 VideoTrackSourceProxy::Create(rtc::Thread::Current(), 121 VideoTrackSourceProxy::Create(rtc::Thread::Current(),
102 worker_thread, 122 worker_thread,
103 source_)))) { 123 source_)))) {
104 source_->SetState(MediaSourceInterface::kLive); 124 source_->SetState(MediaSourceInterface::kLive);
105 provider_->SetVideoPlayout(ssrc_, true, &broadcaster_); 125 if (!channel_) {
126 LOG(LS_ERROR)
127 << "VideoRtpReceiver::VideoRtpReceiver: No video channel exists.";
128 } else {
129 RTC_DCHECK(channel_->SetSink(ssrc_, &broadcaster_));
130 }
106 stream->AddTrack(track_); 131 stream->AddTrack(track_);
107 } 132 }
108 133
109 VideoRtpReceiver::~VideoRtpReceiver() { 134 VideoRtpReceiver::~VideoRtpReceiver() {
110 // Since cricket::VideoRenderer is not reference counted, 135 // Since cricket::VideoRenderer is not reference counted,
111 // we need to remove it from the provider before we are deleted. 136 // we need to remove it from the channel before we are deleted.
112 Stop(); 137 Stop();
113 } 138 }
114 139
115 RtpParameters VideoRtpReceiver::GetParameters() const { 140 RtpParameters VideoRtpReceiver::GetParameters() const {
116 return provider_->GetVideoRtpReceiveParameters(ssrc_); 141 if (!channel_ || stopped_) {
142 return RtpParameters();
143 }
144 return channel_->GetRtpReceiveParameters(ssrc_);
117 } 145 }
118 146
119 bool VideoRtpReceiver::SetParameters(const RtpParameters& parameters) { 147 bool VideoRtpReceiver::SetParameters(const RtpParameters& parameters) {
120 TRACE_EVENT0("webrtc", "VideoRtpReceiver::SetParameters"); 148 TRACE_EVENT0("webrtc", "VideoRtpReceiver::SetParameters");
121 return provider_->SetVideoRtpReceiveParameters(ssrc_, parameters); 149 if (!channel_ || stopped_) {
150 return false;
151 }
152 return channel_->SetRtpReceiveParameters(ssrc_, parameters);
122 } 153 }
123 154
124 void VideoRtpReceiver::Stop() { 155 void VideoRtpReceiver::Stop() {
125 // TODO(deadbeef): Need to do more here to fully stop receiving packets. 156 // TODO(deadbeef): Need to do more here to fully stop receiving packets.
126 if (!provider_) { 157 if (stopped_) {
127 return; 158 return;
128 } 159 }
129 source_->SetState(MediaSourceInterface::kEnded); 160 source_->SetState(MediaSourceInterface::kEnded);
130 source_->OnSourceDestroyed(); 161 source_->OnSourceDestroyed();
131 provider_->SetVideoPlayout(ssrc_, false, nullptr); 162 if (!channel_) {
132 provider_ = nullptr; 163 LOG(LS_WARNING) << "VideoRtpReceiver::Stop: No video channel exists.";
164 } else {
165 // Allow that SetSink fail. This is the normal case when the underlying
166 // media channel has already been deleted.
167 channel_->SetSink(ssrc_, nullptr);
168 }
169 stopped_ = true;
133 } 170 }
134 171
135 } // namespace webrtc 172 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698