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

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: Moving code that needs to execute out of RTC_DCHECKs. Created 4 years, 5 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
« no previous file with comments | « webrtc/api/rtpreceiver.h ('k') | webrtc/api/rtpreceiverinterface.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 provider_->SignalFirstAudioPacketReceived.connect( 38 if (channel_) {
39 this, &AudioRtpReceiver::OnFirstAudioPacketReceived); 39 channel_->SignalFirstPacketReceived.connect(
40 this, &AudioRtpReceiver::OnFirstPacketReceived);
41 }
40 } 42 }
41 43
42 AudioRtpReceiver::~AudioRtpReceiver() { 44 AudioRtpReceiver::~AudioRtpReceiver() {
43 track_->GetSource()->UnregisterAudioObserver(this); 45 track_->GetSource()->UnregisterAudioObserver(this);
44 track_->UnregisterObserver(this); 46 track_->UnregisterObserver(this);
45 Stop(); 47 Stop();
46 } 48 }
47 49
48 void AudioRtpReceiver::OnChanged() { 50 void AudioRtpReceiver::OnChanged() {
49 if (cached_track_enabled_ != track_->enabled()) { 51 if (cached_track_enabled_ != track_->enabled()) {
50 cached_track_enabled_ = track_->enabled(); 52 cached_track_enabled_ = track_->enabled();
51 Reconfigure(); 53 Reconfigure();
52 } 54 }
53 } 55 }
54 56
55 void AudioRtpReceiver::OnSetVolume(double volume) { 57 void AudioRtpReceiver::OnSetVolume(double volume) {
58 RTC_DCHECK(volume >= 0 && volume <= 10);
59 cached_volume_ = volume;
60 if (!channel_) {
61 LOG(LS_ERROR) << "AudioRtpReceiver::OnSetVolume: No audio channel exists.";
62 return;
63 }
56 // When the track is disabled, the volume of the source, which is the 64 // When the track is disabled, the volume of the source, which is the
57 // corresponding WebRtc Voice Engine channel will be 0. So we do not allow 65 // corresponding WebRtc Voice Engine channel will be 0. So we do not allow
58 // setting the volume to the source when the track is disabled. 66 // setting the volume to the source when the track is disabled.
59 if (provider_ && track_->enabled()) 67 if (!stopped_ && track_->enabled()) {
60 provider_->SetAudioPlayoutVolume(ssrc_, volume); 68 if (!channel_->SetOutputVolume(ssrc_, cached_volume_)) {
69 RTC_DCHECK(false);
70 }
71 }
61 } 72 }
62 73
63 RtpParameters AudioRtpReceiver::GetParameters() const { 74 RtpParameters AudioRtpReceiver::GetParameters() const {
64 return provider_->GetAudioRtpReceiveParameters(ssrc_); 75 if (!channel_ || stopped_) {
76 return RtpParameters();
77 }
78 return channel_->GetRtpReceiveParameters(ssrc_);
65 } 79 }
66 80
67 bool AudioRtpReceiver::SetParameters(const RtpParameters& parameters) { 81 bool AudioRtpReceiver::SetParameters(const RtpParameters& parameters) {
68 TRACE_EVENT0("webrtc", "AudioRtpReceiver::SetParameters"); 82 TRACE_EVENT0("webrtc", "AudioRtpReceiver::SetParameters");
69 return provider_->SetAudioRtpReceiveParameters(ssrc_, parameters); 83 if (!channel_ || stopped_) {
84 return false;
85 }
86 return channel_->SetRtpReceiveParameters(ssrc_, parameters);
70 } 87 }
71 88
72 void AudioRtpReceiver::Stop() { 89 void AudioRtpReceiver::Stop() {
73 // TODO(deadbeef): Need to do more here to fully stop receiving packets. 90 // TODO(deadbeef): Need to do more here to fully stop receiving packets.
74 if (!provider_) { 91 if (stopped_) {
75 return; 92 return;
76 } 93 }
77 provider_->SetAudioPlayout(ssrc_, false); 94 if (channel_) {
78 provider_ = nullptr; 95 // Allow that SetOutputVolume fail. This is the normal case when the
96 // underlying media channel has already been deleted.
97 channel_->SetOutputVolume(ssrc_, 0);
98 }
99 stopped_ = true;
79 } 100 }
80 101
81 void AudioRtpReceiver::Reconfigure() { 102 void AudioRtpReceiver::Reconfigure() {
82 if (!provider_) { 103 RTC_DCHECK(!stopped_);
104 if (!channel_) {
105 LOG(LS_ERROR) << "AudioRtpReceiver::Reconfigure: No audio channel exists.";
83 return; 106 return;
84 } 107 }
85 provider_->SetAudioPlayout(ssrc_, track_->enabled()); 108 if (!channel_->SetOutputVolume(ssrc_,
109 track_->enabled() ? cached_volume_ : 0)) {
110 RTC_DCHECK(false);
111 }
86 } 112 }
87 113
88 void AudioRtpReceiver::SetObserver(RtpReceiverObserverInterface* observer) { 114 void AudioRtpReceiver::SetObserver(RtpReceiverObserverInterface* observer) {
89 observer_ = observer; 115 observer_ = observer;
90 // If received the first packet before setting the observer, call the 116 // Deliver any notifications the observer may have missed by being set late.
91 // observer.
92 if (received_first_packet_) { 117 if (received_first_packet_) {
93 observer_->OnFirstPacketReceived(media_type()); 118 observer_->OnFirstPacketReceived(media_type());
94 } 119 }
95 } 120 }
96 121
97 void AudioRtpReceiver::OnFirstAudioPacketReceived() { 122 void AudioRtpReceiver::SetChannel(cricket::VoiceChannel* channel) {
123 if (channel_) {
124 channel_->SignalFirstPacketReceived.disconnect(this);
125 }
126 channel_ = channel;
127 if (channel_) {
128 channel_->SignalFirstPacketReceived.connect(
129 this, &AudioRtpReceiver::OnFirstPacketReceived);
130 }
131 }
132
133 void AudioRtpReceiver::OnFirstPacketReceived(cricket::BaseChannel* channel) {
98 if (observer_) { 134 if (observer_) {
99 observer_->OnFirstPacketReceived(media_type()); 135 observer_->OnFirstPacketReceived(media_type());
100 } 136 }
101 received_first_packet_ = true; 137 received_first_packet_ = true;
102 } 138 }
103 139
104 VideoRtpReceiver::VideoRtpReceiver(MediaStreamInterface* stream, 140 VideoRtpReceiver::VideoRtpReceiver(MediaStreamInterface* stream,
105 const std::string& track_id, 141 const std::string& track_id,
106 rtc::Thread* worker_thread, 142 rtc::Thread* worker_thread,
107 uint32_t ssrc, 143 uint32_t ssrc,
108 VideoProviderInterface* provider) 144 cricket::VideoChannel* channel)
109 : id_(track_id), 145 : id_(track_id),
110 ssrc_(ssrc), 146 ssrc_(ssrc),
111 provider_(provider), 147 channel_(channel),
112 source_(new RefCountedObject<VideoTrackSource>(&broadcaster_, 148 source_(new RefCountedObject<VideoTrackSource>(&broadcaster_,
113 true /* remote */)), 149 true /* remote */)),
114 track_(VideoTrackProxy::Create( 150 track_(VideoTrackProxy::Create(
115 rtc::Thread::Current(), 151 rtc::Thread::Current(),
116 worker_thread, 152 worker_thread,
117 VideoTrack::Create( 153 VideoTrack::Create(
118 track_id, 154 track_id,
119 VideoTrackSourceProxy::Create(rtc::Thread::Current(), 155 VideoTrackSourceProxy::Create(rtc::Thread::Current(),
120 worker_thread, 156 worker_thread,
121 source_)))) { 157 source_)))) {
122 source_->SetState(MediaSourceInterface::kLive); 158 source_->SetState(MediaSourceInterface::kLive);
123 provider_->SetVideoPlayout(ssrc_, true, &broadcaster_); 159 if (!channel_) {
160 LOG(LS_ERROR)
161 << "VideoRtpReceiver::VideoRtpReceiver: No video channel exists.";
162 } else {
163 if (!channel_->SetSink(ssrc_, &broadcaster_)) {
164 RTC_DCHECK(false);
165 }
166 }
124 stream->AddTrack(track_); 167 stream->AddTrack(track_);
125 provider_->SignalFirstVideoPacketReceived.connect( 168 if (channel_) {
126 this, &VideoRtpReceiver::OnFirstVideoPacketReceived); 169 channel_->SignalFirstPacketReceived.connect(
170 this, &VideoRtpReceiver::OnFirstPacketReceived);
171 }
127 } 172 }
128 173
129 VideoRtpReceiver::~VideoRtpReceiver() { 174 VideoRtpReceiver::~VideoRtpReceiver() {
130 // Since cricket::VideoRenderer is not reference counted, 175 // Since cricket::VideoRenderer is not reference counted,
131 // we need to remove it from the provider before we are deleted. 176 // we need to remove it from the channel before we are deleted.
132 Stop(); 177 Stop();
133 } 178 }
134 179
135 RtpParameters VideoRtpReceiver::GetParameters() const { 180 RtpParameters VideoRtpReceiver::GetParameters() const {
136 return provider_->GetVideoRtpReceiveParameters(ssrc_); 181 if (!channel_ || stopped_) {
182 return RtpParameters();
183 }
184 return channel_->GetRtpReceiveParameters(ssrc_);
137 } 185 }
138 186
139 bool VideoRtpReceiver::SetParameters(const RtpParameters& parameters) { 187 bool VideoRtpReceiver::SetParameters(const RtpParameters& parameters) {
140 TRACE_EVENT0("webrtc", "VideoRtpReceiver::SetParameters"); 188 TRACE_EVENT0("webrtc", "VideoRtpReceiver::SetParameters");
141 return provider_->SetVideoRtpReceiveParameters(ssrc_, parameters); 189 if (!channel_ || stopped_) {
190 return false;
191 }
192 return channel_->SetRtpReceiveParameters(ssrc_, parameters);
142 } 193 }
143 194
144 void VideoRtpReceiver::Stop() { 195 void VideoRtpReceiver::Stop() {
145 // TODO(deadbeef): Need to do more here to fully stop receiving packets. 196 // TODO(deadbeef): Need to do more here to fully stop receiving packets.
146 if (!provider_) { 197 if (stopped_) {
147 return; 198 return;
148 } 199 }
149 source_->SetState(MediaSourceInterface::kEnded); 200 source_->SetState(MediaSourceInterface::kEnded);
150 source_->OnSourceDestroyed(); 201 source_->OnSourceDestroyed();
151 provider_->SetVideoPlayout(ssrc_, false, nullptr); 202 if (!channel_) {
152 provider_ = nullptr; 203 LOG(LS_WARNING) << "VideoRtpReceiver::Stop: No video channel exists.";
204 } else {
205 // Allow that SetSink fail. This is the normal case when the underlying
206 // media channel has already been deleted.
207 channel_->SetSink(ssrc_, nullptr);
208 }
209 stopped_ = true;
153 } 210 }
154 211
155 void VideoRtpReceiver::SetObserver(RtpReceiverObserverInterface* observer) { 212 void VideoRtpReceiver::SetObserver(RtpReceiverObserverInterface* observer) {
156 observer_ = observer; 213 observer_ = observer;
157 // If received the first packet before setting the observer, call the 214 // Deliver any notifications the observer may have missed by being set late.
158 // observer.
159 if (received_first_packet_) { 215 if (received_first_packet_) {
160 observer_->OnFirstPacketReceived(media_type()); 216 observer_->OnFirstPacketReceived(media_type());
161 } 217 }
162 } 218 }
163 219
164 void VideoRtpReceiver::OnFirstVideoPacketReceived() { 220 void VideoRtpReceiver::SetChannel(cricket::VideoChannel* channel) {
221 if (channel_) {
222 channel_->SignalFirstPacketReceived.disconnect(this);
223 channel_->SetSink(ssrc_, nullptr);
224 }
225 channel_ = channel;
226 if (channel_) {
227 if (!channel_->SetSink(ssrc_, &broadcaster_)) {
228 RTC_DCHECK(false);
229 }
230 channel_->SignalFirstPacketReceived.connect(
231 this, &VideoRtpReceiver::OnFirstPacketReceived);
232 }
233 }
234
235 void VideoRtpReceiver::OnFirstPacketReceived(cricket::BaseChannel* channel) {
165 if (observer_) { 236 if (observer_) {
166 observer_->OnFirstPacketReceived(media_type()); 237 observer_->OnFirstPacketReceived(media_type());
167 } 238 }
168 received_first_packet_ = true; 239 received_first_packet_ = true;
169 } 240 }
170 241
171 } // namespace webrtc 242 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/api/rtpreceiver.h ('k') | webrtc/api/rtpreceiverinterface.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698