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 |
(...skipping 11 matching lines...) Loading... | |
22 const std::string& track_id, | 22 const std::string& track_id, |
23 uint32_t ssrc, | 23 uint32_t ssrc, |
24 AudioProviderInterface* provider) | 24 AudioProviderInterface* provider) |
25 : id_(track_id), | 25 : id_(track_id), |
26 ssrc_(ssrc), | 26 ssrc_(ssrc), |
27 provider_(provider), | 27 provider_(provider), |
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, provider)))), |
32 cached_track_enabled_(track_->enabled()) { | 32 cached_track_enabled_(track_->enabled()), |
33 rtp_receiver_observer_(nullptr) { | |
33 RTC_DCHECK(track_->GetSource()->remote()); | 34 RTC_DCHECK(track_->GetSource()->remote()); |
34 track_->RegisterObserver(this); | 35 track_->RegisterObserver(this); |
35 track_->GetSource()->RegisterAudioObserver(this); | 36 track_->GetSource()->RegisterAudioObserver(this); |
36 Reconfigure(); | 37 Reconfigure(); |
37 stream->AddTrack(track_); | 38 stream->AddTrack(track_); |
39 provider_->SignalFirstAudioPacketReceived.connect( | |
40 this, &AudioRtpReceiver::onFirstAudioPacketReceived); | |
38 } | 41 } |
39 | 42 |
40 AudioRtpReceiver::~AudioRtpReceiver() { | 43 AudioRtpReceiver::~AudioRtpReceiver() { |
41 track_->GetSource()->UnregisterAudioObserver(this); | 44 track_->GetSource()->UnregisterAudioObserver(this); |
42 track_->UnregisterObserver(this); | 45 track_->UnregisterObserver(this); |
43 Stop(); | 46 Stop(); |
44 } | 47 } |
45 | 48 |
46 void AudioRtpReceiver::OnChanged() { | 49 void AudioRtpReceiver::OnChanged() { |
47 if (cached_track_enabled_ != track_->enabled()) { | 50 if (cached_track_enabled_ != track_->enabled()) { |
(...skipping 28 matching lines...) Loading... | |
76 return provider_->SetAudioRtpReceiveParameters(ssrc_, parameters); | 79 return provider_->SetAudioRtpReceiveParameters(ssrc_, parameters); |
77 } | 80 } |
78 | 81 |
79 void AudioRtpReceiver::Reconfigure() { | 82 void AudioRtpReceiver::Reconfigure() { |
80 if (!provider_) { | 83 if (!provider_) { |
81 return; | 84 return; |
82 } | 85 } |
83 provider_->SetAudioPlayout(ssrc_, track_->enabled()); | 86 provider_->SetAudioPlayout(ssrc_, track_->enabled()); |
84 } | 87 } |
85 | 88 |
89 void AudioRtpReceiver::RegisterRtpReceiverObserver( | |
90 RtpReceiverObserverInterface* observer) { | |
91 rtp_receiver_observer_ = observer; | |
pthatcher2
2016/05/20 20:23:13
We could add:
if (received_first_packet_) {
obs
Zhi Huang
2016/06/09 00:37:36
This is a good point! In this way, we can fire the
| |
92 } | |
93 | |
94 void AudioRtpReceiver::onFirstAudioPacketReceived() { | |
95 if (rtp_receiver_observer_) { | |
96 rtp_receiver_observer_->onFirstPacketReceived(cricket::MEDIA_TYPE_AUDIO); | |
97 } | |
pthatcher2
2016/05/20 20:23:13
Right here we could store:
received_first_packet_
| |
98 } | |
99 | |
86 VideoRtpReceiver::VideoRtpReceiver(MediaStreamInterface* stream, | 100 VideoRtpReceiver::VideoRtpReceiver(MediaStreamInterface* stream, |
87 const std::string& track_id, | 101 const std::string& track_id, |
88 rtc::Thread* worker_thread, | 102 rtc::Thread* worker_thread, |
89 uint32_t ssrc, | 103 uint32_t ssrc, |
90 VideoProviderInterface* provider) | 104 VideoProviderInterface* provider) |
91 : id_(track_id), | 105 : id_(track_id), |
92 ssrc_(ssrc), | 106 ssrc_(ssrc), |
93 provider_(provider), | 107 provider_(provider), |
94 source_(new RefCountedObject<VideoTrackSource>(&broadcaster_, | 108 source_(new RefCountedObject<VideoTrackSource>(&broadcaster_, |
95 true /* remote */)), | 109 true /* remote */)), |
96 track_(VideoTrackProxy::Create( | 110 track_(VideoTrackProxy::Create( |
97 rtc::Thread::Current(), | 111 rtc::Thread::Current(), |
98 worker_thread, | 112 worker_thread, |
99 VideoTrack::Create( | 113 VideoTrack::Create( |
100 track_id, | 114 track_id, |
101 VideoTrackSourceProxy::Create(rtc::Thread::Current(), | 115 VideoTrackSourceProxy::Create(rtc::Thread::Current(), |
102 worker_thread, | 116 worker_thread, |
103 source_)))) { | 117 source_)))), |
118 rtp_receiver_observer_(nullptr) { | |
104 source_->SetState(MediaSourceInterface::kLive); | 119 source_->SetState(MediaSourceInterface::kLive); |
105 provider_->SetVideoPlayout(ssrc_, true, &broadcaster_); | 120 provider_->SetVideoPlayout(ssrc_, true, &broadcaster_); |
106 stream->AddTrack(track_); | 121 stream->AddTrack(track_); |
122 provider_->SignalFirstVideoPacketReceived.connect( | |
123 this, &VideoRtpReceiver::onFirstVideoPacketReceived); | |
107 } | 124 } |
108 | 125 |
109 VideoRtpReceiver::~VideoRtpReceiver() { | 126 VideoRtpReceiver::~VideoRtpReceiver() { |
110 // Since cricket::VideoRenderer is not reference counted, | 127 // Since cricket::VideoRenderer is not reference counted, |
111 // we need to remove it from the provider before we are deleted. | 128 // we need to remove it from the provider before we are deleted. |
112 Stop(); | 129 Stop(); |
113 } | 130 } |
114 | 131 |
115 void VideoRtpReceiver::Stop() { | 132 void VideoRtpReceiver::Stop() { |
116 // TODO(deadbeef): Need to do more here to fully stop receiving packets. | 133 // TODO(deadbeef): Need to do more here to fully stop receiving packets. |
117 if (!provider_) { | 134 if (!provider_) { |
118 return; | 135 return; |
119 } | 136 } |
120 source_->SetState(MediaSourceInterface::kEnded); | 137 source_->SetState(MediaSourceInterface::kEnded); |
121 source_->OnSourceDestroyed(); | 138 source_->OnSourceDestroyed(); |
122 provider_->SetVideoPlayout(ssrc_, false, nullptr); | 139 provider_->SetVideoPlayout(ssrc_, false, nullptr); |
123 provider_ = nullptr; | 140 provider_ = nullptr; |
124 } | 141 } |
125 | 142 |
126 RtpParameters VideoRtpReceiver::GetParameters() const { | 143 RtpParameters VideoRtpReceiver::GetParameters() const { |
127 return provider_->GetVideoRtpReceiveParameters(ssrc_); | 144 return provider_->GetVideoRtpReceiveParameters(ssrc_); |
128 } | 145 } |
129 | 146 |
130 bool VideoRtpReceiver::SetParameters(const RtpParameters& parameters) { | 147 bool VideoRtpReceiver::SetParameters(const RtpParameters& parameters) { |
131 TRACE_EVENT0("webrtc", "VideoRtpReceiver::SetParameters"); | 148 TRACE_EVENT0("webrtc", "VideoRtpReceiver::SetParameters"); |
132 return provider_->SetVideoRtpReceiveParameters(ssrc_, parameters); | 149 return provider_->SetVideoRtpReceiveParameters(ssrc_, parameters); |
133 } | 150 } |
134 | 151 |
152 void VideoRtpReceiver::RegisterRtpReceiverObserver( | |
153 RtpReceiverObserverInterface* observer) { | |
154 rtp_receiver_observer_ = observer; | |
155 } | |
156 | |
157 void VideoRtpReceiver::onFirstVideoPacketReceived() { | |
158 if (rtp_receiver_observer_) { | |
159 rtp_receiver_observer_->onFirstPacketReceived(cricket::MEDIA_TYPE_VIDEO); | |
160 } | |
161 } | |
pthatcher2
2016/05/20 20:23:13
Same here.
| |
162 | |
135 } // namespace webrtc | 163 } // namespace webrtc |
OLD | NEW |