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

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

Issue 1999853002: Forward the SignalFirstPacketReceived to RtpReceiver. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Add media type to BaseChannel. Created 4 years, 7 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
(...skipping 11 matching lines...) Expand all
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 observer_(nullptr) {
pthatcher1 2016/06/08 17:35:55 You don't need this if you use "= nullptr" in the
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...) Expand all
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::SetObserver(RtpReceiverObserverInterface* observer) {
90 observer_ = observer;
91 // If received the first packet before setting the observer, call the
92 // observer.
93 if (received_first_packet_) {
94 observer_->OnFirstPacketReceived(cricket::MEDIA_TYPE_AUDIO);
95 }
96 }
97
98 void AudioRtpReceiver::OnFirstAudioPacketReceived() {
99 if (observer_) {
100 observer_->OnFirstPacketReceived(cricket::MEDIA_TYPE_AUDIO);
101 }
102 received_first_packet_ = true;
pthatcher1 2016/06/08 17:35:55 Do you have a unit test that covers setting the ob
103 }
104
86 VideoRtpReceiver::VideoRtpReceiver(MediaStreamInterface* stream, 105 VideoRtpReceiver::VideoRtpReceiver(MediaStreamInterface* stream,
87 const std::string& track_id, 106 const std::string& track_id,
88 rtc::Thread* worker_thread, 107 rtc::Thread* worker_thread,
89 uint32_t ssrc, 108 uint32_t ssrc,
90 VideoProviderInterface* provider) 109 VideoProviderInterface* provider)
91 : id_(track_id), 110 : id_(track_id),
92 ssrc_(ssrc), 111 ssrc_(ssrc),
93 provider_(provider), 112 provider_(provider),
94 source_(new RefCountedObject<VideoTrackSource>(&broadcaster_, 113 source_(new RefCountedObject<VideoTrackSource>(&broadcaster_,
95 true /* remote */)), 114 true /* remote */)),
96 track_(VideoTrackProxy::Create( 115 track_(VideoTrackProxy::Create(
97 rtc::Thread::Current(), 116 rtc::Thread::Current(),
98 worker_thread, 117 worker_thread,
99 VideoTrack::Create( 118 VideoTrack::Create(
100 track_id, 119 track_id,
101 VideoTrackSourceProxy::Create(rtc::Thread::Current(), 120 VideoTrackSourceProxy::Create(rtc::Thread::Current(),
102 worker_thread, 121 worker_thread,
103 source_)))) { 122 source_)))),
123 observer_(nullptr) {
104 source_->SetState(MediaSourceInterface::kLive); 124 source_->SetState(MediaSourceInterface::kLive);
105 provider_->SetVideoPlayout(ssrc_, true, &broadcaster_); 125 provider_->SetVideoPlayout(ssrc_, true, &broadcaster_);
106 stream->AddTrack(track_); 126 stream->AddTrack(track_);
127 provider_->SignalFirstVideoPacketReceived.connect(
128 this, &VideoRtpReceiver::OnFirstVideoPacketReceived);
107 } 129 }
108 130
109 VideoRtpReceiver::~VideoRtpReceiver() { 131 VideoRtpReceiver::~VideoRtpReceiver() {
110 // Since cricket::VideoRenderer is not reference counted, 132 // Since cricket::VideoRenderer is not reference counted,
111 // we need to remove it from the provider before we are deleted. 133 // we need to remove it from the provider before we are deleted.
112 Stop(); 134 Stop();
113 } 135 }
114 136
115 void VideoRtpReceiver::Stop() { 137 void VideoRtpReceiver::Stop() {
116 // TODO(deadbeef): Need to do more here to fully stop receiving packets. 138 // TODO(deadbeef): Need to do more here to fully stop receiving packets.
117 if (!provider_) { 139 if (!provider_) {
118 return; 140 return;
119 } 141 }
120 source_->SetState(MediaSourceInterface::kEnded); 142 source_->SetState(MediaSourceInterface::kEnded);
121 source_->OnSourceDestroyed(); 143 source_->OnSourceDestroyed();
122 provider_->SetVideoPlayout(ssrc_, false, nullptr); 144 provider_->SetVideoPlayout(ssrc_, false, nullptr);
123 provider_ = nullptr; 145 provider_ = nullptr;
124 } 146 }
125 147
126 RtpParameters VideoRtpReceiver::GetParameters() const { 148 RtpParameters VideoRtpReceiver::GetParameters() const {
127 return provider_->GetVideoRtpReceiveParameters(ssrc_); 149 return provider_->GetVideoRtpReceiveParameters(ssrc_);
128 } 150 }
129 151
130 bool VideoRtpReceiver::SetParameters(const RtpParameters& parameters) { 152 bool VideoRtpReceiver::SetParameters(const RtpParameters& parameters) {
131 TRACE_EVENT0("webrtc", "VideoRtpReceiver::SetParameters"); 153 TRACE_EVENT0("webrtc", "VideoRtpReceiver::SetParameters");
132 return provider_->SetVideoRtpReceiveParameters(ssrc_, parameters); 154 return provider_->SetVideoRtpReceiveParameters(ssrc_, parameters);
133 } 155 }
134 156
157 void VideoRtpReceiver::SetObserver(RtpReceiverObserverInterface* observer) {
158 observer_ = observer;
159 // If received the first packet before setting the observer, call the
160 // observer.
161 if (received_first_packet_) {
162 observer_->OnFirstPacketReceived(cricket::MEDIA_TYPE_VIDEO);
163 }
164 }
165
166 void VideoRtpReceiver::OnFirstVideoPacketReceived() {
167 if (observer_) {
168 observer_->OnFirstPacketReceived(cricket::MEDIA_TYPE_VIDEO);
pthatcher1 2016/06/08 17:35:55 Might as well add a media_type() getter to the Rtp
Zhi Huang 2016/06/09 00:37:36 Done.
169 }
170 received_first_packet_ = true;
171 }
172
135 } // namespace webrtc 173 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698