OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 codec.width = 320; | 137 codec.width = 320; |
138 codec.height = 180; | 138 codec.height = 180; |
139 codec.startBitrate = codec.minBitrate = codec.maxBitrate = | 139 codec.startBitrate = codec.minBitrate = codec.maxBitrate = |
140 Call::Config::kDefaultStartBitrateBps / 1000; | 140 Call::Config::kDefaultStartBitrateBps / 1000; |
141 | 141 |
142 return codec; | 142 return codec; |
143 } | 143 } |
144 } // namespace | 144 } // namespace |
145 | 145 |
146 namespace internal { | 146 namespace internal { |
147 | |
148 VideoReceiveStream::VideoReceiveStream( | 147 VideoReceiveStream::VideoReceiveStream( |
149 int num_cpu_cores, | 148 int num_cpu_cores, |
150 CongestionController* congestion_controller, | 149 CongestionController* congestion_controller, |
151 VideoReceiveStream::Config config, | 150 VideoReceiveStream::Config config, |
152 webrtc::VoiceEngine* voice_engine, | 151 webrtc::VoiceEngine* voice_engine, |
153 ProcessThread* process_thread, | 152 ProcessThread* process_thread, |
154 CallStats* call_stats, | 153 CallStats* call_stats, |
155 VieRemb* remb) | 154 VieRemb* remb) |
156 : transport_adapter_(config.rtcp_send_transport), | 155 : transport_adapter_(config.rtcp_send_transport), |
157 config_(std::move(config)), | 156 config_(std::move(config)), |
158 process_thread_(process_thread), | 157 process_thread_(process_thread), |
159 clock_(Clock::GetRealTimeClock()), | 158 clock_(Clock::GetRealTimeClock()), |
160 decode_thread_(DecodeThreadFunction, this, "DecodingThread"), | 159 decode_thread_(DecodeThreadFunction, this, "DecodingThread"), |
161 congestion_controller_(congestion_controller), | 160 congestion_controller_(congestion_controller), |
162 call_stats_(call_stats), | 161 call_stats_(call_stats), |
163 video_receiver_(clock_, nullptr, this, this, this), | 162 video_receiver_(clock_, nullptr, this, this, this), |
| 163 incoming_video_stream_(config_.disable_prerenderer_smoothing), |
164 stats_proxy_(&config_, clock_), | 164 stats_proxy_(&config_, clock_), |
165 rtp_stream_receiver_(&video_receiver_, | 165 rtp_stream_receiver_(&video_receiver_, |
166 congestion_controller_->GetRemoteBitrateEstimator( | 166 congestion_controller_->GetRemoteBitrateEstimator( |
167 UseSendSideBwe(config_)), | 167 UseSendSideBwe(config_)), |
168 &transport_adapter_, | 168 &transport_adapter_, |
169 call_stats_->rtcp_rtt_stats(), | 169 call_stats_->rtcp_rtt_stats(), |
170 congestion_controller_->pacer(), | 170 congestion_controller_->pacer(), |
171 congestion_controller_->packet_router(), | 171 congestion_controller_->packet_router(), |
172 remb, | 172 remb, |
173 &config_, | 173 &config_, |
174 &stats_proxy_, | 174 &stats_proxy_, |
175 process_thread_), | 175 process_thread_), |
| 176 video_stream_decoder_(&video_receiver_, |
| 177 &rtp_stream_receiver_, |
| 178 &rtp_stream_receiver_, |
| 179 rtp_stream_receiver_.IsRetransmissionsEnabled(), |
| 180 rtp_stream_receiver_.IsFecEnabled(), |
| 181 &stats_proxy_, |
| 182 &incoming_video_stream_, |
| 183 config.pre_render_callback), |
176 vie_sync_(&video_receiver_) { | 184 vie_sync_(&video_receiver_) { |
177 LOG(LS_INFO) << "VideoReceiveStream: " << config_.ToString(); | 185 LOG(LS_INFO) << "VideoReceiveStream: " << config_.ToString(); |
178 | 186 |
179 RTC_DCHECK(process_thread_); | 187 RTC_DCHECK(process_thread_); |
180 RTC_DCHECK(congestion_controller_); | 188 RTC_DCHECK(congestion_controller_); |
181 RTC_DCHECK(call_stats_); | 189 RTC_DCHECK(call_stats_); |
182 | 190 |
| 191 // Register the channel to receive stats updates. |
| 192 call_stats_->RegisterStatsObserver(&video_stream_decoder_); |
| 193 |
183 RTC_DCHECK(!config_.decoders.empty()); | 194 RTC_DCHECK(!config_.decoders.empty()); |
184 std::set<int> decoder_payload_types; | 195 std::set<int> decoder_payload_types; |
185 for (const Decoder& decoder : config_.decoders) { | 196 for (const Decoder& decoder : config_.decoders) { |
186 RTC_CHECK(decoder.decoder); | 197 RTC_CHECK(decoder.decoder); |
187 RTC_CHECK(decoder_payload_types.find(decoder.payload_type) == | 198 RTC_CHECK(decoder_payload_types.find(decoder.payload_type) == |
188 decoder_payload_types.end()) | 199 decoder_payload_types.end()) |
189 << "Duplicate payload type (" << decoder.payload_type | 200 << "Duplicate payload type (" << decoder.payload_type |
190 << ") for different decoders."; | 201 << ") for different decoders."; |
191 decoder_payload_types.insert(decoder.payload_type); | 202 decoder_payload_types.insert(decoder.payload_type); |
192 video_receiver_.RegisterExternalDecoder(decoder.decoder, | 203 video_receiver_.RegisterExternalDecoder(decoder.decoder, |
193 decoder.payload_type); | 204 decoder.payload_type); |
194 | 205 |
195 VideoCodec codec = CreateDecoderVideoCodec(decoder); | 206 VideoCodec codec = CreateDecoderVideoCodec(decoder); |
196 RTC_CHECK(rtp_stream_receiver_.SetReceiveCodec(codec)); | 207 RTC_CHECK(rtp_stream_receiver_.SetReceiveCodec(codec)); |
197 RTC_CHECK_EQ(VCM_OK, video_receiver_.RegisterReceiveCodec( | 208 RTC_CHECK_EQ(VCM_OK, video_receiver_.RegisterReceiveCodec( |
198 &codec, num_cpu_cores, false)); | 209 &codec, num_cpu_cores, false)); |
199 } | 210 } |
200 | 211 |
201 video_receiver_.SetRenderDelay(config.render_delay_ms); | 212 video_receiver_.SetRenderDelay(config.render_delay_ms); |
| 213 incoming_video_stream_.SetExpectedRenderDelay(config.render_delay_ms); |
| 214 incoming_video_stream_.SetExternalCallback(this); |
202 | 215 |
203 process_thread_->RegisterModule(&video_receiver_); | 216 process_thread_->RegisterModule(&video_receiver_); |
204 process_thread_->RegisterModule(&vie_sync_); | 217 process_thread_->RegisterModule(&vie_sync_); |
205 } | 218 } |
206 | 219 |
207 VideoReceiveStream::~VideoReceiveStream() { | 220 VideoReceiveStream::~VideoReceiveStream() { |
208 LOG(LS_INFO) << "~VideoReceiveStream: " << config_.ToString(); | 221 LOG(LS_INFO) << "~VideoReceiveStream: " << config_.ToString(); |
209 Stop(); | 222 Stop(); |
210 | 223 |
211 process_thread_->DeRegisterModule(&vie_sync_); | 224 process_thread_->DeRegisterModule(&vie_sync_); |
212 process_thread_->DeRegisterModule(&video_receiver_); | 225 process_thread_->DeRegisterModule(&video_receiver_); |
213 | 226 |
214 // Deregister external decoders so they are no longer running during | 227 // Deregister external decoders so they are no longer running during |
215 // destruction. This effectively stops the VCM since the decoder thread is | 228 // destruction. This effectively stops the VCM since the decoder thread is |
216 // stopped, the VCM is deregistered and no asynchronous decoder threads are | 229 // stopped, the VCM is deregistered and no asynchronous decoder threads are |
217 // running. | 230 // running. |
218 for (const Decoder& decoder : config_.decoders) | 231 for (const Decoder& decoder : config_.decoders) |
219 video_receiver_.RegisterExternalDecoder(nullptr, decoder.payload_type); | 232 video_receiver_.RegisterExternalDecoder(nullptr, decoder.payload_type); |
220 | 233 |
| 234 call_stats_->DeregisterStatsObserver(&video_stream_decoder_); |
| 235 |
221 congestion_controller_->GetRemoteBitrateEstimator(UseSendSideBwe(config_)) | 236 congestion_controller_->GetRemoteBitrateEstimator(UseSendSideBwe(config_)) |
222 ->RemoveStream(rtp_stream_receiver_.GetRemoteSsrc()); | 237 ->RemoveStream(rtp_stream_receiver_.GetRemoteSsrc()); |
223 } | 238 } |
224 | 239 |
225 void VideoReceiveStream::SignalNetworkState(NetworkState state) { | 240 void VideoReceiveStream::SignalNetworkState(NetworkState state) { |
226 rtp_stream_receiver_.SignalNetworkState(state); | 241 rtp_stream_receiver_.SignalNetworkState(state); |
227 } | 242 } |
228 | 243 |
229 | 244 |
230 bool VideoReceiveStream::DeliverRtcp(const uint8_t* packet, size_t length) { | 245 bool VideoReceiveStream::DeliverRtcp(const uint8_t* packet, size_t length) { |
231 return rtp_stream_receiver_.DeliverRtcp(packet, length); | 246 return rtp_stream_receiver_.DeliverRtcp(packet, length); |
232 } | 247 } |
233 | 248 |
234 bool VideoReceiveStream::DeliverRtp(const uint8_t* packet, | 249 bool VideoReceiveStream::DeliverRtp(const uint8_t* packet, |
235 size_t length, | 250 size_t length, |
236 const PacketTime& packet_time) { | 251 const PacketTime& packet_time) { |
237 return rtp_stream_receiver_.DeliverRtp(packet, length, packet_time); | 252 return rtp_stream_receiver_.DeliverRtp(packet, length, packet_time); |
238 } | 253 } |
239 | 254 |
240 void VideoReceiveStream::Start() { | 255 void VideoReceiveStream::Start() { |
241 if (decode_thread_.IsRunning()) | 256 if (decode_thread_.IsRunning()) |
242 return; | 257 return; |
243 transport_adapter_.Enable(); | 258 transport_adapter_.Enable(); |
244 rtc::VideoSinkInterface<VideoFrame>* renderer = nullptr; | 259 incoming_video_stream_.Start(); |
245 if (config_.renderer) { | |
246 if (config_.disable_prerenderer_smoothing) { | |
247 renderer = this; | |
248 } else { | |
249 incoming_video_stream_.reset( | |
250 new IncomingVideoStream(config_.render_delay_ms, this)); | |
251 renderer = incoming_video_stream_.get(); | |
252 } | |
253 } | |
254 | |
255 video_stream_decoder_.reset(new VideoStreamDecoder( | |
256 &video_receiver_, &rtp_stream_receiver_, &rtp_stream_receiver_, | |
257 rtp_stream_receiver_.IsRetransmissionsEnabled(), | |
258 rtp_stream_receiver_.IsFecEnabled(), &stats_proxy_, renderer, | |
259 config_.pre_render_callback)); | |
260 // Register the channel to receive stats updates. | |
261 call_stats_->RegisterStatsObserver(video_stream_decoder_.get()); | |
262 // Start the decode thread | 260 // Start the decode thread |
263 decode_thread_.Start(); | 261 decode_thread_.Start(); |
264 decode_thread_.SetPriority(rtc::kHighestPriority); | 262 decode_thread_.SetPriority(rtc::kHighestPriority); |
265 rtp_stream_receiver_.StartReceive(); | 263 rtp_stream_receiver_.StartReceive(); |
266 } | 264 } |
267 | 265 |
268 void VideoReceiveStream::Stop() { | 266 void VideoReceiveStream::Stop() { |
| 267 incoming_video_stream_.Stop(); |
269 rtp_stream_receiver_.StopReceive(); | 268 rtp_stream_receiver_.StopReceive(); |
270 video_receiver_.TriggerDecoderShutdown(); | 269 video_receiver_.TriggerDecoderShutdown(); |
271 decode_thread_.Stop(); | 270 decode_thread_.Stop(); |
272 call_stats_->DeregisterStatsObserver(video_stream_decoder_.get()); | |
273 video_stream_decoder_.reset(); | |
274 incoming_video_stream_.reset(); | |
275 transport_adapter_.Disable(); | 271 transport_adapter_.Disable(); |
276 } | 272 } |
277 | 273 |
278 void VideoReceiveStream::SetSyncChannel(VoiceEngine* voice_engine, | 274 void VideoReceiveStream::SetSyncChannel(VoiceEngine* voice_engine, |
279 int audio_channel_id) { | 275 int audio_channel_id) { |
280 if (voice_engine && audio_channel_id != -1) { | 276 if (voice_engine && audio_channel_id != -1) { |
281 VoEVideoSync* voe_sync_interface = VoEVideoSync::GetInterface(voice_engine); | 277 VoEVideoSync* voe_sync_interface = VoEVideoSync::GetInterface(voice_engine); |
282 vie_sync_.ConfigureSync(audio_channel_id, voe_sync_interface, | 278 vie_sync_.ConfigureSync(audio_channel_id, voe_sync_interface, |
283 rtp_stream_receiver_.rtp_rtcp(), | 279 rtp_stream_receiver_.rtp_rtcp(), |
284 rtp_stream_receiver_.GetRtpReceiver()); | 280 rtp_stream_receiver_.GetRtpReceiver()); |
285 voe_sync_interface->Release(); | 281 voe_sync_interface->Release(); |
286 } else { | 282 } else { |
287 vie_sync_.ConfigureSync(-1, nullptr, rtp_stream_receiver_.rtp_rtcp(), | 283 vie_sync_.ConfigureSync(-1, nullptr, rtp_stream_receiver_.rtp_rtcp(), |
288 rtp_stream_receiver_.GetRtpReceiver()); | 284 rtp_stream_receiver_.GetRtpReceiver()); |
289 } | 285 } |
290 } | 286 } |
291 | 287 |
292 VideoReceiveStream::Stats VideoReceiveStream::GetStats() const { | 288 VideoReceiveStream::Stats VideoReceiveStream::GetStats() const { |
293 return stats_proxy_.GetStats(); | 289 return stats_proxy_.GetStats(); |
294 } | 290 } |
295 | 291 |
296 // TODO(tommi): This method grabs a lock 6 times. | |
297 void VideoReceiveStream::OnFrame(const VideoFrame& video_frame) { | 292 void VideoReceiveStream::OnFrame(const VideoFrame& video_frame) { |
298 // TODO(tommi): OnDecodedFrame grabs a lock, incidentally the same lock | |
299 // that OnSyncOffsetUpdated() and OnRenderedFrame() below grab. | |
300 stats_proxy_.OnDecodedFrame(); | 293 stats_proxy_.OnDecodedFrame(); |
301 | 294 |
302 int64_t sync_offset_ms; | 295 int64_t sync_offset_ms; |
303 // TODO(tommi): GetStreamSyncOffsetInMs grabs three locks. One inside the | 296 if (vie_sync_.GetStreamSyncOffsetInMs(video_frame, &sync_offset_ms)) |
304 // function itself, another in GetChannel() and a third in | |
305 // GetPlayoutTimestamp. Seems excessive. Anyhow, I'm assuming the function | |
306 // succeeds most of the time, which leads to grabbing a fourth lock. | |
307 if (vie_sync_.GetStreamSyncOffsetInMs(video_frame, &sync_offset_ms)) { | |
308 // TODO(tommi): OnSyncOffsetUpdated grabs a lock. | |
309 stats_proxy_.OnSyncOffsetUpdated(sync_offset_ms); | 297 stats_proxy_.OnSyncOffsetUpdated(sync_offset_ms); |
310 } | |
311 | 298 |
312 // config_.renderer must never be null if we're getting this callback. | 299 if (config_.renderer) |
313 config_.renderer->OnFrame(video_frame); | 300 config_.renderer->OnFrame(video_frame); |
314 | 301 |
315 // TODO(tommi): OnRenderFrame grabs a lock too. | |
316 stats_proxy_.OnRenderedFrame(video_frame.width(), video_frame.height()); | 302 stats_proxy_.OnRenderedFrame(video_frame.width(), video_frame.height()); |
317 } | 303 } |
318 | 304 |
319 // TODO(asapersson): Consider moving callback from video_encoder.h or | 305 // TODO(asapersson): Consider moving callback from video_encoder.h or |
320 // creating a different callback. | 306 // creating a different callback. |
321 int32_t VideoReceiveStream::Encoded( | 307 int32_t VideoReceiveStream::Encoded( |
322 const EncodedImage& encoded_image, | 308 const EncodedImage& encoded_image, |
323 const CodecSpecificInfo* codec_specific_info, | 309 const CodecSpecificInfo* codec_specific_info, |
324 const RTPFragmentationHeader* fragmentation) { | 310 const RTPFragmentationHeader* fragmentation) { |
325 stats_proxy_.OnPreDecode(encoded_image, codec_specific_info); | 311 stats_proxy_.OnPreDecode(encoded_image, codec_specific_info); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 const std::vector<uint16_t>& sequence_numbers) { | 345 const std::vector<uint16_t>& sequence_numbers) { |
360 rtp_stream_receiver_.RequestPacketRetransmit(sequence_numbers); | 346 rtp_stream_receiver_.RequestPacketRetransmit(sequence_numbers); |
361 } | 347 } |
362 | 348 |
363 void VideoReceiveStream::RequestKeyFrame() { | 349 void VideoReceiveStream::RequestKeyFrame() { |
364 rtp_stream_receiver_.RequestKeyFrame(); | 350 rtp_stream_receiver_.RequestKeyFrame(); |
365 } | 351 } |
366 | 352 |
367 } // namespace internal | 353 } // namespace internal |
368 } // namespace webrtc | 354 } // namespace webrtc |
OLD | NEW |