OLD | NEW |
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/pc/rtpreceiver.h" | 11 #include "webrtc/pc/rtpreceiver.h" |
12 | 12 |
13 #include "webrtc/api/mediastreamtrackproxy.h" | 13 #include "webrtc/api/mediastreamtrackproxy.h" |
14 #include "webrtc/api/videosourceproxy.h" | 14 #include "webrtc/api/videosourceproxy.h" |
15 #include "webrtc/base/trace_event.h" | 15 #include "webrtc/base/trace_event.h" |
16 #include "webrtc/pc/audiotrack.h" | 16 #include "webrtc/pc/audiotrack.h" |
17 #include "webrtc/pc/videotrack.h" | 17 #include "webrtc/pc/videotrack.h" |
18 | 18 |
19 namespace webrtc { | 19 namespace webrtc { |
20 | 20 |
21 AudioRtpReceiver::AudioRtpReceiver(MediaStreamInterface* stream, | 21 AudioRtpReceiver::AudioRtpReceiver(const std::string& track_id, |
22 const std::string& track_id, | |
23 uint32_t ssrc, | 22 uint32_t ssrc, |
24 cricket::VoiceChannel* channel) | 23 cricket::VoiceChannel* channel) |
25 : id_(track_id), | 24 : id_(track_id), |
26 ssrc_(ssrc), | 25 ssrc_(ssrc), |
27 channel_(channel), | 26 channel_(channel), |
28 track_(AudioTrackProxy::Create( | 27 track_(AudioTrackProxy::Create( |
29 rtc::Thread::Current(), | 28 rtc::Thread::Current(), |
30 AudioTrack::Create(track_id, | 29 AudioTrack::Create(track_id, |
31 RemoteAudioSource::Create(ssrc, channel)))), | 30 RemoteAudioSource::Create(ssrc, channel)))), |
32 cached_track_enabled_(track_->enabled()) { | 31 cached_track_enabled_(track_->enabled()) { |
33 RTC_DCHECK(track_->GetSource()->remote()); | 32 RTC_DCHECK(track_->GetSource()->remote()); |
34 track_->RegisterObserver(this); | 33 track_->RegisterObserver(this); |
35 track_->GetSource()->RegisterAudioObserver(this); | 34 track_->GetSource()->RegisterAudioObserver(this); |
36 Reconfigure(); | 35 Reconfigure(); |
37 stream->AddTrack(track_); | |
38 if (channel_) { | 36 if (channel_) { |
39 channel_->SignalFirstPacketReceived.connect( | 37 channel_->SignalFirstPacketReceived.connect( |
40 this, &AudioRtpReceiver::OnFirstPacketReceived); | 38 this, &AudioRtpReceiver::OnFirstPacketReceived); |
41 } | 39 } |
42 } | 40 } |
43 | 41 |
44 AudioRtpReceiver::~AudioRtpReceiver() { | 42 AudioRtpReceiver::~AudioRtpReceiver() { |
45 track_->GetSource()->UnregisterAudioObserver(this); | 43 track_->GetSource()->UnregisterAudioObserver(this); |
46 track_->UnregisterObserver(this); | 44 track_->UnregisterObserver(this); |
47 Stop(); | 45 Stop(); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 } | 128 } |
131 } | 129 } |
132 | 130 |
133 void AudioRtpReceiver::OnFirstPacketReceived(cricket::BaseChannel* channel) { | 131 void AudioRtpReceiver::OnFirstPacketReceived(cricket::BaseChannel* channel) { |
134 if (observer_) { | 132 if (observer_) { |
135 observer_->OnFirstPacketReceived(media_type()); | 133 observer_->OnFirstPacketReceived(media_type()); |
136 } | 134 } |
137 received_first_packet_ = true; | 135 received_first_packet_ = true; |
138 } | 136 } |
139 | 137 |
140 VideoRtpReceiver::VideoRtpReceiver(MediaStreamInterface* stream, | 138 VideoRtpReceiver::VideoRtpReceiver(const std::string& track_id, |
141 const std::string& track_id, | |
142 rtc::Thread* worker_thread, | 139 rtc::Thread* worker_thread, |
143 uint32_t ssrc, | 140 uint32_t ssrc, |
144 cricket::VideoChannel* channel) | 141 cricket::VideoChannel* channel) |
145 : id_(track_id), | 142 : id_(track_id), |
146 ssrc_(ssrc), | 143 ssrc_(ssrc), |
147 channel_(channel), | 144 channel_(channel), |
148 source_(new RefCountedObject<VideoTrackSource>(&broadcaster_, | 145 source_(new RefCountedObject<VideoTrackSource>(&broadcaster_, |
149 true /* remote */)), | 146 true /* remote */)), |
150 track_(VideoTrackProxy::Create( | 147 track_(VideoTrackProxy::Create( |
151 rtc::Thread::Current(), | 148 rtc::Thread::Current(), |
152 worker_thread, | 149 worker_thread, |
153 VideoTrack::Create( | 150 VideoTrack::Create( |
154 track_id, | 151 track_id, |
155 VideoTrackSourceProxy::Create(rtc::Thread::Current(), | 152 VideoTrackSourceProxy::Create(rtc::Thread::Current(), |
156 worker_thread, | 153 worker_thread, |
157 source_)))) { | 154 source_)))) { |
158 source_->SetState(MediaSourceInterface::kLive); | 155 source_->SetState(MediaSourceInterface::kLive); |
159 if (!channel_) { | 156 if (!channel_) { |
160 LOG(LS_ERROR) | 157 LOG(LS_ERROR) |
161 << "VideoRtpReceiver::VideoRtpReceiver: No video channel exists."; | 158 << "VideoRtpReceiver::VideoRtpReceiver: No video channel exists."; |
162 } else { | 159 } else { |
163 if (!channel_->SetSink(ssrc_, &broadcaster_)) { | 160 if (!channel_->SetSink(ssrc_, &broadcaster_)) { |
164 RTC_NOTREACHED(); | 161 RTC_NOTREACHED(); |
165 } | 162 } |
166 } | 163 } |
167 stream->AddTrack(track_); | |
168 if (channel_) { | 164 if (channel_) { |
169 channel_->SignalFirstPacketReceived.connect( | 165 channel_->SignalFirstPacketReceived.connect( |
170 this, &VideoRtpReceiver::OnFirstPacketReceived); | 166 this, &VideoRtpReceiver::OnFirstPacketReceived); |
171 } | 167 } |
172 } | 168 } |
173 | 169 |
174 VideoRtpReceiver::~VideoRtpReceiver() { | 170 VideoRtpReceiver::~VideoRtpReceiver() { |
175 // Since cricket::VideoRenderer is not reference counted, | 171 // Since cricket::VideoRenderer is not reference counted, |
176 // we need to remove it from the channel before we are deleted. | 172 // we need to remove it from the channel before we are deleted. |
177 Stop(); | 173 Stop(); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 } | 229 } |
234 | 230 |
235 void VideoRtpReceiver::OnFirstPacketReceived(cricket::BaseChannel* channel) { | 231 void VideoRtpReceiver::OnFirstPacketReceived(cricket::BaseChannel* channel) { |
236 if (observer_) { | 232 if (observer_) { |
237 observer_->OnFirstPacketReceived(media_type()); | 233 observer_->OnFirstPacketReceived(media_type()); |
238 } | 234 } |
239 received_first_packet_ = true; | 235 received_first_packet_ = true; |
240 } | 236 } |
241 | 237 |
242 } // namespace webrtc | 238 } // namespace webrtc |
OLD | NEW |